Skip to content

Commit

Permalink
Porting IGC code to LLVM16 - Removing calls to getBasicBlockList for…
Browse files Browse the repository at this point in the history
… loop/push_back cases

Porting IGC code to LLVM16

* Removing calls to getBasicBlockList for loop/push_back cases
  • Loading branch information
bokrzesi authored and igcbot committed Aug 29, 2024
1 parent e70dcc9 commit 13ccad4
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 23 deletions.
8 changes: 4 additions & 4 deletions IGC/Compiler/CISACodeGen/EstimateFunctionSize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ void EstimateFunctionSize::runStaticAnalysis()
FunctionNode* Node = get<FunctionNode>(&F);
Node->setEntryFrequency(BFI.getEntryFreq(), 0);

for (auto& B : F.getBasicBlockList())
for (auto& B : F)
Node->blockFreqs[&B] = Scaled64(BFI.getBlockFreq(&B).getFrequency(), 0);
}
updateStaticFuncFreq();
Expand All @@ -717,7 +717,7 @@ void EstimateFunctionSize::runStaticAnalysis()
FunctionNode* Node = get<FunctionNode>(&F);
Scaled64 EntryFreq = Node->getEntryFrequency();
PrintStaticProfileGuidedKernelSizeReduction(0x1, "Function frequency of " << Node->F->getName().str() << ": " << Node->getStaticFuncFreqStr())
for (auto& B : F.getBasicBlockList())
for (auto& B : F)
{
Scaled64 BBCount = Node->blockFreqs[&B];
BBCount /= EntryFreq;
Expand Down Expand Up @@ -853,7 +853,7 @@ void EstimateFunctionSize::estimateTotalLoopIteration(llvm::Function &F,
void EstimateFunctionSize::analyze() {
auto getSize = [&](llvm::Function &F) {
std::size_t Size = 0;
for (auto &BB : F.getBasicBlockList()) {
for (auto &BB : F) {
std::size_t BlkSize = IGCLLVM::sizeWithoutDebug(&BB);
Size += BlkSize;
}
Expand All @@ -862,7 +862,7 @@ void EstimateFunctionSize::analyze() {

auto getSizeWithLoopCnt = [&](llvm::Function &F, LoopInfo &LI) {
std::size_t Size = 0;
for (auto &BB : F.getBasicBlockList()) {
for (auto &BB : F) {
std::size_t BlkSize = IGCLLVM::sizeWithoutDebug(&BB);
Loop *L = LI.getLoopFor(&BB);
if (L) {
Expand Down
2 changes: 1 addition & 1 deletion IGC/Compiler/CISACodeGen/FPRoundingModeCoalescing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ bool FPRoundingModeCoalescing::runOnFunction(Function &F) {

bool result = false;

for (auto &BB : F.getBasicBlockList()) {
for (auto &BB : F) {
result |= FPRoundingModeCoalescingImpl(MMD, BB).coalesce();
}

Expand Down
4 changes: 2 additions & 2 deletions IGC/Compiler/CISACodeGen/GenerateFrequencyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void GenerateFrequencyData::runStaticAnalysis()
PGSS_IGC_DUMP_BLK) != 0)
dbgs() << "Function frequency of " << F.getName().str() << ": " << F_freqs[&F].toString() << "\n";

for (auto& B : F.getBasicBlockList())
for (auto& B : F)
{
Scaled64 BBCount(BFI.getBlockFreq(&B).getFrequency(), 0);
BBCount /= EntryFreq;
Expand Down Expand Up @@ -153,7 +153,7 @@ void GenerateFrequencyData::updateStaticFuncFreq(DenseMap<Function*, ScaledNumbe
{
auto& BFI = getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
entryFreqs[&F] = Scaled64(BFI.getEntryFreq(), 0);
for (auto& B : F.getBasicBlockList())
for (auto& B : F)
blockFreqs[&B] = Scaled64(BFI.getBlockFreq(&B).getFrequency(), 0);
}
if (F.isDeclaration())
Expand Down
2 changes: 1 addition & 1 deletion IGC/Compiler/CISACodeGen/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ namespace IGC
{
unsigned numberOfExitBlocks = 0;

for (llvm::BasicBlock& block : function.getBasicBlockList())
for (llvm::BasicBlock& block : function)
{
llvm::Instruction* terminator = block.getTerminator();

Expand Down
2 changes: 0 additions & 2 deletions IGC/Compiler/CISACodeGen/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,6 @@ void Layout::LayoutBlocks(Function& func, LoopInfo& LI)
moveAtomicWrites2Loop(func, LI, false);

// if function has a single exit, then the last block must be an exit
// comment this out due to infinite loop example in OCL
// IGC_ASSERT(PDT.getRootNode()->getBlock() == 0x0 || PDT.getRootNode()->getBlock() == &(func.back()));
// fix the loop-exit pattern, put break-blocks into the loop
for (llvm::Function::iterator blkIter = func.begin(), blkEnd = func.end();
blkIter != blkEnd; ++blkIter)
Expand Down
2 changes: 1 addition & 1 deletion IGC/Compiler/CustomUnsafeOptPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2811,7 +2811,7 @@ void CustomUnsafeOptPass::reassociateMulAdd(Function& F)

using namespace PatternMatch;

for (auto& BB : F.getBasicBlockList())
for (auto& BB : F)
{
for (auto I = BB.begin(); I != BB.end(); /*Empty*/)
{
Expand Down
2 changes: 1 addition & 1 deletion IGC/Compiler/LegalizationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2809,7 +2809,7 @@ static bool needsNoScaling(Value* Val)
//
bool IGC::expandFDIVInstructions(llvm::Function &F, ShaderType ShaderTy) {
bool Changed = false;
for (auto& BB : F.getBasicBlockList()) {
for (auto& BB : F) {
for (auto Iter = BB.begin(); Iter != BB.end();) {
Instruction* Inst = &*Iter++;
if (!isCandidateFDiv(Inst))
Expand Down
23 changes: 12 additions & 11 deletions IGC/LLVM3DBuilder/BuiltinsFrontendDefinitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SPDX-License-Identifier: MIT
#include "common/LLVMWarningsPop.hpp"
#include "Probe/Assertion.h"
#include "visa/include/visa_igc_common_header.h"
#include "llvmWrapper/IR/Function.h"

typedef union _gfxResourceAddressSpace
{
Expand Down Expand Up @@ -2831,7 +2832,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep
}
this->CreateCondBr(int1_tgesr, block_major_t, block_not_t);
this->SetInsertPoint(block_major_t);
parentFunc->getBasicBlockList().push_back(block_major_t);
IGCLLVM::pushBackBasicBlock(parentFunc, block_major_t);

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

// Face +Z,
// major = neg T
Expand Down Expand Up @@ -2882,7 +2883,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep

this->CreateBr(block_final);
this->SetInsertPoint(block_zm);
parentFunc->getBasicBlockList().push_back(block_zm);
IGCLLVM::pushBackBasicBlock(parentFunc, block_zm);

// Face -Z,
// major = T
Expand Down Expand Up @@ -2915,15 +2916,15 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep

this->CreateBr(block_final);
this->SetInsertPoint(block_not_t);
parentFunc->getBasicBlockList().push_back(block_not_t);
IGCLLVM::pushBackBasicBlock(parentFunc, block_not_t);

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

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

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

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

this->CreateBr(block_final);
this->SetInsertPoint(block_ym);
parentFunc->getBasicBlockList().push_back(block_ym);
IGCLLVM::pushBackBasicBlock(parentFunc, block_ym);

// Face -Y,
// major = S
Expand Down Expand Up @@ -3007,7 +3008,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep

this->CreateBr(block_final);
this->SetInsertPoint(block_major_r);
parentFunc->getBasicBlockList().push_back(block_major_r);
IGCLLVM::pushBackBasicBlock(parentFunc, block_major_r);

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

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

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

this->CreateBr(block_final);
this->SetInsertPoint(block_xm);
parentFunc->getBasicBlockList().push_back(block_xm);
IGCLLVM::pushBackBasicBlock(parentFunc, block_xm);

// Face -X,
// major = R
Expand Down Expand Up @@ -3091,7 +3092,7 @@ inline SampleD_DC_FromCubeParams LLVM3DBuilder<preserveNames, T, Inserter>::Prep

this->CreateBr(block_final);
this->SetInsertPoint(block_final);
parentFunc->getBasicBlockList().push_back(block_final);
IGCLLVM::pushBackBasicBlock(parentFunc, block_final);

llvm::PHINode* phi_u = this->CreatePHI(coordType, 6, VALUE_NAME("phi_u"));
phi_u->addIncoming(float_face_xp_u, block_xp);
Expand Down
8 changes: 8 additions & 0 deletions IGC/WrapperLLVM/include/llvmWrapper/IR/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ inline bool onlyWritesMemory(llvm::Function *F) {
#endif
}

inline void pushBackBasicBlock(llvm::Function* F, llvm::BasicBlock* BB) {
#if LLVM_VERSION_MAJOR < 16
F->getBasicBlockList().push_back(BB);
#else
F->insert(F->end(), BB);
#endif
}

} // namespace IGCLLVM

#endif

0 comments on commit 13ccad4

Please sign in to comment.