Skip to content

Commit 44ef7dc

Browse files
amielczaigcbot
authored andcommitted
insertPosition API Wrapper
Wrap insertPosition to ensure buildability with LLVM22.
1 parent 17b5b0c commit 44ef7dc

59 files changed

Lines changed: 803 additions & 663 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

IGC/AdaptorCommon/AddImplicitArgs.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ SPDX-License-Identifier: MIT
2525
#include <llvm/ADT/DepthFirstIterator.h>
2626
#include "common/LLVMWarningsPop.hpp"
2727
#include "llvmWrapper/IR/Function.h"
28+
#include "llvmWrapper/IR/DIBuilder.h"
2829
#include <llvmWrapper/ADT/STLExtras.h>
2930
#include <llvmWrapper/IR/Instructions.h>
3031

@@ -241,7 +242,7 @@ void AddImplicitArgs::updateNewFuncArgs(llvm::Function *pFunc, llvm::Function *p
241242
for (const auto &toReplace : newAddr) {
242243
auto d = dyn_cast<DbgDeclareInst>(toReplace.first);
243244

244-
llvm::DIBuilder Builder(*pNewFunc->getParent());
245+
IGCLLVM::DIBuilder Builder(*pNewFunc->getParent());
245246
auto DIVar = d->getVariable();
246247
auto DIExpr = d->getExpression();
247248

@@ -391,9 +392,9 @@ void AddImplicitArgs::replaceAllUsesWithNewOCLBuiltinFunction(llvm::Function *ol
391392
// insert new call instruction before old one
392393
llvm::CallInst *inst;
393394
if (new_func->getReturnType()->isVoidTy()) {
394-
inst = CallInst::Create(new_func, new_args, "", cInst);
395+
inst = CallInst::Create(new_func, new_args, "", IGCLLVM::insertPosition(cInst));
395396
} else {
396-
inst = CallInst::Create(new_func, new_args, new_func->getName(), cInst);
397+
inst = CallInst::Create(new_func, new_args, new_func->getName(), IGCLLVM::insertPosition(cInst));
397398
}
398399
inst->setCallingConv(new_func->getCallingConv());
399400
inst->setDebugLoc(cInst->getDebugLoc());
@@ -414,7 +415,7 @@ llvm::Value *AddImplicitArgs::coerce(llvm::Value *arg, llvm::Type *type, llvm::I
414415
std::string str0;
415416
llvm::raw_string_ostream s(str0);
416417
arg->getType()->print(s);
417-
return new llvm::BitCastInst(arg, type, "", insertBefore);
418+
return new llvm::BitCastInst(arg, type, "", IGCLLVM::insertPosition(insertBefore));
418419
}
419420

420421
// Builtin CallGraph Analysis

IGC/AdaptorCommon/RayTracing/SplitAsyncUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ static void rewritePHIs(BasicBlock &BB) {
7676
do {
7777
int Index = PN->getBasicBlockIndex(IncomingBB);
7878
Value *V = PN->getIncomingValue(Index);
79-
PHINode *InputV =
80-
PHINode::Create(V->getType(), 1, V->getName() + Twine(".") + BB.getName(), &IncomingBB->front());
79+
PHINode *InputV = PHINode::Create(V->getType(), 1, V->getName() + Twine(".") + BB.getName(),
80+
IGCLLVM::insertPosition(&IncomingBB->front()));
8181
InputV->addIncoming(V, Pred);
8282
PN->setIncomingValue(Index, InputV);
8383
PN = dyn_cast<PHINode>(PN->getNextNode());

IGC/AdaptorCommon/RayTracing/TraceRayInlineLoweringPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class TraceRayInlineLoweringPass : public FunctionPass {
8383
GetElementPtrInst *getShMemRTCtrl(RTBuilder &builder, Value *queryIndex) {
8484
return GetElementPtrInst::Create(m_ShMemRTCtrls->getAllocatedType(), m_ShMemRTCtrls,
8585
{builder.getInt32(0), queryIndex}, VALUE_NAME("&shadowMem.RTCtrl"),
86-
&(*builder.GetInsertPoint()));
86+
IGCLLVM::insertPosition(&(*builder.GetInsertPoint())));
8787
}
8888

8989
// return rtStacks[index]

IGC/Compiler/CISACodeGen/ConstantCoalescing.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,8 @@ void ConstantCoalescing::CombineTwoLoads(BufChunk *cov_chunk, Instruction *load,
718718
}
719719
// new IntToPtr and new load
720720
// cannot use irbuilder to create IntToPtr. It may create ConstantExpr instead of instruction
721-
auto *ptrcast =
722-
CastInst::CreateBitOrPointerCast(eac, IGCLLVM::PointerType::get(vty, addrSpace), "twoScalar", load0);
721+
auto *ptrcast = CastInst::CreateBitOrPointerCast(eac, IGCLLVM::PointerType::get(vty, addrSpace), "twoScalar",
722+
IGCLLVM::insertPosition(load0));
723723
m_TT->RegisterNewValueAndAssignID(ptrcast);
724724
wiAns->incUpdateDepend(ptrcast, WIAnalysis::RANDOM);
725725
cov_chunk->chunkIO = irBuilder->CreateLoad(vty, ptrcast, false);
@@ -1216,7 +1216,7 @@ Value *ConstantCoalescing::SimpleBaseOffset(Value *elt_idxv, uint64_t &offset, E
12161216
if (it1 != m_BaseOffsets.end()) {
12171217
return it1->second;
12181218
}
1219-
Instruction *newBase = BinaryOperator::Create(Instruction::Add, base0, base1, "", expr);
1219+
Instruction *newBase = BinaryOperator::Create(Instruction::Add, base0, base1, "", IGCLLVM::insertPosition(expr));
12201220
wiAns->incUpdateDepend(newBase, std::max(wiAns->whichDepend(base0), wiAns->whichDepend(base1)));
12211221
m_BaseOffsets.insert({MakeSortedPair(base0, base1), newBase});
12221222
return newBase;
@@ -1452,7 +1452,8 @@ Instruction *ConstantCoalescing::CreateChunkLoad(Instruction *seedi, BufChunk *c
14521452
unsigned addrSpace = (cast<PointerType>(cb_ptr->getType()))->getAddressSpace();
14531453
PointerType *pty = IGCLLVM::PointerType::get(vty, addrSpace);
14541454
// cannot use irbuilder to create IntToPtr. It may create ConstantExpr instead of instruction
1455-
Instruction *ptr = IntToPtrInst::Create(Instruction::IntToPtr, eac, pty, "chunkPtr", seedi);
1455+
Instruction *ptr =
1456+
IntToPtrInst::Create(Instruction::IntToPtr, eac, pty, "chunkPtr", IGCLLVM::insertPosition(seedi));
14561457
m_TT->RegisterNewValueAndAssignID(ptr);
14571458
// Update debug location
14581459
ptr->setDebugLoc(irBuilder->getCurrentDebugLocation());

IGC/Compiler/CISACodeGen/Emu64OpsPass.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,9 @@ bool InstExpander::visitShl(BinaryOperator &BinOp) {
840840
// uniform one in most cases.
841841
Value *NE = IRB->CreateICmpNE(ShAmt, Constant::getNullValue(ShAmt->getType()));
842842
BasicBlock *JointBB = OldBB->splitBasicBlock(&BinOp);
843-
ResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".shl.outer.merge.lo", &BinOp);
843+
ResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".shl.outer.merge.lo", IGCLLVM::insertPosition(&BinOp));
844844
cast<Instruction>(ResLo)->setDebugLoc(BinOpDebugLoc);
845-
ResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".shl.outer.merge.hi", &BinOp);
845+
ResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".shl.outer.merge.hi", IGCLLVM::insertPosition(&BinOp));
846846
cast<Instruction>(ResHi)->setDebugLoc(BinOpDebugLoc);
847847

848848
BasicBlock *TrueBB = BasicBlock::Create(*Emu->getContext(), ".shl.outer.true.branch");
@@ -861,9 +861,9 @@ bool InstExpander::visitShl(BinaryOperator &BinOp) {
861861
// Prepare to generate branches to handle the case where `ShAmt` is less
862862
// than 32 (true branch) or otherwise (false branch).
863863
BasicBlock *InnerJBB = TrueBB->splitBasicBlock(TrueJmp);
864-
InnerResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".shl.merge.inner.lo", TrueJmp);
864+
InnerResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".shl.merge.inner.lo", IGCLLVM::insertPosition(TrueJmp));
865865
InnerResLo->setDebugLoc(BinOpDebugLoc);
866-
InnerResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".shl.merge.inner.hi", TrueJmp);
866+
InnerResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".shl.merge.inner.hi", IGCLLVM::insertPosition(TrueJmp));
867867
InnerResHi->setDebugLoc(BinOpDebugLoc);
868868

869869
InnerTBB = BasicBlock::Create(*Emu->getContext(), ".shl.inner.true.branch");
@@ -966,9 +966,9 @@ bool InstExpander::visitLShr(BinaryOperator &BinOp) {
966966
// uniform one in most cases.
967967
Value *NE = IRB->CreateICmpNE(ShAmt, Constant::getNullValue(ShAmt->getType()));
968968
BasicBlock *JointBB = OldBB->splitBasicBlock(&BinOp);
969-
ResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".lshr.outer.merge.lo", &BinOp);
969+
ResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".lshr.outer.merge.lo", IGCLLVM::insertPosition(&BinOp));
970970
cast<Instruction>(ResLo)->setDebugLoc(BinOpDebugLoc);
971-
ResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".lshr.outer.merge.hi", &BinOp);
971+
ResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".lshr.outer.merge.hi", IGCLLVM::insertPosition(&BinOp));
972972
cast<Instruction>(ResHi)->setDebugLoc(BinOpDebugLoc);
973973

974974
BasicBlock *TrueBB = BasicBlock::Create(*Emu->getContext(), ".lshr.outer.true.branch");
@@ -987,9 +987,9 @@ bool InstExpander::visitLShr(BinaryOperator &BinOp) {
987987
// Prepare to generate branches to handle the case where `ShAmt` is less
988988
// than 32 (true branch) or otherwise (false branch).
989989
BasicBlock *InnerJBB = TrueBB->splitBasicBlock(TrueJmp);
990-
InnerResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".lshr.merge.inner.lo", TrueJmp);
990+
InnerResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".lshr.merge.inner.lo", IGCLLVM::insertPosition(TrueJmp));
991991
InnerResLo->setDebugLoc(BinOpDebugLoc);
992-
InnerResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".lshr.merge.inner.hi", TrueJmp);
992+
InnerResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".lshr.merge.inner.hi", IGCLLVM::insertPosition(TrueJmp));
993993
InnerResHi->setDebugLoc(BinOpDebugLoc);
994994

995995
InnerTBB = BasicBlock::Create(*Emu->getContext(), ".lshr.inner.true.branch");
@@ -1097,9 +1097,9 @@ bool InstExpander::visitAShr(BinaryOperator &BinOp) {
10971097
// uniform one in most cases.
10981098
Value *NE = IRB->CreateICmpNE(ShAmt, Constant::getNullValue(ShAmt->getType()));
10991099
BasicBlock *JointBB = OldBB->splitBasicBlock(&BinOp);
1100-
ResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".ashr.outer.merge.lo", &BinOp);
1100+
ResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".ashr.outer.merge.lo", IGCLLVM::insertPosition(&BinOp));
11011101
cast<Instruction>(ResLo)->setDebugLoc(BinOpDebugLoc);
1102-
ResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".ashr.outer.merge.hi", &BinOp);
1102+
ResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".ashr.outer.merge.hi", IGCLLVM::insertPosition(&BinOp));
11031103
cast<Instruction>(ResHi)->setDebugLoc(BinOpDebugLoc);
11041104

11051105
BasicBlock *TrueBB = BasicBlock::Create(*Emu->getContext(), ".ashr.outer.true.branch");
@@ -1118,9 +1118,9 @@ bool InstExpander::visitAShr(BinaryOperator &BinOp) {
11181118
// Prepare to generate branches to handle the case where `ShAmt` is less
11191119
// than 32 or otherwise.
11201120
BasicBlock *InnerJBB = TrueBB->splitBasicBlock(TrueJmp);
1121-
InnerResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".ashr.merge.inner.lo", TrueJmp);
1121+
InnerResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".ashr.merge.inner.lo", IGCLLVM::insertPosition(TrueJmp));
11221122
InnerResLo->setDebugLoc(BinOpDebugLoc);
1123-
InnerResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".ashr.merge.inner.hi", TrueJmp);
1123+
InnerResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".ashr.merge.inner.hi", IGCLLVM::insertPosition(TrueJmp));
11241124
InnerResHi->setDebugLoc(BinOpDebugLoc);
11251125

11261126
InnerTBB = BasicBlock::Create(*Emu->getContext(), ".ashr.inner.true.branch");
@@ -1490,7 +1490,7 @@ Value *InstExpander::convertUIToFP32(Type *DstTy, Value *Lo, Value *Hi, Instruct
14901490
IRB->SetInsertPoint(Pos);
14911491
DebugLoc PosDebugLoc = Pos->getDebugLoc();
14921492

1493-
PHINode *Res = PHINode::Create(IRB->getInt32Ty(), 2, ".u2f.outer.merge", Pos);
1493+
PHINode *Res = PHINode::Create(IRB->getInt32Ty(), 2, ".u2f.outer.merge", IGCLLVM::insertPosition(Pos));
14941494
Res->setDebugLoc(PosDebugLoc);
14951495

14961496
{
@@ -1510,9 +1510,11 @@ Value *InstExpander::convertUIToFP32(Type *DstTy, Value *Lo, Value *Hi, Instruct
15101510
NE = IRB->CreateICmpNE(ShAmt, Constant::getNullValue(ShAmt->getType()));
15111511

15121512
BasicBlock *InnerJBB = TrueBB->splitBasicBlock(TrueJmp);
1513-
PHINode *InnerResHi = PHINode::Create(IRB->getInt32Ty(), 2, ".u2f.inner.merge.hi", TrueJmp);
1513+
PHINode *InnerResHi =
1514+
PHINode::Create(IRB->getInt32Ty(), 2, ".u2f.inner.merge.hi", IGCLLVM::insertPosition(TrueJmp));
15141515
InnerResHi->setDebugLoc(PosDebugLoc);
1515-
PHINode *InnerResLo = PHINode::Create(IRB->getInt32Ty(), 2, ".u2f.inner.merge.lo", TrueJmp);
1516+
PHINode *InnerResLo =
1517+
PHINode::Create(IRB->getInt32Ty(), 2, ".u2f.inner.merge.lo", IGCLLVM::insertPosition(TrueJmp));
15161518
InnerResLo->setDebugLoc(PosDebugLoc);
15171519

15181520
BasicBlock *InnerTBB = BasicBlock::Create(*Emu->getContext(), ".u2f.inner.true.branch");
@@ -1544,7 +1546,8 @@ Value *InstExpander::convertUIToFP32(Type *DstTy, Value *Lo, Value *Hi, Instruct
15441546
NE = IRB->CreateICmpNE(InnerResLo, Constant::getNullValue(InnerResLo->getType()));
15451547

15461548
BasicBlock *RoundingJBB = InnerJBB->splitBasicBlock(InnerJmp);
1547-
PHINode *RoundingRes = PHINode::Create(IRB->getInt32Ty(), 2, ".u2f.rounding.merge.hi", InnerJmp);
1549+
PHINode *RoundingRes =
1550+
PHINode::Create(IRB->getInt32Ty(), 2, ".u2f.rounding.merge.hi", IGCLLVM::insertPosition(InnerJmp));
15481551
RoundingRes->setDebugLoc(PosDebugLoc);
15491552

15501553
BasicBlock *RoundingBB = BasicBlock::Create(*Emu->getContext(), ".u2f.rounding.branch");

IGC/Compiler/CISACodeGen/FixAddrSpaceCast.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SPDX-License-Identifier: MIT
1919
#include <llvm/IR/BasicBlock.h>
2020
#include "common/LLVMWarningsPop.hpp"
2121
#include "llvmWrapper/IR/DerivedTypes.h"
22+
#include "llvmWrapper/IR/Instructions.h"
2223

2324
using namespace llvm;
2425
using namespace IGC;
@@ -220,9 +221,10 @@ bool AddrSpaceCastFixing::fixCase1(Instruction *I, BasicBlock::iterator &BI) con
220221

221222
// Create `addrspacecast` if necessary.
222223
if (SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace())
223-
V = CastInst::Create(Instruction::AddrSpaceCast, V, DstPtrTy, I->getName() + ".fix1.addrspacecast", I);
224+
V = CastInst::Create(Instruction::AddrSpaceCast, V, DstPtrTy, I->getName() + ".fix1.addrspacecast",
225+
IGCLLVM::insertPosition(I));
224226
else
225-
V = CastInst::Create(Instruction::BitCast, V, DstPtrTy, I->getName() + ".fix1.bitcast", I);
227+
V = CastInst::Create(Instruction::BitCast, V, DstPtrTy, I->getName() + ".fix1.bitcast", IGCLLVM::insertPosition(I));
226228

227229
// Remove the short sequence of `ptrtoint` followed by `inttoptr`.
228230
if (Instruction *VInst = dyn_cast<Instruction>(V)) {
@@ -267,13 +269,15 @@ bool AddrSpaceCastFixing::fixCase2(Instruction *I, BasicBlock::iterator &BI) con
267269
if (TVal->hasOneUse() && isa<AddrSpaceCastInst>(TVal))
268270
TVal->mutateType(DstPtrTy);
269271
else
270-
TVal = CastInst::Create(Instruction::AddrSpaceCast, TVal, DstPtrTy, TVal->getName() + ".fix2.addrspacecast", SI);
272+
TVal = CastInst::Create(Instruction::AddrSpaceCast, TVal, DstPtrTy, TVal->getName() + ".fix2.addrspacecast",
273+
IGCLLVM::insertPosition(SI));
271274

272275
Value *FVal = SI->getFalseValue();
273276
if (FVal->hasOneUse() && isa<AddrSpaceCastInst>(FVal))
274277
FVal->mutateType(DstPtrTy);
275278
else
276-
FVal = CastInst::Create(Instruction::AddrSpaceCast, FVal, DstPtrTy, FVal->getName() + ".fix2.addrspacecast", SI);
279+
FVal = CastInst::Create(Instruction::AddrSpaceCast, FVal, DstPtrTy, FVal->getName() + ".fix2.addrspacecast",
280+
IGCLLVM::insertPosition(SI));
277281

278282
SI->setOperand(1, TVal);
279283
SI->setOperand(2, FVal);

IGC/Compiler/CISACodeGen/GenCodeGenModule.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,12 +1251,12 @@ void SubroutineInliner::visitGetElementPtrInst(GetElementPtrInst &GEPI) {
12511251
// we need to create a new GEPI because the old one has coded old AS,
12521252
// and we can not create new load instruction with the old GEPI with the correct AS
12531253
// This is WA for a bug in LLVM 11.
1254-
GetElementPtrInst *newGEPI =
1255-
GetElementPtrInst::Create(GEPI.getSourceElementType(), GEPIPointerOperand, Idx, "", &GEPI);
1254+
GetElementPtrInst *newGEPI = GetElementPtrInst::Create(GEPI.getSourceElementType(), GEPIPointerOperand, Idx, "",
1255+
IGCLLVM::insertPosition(&GEPI));
12561256
newGEPI->setIsInBounds(GEPI.isInBounds());
12571257
newGEPI->setDebugLoc(GEPI.getDebugLoc());
12581258

1259-
auto *newLoad = new LoadInst(loadInst->getType(), newGEPI, "", loadInst);
1259+
auto *newLoad = new LoadInst(loadInst->getType(), newGEPI, "", IGCLLVM::insertPosition(loadInst));
12601260
newLoad->setAlignment(IGCLLVM::getAlign(*loadInst));
12611261
loadInst->replaceAllUsesWith(newLoad);
12621262
newLoad->setDebugLoc(loadInst->getDebugLoc());
@@ -1276,14 +1276,14 @@ void SubroutineInliner::visitMemCpyInst(MemCpyInst &I) {
12761276
Value *SrcCast = BitCastInst::Create(Instruction::BitCast, origSrc,
12771277
IGCLLVM::PointerType::get(dyn_cast<PointerType>(Src->getType()),
12781278
origSrc->getType()->getPointerAddressSpace()),
1279-
"", &I);
1279+
"", IGCLLVM::insertPosition(&I));
12801280
I.replaceUsesOfWith(Src, SrcCast);
12811281
}
12821282
if (origDst->getType()->getPointerAddressSpace() != Dst->getType()->getPointerAddressSpace()) {
12831283
Value *DstCast = BitCastInst::Create(Instruction::BitCast, origDst,
12841284
IGCLLVM::PointerType::get(dyn_cast<PointerType>(Dst->getType()),
12851285
origDst->getType()->getPointerAddressSpace()),
1286-
"", &I);
1286+
"", IGCLLVM::insertPosition(&I));
12871287
I.replaceUsesOfWith(Dst, DstCast);
12881288
}
12891289
}

IGC/Compiler/CISACodeGen/HalfPromotion.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ void HalfPromotion::visitPHINode(llvm::PHINode &PHI) {
190190
}
191191

192192
llvm::IGCIRBuilder<> builder(&PHI);
193-
llvm::PHINode *pNewPhi = llvm::PHINode::Create(builder.getFloatTy(), PHI.getNumIncomingValues(), "", &PHI);
193+
llvm::PHINode *pNewPhi =
194+
llvm::PHINode::Create(builder.getFloatTy(), PHI.getNumIncomingValues(), "", IGCLLVM::insertPosition(&PHI));
194195

195196
for (unsigned int i = 0; i < PHI.getNumIncomingValues(); ++i) {
196197
builder.SetInsertPoint(PHI.getIncomingBlock(i)->getTerminator());

0 commit comments

Comments
 (0)