mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-29 10:25:12 +00:00
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
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#ifndef LLVM_TRANSFORMS_UTILS_FUNCTION_H
|
#ifndef LLVM_TRANSFORMS_UTILS_FUNCTION_H
|
||||||
#define LLVM_TRANSFORMS_UTILS_FUNCTION_H
|
#define LLVM_TRANSFORMS_UTILS_FUNCTION_H
|
||||||
|
|
||||||
|
#include <llvm/Analysis/Dominators.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@@ -24,13 +25,13 @@ namespace llvm {
|
|||||||
|
|
||||||
/// ExtractCodeRegion - rip out a sequence of basic blocks into a new function
|
/// 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<BasicBlock*> &code,
|
const std::vector<BasicBlock*> &code,
|
||||||
bool AggregateArgs = false);
|
bool AggregateArgs = false);
|
||||||
|
|
||||||
/// ExtractLoop - rip out a natural loop into a new function
|
/// 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);
|
bool AggregateArgs = false);
|
||||||
|
|
||||||
/// ExtractBasicBlock - rip out a basic block into a new function
|
/// ExtractBasicBlock - rip out a basic block into a new function
|
||||||
|
@@ -43,7 +43,8 @@ namespace {
|
|||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.addRequiredID(BreakCriticalEdgesID);
|
AU.addRequiredID(BreakCriticalEdgesID);
|
||||||
AU.addRequiredID(LoopSimplifyID);
|
AU.addRequiredID(LoopSimplifyID);
|
||||||
AU.addRequired<DominatorSet>();
|
AU.addRequired<ETForest>();
|
||||||
|
AU.addRequired<DominatorTree>();
|
||||||
AU.addRequired<LoopInfo>();
|
AU.addRequired<LoopInfo>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -72,7 +73,8 @@ bool LoopExtractor::runOnFunction(Function &F) {
|
|||||||
if (LI.begin() == LI.end())
|
if (LI.begin() == LI.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
DominatorSet &DS = getAnalysis<DominatorSet>();
|
ETForest &EF = getAnalysis<ETForest>();
|
||||||
|
DominatorTree &DT = getAnalysis<DominatorTree>();
|
||||||
|
|
||||||
// If there is more than one top-level loop in this function, extract all of
|
// If there is more than one top-level loop in this function, extract all of
|
||||||
// the loops.
|
// the loops.
|
||||||
@@ -81,7 +83,7 @@ bool LoopExtractor::runOnFunction(Function &F) {
|
|||||||
for (LoopInfo::iterator i = LI.begin(), e = LI.end(); i != e; ++i) {
|
for (LoopInfo::iterator i = LI.begin(), e = LI.end(); i != e; ++i) {
|
||||||
if (NumLoops == 0) return Changed;
|
if (NumLoops == 0) return Changed;
|
||||||
--NumLoops;
|
--NumLoops;
|
||||||
Changed |= ExtractLoop(DS, *i) != 0;
|
Changed |= ExtractLoop(EF, DT, *i) != 0;
|
||||||
++NumExtracted;
|
++NumExtracted;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -111,7 +113,7 @@ bool LoopExtractor::runOnFunction(Function &F) {
|
|||||||
if (ShouldExtractLoop) {
|
if (ShouldExtractLoop) {
|
||||||
if (NumLoops == 0) return Changed;
|
if (NumLoops == 0) return Changed;
|
||||||
--NumLoops;
|
--NumLoops;
|
||||||
Changed |= ExtractLoop(DS, TLL) != 0;
|
Changed |= ExtractLoop(EF, DT, TLL) != 0;
|
||||||
++NumExtracted;
|
++NumExtracted;
|
||||||
} else {
|
} else {
|
||||||
// Okay, this function is a minimal container around the specified loop.
|
// 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) {
|
for (Loop::iterator i = TLL->begin(), e = TLL->end(); i != e; ++i) {
|
||||||
if (NumLoops == 0) return Changed;
|
if (NumLoops == 0) return Changed;
|
||||||
--NumLoops;
|
--NumLoops;
|
||||||
Changed |= ExtractLoop(DS, *i) != 0;
|
Changed |= ExtractLoop(EF, DT, *i) != 0;
|
||||||
++NumExtracted;
|
++NumExtracted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -44,13 +44,14 @@ namespace {
|
|||||||
class VISIBILITY_HIDDEN CodeExtractor {
|
class VISIBILITY_HIDDEN CodeExtractor {
|
||||||
typedef std::vector<Value*> Values;
|
typedef std::vector<Value*> Values;
|
||||||
std::set<BasicBlock*> BlocksToExtract;
|
std::set<BasicBlock*> BlocksToExtract;
|
||||||
DominatorSet *DS;
|
ETForest *EF;
|
||||||
|
DominatorTree* DT;
|
||||||
bool AggregateArgs;
|
bool AggregateArgs;
|
||||||
unsigned NumExitBlocks;
|
unsigned NumExitBlocks;
|
||||||
const Type *RetTy;
|
const Type *RetTy;
|
||||||
public:
|
public:
|
||||||
CodeExtractor(DominatorSet *ds = 0, bool AggArgs = false)
|
CodeExtractor(ETForest *ef = 0, DominatorTree* dt = 0, bool AggArgs = false)
|
||||||
: DS(ds), AggregateArgs(AggArgs||AggregateArgsOpt), NumExitBlocks(~0U) {}
|
: EF(ef), DT(dt), AggregateArgs(AggArgs||AggregateArgsOpt), NumExitBlocks(~0U) {}
|
||||||
|
|
||||||
Function *ExtractCodeRegion(const std::vector<BasicBlock*> &code);
|
Function *ExtractCodeRegion(const std::vector<BasicBlock*> &code);
|
||||||
|
|
||||||
@@ -140,17 +141,18 @@ void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) {
|
|||||||
|
|
||||||
// Okay, update dominator sets. The blocks that dominate the new one are the
|
// Okay, update dominator sets. The blocks that dominate the new one are the
|
||||||
// blocks that dominate TIBB plus the new block itself.
|
// blocks that dominate TIBB plus the new block itself.
|
||||||
if (DS) {
|
if (EF) {
|
||||||
DominatorSet::DomSetType DomSet = DS->getDominators(OldPred);
|
DominatorTree::Node* idom = DT->getNode(OldPred)->getIDom();
|
||||||
DomSet.insert(NewBB); // A block always dominates itself.
|
DT->createNewNode(NewBB, idom);
|
||||||
DS->addBasicBlock(NewBB, DomSet);
|
EF->addNewBlock(NewBB, idom->getBlock());
|
||||||
|
|
||||||
// Additionally, NewBB dominates all blocks in the function that are
|
// Additionally, NewBB replaces OldPred as the immediate dominator of blocks
|
||||||
// dominated by OldPred.
|
|
||||||
Function *F = Header->getParent();
|
Function *F = Header->getParent();
|
||||||
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
|
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
|
||||||
if (DS->properlyDominates(OldPred, I))
|
if (DT->getNode(I)->getIDom()->getBlock() == OldPred) {
|
||||||
DS->addDominator(I, NewBB);
|
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
|
// 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
|
// In the extract block case, if the block we are extracting ends
|
||||||
// with an invoke instruction, make sure that we don't emit a
|
// with an invoke instruction, make sure that we don't emit a
|
||||||
// store of the invoke value for the unwind block.
|
// store of the invoke value for the unwind block.
|
||||||
if (!DS && DefBlock != OldTarget)
|
if (!EF && DefBlock != OldTarget)
|
||||||
DominatesDef = false;
|
DominatesDef = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DS)
|
if (EF)
|
||||||
DominatesDef = DS->dominates(DefBlock, OldTarget);
|
DominatesDef = EF->dominates(DefBlock, OldTarget);
|
||||||
|
|
||||||
if (DominatesDef) {
|
if (DominatesDef) {
|
||||||
if (AggregateArgs) {
|
if (AggregateArgs) {
|
||||||
@@ -726,16 +728,16 @@ bool CodeExtractor::isEligible(const std::vector<BasicBlock*> &code) {
|
|||||||
/// ExtractCodeRegion - slurp a sequence of basic blocks into a brand new
|
/// ExtractCodeRegion - slurp a sequence of basic blocks into a brand new
|
||||||
/// function
|
/// function
|
||||||
///
|
///
|
||||||
Function* llvm::ExtractCodeRegion(DominatorSet &DS,
|
Function* llvm::ExtractCodeRegion(ETForest &EF, DominatorTree &DT,
|
||||||
const std::vector<BasicBlock*> &code,
|
const std::vector<BasicBlock*> &code,
|
||||||
bool AggregateArgs) {
|
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
|
/// ExtractBasicBlock - slurp a natural loop into a brand new function
|
||||||
///
|
///
|
||||||
Function* llvm::ExtractLoop(DominatorSet &DS, Loop *L, bool AggregateArgs) {
|
Function* llvm::ExtractLoop(ETForest &EF, DominatorTree &DF, Loop *L, bool AggregateArgs) {
|
||||||
return CodeExtractor(&DS, AggregateArgs).ExtractCodeRegion(L->getBlocks());
|
return CodeExtractor(&EF, &DF, AggregateArgs).ExtractCodeRegion(L->getBlocks());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ExtractBasicBlock - slurp a basic block into a brand new function
|
/// 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) {
|
Function* llvm::ExtractBasicBlock(BasicBlock *BB, bool AggregateArgs) {
|
||||||
std::vector<BasicBlock*> Blocks;
|
std::vector<BasicBlock*> Blocks;
|
||||||
Blocks.push_back(BB);
|
Blocks.push_back(BB);
|
||||||
return CodeExtractor(0, AggregateArgs).ExtractCodeRegion(Blocks);
|
return CodeExtractor(0, 0, AggregateArgs).ExtractCodeRegion(Blocks);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user