Do not generate load/store instructions with indexing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3461 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-08-22 16:41:31 +00:00
parent 5a3e29c661
commit ff9a9e5b13

View File

@ -981,19 +981,24 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
const Type *LoadedTy = const Type *LoadedTy =
cast<PointerType>(NewVal->getType())->getElementType(); cast<PointerType>(NewVal->getType())->getElementType();
std::vector<Value*> Indices; Value *Src = NewVal;
Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
if (const CompositeType *CT = dyn_cast<CompositeType>(LoadedTy)) { if (const CompositeType *CT = dyn_cast<CompositeType>(LoadedTy)) {
std::vector<Value*> Indices;
Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
unsigned Offset = 0; // No offset, get first leaf. unsigned Offset = 0; // No offset, get first leaf.
LoadedTy = getStructOffsetType(CT, Offset, Indices, false); LoadedTy = getStructOffsetType(CT, Offset, Indices, false);
assert(LoadedTy->isFirstClassType());
if (Indices.size() != 1) { // Do not generate load X, 0
Src = new GetElementPtrInst(Src, Indices, Name+".idx");
// Insert the GEP instruction before this load.
BIL.insert(I, cast<Instruction>(Src));
}
} }
assert(LoadedTy->isFirstClassType());
Res = new LoadInst(Src, Name);
if (Indices.size() == 1)
Indices.clear(); // Do not generate load X, 0
Res = new LoadInst(NewVal, Indices, Name);
assert(Res->getType()->isFirstClassType() && "Load of structure or array!"); assert(Res->getType()->isFirstClassType() && "Load of structure or array!");
break; break;
} }
@ -1009,23 +1014,27 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
// //
const Type *ElTy = const Type *ElTy =
cast<PointerType>(VMCI->second->getType())->getElementType(); cast<PointerType>(VMCI->second->getType())->getElementType();
if (ElTy == NewTy) {
// If it happens to be converted to exactly the right type, use it Value *SrcPtr = VMCI->second;
// directly...
Res = new StoreInst(NewVal, VMCI->second); if (ElTy != NewTy) {
} else {
// We check that this is a struct in the initial scan... // We check that this is a struct in the initial scan...
const StructType *SElTy = cast<StructType>(ElTy); const StructType *SElTy = cast<StructType>(ElTy);
unsigned Offset = 0;
std::vector<Value*> Indices; std::vector<Value*> Indices;
Indices.push_back(ConstantUInt::get(Type::UIntTy, 0)); Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
unsigned Offset = 0;
const Type *Ty = getStructOffsetType(ElTy, Offset, Indices, false); const Type *Ty = getStructOffsetType(ElTy, Offset, Indices, false);
assert(Offset == 0 && "Offset changed!"); assert(Offset == 0 && "Offset changed!");
assert(NewTy == Ty && "Did not convert to correct type!"); assert(NewTy == Ty && "Did not convert to correct type!");
Res = new StoreInst(NewVal, VMCI->second, Indices); SrcPtr = new GetElementPtrInst(SrcPtr, Indices,
SrcPtr->getName()+".idx");
// Insert the GEP instruction before this load.
BIL.insert(I, cast<Instruction>(SrcPtr));
} }
Res = new StoreInst(NewVal, SrcPtr);
VMC.ExprMap[I] = Res; VMC.ExprMap[I] = Res;
} else { } else {
@ -1038,16 +1047,25 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
} }
} else { // Replace the source pointer } else { // Replace the source pointer
const Type *ValTy = cast<PointerType>(NewTy)->getElementType(); const Type *ValTy = cast<PointerType>(NewTy)->getElementType();
std::vector<Value*> Indices;
Value *SrcPtr = NewVal;
if (isa<StructType>(ValTy)) { if (isa<StructType>(ValTy)) {
unsigned Offset = 0; std::vector<Value*> Indices;
Indices.push_back(ConstantUInt::get(Type::UIntTy, 0)); Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
unsigned Offset = 0;
ValTy = getStructOffsetType(ValTy, Offset, Indices, false); ValTy = getStructOffsetType(ValTy, Offset, Indices, false);
assert(Offset == 0 && ValTy); assert(Offset == 0 && ValTy);
SrcPtr = new GetElementPtrInst(SrcPtr, Indices,
SrcPtr->getName()+".idx");
// Insert the GEP instruction before this load.
BIL.insert(I, cast<Instruction>(SrcPtr));
} }
Res = new StoreInst(Constant::getNullValue(ValTy), NewVal, Indices); Res = new StoreInst(Constant::getNullValue(ValTy), SrcPtr);
VMC.ExprMap[I] = Res; VMC.ExprMap[I] = Res;
Res->setOperand(0, ConvertExpressionToType(I->getOperand(0), ValTy, VMC)); Res->setOperand(0, ConvertExpressionToType(I->getOperand(0), ValTy, VMC));
} }