Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 1 | //===-- StructurizeCFG.cpp ------------------------------------------------===// |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 9 | |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 10 | #include "llvm/Transforms/Scalar.h" |
Christian Konig | 90b4512 | 2013-03-26 10:24:20 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/MapVector.h" |
Benjamin Kramer | d78bb46 | 2013-05-23 17:10:37 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/SCCIterator.h" |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 13 | #include "llvm/Analysis/RegionInfo.h" |
Chandler Carruth | be81023 | 2013-01-02 10:22:59 +0000 | [diff] [blame] | 14 | #include "llvm/Analysis/RegionIterator.h" |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 15 | #include "llvm/Analysis/RegionPass.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 16 | #include "llvm/IR/Module.h" |
Chandler Carruth | 820a908 | 2014-03-04 11:08:18 +0000 | [diff] [blame] | 17 | #include "llvm/IR/PatternMatch.h" |
Benjamin Kramer | d78bb46 | 2013-05-23 17:10:37 +0000 | [diff] [blame] | 18 | #include "llvm/Transforms/Utils/SSAUpdater.h" |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace llvm; |
Christian Konig | d886099 | 2013-02-16 11:27:50 +0000 | [diff] [blame] | 21 | using namespace llvm::PatternMatch; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 22 | |
Chandler Carruth | 964daaa | 2014-04-22 02:55:47 +0000 | [diff] [blame] | 23 | #define DEBUG_TYPE "structurizecfg" |
| 24 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 25 | namespace { |
| 26 | |
| 27 | // Definition of the complex types used in this pass. |
| 28 | |
| 29 | typedef std::pair<BasicBlock *, Value *> BBValuePair; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 30 | |
| 31 | typedef SmallVector<RegionNode*, 8> RNVector; |
| 32 | typedef SmallVector<BasicBlock*, 8> BBVector; |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 33 | typedef SmallVector<BranchInst*, 8> BranchVector; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 34 | typedef SmallVector<BBValuePair, 2> BBValueVector; |
| 35 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 36 | typedef SmallPtrSet<BasicBlock *, 8> BBSet; |
| 37 | |
Christian Konig | 90b4512 | 2013-03-26 10:24:20 +0000 | [diff] [blame] | 38 | typedef MapVector<PHINode *, BBValueVector> PhiMap; |
| 39 | typedef MapVector<BasicBlock *, BBVector> BB2BBVecMap; |
| 40 | |
Christian Konig | d08e3d7 | 2013-02-16 11:27:29 +0000 | [diff] [blame] | 41 | typedef DenseMap<DomTreeNode *, unsigned> DTN2UnsignedMap; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 42 | typedef DenseMap<BasicBlock *, PhiMap> BBPhiMap; |
| 43 | typedef DenseMap<BasicBlock *, Value *> BBPredicates; |
| 44 | typedef DenseMap<BasicBlock *, BBPredicates> PredMap; |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 45 | typedef DenseMap<BasicBlock *, BasicBlock*> BB2BBMap; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 46 | |
| 47 | // The name for newly created blocks. |
| 48 | |
Craig Topper | d3a34f8 | 2013-07-16 01:17:10 +0000 | [diff] [blame] | 49 | static const char *const FlowBlockName = "Flow"; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 50 | |
Christian Konig | d08e3d7 | 2013-02-16 11:27:29 +0000 | [diff] [blame] | 51 | /// @brief Find the nearest common dominator for multiple BasicBlocks |
| 52 | /// |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 53 | /// Helper class for StructurizeCFG |
Christian Konig | d08e3d7 | 2013-02-16 11:27:29 +0000 | [diff] [blame] | 54 | /// TODO: Maybe move into common code |
| 55 | class NearestCommonDominator { |
Christian Konig | d08e3d7 | 2013-02-16 11:27:29 +0000 | [diff] [blame] | 56 | DominatorTree *DT; |
| 57 | |
| 58 | DTN2UnsignedMap IndexMap; |
| 59 | |
| 60 | BasicBlock *Result; |
| 61 | unsigned ResultIndex; |
| 62 | bool ExplicitMentioned; |
| 63 | |
| 64 | public: |
| 65 | /// \brief Start a new query |
| 66 | NearestCommonDominator(DominatorTree *DomTree) { |
| 67 | DT = DomTree; |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 68 | Result = nullptr; |
Christian Konig | d08e3d7 | 2013-02-16 11:27:29 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /// \brief Add BB to the resulting dominator |
| 72 | void addBlock(BasicBlock *BB, bool Remember = true) { |
Christian Konig | d08e3d7 | 2013-02-16 11:27:29 +0000 | [diff] [blame] | 73 | DomTreeNode *Node = DT->getNode(BB); |
| 74 | |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 75 | if (!Result) { |
Christian Konig | d08e3d7 | 2013-02-16 11:27:29 +0000 | [diff] [blame] | 76 | unsigned Numbering = 0; |
| 77 | for (;Node;Node = Node->getIDom()) |
| 78 | IndexMap[Node] = ++Numbering; |
| 79 | Result = BB; |
| 80 | ResultIndex = 1; |
| 81 | ExplicitMentioned = Remember; |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | for (;Node;Node = Node->getIDom()) |
| 86 | if (IndexMap.count(Node)) |
| 87 | break; |
| 88 | else |
| 89 | IndexMap[Node] = 0; |
| 90 | |
| 91 | assert(Node && "Dominator tree invalid!"); |
| 92 | |
| 93 | unsigned Numbering = IndexMap[Node]; |
| 94 | if (Numbering > ResultIndex) { |
| 95 | Result = Node->getBlock(); |
| 96 | ResultIndex = Numbering; |
| 97 | ExplicitMentioned = Remember && (Result == BB); |
| 98 | } else if (Numbering == ResultIndex) { |
| 99 | ExplicitMentioned |= Remember; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /// \brief Is "Result" one of the BBs added with "Remember" = True? |
| 104 | bool wasResultExplicitMentioned() { |
| 105 | return ExplicitMentioned; |
| 106 | } |
| 107 | |
| 108 | /// \brief Get the query result |
| 109 | BasicBlock *getResult() { |
| 110 | return Result; |
| 111 | } |
| 112 | }; |
| 113 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 114 | /// @brief Transforms the control flow graph on one single entry/exit region |
| 115 | /// at a time. |
| 116 | /// |
| 117 | /// After the transform all "If"/"Then"/"Else" style control flow looks like |
| 118 | /// this: |
| 119 | /// |
| 120 | /// \verbatim |
| 121 | /// 1 |
| 122 | /// || |
| 123 | /// | | |
| 124 | /// 2 | |
| 125 | /// | / |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 126 | /// |/ |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 127 | /// 3 |
| 128 | /// || Where: |
| 129 | /// | | 1 = "If" block, calculates the condition |
| 130 | /// 4 | 2 = "Then" subregion, runs if the condition is true |
| 131 | /// | / 3 = "Flow" blocks, newly inserted flow blocks, rejoins the flow |
| 132 | /// |/ 4 = "Else" optional subregion, runs if the condition is false |
| 133 | /// 5 5 = "End" block, also rejoins the control flow |
| 134 | /// \endverbatim |
| 135 | /// |
| 136 | /// Control flow is expressed as a branch where the true exit goes into the |
| 137 | /// "Then"/"Else" region, while the false exit skips the region |
| 138 | /// The condition for the optional "Else" region is expressed as a PHI node. |
| 139 | /// The incomming values of the PHI node are true for the "If" edge and false |
| 140 | /// for the "Then" edge. |
| 141 | /// |
| 142 | /// Additionally to that even complicated loops look like this: |
| 143 | /// |
| 144 | /// \verbatim |
| 145 | /// 1 |
| 146 | /// || |
| 147 | /// | | |
| 148 | /// 2 ^ Where: |
| 149 | /// | / 1 = "Entry" block |
| 150 | /// |/ 2 = "Loop" optional subregion, with all exits at "Flow" block |
| 151 | /// 3 3 = "Flow" block, with back edge to entry block |
| 152 | /// | |
| 153 | /// \endverbatim |
| 154 | /// |
| 155 | /// The back edge of the "Flow" block is always on the false side of the branch |
| 156 | /// while the true side continues the general flow. So the loop condition |
| 157 | /// consist of a network of PHI nodes where the true incoming values expresses |
| 158 | /// breaks and the false values expresses continue states. |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 159 | class StructurizeCFG : public RegionPass { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 160 | Type *Boolean; |
| 161 | ConstantInt *BoolTrue; |
| 162 | ConstantInt *BoolFalse; |
| 163 | UndefValue *BoolUndef; |
| 164 | |
| 165 | Function *Func; |
| 166 | Region *ParentRegion; |
| 167 | |
| 168 | DominatorTree *DT; |
| 169 | |
| 170 | RNVector Order; |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 171 | BBSet Visited; |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 172 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 173 | BBPhiMap DeletedPhis; |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 174 | BB2BBVecMap AddedPhis; |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 175 | |
| 176 | PredMap Predicates; |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 177 | BranchVector Conditions; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 178 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 179 | BB2BBMap Loops; |
| 180 | PredMap LoopPreds; |
| 181 | BranchVector LoopConds; |
| 182 | |
| 183 | RegionNode *PrevNode; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 184 | |
| 185 | void orderNodes(); |
| 186 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 187 | void analyzeLoops(RegionNode *N); |
| 188 | |
Christian Konig | d886099 | 2013-02-16 11:27:50 +0000 | [diff] [blame] | 189 | Value *invert(Value *Condition); |
| 190 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 191 | Value *buildCondition(BranchInst *Term, unsigned Idx, bool Invert); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 192 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 193 | void gatherPredicates(RegionNode *N); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 194 | |
| 195 | void collectInfos(); |
| 196 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 197 | void insertConditions(bool Loops); |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 198 | |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 199 | void delPhiValues(BasicBlock *From, BasicBlock *To); |
| 200 | |
| 201 | void addPhiValues(BasicBlock *From, BasicBlock *To); |
| 202 | |
| 203 | void setPhiValues(); |
| 204 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 205 | void killTerminator(BasicBlock *BB); |
| 206 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 207 | void changeExit(RegionNode *Node, BasicBlock *NewExit, |
| 208 | bool IncludeDominator); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 209 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 210 | BasicBlock *getNextFlow(BasicBlock *Dominator); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 211 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 212 | BasicBlock *needPrefix(bool NeedEmpty); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 213 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 214 | BasicBlock *needPostfix(BasicBlock *Flow, bool ExitUseAllowed); |
| 215 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 216 | void setPrevNode(BasicBlock *BB); |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 217 | |
| 218 | bool dominatesPredicates(BasicBlock *BB, RegionNode *Node); |
| 219 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 220 | bool isPredictableTrue(RegionNode *Node); |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 221 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 222 | void wireFlow(bool ExitUseAllowed, BasicBlock *LoopEnd); |
| 223 | |
| 224 | void handleLoops(bool ExitUseAllowed, BasicBlock *LoopEnd); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 225 | |
| 226 | void createFlow(); |
| 227 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 228 | void rebuildSSA(); |
| 229 | |
| 230 | public: |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 231 | static char ID; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 232 | |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 233 | StructurizeCFG() : |
| 234 | RegionPass(ID) { |
Tom Stellard | d3e916e | 2013-10-02 17:04:59 +0000 | [diff] [blame] | 235 | initializeStructurizeCFGPass(*PassRegistry::getPassRegistry()); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Christian Konig | 01fd1f6 | 2013-03-01 09:46:11 +0000 | [diff] [blame] | 238 | using Pass::doInitialization; |
Craig Topper | 3e4c697 | 2014-03-05 09:10:37 +0000 | [diff] [blame] | 239 | bool doInitialization(Region *R, RGPassManager &RGM) override; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 240 | |
Craig Topper | 3e4c697 | 2014-03-05 09:10:37 +0000 | [diff] [blame] | 241 | bool runOnRegion(Region *R, RGPassManager &RGM) override; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 242 | |
Craig Topper | 3e4c697 | 2014-03-05 09:10:37 +0000 | [diff] [blame] | 243 | const char *getPassName() const override { |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 244 | return "Structurize control flow"; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Craig Topper | 3e4c697 | 2014-03-05 09:10:37 +0000 | [diff] [blame] | 247 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
Tom Stellard | d3e916e | 2013-10-02 17:04:59 +0000 | [diff] [blame] | 248 | AU.addRequiredID(LowerSwitchID); |
Chandler Carruth | 7352302 | 2014-01-13 13:07:17 +0000 | [diff] [blame] | 249 | AU.addRequired<DominatorTreeWrapperPass>(); |
| 250 | AU.addPreserved<DominatorTreeWrapperPass>(); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 251 | RegionPass::getAnalysisUsage(AU); |
| 252 | } |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | } // end anonymous namespace |
| 256 | |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 257 | char StructurizeCFG::ID = 0; |
| 258 | |
| 259 | INITIALIZE_PASS_BEGIN(StructurizeCFG, "structurizecfg", "Structurize the CFG", |
| 260 | false, false) |
Tom Stellard | d3e916e | 2013-10-02 17:04:59 +0000 | [diff] [blame] | 261 | INITIALIZE_PASS_DEPENDENCY(LowerSwitch) |
Chandler Carruth | 7352302 | 2014-01-13 13:07:17 +0000 | [diff] [blame] | 262 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
Matt Arsenault | 1b8d837 | 2014-07-19 18:29:29 +0000 | [diff] [blame] | 263 | INITIALIZE_PASS_DEPENDENCY(RegionInfoPass) |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 264 | INITIALIZE_PASS_END(StructurizeCFG, "structurizecfg", "Structurize the CFG", |
| 265 | false, false) |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 266 | |
| 267 | /// \brief Initialize the types and constants used in the pass |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 268 | bool StructurizeCFG::doInitialization(Region *R, RGPassManager &RGM) { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 269 | LLVMContext &Context = R->getEntry()->getContext(); |
| 270 | |
| 271 | Boolean = Type::getInt1Ty(Context); |
| 272 | BoolTrue = ConstantInt::getTrue(Context); |
| 273 | BoolFalse = ConstantInt::getFalse(Context); |
| 274 | BoolUndef = UndefValue::get(Boolean); |
| 275 | |
| 276 | return false; |
| 277 | } |
| 278 | |
| 279 | /// \brief Build up the general order of nodes |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 280 | void StructurizeCFG::orderNodes() { |
Duncan P. N. Exon Smith | 8e661ef | 2014-02-04 19:19:07 +0000 | [diff] [blame] | 281 | scc_iterator<Region *> I = scc_begin(ParentRegion); |
| 282 | for (Order.clear(); !I.isAtEnd(); ++I) { |
Duncan P. N. Exon Smith | d2b2fac | 2014-04-25 18:24:50 +0000 | [diff] [blame] | 283 | const std::vector<RegionNode *> &Nodes = *I; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 284 | Order.append(Nodes.begin(), Nodes.end()); |
| 285 | } |
| 286 | } |
| 287 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 288 | /// \brief Determine the end of the loops |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 289 | void StructurizeCFG::analyzeLoops(RegionNode *N) { |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 290 | if (N->isSubRegion()) { |
| 291 | // Test for exit as back edge |
| 292 | BasicBlock *Exit = N->getNodeAs<Region>()->getExit(); |
| 293 | if (Visited.count(Exit)) |
| 294 | Loops[Exit] = N->getEntry(); |
| 295 | |
| 296 | } else { |
| 297 | // Test for sucessors as back edge |
| 298 | BasicBlock *BB = N->getNodeAs<BasicBlock>(); |
| 299 | BranchInst *Term = cast<BranchInst>(BB->getTerminator()); |
| 300 | |
| 301 | for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) { |
| 302 | BasicBlock *Succ = Term->getSuccessor(i); |
| 303 | |
| 304 | if (Visited.count(Succ)) |
| 305 | Loops[Succ] = BB; |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
Christian Konig | d886099 | 2013-02-16 11:27:50 +0000 | [diff] [blame] | 310 | /// \brief Invert the given condition |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 311 | Value *StructurizeCFG::invert(Value *Condition) { |
Christian Konig | d886099 | 2013-02-16 11:27:50 +0000 | [diff] [blame] | 312 | // First: Check if it's a constant |
| 313 | if (Condition == BoolTrue) |
| 314 | return BoolFalse; |
| 315 | |
| 316 | if (Condition == BoolFalse) |
| 317 | return BoolTrue; |
| 318 | |
| 319 | if (Condition == BoolUndef) |
| 320 | return BoolUndef; |
| 321 | |
| 322 | // Second: If the condition is already inverted, return the original value |
| 323 | if (match(Condition, m_Not(m_Value(Condition)))) |
| 324 | return Condition; |
| 325 | |
Matt Arsenault | 9fb6e0b | 2013-11-22 19:24:37 +0000 | [diff] [blame] | 326 | if (Instruction *Inst = dyn_cast<Instruction>(Condition)) { |
| 327 | // Third: Check all the users for an invert |
| 328 | BasicBlock *Parent = Inst->getParent(); |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 329 | for (User *U : Condition->users()) |
| 330 | if (Instruction *I = dyn_cast<Instruction>(U)) |
| 331 | if (I->getParent() == Parent && match(I, m_Not(m_Specific(Condition)))) |
| 332 | return I; |
Matt Arsenault | 9fb6e0b | 2013-11-22 19:24:37 +0000 | [diff] [blame] | 333 | |
| 334 | // Last option: Create a new instruction |
| 335 | return BinaryOperator::CreateNot(Condition, "", Parent->getTerminator()); |
Christian Konig | d886099 | 2013-02-16 11:27:50 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Matt Arsenault | 9fb6e0b | 2013-11-22 19:24:37 +0000 | [diff] [blame] | 338 | if (Argument *Arg = dyn_cast<Argument>(Condition)) { |
| 339 | BasicBlock &EntryBlock = Arg->getParent()->getEntryBlock(); |
| 340 | return BinaryOperator::CreateNot(Condition, |
| 341 | Arg->getName() + ".inv", |
| 342 | EntryBlock.getTerminator()); |
| 343 | } |
| 344 | |
| 345 | llvm_unreachable("Unhandled condition to invert"); |
Christian Konig | d886099 | 2013-02-16 11:27:50 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 348 | /// \brief Build the condition for one edge |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 349 | Value *StructurizeCFG::buildCondition(BranchInst *Term, unsigned Idx, |
| 350 | bool Invert) { |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 351 | Value *Cond = Invert ? BoolFalse : BoolTrue; |
| 352 | if (Term->isConditional()) { |
| 353 | Cond = Term->getCondition(); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 354 | |
Aaron Ballman | 1997855 | 2013-06-04 01:03:03 +0000 | [diff] [blame] | 355 | if (Idx != (unsigned)Invert) |
Christian Konig | d886099 | 2013-02-16 11:27:50 +0000 | [diff] [blame] | 356 | Cond = invert(Cond); |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 357 | } |
| 358 | return Cond; |
| 359 | } |
| 360 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 361 | /// \brief Analyze the predecessors of each block and build up predicates |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 362 | void StructurizeCFG::gatherPredicates(RegionNode *N) { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 363 | RegionInfo *RI = ParentRegion->getRegionInfo(); |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 364 | BasicBlock *BB = N->getEntry(); |
| 365 | BBPredicates &Pred = Predicates[BB]; |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 366 | BBPredicates &LPred = LoopPreds[BB]; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 367 | |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 368 | for (BasicBlock *Predecessor : predecessors(BB)) { |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 369 | // Ignore it if it's a branch from outside into our region entry |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 370 | if (!ParentRegion->contains(Predecessor)) |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 371 | continue; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 372 | |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 373 | Region *R = RI->getRegionFor(Predecessor); |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 374 | if (R == ParentRegion) { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 375 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 376 | // It's a top level block in our region |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 377 | BranchInst *Term = cast<BranchInst>(Predecessor->getTerminator()); |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 378 | for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) { |
| 379 | BasicBlock *Succ = Term->getSuccessor(i); |
| 380 | if (Succ != BB) |
| 381 | continue; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 382 | |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 383 | if (Visited.count(Predecessor)) { |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 384 | // Normal forward edge |
| 385 | if (Term->isConditional()) { |
| 386 | // Try to treat it like an ELSE block |
| 387 | BasicBlock *Other = Term->getSuccessor(!i); |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 388 | if (Visited.count(Other) && !Loops.count(Other) && |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 389 | !Pred.count(Other) && !Pred.count(Predecessor)) { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 390 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 391 | Pred[Other] = BoolFalse; |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 392 | Pred[Predecessor] = BoolTrue; |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 393 | continue; |
| 394 | } |
| 395 | } |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 396 | Pred[Predecessor] = buildCondition(Term, i, false); |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 397 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 398 | } else { |
| 399 | // Back edge |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 400 | LPred[Predecessor] = buildCondition(Term, i, true); |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 401 | } |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | } else { |
| 405 | |
| 406 | // It's an exit from a sub region |
Matt Arsenault | 1b8d837 | 2014-07-19 18:29:29 +0000 | [diff] [blame] | 407 | while (R->getParent() != ParentRegion) |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 408 | R = R->getParent(); |
| 409 | |
| 410 | // Edge from inside a subregion to its entry, ignore it |
Matt Arsenault | 1b8d837 | 2014-07-19 18:29:29 +0000 | [diff] [blame] | 411 | if (*R == *N) |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 412 | continue; |
| 413 | |
| 414 | BasicBlock *Entry = R->getEntry(); |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 415 | if (Visited.count(Entry)) |
| 416 | Pred[Entry] = BoolTrue; |
| 417 | else |
| 418 | LPred[Entry] = BoolFalse; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | /// \brief Collect various loop and predicate infos |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 424 | void StructurizeCFG::collectInfos() { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 425 | // Reset predicate |
| 426 | Predicates.clear(); |
| 427 | |
| 428 | // and loop infos |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 429 | Loops.clear(); |
| 430 | LoopPreds.clear(); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 431 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 432 | // Reset the visited nodes |
| 433 | Visited.clear(); |
| 434 | |
| 435 | for (RNVector::reverse_iterator OI = Order.rbegin(), OE = Order.rend(); |
| 436 | OI != OE; ++OI) { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 437 | |
| 438 | // Analyze all the conditions leading to a node |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 439 | gatherPredicates(*OI); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 440 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 441 | // Remember that we've seen this node |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 442 | Visited.insert((*OI)->getEntry()); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 443 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 444 | // Find the last back edges |
| 445 | analyzeLoops(*OI); |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 446 | } |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /// \brief Insert the missing branch conditions |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 450 | void StructurizeCFG::insertConditions(bool Loops) { |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 451 | BranchVector &Conds = Loops ? LoopConds : Conditions; |
| 452 | Value *Default = Loops ? BoolTrue : BoolFalse; |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 453 | SSAUpdater PhiInserter; |
| 454 | |
Matt Arsenault | 04b67ce | 2014-05-19 17:52:48 +0000 | [diff] [blame] | 455 | for (BranchInst *Term : Conds) { |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 456 | assert(Term->isConditional()); |
| 457 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 458 | BasicBlock *Parent = Term->getParent(); |
| 459 | BasicBlock *SuccTrue = Term->getSuccessor(0); |
| 460 | BasicBlock *SuccFalse = Term->getSuccessor(1); |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 461 | |
Christian Konig | b5d8866 | 2013-02-16 11:27:40 +0000 | [diff] [blame] | 462 | PhiInserter.Initialize(Boolean, ""); |
| 463 | PhiInserter.AddAvailableValue(&Func->getEntryBlock(), Default); |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 464 | PhiInserter.AddAvailableValue(Loops ? SuccFalse : Parent, Default); |
Christian Konig | b5d8866 | 2013-02-16 11:27:40 +0000 | [diff] [blame] | 465 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 466 | BBPredicates &Preds = Loops ? LoopPreds[SuccFalse] : Predicates[SuccTrue]; |
Christian Konig | b5d8866 | 2013-02-16 11:27:40 +0000 | [diff] [blame] | 467 | |
| 468 | NearestCommonDominator Dominator(DT); |
| 469 | Dominator.addBlock(Parent, false); |
| 470 | |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 471 | Value *ParentValue = nullptr; |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 472 | for (BBPredicates::iterator PI = Preds.begin(), PE = Preds.end(); |
| 473 | PI != PE; ++PI) { |
| 474 | |
Christian Konig | b5d8866 | 2013-02-16 11:27:40 +0000 | [diff] [blame] | 475 | if (PI->first == Parent) { |
| 476 | ParentValue = PI->second; |
| 477 | break; |
| 478 | } |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 479 | PhiInserter.AddAvailableValue(PI->first, PI->second); |
Christian Konig | b5d8866 | 2013-02-16 11:27:40 +0000 | [diff] [blame] | 480 | Dominator.addBlock(PI->first); |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Christian Konig | b5d8866 | 2013-02-16 11:27:40 +0000 | [diff] [blame] | 483 | if (ParentValue) { |
| 484 | Term->setCondition(ParentValue); |
| 485 | } else { |
| 486 | if (!Dominator.wasResultExplicitMentioned()) |
| 487 | PhiInserter.AddAvailableValue(Dominator.getResult(), Default); |
| 488 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 489 | Term->setCondition(PhiInserter.GetValueInMiddleOfBlock(Parent)); |
Christian Konig | b5d8866 | 2013-02-16 11:27:40 +0000 | [diff] [blame] | 490 | } |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 494 | /// \brief Remove all PHI values coming from "From" into "To" and remember |
| 495 | /// them in DeletedPhis |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 496 | void StructurizeCFG::delPhiValues(BasicBlock *From, BasicBlock *To) { |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 497 | PhiMap &Map = DeletedPhis[To]; |
| 498 | for (BasicBlock::iterator I = To->begin(), E = To->end(); |
| 499 | I != E && isa<PHINode>(*I);) { |
| 500 | |
| 501 | PHINode &Phi = cast<PHINode>(*I++); |
| 502 | while (Phi.getBasicBlockIndex(From) != -1) { |
| 503 | Value *Deleted = Phi.removeIncomingValue(From, false); |
| 504 | Map[&Phi].push_back(std::make_pair(From, Deleted)); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | /// \brief Add a dummy PHI value as soon as we knew the new predecessor |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 510 | void StructurizeCFG::addPhiValues(BasicBlock *From, BasicBlock *To) { |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 511 | for (BasicBlock::iterator I = To->begin(), E = To->end(); |
| 512 | I != E && isa<PHINode>(*I);) { |
| 513 | |
| 514 | PHINode &Phi = cast<PHINode>(*I++); |
| 515 | Value *Undef = UndefValue::get(Phi.getType()); |
| 516 | Phi.addIncoming(Undef, From); |
| 517 | } |
| 518 | AddedPhis[To].push_back(From); |
| 519 | } |
| 520 | |
| 521 | /// \brief Add the real PHI value as soon as everything is set up |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 522 | void StructurizeCFG::setPhiValues() { |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 523 | SSAUpdater Updater; |
| 524 | for (BB2BBVecMap::iterator AI = AddedPhis.begin(), AE = AddedPhis.end(); |
| 525 | AI != AE; ++AI) { |
| 526 | |
| 527 | BasicBlock *To = AI->first; |
| 528 | BBVector &From = AI->second; |
| 529 | |
| 530 | if (!DeletedPhis.count(To)) |
| 531 | continue; |
| 532 | |
| 533 | PhiMap &Map = DeletedPhis[To]; |
| 534 | for (PhiMap::iterator PI = Map.begin(), PE = Map.end(); |
| 535 | PI != PE; ++PI) { |
| 536 | |
| 537 | PHINode *Phi = PI->first; |
| 538 | Value *Undef = UndefValue::get(Phi->getType()); |
| 539 | Updater.Initialize(Phi->getType(), ""); |
| 540 | Updater.AddAvailableValue(&Func->getEntryBlock(), Undef); |
| 541 | Updater.AddAvailableValue(To, Undef); |
| 542 | |
Christian Konig | 0bccf9d | 2013-02-16 11:27:35 +0000 | [diff] [blame] | 543 | NearestCommonDominator Dominator(DT); |
| 544 | Dominator.addBlock(To, false); |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 545 | for (BBValueVector::iterator VI = PI->second.begin(), |
| 546 | VE = PI->second.end(); VI != VE; ++VI) { |
| 547 | |
| 548 | Updater.AddAvailableValue(VI->first, VI->second); |
Christian Konig | 0bccf9d | 2013-02-16 11:27:35 +0000 | [diff] [blame] | 549 | Dominator.addBlock(VI->first); |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Christian Konig | 0bccf9d | 2013-02-16 11:27:35 +0000 | [diff] [blame] | 552 | if (!Dominator.wasResultExplicitMentioned()) |
| 553 | Updater.AddAvailableValue(Dominator.getResult(), Undef); |
| 554 | |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 555 | for (BBVector::iterator FI = From.begin(), FE = From.end(); |
| 556 | FI != FE; ++FI) { |
| 557 | |
| 558 | int Idx = Phi->getBasicBlockIndex(*FI); |
| 559 | assert(Idx != -1); |
| 560 | Phi->setIncomingValue(Idx, Updater.GetValueAtEndOfBlock(*FI)); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | DeletedPhis.erase(To); |
| 565 | } |
| 566 | assert(DeletedPhis.empty()); |
| 567 | } |
| 568 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 569 | /// \brief Remove phi values from all successors and then remove the terminator. |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 570 | void StructurizeCFG::killTerminator(BasicBlock *BB) { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 571 | TerminatorInst *Term = BB->getTerminator(); |
| 572 | if (!Term) |
| 573 | return; |
| 574 | |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 575 | for (BasicBlock *Succ : successors(BB)) |
| 576 | delPhiValues(BB, Succ); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 577 | |
| 578 | Term->eraseFromParent(); |
| 579 | } |
| 580 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 581 | /// \brief Let node exit(s) point to NewExit |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 582 | void StructurizeCFG::changeExit(RegionNode *Node, BasicBlock *NewExit, |
| 583 | bool IncludeDominator) { |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 584 | if (Node->isSubRegion()) { |
| 585 | Region *SubRegion = Node->getNodeAs<Region>(); |
| 586 | BasicBlock *OldExit = SubRegion->getExit(); |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 587 | BasicBlock *Dominator = nullptr; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 588 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 589 | // Find all the edges from the sub region to the exit |
Manuel Jacob | d11beff | 2014-07-20 09:10:11 +0000 | [diff] [blame] | 590 | for (BasicBlock *BB : predecessors(OldExit)) { |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 591 | if (!SubRegion->contains(BB)) |
| 592 | continue; |
| 593 | |
| 594 | // Modify the edges to point to the new exit |
| 595 | delPhiValues(BB, OldExit); |
| 596 | BB->getTerminator()->replaceUsesOfWith(OldExit, NewExit); |
| 597 | addPhiValues(BB, NewExit); |
| 598 | |
| 599 | // Find the new dominator (if requested) |
| 600 | if (IncludeDominator) { |
| 601 | if (!Dominator) |
| 602 | Dominator = BB; |
| 603 | else |
| 604 | Dominator = DT->findNearestCommonDominator(Dominator, BB); |
| 605 | } |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 608 | // Change the dominator (if requested) |
| 609 | if (Dominator) |
| 610 | DT->changeImmediateDominator(NewExit, Dominator); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 611 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 612 | // Update the region info |
| 613 | SubRegion->replaceExit(NewExit); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 614 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 615 | } else { |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 616 | BasicBlock *BB = Node->getNodeAs<BasicBlock>(); |
| 617 | killTerminator(BB); |
| 618 | BranchInst::Create(NewExit, BB); |
| 619 | addPhiValues(BB, NewExit); |
| 620 | if (IncludeDominator) |
| 621 | DT->changeImmediateDominator(NewExit, BB); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 622 | } |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 625 | /// \brief Create a new flow node and update dominator tree and region info |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 626 | BasicBlock *StructurizeCFG::getNextFlow(BasicBlock *Dominator) { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 627 | LLVMContext &Context = Func->getContext(); |
| 628 | BasicBlock *Insert = Order.empty() ? ParentRegion->getExit() : |
| 629 | Order.back()->getEntry(); |
| 630 | BasicBlock *Flow = BasicBlock::Create(Context, FlowBlockName, |
| 631 | Func, Insert); |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 632 | DT->addNewBlock(Flow, Dominator); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 633 | ParentRegion->getRegionInfo()->setRegionFor(Flow, ParentRegion); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 634 | return Flow; |
| 635 | } |
| 636 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 637 | /// \brief Create a new or reuse the previous node as flow node |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 638 | BasicBlock *StructurizeCFG::needPrefix(bool NeedEmpty) { |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 639 | BasicBlock *Entry = PrevNode->getEntry(); |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 640 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 641 | if (!PrevNode->isSubRegion()) { |
| 642 | killTerminator(Entry); |
| 643 | if (!NeedEmpty || Entry->getFirstInsertionPt() == Entry->end()) |
| 644 | return Entry; |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 645 | |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 646 | } |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 647 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 648 | // create a new flow node |
| 649 | BasicBlock *Flow = getNextFlow(Entry); |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 650 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 651 | // and wire it up |
| 652 | changeExit(PrevNode, Flow, true); |
| 653 | PrevNode = ParentRegion->getBBNode(Flow); |
| 654 | return Flow; |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | /// \brief Returns the region exit if possible, otherwise just a new flow node |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 658 | BasicBlock *StructurizeCFG::needPostfix(BasicBlock *Flow, |
| 659 | bool ExitUseAllowed) { |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 660 | if (Order.empty() && ExitUseAllowed) { |
| 661 | BasicBlock *Exit = ParentRegion->getExit(); |
| 662 | DT->changeImmediateDominator(Exit, Flow); |
| 663 | addPhiValues(Flow, Exit); |
| 664 | return Exit; |
| 665 | } |
| 666 | return getNextFlow(Flow); |
| 667 | } |
| 668 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 669 | /// \brief Set the previous node |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 670 | void StructurizeCFG::setPrevNode(BasicBlock *BB) { |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 671 | PrevNode = ParentRegion->contains(BB) ? ParentRegion->getBBNode(BB) |
| 672 | : nullptr; |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /// \brief Does BB dominate all the predicates of Node ? |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 676 | bool StructurizeCFG::dominatesPredicates(BasicBlock *BB, RegionNode *Node) { |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 677 | BBPredicates &Preds = Predicates[Node->getEntry()]; |
| 678 | for (BBPredicates::iterator PI = Preds.begin(), PE = Preds.end(); |
| 679 | PI != PE; ++PI) { |
| 680 | |
| 681 | if (!DT->dominates(BB, PI->first)) |
| 682 | return false; |
| 683 | } |
| 684 | return true; |
| 685 | } |
| 686 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 687 | /// \brief Can we predict that this node will always be called? |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 688 | bool StructurizeCFG::isPredictableTrue(RegionNode *Node) { |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 689 | BBPredicates &Preds = Predicates[Node->getEntry()]; |
| 690 | bool Dominated = false; |
| 691 | |
| 692 | // Regionentry is always true |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 693 | if (!PrevNode) |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 694 | return true; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 695 | |
| 696 | for (BBPredicates::iterator I = Preds.begin(), E = Preds.end(); |
| 697 | I != E; ++I) { |
| 698 | |
| 699 | if (I->second != BoolTrue) |
| 700 | return false; |
| 701 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 702 | if (!Dominated && DT->dominates(I->first, PrevNode->getEntry())) |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 703 | Dominated = true; |
| 704 | } |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 705 | |
| 706 | // TODO: The dominator check is too strict |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 707 | return Dominated; |
| 708 | } |
| 709 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 710 | /// Take one node from the order vector and wire it up |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 711 | void StructurizeCFG::wireFlow(bool ExitUseAllowed, |
| 712 | BasicBlock *LoopEnd) { |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 713 | RegionNode *Node = Order.pop_back_val(); |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 714 | Visited.insert(Node->getEntry()); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 715 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 716 | if (isPredictableTrue(Node)) { |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 717 | // Just a linear flow |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 718 | if (PrevNode) { |
| 719 | changeExit(PrevNode, Node->getEntry(), true); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 720 | } |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 721 | PrevNode = Node; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 722 | |
| 723 | } else { |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 724 | // Insert extra prefix node (or reuse last one) |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 725 | BasicBlock *Flow = needPrefix(false); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 726 | |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 727 | // Insert extra postfix node (or use exit instead) |
| 728 | BasicBlock *Entry = Node->getEntry(); |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 729 | BasicBlock *Next = needPostfix(Flow, ExitUseAllowed); |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 730 | |
| 731 | // let it point to entry and next block |
| 732 | Conditions.push_back(BranchInst::Create(Entry, Next, BoolUndef, Flow)); |
| 733 | addPhiValues(Flow, Entry); |
| 734 | DT->changeImmediateDominator(Entry, Flow); |
| 735 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 736 | PrevNode = Node; |
| 737 | while (!Order.empty() && !Visited.count(LoopEnd) && |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 738 | dominatesPredicates(Entry, Order.back())) { |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 739 | handleLoops(false, LoopEnd); |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 742 | changeExit(PrevNode, Next, false); |
| 743 | setPrevNode(Next); |
| 744 | } |
| 745 | } |
| 746 | |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 747 | void StructurizeCFG::handleLoops(bool ExitUseAllowed, |
| 748 | BasicBlock *LoopEnd) { |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 749 | RegionNode *Node = Order.back(); |
| 750 | BasicBlock *LoopStart = Node->getEntry(); |
| 751 | |
| 752 | if (!Loops.count(LoopStart)) { |
| 753 | wireFlow(ExitUseAllowed, LoopEnd); |
| 754 | return; |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 757 | if (!isPredictableTrue(Node)) |
| 758 | LoopStart = needPrefix(true); |
| 759 | |
| 760 | LoopEnd = Loops[Node->getEntry()]; |
| 761 | wireFlow(false, LoopEnd); |
| 762 | while (!Visited.count(LoopEnd)) { |
| 763 | handleLoops(false, LoopEnd); |
| 764 | } |
| 765 | |
Matt Arsenault | 6ea0aad | 2013-11-22 19:24:39 +0000 | [diff] [blame] | 766 | // If the start of the loop is the entry block, we can't branch to it so |
| 767 | // insert a new dummy entry block. |
| 768 | Function *LoopFunc = LoopStart->getParent(); |
| 769 | if (LoopStart == &LoopFunc->getEntryBlock()) { |
| 770 | LoopStart->setName("entry.orig"); |
| 771 | |
| 772 | BasicBlock *NewEntry = |
| 773 | BasicBlock::Create(LoopStart->getContext(), |
| 774 | "entry", |
| 775 | LoopFunc, |
| 776 | LoopStart); |
| 777 | BranchInst::Create(LoopStart, NewEntry); |
| 778 | } |
| 779 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 780 | // Create an extra loop end node |
| 781 | LoopEnd = needPrefix(false); |
| 782 | BasicBlock *Next = needPostfix(LoopEnd, ExitUseAllowed); |
| 783 | LoopConds.push_back(BranchInst::Create(Next, LoopStart, |
| 784 | BoolUndef, LoopEnd)); |
| 785 | addPhiValues(LoopEnd, LoopStart); |
| 786 | setPrevNode(Next); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 789 | /// After this function control flow looks like it should be, but |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 790 | /// branches and PHI nodes only have undefined conditions. |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 791 | void StructurizeCFG::createFlow() { |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 792 | BasicBlock *Exit = ParentRegion->getExit(); |
| 793 | bool EntryDominatesExit = DT->dominates(ParentRegion->getEntry(), Exit); |
| 794 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 795 | DeletedPhis.clear(); |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 796 | AddedPhis.clear(); |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 797 | Conditions.clear(); |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 798 | LoopConds.clear(); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 799 | |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 800 | PrevNode = nullptr; |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 801 | Visited.clear(); |
| 802 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 803 | while (!Order.empty()) { |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 804 | handleLoops(EntryDominatesExit, nullptr); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 807 | if (PrevNode) |
| 808 | changeExit(PrevNode, Exit, EntryDominatesExit); |
Tom Stellard | 7370ede | 2013-02-08 22:24:38 +0000 | [diff] [blame] | 809 | else |
| 810 | assert(EntryDominatesExit); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 813 | /// Handle a rare case where the disintegrated nodes instructions |
| 814 | /// no longer dominate all their uses. Not sure if this is really nessasary |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 815 | void StructurizeCFG::rebuildSSA() { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 816 | SSAUpdater Updater; |
Tobias Grosser | 4abf9d3 | 2014-03-03 13:00:39 +0000 | [diff] [blame] | 817 | for (const auto &BB : ParentRegion->blocks()) |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 818 | for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); |
| 819 | II != IE; ++II) { |
| 820 | |
| 821 | bool Initialized = false; |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 822 | for (auto I = II->use_begin(), E = II->use_end(); I != E;) { |
| 823 | Use &U = *I++; |
| 824 | Instruction *User = cast<Instruction>(U.getUser()); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 825 | if (User->getParent() == BB) { |
| 826 | continue; |
| 827 | |
| 828 | } else if (PHINode *UserPN = dyn_cast<PHINode>(User)) { |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 829 | if (UserPN->getIncomingBlock(U) == BB) |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 830 | continue; |
| 831 | } |
| 832 | |
| 833 | if (DT->dominates(II, User)) |
| 834 | continue; |
| 835 | |
| 836 | if (!Initialized) { |
| 837 | Value *Undef = UndefValue::get(II->getType()); |
| 838 | Updater.Initialize(II->getType(), ""); |
| 839 | Updater.AddAvailableValue(&Func->getEntryBlock(), Undef); |
| 840 | Updater.AddAvailableValue(BB, II); |
| 841 | Initialized = true; |
| 842 | } |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 843 | Updater.RewriteUseAfterInsertions(U); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 844 | } |
| 845 | } |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /// \brief Run the transformation for each region found |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 849 | bool StructurizeCFG::runOnRegion(Region *R, RGPassManager &RGM) { |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 850 | if (R->isTopLevelRegion()) |
| 851 | return false; |
| 852 | |
| 853 | Func = R->getEntry()->getParent(); |
| 854 | ParentRegion = R; |
| 855 | |
Chandler Carruth | 7352302 | 2014-01-13 13:07:17 +0000 | [diff] [blame] | 856 | DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 857 | |
| 858 | orderNodes(); |
| 859 | collectInfos(); |
| 860 | createFlow(); |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 861 | insertConditions(false); |
| 862 | insertConditions(true); |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 863 | setPhiValues(); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 864 | rebuildSSA(); |
| 865 | |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 866 | // Cleanup |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 867 | Order.clear(); |
| 868 | Visited.clear(); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 869 | DeletedPhis.clear(); |
Tom Stellard | 7ec0e4f | 2013-02-08 22:24:35 +0000 | [diff] [blame] | 870 | AddedPhis.clear(); |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 871 | Predicates.clear(); |
Tom Stellard | 048f14f | 2013-02-08 22:24:37 +0000 | [diff] [blame] | 872 | Conditions.clear(); |
Christian Konig | fc6a985 | 2013-02-16 11:27:45 +0000 | [diff] [blame] | 873 | Loops.clear(); |
| 874 | LoopPreds.clear(); |
| 875 | LoopConds.clear(); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 876 | |
| 877 | return true; |
| 878 | } |
| 879 | |
| 880 | /// \brief Create the pass |
Matt Arsenault | d46fce1 | 2013-06-19 20:18:24 +0000 | [diff] [blame] | 881 | Pass *llvm::createStructurizeCFGPass() { |
| 882 | return new StructurizeCFG(); |
Tom Stellard | f879435 | 2012-12-19 22:10:31 +0000 | [diff] [blame] | 883 | } |