Update GEP constructors to use an iterator interface to fix

GLIBCXX_DEBUG issues.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41697 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Greene 2007-09-04 15:46:09 +00:00
parent 3825262399
commit b8f74793b9
21 changed files with 195 additions and 160 deletions

View File

@ -367,6 +367,14 @@ public:
// GetElementPtrInst Class // GetElementPtrInst Class
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// checkType - Simple wrapper function to give a better assertion failure
// message on bad indexes for a gep instruction.
//
static inline const Type *checkType(const Type *Ty) {
assert(Ty && "Invalid GetElementPtrInst indices for type!");
return Ty;
}
/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
/// access elements of arrays and structs /// access elements of arrays and structs
/// ///
@ -380,28 +388,94 @@ class GetElementPtrInst : public Instruction {
OL[i].init(GEPIOL[i], this); OL[i].init(GEPIOL[i], this);
} }
void init(Value *Ptr, Value* const *Idx, unsigned NumIdx); void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
void init(Value *Ptr, Value *Idx0, Value *Idx1);
void init(Value *Ptr, Value *Idx); void init(Value *Ptr, Value *Idx);
template<typename InputIterator>
void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
const std::string &Name,
// This argument ensures that we have an iterator we can
// do arithmetic on in constant time
std::random_access_iterator_tag) {
typename std::iterator_traits<InputIterator>::difference_type NumIdx =
std::distance(IdxBegin, IdxEnd);
if (NumIdx > 0) {
// This requires that the itoerator points to contiguous memory.
init(Ptr, &*IdxBegin, NumIdx);
}
else {
init(Ptr, 0, NumIdx);
}
setName(Name);
}
/// getIndexedType - Returns the type of the element that would be loaded with
/// a load instruction with the specified parameters.
///
/// A null type is returned if the indices are invalid for the specified
/// pointer type.
///
static const Type *getIndexedType(const Type *Ptr,
Value* const *Idx, unsigned NumIdx,
bool AllowStructLeaf = false);
template<typename InputIterator>
static const Type *getIndexedType(const Type *Ptr,
InputIterator IdxBegin,
InputIterator IdxEnd,
bool AllowStructLeaf,
// This argument ensures that we
// have an iterator we can do
// arithmetic on in constant time
std::random_access_iterator_tag) {
typename std::iterator_traits<InputIterator>::difference_type NumIdx =
std::distance(IdxBegin, IdxEnd);
if (NumIdx > 0) {
// This requires that the iterator points to contiguous memory.
return(getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx,
AllowStructLeaf));
}
else {
return(getIndexedType(Ptr, (Value *const*)0, NumIdx, AllowStructLeaf));
}
}
public: public:
/// Constructors - Create a getelementptr instruction with a base pointer an /// Constructors - Create a getelementptr instruction with a base pointer an
/// list of indices. The first ctor can optionally insert before an existing /// list of indices. The first ctor can optionally insert before an existing
/// instruction, the second appends the new instruction to the specified /// instruction, the second appends the new instruction to the specified
/// BasicBlock. /// BasicBlock.
GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx, template<typename InputIterator>
const std::string &Name = "", Instruction *InsertBefore =0); GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx, InputIterator IdxEnd,
const std::string &Name, BasicBlock *InsertAtEnd); const std::string &Name = "",
Instruction *InsertBefore =0)
: Instruction(PointerType::get(
checkType(getIndexedType(Ptr->getType(),
IdxBegin, IdxEnd, true))),
GetElementPtr, 0, 0, InsertBefore) {
init(Ptr, IdxBegin, IdxEnd, Name,
typename std::iterator_traits<InputIterator>::iterator_category());
}
template<typename InputIterator>
GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
const std::string &Name, BasicBlock *InsertAtEnd)
: Instruction(PointerType::get(
checkType(getIndexedType(Ptr->getType(),
IdxBegin, IdxEnd, true))),
GetElementPtr, 0, 0, InsertAtEnd) {
init(Ptr, IdxBegin, IdxEnd, Name,
typename std::iterator_traits<InputIterator>::iterator_category());
}
/// Constructors - These two constructors are convenience methods because one /// Constructors - These two constructors are convenience methods because one
/// and two index getelementptr instructions are so common. /// and two index getelementptr instructions are so common.
GetElementPtrInst(Value *Ptr, Value *Idx, GetElementPtrInst(Value *Ptr, Value *Idx,
const std::string &Name = "", Instruction *InsertBefore =0); const std::string &Name = "", Instruction *InsertBefore =0);
GetElementPtrInst(Value *Ptr, Value *Idx, GetElementPtrInst(Value *Ptr, Value *Idx,
const std::string &Name, BasicBlock *InsertAtEnd); const std::string &Name, BasicBlock *InsertAtEnd);
GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
const std::string &Name = "", Instruction *InsertBefore =0);
GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
const std::string &Name, BasicBlock *InsertAtEnd);
~GetElementPtrInst(); ~GetElementPtrInst();
virtual GetElementPtrInst *clone() const; virtual GetElementPtrInst *clone() const;
@ -417,12 +491,15 @@ public:
/// A null type is returned if the indices are invalid for the specified /// A null type is returned if the indices are invalid for the specified
/// pointer type. /// pointer type.
/// ///
template<typename InputIterator>
static const Type *getIndexedType(const Type *Ptr, static const Type *getIndexedType(const Type *Ptr,
Value* const *Idx, unsigned NumIdx, InputIterator IdxBegin,
bool AllowStructLeaf = false); InputIterator IdxEnd,
bool AllowStructLeaf = false) {
static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1, return(getIndexedType(Ptr, IdxBegin, IdxEnd, AllowStructLeaf,
bool AllowStructLeaf = false); typename std::iterator_traits<InputIterator>::
iterator_category()));
}
static const Type *getIndexedType(const Type *Ptr, Value *Idx); static const Type *getIndexedType(const Type *Ptr, Value *Idx);
inline op_iterator idx_begin() { return op_begin()+1; } inline op_iterator idx_begin() { return op_begin()+1; }

View File

@ -217,16 +217,13 @@ public:
StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) { StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
return Insert(new StoreInst(Val, Ptr, isVolatile)); return Insert(new StoreInst(Val, Ptr, isVolatile));
} }
GetElementPtrInst *CreateGEP(Value *Ptr, Value* const *Idx, unsigned NumIdx, template<typename InputIterator>
const char *Name = "") { GetElementPtrInst *CreateGEP(Value *Ptr, InputIterator IdxBegin,
return Insert(new GetElementPtrInst(Ptr, Idx, NumIdx, Name)); InputIterator IdxEnd, const char *Name = "") {
return(Insert(new GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name)));
} }
GetElementPtrInst *CreateGEP(Value *Ptr, Value *Idx, const char *Name = "") { GetElementPtrInst *CreateGEP(Value *Ptr, Value *Idx, const char *Name = "") {
return Insert(new GetElementPtrInst(Ptr, &Idx, 1, Name)); return Insert(new GetElementPtrInst(Ptr, Idx, Name));
}
GetElementPtrInst *CreateGEP(Value *Ptr, Value *Idx0, Value *Idx1,
const char *Name = "") {
return Insert(new GetElementPtrInst(Ptr, Idx0, Idx1, Name));
} }
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//

View File

@ -1886,7 +1886,7 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
GEN_ERROR("GetElementPtr requires a pointer operand"); GEN_ERROR("GetElementPtr requires a pointer operand");
const Type *IdxTy = const Type *IdxTy =
GetElementPtrInst::getIndexedType($3->getType(), &(*$4)[0], $4->size(), GetElementPtrInst::getIndexedType($3->getType(), $4->begin(), $4->end(),
true); true);
if (!IdxTy) if (!IdxTy)
GEN_ERROR("Index list invalid for constant getelementptr"); GEN_ERROR("Index list invalid for constant getelementptr");
@ -3064,12 +3064,12 @@ MemoryInst : MALLOC Types OptCAlign {
if (!isa<PointerType>($2->get())) if (!isa<PointerType>($2->get()))
GEN_ERROR("getelementptr insn requires pointer operand"); GEN_ERROR("getelementptr insn requires pointer operand");
if (!GetElementPtrInst::getIndexedType(*$2, &(*$4)[0], $4->size(), true)) if (!GetElementPtrInst::getIndexedType(*$2, $4->begin(), $4->end(), true))
GEN_ERROR("Invalid getelementptr indices for type '" + GEN_ERROR("Invalid getelementptr indices for type '" +
(*$2)->getDescription()+ "'"); (*$2)->getDescription()+ "'");
Value* tmpVal = getVal(*$2, $3); Value* tmpVal = getVal(*$2, $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new GetElementPtrInst(tmpVal, &(*$4)[0], $4->size()); $$ = new GetElementPtrInst(tmpVal, $4->begin(), $4->end());
delete $2; delete $2;
delete $4; delete $4;
}; };

View File

@ -1234,7 +1234,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
GEPIdx.push_back(Op); GEPIdx.push_back(Op);
} }
I = new GetElementPtrInst(BasePtr, &GEPIdx[0], GEPIdx.size()); I = new GetElementPtrInst(BasePtr, GEPIdx.begin(), GEPIdx.end());
break; break;
} }

View File

@ -376,8 +376,8 @@ Function *ArgPromotion::DoPromotion(Function *F,
for (ScalarizeTable::iterator SI = ArgIndices.begin(), for (ScalarizeTable::iterator SI = ArgIndices.begin(),
E = ArgIndices.end(); SI != E; ++SI) E = ArgIndices.end(); SI != E; ++SI)
Params.push_back(GetElementPtrInst::getIndexedType(I->getType(), Params.push_back(GetElementPtrInst::getIndexedType(I->getType(),
&(*SI)[0], SI->begin(),
SI->size())); SI->end()));
if (ArgIndices.size() == 1 && ArgIndices.begin()->empty()) if (ArgIndices.size() == 1 && ArgIndices.begin()->empty())
++NumArgumentsPromoted; ++NumArgumentsPromoted;
@ -428,7 +428,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
Value *V = *AI; Value *V = *AI;
LoadInst *OrigLoad = OriginalLoads[*SI]; LoadInst *OrigLoad = OriginalLoads[*SI];
if (!SI->empty()) { if (!SI->empty()) {
V = new GetElementPtrInst(V, &(*SI)[0], SI->size(), V = new GetElementPtrInst(V, SI->begin(), SI->end(),
V->getName()+".idx", Call); V->getName()+".idx", Call);
AA.copyValue(OrigLoad->getOperand(0), V); AA.copyValue(OrigLoad->getOperand(0), V);
} }

View File

@ -464,7 +464,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV) {
Idxs.push_back(NullInt); Idxs.push_back(NullInt);
for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i) for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i)
Idxs.push_back(GEPI->getOperand(i)); Idxs.push_back(GEPI->getOperand(i));
NewPtr = new GetElementPtrInst(NewPtr, &Idxs[0], Idxs.size(), NewPtr = new GetElementPtrInst(NewPtr, Idxs.begin(), Idxs.end(),
GEPI->getName()+"."+utostr(Val), GEPI); GEPI->getName()+"."+utostr(Val), GEPI);
} }
GEP->replaceAllUsesWith(NewPtr); GEP->replaceAllUsesWith(NewPtr);
@ -698,7 +698,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
MI->getAlignment(), MI->getName(), MI); MI->getAlignment(), MI->getName(), MI);
Value* Indices[2]; Value* Indices[2];
Indices[0] = Indices[1] = Constant::getNullValue(Type::Int32Ty); Indices[0] = Indices[1] = Constant::getNullValue(Type::Int32Ty);
Value *NewGEP = new GetElementPtrInst(NewMI, Indices, 2, Value *NewGEP = new GetElementPtrInst(NewMI, Indices, Indices + 2,
NewMI->getName()+".el0", MI); NewMI->getName()+".el0", MI);
MI->replaceAllUsesWith(NewGEP); MI->replaceAllUsesWith(NewGEP);
MI->eraseFromParent(); MI->eraseFromParent();
@ -926,7 +926,7 @@ static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Ptr,
GEPIdx.push_back(GEPI->getOperand(1)); GEPIdx.push_back(GEPI->getOperand(1));
GEPIdx.append(GEPI->op_begin()+3, GEPI->op_end()); GEPIdx.append(GEPI->op_begin()+3, GEPI->op_end());
Value *NGEPI = new GetElementPtrInst(NewPtr, &GEPIdx[0], GEPIdx.size(), Value *NGEPI = new GetElementPtrInst(NewPtr, GEPIdx.begin(), GEPIdx.end(),
GEPI->getName(), GEPI); GEPI->getName(), GEPI);
GEPI->replaceAllUsesWith(NGEPI); GEPI->replaceAllUsesWith(NGEPI);
GEPI->eraseFromParent(); GEPI->eraseFromParent();

View File

@ -945,7 +945,7 @@ Value* GVNPRE::phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ) {
if (newOp1 != U->getPointerOperand() || changed_idx) { if (newOp1 != U->getPointerOperand() || changed_idx) {
Instruction* newVal = new GetElementPtrInst(newOp1, Instruction* newVal = new GetElementPtrInst(newOp1,
&newIdx[0], newIdx.size(), newIdx.begin(), newIdx.end(),
U->getName()+".expr"); U->getName()+".expr");
uint32_t v = VN.lookup_or_add(newVal); uint32_t v = VN.lookup_or_add(newVal);
@ -1675,7 +1675,7 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB,
C->getName()+".gvnpre", C->getName()+".gvnpre",
(*PI)->getTerminator()); (*PI)->getTerminator());
else if (GetElementPtrInst* G = dyn_cast<GetElementPtrInst>(U)) else if (GetElementPtrInst* G = dyn_cast<GetElementPtrInst>(U))
newVal = new GetElementPtrInst(s1, &sVarargs[0], sVarargs.size(), newVal = new GetElementPtrInst(s1, sVarargs.begin(), sVarargs.end(),
G->getName()+".gvnpre", G->getName()+".gvnpre",
(*PI)->getTerminator()); (*PI)->getTerminator());

View File

@ -178,8 +178,11 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN,
Constant *NCE = ConstantExpr::getGetElementPtr(CE->getOperand(0), Constant *NCE = ConstantExpr::getGetElementPtr(CE->getOperand(0),
&CEIdxs[0], &CEIdxs[0],
CEIdxs.size()); CEIdxs.size());
Value *Idx[2];
Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = NewAdd;
GetElementPtrInst *NGEPI = new GetElementPtrInst( GetElementPtrInst *NGEPI = new GetElementPtrInst(
NCE, Constant::getNullValue(Type::Int32Ty), NewAdd, NCE, Idx, Idx + 2,
GEPI->getName(), GEPI); GEPI->getName(), GEPI);
SE->deleteValueFromRecords(GEPI); SE->deleteValueFromRecords(GEPI);
GEPI->replaceAllUsesWith(NGEPI); GEPI->replaceAllUsesWith(NGEPI);

View File

@ -6564,8 +6564,9 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) {
// If we were able to index down into an element, create the GEP // If we were able to index down into an element, create the GEP
// and bitcast the result. This eliminates one bitcast, potentially // and bitcast the result. This eliminates one bitcast, potentially
// two. // two.
Instruction *NGEP = new GetElementPtrInst(OrigBase, &NewIndices[0], Instruction *NGEP = new GetElementPtrInst(OrigBase,
NewIndices.size(), ""); NewIndices.begin(),
NewIndices.end(), "");
InsertNewInstBefore(NGEP, CI); InsertNewInstBefore(NGEP, CI);
NGEP->takeName(GEP); NGEP->takeName(GEP);
@ -7057,7 +7058,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
// If we found a path from the src to dest, create the getelementptr now. // If we found a path from the src to dest, create the getelementptr now.
if (SrcElTy == DstElTy) { if (SrcElTy == DstElTy) {
SmallVector<Value*, 8> Idxs(NumZeros+1, ZeroUInt); SmallVector<Value*, 8> Idxs(NumZeros+1, ZeroUInt);
return new GetElementPtrInst(Src, &Idxs[0], Idxs.size()); return new GetElementPtrInst(Src, Idxs.begin(), Idxs.end());
} }
} }
@ -8502,8 +8503,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
} }
if (!Indices.empty()) if (!Indices.empty())
return new GetElementPtrInst(SrcGEPOperands[0], &Indices[0], return new GetElementPtrInst(SrcGEPOperands[0], Indices.begin(),
Indices.size(), GEP.getName()); Indices.end(), GEP.getName());
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(PtrOp)) { } else if (GlobalValue *GV = dyn_cast<GlobalValue>(PtrOp)) {
// GEP of global variable. If all of the indices for this GEP are // GEP of global variable. If all of the indices for this GEP are
@ -8554,9 +8555,11 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
if (isa<ArrayType>(SrcElTy) && if (isa<ArrayType>(SrcElTy) &&
TD->getTypeSize(cast<ArrayType>(SrcElTy)->getElementType()) == TD->getTypeSize(cast<ArrayType>(SrcElTy)->getElementType()) ==
TD->getTypeSize(ResElTy)) { TD->getTypeSize(ResElTy)) {
Value *Idx[2];
Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = GEP.getOperand(1);
Value *V = InsertNewInstBefore( Value *V = InsertNewInstBefore(
new GetElementPtrInst(X, Constant::getNullValue(Type::Int32Ty), new GetElementPtrInst(X, Idx, Idx + 2, GEP.getName()), GEP);
GEP.getOperand(1), GEP.getName()), GEP);
// V and GEP are both pointer types --> BitCast // V and GEP are both pointer types --> BitCast
return new BitCastInst(V, GEP.getType()); return new BitCastInst(V, GEP.getType());
} }
@ -8609,9 +8612,11 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
} }
// Insert the new GEP instruction. // Insert the new GEP instruction.
Value *Idx[2];
Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = NewIdx;
Instruction *NewGEP = Instruction *NewGEP =
new GetElementPtrInst(X, Constant::getNullValue(Type::Int32Ty), new GetElementPtrInst(X, Idx, Idx + 2, GEP.getName());
NewIdx, GEP.getName());
NewGEP = InsertNewInstBefore(NewGEP, GEP); NewGEP = InsertNewInstBefore(NewGEP, GEP);
// The NewGEP must be pointer typed, so must the old one -> BitCast // The NewGEP must be pointer typed, so must the old one -> BitCast
return new BitCastInst(NewGEP, GEP.getType()); return new BitCastInst(NewGEP, GEP.getType());
@ -8651,7 +8656,10 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
// insert our getelementptr instruction... // insert our getelementptr instruction...
// //
Value *NullIdx = Constant::getNullValue(Type::Int32Ty); Value *NullIdx = Constant::getNullValue(Type::Int32Ty);
Value *V = new GetElementPtrInst(New, NullIdx, NullIdx, Value *Idx[2];
Idx[0] = NullIdx;
Idx[1] = NullIdx;
Value *V = new GetElementPtrInst(New, Idx, Idx + 2,
New->getName()+".sub", It); New->getName()+".sub", It);
// Now make everything use the getelementptr instead of the original // Now make everything use the getelementptr instead of the original

View File

@ -242,8 +242,11 @@ bool LowerGC::runOnFunction(Function &F) {
Constant *Zero = ConstantInt::get(Type::Int32Ty, 0); Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
Constant *One = ConstantInt::get(Type::Int32Ty, 1); Constant *One = ConstantInt::get(Type::Int32Ty, 1);
Value *Idx[2] = { Zero, Zero };
// Get a pointer to the prev pointer. // Get a pointer to the prev pointer.
Value *PrevPtrPtr = new GetElementPtrInst(AI, Zero, Zero, "prevptrptr", IP); Value *PrevPtrPtr = new GetElementPtrInst(AI, Idx, Idx + 2,
"prevptrptr", IP);
// Load the previous pointer. // Load the previous pointer.
Value *PrevPtr = new LoadInst(RootChain, "prevptr", IP); Value *PrevPtr = new LoadInst(RootChain, "prevptr", IP);
@ -251,7 +254,9 @@ bool LowerGC::runOnFunction(Function &F) {
new StoreInst(PrevPtr, PrevPtrPtr, IP); new StoreInst(PrevPtr, PrevPtrPtr, IP);
// Set the number of elements in this record. // Set the number of elements in this record.
Value *NumEltsPtr = new GetElementPtrInst(AI, Zero, One, "numeltsptr", IP); Idx[1] = One;
Value *NumEltsPtr = new GetElementPtrInst(AI, Idx, Idx + 2,
"numeltsptr", IP);
new StoreInst(ConstantInt::get(Type::Int32Ty, GCRoots.size()), NumEltsPtr,IP); new StoreInst(ConstantInt::get(Type::Int32Ty, GCRoots.size()), NumEltsPtr,IP);
Value* Par[4]; Value* Par[4];
@ -267,13 +272,15 @@ bool LowerGC::runOnFunction(Function &F) {
// Initialize the meta-data pointer. // Initialize the meta-data pointer.
Par[2] = ConstantInt::get(Type::Int32Ty, i); Par[2] = ConstantInt::get(Type::Int32Ty, i);
Par[3] = One; Par[3] = One;
Value *MetaDataPtr = new GetElementPtrInst(AI, Par, 4, "MetaDataPtr", IP); Value *MetaDataPtr = new GetElementPtrInst(AI, Par, Par + 4,
"MetaDataPtr", IP);
assert(isa<Constant>(GCRoots[i]->getOperand(2)) && "Must be a constant"); assert(isa<Constant>(GCRoots[i]->getOperand(2)) && "Must be a constant");
new StoreInst(GCRoots[i]->getOperand(2), MetaDataPtr, IP); new StoreInst(GCRoots[i]->getOperand(2), MetaDataPtr, IP);
// Initialize the root pointer to null on entry to the function. // Initialize the root pointer to null on entry to the function.
Par[3] = Zero; Par[3] = Zero;
Value *RootPtrPtr = new GetElementPtrInst(AI, Par, 4, "RootEntPtr", IP); Value *RootPtrPtr = new GetElementPtrInst(AI, Par, Par + 4,
"RootEntPtr", IP);
new StoreInst(Null, RootPtrPtr, IP); new StoreInst(Null, RootPtrPtr, IP);
// Each occurrance of the llvm.gcroot intrinsic now turns into an // Each occurrance of the llvm.gcroot intrinsic now turns into an

View File

@ -235,7 +235,7 @@ void LowerPacked::visitLoadInst(LoadInst& LI)
// Get the pointer // Get the pointer
Value* val = new GetElementPtrInst(array, Value* val = new GetElementPtrInst(array,
&Idx[0], Idx.size(), Idx.begin(), Idx.end(),
LI.getName() + LI.getName() +
".ge." + utostr(i), ".ge." + utostr(i),
&LI); &LI);
@ -333,7 +333,7 @@ void LowerPacked::visitStoreInst(StoreInst& SI)
// Generate the indices for getelementptr // Generate the indices for getelementptr
Idx[1] = ConstantInt::get(Type::Int32Ty,i); Idx[1] = ConstantInt::get(Type::Int32Ty,i);
Value* val = new GetElementPtrInst(array, Value* val = new GetElementPtrInst(array,
&Idx[0], Idx.size(), Idx.begin(), Idx.end(),
"store.ge." + "store.ge." +
utostr(i) + ".", utostr(i) + ".",
&SI); &SI);

View File

@ -319,8 +319,8 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
SmallVector<Value*, 8> NewArgs; SmallVector<Value*, 8> NewArgs;
NewArgs.push_back(Constant::getNullValue(Type::Int32Ty)); NewArgs.push_back(Constant::getNullValue(Type::Int32Ty));
NewArgs.append(GEPI->op_begin()+3, GEPI->op_end()); NewArgs.append(GEPI->op_begin()+3, GEPI->op_end());
RepValue = new GetElementPtrInst(AllocaToUse, &NewArgs[0], RepValue = new GetElementPtrInst(AllocaToUse, NewArgs.begin(),
NewArgs.size(), "", GEPI); NewArgs.end(), "", GEPI);
RepValue->takeName(GEPI); RepValue->takeName(GEPI);
} }
@ -626,8 +626,10 @@ void SROA::RewriteBitCastUserOfAlloca(Instruction *BCInst, AllocationInst *AI,
// If this is a memcpy/memmove, emit a GEP of the other element address. // If this is a memcpy/memmove, emit a GEP of the other element address.
Value *OtherElt = 0; Value *OtherElt = 0;
if (OtherPtr) { if (OtherPtr) {
OtherElt = new GetElementPtrInst(OtherPtr, Zero, Value *Idx[2];
ConstantInt::get(Type::Int32Ty, i), Idx[0] = Zero;
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
OtherElt = new GetElementPtrInst(OtherPtr, Idx, Idx + 2,
OtherPtr->getNameStr()+"."+utostr(i), OtherPtr->getNameStr()+"."+utostr(i),
MI); MI);
} }
@ -829,11 +831,13 @@ void SROA::CanonicalizeAllocaUsers(AllocationInst *AI) {
SmallVector<Value*, 8> Indices(GEPI->op_begin()+1, GEPI->op_end()); SmallVector<Value*, 8> Indices(GEPI->op_begin()+1, GEPI->op_end());
Indices[1] = Constant::getNullValue(Type::Int32Ty); Indices[1] = Constant::getNullValue(Type::Int32Ty);
Value *ZeroIdx = new GetElementPtrInst(GEPI->getOperand(0), Value *ZeroIdx = new GetElementPtrInst(GEPI->getOperand(0),
&Indices[0], Indices.size(), Indices.begin(),
Indices.end(),
GEPI->getName()+".0", GEPI); GEPI->getName()+".0", GEPI);
Indices[1] = ConstantInt::get(Type::Int32Ty, 1); Indices[1] = ConstantInt::get(Type::Int32Ty, 1);
Value *OneIdx = new GetElementPtrInst(GEPI->getOperand(0), Value *OneIdx = new GetElementPtrInst(GEPI->getOperand(0),
&Indices[0], Indices.size(), Indices.begin(),
Indices.end(),
GEPI->getName()+".1", GEPI); GEPI->getName()+".1", GEPI);
// Replace all loads of the variable index GEP with loads from both // Replace all loads of the variable index GEP with loads from both
// indexes and a select. // indexes and a select.

View File

@ -294,11 +294,12 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
for (unsigned i = 0, e = inputs.size(); i != e; ++i) { for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
Value *RewriteVal; Value *RewriteVal;
if (AggregateArgs) { if (AggregateArgs) {
Value *Idx0 = Constant::getNullValue(Type::Int32Ty); Value *Idx[2];
Value *Idx1 = ConstantInt::get(Type::Int32Ty, i); Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
std::string GEPname = "gep_" + inputs[i]->getName(); std::string GEPname = "gep_" + inputs[i]->getName();
TerminatorInst *TI = newFunction->begin()->getTerminator(); TerminatorInst *TI = newFunction->begin()->getTerminator();
GetElementPtrInst *GEP = new GetElementPtrInst(AI, Idx0, Idx1, GetElementPtrInst *GEP = new GetElementPtrInst(AI, Idx, Idx+2,
GEPname, TI); GEPname, TI);
RewriteVal = new LoadInst(GEP, "load" + GEPname, TI); RewriteVal = new LoadInst(GEP, "load" + GEPname, TI);
} else } else
@ -381,10 +382,11 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
params.push_back(Struct); params.push_back(Struct);
for (unsigned i = 0, e = inputs.size(); i != e; ++i) { for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
Value *Idx0 = Constant::getNullValue(Type::Int32Ty); Value *Idx[2];
Value *Idx1 = ConstantInt::get(Type::Int32Ty, i); Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
GetElementPtrInst *GEP = GetElementPtrInst *GEP =
new GetElementPtrInst(Struct, Idx0, Idx1, new GetElementPtrInst(Struct, Idx, Idx + 2,
"gep_" + StructValues[i]->getName()); "gep_" + StructValues[i]->getName());
codeReplacer->getInstList().push_back(GEP); codeReplacer->getInstList().push_back(GEP);
StoreInst *SI = new StoreInst(StructValues[i], GEP); StoreInst *SI = new StoreInst(StructValues[i], GEP);
@ -406,10 +408,11 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
for (unsigned i = 0, e = outputs.size(); i != e; ++i) { for (unsigned i = 0, e = outputs.size(); i != e; ++i) {
Value *Output = 0; Value *Output = 0;
if (AggregateArgs) { if (AggregateArgs) {
Value *Idx0 = Constant::getNullValue(Type::Int32Ty); Value *Idx[2];
Value *Idx1 = ConstantInt::get(Type::Int32Ty, FirstOut + i); Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i);
GetElementPtrInst *GEP GetElementPtrInst *GEP
= new GetElementPtrInst(Struct, Idx0, Idx1, = new GetElementPtrInst(Struct, Idx, Idx + 2,
"gep_reload_" + outputs[i]->getName()); "gep_reload_" + outputs[i]->getName());
codeReplacer->getInstList().push_back(GEP); codeReplacer->getInstList().push_back(GEP);
Output = GEP; Output = GEP;
@ -506,10 +509,11 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
if (DominatesDef) { if (DominatesDef) {
if (AggregateArgs) { if (AggregateArgs) {
Value *Idx0 = Constant::getNullValue(Type::Int32Ty); Value *Idx[2];
Value *Idx1 = ConstantInt::get(Type::Int32Ty,FirstOut+out); Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out);
GetElementPtrInst *GEP = GetElementPtrInst *GEP =
new GetElementPtrInst(OAI, Idx0, Idx1, new GetElementPtrInst(OAI, Idx, Idx + 2,
"gep_" + outputs[out]->getName(), "gep_" + outputs[out]->getName(),
NTRet); NTRet);
new StoreInst(outputs[out], GEP, NTRet); new StoreInst(outputs[out], GEP, NTRet);

View File

@ -450,8 +450,8 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
std::vector<Value*> Idx; std::vector<Value*> Idx;
Idx.push_back(Constant::getNullValue(Type::Int32Ty)); Idx.push_back(Constant::getNullValue(Type::Int32Ty));
Idx.push_back(ConstantInt::get(Type::Int32Ty, 1)); Idx.push_back(ConstantInt::get(Type::Int32Ty, 1));
OldJmpBufPtr = new GetElementPtrInst(JmpBuf, &Idx[0], 2, "OldBuf", OldJmpBufPtr = new GetElementPtrInst(JmpBuf, Idx.begin(), Idx.end(),
EntryBB->getTerminator()); "OldBuf", EntryBB->getTerminator());
// Copy the JBListHead to the alloca. // Copy the JBListHead to the alloca.
Value *OldBuf = new LoadInst(JBListHead, "oldjmpbufptr", true, Value *OldBuf = new LoadInst(JBListHead, "oldjmpbufptr", true,
@ -489,7 +489,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
"setjmp.cont"); "setjmp.cont");
Idx[1] = ConstantInt::get(Type::Int32Ty, 0); Idx[1] = ConstantInt::get(Type::Int32Ty, 0);
Value *JmpBufPtr = new GetElementPtrInst(JmpBuf, &Idx[0], Idx.size(), Value *JmpBufPtr = new GetElementPtrInst(JmpBuf, Idx.begin(), Idx.end(),
"TheJmpBuf", "TheJmpBuf",
EntryBB->getTerminator()); EntryBB->getTerminator());
Value *SJRet = new CallInst(SetJmpFn, JmpBufPtr, "sjret", Value *SJRet = new CallInst(SetJmpFn, JmpBufPtr, "sjret",
@ -540,7 +540,8 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
std::vector<Value*> Idx; std::vector<Value*> Idx;
Idx.push_back(Constant::getNullValue(Type::Int32Ty)); Idx.push_back(Constant::getNullValue(Type::Int32Ty));
Idx.push_back(ConstantInt::get(Type::Int32Ty, 0)); Idx.push_back(ConstantInt::get(Type::Int32Ty, 0));
Idx[0] = new GetElementPtrInst(BufPtr, &Idx[0], 2, "JmpBuf", UnwindBlock); Idx[0] = new GetElementPtrInst(BufPtr, Idx.begin(), Idx.end(), "JmpBuf",
UnwindBlock);
Idx[1] = ConstantInt::get(Type::Int32Ty, 1); Idx[1] = ConstantInt::get(Type::Int32Ty, 1);
new CallInst(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock); new CallInst(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock);
new UnreachableInst(UnwindBlock); new UnreachableInst(UnwindBlock);

View File

@ -1350,7 +1350,7 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
} }
Constant *llvm::ConstantFoldGetElementPtr(const Constant *C, Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
Constant* const *Idxs, Constant* const *Idxs,
unsigned NumIdx) { unsigned NumIdx) {
if (NumIdx == 0 || if (NumIdx == 0 ||
(NumIdx == 1 && Idxs[0]->isNullValue())) (NumIdx == 1 && Idxs[0]->isNullValue()))
@ -1358,7 +1358,8 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
if (isa<UndefValue>(C)) { if (isa<UndefValue>(C)) {
const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(),
(Value**)Idxs, NumIdx, (Value **)Idxs,
(Value **)Idxs+NumIdx,
true); true);
assert(Ty != 0 && "Invalid indices for GEP!"); assert(Ty != 0 && "Invalid indices for GEP!");
return UndefValue::get(PointerType::get(Ty)); return UndefValue::get(PointerType::get(Ty));
@ -1374,7 +1375,8 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
} }
if (isNull) { if (isNull) {
const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(),
(Value**)Idxs, NumIdx, (Value**)Idxs,
(Value**)Idxs+NumIdx,
true); true);
assert(Ty != 0 && "Invalid indices for GEP!"); assert(Ty != 0 && "Invalid indices for GEP!");
return ConstantPointerNull::get(PointerType::get(Ty)); return ConstantPointerNull::get(PointerType::get(Ty));

View File

@ -19,6 +19,8 @@
#ifndef CONSTANTFOLDING_H #ifndef CONSTANTFOLDING_H
#define CONSTANTFOLDING_H #define CONSTANTFOLDING_H
#include <iterator>
namespace llvm { namespace llvm {
class Value; class Value;
class Constant; class Constant;
@ -46,6 +48,7 @@ namespace llvm {
Constant *ConstantFoldCompareInstruction(unsigned short predicate, Constant *ConstantFoldCompareInstruction(unsigned short predicate,
const Constant *C1, const Constant *C1,
const Constant *C2); const Constant *C2);
Constant *ConstantFoldGetElementPtr(const Constant *C, Constant *ConstantFoldGetElementPtr(const Constant *C,
Constant* const *Idxs, unsigned NumIdx); Constant* const *Idxs, unsigned NumIdx);
} // End llvm namespace } // End llvm namespace

View File

@ -1799,7 +1799,7 @@ Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C, Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
Value* const *Idxs, Value* const *Idxs,
unsigned NumIdx) { unsigned NumIdx) {
assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs, NumIdx, true) && assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx, true) &&
"GEP indices invalid!"); "GEP indices invalid!");
if (Constant *FC = ConstantFoldGetElementPtr(C, (Constant**)Idxs, NumIdx)) if (Constant *FC = ConstantFoldGetElementPtr(C, (Constant**)Idxs, NumIdx))
@ -1821,7 +1821,7 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
unsigned NumIdx) { unsigned NumIdx) {
// Get the result type of the getelementptr! // Get the result type of the getelementptr!
const Type *Ty = const Type *Ty =
GetElementPtrInst::getIndexedType(C->getType(), Idxs, NumIdx, true); GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx, true);
assert(Ty && "GEP indices invalid!"); assert(Ty && "GEP indices invalid!");
return getGetElementPtrTy(PointerType::get(Ty), C, Idxs, NumIdx); return getGetElementPtrTy(PointerType::get(Ty), C, Idxs, NumIdx);
} }

View File

@ -864,14 +864,6 @@ void StoreInst::setAlignment(unsigned Align) {
// GetElementPtrInst Implementation // GetElementPtrInst Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// checkType - Simple wrapper function to give a better assertion failure
// message on bad indexes for a gep instruction.
//
static inline const Type *checkType(const Type *Ty) {
assert(Ty && "Invalid GetElementPtrInst indices for type!");
return Ty;
}
void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) { void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
NumOperands = 1+NumIdx; NumOperands = 1+NumIdx;
Use *OL = OperandList = new Use[NumOperands]; Use *OL = OperandList = new Use[NumOperands];
@ -881,14 +873,6 @@ void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
OL[i+1].init(Idx[i], this); OL[i+1].init(Idx[i], this);
} }
void GetElementPtrInst::init(Value *Ptr, Value *Idx0, Value *Idx1) {
NumOperands = 3;
Use *OL = OperandList = new Use[3];
OL[0].init(Ptr, this);
OL[1].init(Idx0, this);
OL[2].init(Idx1, this);
}
void GetElementPtrInst::init(Value *Ptr, Value *Idx) { void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
NumOperands = 2; NumOperands = 2;
Use *OL = OperandList = new Use[2]; Use *OL = OperandList = new Use[2];
@ -896,27 +880,6 @@ void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
OL[1].init(Idx, this); OL[1].init(Idx, this);
} }
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx,
unsigned NumIdx,
const std::string &Name, Instruction *InBe)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
Idx, NumIdx, true))),
GetElementPtr, 0, 0, InBe) {
init(Ptr, Idx, NumIdx);
setName(Name);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx,
unsigned NumIdx,
const std::string &Name, BasicBlock *IAE)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
Idx, NumIdx, true))),
GetElementPtr, 0, 0, IAE) {
init(Ptr, Idx, NumIdx);
setName(Name);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx, GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
const std::string &Name, Instruction *InBe) const std::string &Name, Instruction *InBe)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))), : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))),
@ -933,24 +896,6 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
setName(Name); setName(Name);
} }
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
const std::string &Name, Instruction *InBe)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
Idx0, Idx1, true))),
GetElementPtr, 0, 0, InBe) {
init(Ptr, Idx0, Idx1);
setName(Name);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
const std::string &Name, BasicBlock *IAE)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
Idx0, Idx1, true))),
GetElementPtr, 0, 0, IAE) {
init(Ptr, Idx0, Idx1);
setName(Name);
}
GetElementPtrInst::~GetElementPtrInst() { GetElementPtrInst::~GetElementPtrInst() {
delete[] OperandList; delete[] OperandList;
} }
@ -999,24 +944,6 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
return CurIdx == NumIdx ? Ptr : 0; return CurIdx == NumIdx ? Ptr : 0;
} }
const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
Value *Idx0, Value *Idx1,
bool AllowCompositeLeaf) {
const PointerType *PTy = dyn_cast<PointerType>(Ptr);
if (!PTy) return 0; // Type isn't a pointer type!
// Check the pointer index.
if (!PTy->indexValid(Idx0)) return 0;
const CompositeType *CT = dyn_cast<CompositeType>(PTy->getElementType());
if (!CT || !CT->indexValid(Idx1)) return 0;
const Type *ElTy = CT->getTypeAtIndex(Idx1);
if (AllowCompositeLeaf || ElTy->isFirstClassType())
return ElTy;
return 0;
}
const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) { const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
const PointerType *PTy = dyn_cast<PointerType>(Ptr); const PointerType *PTy = dyn_cast<PointerType>(Ptr);
if (!PTy) return 0; // Type isn't a pointer type! if (!PTy) return 0; // Type isn't a pointer type!

View File

@ -913,7 +913,7 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end()); SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end());
const Type *ElTy = const Type *ElTy =
GetElementPtrInst::getIndexedType(GEP.getOperand(0)->getType(), GetElementPtrInst::getIndexedType(GEP.getOperand(0)->getType(),
&Idxs[0], Idxs.size(), true); Idxs.begin(), Idxs.end(), true);
Assert1(ElTy, "Invalid indices for GEP pointer type!", &GEP); Assert1(ElTy, "Invalid indices for GEP pointer type!", &GEP);
Assert2(isa<PointerType>(GEP.getType()) && Assert2(isa<PointerType>(GEP.getType()) &&
cast<PointerType>(GEP.getType())->getElementType() == ElTy, cast<PointerType>(GEP.getType())->getElementType() == ElTy,

View File

@ -1533,8 +1533,8 @@ const Type* upgradeGEPCEIndices(const Type* PTy,
} }
} }
Result.push_back(Index); Result.push_back(Index);
Ty = GetElementPtrInst::getIndexedType(PTy, (Value**)&Result[0], Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
Result.size(),true); Result.end(),true);
if (!Ty) if (!Ty)
error("Index list invalid for constant getelementptr"); error("Index list invalid for constant getelementptr");
} }
@ -1579,7 +1579,8 @@ const Type* upgradeGEPInstIndices(const Type* PTy,
} }
} }
Result.push_back(Index); Result.push_back(Index);
Ty = GetElementPtrInst::getIndexedType(PTy, &Result[0], Result.size(),true); Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
Result.end(),true);
if (!Ty) if (!Ty)
error("Index list invalid for constant getelementptr"); error("Index list invalid for constant getelementptr");
} }
@ -3890,7 +3891,7 @@ MemoryInst
upgradeGEPInstIndices(Ty, $4, VIndices); upgradeGEPInstIndices(Ty, $4, VIndices);
Value* tmpVal = getVal(Ty, $3); Value* tmpVal = getVal(Ty, $3);
$$.I = new GetElementPtrInst(tmpVal, &VIndices[0], VIndices.size()); $$.I = new GetElementPtrInst(tmpVal, VIndices.begin(), VIndices.end());
ValueInfo VI; VI.V = tmpVal; VI.S.copy($2.S); ValueInfo VI; VI.V = tmpVal; VI.S.copy($2.S);
$$.S.copy(getElementSign(VI, VIndices)); $$.S.copy(getElementSign(VI, VIndices));
delete $2.PAT; delete $2.PAT;

View File

@ -787,7 +787,8 @@ void CppWriter::printConstant(const Constant *CV) {
Out << "Constant* " << constName Out << "Constant* " << constName
<< " = ConstantExpr::getGetElementPtr(" << " = ConstantExpr::getGetElementPtr("
<< getCppName(CE->getOperand(0)) << ", " << getCppName(CE->getOperand(0)) << ", "
<< "&" << constName << "_indices[0], " << CE->getNumOperands() - 1 << constName << "_indices.begin(), "
<< constName << "_indices.end(), "
<< " );"; << " );";
} else if (CE->isCast()) { } else if (CE->isCast()) {
printConstant(CE->getOperand(0)); printConstant(CE->getOperand(0));
@ -1253,8 +1254,8 @@ CppWriter::printInstruction(const Instruction *I, const std::string& bbname) {
nl(Out); nl(Out);
} }
Out << "Instruction* " << iName << " = new GetElementPtrInst(" Out << "Instruction* " << iName << " = new GetElementPtrInst("
<< opNames[0] << ", &" << iName << "_indices[0], " << opNames[0] << ", " << iName << "_indices.begin(), "
<< gep->getNumOperands() - 1; << iName << "_indices.end()";
} }
Out << ", \""; Out << ", \"";
printEscapedString(gep->getName()); printEscapedString(gep->getName());