LLVM: lib/Transforms/Scalar/FlattenCFGPass.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
21
22using namespace llvm;
23
24#define DEBUG_TYPE "flatten-cfg"
25
26namespace {
27struct FlattenCFGLegacyPass : public FunctionPass {
28 static char ID;
29public:
32 }
34
35 void getAnalysisUsage(AnalysisUsage &AU) const override {
37 }
38
39private:
41};
42}
43
44
45
48 bool LocalChange = true;
49
50
51
52 std::vector Blocks;
53 Blocks.reserve(F.size());
54 for (auto &BB : F)
55 Blocks.push_back(&BB);
56
57 while (LocalChange) {
58 LocalChange = false;
59
60
61 for (WeakVH &BlockHandle : Blocks) {
62
65 LocalChange = true;
66 }
68 }
70}
71
72char FlattenCFGLegacyPass::ID = 0;
73
75 false, false)
79
80
82 return new FlattenCFGLegacyPass();
83}
84
85bool FlattenCFGLegacyPass::runOnFunction(Function &F) {
86 AA = &getAnalysis().getAAResults();
87 bool EverChanged = false;
88
91 EverChanged = true;
92 }
93 return EverChanged;
94}
95
98 bool EverChanged = false;
100
103 EverChanged = true;
104 }
106}
static bool runOnFunction(Function &F, bool PostInlining)
static bool iterativelyFlattenCFG(Function &F, AliasAnalysis *AA)
iterativelyFlattenCFG - Call FlattenCFG on all the blocks in the function, iterating until no more ch...
Definition FlattenCFGPass.cpp:46
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
A manager for alias analyses.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
FunctionPass class - This class is used to implement most global optimizations.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A nullable Value handle that is nullable.
Abstract Attribute helper functions.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI FunctionPass * createFlattenCFGPass()
Definition FlattenCFGPass.cpp:81
LLVM_ABI bool FlattenCFG(BasicBlock *BB, AAResults *AA=nullptr)
This function is used to flatten a CFG.
auto cast_or_null(const Y &Val)
LLVM_ABI void initializeFlattenCFGLegacyPassPass(PassRegistry &)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
LLVM_ABI bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Remove all blocks that can not be reached from the function's entry.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition FlattenCFGPass.cpp:96