Skip to content

Commit c628a2a

Browse files
svenvhvmaksimo
authored andcommitted
Migrate SPIRVReader to new PassManager
Co-authored-by: Pedro Olsen Ferreira Original commit: KhronosGroup/SPIRV-LLVM-Translator@4611812
1 parent f8742e2 commit c628a2a

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "SPIRVMemAliasingINTEL.h"
4949
#include "SPIRVModule.h"
5050
#include "SPIRVToLLVMDbgTran.h"
51+
#include "SPIRVToOCL.h"
5152
#include "SPIRVType.h"
5253
#include "SPIRVUtil.h"
5354
#include "SPIRVValue.h"
@@ -64,7 +65,6 @@
6465
#include "llvm/IR/InlineAsm.h"
6566
#include "llvm/IR/Instructions.h"
6667
#include "llvm/IR/IntrinsicInst.h"
67-
#include "llvm/IR/LegacyPassManager.h"
6868
#include "llvm/IR/MDBuilder.h"
6969
#include "llvm/IR/Metadata.h"
7070
#include "llvm/IR/Module.h"
@@ -4435,14 +4435,11 @@ llvm::convertSpirvToLLVM(LLVMContext &C, SPIRVModule &BM,
44354435
return nullptr;
44364436
}
44374437

4438-
llvm::ModulePass *LoweringPass =
4439-
createSPIRVBIsLoweringPass(*M, Opts.getDesiredBIsRepresentation());
4440-
if (LoweringPass) {
4441-
// nullptr means no additional lowering is required
4442-
llvm::legacy::PassManager PassMgr;
4443-
PassMgr.add(LoweringPass);
4444-
PassMgr.run(*M);
4445-
}
4438+
llvm::ModulePassManager PassMgr;
4439+
addSPIRVBIsLoweringPass(PassMgr, Opts.getDesiredBIsRepresentation());
4440+
llvm::ModuleAnalysisManager MAM;
4441+
MAM.registerPass([&] { return PassInstrumentationAnalysis(); });
4442+
PassMgr.run(*M, MAM);
44464443

44474444
return M;
44484445
}

llvm-spirv/lib/SPIRV/SPIRVToOCL.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,21 @@ void SPIRVToOCLBase::translateOpaqueTypes() {
12701270
}
12711271
}
12721272

1273+
void addSPIRVBIsLoweringPass(ModulePassManager &PassMgr,
1274+
SPIRV::BIsRepresentation BIsRep) {
1275+
switch (BIsRep) {
1276+
case SPIRV::BIsRepresentation::OpenCL12:
1277+
PassMgr.addPass(SPIRVToOCL12Pass());
1278+
break;
1279+
case SPIRV::BIsRepresentation::OpenCL20:
1280+
PassMgr.addPass(SPIRVToOCL20Pass());
1281+
break;
1282+
case SPIRV::BIsRepresentation::SPIRVFriendlyIR:
1283+
// nothing to do, already done
1284+
break;
1285+
}
1286+
}
1287+
12731288
} // namespace SPIRV
12741289

12751290
ModulePass *

llvm-spirv/lib/SPIRV/SPIRVToOCL.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ class SPIRVToOCL20Legacy : public SPIRVToOCLLegacy, public SPIRVToOCL20Base {
426426
static char ID;
427427
};
428428

429+
/// Add passes for translating SPIR-V Instructions to the desired
430+
/// representation in LLVM IR (such as OpenCL builtins or SPIR-V Friendly IR).
431+
void addSPIRVBIsLoweringPass(ModulePassManager &PassMgr,
432+
SPIRV::BIsRepresentation BIsRep);
433+
429434
} // namespace SPIRV
430435

431436
#endif // SPIRVTOOCL_H

0 commit comments

Comments
 (0)