Skip to content

Commit 5d21ee3

Browse files
Anton Sidorenkoigcbot
authored andcommitted
Stop using deprecated IRBuilder functions
Use methods with the explicit type parameter instead.
1 parent 139edf8 commit 5d21ee3

File tree

9 files changed

+102
-33
lines changed

9 files changed

+102
-33
lines changed

IGC/VectorCompiler/CMCL/lib/Support/BuiltinTranslator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ static Value &searchForVectorPointer(Value &V) {
183183
// pointer to vector first and then load the vector.
184184
static Value &readVectorFromBuiltinOp(Value &BiOp, IRBuilder<> &IRB) {
185185
auto &Ptr = searchForVectorPointer(BiOp);
186-
return *IRB.CreateLoad(&Ptr, Ptr.getName() + ".ld.arg");
186+
Type *Ty = Ptr.getType()->getPointerElementType();
187+
return *IRB.CreateLoad(Ty, &Ptr, Ptr.getName() + ".ld.arg");
187188
}
188189

189190
// Output vector operands is also passed as void*.

IGC/VectorCompiler/lib/GenXCodeGen/GenXAggregatePseudoLowering.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,19 +344,24 @@ class SplitInstCreator : public InstVisitor<SplitInstCreator, Instruction *> {
344344
IGC_ASSERT_MESSAGE(OrigLoad.getPointerOperand() == NewOps[0],
345345
"should take the operand from the original load");
346346
IRBuilder<> IRB{&OrigLoad};
347-
auto *GEP = IRB.CreateInBoundsGEP(OrigLoad.getPointerOperand(),
348-
CreateIdxListForGEP(IRB),
347+
Value *PointerOp = OrigLoad.getPointerOperand();
348+
Type *Ty = cast<PointerType>(PointerOp->getType()->getScalarType())
349+
->getElementType();
350+
auto *GEP = IRB.CreateInBoundsGEP(Ty, PointerOp, CreateIdxListForGEP(IRB),
349351
OrigLoad.getName() + "aggr.gep");
350352
// FIXME: replace a structure alignment with an element alignment
351-
return IRB.CreateAlignedLoad(GEP, IGCLLVM::getAlign(OrigLoad),
353+
Type *GEPPtrTy = GEP->getType()->getPointerElementType();
354+
return IRB.CreateAlignedLoad(GEPPtrTy, GEP, IGCLLVM::getAlign(OrigLoad),
352355
OrigLoad.isVolatile(),
353356
OrigLoad.getName() + ".split.aggr");
354357
}
355358

356359
Instruction *visitStoreInst(StoreInst &OrigStore) const {
357360
IRBuilder<> IRB{&OrigStore};
358-
auto *GEP = IRB.CreateInBoundsGEP(OrigStore.getPointerOperand(),
359-
CreateIdxListForGEP(IRB),
361+
Value *PointerOp = OrigStore.getPointerOperand();
362+
Type *Ty = cast<PointerType>(PointerOp->getType()->getScalarType())
363+
->getElementType();
364+
auto *GEP = IRB.CreateInBoundsGEP(Ty, PointerOp, CreateIdxListForGEP(IRB),
360365
OrigStore.getName() + "aggr.gep");
361366
// FIXME: replace a structure alignment with an element alignment
362367
return IRB.CreateAlignedStore(NewOps[0], GEP, IGCLLVM::getAlign(OrigStore),

IGC/VectorCompiler/lib/GenXCodeGen/GenXLowerAggrCopies.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ void GenXLowerAggrCopies::expandMemMov2VecLoadStore(T *MemCall) {
244244
auto SrcAddr = MemCall->getRawSource();
245245
unsigned srcAS = cast<PointerType>(SrcAddr->getType())->getAddressSpace();
246246
auto LoadPtrV = IRB.CreateBitCast(SrcAddr, VecTy->getPointerTo(srcAS));
247-
auto ReadIn = IRB.CreateLoad(LoadPtrV);
247+
Type *Ty = LoadPtrV->getType()->getPointerElementType();
248+
auto ReadIn = IRB.CreateLoad(Ty, LoadPtrV);
248249
auto DstAddr = MemCall->getRawDest();
249250
unsigned dstAS = cast<PointerType>(DstAddr->getType())->getAddressSpace();
250251
auto StorePtrV = IRB.CreateBitCast(DstAddr, VecTy->getPointerTo(dstAS));

IGC/VectorCompiler/lib/GenXCodeGen/GenXPromoteArray.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ void TransposeHelper::handlePHINode(PHINode *pPhi, GenericVectorIndex Idx,
872872
template <typename FolderT = ConstantFolder>
873873
Instruction *loadAndCastVector(AllocaInst &VecAlloca, Type &CastTo,
874874
IRBuilder<FolderT> &IRB) {
875-
auto *LoadVecAlloca = IRB.CreateLoad(&VecAlloca);
875+
auto *LoadVecAlloca =
876+
IRB.CreateLoad(VecAlloca.getType()->getPointerElementType(), &VecAlloca);
876877
auto *AllocatedElemTy = LoadVecAlloca->getType()->getScalarType();
877878
bool IsFuncPointer =
878879
CastTo.isPointerTy() && CastTo.getPointerElementType()->isFunctionTy();
@@ -1035,7 +1036,8 @@ void TransposeHelperPromote::handlePrivateGather(IntrinsicInst *pInst,
10351036
Value *pScalarizedIdx) {
10361037
IRBuilder<> IRB(pInst);
10371038
IGC_ASSERT(pInst->getType()->isVectorTy());
1038-
Value *pLoadVecAlloca = IRB.CreateLoad(pVecAlloca);
1039+
Value *pLoadVecAlloca = IRB.CreateLoad(
1040+
pVecAlloca->getType()->getPointerElementType(), pVecAlloca);
10391041
auto *InstTy = cast<IGCLLVM::FixedVectorType>(pInst->getType());
10401042
auto N = InstTy->getNumElements();
10411043
auto ElemType = InstTy->getElementType();
@@ -1113,7 +1115,8 @@ void TransposeHelperPromote::handlePrivateScatter(llvm::IntrinsicInst *pInst,
11131115
// Add Store instruction to remove list
11141116
IRBuilder<> IRB(pInst);
11151117
llvm::Value *pStoreVal = pInst->getArgOperand(3);
1116-
llvm::Value *pLoadVecAlloca = IRB.CreateLoad(pVecAlloca);
1118+
llvm::Value *pLoadVecAlloca = IRB.CreateLoad(
1119+
pVecAlloca->getType()->getPointerElementType(), pVecAlloca);
11171120
IGC_ASSERT(pStoreVal->getType()->isVectorTy());
11181121
auto *StoreValTy = cast<IGCLLVM::FixedVectorType>(pStoreVal->getType());
11191122
auto N = StoreValTy->getNumElements();
@@ -1308,7 +1311,8 @@ void TransposeHelperPromote::handleSVMGather(IntrinsicInst *pInst,
13081311

13091312
// part of this is taken from handleLLVMGather above
13101313
IRBuilder<> IRB(pInst);
1311-
llvm::Value *pLoadVecAlloca = IRB.CreateLoad(pVecAlloca);
1314+
llvm::Value *pLoadVecAlloca = IRB.CreateLoad(
1315+
pVecAlloca->getType()->getPointerElementType(), pVecAlloca);
13121316
Region R(pInst);
13131317
R.Mask = pInst->getArgOperand(0);
13141318
R.Indirect = IRB.CreateTrunc(
@@ -1344,7 +1348,8 @@ void TransposeHelperPromote::handleSVMScatter(IntrinsicInst *pInst,
13441348
Value *pScalarizedIdx) {
13451349
IRBuilder<> IRB(pInst);
13461350
Value *pStoreVal = pInst->getArgOperand(3);
1347-
Value *pLoadVecAlloca = IRB.CreateLoad(pVecAlloca);
1351+
Value *pLoadVecAlloca = IRB.CreateLoad(
1352+
pVecAlloca->getType()->getPointerElementType(), pVecAlloca);
13481353
Region R(pStoreVal);
13491354
R.Mask = pInst->getArgOperand(0);
13501355
R.Indirect = IRB.CreateTrunc(

IGC/VectorCompiler/lib/GenXCodeGen/GenXPromoteStatefulToBindless.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ SPDX-License-Identifier: MIT
5252
#include <llvm/ADT/Twine.h>
5353
#include <llvm/IR/Function.h>
5454
#include <llvm/IR/GlobalVariable.h>
55+
#include <llvm/IR/IRBuilder.h>
5556
#include <llvm/IR/InstIterator.h>
5657
#include <llvm/IR/Module.h>
5758
#include <llvm/Pass.h>

IGC/VectorCompiler/lib/GenXOpts/CMPacketize/gen_builder.hpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,6 @@ Value* IN_BOUNDS_GEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name = "")
566566
return IRB()->CreateInBoundsGEP(Ty, Ptr, Idx, Name);
567567
}
568568

569-
Value* CONST_GEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "")
570-
{
571-
return IRB()->CreateConstGEP1_32(Ptr, Idx0, Name);
572-
}
573-
574569
Value* CONST_GEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name = "")
575570
{
576571
return IRB()->CreateConstGEP1_32(Ty, Ptr, Idx0, Name);
@@ -591,24 +586,24 @@ Value* CONST_IN_BOUNDS_GEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx
591586
return IRB()->CreateConstInBoundsGEP2_32(Ty, Ptr, Idx0, Idx1, Name);
592587
}
593588

594-
Value* CONST_GEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "")
589+
Value* CONST_GEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name = "")
595590
{
596-
return IRB()->CreateConstGEP1_64(Ptr, Idx0, Name);
591+
return IRB()->CreateConstGEP1_64(Ty, Ptr, Idx0, Name);
597592
}
598593

599-
Value* CONST_IN_BOUNDS_GEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "")
594+
Value* CONST_IN_BOUNDS_GEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name = "")
600595
{
601-
return IRB()->CreateConstInBoundsGEP1_64(Ptr, Idx0, Name);
596+
return IRB()->CreateConstInBoundsGEP1_64(Ty, Ptr, Idx0, Name);
602597
}
603598

604-
Value* CONST_GEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name = "")
599+
Value* CONST_GEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name = "")
605600
{
606-
return IRB()->CreateConstGEP2_64(Ptr, Idx0, Idx1, Name);
601+
return IRB()->CreateConstGEP2_64(Ty, Ptr, Idx0, Idx1, Name);
607602
}
608603

609-
Value* CONST_IN_BOUNDS_GEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name = "")
604+
Value* CONST_IN_BOUNDS_GEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name = "")
610605
{
611-
return IRB()->CreateConstInBoundsGEP2_64(Ptr, Idx0, Idx1, Name);
606+
return IRB()->CreateConstInBoundsGEP2_64(Ty, Ptr, Idx0, Idx1, Name);
612607
}
613608

614609
Value* STRUCT_GEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name = "")

IGC/VectorCompiler/lib/GenXOpts/CMTrans/CMABI.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,8 @@ appendTransformedFuncRetPortion(Value &NewRetVal, int RetIdx, int ArgIdx,
10331033
NewFuncInfo.getGlobalArgsInfo().FirstGlobalArgIdx];
10341034
IGC_ASSERT_MESSAGE(isa<AllocaInst>(LocalizedGlobal),
10351035
"an alloca is expected when pass localized global by value");
1036-
Value *LocalizedGlobalVal = Builder.CreateLoad(LocalizedGlobal);
1036+
Value *LocalizedGlobalVal = Builder.CreateLoad(
1037+
LocalizedGlobal->getType()->getPointerElementType(), LocalizedGlobal);
10371038
return Builder.CreateInsertValue(&NewRetVal, LocalizedGlobalVal, RetIdx);
10381039
}
10391040
IGC_ASSERT_MESSAGE(NewFuncInfo.getArgKinds()[ArgIdx] == ArgKind::CopyInOut,
@@ -1045,7 +1046,8 @@ appendTransformedFuncRetPortion(Value &NewRetVal, int RetIdx, int ArgIdx,
10451046
CurRetByPtr = cast<AddrSpaceCastInst>(CurRetByPtr)->getOperand(0);
10461047
IGC_ASSERT_MESSAGE(isa<AllocaInst>(CurRetByPtr),
10471048
"corresponding alloca is expected");
1048-
Value *CurRetByVal = Builder.CreateLoad(CurRetByPtr);
1049+
Value *CurRetByVal = Builder.CreateLoad(
1050+
CurRetByPtr->getType()->getPointerElementType(), CurRetByPtr);
10491051
return Builder.CreateInsertValue(&NewRetVal, CurRetByVal, RetIdx);
10501052
}
10511053

@@ -1820,7 +1822,9 @@ bool CMLowerVLoadVStore::lowerLoadStore(Function &F) {
18201822
if (GenXIntrinsic::isVStore(&Inst))
18211823
Builder.CreateStore(Inst.getOperand(0), Inst.getOperand(1));
18221824
else {
1823-
auto LI = Builder.CreateLoad(Inst.getOperand(0), Inst.getName());
1825+
Value *Op0 = Inst.getOperand(0);
1826+
auto LI = Builder.CreateLoad(Op0->getType()->getPointerElementType(),
1827+
Op0, Inst.getName());
18241828
LI->setDebugLoc(Inst.getDebugLoc());
18251829
Inst.replaceAllUsesWith(LI);
18261830
}
@@ -2034,13 +2038,16 @@ void ArgRefPattern::process() {
20342038

20352039
if (CopyOutRegion) {
20362040
Builder.SetInsertPoint(CopyOutRegion);
2037-
CopyOutRegion->setArgOperand(0, Builder.CreateLoad(BaseAlloca));
2041+
CopyOutRegion->setArgOperand(
2042+
0, Builder.CreateLoad(BaseAlloca->getType()->getPointerElementType(),
2043+
BaseAlloca));
20382044
}
20392045

20402046
// Rewrite all stores.
20412047
for (auto ST : VStores) {
20422048
Builder.SetInsertPoint(ST);
2043-
Value *OldVal = Builder.CreateLoad(BaseAlloca);
2049+
Value *OldVal = Builder.CreateLoad(
2050+
BaseAlloca->getType()->getPointerElementType(), BaseAlloca);
20442051
// Always use copy-in region arguments as copy-out region
20452052
// arguments do not dominate this store.
20462053
auto M = ST->getParent()->getParent()->getParent();
@@ -2068,7 +2075,8 @@ void ArgRefPattern::process() {
20682075
continue;
20692076

20702077
Builder.SetInsertPoint(LI);
2071-
Value *SrcVal = Builder.CreateLoad(BaseAlloca);
2078+
Value *SrcVal = Builder.CreateLoad(
2079+
BaseAlloca->getType()->getPointerElementType(), BaseAlloca);
20722080
SmallVector<Value *, 8> Args(CopyInRegion->arg_operands());
20732081
Args[0] = SrcVal;
20742082
Value *Val = Builder.CreateCall(RdFn, Args);

IGC/VectorCompiler/lib/GenXOpts/CMTrans/CMKernelArgOffset.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,9 @@ void CMKernelArgOffset::resolveByValArgs(Function *F) const {
500500
Value *BaseAsI8Ptr = Builder.CreateBitCast(Base, Builder.getInt8PtrTy(),
501501
Base->getName() + ".i8");
502502
for (const auto &Info : KM->arg_lin(&Arg)) {
503-
Value *StoreAddrUntyped = Builder.CreateGEP(BaseAsI8Ptr, Info.Offset);
503+
Type *Ty = cast<PointerType>(BaseAsI8Ptr->getType()->getScalarType())
504+
->getElementType();
505+
Value *StoreAddrUntyped = Builder.CreateGEP(Ty, BaseAsI8Ptr, Info.Offset);
504506
Value *StoreAddrTyped = Builder.CreateBitCast(
505507
StoreAddrUntyped, Info.Arg->getType()->getPointerTo());
506508
Builder.CreateStore(Info.Arg, StoreAddrTyped);

IGC/WrapperLLVM/include/llvmWrapper/IR/IRBuilder.h

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ namespace IGCLLVM
189189
#endif
190190

191191
#if LLVM_VERSION_MAJOR >= 13
192+
inline llvm::LoadInst* CreateLoad(llvm::Value* Ptr, const char *Name)
193+
{
194+
Type* ptrType = Ptr->getType()->getPointerElementType();
195+
return llvm::IRBuilder<T, InserterTyDef()>::CreateLoad(ptrType, Ptr, Name);
196+
}
197+
192198
inline llvm::LoadInst* CreateLoad(llvm::Value* Ptr, const Twine &Name = "")
193199
{
194200
Type* ptrType = Ptr->getType()->getPointerElementType();
@@ -201,6 +207,8 @@ namespace IGCLLVM
201207
return llvm::IRBuilder<T, InserterTyDef()>::CreateLoad(ptrType, Ptr, isVolatile, Name);
202208
}
203209

210+
using llvm::IRBuilder<T, InserterTyDef()>::CreateLoad;
211+
204212
inline llvm::LoadInst* CreateAlignedLoad(llvm::Value* Ptr, IGCLLVM::Align Align, const llvm::Twine& Name = "")
205213
{
206214
Type* ptrType = Ptr->getType()->getPointerElementType();
@@ -215,23 +223,65 @@ namespace IGCLLVM
215223

216224
inline llvm::Value* CreateConstGEP1_32(
217225
llvm::Value* Ptr,
218-
uint64_t Idx0,
226+
unsigned Idx0,
219227
const llvm::Twine& Name = "")
220228
{
221229
return llvm::IRBuilder<T, InserterTyDef()>::CreateConstGEP1_32(Ptr->getType()->getPointerElementType(), Ptr, Idx0, Name);
222230
}
223231

232+
using llvm::IRBuilder<T, InserterTyDef()>::CreateConstGEP1_32;
233+
224234
inline llvm::Value* CreateInBoundsGEP(llvm::Value *Ptr, llvm::ArrayRef<llvm::Value*> IdxList,
225235
const llvm::Twine &Name = "") {
226236
Type *Ty = cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
227237
return llvm::IRBuilder<T, InserterTyDef()>::CreateInBoundsGEP(Ty, Ptr, IdxList, Name);
228238
}
229239

240+
using llvm::IRBuilder<T, InserterTyDef()>::CreateInBoundsGEP;
241+
230242
inline llvm::Value* CreateGEP(llvm::Value* Ptr, llvm::ArrayRef<llvm::Value*> IdxList,
231243
const llvm::Twine& Name = "") {
232244
Type* Ty = cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
233245
return llvm::IRBuilder<T, InserterTyDef()>::CreateGEP(Ty, Ptr, IdxList, Name);
234246
}
247+
248+
using llvm::IRBuilder<T, InserterTyDef()>::CreateGEP;
249+
250+
CallInst *CreateMaskedGather(Value *Ptrs, Align Alignment, Value *Mask,
251+
Value *PassThru, const Twine &Name) {
252+
auto *PtrsTy = cast<FixedVectorType>(Ptrs->getType());
253+
auto *PtrTy = cast<PointerType>(PtrsTy->getElementType());
254+
unsigned NumElts = PtrsTy->getNumElements();
255+
auto *Ty = FixedVectorType::get(PtrTy->getElementType(), NumElts);
256+
return llvm::IRBuilder<T, InserterTyDef()>::CreateMaskedGather(
257+
Ty, Ptrs, Alignment, Mask, PassThru, Name);
258+
}
259+
260+
AtomicCmpXchgInst *
261+
CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New,
262+
AtomicOrdering SuccessOrdering,
263+
AtomicOrdering FailureOrdering,
264+
SyncScope::ID SSID = SyncScope::System) {
265+
return llvm::IRBuilder<T, InserterTyDef()>::CreateAtomicCmpXchg(
266+
Ptr, Cmp, New, MaybeAlign(), SuccessOrdering, FailureOrdering,
267+
SSID);
268+
}
269+
270+
AtomicRMWInst *CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr,
271+
Value *Val, AtomicOrdering Ordering,
272+
SyncScope::ID SSID = SyncScope::System) {
273+
return llvm::IRBuilder<T, InserterTyDef()>::CreateAtomicRMW(
274+
Op, Ptr, Val, MaybeAlign(), Ordering, SSID);
275+
}
276+
277+
CallInst *CreateMaskedLoad(Value *Ptr, Align Alignment, Value *Mask,
278+
Value *PassThru, const Twine &Name) {
279+
auto *PtrTy = cast<PointerType>(Ptr->getType());
280+
Type *Ty = PtrTy->getElementType();
281+
return llvm::IRBuilder<T, InserterTyDef()>::CreateMaskedLoad(
282+
Ty, Ptr, Alignment, Mask, PassThru, Name);
283+
}
284+
235285
#endif
236286

237287
inline llvm::Value* CreateConstInBoundsGEP2_64(
@@ -247,6 +297,7 @@ namespace IGCLLVM
247297
#endif
248298
}
249299

300+
using llvm::IRBuilder<T, InserterTyDef()>::CreateConstInBoundsGEP2_64;
250301

251302
inline static llvm::CallInst* Create(llvm::Value* Func, llvm::ArrayRef<llvm::Value*> Args,
252303
llvm::ArrayRef<llvm::OperandBundleDef> Bundles = llvm::None,

0 commit comments

Comments
 (0)