88
99#include " DeviceCompilation.h"
1010
11- #include " PostLinkActions.h"
12-
1311#include < clang/Basic/DiagnosticDriver.h>
1412#include < clang/Basic/Version.h>
1513#include < clang/CodeGen/CodeGenAction.h>
2018#include < clang/Tooling/CompilationDatabase.h>
2119#include < clang/Tooling/Tooling.h>
2220
21+ #include < llvm/IR/PassInstrumentation.h>
22+ #include < llvm/IR/PassManager.h>
2323#include < llvm/IRReader/IRReader.h>
2424#include < llvm/Linker/Linker.h>
2525#include < llvm/SYCLLowerIR/ComputeModuleRuntimeInfo.h>
@@ -37,7 +37,6 @@ using namespace llvm::sycl;
3737using namespace llvm ::module_split;
3838using namespace llvm ::util;
3939using namespace jit_compiler ;
40- using namespace jit_compiler ::post_link;
4140
4241#ifdef _GNU_SOURCE
4342#include < dlfcn.h>
@@ -365,26 +364,26 @@ Error jit_compiler::linkDeviceLibraries(llvm::Module &Module,
365364 return Error::success ();
366365}
367366
367+ template <class PassClass > static bool runModulePass (llvm::Module &M) {
368+ ModulePassManager MPM;
369+ ModuleAnalysisManager MAM;
370+ // Register required analysis
371+ MAM.registerPass ([&] { return PassInstrumentationAnalysis (); });
372+ MPM.addPass (PassClass{});
373+ PreservedAnalyses Res = MPM.run (M, MAM);
374+ return !Res.areAllPreserved ();
375+ }
376+
368377Expected<RTCBundleInfo> jit_compiler::performPostLink (
369378 llvm::Module &Module, [[maybe_unused]] const InputArgList &UserArgList) {
370379 // This is a simplified version of `processInputModule` in
371380 // `llvm/tools/sycl-post-link.cpp`. Assertions/TODOs point to functionality
372381 // left out of the algorithm for now.
373382
374- // After linking device bitcode "llvm.used" holds references to the kernels
375- // that are defined in the device image. But after splitting device image into
376- // separate kernels we may end up with having references to kernel declaration
377- // originating from "llvm.used" in the IR that is passed to llvm-spirv tool,
378- // and these declarations cause an assertion in llvm-spirv. To workaround this
379- // issue remove "llvm.used" from the input module before performing any other
380- // actions.
381- removeSYCLKernelsConstRefArray (Module);
382-
383- // There may be device_global variables kept alive in "llvm.compiler.used"
384- // to keep the optimizer from wrongfully removing them. llvm.compiler.used
385- // symbols are usually removed at backend lowering, but this is handled here
386- // for SPIR-V since SYCL compilation uses llvm-spirv, not the SPIR-V backend.
387- removeDeviceGlobalFromCompilerUsed (Module);
383+ assert (!Module.getGlobalVariable (" llvm.used" ) &&
384+ !Module.getGlobalVariable (" llvm.compiler.used" ));
385+ // Otherwise: Port over the `removeSYCLKernelsConstRefArray` and
386+ // `removeDeviceGlobalFromCompilerUsed` methods.
388387
389388 assert (!isModuleUsingAsan (Module));
390389 // Otherwise: Need to instrument each image scope device globals if the module
0 commit comments