mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-26 09:18:56 +00:00
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:
@@ -376,8 +376,8 @@ Function *ArgPromotion::DoPromotion(Function *F,
|
||||
for (ScalarizeTable::iterator SI = ArgIndices.begin(),
|
||||
E = ArgIndices.end(); SI != E; ++SI)
|
||||
Params.push_back(GetElementPtrInst::getIndexedType(I->getType(),
|
||||
&(*SI)[0],
|
||||
SI->size()));
|
||||
SI->begin(),
|
||||
SI->end()));
|
||||
|
||||
if (ArgIndices.size() == 1 && ArgIndices.begin()->empty())
|
||||
++NumArgumentsPromoted;
|
||||
@@ -428,7 +428,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
|
||||
Value *V = *AI;
|
||||
LoadInst *OrigLoad = OriginalLoads[*SI];
|
||||
if (!SI->empty()) {
|
||||
V = new GetElementPtrInst(V, &(*SI)[0], SI->size(),
|
||||
V = new GetElementPtrInst(V, SI->begin(), SI->end(),
|
||||
V->getName()+".idx", Call);
|
||||
AA.copyValue(OrigLoad->getOperand(0), V);
|
||||
}
|
||||
|
@@ -464,7 +464,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV) {
|
||||
Idxs.push_back(NullInt);
|
||||
for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++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);
|
||||
}
|
||||
GEP->replaceAllUsesWith(NewPtr);
|
||||
@@ -698,7 +698,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
|
||||
MI->getAlignment(), MI->getName(), MI);
|
||||
Value* Indices[2];
|
||||
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);
|
||||
MI->replaceAllUsesWith(NewGEP);
|
||||
MI->eraseFromParent();
|
||||
@@ -926,7 +926,7 @@ static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Ptr,
|
||||
GEPIdx.push_back(GEPI->getOperand(1));
|
||||
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->replaceAllUsesWith(NGEPI);
|
||||
GEPI->eraseFromParent();
|
||||
|
@@ -945,7 +945,7 @@ Value* GVNPRE::phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ) {
|
||||
|
||||
if (newOp1 != U->getPointerOperand() || changed_idx) {
|
||||
Instruction* newVal = new GetElementPtrInst(newOp1,
|
||||
&newIdx[0], newIdx.size(),
|
||||
newIdx.begin(), newIdx.end(),
|
||||
U->getName()+".expr");
|
||||
|
||||
uint32_t v = VN.lookup_or_add(newVal);
|
||||
@@ -1675,7 +1675,7 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB,
|
||||
C->getName()+".gvnpre",
|
||||
(*PI)->getTerminator());
|
||||
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",
|
||||
(*PI)->getTerminator());
|
||||
|
||||
|
@@ -178,8 +178,11 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN,
|
||||
Constant *NCE = ConstantExpr::getGetElementPtr(CE->getOperand(0),
|
||||
&CEIdxs[0],
|
||||
CEIdxs.size());
|
||||
Value *Idx[2];
|
||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
||||
Idx[1] = NewAdd;
|
||||
GetElementPtrInst *NGEPI = new GetElementPtrInst(
|
||||
NCE, Constant::getNullValue(Type::Int32Ty), NewAdd,
|
||||
NCE, Idx, Idx + 2,
|
||||
GEPI->getName(), GEPI);
|
||||
SE->deleteValueFromRecords(GEPI);
|
||||
GEPI->replaceAllUsesWith(NGEPI);
|
||||
|
@@ -6564,8 +6564,9 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) {
|
||||
// If we were able to index down into an element, create the GEP
|
||||
// and bitcast the result. This eliminates one bitcast, potentially
|
||||
// two.
|
||||
Instruction *NGEP = new GetElementPtrInst(OrigBase, &NewIndices[0],
|
||||
NewIndices.size(), "");
|
||||
Instruction *NGEP = new GetElementPtrInst(OrigBase,
|
||||
NewIndices.begin(),
|
||||
NewIndices.end(), "");
|
||||
InsertNewInstBefore(NGEP, CI);
|
||||
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 (SrcElTy == DstElTy) {
|
||||
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())
|
||||
return new GetElementPtrInst(SrcGEPOperands[0], &Indices[0],
|
||||
Indices.size(), GEP.getName());
|
||||
return new GetElementPtrInst(SrcGEPOperands[0], Indices.begin(),
|
||||
Indices.end(), GEP.getName());
|
||||
|
||||
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(PtrOp)) {
|
||||
// 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) &&
|
||||
TD->getTypeSize(cast<ArrayType>(SrcElTy)->getElementType()) ==
|
||||
TD->getTypeSize(ResElTy)) {
|
||||
Value *Idx[2];
|
||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
||||
Idx[1] = GEP.getOperand(1);
|
||||
Value *V = InsertNewInstBefore(
|
||||
new GetElementPtrInst(X, Constant::getNullValue(Type::Int32Ty),
|
||||
GEP.getOperand(1), GEP.getName()), GEP);
|
||||
new GetElementPtrInst(X, Idx, Idx + 2, GEP.getName()), GEP);
|
||||
// V and GEP are both pointer types --> BitCast
|
||||
return new BitCastInst(V, GEP.getType());
|
||||
}
|
||||
@@ -8609,9 +8612,11 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||
}
|
||||
|
||||
// Insert the new GEP instruction.
|
||||
Value *Idx[2];
|
||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
||||
Idx[1] = NewIdx;
|
||||
Instruction *NewGEP =
|
||||
new GetElementPtrInst(X, Constant::getNullValue(Type::Int32Ty),
|
||||
NewIdx, GEP.getName());
|
||||
new GetElementPtrInst(X, Idx, Idx + 2, GEP.getName());
|
||||
NewGEP = InsertNewInstBefore(NewGEP, GEP);
|
||||
// The NewGEP must be pointer typed, so must the old one -> BitCast
|
||||
return new BitCastInst(NewGEP, GEP.getType());
|
||||
@@ -8651,7 +8656,10 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
|
||||
// insert our getelementptr instruction...
|
||||
//
|
||||
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);
|
||||
|
||||
// Now make everything use the getelementptr instead of the original
|
||||
|
@@ -242,8 +242,11 @@ bool LowerGC::runOnFunction(Function &F) {
|
||||
Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
|
||||
Constant *One = ConstantInt::get(Type::Int32Ty, 1);
|
||||
|
||||
Value *Idx[2] = { Zero, Zero };
|
||||
|
||||
// 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.
|
||||
Value *PrevPtr = new LoadInst(RootChain, "prevptr", IP);
|
||||
@@ -251,7 +254,9 @@ bool LowerGC::runOnFunction(Function &F) {
|
||||
new StoreInst(PrevPtr, PrevPtrPtr, IP);
|
||||
|
||||
// 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);
|
||||
|
||||
Value* Par[4];
|
||||
@@ -267,13 +272,15 @@ bool LowerGC::runOnFunction(Function &F) {
|
||||
// Initialize the meta-data pointer.
|
||||
Par[2] = ConstantInt::get(Type::Int32Ty, i);
|
||||
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");
|
||||
new StoreInst(GCRoots[i]->getOperand(2), MetaDataPtr, IP);
|
||||
|
||||
// Initialize the root pointer to null on entry to the function.
|
||||
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);
|
||||
|
||||
// Each occurrance of the llvm.gcroot intrinsic now turns into an
|
||||
|
@@ -235,7 +235,7 @@ void LowerPacked::visitLoadInst(LoadInst& LI)
|
||||
|
||||
// Get the pointer
|
||||
Value* val = new GetElementPtrInst(array,
|
||||
&Idx[0], Idx.size(),
|
||||
Idx.begin(), Idx.end(),
|
||||
LI.getName() +
|
||||
".ge." + utostr(i),
|
||||
&LI);
|
||||
@@ -333,7 +333,7 @@ void LowerPacked::visitStoreInst(StoreInst& SI)
|
||||
// Generate the indices for getelementptr
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty,i);
|
||||
Value* val = new GetElementPtrInst(array,
|
||||
&Idx[0], Idx.size(),
|
||||
Idx.begin(), Idx.end(),
|
||||
"store.ge." +
|
||||
utostr(i) + ".",
|
||||
&SI);
|
||||
|
@@ -319,8 +319,8 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
|
||||
SmallVector<Value*, 8> NewArgs;
|
||||
NewArgs.push_back(Constant::getNullValue(Type::Int32Ty));
|
||||
NewArgs.append(GEPI->op_begin()+3, GEPI->op_end());
|
||||
RepValue = new GetElementPtrInst(AllocaToUse, &NewArgs[0],
|
||||
NewArgs.size(), "", GEPI);
|
||||
RepValue = new GetElementPtrInst(AllocaToUse, NewArgs.begin(),
|
||||
NewArgs.end(), "", 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.
|
||||
Value *OtherElt = 0;
|
||||
if (OtherPtr) {
|
||||
OtherElt = new GetElementPtrInst(OtherPtr, Zero,
|
||||
ConstantInt::get(Type::Int32Ty, i),
|
||||
Value *Idx[2];
|
||||
Idx[0] = Zero;
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
|
||||
OtherElt = new GetElementPtrInst(OtherPtr, Idx, Idx + 2,
|
||||
OtherPtr->getNameStr()+"."+utostr(i),
|
||||
MI);
|
||||
}
|
||||
@@ -829,11 +831,13 @@ void SROA::CanonicalizeAllocaUsers(AllocationInst *AI) {
|
||||
SmallVector<Value*, 8> Indices(GEPI->op_begin()+1, GEPI->op_end());
|
||||
Indices[1] = Constant::getNullValue(Type::Int32Ty);
|
||||
Value *ZeroIdx = new GetElementPtrInst(GEPI->getOperand(0),
|
||||
&Indices[0], Indices.size(),
|
||||
Indices.begin(),
|
||||
Indices.end(),
|
||||
GEPI->getName()+".0", GEPI);
|
||||
Indices[1] = ConstantInt::get(Type::Int32Ty, 1);
|
||||
Value *OneIdx = new GetElementPtrInst(GEPI->getOperand(0),
|
||||
&Indices[0], Indices.size(),
|
||||
Indices.begin(),
|
||||
Indices.end(),
|
||||
GEPI->getName()+".1", GEPI);
|
||||
// Replace all loads of the variable index GEP with loads from both
|
||||
// indexes and a select.
|
||||
|
@@ -294,11 +294,12 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
|
||||
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
|
||||
Value *RewriteVal;
|
||||
if (AggregateArgs) {
|
||||
Value *Idx0 = Constant::getNullValue(Type::Int32Ty);
|
||||
Value *Idx1 = ConstantInt::get(Type::Int32Ty, i);
|
||||
Value *Idx[2];
|
||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
|
||||
std::string GEPname = "gep_" + inputs[i]->getName();
|
||||
TerminatorInst *TI = newFunction->begin()->getTerminator();
|
||||
GetElementPtrInst *GEP = new GetElementPtrInst(AI, Idx0, Idx1,
|
||||
GetElementPtrInst *GEP = new GetElementPtrInst(AI, Idx, Idx+2,
|
||||
GEPname, TI);
|
||||
RewriteVal = new LoadInst(GEP, "load" + GEPname, TI);
|
||||
} else
|
||||
@@ -381,10 +382,11 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
params.push_back(Struct);
|
||||
|
||||
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
|
||||
Value *Idx0 = Constant::getNullValue(Type::Int32Ty);
|
||||
Value *Idx1 = ConstantInt::get(Type::Int32Ty, i);
|
||||
Value *Idx[2];
|
||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
|
||||
GetElementPtrInst *GEP =
|
||||
new GetElementPtrInst(Struct, Idx0, Idx1,
|
||||
new GetElementPtrInst(Struct, Idx, Idx + 2,
|
||||
"gep_" + StructValues[i]->getName());
|
||||
codeReplacer->getInstList().push_back(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) {
|
||||
Value *Output = 0;
|
||||
if (AggregateArgs) {
|
||||
Value *Idx0 = Constant::getNullValue(Type::Int32Ty);
|
||||
Value *Idx1 = ConstantInt::get(Type::Int32Ty, FirstOut + i);
|
||||
Value *Idx[2];
|
||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i);
|
||||
GetElementPtrInst *GEP
|
||||
= new GetElementPtrInst(Struct, Idx0, Idx1,
|
||||
= new GetElementPtrInst(Struct, Idx, Idx + 2,
|
||||
"gep_reload_" + outputs[i]->getName());
|
||||
codeReplacer->getInstList().push_back(GEP);
|
||||
Output = GEP;
|
||||
@@ -506,10 +509,11 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
|
||||
if (DominatesDef) {
|
||||
if (AggregateArgs) {
|
||||
Value *Idx0 = Constant::getNullValue(Type::Int32Ty);
|
||||
Value *Idx1 = ConstantInt::get(Type::Int32Ty,FirstOut+out);
|
||||
Value *Idx[2];
|
||||
Idx[0] = Constant::getNullValue(Type::Int32Ty);
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out);
|
||||
GetElementPtrInst *GEP =
|
||||
new GetElementPtrInst(OAI, Idx0, Idx1,
|
||||
new GetElementPtrInst(OAI, Idx, Idx + 2,
|
||||
"gep_" + outputs[out]->getName(),
|
||||
NTRet);
|
||||
new StoreInst(outputs[out], GEP, NTRet);
|
||||
|
@@ -450,8 +450,8 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
std::vector<Value*> Idx;
|
||||
Idx.push_back(Constant::getNullValue(Type::Int32Ty));
|
||||
Idx.push_back(ConstantInt::get(Type::Int32Ty, 1));
|
||||
OldJmpBufPtr = new GetElementPtrInst(JmpBuf, &Idx[0], 2, "OldBuf",
|
||||
EntryBB->getTerminator());
|
||||
OldJmpBufPtr = new GetElementPtrInst(JmpBuf, Idx.begin(), Idx.end(),
|
||||
"OldBuf", EntryBB->getTerminator());
|
||||
|
||||
// Copy the JBListHead to the alloca.
|
||||
Value *OldBuf = new LoadInst(JBListHead, "oldjmpbufptr", true,
|
||||
@@ -489,7 +489,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
"setjmp.cont");
|
||||
|
||||
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",
|
||||
EntryBB->getTerminator());
|
||||
Value *SJRet = new CallInst(SetJmpFn, JmpBufPtr, "sjret",
|
||||
@@ -540,7 +540,8 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
std::vector<Value*> Idx;
|
||||
Idx.push_back(Constant::getNullValue(Type::Int32Ty));
|
||||
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);
|
||||
new CallInst(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock);
|
||||
new UnreachableInst(UnwindBlock);
|
||||
|
Reference in New Issue
Block a user