1 //===- 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 13 /// branch to the header of it's containing loop. 14 /// 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 27 namespace llvm { 28 29 class Instruction; 30 class DominatorTree; 31 class Loop; 32 33 /// Captures loop safety information. 34 /// 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. 39 struct 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 49 /// Computes safety information for a loop checks loop body & header for 50 /// 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. 54 void 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). 58 bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, 59 const Loop *CurLoop, 60 const LoopSafetyInfo *SafetyInfo); 61 62 } 63 64 #endif 65