Skip to content

Commit 4611812

Browse files
committed
Migrate SPIRVReader to new PassManager
Co-authored-by: Pedro Olsen Ferreira
1 parent 348da24 commit 4611812

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

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"
@@ -4444,14 +4444,11 @@ llvm::convertSpirvToLLVM(LLVMContext &C, SPIRVModule &BM,
44444444
return nullptr;
44454445
}
44464446

4447-
llvm::ModulePass *LoweringPass =
4448-
createSPIRVBIsLoweringPass(*M, Opts.getDesiredBIsRepresentation());
4449-
if (LoweringPass) {
4450-
// nullptr means no additional lowering is required
4451-
llvm::legacy::PassManager PassMgr;
4452-
PassMgr.add(LoweringPass);
4453-
PassMgr.run(*M);
4454-
}
4447+
llvm::ModulePassManager PassMgr;
4448+
addSPIRVBIsLoweringPass(PassMgr, Opts.getDesiredBIsRepresentation());
4449+
llvm::ModuleAnalysisManager MAM;
4450+
MAM.registerPass([&] { return PassInstrumentationAnalysis(); });
4451+
PassMgr.run(*M, MAM);
44554452

44564453
return M;
44574454
}

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 *

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)