diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
| commit | eb11fae6d08f479c0799db45860a98af528fa6e7 (patch) | |
| tree | 44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /include/llvm/Analysis/MustExecute.h | |
| parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) | |
Notes
Diffstat (limited to 'include/llvm/Analysis/MustExecute.h')
| -rw-r--r-- | include/llvm/Analysis/MustExecute.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/include/llvm/Analysis/MustExecute.h b/include/llvm/Analysis/MustExecute.h new file mode 100644 index 000000000000..8daf156567cd --- /dev/null +++ b/include/llvm/Analysis/MustExecute.h @@ -0,0 +1,64 @@ +//===- MustExecute.h - Is an instruction known to execute--------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// \file +/// Contains a collection of routines for determining if a given instruction is +/// guaranteed to execute if a given point in control flow is reached. The most +/// common example is an instruction within a loop being provably executed if we +/// branch to the header of it's containing loop. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_ANALYSIS_MUSTEXECUTE_H +#define LLVM_ANALYSIS_MUSTEXECUTE_H + +#include "llvm/ADT/DenseMap.h" +#include "llvm/Analysis/EHPersonalities.h" +#include "llvm/Analysis/LoopInfo.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Dominators.h" +#include "llvm/IR/Instruction.h" + +namespace llvm { + +class Instruction; +class DominatorTree; +class Loop; + +/// Captures loop safety information. +/// It keep information for loop & its header may throw exception or otherwise +/// exit abnormaly on any iteration of the loop which might actually execute +/// at runtime. The primary way to consume this infromation is via +/// isGuaranteedToExecute below, but some callers bailout or fallback to +/// alternate reasoning if a loop contains any implicit control flow. +struct LoopSafetyInfo { + bool MayThrow = false; // The current loop contains an instruction which + // may throw. + bool HeaderMayThrow = false; // Same as previous, but specific to loop header + // Used to update funclet bundle operands. + DenseMap<BasicBlock *, ColorVector> BlockColors; + + LoopSafetyInfo() = default; +}; + +/// Computes safety information for a loop checks loop body & header for +/// the possibility of may throw exception, it takes LoopSafetyInfo and loop as +/// argument. Updates safety information in LoopSafetyInfo argument. +/// Note: This is defined to clear and reinitialize an already initialized +/// LoopSafetyInfo. Some callers rely on this fact. +void computeLoopSafetyInfo(LoopSafetyInfo *, Loop *); + +/// Returns true if the instruction in a loop is guaranteed to execute at least +/// once (under the assumption that the loop is entered). +bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, + const Loop *CurLoop, + const LoopSafetyInfo *SafetyInfo); + +} + +#endif |
