- Change getelementptr instruction to use long indexes instead of uint

indexes for sequential types.

llvm-svn: 3681
This commit is contained in:
Chris Lattner 2002-09-11 01:21:29 +00:00
parent 236c129844
commit b9d9e0ff8d
7 changed files with 47 additions and 52 deletions

View File

@ -916,7 +916,7 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I,
}
for (; I != E; ++I)
if ((*I)->getType() == Type::UIntTy) {
if ((*I)->getType() == Type::LongTy) {
Out << "[((int) ("; // sign-extend from 32 (to 64) bits
writeOperand(*I);
Out << " * sizeof(";
@ -925,7 +925,7 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I,
printType(cast<PointerType>(Ptr->getType())->getElementType());
Out << ")]";
} else {
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
Out << ".field" << cast<ConstantSInt>(*I)->getValue();
}
}

View File

@ -113,12 +113,12 @@ static Value*
FoldGetElemChain(InstrTreeNode* ptrNode, vector<Value*>& chainIdxVec)
{
InstructionNode* gepNode = dyn_cast<InstructionNode>(ptrNode);
if (gepNode == NULL)
return NULL; // ptr value is not computed in this tree
GetElementPtrInst* gepInst =
dyn_cast<GetElementPtrInst>(gepNode->getInstruction());
if (gepInst == NULL) // ptr value does not come from GEP instruction
dyn_cast_or_null<GetElementPtrInst>(gepNode->getInstruction());
// ptr value is not computed in this tree or ptr value does not come from GEP
// instruction
if (gepInst == NULL)
return NULL;
// Return NULL if we don't fold any instructions in.
@ -149,8 +149,8 @@ FoldGetElemChain(InstrTreeNode* ptrNode, vector<Value*>& chainIdxVec)
ptrVal = gepInst->getPointerOperand();
// Check for a leading [0] index, if any. It will be discarded later.
ConstantUInt* CV = dyn_cast<ConstantUInt>((Value*) *firstIdx);
hasLeadingZero = bool(CV && CV->getValue() == 0);
hasLeadingZero = (*firstIdx ==
Constant::getNullValue((*firstIdx)->getType()));
// Insert its index vector at the start, skipping any leading [0]
chainIdxVec.insert(chainIdxVec.begin(),
@ -168,7 +168,7 @@ FoldGetElemChain(InstrTreeNode* ptrNode, vector<Value*>& chainIdxVec)
// If the first getElementPtr instruction had a leading [0], add it back.
// Note that this instruction is the *last* one successfully folded above.
if (ptrVal && hasLeadingZero)
chainIdxVec.insert(chainIdxVec.begin(), ConstantUInt::get(Type::UIntTy,0));
chainIdxVec.insert(chainIdxVec.begin(), ConstantSInt::get(Type::LongTy,0));
return ptrVal;
}

View File

@ -233,8 +233,8 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
const Type *BaseType = GEP->getPointerOperand()->getType();
const Type *ElTy = 0;
while (!Indices.empty() && isa<ConstantUInt>(Indices.back()) &&
cast<ConstantUInt>(Indices.back())->getValue() == 0) {
while (!Indices.empty() &&
Indices.back() == Constant::getNullValue(Indices.back()->getType())){
Indices.pop_back();
ElTy = GetElementPtrInst::getIndexedType(BaseType, Indices, true);
if (ElTy == PVTy)
@ -245,11 +245,11 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
if (ElTy) break; // Found a number of zeros we can strip off!
// Otherwise, we can convert a GEP from one form to the other iff the
// current gep is of the form 'getelementptr sbyte*, unsigned N
// current gep is of the form 'getelementptr sbyte*, long N
// and we could convert this to an appropriate GEP for the new type.
//
if (GEP->getNumOperands() == 2 &&
GEP->getOperand(1)->getType() == Type::UIntTy &&
GEP->getOperand(1)->getType() == Type::LongTy &&
GEP->getType() == PointerType::get(Type::SByteTy)) {
// Do not Check to see if our incoming pointer can be converted
@ -272,12 +272,12 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
}
// Otherwise, it could be that we have something like this:
// getelementptr [[sbyte] *] * %reg115, uint %reg138 ; [sbyte]**
// getelementptr [[sbyte] *] * %reg115, long %reg138 ; [sbyte]**
// and want to convert it into something like this:
// getelemenptr [[int] *] * %reg115, uint %reg138 ; [int]**
// getelemenptr [[int] *] * %reg115, long %reg138 ; [int]**
//
if (GEP->getNumOperands() == 2 &&
GEP->getOperand(1)->getType() == Type::UIntTy &&
GEP->getOperand(1)->getType() == Type::LongTy &&
TD.getTypeSize(PTy->getElementType()) ==
TD.getTypeSize(GEP->getType()->getElementType())) {
const PointerType *NewSrcTy = PointerType::get(PVTy);
@ -425,21 +425,20 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
const Type *BaseType = GEP->getPointerOperand()->getType();
const Type *PVTy = cast<PointerType>(Ty)->getElementType();
Res = 0;
while (!Indices.empty() && isa<ConstantUInt>(Indices.back()) &&
cast<ConstantUInt>(Indices.back())->getValue() == 0) {
while (!Indices.empty() &&
Indices.back() == Constant::getNullValue(Indices.back()->getType())){
Indices.pop_back();
if (GetElementPtrInst::getIndexedType(BaseType, Indices, true) == PVTy) {
if (Indices.size() == 0) {
Res = new CastInst(GEP->getPointerOperand(), BaseType); // NOOP
} else {
if (Indices.size() == 0)
Res = new CastInst(GEP->getPointerOperand(), BaseType); // NOOP CAST
else
Res = new GetElementPtrInst(GEP->getPointerOperand(), Indices, Name);
}
break;
}
}
if (Res == 0 && GEP->getNumOperands() == 2 &&
GEP->getOperand(1)->getType() == Type::UIntTy &&
GEP->getOperand(1)->getType() == Type::LongTy &&
GEP->getType() == PointerType::get(Type::SByteTy)) {
// Otherwise, we can convert a GEP from one form to the other iff the
@ -749,7 +748,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
//
if (DataSize != 1) {
TempScale = BinaryOperator::create(Instruction::Mul, Index,
ConstantUInt::get(Type::UIntTy,
ConstantSInt::get(Type::LongTy,
DataSize));
Index = TempScale;
}
@ -952,7 +951,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
if (const CompositeType *CT = dyn_cast<CompositeType>(LoadedTy)) {
std::vector<Value*> Indices;
Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
Indices.push_back(ConstantSInt::get(Type::LongTy, 0));
unsigned Offset = 0; // No offset, get first leaf.
LoadedTy = getStructOffsetType(CT, Offset, Indices, false);
@ -988,7 +987,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
const StructType *SElTy = cast<StructType>(ElTy);
std::vector<Value*> Indices;
Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
Indices.push_back(Constant::getNullValue(Type::LongTy));
unsigned Offset = 0;
const Type *Ty = getStructOffsetType(ElTy, Offset, Indices, false);
@ -1017,7 +1016,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
if (isa<StructType>(ValTy)) {
std::vector<Value*> Indices;
Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
Indices.push_back(Constant::getNullValue(Type::LongTy));
unsigned Offset = 0;
ValTy = getStructOffsetType(ValTy, Offset, Indices, false);
@ -1049,7 +1048,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
if (DataSize != 1) {
// Insert a multiply of the old element type is not a unit size...
Index = BinaryOperator::create(Instruction::Mul, Index,
ConstantUInt::get(Type::UIntTy, DataSize),
ConstantSInt::get(Type::LongTy, DataSize),
"scale", It);
}

View File

@ -55,9 +55,9 @@ static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
//M->getGlobalList().push_back(gbl);
vector<Value *> elargs;
elargs.push_back(ConstantUInt::get(Type::UIntTy, 0));
elargs.push_back(ConstantUInt::get(Type::UIntTy, 0));
//vector<Value *> elargs;
//elargs.push_back(ConstantSInt::get(Type::LongTy, 0));
//elargs.push_back(ConstantSInt::get(Type::LongTy, 0));
// commented out bb name frm which its called
//Instruction *getElmntInst=new GetElementPtrInst(gbl,elargs,"elmntInst");
@ -119,7 +119,7 @@ void getEdgeCode::getCode(Instruction *rInst,
assert(inc>=0 && inc<=numPaths && "inc out of bound!");
Instruction *Idx = new GetElementPtrInst(countInst,
vector<Value*>(1,ConstantUInt::get(Type::UIntTy, inc)),
vector<Value*>(1,ConstantSInt::get(Type::LongTy, inc)),
"", InsertPos);
Instruction *ldInst=new LoadInst(Idx, "ti1", InsertPos);
@ -154,7 +154,7 @@ void getEdgeCode::getCode(Instruction *rInst,
//now load count[addIndex]
Instruction *castInst=new CastInst(addIndex,
Type::UIntTy,"ctin", InsertPos);
Type::LongTy,"ctin", InsertPos);
Instruction *Idx = new GetElementPtrInst(countInst,
vector<Value*>(1,castInst), "",
InsertPos);
@ -184,7 +184,7 @@ void getEdgeCode::getCode(Instruction *rInst,
Instruction *ldIndex=new LoadInst(rInst, "ti1", InsertPos);
//now load count[addIndex]
Instruction *castInst2=new CastInst(ldIndex, Type::UIntTy,"ctin",InsertPos);
Instruction *castInst2=new CastInst(ldIndex, Type::LongTy,"ctin",InsertPos);
Instruction *Idx = new GetElementPtrInst(countInst,
vector<Value*>(1,castInst2), "",
InsertPos);
@ -236,10 +236,6 @@ void insertInTopBB(BasicBlock *front,
Value *Int0 = ConstantInt::get(Type::IntTy, 0);
//store uint 0, uint *%R, uint 0
vector<Value *> idx;
idx.push_back(ConstantUInt::get(Type::UIntTy, 0));
//now push all instructions in front of the BB
BasicBlock::iterator here=front->begin();
front->getInstList().insert(here, rVar);
@ -249,13 +245,13 @@ void insertInTopBB(BasicBlock *front,
for (int i=0;i<k; i++){
Value *GEP2 = new GetElementPtrInst(countVar,
vector<Value *>(1,ConstantUInt::get(Type::UIntTy, i)),
vector<Value *>(1,ConstantSInt::get(Type::LongTy, i)),
"", here);
new StoreInst(Int0, GEP2, here);
}
Instruction *GEP = new GetElementPtrInst(rVar, idx, "", here);
new StoreInst(Int0, GEP, here);
//store uint 0, uint *%R
new StoreInst(Int0, rVar, here);
}

View File

@ -226,7 +226,7 @@ static void InsertPrintInst(Value *V, BasicBlock *BB, Instruction *InsertBefore,
// Turn the format string into an sbyte *
Instruction *GEP =
new GetElementPtrInst(fmtVal,
vector<Value*>(2,ConstantUInt::get(Type::UIntTy, 0)),
vector<Value*>(2,ConstantSInt::get(Type::LongTy, 0)),
"trstr", InsertBefore);
// Insert a call to the hash function if this is a pointer value

View File

@ -323,7 +323,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
// Build the index vector, full of all zeros
std::vector<Value*> Indices;
Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
Indices.push_back(ConstantSInt::get(Type::LongTy, 0));
while (CurCTy && !isa<PointerType>(CurCTy)) {
if (const StructType *CurSTy = dyn_cast<StructType>(CurCTy)) {
// Check for a zero element struct type... if we have one, bail.
@ -338,7 +338,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
}
// Insert a zero to index through this type...
Indices.push_back(ConstantUInt::get(CurCTy->getIndexType(), 0));
Indices.push_back(Constant::getNullValue(CurCTy->getIndexType()));
// Did we find what we're looking for?
if (ElTy->isLosslesslyConvertableTo(DestPointedTy)) break;

View File

@ -66,7 +66,7 @@ const Type *getStructOffsetType(const Type *Ty, unsigned &Offset,
NextType = ATy->getElementType();
unsigned ChildSize = TD.getTypeSize(NextType);
Indices.push_back(ConstantUInt::get(Type::UIntTy, Offset/ChildSize));
Indices.push_back(ConstantSInt::get(Type::LongTy, Offset/ChildSize));
ThisOffset = (Offset/ChildSize)*ChildSize;
} else {
Offset = 0; // Return the offset that we were able to acheive
@ -141,13 +141,13 @@ const Type *ConvertableToGEP(const Type *Ty, Value *OffsetVal,
if (BI) { // Generate code?
BasicBlock *BB = (*BI)->getParent();
if (Expr.Var->getType() != Type::UIntTy)
Expr.Var = new CastInst(Expr.Var, Type::UIntTy,
if (Expr.Var->getType() != Type::LongTy)
Expr.Var = new CastInst(Expr.Var, Type::LongTy,
Expr.Var->getName()+"-idxcast", *BI);
if (ScaleAmt && ScaleAmt != 1) {
// If we have to scale up our index, do so now
Value *ScaleAmtVal = ConstantUInt::get(Type::UIntTy,
Value *ScaleAmtVal = ConstantSInt::get(Type::LongTy,
(unsigned)ScaleAmt);
Expr.Var = BinaryOperator::create(Instruction::Mul, Expr.Var,
ScaleAmtVal,
@ -155,7 +155,7 @@ const Type *ConvertableToGEP(const Type *Ty, Value *OffsetVal,
}
if (Index) { // Add an offset to the index
Value *IndexAmt = ConstantUInt::get(Type::UIntTy, (unsigned)Index);
Value *IndexAmt = ConstantSInt::get(Type::LongTy, (unsigned)Index);
Expr.Var = BinaryOperator::create(Instruction::Add, Expr.Var,
IndexAmt,
Expr.Var->getName()+"-offset",
@ -168,14 +168,14 @@ const Type *ConvertableToGEP(const Type *Ty, Value *OffsetVal,
} else if (Offset >= (int)ElSize || -Offset >= (int)ElSize) {
// Calculate the index that we are entering into the array cell with
unsigned Index = Offset/ElSize;
Indices.push_back(ConstantUInt::get(Type::UIntTy, Index));
Indices.push_back(ConstantSInt::get(Type::LongTy, Index));
Offset -= (int)(Index*ElSize); // Consume part of the offset
} else if (isa<ArrayType>(CompTy) || Indices.empty()) {
// Must be indexing a small amount into the first cell of the array
// Just index into element zero of the array here.
//
Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
Indices.push_back(ConstantSInt::get(Type::LongTy, 0));
} else {
return 0; // Hrm. wierd, can't handle this case. Bail
}