From c6fcf29e81f54b68146fb8d375c347d2c689566d Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Sat, 7 Apr 2007 05:31:27 +0000 Subject: [PATCH] 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 --- include/llvm/Transforms/Utils/FunctionUtils.h | 5 ++-- lib/Transforms/IPO/LoopExtractor.cpp | 12 ++++---- lib/Transforms/Utils/CodeExtractor.cpp | 40 ++++++++++++++------------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/include/llvm/Transforms/Utils/FunctionUtils.h b/include/llvm/Transforms/Utils/FunctionUtils.h index d6e486be99b..12291cb473a 100644 --- a/include/llvm/Transforms/Utils/FunctionUtils.h +++ b/include/llvm/Transforms/Utils/FunctionUtils.h @@ -14,6 +14,7 @@ #ifndef LLVM_TRANSFORMS_UTILS_FUNCTION_H #define LLVM_TRANSFORMS_UTILS_FUNCTION_H +#include #include namespace llvm { @@ -24,13 +25,13 @@ namespace llvm { /// ExtractCodeRegion - rip out a sequence of basic blocks into a new function /// - Function* ExtractCodeRegion(DominatorSet &DS, + Function* ExtractCodeRegion(ETForest &DS, DominatorTree& DT, const std::vector &code, bool AggregateArgs = false); /// ExtractLoop - rip out a natural loop into a new function /// - Function* ExtractLoop(DominatorSet &DS, Loop *L, + Function* ExtractLoop(ETForest &DS, DominatorTree& DT, Loop *L, bool AggregateArgs = false); /// ExtractBasicBlock - rip out a basic block into a new function diff --git a/lib/Transforms/IPO/LoopExtractor.cpp b/lib/Transforms/IPO/LoopExtractor.cpp index e99fa78a7d2..c5f4fca12af 100644 --- a/lib/Transforms/IPO/LoopExtractor.cpp +++ b/lib/Transforms/IPO/LoopExtractor.cpp @@ -43,7 +43,8 @@ namespace { virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequiredID(BreakCriticalEdgesID); AU.addRequiredID(LoopSimplifyID); - AU.addRequired(); + AU.addRequired(); + AU.addRequired(); AU.addRequired(); } }; @@ -72,7 +73,8 @@ bool LoopExtractor::runOnFunction(Function &F) { if (LI.begin() == LI.end()) return false; - DominatorSet &DS = getAnalysis(); + ETForest &EF = getAnalysis(); + DominatorTree &DT = getAnalysis(); // If there is more than one top-level loop in this function, extract all of // the loops. @@ -81,7 +83,7 @@ bool LoopExtractor::runOnFunction(Function &F) { for (LoopInfo::iterator i = LI.begin(), e = LI.end(); i != e; ++i) { if (NumLoops == 0) return Changed; --NumLoops; - Changed |= ExtractLoop(DS, *i) != 0; + Changed |= ExtractLoop(EF, DT, *i) != 0; ++NumExtracted; } } else { @@ -111,7 +113,7 @@ bool LoopExtractor::runOnFunction(Function &F) { if (ShouldExtractLoop) { if (NumLoops == 0) return Changed; --NumLoops; - Changed |= ExtractLoop(DS, TLL) != 0; + Changed |= ExtractLoop(EF, DT, TLL) != 0; ++NumExtracted; } else { // Okay, this function is a minimal container around the specified loop. @@ -121,7 +123,7 @@ bool LoopExtractor::runOnFunction(Function &F) { for (Loop::iterator i = TLL->begin(), e = TLL->end(); i != e; ++i) { if (NumLoops == 0) return Changed; --NumLoops; - Changed |= ExtractLoop(DS, *i) != 0; + Changed |= ExtractLoop(EF, DT, *i) != 0; ++NumExtracted; } } diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index a4e7ab8972d..6ad7c2a899d 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -44,13 +44,14 @@ namespace { class VISIBILITY_HIDDEN CodeExtractor { typedef std::vector Values; std::set BlocksToExtract; - DominatorSet *DS; + ETForest *EF; + DominatorTree* DT; bool AggregateArgs; unsigned NumExitBlocks; const Type *RetTy; public: - CodeExtractor(DominatorSet *ds = 0, bool AggArgs = false) - : DS(ds), AggregateArgs(AggArgs||AggregateArgsOpt), NumExitBlocks(~0U) {} + CodeExtractor(ETForest *ef = 0, DominatorTree* dt = 0, bool AggArgs = false) + : EF(ef), DT(dt), AggregateArgs(AggArgs||AggregateArgsOpt), NumExitBlocks(~0U) {} Function *ExtractCodeRegion(const std::vector &code); @@ -140,17 +141,18 @@ void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) { // Okay, update dominator sets. The blocks that dominate the new one are the // blocks that dominate TIBB plus the new block itself. - if (DS) { - DominatorSet::DomSetType DomSet = DS->getDominators(OldPred); - DomSet.insert(NewBB); // A block always dominates itself. - DS->addBasicBlock(NewBB, DomSet); + if (EF) { + DominatorTree::Node* idom = DT->getNode(OldPred)->getIDom(); + DT->createNewNode(NewBB, idom); + EF->addNewBlock(NewBB, idom->getBlock()); - // Additionally, NewBB dominates all blocks in the function that are - // dominated by OldPred. + // Additionally, NewBB replaces OldPred as the immediate dominator of blocks Function *F = Header->getParent(); for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) - if (DS->properlyDominates(OldPred, I)) - DS->addDominator(I, NewBB); + if (DT->getNode(I)->getIDom()->getBlock() == OldPred) { + DT->changeImmediateDominator(DT->getNode(I), DT->getNode(NewBB)); + EF->setImmediateDominator(I, NewBB); + } } // Okay, now we need to adjust the PHI nodes and any branches from within the @@ -507,12 +509,12 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, // In the extract block case, if the block we are extracting ends // with an invoke instruction, make sure that we don't emit a // store of the invoke value for the unwind block. - if (!DS && DefBlock != OldTarget) + if (!EF && DefBlock != OldTarget) DominatesDef = false; } - if (DS) - DominatesDef = DS->dominates(DefBlock, OldTarget); + if (EF) + DominatesDef = EF->dominates(DefBlock, OldTarget); if (DominatesDef) { if (AggregateArgs) { @@ -726,16 +728,16 @@ bool CodeExtractor::isEligible(const std::vector &code) { /// ExtractCodeRegion - slurp a sequence of basic blocks into a brand new /// function /// -Function* llvm::ExtractCodeRegion(DominatorSet &DS, +Function* llvm::ExtractCodeRegion(ETForest &EF, DominatorTree &DT, const std::vector &code, bool AggregateArgs) { - return CodeExtractor(&DS, AggregateArgs).ExtractCodeRegion(code); + return CodeExtractor(&EF, &DT, AggregateArgs).ExtractCodeRegion(code); } /// ExtractBasicBlock - slurp a natural loop into a brand new function /// -Function* llvm::ExtractLoop(DominatorSet &DS, Loop *L, bool AggregateArgs) { - return CodeExtractor(&DS, AggregateArgs).ExtractCodeRegion(L->getBlocks()); +Function* llvm::ExtractLoop(ETForest &EF, DominatorTree &DF, Loop *L, bool AggregateArgs) { + return CodeExtractor(&EF, &DF, AggregateArgs).ExtractCodeRegion(L->getBlocks()); } /// ExtractBasicBlock - slurp a basic block into a brand new function @@ -743,5 +745,5 @@ Function* llvm::ExtractLoop(DominatorSet &DS, Loop *L, bool AggregateArgs) { Function* llvm::ExtractBasicBlock(BasicBlock *BB, bool AggregateArgs) { std::vector Blocks; Blocks.push_back(BB); - return CodeExtractor(0, AggregateArgs).ExtractCodeRegion(Blocks); + return CodeExtractor(0, 0, AggregateArgs).ExtractCodeRegion(Blocks); } -- 2.11.0