[llvm-commits] CVS: llvm/lib/Transforms/Scalar/Reassociate.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sat Dec 14 21:57:00 PST 2002
Changes in directory llvm/lib/Transforms/Scalar:
Reassociate.cpp updated: 1.14 -> 1.15
---
Log message:
Fix a huge performance problem in reassociate by introducing a
rank map cache for instruction ranks
---
Diffs of the changes:
Index: llvm/lib/Transforms/Scalar/Reassociate.cpp
diff -u llvm/lib/Transforms/Scalar/Reassociate.cpp:1.14 llvm/lib/Transforms/Scalar/Reassociate.cpp:1.15
--- llvm/lib/Transforms/Scalar/Reassociate.cpp:1.14 Sat Dec 14 21:49:50 2002
+++ llvm/lib/Transforms/Scalar/Reassociate.cpp Sat Dec 14 21:56:00 2002
@@ -36,6 +36,7 @@
class Reassociate : public FunctionPass {
std::map<BasicBlock*, unsigned> RankMap;
+ std::map<Instruction*, unsigned> InstRankMap;
public:
bool runOnFunction(Function &F);
@@ -76,12 +77,16 @@
I->hasSideEffects())
return RankMap[I->getParent()];
+ unsigned &CachedRank = InstRankMap[I];
+ if (CachedRank) return CachedRank; // Rank already known?
+
+ // If not, compute it!
unsigned Rank = 0, MaxRank = RankMap[I->getParent()];
for (unsigned i = 0, e = I->getNumOperands();
i != e && Rank != MaxRank; ++i)
Rank = std::max(Rank, getRank(I->getOperand(i)));
- return Rank;
+ return CachedRank = Rank;
}
// Otherwise it's a global or constant, rank 0.
@@ -267,5 +272,6 @@
// We are done with the rank map...
RankMap.clear();
+ InstRankMap.clear();
return Changed;
}
More information about the llvm-commits
mailing list