LLVM  6.0.0svn
FlattenCFGPass.cpp
Go to the documentation of this file.
1 //===- FlattenCFGPass.cpp - CFG Flatten Pass ----------------------===//
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 //
10 // This file implements flattening of CFG.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/IR/CFG.h"
16 #include "llvm/Pass.h"
17 #include "llvm/Transforms/Scalar.h"
19 using namespace llvm;
20 
21 #define DEBUG_TYPE "flattencfg"
22 
23 namespace {
24 struct FlattenCFGPass : public FunctionPass {
25  static char ID; // Pass identification, replacement for typeid
26 public:
27  FlattenCFGPass() : FunctionPass(ID) {
29  }
30  bool runOnFunction(Function &F) override;
31 
32  void getAnalysisUsage(AnalysisUsage &AU) const override {
34  }
35 
36 private:
37  AliasAnalysis *AA;
38 };
39 }
40 
41 char FlattenCFGPass::ID = 0;
42 INITIALIZE_PASS_BEGIN(FlattenCFGPass, "flattencfg", "Flatten the CFG", false,
43  false)
45 INITIALIZE_PASS_END(FlattenCFGPass, "flattencfg", "Flatten the CFG", false,
46  false)
47 
48 // Public interface to the FlattenCFG pass
49 FunctionPass *llvm::createFlattenCFGPass() { return new FlattenCFGPass(); }
50 
51 /// iterativelyFlattenCFG - Call FlattenCFG on all the blocks in the function,
52 /// iterating until no more changes are made.
54  bool Changed = false;
55  bool LocalChange = true;
56  while (LocalChange) {
57  LocalChange = false;
58 
59  // Loop over all of the basic blocks and remove them if they are unneeded...
60  //
61  for (Function::iterator BBIt = F.begin(); BBIt != F.end();) {
62  if (FlattenCFG(&*BBIt++, AA)) {
63  LocalChange = true;
64  }
65  }
66  Changed |= LocalChange;
67  }
68  return Changed;
69 }
70 
72  AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
73  bool EverChanged = false;
74  // iterativelyFlattenCFG can make some blocks dead.
75  while (iterativelyFlattenCFG(F, AA)) {
77  EverChanged = true;
78  }
79  return EverChanged;
80 }
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
iterator end()
Definition: Function.h:590
INITIALIZE_PASS_BEGIN(FlattenCFGPass, "flattencfg", "Flatten the CFG", false, false) INITIALIZE_PASS_END(FlattenCFGPass
F(f)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
iterator begin()
Definition: Function.h:588
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA=nullptr)
This function is used to flatten a CFG.
Definition: FlattenCFG.cpp:490
flattencfg
static bool runOnFunction(Function &F, bool PostInlining)
FunctionPass * createFlattenCFGPass()
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
static bool iterativelyFlattenCFG(Function &F, AliasAnalysis *AA)
iterativelyFlattenCFG - Call FlattenCFG on all the blocks in the function, iterating until no more ch...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
Iterator for intrusive lists based on ilist_node.
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr)
Remove all blocks that can not be reached from the function&#39;s entry.
Definition: Local.cpp:1730
Flatten the CFG
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
void initializeFlattenCFGPassPass(PassRegistry &)