minor simplifications of the code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20497 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-03-06 21:58:22 +00:00
parent bc99f12dd2
commit 2461dff070

View File

@ -35,16 +35,15 @@ using namespace llvm;
namespace { namespace {
Statistic<> NumReduced ("loop-reduce", "Number of GEPs strength reduced"); Statistic<> NumReduced ("loop-reduce", "Number of GEPs strength reduced");
class GEPCache class GEPCache {
{
public: public:
GEPCache() : CachedPHINode(0), Map() {} GEPCache() : CachedPHINode(0), Map() {}
GEPCache* operator[](Value *v) { GEPCache *get(Value *v) {
std::map<Value *, GEPCache>::iterator I = Map.find(v); std::map<Value *, GEPCache>::iterator I = Map.find(v);
if (I == Map.end()) if (I == Map.end())
I = Map.insert(std::pair<Value *, GEPCache>(v, GEPCache())).first; I = Map.insert(std::pair<Value *, GEPCache>(v, GEPCache())).first;
return &(I->second); return &I->second;
} }
PHINode *CachedPHINode; PHINode *CachedPHINode;
@ -135,7 +134,7 @@ void LoopStrengthReduce::strengthReduceGEP(GetElementPtrInst *GEPI, Loop *L,
BasicBlock *Header = L->getHeader(); BasicBlock *Header = L->getHeader();
BasicBlock *Preheader = L->getLoopPreheader(); BasicBlock *Preheader = L->getLoopPreheader();
bool AllConstantOperands = true; bool AllConstantOperands = true;
Cache = (*Cache)[GEPI->getOperand(0)]; Cache = Cache->get(GEPI->getOperand(0));
for (unsigned op = 1, e = GEPI->getNumOperands(); op != e; ++op) { for (unsigned op = 1, e = GEPI->getNumOperands(); op != e; ++op) {
Value *operand = GEPI->getOperand(op); Value *operand = GEPI->getOperand(op);
@ -164,7 +163,7 @@ void LoopStrengthReduce::strengthReduceGEP(GetElementPtrInst *GEPI, Loop *L,
AllConstantOperands = false; AllConstantOperands = false;
} else } else
return; return;
Cache = (*Cache)[operand]; Cache = Cache->get(operand);
} }
assert(indvar > 0 && "Indvar used by GEP not found in operand list"); assert(indvar > 0 && "Indvar used by GEP not found in operand list");
@ -179,8 +178,8 @@ void LoopStrengthReduce::strengthReduceGEP(GetElementPtrInst *GEPI, Loop *L,
// Don't reduce multiplies that the target can handle via addressing modes. // Don't reduce multiplies that the target can handle via addressing modes.
uint64_t sz = getAnalysis<TargetData>().getTypeSize(ty); uint64_t sz = getAnalysis<TargetData>().getTypeSize(ty);
for (unsigned i = 1; i <= MaxTargetAMSize; i *= 2) if (sz && (sz & (sz-1)) == 0) // Power of two?
if (i == sz) if (sz <= (1ULL << (MaxTargetAMSize-1)))
return; return;
// If all operands of the GEP we are going to insert into the preheader // If all operands of the GEP we are going to insert into the preheader
@ -248,7 +247,7 @@ void LoopStrengthReduce::strengthReduceGEP(GetElementPtrInst *GEPI, Loop *L,
GEPI->getName() + ".lsr", GEPI->getName() + ".lsr",
GEPI); GEPI);
GEPI->replaceAllUsesWith(newGEP); GEPI->replaceAllUsesWith(newGEP);
} }
// The old GEP is now dead. // The old GEP is now dead.
DeadInsts.insert(GEPI); DeadInsts.insert(GEPI);