summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/PredicateSimplifier.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2007-04-25 04:18:54 +0000
committerOwen Anderson <resistor@mac.com>2007-04-25 04:18:54 +0000
commitab0e4d38f0301089127f7c643ee19207cd7ce388 (patch)
tree55b8cdac507339fb4249f3a363392cec5e4dfae8 /lib/Transforms/Scalar/PredicateSimplifier.cpp
parent6266c18ea12b42bd9b262a1f4f8c3d7a85130118 (diff)
downloadllvm-ab0e4d38f0301089127f7c643ee19207cd7ce388.tar.gz
llvm-ab0e4d38f0301089127f7c643ee19207cd7ce388.tar.bz2
llvm-ab0e4d38f0301089127f7c643ee19207cd7ce388.tar.xz
Undo my previous changes. Since my approach to this problem is being revised,
this approach is no longer appropriate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36421 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/PredicateSimplifier.cpp')
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp63
1 files changed, 31 insertions, 32 deletions
diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp
index 871dd380a8..7eef9ac691 100644
--- a/lib/Transforms/Scalar/PredicateSimplifier.cpp
+++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp
@@ -1980,19 +1980,21 @@ namespace {
/// can't be equal and will solve setcc instructions when possible.
/// @brief Root of the predicate simplifier optimization.
class VISIBILITY_HIDDEN PredicateSimplifier : public FunctionPass {
+ DominatorTree *DT;
ETForest *Forest;
bool modified;
InequalityGraph *IG;
UnreachableBlocks UB;
ValueRanges *VR;
- std::vector<BasicBlock *> WorkList;
+ std::vector<DominatorTree::Node *> WorkList;
public:
bool runOnFunction(Function &F);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequiredID(BreakCriticalEdgesID);
+ AU.addRequired<DominatorTree>();
AU.addRequired<ETForest>();
AU.addRequired<TargetData>();
AU.addPreserved<TargetData>();
@@ -2008,15 +2010,15 @@ namespace {
class VISIBILITY_HIDDEN Forwards : public InstVisitor<Forwards> {
friend class InstVisitor<Forwards>;
PredicateSimplifier *PS;
- BasicBlock *Node;
+ DominatorTree::Node *DTNode;
public:
InequalityGraph &IG;
UnreachableBlocks &UB;
ValueRanges &VR;
- Forwards(PredicateSimplifier *PS, BasicBlock* node)
- : PS(PS), Node(node), IG(*PS->IG), UB(PS->UB), VR(*PS->VR) {}
+ Forwards(PredicateSimplifier *PS, DominatorTree::Node *DTNode)
+ : PS(PS), DTNode(DTNode), IG(*PS->IG), UB(PS->UB), VR(*PS->VR) {}
void visitTerminatorInst(TerminatorInst &TI);
void visitBranchInst(BranchInst &BI);
@@ -2036,32 +2038,31 @@ namespace {
// Used by terminator instructions to proceed from the current basic
// block to the next. Verifies that "current" dominates "next",
// then calls visitBasicBlock.
- void proceedToSuccessors(BasicBlock *Current) {
- std::vector<BasicBlock*> Children;
- Forest->getChildren(Current, Children);
- for (std::vector<BasicBlock*>::iterator I = Children.begin(),
- E = Children.end(); I != E; ++I) {
+ void proceedToSuccessors(DominatorTree::Node *Current) {
+ for (DominatorTree::Node::iterator I = Current->begin(),
+ E = Current->end(); I != E; ++I) {
WorkList.push_back(*I);
}
}
- void proceedToSuccessor(BasicBlock *Next) {
+ void proceedToSuccessor(DominatorTree::Node *Next) {
WorkList.push_back(Next);
}
// Visits each instruction in the basic block.
- void visitBasicBlock(BasicBlock *BB) {
+ void visitBasicBlock(DominatorTree::Node *Node) {
+ BasicBlock *BB = Node->getBlock();
ETNode *ET = Forest->getNodeForBlock(BB);
DOUT << "Entering Basic Block: " << BB->getName()
<< " (" << ET->getDFSNumIn() << ")\n";
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
- visitInstruction(I++, BB, ET);
+ visitInstruction(I++, Node, ET);
}
}
// Tries to simplify each Instruction and add new properties to
// the PropertySet.
- void visitInstruction(Instruction *I, BasicBlock *node, ETNode *ET) {
+ void visitInstruction(Instruction *I, DominatorTree::Node *DT, ETNode *ET) {
DOUT << "Considering instruction " << *I << "\n";
DEBUG(IG->dump());
@@ -2105,13 +2106,14 @@ namespace {
std::string name = I->getParent()->getName();
DOUT << "push (%" << name << ")\n";
- Forwards visit(this, node);
+ Forwards visit(this, DT);
visit.visit(*I);
DOUT << "pop (%" << name << ")\n";
}
};
bool PredicateSimplifier::runOnFunction(Function &F) {
+ DT = &getAnalysis<DominatorTree>();
Forest = &getAnalysis<ETForest>();
TargetData *TD = &getAnalysis<TargetData>();
@@ -2125,12 +2127,12 @@ namespace {
BasicBlock *RootBlock = &F.getEntryBlock();
IG = new InequalityGraph(Forest->getNodeForBlock(RootBlock));
VR = new ValueRanges(TD);
- WorkList.push_back(Forest->getRoot());
+ WorkList.push_back(DT->getRootNode());
do {
- BasicBlock *node = WorkList.back();
+ DominatorTree::Node *DTNode = WorkList.back();
WorkList.pop_back();
- if (!UB.isDead(node)) visitBasicBlock(node);
+ if (!UB.isDead(DTNode->getBlock())) visitBasicBlock(DTNode);
} while (!WorkList.empty());
delete VR;
@@ -2142,12 +2144,12 @@ namespace {
}
void PredicateSimplifier::Forwards::visitTerminatorInst(TerminatorInst &TI) {
- PS->proceedToSuccessors(Node);
+ PS->proceedToSuccessors(DTNode);
}
void PredicateSimplifier::Forwards::visitBranchInst(BranchInst &BI) {
if (BI.isUnconditional()) {
- PS->proceedToSuccessors(Node);
+ PS->proceedToSuccessors(DTNode);
return;
}
@@ -2156,26 +2158,24 @@ namespace {
BasicBlock *FalseDest = BI.getSuccessor(1);
if (isa<Constant>(Condition) || TrueDest == FalseDest) {
- PS->proceedToSuccessors(Node);
+ PS->proceedToSuccessors(DTNode);
return;
}
- std::vector<BasicBlock*> Children;
- PS->Forest->getChildren(Node, Children);
- for (std::vector<BasicBlock*>::iterator I = Children.begin(),
- E = Children.end(); I != E; ++I) {
- BasicBlock *Dest = *I;
+ for (DominatorTree::Node::iterator I = DTNode->begin(), E = DTNode->end();
+ I != E; ++I) {
+ BasicBlock *Dest = (*I)->getBlock();
DOUT << "Branch thinking about %" << Dest->getName()
<< "(" << PS->Forest->getNodeForBlock(Dest)->getDFSNumIn() << ")\n";
if (Dest == TrueDest) {
- DOUT << "(" << Node->getName() << ") true set:\n";
+ DOUT << "(" << DTNode->getBlock()->getName() << ") true set:\n";
VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, Dest);
VRP.add(ConstantInt::getTrue(), Condition, ICmpInst::ICMP_EQ);
VRP.solve();
DEBUG(IG.dump());
} else if (Dest == FalseDest) {
- DOUT << "(" << Node->getName() << ") false set:\n";
+ DOUT << "(" << DTNode->getBlock()->getName() << ") false set:\n";
VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, Dest);
VRP.add(ConstantInt::getFalse(), Condition, ICmpInst::ICMP_EQ);
VRP.solve();
@@ -2191,11 +2191,10 @@ namespace {
// Set the EQProperty in each of the cases BBs, and the NEProperties
// in the default BB.
- std::vector<BasicBlock*> Children;
- PS->Forest->getChildren(Node, Children);
- for (std::vector<BasicBlock*>::iterator I = Children.begin(),
- E = Children.end(); I != E; ++I) {
- BasicBlock *BB = *I;
+
+ for (DominatorTree::Node::iterator I = DTNode->begin(), E = DTNode->end();
+ I != E; ++I) {
+ BasicBlock *BB = (*I)->getBlock();
DOUT << "Switch thinking about BB %" << BB->getName()
<< "(" << PS->Forest->getNodeForBlock(BB)->getDFSNumIn() << ")\n";