blob: 97ad76d451ca45891b82c34d902bb423c3ae8cae [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- MustExecute.h - Is an instruction known to execute--------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10/// Contains a collection of routines for determining if a given instruction is
11/// guaranteed to execute if a given point in control flow is reached. The most
12/// common example is an instruction within a loop being provably executed if we
Andrew Scullcdfcccc2018-10-05 20:58:37 +010013/// branch to the header of it's containing loop.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010014///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_ANALYSIS_MUSTEXECUTE_H
18#define LLVM_ANALYSIS_MUSTEXECUTE_H
19
20#include "llvm/ADT/DenseMap.h"
21#include "llvm/Analysis/EHPersonalities.h"
22#include "llvm/Analysis/LoopInfo.h"
23#include "llvm/IR/BasicBlock.h"
24#include "llvm/IR/Dominators.h"
25#include "llvm/IR/Instruction.h"
26
27namespace llvm {
28
29class Instruction;
30class DominatorTree;
31class Loop;
32
Andrew Scullcdfcccc2018-10-05 20:58:37 +010033/// Captures loop safety information.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010034/// It keep information for loop & its header may throw exception or otherwise
35/// exit abnormaly on any iteration of the loop which might actually execute
36/// at runtime. The primary way to consume this infromation is via
37/// isGuaranteedToExecute below, but some callers bailout or fallback to
38/// alternate reasoning if a loop contains any implicit control flow.
39struct LoopSafetyInfo {
40 bool MayThrow = false; // The current loop contains an instruction which
41 // may throw.
42 bool HeaderMayThrow = false; // Same as previous, but specific to loop header
43 // Used to update funclet bundle operands.
44 DenseMap<BasicBlock *, ColorVector> BlockColors;
45
46 LoopSafetyInfo() = default;
47};
48
Andrew Scullcdfcccc2018-10-05 20:58:37 +010049/// Computes safety information for a loop checks loop body & header for
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010050/// the possibility of may throw exception, it takes LoopSafetyInfo and loop as
51/// argument. Updates safety information in LoopSafetyInfo argument.
52/// Note: This is defined to clear and reinitialize an already initialized
53/// LoopSafetyInfo. Some callers rely on this fact.
54void computeLoopSafetyInfo(LoopSafetyInfo *, Loop *);
55
56/// Returns true if the instruction in a loop is guaranteed to execute at least
57/// once (under the assumption that the loop is entered).
58bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT,
59 const Loop *CurLoop,
60 const LoopSafetyInfo *SafetyInfo);
Andrew Scullcdfcccc2018-10-05 20:58:37 +010061
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010062}
63
64#endif