1 //===-- StructurizeCFG.cpp ------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #define DEBUG_TYPE "structurizecfg"
11 #include "llvm/Transforms/Scalar.h"
12 #include "llvm/ADT/MapVector.h"
13 #include "llvm/ADT/SCCIterator.h"
14 #include "llvm/Analysis/RegionInfo.h"
15 #include "llvm/Analysis/RegionIterator.h"
16 #include "llvm/Analysis/RegionPass.h"
17 #include "llvm/IR/Module.h"
18 #include "llvm/Support/PatternMatch.h"
19 #include "llvm/Transforms/Utils/SSAUpdater.h"
22 using namespace llvm::PatternMatch;
26 // Definition of the complex types used in this pass.
28 typedef std::pair<BasicBlock *, Value *> BBValuePair;
30 typedef SmallVector<RegionNode*, 8> RNVector;
31 typedef SmallVector<BasicBlock*, 8> BBVector;
32 typedef SmallVector<BranchInst*, 8> BranchVector;
33 typedef SmallVector<BBValuePair, 2> BBValueVector;
35 typedef SmallPtrSet<BasicBlock *, 8> BBSet;
37 typedef MapVector<PHINode *, BBValueVector> PhiMap;
38 typedef MapVector<BasicBlock *, BBVector> BB2BBVecMap;
40 typedef DenseMap<DomTreeNode *, unsigned> DTN2UnsignedMap;
41 typedef DenseMap<BasicBlock *, PhiMap> BBPhiMap;
42 typedef DenseMap<BasicBlock *, Value *> BBPredicates;
43 typedef DenseMap<BasicBlock *, BBPredicates> PredMap;
44 typedef DenseMap<BasicBlock *, BasicBlock*> BB2BBMap;
46 // The name for newly created blocks.
48 static const char *const FlowBlockName = "Flow";
50 /// @brief Find the nearest common dominator for multiple BasicBlocks
52 /// Helper class for StructurizeCFG
53 /// TODO: Maybe move into common code
54 class NearestCommonDominator {
57 DTN2UnsignedMap IndexMap;
61 bool ExplicitMentioned;
64 /// \brief Start a new query
65 NearestCommonDominator(DominatorTree *DomTree) {
70 /// \brief Add BB to the resulting dominator
71 void addBlock(BasicBlock *BB, bool Remember = true) {
72 DomTreeNode *Node = DT->getNode(BB);
75 unsigned Numbering = 0;
76 for (;Node;Node = Node->getIDom())
77 IndexMap[Node] = ++Numbering;
80 ExplicitMentioned = Remember;
84 for (;Node;Node = Node->getIDom())
85 if (IndexMap.count(Node))
90 assert(Node && "Dominator tree invalid!");
92 unsigned Numbering = IndexMap[Node];
93 if (Numbering > ResultIndex) {
94 Result = Node->getBlock();
95 ResultIndex = Numbering;
96 ExplicitMentioned = Remember && (Result == BB);
97 } else if (Numbering == ResultIndex) {
98 ExplicitMentioned |= Remember;
102 /// \brief Is "Result" one of the BBs added with "Remember" = True?
103 bool wasResultExplicitMentioned() {
104 return ExplicitMentioned;
107 /// \brief Get the query result
108 BasicBlock *getResult() {
113 /// @brief Transforms the control flow graph on one single entry/exit region
116 /// After the transform all "If"/"Then"/"Else" style control flow looks like
128 /// | | 1 = "If" block, calculates the condition
129 /// 4 | 2 = "Then" subregion, runs if the condition is true
130 /// | / 3 = "Flow" blocks, newly inserted flow blocks, rejoins the flow
131 /// |/ 4 = "Else" optional subregion, runs if the condition is false
132 /// 5 5 = "End" block, also rejoins the control flow
135 /// Control flow is expressed as a branch where the true exit goes into the
136 /// "Then"/"Else" region, while the false exit skips the region
137 /// The condition for the optional "Else" region is expressed as a PHI node.
138 /// The incomming values of the PHI node are true for the "If" edge and false
139 /// for the "Then" edge.
141 /// Additionally to that even complicated loops look like this:
148 /// | / 1 = "Entry" block
149 /// |/ 2 = "Loop" optional subregion, with all exits at "Flow" block
150 /// 3 3 = "Flow" block, with back edge to entry block
154 /// The back edge of the "Flow" block is always on the false side of the branch
155 /// while the true side continues the general flow. So the loop condition
156 /// consist of a network of PHI nodes where the true incoming values expresses
157 /// breaks and the false values expresses continue states.
158 class StructurizeCFG : public RegionPass {
160 ConstantInt *BoolTrue;
161 ConstantInt *BoolFalse;
162 UndefValue *BoolUndef;
165 Region *ParentRegion;
172 BBPhiMap DeletedPhis;
173 BB2BBVecMap AddedPhis;
176 BranchVector Conditions;
180 BranchVector LoopConds;
182 RegionNode *PrevNode;
186 void analyzeLoops(RegionNode *N);
188 Value *invert(Value *Condition);
190 Value *buildCondition(BranchInst *Term, unsigned Idx, bool Invert);
192 void gatherPredicates(RegionNode *N);
196 void insertConditions(bool Loops);
198 void delPhiValues(BasicBlock *From, BasicBlock *To);
200 void addPhiValues(BasicBlock *From, BasicBlock *To);
204 void killTerminator(BasicBlock *BB);
206 void changeExit(RegionNode *Node, BasicBlock *NewExit,
207 bool IncludeDominator);
209 BasicBlock *getNextFlow(BasicBlock *Dominator);
211 BasicBlock *needPrefix(bool NeedEmpty);
213 BasicBlock *needPostfix(BasicBlock *Flow, bool ExitUseAllowed);
215 void setPrevNode(BasicBlock *BB);
217 bool dominatesPredicates(BasicBlock *BB, RegionNode *Node);
219 bool isPredictableTrue(RegionNode *Node);
221 void wireFlow(bool ExitUseAllowed, BasicBlock *LoopEnd);
223 void handleLoops(bool ExitUseAllowed, BasicBlock *LoopEnd);
234 initializeStructurizeCFGPass(*PassRegistry::getPassRegistry());
237 using Pass::doInitialization;
238 virtual bool doInitialization(Region *R, RGPassManager &RGM);
240 virtual bool runOnRegion(Region *R, RGPassManager &RGM);
242 virtual const char *getPassName() const {
243 return "Structurize control flow";
246 void getAnalysisUsage(AnalysisUsage &AU) const {
247 AU.addRequiredID(LowerSwitchID);
248 AU.addRequired<DominatorTree>();
249 AU.addPreserved<DominatorTree>();
250 RegionPass::getAnalysisUsage(AU);
254 } // end anonymous namespace
256 char StructurizeCFG::ID = 0;
258 INITIALIZE_PASS_BEGIN(StructurizeCFG, "structurizecfg", "Structurize the CFG",
260 INITIALIZE_PASS_DEPENDENCY(LowerSwitch)
261 INITIALIZE_PASS_DEPENDENCY(DominatorTree)
262 INITIALIZE_PASS_DEPENDENCY(RegionInfo)
263 INITIALIZE_PASS_END(StructurizeCFG, "structurizecfg", "Structurize the CFG",
266 /// \brief Initialize the types and constants used in the pass
267 bool StructurizeCFG::doInitialization(Region *R, RGPassManager &RGM) {
268 LLVMContext &Context = R->getEntry()->getContext();
270 Boolean = Type::getInt1Ty(Context);
271 BoolTrue = ConstantInt::getTrue(Context);
272 BoolFalse = ConstantInt::getFalse(Context);
273 BoolUndef = UndefValue::get(Boolean);
278 /// \brief Build up the general order of nodes
279 void StructurizeCFG::orderNodes() {
280 scc_iterator<Region *> I = scc_begin(ParentRegion),
281 E = scc_end(ParentRegion);
282 for (Order.clear(); I != E; ++I) {
283 std::vector<RegionNode *> &Nodes = *I;
284 Order.append(Nodes.begin(), Nodes.end());
288 /// \brief Determine the end of the loops
289 void StructurizeCFG::analyzeLoops(RegionNode *N) {
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();
297 // Test for sucessors as back edge
298 BasicBlock *BB = N->getNodeAs<BasicBlock>();
299 BranchInst *Term = cast<BranchInst>(BB->getTerminator());
301 for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) {
302 BasicBlock *Succ = Term->getSuccessor(i);
304 if (Visited.count(Succ))
310 /// \brief Invert the given condition
311 Value *StructurizeCFG::invert(Value *Condition) {
312 // First: Check if it's a constant
313 if (Condition == BoolTrue)
316 if (Condition == BoolFalse)
319 if (Condition == BoolUndef)
322 // Second: If the condition is already inverted, return the original value
323 if (match(Condition, m_Not(m_Value(Condition))))
326 if (Instruction *Inst = dyn_cast<Instruction>(Condition)) {
327 // Third: Check all the users for an invert
328 BasicBlock *Parent = Inst->getParent();
329 for (Value::use_iterator I = Condition->use_begin(),
330 E = Condition->use_end(); I != E; ++I) {
332 Instruction *User = dyn_cast<Instruction>(*I);
333 if (!User || User->getParent() != Parent)
336 if (match(*I, m_Not(m_Specific(Condition))))
340 // Last option: Create a new instruction
341 return BinaryOperator::CreateNot(Condition, "", Parent->getTerminator());
344 if (Argument *Arg = dyn_cast<Argument>(Condition)) {
345 BasicBlock &EntryBlock = Arg->getParent()->getEntryBlock();
346 return BinaryOperator::CreateNot(Condition,
347 Arg->getName() + ".inv",
348 EntryBlock.getTerminator());
351 llvm_unreachable("Unhandled condition to invert");
354 /// \brief Build the condition for one edge
355 Value *StructurizeCFG::buildCondition(BranchInst *Term, unsigned Idx,
357 Value *Cond = Invert ? BoolFalse : BoolTrue;
358 if (Term->isConditional()) {
359 Cond = Term->getCondition();
361 if (Idx != (unsigned)Invert)
367 /// \brief Analyze the predecessors of each block and build up predicates
368 void StructurizeCFG::gatherPredicates(RegionNode *N) {
369 RegionInfo *RI = ParentRegion->getRegionInfo();
370 BasicBlock *BB = N->getEntry();
371 BBPredicates &Pred = Predicates[BB];
372 BBPredicates &LPred = LoopPreds[BB];
374 for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
377 // Ignore it if it's a branch from outside into our region entry
378 if (!ParentRegion->contains(*PI))
381 Region *R = RI->getRegionFor(*PI);
382 if (R == ParentRegion) {
384 // It's a top level block in our region
385 BranchInst *Term = cast<BranchInst>((*PI)->getTerminator());
386 for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) {
387 BasicBlock *Succ = Term->getSuccessor(i);
391 if (Visited.count(*PI)) {
392 // Normal forward edge
393 if (Term->isConditional()) {
394 // Try to treat it like an ELSE block
395 BasicBlock *Other = Term->getSuccessor(!i);
396 if (Visited.count(Other) && !Loops.count(Other) &&
397 !Pred.count(Other) && !Pred.count(*PI)) {
399 Pred[Other] = BoolFalse;
400 Pred[*PI] = BoolTrue;
404 Pred[*PI] = buildCondition(Term, i, false);
408 LPred[*PI] = buildCondition(Term, i, true);
414 // It's an exit from a sub region
415 while(R->getParent() != ParentRegion)
418 // Edge from inside a subregion to its entry, ignore it
422 BasicBlock *Entry = R->getEntry();
423 if (Visited.count(Entry))
424 Pred[Entry] = BoolTrue;
426 LPred[Entry] = BoolFalse;
431 /// \brief Collect various loop and predicate infos
432 void StructurizeCFG::collectInfos() {
440 // Reset the visited nodes
443 for (RNVector::reverse_iterator OI = Order.rbegin(), OE = Order.rend();
446 // Analyze all the conditions leading to a node
447 gatherPredicates(*OI);
449 // Remember that we've seen this node
450 Visited.insert((*OI)->getEntry());
452 // Find the last back edges
457 /// \brief Insert the missing branch conditions
458 void StructurizeCFG::insertConditions(bool Loops) {
459 BranchVector &Conds = Loops ? LoopConds : Conditions;
460 Value *Default = Loops ? BoolTrue : BoolFalse;
461 SSAUpdater PhiInserter;
463 for (BranchVector::iterator I = Conds.begin(),
464 E = Conds.end(); I != E; ++I) {
466 BranchInst *Term = *I;
467 assert(Term->isConditional());
469 BasicBlock *Parent = Term->getParent();
470 BasicBlock *SuccTrue = Term->getSuccessor(0);
471 BasicBlock *SuccFalse = Term->getSuccessor(1);
473 PhiInserter.Initialize(Boolean, "");
474 PhiInserter.AddAvailableValue(&Func->getEntryBlock(), Default);
475 PhiInserter.AddAvailableValue(Loops ? SuccFalse : Parent, Default);
477 BBPredicates &Preds = Loops ? LoopPreds[SuccFalse] : Predicates[SuccTrue];
479 NearestCommonDominator Dominator(DT);
480 Dominator.addBlock(Parent, false);
482 Value *ParentValue = 0;
483 for (BBPredicates::iterator PI = Preds.begin(), PE = Preds.end();
486 if (PI->first == Parent) {
487 ParentValue = PI->second;
490 PhiInserter.AddAvailableValue(PI->first, PI->second);
491 Dominator.addBlock(PI->first);
495 Term->setCondition(ParentValue);
497 if (!Dominator.wasResultExplicitMentioned())
498 PhiInserter.AddAvailableValue(Dominator.getResult(), Default);
500 Term->setCondition(PhiInserter.GetValueInMiddleOfBlock(Parent));
505 /// \brief Remove all PHI values coming from "From" into "To" and remember
506 /// them in DeletedPhis
507 void StructurizeCFG::delPhiValues(BasicBlock *From, BasicBlock *To) {
508 PhiMap &Map = DeletedPhis[To];
509 for (BasicBlock::iterator I = To->begin(), E = To->end();
510 I != E && isa<PHINode>(*I);) {
512 PHINode &Phi = cast<PHINode>(*I++);
513 while (Phi.getBasicBlockIndex(From) != -1) {
514 Value *Deleted = Phi.removeIncomingValue(From, false);
515 Map[&Phi].push_back(std::make_pair(From, Deleted));
520 /// \brief Add a dummy PHI value as soon as we knew the new predecessor
521 void StructurizeCFG::addPhiValues(BasicBlock *From, BasicBlock *To) {
522 for (BasicBlock::iterator I = To->begin(), E = To->end();
523 I != E && isa<PHINode>(*I);) {
525 PHINode &Phi = cast<PHINode>(*I++);
526 Value *Undef = UndefValue::get(Phi.getType());
527 Phi.addIncoming(Undef, From);
529 AddedPhis[To].push_back(From);
532 /// \brief Add the real PHI value as soon as everything is set up
533 void StructurizeCFG::setPhiValues() {
535 for (BB2BBVecMap::iterator AI = AddedPhis.begin(), AE = AddedPhis.end();
538 BasicBlock *To = AI->first;
539 BBVector &From = AI->second;
541 if (!DeletedPhis.count(To))
544 PhiMap &Map = DeletedPhis[To];
545 for (PhiMap::iterator PI = Map.begin(), PE = Map.end();
548 PHINode *Phi = PI->first;
549 Value *Undef = UndefValue::get(Phi->getType());
550 Updater.Initialize(Phi->getType(), "");
551 Updater.AddAvailableValue(&Func->getEntryBlock(), Undef);
552 Updater.AddAvailableValue(To, Undef);
554 NearestCommonDominator Dominator(DT);
555 Dominator.addBlock(To, false);
556 for (BBValueVector::iterator VI = PI->second.begin(),
557 VE = PI->second.end(); VI != VE; ++VI) {
559 Updater.AddAvailableValue(VI->first, VI->second);
560 Dominator.addBlock(VI->first);
563 if (!Dominator.wasResultExplicitMentioned())
564 Updater.AddAvailableValue(Dominator.getResult(), Undef);
566 for (BBVector::iterator FI = From.begin(), FE = From.end();
569 int Idx = Phi->getBasicBlockIndex(*FI);
571 Phi->setIncomingValue(Idx, Updater.GetValueAtEndOfBlock(*FI));
575 DeletedPhis.erase(To);
577 assert(DeletedPhis.empty());
580 /// \brief Remove phi values from all successors and then remove the terminator.
581 void StructurizeCFG::killTerminator(BasicBlock *BB) {
582 TerminatorInst *Term = BB->getTerminator();
586 for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
589 delPhiValues(BB, *SI);
592 Term->eraseFromParent();
595 /// \brief Let node exit(s) point to NewExit
596 void StructurizeCFG::changeExit(RegionNode *Node, BasicBlock *NewExit,
597 bool IncludeDominator) {
598 if (Node->isSubRegion()) {
599 Region *SubRegion = Node->getNodeAs<Region>();
600 BasicBlock *OldExit = SubRegion->getExit();
601 BasicBlock *Dominator = 0;
603 // Find all the edges from the sub region to the exit
604 for (pred_iterator I = pred_begin(OldExit), E = pred_end(OldExit);
607 BasicBlock *BB = *I++;
608 if (!SubRegion->contains(BB))
611 // Modify the edges to point to the new exit
612 delPhiValues(BB, OldExit);
613 BB->getTerminator()->replaceUsesOfWith(OldExit, NewExit);
614 addPhiValues(BB, NewExit);
616 // Find the new dominator (if requested)
617 if (IncludeDominator) {
621 Dominator = DT->findNearestCommonDominator(Dominator, BB);
625 // Change the dominator (if requested)
627 DT->changeImmediateDominator(NewExit, Dominator);
629 // Update the region info
630 SubRegion->replaceExit(NewExit);
633 BasicBlock *BB = Node->getNodeAs<BasicBlock>();
635 BranchInst::Create(NewExit, BB);
636 addPhiValues(BB, NewExit);
637 if (IncludeDominator)
638 DT->changeImmediateDominator(NewExit, BB);
642 /// \brief Create a new flow node and update dominator tree and region info
643 BasicBlock *StructurizeCFG::getNextFlow(BasicBlock *Dominator) {
644 LLVMContext &Context = Func->getContext();
645 BasicBlock *Insert = Order.empty() ? ParentRegion->getExit() :
646 Order.back()->getEntry();
647 BasicBlock *Flow = BasicBlock::Create(Context, FlowBlockName,
649 DT->addNewBlock(Flow, Dominator);
650 ParentRegion->getRegionInfo()->setRegionFor(Flow, ParentRegion);
654 /// \brief Create a new or reuse the previous node as flow node
655 BasicBlock *StructurizeCFG::needPrefix(bool NeedEmpty) {
656 BasicBlock *Entry = PrevNode->getEntry();
658 if (!PrevNode->isSubRegion()) {
659 killTerminator(Entry);
660 if (!NeedEmpty || Entry->getFirstInsertionPt() == Entry->end())
665 // create a new flow node
666 BasicBlock *Flow = getNextFlow(Entry);
669 changeExit(PrevNode, Flow, true);
670 PrevNode = ParentRegion->getBBNode(Flow);
674 /// \brief Returns the region exit if possible, otherwise just a new flow node
675 BasicBlock *StructurizeCFG::needPostfix(BasicBlock *Flow,
676 bool ExitUseAllowed) {
677 if (Order.empty() && ExitUseAllowed) {
678 BasicBlock *Exit = ParentRegion->getExit();
679 DT->changeImmediateDominator(Exit, Flow);
680 addPhiValues(Flow, Exit);
683 return getNextFlow(Flow);
686 /// \brief Set the previous node
687 void StructurizeCFG::setPrevNode(BasicBlock *BB) {
688 PrevNode = ParentRegion->contains(BB) ? ParentRegion->getBBNode(BB) : 0;
691 /// \brief Does BB dominate all the predicates of Node ?
692 bool StructurizeCFG::dominatesPredicates(BasicBlock *BB, RegionNode *Node) {
693 BBPredicates &Preds = Predicates[Node->getEntry()];
694 for (BBPredicates::iterator PI = Preds.begin(), PE = Preds.end();
697 if (!DT->dominates(BB, PI->first))
703 /// \brief Can we predict that this node will always be called?
704 bool StructurizeCFG::isPredictableTrue(RegionNode *Node) {
705 BBPredicates &Preds = Predicates[Node->getEntry()];
706 bool Dominated = false;
708 // Regionentry is always true
712 for (BBPredicates::iterator I = Preds.begin(), E = Preds.end();
715 if (I->second != BoolTrue)
718 if (!Dominated && DT->dominates(I->first, PrevNode->getEntry()))
722 // TODO: The dominator check is too strict
726 /// Take one node from the order vector and wire it up
727 void StructurizeCFG::wireFlow(bool ExitUseAllowed,
728 BasicBlock *LoopEnd) {
729 RegionNode *Node = Order.pop_back_val();
730 Visited.insert(Node->getEntry());
732 if (isPredictableTrue(Node)) {
733 // Just a linear flow
735 changeExit(PrevNode, Node->getEntry(), true);
740 // Insert extra prefix node (or reuse last one)
741 BasicBlock *Flow = needPrefix(false);
743 // Insert extra postfix node (or use exit instead)
744 BasicBlock *Entry = Node->getEntry();
745 BasicBlock *Next = needPostfix(Flow, ExitUseAllowed);
747 // let it point to entry and next block
748 Conditions.push_back(BranchInst::Create(Entry, Next, BoolUndef, Flow));
749 addPhiValues(Flow, Entry);
750 DT->changeImmediateDominator(Entry, Flow);
753 while (!Order.empty() && !Visited.count(LoopEnd) &&
754 dominatesPredicates(Entry, Order.back())) {
755 handleLoops(false, LoopEnd);
758 changeExit(PrevNode, Next, false);
763 void StructurizeCFG::handleLoops(bool ExitUseAllowed,
764 BasicBlock *LoopEnd) {
765 RegionNode *Node = Order.back();
766 BasicBlock *LoopStart = Node->getEntry();
768 if (!Loops.count(LoopStart)) {
769 wireFlow(ExitUseAllowed, LoopEnd);
773 if (!isPredictableTrue(Node))
774 LoopStart = needPrefix(true);
776 LoopEnd = Loops[Node->getEntry()];
777 wireFlow(false, LoopEnd);
778 while (!Visited.count(LoopEnd)) {
779 handleLoops(false, LoopEnd);
782 // Create an extra loop end node
783 LoopEnd = needPrefix(false);
784 BasicBlock *Next = needPostfix(LoopEnd, ExitUseAllowed);
785 LoopConds.push_back(BranchInst::Create(Next, LoopStart,
786 BoolUndef, LoopEnd));
787 addPhiValues(LoopEnd, LoopStart);
791 /// After this function control flow looks like it should be, but
792 /// branches and PHI nodes only have undefined conditions.
793 void StructurizeCFG::createFlow() {
794 BasicBlock *Exit = ParentRegion->getExit();
795 bool EntryDominatesExit = DT->dominates(ParentRegion->getEntry(), Exit);
805 while (!Order.empty()) {
806 handleLoops(EntryDominatesExit, 0);
810 changeExit(PrevNode, Exit, EntryDominatesExit);
812 assert(EntryDominatesExit);
815 /// Handle a rare case where the disintegrated nodes instructions
816 /// no longer dominate all their uses. Not sure if this is really nessasary
817 void StructurizeCFG::rebuildSSA() {
819 for (Region::block_iterator I = ParentRegion->block_begin(),
820 E = ParentRegion->block_end();
824 for (BasicBlock::iterator II = BB->begin(), IE = BB->end();
827 bool Initialized = false;
828 for (Use *I = &II->use_begin().getUse(), *Next; I; I = Next) {
832 Instruction *User = cast<Instruction>(I->getUser());
833 if (User->getParent() == BB) {
836 } else if (PHINode *UserPN = dyn_cast<PHINode>(User)) {
837 if (UserPN->getIncomingBlock(*I) == BB)
841 if (DT->dominates(II, User))
845 Value *Undef = UndefValue::get(II->getType());
846 Updater.Initialize(II->getType(), "");
847 Updater.AddAvailableValue(&Func->getEntryBlock(), Undef);
848 Updater.AddAvailableValue(BB, II);
851 Updater.RewriteUseAfterInsertions(*I);
857 /// \brief Run the transformation for each region found
858 bool StructurizeCFG::runOnRegion(Region *R, RGPassManager &RGM) {
859 if (R->isTopLevelRegion())
862 Func = R->getEntry()->getParent();
865 DT = &getAnalysis<DominatorTree>();
870 insertConditions(false);
871 insertConditions(true);
889 /// \brief Create the pass
890 Pass *llvm::createStructurizeCFGPass() {
891 return new StructurizeCFG();