From b9d9e0ff8d4c5c505212448109bf5d2825bde9c5 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 11 Sep 2002 01:21:29 +0000 Subject: [PATCH] - Change getelementptr instruction to use long indexes instead of uint indexes for sequential types. llvm-svn: 3681 --- llvm/lib/CWriter/Writer.cpp | 4 +- .../InstrSelection/InstrSelectionSupport.cpp | 16 ++++---- llvm/lib/Transforms/ExprTypeConvert.cpp | 37 +++++++++---------- .../Instrumentation/ProfilePaths/EdgeCode.cpp | 22 +++++------ .../Instrumentation/TraceValues.cpp | 2 +- llvm/lib/Transforms/LevelRaise.cpp | 4 +- llvm/lib/Transforms/TransformInternals.cpp | 14 +++---- 7 files changed, 47 insertions(+), 52 deletions(-) diff --git a/llvm/lib/CWriter/Writer.cpp b/llvm/lib/CWriter/Writer.cpp index 941af03af2be..bc3829f67cdb 100644 --- a/llvm/lib/CWriter/Writer.cpp +++ b/llvm/lib/CWriter/Writer.cpp @@ -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(Ptr->getType())->getElementType()); Out << ")]"; } else { - Out << ".field" << cast(*I)->getValue(); + Out << ".field" << cast(*I)->getValue(); } } diff --git a/llvm/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp b/llvm/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp index 870bbbd7879e..036b1a7f3f2c 100644 --- a/llvm/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp +++ b/llvm/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp @@ -113,12 +113,12 @@ static Value* FoldGetElemChain(InstrTreeNode* ptrNode, vector& chainIdxVec) { InstructionNode* gepNode = dyn_cast(ptrNode); - if (gepNode == NULL) - return NULL; // ptr value is not computed in this tree - GetElementPtrInst* gepInst = - dyn_cast(gepNode->getInstruction()); - if (gepInst == NULL) // ptr value does not come from GEP instruction + dyn_cast_or_null(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& chainIdxVec) ptrVal = gepInst->getPointerOperand(); // Check for a leading [0] index, if any. It will be discarded later. - ConstantUInt* CV = dyn_cast((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& 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; } diff --git a/llvm/lib/Transforms/ExprTypeConvert.cpp b/llvm/lib/Transforms/ExprTypeConvert.cpp index ab56c5270db8..4abbbeb167c2 100644 --- a/llvm/lib/Transforms/ExprTypeConvert.cpp +++ b/llvm/lib/Transforms/ExprTypeConvert.cpp @@ -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(Indices.back()) && - cast(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(Ty)->getElementType(); Res = 0; - while (!Indices.empty() && isa(Indices.back()) && - cast(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(LoadedTy)) { std::vector 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(ElTy); std::vector 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(ValTy)) { std::vector 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); } diff --git a/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp b/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp index 2e5c0e7ffe65..b8edb2260ad9 100644 --- a/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp +++ b/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp @@ -55,9 +55,9 @@ static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo, //M->getGlobalList().push_back(gbl); - vector elargs; - elargs.push_back(ConstantUInt::get(Type::UIntTy, 0)); - elargs.push_back(ConstantUInt::get(Type::UIntTy, 0)); + //vector 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(1,ConstantUInt::get(Type::UIntTy, inc)), + vector(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(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(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 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(1,ConstantUInt::get(Type::UIntTy, i)), + vector(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); } diff --git a/llvm/lib/Transforms/Instrumentation/TraceValues.cpp b/llvm/lib/Transforms/Instrumentation/TraceValues.cpp index f3fc7ba32271..5abfe2723874 100644 --- a/llvm/lib/Transforms/Instrumentation/TraceValues.cpp +++ b/llvm/lib/Transforms/Instrumentation/TraceValues.cpp @@ -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(2,ConstantUInt::get(Type::UIntTy, 0)), + vector(2,ConstantSInt::get(Type::LongTy, 0)), "trstr", InsertBefore); // Insert a call to the hash function if this is a pointer value diff --git a/llvm/lib/Transforms/LevelRaise.cpp b/llvm/lib/Transforms/LevelRaise.cpp index 92f2f79381c9..fd32251bea80 100644 --- a/llvm/lib/Transforms/LevelRaise.cpp +++ b/llvm/lib/Transforms/LevelRaise.cpp @@ -323,7 +323,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) { // Build the index vector, full of all zeros std::vector Indices; - Indices.push_back(ConstantUInt::get(Type::UIntTy, 0)); + Indices.push_back(ConstantSInt::get(Type::LongTy, 0)); while (CurCTy && !isa(CurCTy)) { if (const StructType *CurSTy = dyn_cast(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; diff --git a/llvm/lib/Transforms/TransformInternals.cpp b/llvm/lib/Transforms/TransformInternals.cpp index f9ee232b08f8..85868320763e 100644 --- a/llvm/lib/Transforms/TransformInternals.cpp +++ b/llvm/lib/Transforms/TransformInternals.cpp @@ -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(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 }