Skip to content

Commit 847f91e

Browse files
svenvhsys-ce-bb
authored andcommitted
Start moving away from insert-before Instruction pointers (#2498)
In preparation for LLVM's deprecation of Instruction constructors and Create methods that accept `Instruction` pointers, upgrade call sites to pass an iterator instead of an `Instruction` pointer. This patch only upgrades constructor and `Create` calls that were trivial to upgrade with no impact on the test suite. Some calls remain to be upgraded as future work. Original commit: KhronosGroup/SPIRV-LLVM-Translator@7fb89d5a0f2dfd7
1 parent 98a34d2 commit 847f91e

File tree

7 files changed

+41
-32
lines changed

7 files changed

+41
-32
lines changed

llvm-spirv/lib/SPIRV/OCLToSPIRV.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ CallInst *OCLToSPIRVBase::visitCallAtomicCmpXchg(CallInst *CI) {
499499
}
500500

501501
void OCLToSPIRVBase::visitCallAtomicInit(CallInst *CI) {
502-
auto *ST = new StoreInst(CI->getArgOperand(1), CI->getArgOperand(0), CI);
502+
auto *ST = new StoreInst(CI->getArgOperand(1), CI->getArgOperand(0),
503+
CI->getIterator());
503504
ST->takeName(CI);
504505
CI->dropAllReferences();
505506
CI->eraseFromParent();
@@ -515,11 +516,11 @@ void OCLToSPIRVBase::visitCallAllAny(spv::Op OC, CallInst *CI) {
515516
auto *Zero = Constant::getNullValue(Args[0]->getType());
516517

517518
auto *Cmp = CmpInst::Create(CmpInst::ICmp, CmpInst::ICMP_SLT, Args[0], Zero,
518-
"cast", CI);
519+
"cast", CI->getIterator());
519520

520521
if (!isa<VectorType>(ArgTy)) {
521-
auto *Cast = CastInst::CreateZExtOrBitCast(Cmp, Type::getInt32Ty(*Ctx), "",
522-
Cmp->getNextNode());
522+
auto *Cast = CastInst::CreateZExtOrBitCast(
523+
Cmp, Type::getInt32Ty(*Ctx), "", Cmp->getNextNode()->getIterator());
523524
CI->replaceAllUsesWith(Cast);
524525
CI->eraseFromParent();
525526
} else {
@@ -1040,13 +1041,15 @@ void OCLToSPIRVBase::visitCallGetImageSize(CallInst *CI,
10401041
Constant *Index[] = {getInt32(M, 0), getInt32(M, 1), getInt32(M, 2),
10411042
getInt32(M, 3)};
10421043
return new ShuffleVectorInst(NCI, ZeroVec,
1043-
ConstantVector::get(Index), "", CI);
1044+
ConstantVector::get(Index), "",
1045+
CI->getIterator());
10441046

10451047
} else if (Desc.Dim == Dim2D && Desc.Arrayed) {
10461048
Constant *Index[] = {getInt32(M, 0), getInt32(M, 1)};
10471049
Constant *Mask = ConstantVector::get(Index);
10481050
return new ShuffleVectorInst(NCI, UndefValue::get(NCI->getType()),
1049-
Mask, NCI->getName(), CI);
1051+
Mask, NCI->getName(),
1052+
CI->getIterator());
10501053
}
10511054
return NCI;
10521055
}
@@ -1056,7 +1059,7 @@ void OCLToSPIRVBase::visitCallGetImageSize(CallInst *CI,
10561059
.Case(kOCLBuiltinName::GetImageDepth, 2)
10571060
.Case(kOCLBuiltinName::GetImageArraySize, Dim - 1);
10581061
return ExtractElementInst::Create(NCI, getUInt32(M, I), "",
1059-
NCI->getNextNode());
1062+
NCI->getNextNode()->getIterator());
10601063
});
10611064
}
10621065

@@ -1371,11 +1374,12 @@ void OCLToSPIRVBase::visitCallScalToVec(CallInst *CI, StringRef MangledName,
13711374
getExtOp(MangledName, DemangledName)));
13721375
for (auto I : ScalarPos)
13731376
Mutator.mapArg(I, [&](Value *V) {
1374-
Instruction *Inst = InsertElementInst::Create(UndefValue::get(VecTy), V,
1375-
getInt32(M, 0), "", CI);
1377+
Instruction *Inst = InsertElementInst::Create(
1378+
UndefValue::get(VecTy), V, getInt32(M, 0), "", CI->getIterator());
13761379
return new ShuffleVectorInst(
13771380
Inst, UndefValue::get(VecTy),
1378-
ConstantVector::getSplat(VecElemCount, getInt32(M, 0)), "", CI);
1381+
ConstantVector::getSplat(VecElemCount, getInt32(M, 0)), "",
1382+
CI->getIterator());
13791383
});
13801384
}
13811385

@@ -1488,7 +1492,7 @@ void OCLToSPIRVBase::visitCallEnqueueKernel(CallInst *CI,
14881492
LocalSizeArray->getSourceElementType(), // Pointee type
14891493
LocalSizeArray->getPointerOperand(), // Alloca
14901494
{getInt32(M, 0), getInt32(M, I)}, // Indices
1491-
"", CI));
1495+
"", CI->getIterator()));
14921496
}
14931497

14941498
StringRef NewName = "__spirv_EnqueueKernel__";
@@ -1497,7 +1501,7 @@ void OCLToSPIRVBase::visitCallEnqueueKernel(CallInst *CI,
14971501
Function *NewF =
14981502
Function::Create(FT, GlobalValue::ExternalLinkage, NewName, M);
14991503
NewF->setCallingConv(CallingConv::SPIR_FUNC);
1500-
CallInst *NewCall = CallInst::Create(NewF, Args, "", CI);
1504+
CallInst *NewCall = CallInst::Create(NewF, Args, "", CI->getIterator());
15011505
NewCall->setCallingConv(NewF->getCallingConv());
15021506
CI->replaceAllUsesWith(NewCall);
15031507
CI->eraseFromParent();

llvm-spirv/lib/SPIRV/SPIRVLowerBool.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ void SPIRVLowerBoolBase::visitTruncInst(TruncInst &I) {
6868
if (isBoolType(I.getType())) {
6969
auto *Op = I.getOperand(0);
7070
auto *And = BinaryOperator::CreateAnd(
71-
Op, getScalarOrVectorConstantInt(Op->getType(), 1, false), "", &I);
71+
Op, getScalarOrVectorConstantInt(Op->getType(), 1, false), "",
72+
I.getIterator());
7273
And->setDebugLoc(I.getDebugLoc());
7374
auto *Zero = getScalarOrVectorConstantInt(Op->getType(), 0, false);
7475
auto *Cmp = new ICmpInst(&I, CmpInst::ICMP_NE, And, Zero);
@@ -85,7 +86,7 @@ void SPIRVLowerBoolBase::handleExtInstructions(Instruction &I) {
8586
auto *One = getScalarOrVectorConstantInt(
8687
Ty, (Opcode == Instruction::SExt) ? ~0 : 1, false);
8788
assert(Zero && One && "Couldn't create constant int");
88-
auto *Sel = SelectInst::Create(Op, One, Zero, "", &I);
89+
auto *Sel = SelectInst::Create(Op, One, Zero, "", I.getIterator());
8990
replace(&I, Sel);
9091
}
9192
}
@@ -100,7 +101,7 @@ void SPIRVLowerBoolBase::handleCastInstructions(Instruction &I) {
100101
auto *Zero = getScalarOrVectorConstantInt(Ty, 0, false);
101102
auto *One = getScalarOrVectorConstantInt(Ty, 1, false);
102103
assert(Zero && One && "Couldn't create constant int");
103-
auto *Sel = SelectInst::Create(Op, One, Zero, "", &I);
104+
auto *Sel = SelectInst::Create(Op, One, Zero, "", I.getIterator());
104105
Sel->setDebugLoc(I.getDebugLoc());
105106
I.setOperand(0, Sel);
106107
}

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,10 +1196,12 @@ SPIRVToLLVM::expandOCLBuiltinWithScalarArg(CallInst *CI,
11961196
else {
11971197
NewVec = ConstantVector::getSplat(
11981198
VecElemCount, Constant::getNullValue(Arg->getType()));
1199-
NewVec = InsertElementInst::Create(NewVec, Arg, getInt32(M, 0), "", CI);
1199+
NewVec = InsertElementInst::Create(NewVec, Arg, getInt32(M, 0), "",
1200+
CI->getIterator());
12001201
NewVec = new ShuffleVectorInst(
12011202
NewVec, NewVec,
1202-
ConstantVector::getSplat(VecElemCount, getInt32(M, 0)), "", CI);
1203+
ConstantVector::getSplat(VecElemCount, getInt32(M, 0)), "",
1204+
CI->getIterator());
12031205
}
12041206
NewVec->takeName(Arg);
12051207
return NewVec;

llvm-spirv/lib/SPIRV/SPIRVToOCL.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ void SPIRVToOCLBase::visitCallSPIRVImageQuerySize(CallInst *CI) {
276276
// The width of integer type returning by OpImageQuerySize[Lod] may
277277
// differ from i32
278278
if (CI->getType()->getScalarType() != Int32Ty) {
279-
GetImageSize = CastInst::CreateIntegerCast(GetImageSize,
280-
CI->getType()->getScalarType(),
281-
false, CI->getName(), CI);
279+
GetImageSize = CastInst::CreateIntegerCast(
280+
GetImageSize, CI->getType()->getScalarType(), false, CI->getName(),
281+
CI->getIterator());
282282
}
283283
} else {
284284
assert((ImgDim == 2 || ImgDim == 3) && "invalid image type");
@@ -298,7 +298,7 @@ void SPIRVToOCLBase::visitCallSPIRVImageQuerySize(CallInst *CI) {
298298
FixedVectorType::get(
299299
CI->getType()->getScalarType(),
300300
cast<FixedVectorType>(GetImageSize->getType())->getNumElements()),
301-
false, CI->getName(), CI);
301+
false, CI->getName(), CI->getIterator());
302302
}
303303
}
304304

@@ -313,7 +313,7 @@ void SPIRVToOCLBase::visitCallSPIRVImageQuerySize(CallInst *CI) {
313313
"OpImageQuerySize[Lod] must return <2 x iN> vector type");
314314
GetImageSize = InsertElementInst::Create(
315315
UndefValue::get(VecTy), GetImageSize, ConstantInt::get(Int32Ty, 0),
316-
CI->getName(), CI);
316+
CI->getName(), CI->getIterator());
317317
} else {
318318
// get_image_dim and OpImageQuerySize returns different vector
319319
// types for arrayed and 3d images.
@@ -324,7 +324,7 @@ void SPIRVToOCLBase::visitCallSPIRVImageQuerySize(CallInst *CI) {
324324

325325
GetImageSize = new ShuffleVectorInst(
326326
GetImageSize, UndefValue::get(GetImageSize->getType()), Mask,
327-
CI->getName(), CI);
327+
CI->getName(), CI->getIterator());
328328
}
329329
}
330330

@@ -341,12 +341,13 @@ void SPIRVToOCLBase::visitCallSPIRVImageQuerySize(CallInst *CI) {
341341
// differ from size_t which is returned by get_image_array_size
342342
if (GetImageArraySize->getType() != VecTy->getElementType()) {
343343
GetImageArraySize = CastInst::CreateIntegerCast(
344-
GetImageArraySize, VecTy->getElementType(), false, CI->getName(), CI);
344+
GetImageArraySize, VecTy->getElementType(), false, CI->getName(),
345+
CI->getIterator());
345346
}
346347
GetImageSize = InsertElementInst::Create(
347348
GetImageSize, GetImageArraySize,
348349
ConstantInt::get(Int32Ty, VecTy->getNumElements() - 1), CI->getName(),
349-
CI);
350+
CI->getIterator());
350351
}
351352

352353
assert(GetImageSize && "must not be null");

llvm-spirv/lib/SPIRV/SPIRVToOCL20.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void SPIRVToOCL20Base::visitCallSPIRVEnqueueKernel(CallInst *CI, Op OC) {
263263
auto Mutator = mutateCallInst(CI, FName.str());
264264
Mutator.mapArg(6, [=](IRBuilder<> &Builder, Value *Invoke) {
265265
Value *Replace = CastInst::CreatePointerBitCastOrAddrSpaceCast(
266-
Invoke, Builder.getPtrTy(SPIRAS_Generic), "", CI);
266+
Invoke, Builder.getPtrTy(SPIRAS_Generic), "", CI->getIterator());
267267
return std::make_pair(
268268
Replace, TypedPointerType::get(Builder.getInt8Ty(), SPIRAS_Generic));
269269
});

llvm-spirv/lib/SPIRV/SPIRVUtil.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,13 +2168,13 @@ bool lowerBuiltinCallsToVariables(Module *M) {
21682168
auto *CI = dyn_cast<CallInst>(U);
21692169
assert(CI && "invalid instruction");
21702170
const DebugLoc &DLoc = CI->getDebugLoc();
2171-
Instruction *NewValue = new LoadInst(GVType, BV, "", CI);
2171+
Instruction *NewValue = new LoadInst(GVType, BV, "", CI->getIterator());
21722172
if (DLoc)
21732173
NewValue->setDebugLoc(DLoc);
21742174
LLVM_DEBUG(dbgs() << "Transform: " << *CI << " => " << *NewValue << '\n');
21752175
if (IsVec) {
2176-
NewValue =
2177-
ExtractElementInst::Create(NewValue, CI->getArgOperand(0), "", CI);
2176+
NewValue = ExtractElementInst::Create(NewValue, CI->getArgOperand(0),
2177+
"", CI->getIterator());
21782178
if (DLoc)
21792179
NewValue->setDebugLoc(DLoc);
21802180
LLVM_DEBUG(dbgs() << *NewValue << '\n');
@@ -2272,11 +2272,12 @@ bool postProcessBuiltinWithArrayArguments(Function *F,
22722272
if (!T->isArrayTy())
22732273
continue;
22742274
auto *Alloca = new AllocaInst(T, 0, "", &(*FBegin));
2275-
new StoreInst(I, Alloca, false, CI);
2275+
new StoreInst(I, Alloca, false, CI->getIterator());
22762276
auto *Zero =
22772277
ConstantInt::getNullValue(Type::getInt32Ty(T->getContext()));
22782278
Value *Index[] = {Zero, Zero};
2279-
I = GetElementPtrInst::CreateInBounds(T, Alloca, Index, "", CI);
2279+
I = GetElementPtrInst::CreateInBounds(T, Alloca, Index, "",
2280+
CI->getIterator());
22802281
}
22812282
return Name.str();
22822283
},

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5501,7 +5501,7 @@ void LLVMToSPIRVBase::mutateFuncArgType(
55015501
auto CastF = M->getOrInsertFunction(SPCV_CAST, I.second, OrigTy);
55025502
std::vector<Value *> Args;
55035503
Args.push_back(Arg);
5504-
auto *Cast = CallInst::Create(CastF, Args, "", Call);
5504+
auto *Cast = CallInst::Create(CastF, Args, "", Call->getIterator());
55055505
Call->replaceUsesOfWith(Arg, Cast);
55065506
SPIRVDBG(dbgs() << "[mutate arg type] -> " << *Cast << '\n');
55075507
}

0 commit comments

Comments
 (0)