llvm.org GIT mirror llvm / c6fcf29
Expunge DomSet from CodeExtractor. This is part of the continuing work on PR1171. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35726 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 12 years ago
3 changed file(s) with 33 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_TRANSFORMS_UTILS_FUNCTION_H
1414 #define LLVM_TRANSFORMS_UTILS_FUNCTION_H
1515
16 #include
1617 #include
1718
1819 namespace llvm {
2324
2425 /// ExtractCodeRegion - rip out a sequence of basic blocks into a new function
2526 ///
26 Function* ExtractCodeRegion(DominatorSet &DS,
27 Function* ExtractCodeRegion(ETForest &DS, DominatorTree& DT,
2728 const std::vector &code,
2829 bool AggregateArgs = false);
2930
3031 /// ExtractLoop - rip out a natural loop into a new function
3132 ///
32 Function* ExtractLoop(DominatorSet &DS, Loop *L,
33 Function* ExtractLoop(ETForest &DS, DominatorTree& DT, Loop *L,
3334 bool AggregateArgs = false);
3435
3536 /// ExtractBasicBlock - rip out a basic block into a new function
4242 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
4343 AU.addRequiredID(BreakCriticalEdgesID);
4444 AU.addRequiredID(LoopSimplifyID);
45 AU.addRequired<DominatorSet>();
45 AU.addRequired<ETForest>();
46 AU.addRequired();
4647 AU.addRequired();
4748 }
4849 };
7172 if (LI.begin() == LI.end())
7273 return false;
7374
74 DominatorSet &DS = getAnalysist>();
75 ETForest &EF = getAnalysist>();
76 DominatorTree &DT = getAnalysis();
7577
7678 // If there is more than one top-level loop in this function, extract all of
7779 // the loops.
8082 for (LoopInfo::iterator i = LI.begin(), e = LI.end(); i != e; ++i) {
8183 if (NumLoops == 0) return Changed;
8284 --NumLoops;
83 Changed |= ExtractLoop(DS, *i) != 0;
85 Changed |= ExtractLoop(EF, DT, *i) != 0;
8486 ++NumExtracted;
8587 }
8688 } else {
110112 if (ShouldExtractLoop) {
111113 if (NumLoops == 0) return Changed;
112114 --NumLoops;
113 Changed |= ExtractLoop(DS, TLL) != 0;
115 Changed |= ExtractLoop(EF, DT, TLL) != 0;
114116 ++NumExtracted;
115117 } else {
116118 // Okay, this function is a minimal container around the specified loop.
120122 for (Loop::iterator i = TLL->begin(), e = TLL->end(); i != e; ++i) {
121123 if (NumLoops == 0) return Changed;
122124 --NumLoops;
123 Changed |= ExtractLoop(DS, *i) != 0;
125 Changed |= ExtractLoop(EF, DT, *i) != 0;
124126 ++NumExtracted;
125127 }
126128 }
4343 class VISIBILITY_HIDDEN CodeExtractor {
4444 typedef std::vector Values;
4545 std::set BlocksToExtract;
46 DominatorSet *DS;
46 ETForest *EF;
47 DominatorTree* DT;
4748 bool AggregateArgs;
4849 unsigned NumExitBlocks;
4950 const Type *RetTy;
5051 public:
51 CodeExtractor(DominatorSet *ds = 0, bool AggArgs = false)
52 : DS(ds), AggregateArgs(AggArgs||AggregateArgsOpt), NumExitBlocks(~0U) {}
52 CodeExtractor(ETForest *ef = 0, DominatorTree* dt = 0, bool AggArgs = false)
53 : EF(ef), DT(dt), AggregateArgs(AggArgs||AggregateArgsOpt), NumExitBlocks(~0U) {}
5354
5455 Function *ExtractCodeRegion(const std::vector &code);
5556
139140
140141 // Okay, update dominator sets. The blocks that dominate the new one are the
141142 // blocks that dominate TIBB plus the new block itself.
142 if (DS) {
143 DominatorSet::DomSetType DomSet = DS->getDominators(OldPred);
144 DomSet.insert(NewBB); // A block always dominates itself.
145 DS->addBasicBlock(NewBB, DomSet);
146
147 // Additionally, NewBB dominates all blocks in the function that are
148 // dominated by OldPred.
143 if (EF) {
144 DominatorTree::Node* idom = DT->getNode(OldPred)->getIDom();
145 DT->createNewNode(NewBB, idom);
146 EF->addNewBlock(NewBB, idom->getBlock());
147
148 // Additionally, NewBB replaces OldPred as the immediate dominator of blocks
149149 Function *F = Header->getParent();
150150 for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
151 if (DS->properlyDominates(OldPred, I))
152 DS->addDominator(I, NewBB);
151 if (DT->getNode(I)->getIDom()->getBlock() == OldPred) {
152 DT->changeImmediateDominator(DT->getNode(I), DT->getNode(NewBB));
153 EF->setImmediateDominator(I, NewBB);
154 }
153155 }
154156
155157 // Okay, now we need to adjust the PHI nodes and any branches from within the
506508 // In the extract block case, if the block we are extracting ends
507509 // with an invoke instruction, make sure that we don't emit a
508510 // store of the invoke value for the unwind block.
509 if (!DS && DefBlock != OldTarget)
511 if (!EF && DefBlock != OldTarget)
510512 DominatesDef = false;
511513 }
512514
513 if (DS)
514 DominatesDef = DS->dominates(DefBlock, OldTarget);
515 if (EF)
516 DominatesDef = EF->dominates(DefBlock, OldTarget);
515517
516518 if (DominatesDef) {
517519 if (AggregateArgs) {
725727 /// ExtractCodeRegion - slurp a sequence of basic blocks into a brand new
726728 /// function
727729 ///
728 Function* llvm::ExtractCodeRegion(DominatorSet &DS,
730 Function* llvm::ExtractCodeRegion(ETForest &EF, DominatorTree &DT,
729731 const std::vector &code,
730732 bool AggregateArgs) {
731 return CodeExtractor(&DS, AggregateArgs).ExtractCodeRegion(code);
733 return CodeExtractor(&EF, &DT, AggregateArgs).ExtractCodeRegion(code);
732734 }
733735
734736 /// ExtractBasicBlock - slurp a natural loop into a brand new function
735737 ///
736 Function* llvm::ExtractLoop(DominatorSet &DS, Loop *L, bool AggregateArgs) {
737 return CodeExtractor(&DS, AggregateArgs).ExtractCodeRegion(L->getBlocks());
738 Function* llvm::ExtractLoop(ETForest &EF, DominatorTree &DF, Loop *L, bool AggregateArgs) {
739 return CodeExtractor(&EF, &DF, AggregateArgs).ExtractCodeRegion(L->getBlocks());
738740 }
739741
740742 /// ExtractBasicBlock - slurp a basic block into a brand new function
742744 Function* llvm::ExtractBasicBlock(BasicBlock *BB, bool AggregateArgs) {
743745 std::vector Blocks;
744746 Blocks.push_back(BB);
745 return CodeExtractor(0, AggregateArgs).ExtractCodeRegion(Blocks);
746 }
747 return CodeExtractor(0, 0, AggregateArgs).ExtractCodeRegion(Blocks);
748 }