* Add better caching of data to avoid silly recusions

* Only check to see if uses of instructions can be converted for expressions... so we don't look at all of the uses of a constant.  This was making the code unnecessarily conservative


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1218 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2001-11-08 22:06:31 +00:00
parent 00d91c6cd8
commit 0bf7bad0c3

View File

@ -77,9 +77,11 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
// have this value converted. This makes use of the map to avoid infinite // have this value converted. This makes use of the map to avoid infinite
// recursion. // recursion.
// //
if (isa<Instruction>(V)) {
for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I)
if (!OperandConvertableToType(*I, V, Ty, CTMap)) if (!OperandConvertableToType(*I, V, Ty, CTMap))
return false; return false;
}
Instruction *I = dyn_cast<Instruction>(V); Instruction *I = dyn_cast<Instruction>(V);
if (I == 0) { if (I == 0) {
@ -336,6 +338,8 @@ bool RetValConvertableToType(Value *V, const Type *Ty,
if (I != ConvertedTypes.end()) return I->second == Ty; if (I != ConvertedTypes.end()) return I->second == Ty;
ConvertedTypes[V] = Ty; ConvertedTypes[V] = Ty;
assert(isa<Instruction>(V) && "Can't convert ret val of non instruction");
// It is safe to convert the specified value to the specified type IFF all of // It is safe to convert the specified value to the specified type IFF all of
// the uses of the value can be converted to accept the new typed value. // the uses of the value can be converted to accept the new typed value.
// //
@ -389,6 +393,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
} }
// FALLTHROUGH // FALLTHROUGH
case Instruction::Sub: { case Instruction::Sub: {
CTMap[I] = Ty;
Value *OtherOp = I->getOperand((V == I->getOperand(0)) ? 1 : 0); Value *OtherOp = I->getOperand((V == I->getOperand(0)) ? 1 : 0);
return RetValConvertableToType(I, Ty, CTMap) && return RetValConvertableToType(I, Ty, CTMap) &&
ExpressionConvertableToType(OtherOp, Ty, CTMap); ExpressionConvertableToType(OtherOp, Ty, CTMap);
@ -403,6 +408,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
// FALL THROUGH // FALL THROUGH
case Instruction::Shl: case Instruction::Shl:
assert(I->getOperand(0) == V); assert(I->getOperand(0) == V);
CTMap[I] = Ty;
return RetValConvertableToType(I, Ty, CTMap); return RetValConvertableToType(I, Ty, CTMap);
case Instruction::Load: case Instruction::Load:
@ -427,6 +433,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
if (TD.getTypeSize(Ty) != TD.getTypeSize(LI->getType())) if (TD.getTypeSize(Ty) != TD.getTypeSize(LI->getType()))
return false; return false;
CTMap[LI] = Ty;
return RetValConvertableToType(LI, Ty, CTMap); return RetValConvertableToType(LI, Ty, CTMap);
} }
return false; return false;
@ -435,6 +442,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
if (TD.getTypeSize(PVTy) != TD.getTypeSize(LI->getType())) if (TD.getTypeSize(PVTy) != TD.getTypeSize(LI->getType()))
return false; return false;
CTMap[LI] = PVTy;
return RetValConvertableToType(LI, PVTy, CTMap); return RetValConvertableToType(LI, PVTy, CTMap);
} }
return false; return false;
@ -465,6 +473,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
} }
case Instruction::PHINode: { case Instruction::PHINode: {
CTMap[I] = Ty;
PHINode *PN = cast<PHINode>(I); PHINode *PN = cast<PHINode>(I);
for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i)
if (!ExpressionConvertableToType(PN->getIncomingValue(i), Ty, CTMap)) if (!ExpressionConvertableToType(PN->getIncomingValue(i), Ty, CTMap))