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
This commit is contained in:
Owen Anderson
2007-04-25 04:18:54 +00:00
parent 6266c18ea1
commit ab0e4d38f0

View File

@@ -1980,19 +1980,21 @@ namespace {
/// can't be equal and will solve setcc instructions when possible. /// can't be equal and will solve setcc instructions when possible.
/// @brief Root of the predicate simplifier optimization. /// @brief Root of the predicate simplifier optimization.
class VISIBILITY_HIDDEN PredicateSimplifier : public FunctionPass { class VISIBILITY_HIDDEN PredicateSimplifier : public FunctionPass {
DominatorTree *DT;
ETForest *Forest; ETForest *Forest;
bool modified; bool modified;
InequalityGraph *IG; InequalityGraph *IG;
UnreachableBlocks UB; UnreachableBlocks UB;
ValueRanges *VR; ValueRanges *VR;
std::vector<BasicBlock *> WorkList; std::vector<DominatorTree::Node *> WorkList;
public: public:
bool runOnFunction(Function &F); bool runOnFunction(Function &F);
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequiredID(BreakCriticalEdgesID); AU.addRequiredID(BreakCriticalEdgesID);
AU.addRequired<DominatorTree>();
AU.addRequired<ETForest>(); AU.addRequired<ETForest>();
AU.addRequired<TargetData>(); AU.addRequired<TargetData>();
AU.addPreserved<TargetData>(); AU.addPreserved<TargetData>();
@@ -2008,15 +2010,15 @@ namespace {
class VISIBILITY_HIDDEN Forwards : public InstVisitor<Forwards> { class VISIBILITY_HIDDEN Forwards : public InstVisitor<Forwards> {
friend class InstVisitor<Forwards>; friend class InstVisitor<Forwards>;
PredicateSimplifier *PS; PredicateSimplifier *PS;
BasicBlock *Node; DominatorTree::Node *DTNode;
public: public:
InequalityGraph &IG; InequalityGraph &IG;
UnreachableBlocks &UB; UnreachableBlocks &UB;
ValueRanges &VR; ValueRanges &VR;
Forwards(PredicateSimplifier *PS, BasicBlock* node) Forwards(PredicateSimplifier *PS, DominatorTree::Node *DTNode)
: PS(PS), Node(node), IG(*PS->IG), UB(PS->UB), VR(*PS->VR) {} : PS(PS), DTNode(DTNode), IG(*PS->IG), UB(PS->UB), VR(*PS->VR) {}
void visitTerminatorInst(TerminatorInst &TI); void visitTerminatorInst(TerminatorInst &TI);
void visitBranchInst(BranchInst &BI); void visitBranchInst(BranchInst &BI);
@@ -2036,32 +2038,31 @@ namespace {
// Used by terminator instructions to proceed from the current basic // Used by terminator instructions to proceed from the current basic
// block to the next. Verifies that "current" dominates "next", // block to the next. Verifies that "current" dominates "next",
// then calls visitBasicBlock. // then calls visitBasicBlock.
void proceedToSuccessors(BasicBlock *Current) { void proceedToSuccessors(DominatorTree::Node *Current) {
std::vector<BasicBlock*> Children; for (DominatorTree::Node::iterator I = Current->begin(),
Forest->getChildren(Current, Children); E = Current->end(); I != E; ++I) {
for (std::vector<BasicBlock*>::iterator I = Children.begin(),
E = Children.end(); I != E; ++I) {
WorkList.push_back(*I); WorkList.push_back(*I);
} }
} }
void proceedToSuccessor(BasicBlock *Next) { void proceedToSuccessor(DominatorTree::Node *Next) {
WorkList.push_back(Next); WorkList.push_back(Next);
} }
// Visits each instruction in the basic block. // 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); ETNode *ET = Forest->getNodeForBlock(BB);
DOUT << "Entering Basic Block: " << BB->getName() DOUT << "Entering Basic Block: " << BB->getName()
<< " (" << ET->getDFSNumIn() << ")\n"; << " (" << ET->getDFSNumIn() << ")\n";
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) { 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 // Tries to simplify each Instruction and add new properties to
// the PropertySet. // the PropertySet.
void visitInstruction(Instruction *I, BasicBlock *node, ETNode *ET) { void visitInstruction(Instruction *I, DominatorTree::Node *DT, ETNode *ET) {
DOUT << "Considering instruction " << *I << "\n"; DOUT << "Considering instruction " << *I << "\n";
DEBUG(IG->dump()); DEBUG(IG->dump());
@@ -2105,13 +2106,14 @@ namespace {
std::string name = I->getParent()->getName(); std::string name = I->getParent()->getName();
DOUT << "push (%" << name << ")\n"; DOUT << "push (%" << name << ")\n";
Forwards visit(this, node); Forwards visit(this, DT);
visit.visit(*I); visit.visit(*I);
DOUT << "pop (%" << name << ")\n"; DOUT << "pop (%" << name << ")\n";
} }
}; };
bool PredicateSimplifier::runOnFunction(Function &F) { bool PredicateSimplifier::runOnFunction(Function &F) {
DT = &getAnalysis<DominatorTree>();
Forest = &getAnalysis<ETForest>(); Forest = &getAnalysis<ETForest>();
TargetData *TD = &getAnalysis<TargetData>(); TargetData *TD = &getAnalysis<TargetData>();
@@ -2125,12 +2127,12 @@ namespace {
BasicBlock *RootBlock = &F.getEntryBlock(); BasicBlock *RootBlock = &F.getEntryBlock();
IG = new InequalityGraph(Forest->getNodeForBlock(RootBlock)); IG = new InequalityGraph(Forest->getNodeForBlock(RootBlock));
VR = new ValueRanges(TD); VR = new ValueRanges(TD);
WorkList.push_back(Forest->getRoot()); WorkList.push_back(DT->getRootNode());
do { do {
BasicBlock *node = WorkList.back(); DominatorTree::Node *DTNode = WorkList.back();
WorkList.pop_back(); WorkList.pop_back();
if (!UB.isDead(node)) visitBasicBlock(node); if (!UB.isDead(DTNode->getBlock())) visitBasicBlock(DTNode);
} while (!WorkList.empty()); } while (!WorkList.empty());
delete VR; delete VR;
@@ -2142,12 +2144,12 @@ namespace {
} }
void PredicateSimplifier::Forwards::visitTerminatorInst(TerminatorInst &TI) { void PredicateSimplifier::Forwards::visitTerminatorInst(TerminatorInst &TI) {
PS->proceedToSuccessors(Node); PS->proceedToSuccessors(DTNode);
} }
void PredicateSimplifier::Forwards::visitBranchInst(BranchInst &BI) { void PredicateSimplifier::Forwards::visitBranchInst(BranchInst &BI) {
if (BI.isUnconditional()) { if (BI.isUnconditional()) {
PS->proceedToSuccessors(Node); PS->proceedToSuccessors(DTNode);
return; return;
} }
@@ -2156,26 +2158,24 @@ namespace {
BasicBlock *FalseDest = BI.getSuccessor(1); BasicBlock *FalseDest = BI.getSuccessor(1);
if (isa<Constant>(Condition) || TrueDest == FalseDest) { if (isa<Constant>(Condition) || TrueDest == FalseDest) {
PS->proceedToSuccessors(Node); PS->proceedToSuccessors(DTNode);
return; return;
} }
std::vector<BasicBlock*> Children; for (DominatorTree::Node::iterator I = DTNode->begin(), E = DTNode->end();
PS->Forest->getChildren(Node, Children); I != E; ++I) {
for (std::vector<BasicBlock*>::iterator I = Children.begin(), BasicBlock *Dest = (*I)->getBlock();
E = Children.end(); I != E; ++I) {
BasicBlock *Dest = *I;
DOUT << "Branch thinking about %" << Dest->getName() DOUT << "Branch thinking about %" << Dest->getName()
<< "(" << PS->Forest->getNodeForBlock(Dest)->getDFSNumIn() << ")\n"; << "(" << PS->Forest->getNodeForBlock(Dest)->getDFSNumIn() << ")\n";
if (Dest == TrueDest) { 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); VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, Dest);
VRP.add(ConstantInt::getTrue(), Condition, ICmpInst::ICMP_EQ); VRP.add(ConstantInt::getTrue(), Condition, ICmpInst::ICMP_EQ);
VRP.solve(); VRP.solve();
DEBUG(IG.dump()); DEBUG(IG.dump());
} else if (Dest == FalseDest) { } 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); VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, Dest);
VRP.add(ConstantInt::getFalse(), Condition, ICmpInst::ICMP_EQ); VRP.add(ConstantInt::getFalse(), Condition, ICmpInst::ICMP_EQ);
VRP.solve(); VRP.solve();
@@ -2191,11 +2191,10 @@ namespace {
// Set the EQProperty in each of the cases BBs, and the NEProperties // Set the EQProperty in each of the cases BBs, and the NEProperties
// in the default BB. // in the default BB.
std::vector<BasicBlock*> Children;
PS->Forest->getChildren(Node, Children); for (DominatorTree::Node::iterator I = DTNode->begin(), E = DTNode->end();
for (std::vector<BasicBlock*>::iterator I = Children.begin(), I != E; ++I) {
E = Children.end(); I != E; ++I) { BasicBlock *BB = (*I)->getBlock();
BasicBlock *BB = *I;
DOUT << "Switch thinking about BB %" << BB->getName() DOUT << "Switch thinking about BB %" << BB->getName()
<< "(" << PS->Forest->getNodeForBlock(BB)->getDFSNumIn() << ")\n"; << "(" << PS->Forest->getNodeForBlock(BB)->getDFSNumIn() << ")\n";