/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Transforms/Utils/ImplicitControlFlowTracking.h
Line | Count | Source |
1 | | //===-- ImplicitControlFlowTracking.h ---------------------------*- 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 | | // This class allows to keep track on instructions with implicit control flow. |
10 | | // These are instructions that may not pass execution to their successors. For |
11 | | // example, throwing calls and guards do not always do this. If we need to know |
12 | | // for sure that some instruction is guaranteed to execute if the given block |
13 | | // is reached, then we need to make sure that there is no implicit control flow |
14 | | // instruction (ICFI) preceeding it. For example, this check is required if we |
15 | | // perform PRE moving non-speculable instruction to other place. |
16 | | //===----------------------------------------------------------------------===// |
17 | | |
18 | | #ifndef LLVM_TRANSFORMS_UTILS_IMPLICITCONTROLFLOWTRACKING_H |
19 | | #define LLVM_TRANSFORMS_UTILS_IMPLICITCONTROLFLOWTRACKING_H |
20 | | |
21 | | #include "llvm/IR/Dominators.h" |
22 | | #include "llvm/Transforms/Utils/OrderedInstructions.h" |
23 | | |
24 | | namespace llvm { |
25 | | |
26 | | class ImplicitControlFlowTracking { |
27 | | public: |
28 | | ImplicitControlFlowTracking(DominatorTree *DT) |
29 | 455k | : OI(OrderedInstructions(DT)) {} |
30 | | |
31 | | // Returns the topmost instruction with implicit control flow from the given |
32 | | // basic block. Returns nullptr if there is no such instructions in the block. |
33 | | const Instruction *getFirstICFI(const BasicBlock *BB); |
34 | | |
35 | | // Returns true if at least one instruction from the given basic block has |
36 | | // implicit control flow. |
37 | | bool hasICF(const BasicBlock *BB); |
38 | | |
39 | | // Returns true if the first ICFI of Insn's block exists and dominates Insn. |
40 | | bool isDominatedByICFIFromSameBlock(const Instruction *Insn); |
41 | | |
42 | | // Clears information about this particular block. |
43 | | void invalidateBlock(const BasicBlock *BB); |
44 | | |
45 | | // Invalidates all information from this tracking. |
46 | | void clear(); |
47 | | |
48 | | private: |
49 | | // Fills information about the given block's implicit control flow. |
50 | | void fill(const BasicBlock *BB); |
51 | | |
52 | | // Maps a block to the topmost instruction with implicit control flow in it. |
53 | | DenseMap<const BasicBlock *, const Instruction *> |
54 | | FirstImplicitControlFlowInsts; |
55 | | OrderedInstructions OI; |
56 | | // Blocks for which we have the actual information. |
57 | | SmallPtrSet<const BasicBlock *, 8> KnownBlocks; |
58 | | }; |
59 | | |
60 | | } // llvm |
61 | | |
62 | | #endif // LLVM_TRANSFORMS_UTILS_IMPLICITCONTROLFLOWTRACKING_H |