Skip to content

Commit c3e412c

Browse files
igorban-inteligcbot
authored andcommitted
Support lit-tests in CMTrans-passes for llvm-16
List of passes with enabled tests: * CMImpParam * CMLowerVLoadVStore * GenXPacketize * BTIAssignment * ImportOCLBiF
1 parent 8da484e commit c3e412c

Some content is hidden

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

42 files changed

+218
-96
lines changed

IGC/VectorCompiler/include/vc/GenXOpts/CMImpParam.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ void initializeCMImpParamPass(PassRegistry &);
1313
}
1414

1515
struct CMImpParamPass : public llvm::PassInfoMixin<CMImpParamPass> {
16+
bool HasPayloadInMemory = false;
17+
CMImpParamPass(bool HasPayloadInMemoryIn)
18+
: HasPayloadInMemory{HasPayloadInMemoryIn} {};
19+
20+
CMImpParamPass();
21+
1622
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM);
1723
};
1824

IGC/VectorCompiler/include/vc/Support/BackendConfig.h

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,20 @@ class GenXBackendData {
230230
std::unique_ptr<MemoryBuffer> ModuleBuffer);
231231
};
232232

233-
class GenXBackendConfig : public ImmutablePass {
234-
public:
235-
static char ID;
236-
237-
private:
233+
struct GenXBackendConfigResult {
234+
protected:
238235
GenXBackendOptions Options;
239236
GenXBackendData Data;
240237

241-
public:
242-
GenXBackendConfig();
243-
explicit GenXBackendConfig(GenXBackendOptions &&OptionsIn,
244-
GenXBackendData &&DataIn);
238+
GenXBackendConfigResult(GenXBackendOptions &&OptionsIn,
239+
GenXBackendData &&DataIn)
240+
: Options(std::move(OptionsIn)), Data(std::move(DataIn)){};
241+
242+
GenXBackendConfigResult()
243+
: Options{GenXBackendOptions::InitFromLLVMOpts{}},
244+
Data{GenXBackendData::InitFromLLMVOpts{}} {};
245245

246+
public:
246247
// Return whether regalloc results should be printed.
247248
bool enableRegAllocDump() const { return Options.DumpRegAlloc; }
248249

@@ -396,6 +397,30 @@ class GenXBackendConfig : public ImmutablePass {
396397

397398
vc::BinaryKind getBinaryFormat() const { return Options.Binary; }
398399
};
400+
401+
class GenXBackendConfig : public ImmutablePass, public GenXBackendConfigResult {
402+
public:
403+
static char ID;
404+
405+
public:
406+
GenXBackendConfig();
407+
explicit GenXBackendConfig(GenXBackendOptions &&OptionsIn,
408+
GenXBackendData &&DataIn);
409+
410+
GenXBackendConfigResult &getResult() { return *this; };
411+
};
399412
} // namespace llvm
400413

414+
#if LLVM_VERSION_MAJOR >= 16
415+
416+
#include "llvm/IR/PassManager.h"
417+
418+
struct GenXBackendConfigPass
419+
: public llvm::AnalysisInfoMixin<GenXBackendConfigPass> {
420+
using Result = llvm::GenXBackendConfigResult;
421+
Result run(llvm::Module &M, llvm::ModuleAnalysisManager &AM);
422+
static llvm::AnalysisKey Key;
423+
};
424+
#endif
425+
401426
#endif

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,8 +1552,6 @@ llvm::PreservedAnalyses CMABIPass::run(llvm::Module &M,
15521552
llvm::ModuleAnalysisManager &AM) {
15531553

15541554
auto &LCG = AM.getResult<LazyCallGraphAnalysis>(M);
1555-
CGSCCAnalysisManager &CGAM =
1556-
AM.getResult<CGSCCAnalysisManagerModuleProxy>(M).getManager();
15571555
LCG.buildRefSCCs();
15581556
bool Changed = false;
15591557
PreservedAnalyses PassPA;
@@ -1577,4 +1575,5 @@ PreservedAnalyses CMLowerVLoadVStorePass::run(Function &F,
15771575
}
15781576
return PreservedAnalyses::none();
15791577
}
1578+
15801579
#endif

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ struct CMImpParam : public ModulePass {
210210
bool HasPayloadInMemory = false;
211211
const DataLayout *DL = nullptr;
212212

213+
#if LLVM_VERSION_MAJOR >= 16
214+
CallGraph &CG;
215+
CMImpParam(CallGraph &CG, bool HasPayloadInMemoryIn)
216+
: ModulePass{ID}, HasPayloadInMemory{HasPayloadInMemoryIn}, CG(CG) {
217+
initializeCMImpParamPass(*PassRegistry::getPassRegistry());
218+
}
219+
220+
CMImpParam(CallGraph &CG)
221+
: ModulePass{ID}, HasPayloadInMemory{PayloadInMemoryOpt}, CG(CG) {
222+
initializeCMImpParamPass(*PassRegistry::getPassRegistry());
223+
}
224+
#else // LLVM_VERSION_MAJOR
213225
CMImpParam(bool HasPayloadInMemoryIn)
214226
: ModulePass{ID}, HasPayloadInMemory{HasPayloadInMemoryIn} {
215227
initializeCMImpParamPass(*PassRegistry::getPassRegistry());
@@ -218,6 +230,7 @@ struct CMImpParam : public ModulePass {
218230
CMImpParam() : ModulePass{ID}, HasPayloadInMemory{PayloadInMemoryOpt} {
219231
initializeCMImpParamPass(*PassRegistry::getPassRegistry());
220232
}
233+
#endif // LLVM_VERSION_MAJOR
221234

222235
void getAnalysisUsage(AnalysisUsage &AU) const override {
223236
AU.addRequired<CallGraphWrapperPass>();
@@ -556,7 +569,9 @@ bool CMImpParam::runOnModule(Module &M) {
556569
void CMImpParam::processKernels(
557570
const std::vector<FunctionRef> &Kernels, const IntrIDMap &UsedIntrInfo,
558571
const std::unordered_set<Function *> &RequireImplArgsBuffer) {
572+
#if LLVM_VERSION_MAJOR < 16
559573
CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
574+
#endif
560575

561576
for (Function &Kernel : Kernels) {
562577
// Traverse the call graph to determine what the total implicit uses are for
@@ -610,14 +625,16 @@ CMImpParam::analyzeFixedSignatureFunctions(Module &M,
610625
const IntrIDMap &UsedIntrInfo) {
611626
IntrIDMap FixedSignFuncInfo;
612627
std::unordered_set<Function *> RequireImplArgsBuffer;
628+
#if LLVM_VERSION_MAJOR < 16
613629
CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
614-
630+
#endif
615631
auto FixedSignatureDefinitions = make_filter_range(
616632
M, [](const Function &F) { return vc::isFixedSignatureDefinition(F); });
617633

618634
for (Function &F : FixedSignatureDefinitions) {
619635
auto [RequiredImplArgs, CalledFixedSignFuncs] =
620636
CallGraphTraverser{CG, UsedIntrInfo}.collectIndirectlyUsedImplArgs(F);
637+
621638
// Function should be marked if it uses implicit args or it calls some
622639
// function that may use it via implicit args buffer.
623640
if (!RequiredImplArgs.empty() || !CalledFixedSignFuncs.has_value() ||
@@ -1013,6 +1030,9 @@ template <bool IsEntry> void CallGraphTraverser::visitFunction(Function &F) {
10131030
// Skipping inline asm.
10141031
if (isa<CallInst>(CI) && cast<CallInst>(CI)->isInlineAsm())
10151032
continue;
1033+
if (!isa<CallInst>(CI) || (GenXIntrinsic::getAnyIntrinsicID(CI) !=
1034+
GenXIntrinsic::not_any_intrinsic))
1035+
continue;
10161036
// Returns nullptr in case of indirect call or inline asm which was already
10171037
// considered.
10181038
auto *Child = CallEdge.second->getFunction();
@@ -1160,7 +1180,9 @@ CMImpParam::processKernelParameters(Function *F,
11601180
}
11611181
}
11621182

1183+
#if LLVM_VERSION_MAJOR < 16
11631184
CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
1185+
#endif
11641186
CallGraphNode *NF_CGN = CG.getOrInsertFunction(NF);
11651187

11661188
if (F->hasDLLExportStorageClass())
@@ -1206,20 +1228,22 @@ INITIALIZE_PASS_END(CMImpParam, "CMImpParam",
12061228
"Transformations required to support implicit arguments",
12071229
false, false)
12081230

1231+
#if LLVM_VERSION_MAJOR < 16
12091232
namespace llvm {
12101233
Pass *createCMImpParamPass(bool HasPayloadInMemory) {
12111234
return new CMImpParam{HasPayloadInMemory};
12121235
}
12131236
} // namespace llvm
12141237

1215-
#if LLVM_VERSION_MAJOR >= 16
1238+
#else // LLVM_VERSION_MAJOR < 16
12161239
PreservedAnalyses CMImpParamPass::run(llvm::Module &M,
1217-
llvm::AnalysisManager<llvm::Module> &) {
1218-
CMImpParam cmip;
1240+
llvm::AnalysisManager<llvm::Module> &AM) {
1241+
auto &CG = AM.getResult<CallGraphAnalysis>(M);
1242+
CMImpParam cmip(CG);
12191243
if (cmip.runOnModule(M)) {
12201244
return PreservedAnalyses::all();
12211245
}
12221246
return PreservedAnalyses::none();
12231247
}
1224-
// TODO: No lit-tests
1225-
#endif
1248+
CMImpParamPass::CMImpParamPass() : HasPayloadInMemory{PayloadInMemoryOpt} {};
1249+
#endif // LLVM_VERSION_MAJOR < 16

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,19 @@ class BTIAssignment final {
8989

9090
class GenXBTIAssignment final : public ModulePass {
9191

92+
#if LLVM_VERSION_MAJOR >= 16
93+
GenXBackendConfigPass::Result &BC;
94+
#endif
95+
9296
public:
9397
static char ID;
9498

99+
#if LLVM_VERSION_MAJOR >= 16
100+
GenXBTIAssignment(GenXBackendConfigPass::Result &BC)
101+
: BC(BC), ModulePass(ID) {}
102+
#else // LLVM_VERSION_MAJOR >= 16
95103
GenXBTIAssignment() : ModulePass(ID) {}
104+
#endif // LLVM_VERSION_MAJOR >= 16
96105

97106
void getAnalysisUsage(AnalysisUsage &AU) const override {
98107
AU.addRequired<GenXBackendConfig>();
@@ -112,18 +121,21 @@ INITIALIZE_PASS_DEPENDENCY(GenXBackendConfig)
112121
INITIALIZE_PASS_END(GenXBTIAssignment, "GenXBTIAssignment", "GenXBTIAssignment",
113122
false, false);
114123

124+
#if LLVM_VERSION_MAJOR < 16
115125
namespace llvm {
116126
ModulePass *createGenXBTIAssignmentPass() {
117127
initializeGenXBTIAssignmentPass(*PassRegistry::getPassRegistry());
118128
return new GenXBTIAssignment();
119129
}
120130
} // namespace llvm
131+
#endif
121132

122133
#if LLVM_VERSION_MAJOR >= 16
123134
PreservedAnalyses
124135
GenXBTIAssignmentPass::run(llvm::Module &M,
125-
llvm::AnalysisManager<llvm::Module> &) {
126-
GenXBTIAssignment GenXBTI;
136+
llvm::AnalysisManager<llvm::Module> &AM) {
137+
auto &Res = AM.getResult<GenXBackendConfigPass>(M);
138+
GenXBTIAssignment GenXBTI(Res);
127139
if (GenXBTI.runOnModule(M)) {
128140
return PreservedAnalyses::all();
129141
}
@@ -132,7 +144,9 @@ GenXBTIAssignmentPass::run(llvm::Module &M,
132144
#endif
133145

134146
bool GenXBTIAssignment::runOnModule(Module &M) {
147+
#if LLVM_VERSION_MAJOR < 16
135148
auto &BC = getAnalysis<GenXBackendConfig>();
149+
#endif
136150
bool emitDebuggableKernels = BC.emitDebuggableKernelsForLegacyPath();
137151
bool useBindlessBuffers = BC.useBindlessBuffers();
138152
bool useBindlessImages = BC.useBindlessImages();

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,18 @@ Value *SPIRVExpander::visitCallInst(CallInst &CI) {
357357
}
358358

359359
class GenXTranslateSPIRVBuiltins final : public ModulePass {
360+
#if LLVM_VERSION_MAJOR >= 16
361+
GenXBackendConfigPass::Result &BC;
362+
#endif
360363
public:
361364
static char ID;
365+
366+
#if LLVM_VERSION_MAJOR >= 16
367+
GenXTranslateSPIRVBuiltins(GenXBackendConfigPass::Result &BC)
368+
: BC(BC), ModulePass(ID), Expander(nullptr) {}
369+
#else // LLVM_VERSION_MAJOR >= 16
362370
GenXTranslateSPIRVBuiltins() : ModulePass(ID), Expander(nullptr) {}
371+
#endif // LLVM_VERSION_MAJOR >= 16
363372
StringRef getPassName() const override {
364373
return "GenX translate SPIR-V builtins";
365374
}
@@ -380,19 +389,22 @@ INITIALIZE_PASS_DEPENDENCY(GenXBackendConfig)
380389
INITIALIZE_PASS_END(GenXTranslateSPIRVBuiltins, "GenXTranslateSPIRVBuiltins",
381390
"GenXTranslateSPIRVBuiltins", false, false)
382391

392+
#if LLVM_VERSION_MAJOR < 16
383393
namespace llvm {
384394
ModulePass *createGenXTranslateSPIRVBuiltinsPass() {
385395
initializeGenXTranslateSPIRVBuiltinsPass(*PassRegistry::getPassRegistry());
386396
return new GenXTranslateSPIRVBuiltins;
387397
}
388398
} // namespace llvm
399+
#endif
389400

390401
#if LLVM_VERSION_MAJOR >= 16
391402
PreservedAnalyses
392403
GenXTranslateSPIRVBuiltinsPass::run(llvm::Module &M,
393-
llvm::AnalysisManager<llvm::Module> &) {
394-
GenXTranslateSPIRVBuiltins GenXPrint;
395-
if (GenXPrint.runOnModule(M)) {
404+
llvm::AnalysisManager<llvm::Module> &AM) {
405+
auto &Res = AM.getResult<GenXBackendConfigPass>(M);
406+
GenXTranslateSPIRVBuiltins GenXTrans(Res);
407+
if (GenXTrans.runOnModule(M)) {
396408
return PreservedAnalyses::all();
397409
}
398410
return PreservedAnalyses::none();
@@ -531,7 +543,11 @@ bool GenXTranslateSPIRVBuiltins::runOnFunction(Function &F) {
531543

532544
std::unique_ptr<Module>
533545
GenXTranslateSPIRVBuiltins::getBiFModule(BiFKind Kind, LLVMContext &Ctx) {
546+
#if LLVM_VERSION_MAJOR >= 16
547+
MemoryBufferRef BiFModuleBuffer = BC.getBiFModule(Kind);
548+
#else
534549
MemoryBufferRef BiFModuleBuffer =
535550
getAnalysis<GenXBackendConfig>().getBiFModule(Kind);
551+
#endif
536552
return vc::getLazyBiFModuleOrReportError(BiFModuleBuffer, Ctx);
537553
}

IGC/VectorCompiler/lib/PassPluginLibrary/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ add_llvm_library(
2525
$<TARGET_OBJECTS:VCGenXUtils>
2626
$<TARGET_OBJECTS:VCTransforms>
2727
$<TARGET_OBJECTS:VCGeneralUtils>
28+
$<TARGET_OBJECTS:VCInternalIntrinsics>
29+
$<TARGET_OBJECTS:${IGC_BUILD__PROJ__BiFManager}>
30+
$<TARGET_OBJECTS:${IGC_BUILD__PROJ__BiFLib_OCL}>
2831
MODULE
2932
PLUGIN_TOOL opt
3033
)

IGC/VectorCompiler/lib/PassPluginLibrary/Plugin.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SPDX-License-Identifier: MIT
1010
#include "llvm/Passes/PassPlugin.h"
1111

1212
#include "vc/GenXOpts/GenXOptsNewPM.h"
13+
#include "vc/Support/BackendConfig.h"
1314

1415
using namespace llvm;
1516

@@ -18,6 +19,7 @@ void registerPluginPasses(PassBuilder &PB) {
1819

1920
PB.registerAnalysisRegistrationCallback([=](ModuleAnalysisManager &MAM) {
2021
MAM.registerPass([&] { return CMABIAnalysisPass(); });
22+
MAM.registerPass([&] { return GenXBackendConfigPass(); });
2123
});
2224

2325
#define ADD_PASS(NAME, CREATE_PASS) \
@@ -26,6 +28,15 @@ void registerPluginPasses(PassBuilder &PB) {
2628
return true; \
2729
}
2830

31+
PB.registerPipelineParsingCallback(
32+
[=](StringRef Name, CGSCCPassManager &PM,
33+
ArrayRef<PassBuilder::PipelineElement>) {
34+
#define CGSCC_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
35+
#include "GenXPassRegistry.def"
36+
#undef CGSCC_PASS
37+
return false;
38+
});
39+
2940
PB.registerPipelineParsingCallback(
3041
[=](StringRef Name, ModulePassManager &PM,
3142
ArrayRef<PassBuilder::PipelineElement>) {

IGC/VectorCompiler/lib/Support/BackendConfig.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,30 @@ void GenXBackendData::setOwningBiFModuleIf(
234234
setOwningBiFModule(Kind, std::move(ModuleBuffer));
235235
}
236236

237-
GenXBackendConfig::GenXBackendConfig()
238-
: ImmutablePass(ID), Options{GenXBackendOptions::InitFromLLVMOpts{}},
239-
Data{GenXBackendData::InitFromLLMVOpts{}} {
237+
GenXBackendConfig::GenXBackendConfig() : ImmutablePass(ID) {
240238
initializeGenXBackendConfigPass(*PassRegistry::getPassRegistry());
241239
}
242240

243241
GenXBackendConfig::GenXBackendConfig(GenXBackendOptions &&OptionsIn,
244242
GenXBackendData &&DataIn)
245-
: ImmutablePass(ID), Options(std::move(OptionsIn)),
246-
Data(std::move(DataIn)) {
243+
: ImmutablePass(ID),
244+
GenXBackendConfigResult(std::move(OptionsIn), std::move(DataIn)) {
247245
initializeGenXBackendConfigPass(*PassRegistry::getPassRegistry());
248246
}
249247

250248
INITIALIZE_PASS(GenXBackendConfig, DEBUG_TYPE, DEBUG_TYPE, false, true)
249+
250+
#if LLVM_VERSION_MAJOR >= 16
251+
252+
AnalysisKey GenXBackendConfigPass::Key;
253+
254+
GenXBackendConfigPass::Result
255+
GenXBackendConfigPass::run(llvm::Module &M,
256+
llvm::AnalysisManager<llvm::Module> &AM) {
257+
258+
GenXBackendConfig BC;
259+
BC.runOnModule(M);
260+
return std::move(BC.getResult());
261+
}
262+
263+
#endif

IGC/VectorCompiler/test/BTIAssignment/debug_shift.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
; Check that bti assignment starts from 1 if debuggable kernels needed.
1010

11-
; RUN: %opt_typed_ptrs %use_old_pass_manager% -GenXBTIAssignment -vc-reserve-bti-zero -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s --check-prefix=CHECK_RESERVE
12-
; RUN: %opt_opaque_ptrs %use_old_pass_manager% -GenXBTIAssignment -vc-reserve-bti-zero -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s --check-prefix=CHECK_RESERVE
13-
; RUN: %opt_typed_ptrs %use_old_pass_manager% -GenXBTIAssignment -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s --check-prefix=CHECK_NO_RESERVE
14-
; RUN: %opt_opaque_ptrs %use_old_pass_manager% -GenXBTIAssignment -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s --check-prefix=CHECK_NO_RESERVE
11+
; RUN: %opt_typed_ptrs %use_old_pass_manager% %pass_pref%GenXBTIAssignment -vc-reserve-bti-zero -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s --check-prefix=CHECK_RESERVE
12+
; RUN: %opt_opaque_ptrs %use_old_pass_manager% %pass_pref%GenXBTIAssignment -vc-reserve-bti-zero -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s --check-prefix=CHECK_RESERVE
13+
; RUN: %opt_typed_ptrs %use_old_pass_manager% %pass_pref%GenXBTIAssignment -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s --check-prefix=CHECK_NO_RESERVE
14+
; RUN: %opt_opaque_ptrs %use_old_pass_manager% %pass_pref%GenXBTIAssignment -march=genx64 -mcpu=Gen9 -S < %s | FileCheck %s --check-prefix=CHECK_NO_RESERVE
1515

1616
target datalayout = "e-p:64:64-i64:64-n8:16:32:64"
1717
target triple = "spir64-unknown-unknown"

0 commit comments

Comments
 (0)