1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

Assign finer grained ranks, make sure to reassociate top-level after reassociating bottom level

llvm-svn: 7787
This commit is contained in:
Chris Lattner 2003-08-12 20:14:27 +00:00
parent 2e2432d69e
commit c8d2398084

View File

@ -57,20 +57,20 @@ namespace {
Pass *createReassociatePass() { return new Reassociate(); } Pass *createReassociatePass() { return new Reassociate(); }
void Reassociate::BuildRankMap(Function &F) { void Reassociate::BuildRankMap(Function &F) {
unsigned i = 1; unsigned i = 2;
ReversePostOrderTraversal<Function*> RPOT(&F); ReversePostOrderTraversal<Function*> RPOT(&F);
for (ReversePostOrderTraversal<Function*>::rpo_iterator I = RPOT.begin(), for (ReversePostOrderTraversal<Function*>::rpo_iterator I = RPOT.begin(),
E = RPOT.end(); I != E; ++I) E = RPOT.end(); I != E; ++I)
RankMap[*I] = ++i; RankMap[*I] = ++i << 16;
} }
unsigned Reassociate::getRank(Value *V) { unsigned Reassociate::getRank(Value *V) {
if (isa<Argument>(V)) return 1; // Function argument... if (isa<Argument>(V)) return 1; // Function argument...
if (Instruction *I = dyn_cast<Instruction>(V)) { if (Instruction *I = dyn_cast<Instruction>(V)) {
// If this is an expression, return the MAX(rank(LHS), rank(RHS)) so that we // If this is an expression, return the 1+MAX(rank(LHS), rank(RHS)) so that
// can reassociate expressions for code motion! Since we do not recurse for // we can reassociate expressions for code motion! Since we do not recurse
// PHI nodes, we cannot have infinite recursion here, because there cannot // for PHI nodes, we cannot have infinite recursion here, because there
// be loops in the value graph that do not go through PHI nodes. // cannot be loops in the value graph that do not go through PHI nodes.
// //
if (I->getOpcode() == Instruction::PHINode || if (I->getOpcode() == Instruction::PHINode ||
I->getOpcode() == Instruction::Alloca || I->getOpcode() == Instruction::Alloca ||
@ -87,7 +87,10 @@ unsigned Reassociate::getRank(Value *V) {
i != e && Rank != MaxRank; ++i) i != e && Rank != MaxRank; ++i)
Rank = std::max(Rank, getRank(I->getOperand(i))); Rank = std::max(Rank, getRank(I->getOperand(i)));
return CachedRank = Rank; DEBUG(std::cerr << "Calculated Rank[" << V->getName() << "] = "
<< Rank+1 << "\n");
return CachedRank = Rank+1;
} }
// Otherwise it's a global or constant, rank 0. // Otherwise it's a global or constant, rank 0.
@ -145,6 +148,7 @@ bool Reassociate::ReassociateExpr(BinaryOperator *I) {
// Since we modified the RHS instruction, make sure that we recheck it. // Since we modified the RHS instruction, make sure that we recheck it.
ReassociateExpr(LHSI); ReassociateExpr(LHSI);
ReassociateExpr(I);
return true; return true;
} }
} }