Skip to content

Commit e4f281c

Browse files
authored
[SYCL][NFC] Simplify SYCLDeviceLibReqMask
Pass manager infrastructure usage replaced with helper function getSYCLDeviceLibReqMask. Closes #5362.
1 parent 7f2e99c commit e4f281c

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This pass goes through input module's function list to detect all SYCL
9+
// This function goes through input module's function list to detect all SYCL
1010
// devicelib functions invoked. Each devicelib function invoked is included in
1111
// one 'fallback' SPIR-V library loaded by SYCL runtime. After scanning all
1212
// functions in input module, a mask telling which SPIR-V libraries are needed
@@ -192,13 +192,15 @@ uint32_t getDeviceLibBits(const std::string &FuncName) {
192192
DeviceLibExt::cl_intel_devicelib_assert)));
193193
}
194194

195+
} // namespace
196+
195197
// For each device image module, we go through all functions which meets
196198
// 1. The function name has prefix "__devicelib_"
197199
// 2. The function is declaration which means it doesn't have function body
198200
// And we don't expect non-spirv functions with "__devicelib_" prefix.
199-
uint32_t getModuleDeviceLibReqMask(const Module &M) {
201+
uint32_t llvm::getSYCLDeviceLibReqMask(const Module &M) {
200202
// Device libraries will be enabled only for spir-v module.
201-
if (!llvm::Triple(M.getTargetTriple()).isSPIR())
203+
if (!Triple(M.getTargetTriple()).isSPIR())
202204
return 0;
203205
uint32_t ReqMask = 0;
204206
for (const Function &SF : M) {
@@ -210,10 +212,3 @@ uint32_t getModuleDeviceLibReqMask(const Module &M) {
210212
}
211213
return ReqMask;
212214
}
213-
} // namespace
214-
215-
char SYCLDeviceLibReqMaskPass::ID = 0;
216-
bool SYCLDeviceLibReqMaskPass::runOnModule(Module &M) {
217-
MReqMask = getModuleDeviceLibReqMask(M);
218-
return false;
219-
}

llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.h

+4-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This pass goes through input module's function list to detect all SYCL
9+
// This function goes through input module's function list to detect all SYCL
1010
// devicelib functions invoked. Each devicelib function invoked is included in
1111
// one 'fallback' SPIR-V library loaded by SYCL runtime. After scanning all
1212
// functions in input module, a mask telling which SPIR-V libraries are needed
@@ -16,12 +16,12 @@
1616

1717
#pragma once
1818

19-
#include "llvm/Pass.h"
20-
2119
#include <cstdint>
2220

2321
namespace llvm {
2422

23+
class Module;
24+
2525
// DeviceLibExt is shared between sycl-post-link tool and sycl runtime.
2626
// If any change is made here, need to sync with DeviceLibExt definition
2727
// in sycl/source/detail/program_manager/program_manager.hpp
@@ -34,15 +34,6 @@ enum class DeviceLibExt : std::uint32_t {
3434
cl_intel_devicelib_cstring,
3535
};
3636

37-
class SYCLDeviceLibReqMaskPass : public ModulePass {
38-
public:
39-
static char ID;
40-
SYCLDeviceLibReqMaskPass() : ModulePass(ID) { MReqMask = 0; }
41-
bool runOnModule(Module &M) override;
42-
uint32_t getSYCLDeviceLibReqMask() { return MReqMask; }
43-
44-
private:
45-
uint32_t MReqMask;
46-
};
37+
uint32_t getSYCLDeviceLibReqMask(const Module &M);
4738

4839
} // namespace llvm

llvm/tools/sycl-post-link/sycl-post-link.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,7 @@ void saveModuleProperties(Module &M, const EntryPointGroup &ModuleEntryPoints,
623623
PropSetRegTy PropSet;
624624

625625
{
626-
legacy::PassManager GetSYCLDeviceLibReqMask;
627-
auto *SDLReqMaskLegacyPass = new SYCLDeviceLibReqMaskPass();
628-
GetSYCLDeviceLibReqMask.add(SDLReqMaskLegacyPass);
629-
GetSYCLDeviceLibReqMask.run(M);
630-
uint32_t MRMask = SDLReqMaskLegacyPass->getSYCLDeviceLibReqMask();
626+
uint32_t MRMask = getSYCLDeviceLibReqMask(M);
631627
std::map<StringRef, uint32_t> RMEntry = {{"DeviceLibReqMask", MRMask}};
632628
PropSet.add(PropSetRegTy::SYCL_DEVICELIB_REQ_MASK, RMEntry);
633629
}

0 commit comments

Comments
 (0)