Skip to content

Commit 13ccad4

Browse files
bokrzesiigcbot
authored andcommitted
Porting IGC code to LLVM16 - Removing calls to getBasicBlockList for loop/push_back cases
Porting IGC code to LLVM16 * Removing calls to getBasicBlockList for loop/push_back cases
1 parent e70dcc9 commit 13ccad4

File tree

9 files changed

+30
-23
lines changed

9 files changed

+30
-23
lines changed

IGC/Compiler/CISACodeGen/EstimateFunctionSize.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ void EstimateFunctionSize::runStaticAnalysis()
705705
FunctionNode* Node = get<FunctionNode>(&F);
706706
Node->setEntryFrequency(BFI.getEntryFreq(), 0);
707707

708-
for (auto& B : F.getBasicBlockList())
708+
for (auto& B : F)
709709
Node->blockFreqs[&B] = Scaled64(BFI.getBlockFreq(&B).getFrequency(), 0);
710710
}
711711
updateStaticFuncFreq();
@@ -717,7 +717,7 @@ void EstimateFunctionSize::runStaticAnalysis()
717717
FunctionNode* Node = get<FunctionNode>(&F);
718718
Scaled64 EntryFreq = Node->getEntryFrequency();
719719
PrintStaticProfileGuidedKernelSizeReduction(0x1, "Function frequency of " << Node->F->getName().str() << ": " << Node->getStaticFuncFreqStr())
720-
for (auto& B : F.getBasicBlockList())
720+
for (auto& B : F)
721721
{
722722
Scaled64 BBCount = Node->blockFreqs[&B];
723723
BBCount /= EntryFreq;
@@ -853,7 +853,7 @@ void EstimateFunctionSize::estimateTotalLoopIteration(llvm::Function &F,
853853
void EstimateFunctionSize::analyze() {
854854
auto getSize = [&](llvm::Function &F) {
855855
std::size_t Size = 0;
856-
for (auto &BB : F.getBasicBlockList()) {
856+
for (auto &BB : F) {
857857
std::size_t BlkSize = IGCLLVM::sizeWithoutDebug(&BB);
858858
Size += BlkSize;
859859
}
@@ -862,7 +862,7 @@ void EstimateFunctionSize::analyze() {
862862

863863
auto getSizeWithLoopCnt = [&](llvm::Function &F, LoopInfo &LI) {
864864
std::size_t Size = 0;
865-
for (auto &BB : F.getBasicBlockList()) {
865+
for (auto &BB : F) {
866866
std::size_t BlkSize = IGCLLVM::sizeWithoutDebug(&BB);
867867
Loop *L = LI.getLoopFor(&BB);
868868
if (L) {

IGC/Compiler/CISACodeGen/FPRoundingModeCoalescing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ bool FPRoundingModeCoalescing::runOnFunction(Function &F) {
340340

341341
bool result = false;
342342

343-
for (auto &BB : F.getBasicBlockList()) {
343+
for (auto &BB : F) {
344344
result |= FPRoundingModeCoalescingImpl(MMD, BB).coalesce();
345345
}
346346

IGC/Compiler/CISACodeGen/GenerateFrequencyData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void GenerateFrequencyData::runStaticAnalysis()
107107
PGSS_IGC_DUMP_BLK) != 0)
108108
dbgs() << "Function frequency of " << F.getName().str() << ": " << F_freqs[&F].toString() << "\n";
109109

110-
for (auto& B : F.getBasicBlockList())
110+
for (auto& B : F)
111111
{
112112
Scaled64 BBCount(BFI.getBlockFreq(&B).getFrequency(), 0);
113113
BBCount /= EntryFreq;
@@ -153,7 +153,7 @@ void GenerateFrequencyData::updateStaticFuncFreq(DenseMap<Function*, ScaledNumbe
153153
{
154154
auto& BFI = getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
155155
entryFreqs[&F] = Scaled64(BFI.getEntryFreq(), 0);
156-
for (auto& B : F.getBasicBlockList())
156+
for (auto& B : F)
157157
blockFreqs[&B] = Scaled64(BFI.getBlockFreq(&B).getFrequency(), 0);
158158
}
159159
if (F.isDeclaration())

IGC/Compiler/CISACodeGen/helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ namespace IGC
243243
{
244244
unsigned numberOfExitBlocks = 0;
245245

246-
for (llvm::BasicBlock& block : function.getBasicBlockList())
246+
for (llvm::BasicBlock& block : function)
247247
{
248248
llvm::Instruction* terminator = block.getTerminator();
249249

IGC/Compiler/CISACodeGen/layout.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,6 @@ void Layout::LayoutBlocks(Function& func, LoopInfo& LI)
570570
moveAtomicWrites2Loop(func, LI, false);
571571

572572
// if function has a single exit, then the last block must be an exit
573-
// comment this out due to infinite loop example in OCL
574-
// IGC_ASSERT(PDT.getRootNode()->getBlock() == 0x0 || PDT.getRootNode()->getBlock() == &(func.back()));
575573
// fix the loop-exit pattern, put break-blocks into the loop
576574
for (llvm::Function::iterator blkIter = func.begin(), blkEnd = func.end();
577575
blkIter != blkEnd; ++blkIter)

IGC/Compiler/CustomUnsafeOptPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2811,7 +2811,7 @@ void CustomUnsafeOptPass::reassociateMulAdd(Function& F)
28112811

28122812
using namespace PatternMatch;
28132813

2814-
for (auto& BB : F.getBasicBlockList())
2814+
for (auto& BB : F)
28152815
{
28162816
for (auto I = BB.begin(); I != BB.end(); /*Empty*/)
28172817
{

IGC/Compiler/LegalizationPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,7 @@ static bool needsNoScaling(Value* Val)
28092809
//
28102810
bool IGC::expandFDIVInstructions(llvm::Function &F, ShaderType ShaderTy) {
28112811
bool Changed = false;
2812-
for (auto& BB : F.getBasicBlockList()) {
2812+
for (auto& BB : F) {
28132813
for (auto Iter = BB.begin(); Iter != BB.end();) {
28142814
Instruction* Inst = &*Iter++;
28152815
if (!isCandidateFDiv(Inst))

IGC/LLVM3DBuilder/BuiltinsFrontendDefinitions.hpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ SPDX-License-Identifier: MIT
1818
#include "common/LLVMWarningsPop.hpp"
1919
#include "Probe/Assertion.h"
2020
#include "visa/include/visa_igc_common_header.h"
21+
#include "llvmWrapper/IR/Function.h"
2122

2223
typedef union _gfxResourceAddressSpace
2324
{
@@ -2831,7 +2832,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
28312832
}
28322833
this->CreateCondBr(int1_tgesr, block_major_t, block_not_t);
28332834
this->SetInsertPoint(block_major_t);
2834-
parentFunc->getBasicBlockList().push_back(block_major_t);
2835+
IGCLLVM::pushBackBasicBlock(parentFunc, block_major_t);
28352836

28362837
// Normalize coordinates and gradients.
28372838
llvm::Value* float_tnorm_r = this->CreateFDiv(float_src_r, float_abs_t, VALUE_NAME("tnorm_r"));
@@ -2847,7 +2848,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
28472848
llvm::Value* int1_cmpx_t = this->CreateFCmp(llvm::FCmpInst::FCMP_OGE, float_src_t, zero, VALUE_NAME("cmpx_t"));
28482849
this->CreateCondBr(int1_cmpx_t, block_zp, block_zm);
28492850
this->SetInsertPoint(block_zp);
2850-
parentFunc->getBasicBlockList().push_back(block_zp);
2851+
IGCLLVM::pushBackBasicBlock(parentFunc, block_zp);
28512852

28522853
// Face +Z,
28532854
// major = neg T
@@ -2882,7 +2883,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
28822883

28832884
this->CreateBr(block_final);
28842885
this->SetInsertPoint(block_zm);
2885-
parentFunc->getBasicBlockList().push_back(block_zm);
2886+
IGCLLVM::pushBackBasicBlock(parentFunc, block_zm);
28862887

28872888
// Face -Z,
28882889
// major = T
@@ -2915,15 +2916,15 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
29152916

29162917
this->CreateBr(block_final);
29172918
this->SetInsertPoint(block_not_t);
2918-
parentFunc->getBasicBlockList().push_back(block_not_t);
2919+
IGCLLVM::pushBackBasicBlock(parentFunc, block_not_t);
29192920

29202921
// Choose major S or R.
29212922
llvm::Value* int1_cmp_sger = this->CreateFCmp(llvm::FCmpInst::FCMP_OGE, float_abs_s, float_abs_r, VALUE_NAME("cmp_sger"));
29222923

29232924
// Major coordinate is S, faces could be +Y or -Y
29242925
this->CreateCondBr(int1_cmp_sger, block_major_s, block_major_r);
29252926
this->SetInsertPoint(block_major_s);
2926-
parentFunc->getBasicBlockList().push_back(block_major_s);
2927+
IGCLLVM::pushBackBasicBlock(parentFunc, block_major_s);
29272928

29282929
// Normalize coordinates and gradients.
29292930
llvm::Value* float_snorm_r = this->CreateFDiv(float_src_r, float_abs_s, VALUE_NAME("snorm_r"));
@@ -2939,7 +2940,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
29392940
llvm::Value* int1_cmpx_s = this->CreateFCmp(llvm::FCmpInst::FCMP_OGE, float_src_s, zero, VALUE_NAME("cmpx_s"));
29402941
this->CreateCondBr(int1_cmpx_s, block_yp, block_ym);
29412942
this->SetInsertPoint(block_yp);
2942-
parentFunc->getBasicBlockList().push_back(block_yp);
2943+
IGCLLVM::pushBackBasicBlock(parentFunc, block_yp);
29432944

29442945
// Face +Y,
29452946
// major = neg S
@@ -2974,7 +2975,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
29742975

29752976
this->CreateBr(block_final);
29762977
this->SetInsertPoint(block_ym);
2977-
parentFunc->getBasicBlockList().push_back(block_ym);
2978+
IGCLLVM::pushBackBasicBlock(parentFunc, block_ym);
29782979

29792980
// Face -Y,
29802981
// major = S
@@ -3007,7 +3008,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
30073008

30083009
this->CreateBr(block_final);
30093010
this->SetInsertPoint(block_major_r);
3010-
parentFunc->getBasicBlockList().push_back(block_major_r);
3011+
IGCLLVM::pushBackBasicBlock(parentFunc, block_major_r);
30113012

30123013
// Major coordinate is R, faces could be +X or -X
30133014

@@ -3025,7 +3026,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
30253026
llvm::Value* int1_cmpx_r = this->CreateFCmp(llvm::FCmpInst::FCMP_OGE, float_src_r, zero, VALUE_NAME("cmpx_r"));
30263027
this->CreateCondBr(int1_cmpx_r, block_xp, block_xm);
30273028
this->SetInsertPoint(block_xp);
3028-
parentFunc->getBasicBlockList().push_back(block_xp);
3029+
IGCLLVM::pushBackBasicBlock(parentFunc, block_xp);
30293030

30303031
// Face +X,
30313032
// major = neg R
@@ -3058,7 +3059,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
30583059

30593060
this->CreateBr(block_final);
30603061
this->SetInsertPoint(block_xm);
3061-
parentFunc->getBasicBlockList().push_back(block_xm);
3062+
IGCLLVM::pushBackBasicBlock(parentFunc, block_xm);
30623063

30633064
// Face -X,
30643065
// major = R
@@ -3091,7 +3092,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
30913092

30923093
this->CreateBr(block_final);
30933094
this->SetInsertPoint(block_final);
3094-
parentFunc->getBasicBlockList().push_back(block_final);
3095+
IGCLLVM::pushBackBasicBlock(parentFunc, block_final);
30953096

30963097
llvm::PHINode* phi_u = this->CreatePHI(coordType, 6, VALUE_NAME("phi_u"));
30973098
phi_u->addIncoming(float_face_xp_u, block_xp);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ inline bool onlyWritesMemory(llvm::Function *F) {
6363
#endif
6464
}
6565

66+
inline void pushBackBasicBlock(llvm::Function* F, llvm::BasicBlock* BB) {
67+
#if LLVM_VERSION_MAJOR < 16
68+
F->getBasicBlockList().push_back(BB);
69+
#else
70+
F->insert(F->end(), BB);
71+
#endif
72+
}
73+
6674
} // namespace IGCLLVM
6775

6876
#endif

0 commit comments

Comments
 (0)