Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/include/llvm/SYCLLowerIR/SYCLUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
#include <functional>

namespace llvm {

class Module;

namespace sycl {

bool isModuleUsingAsan(const Module &M);
bool isModuleUsingMsan(const Module &M);
bool isModuleUsingTsan(const Module &M);

@YuriPlyakhin YuriPlyakhin Aug 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

These three predicates are sanitizer-specific, but SYCLLowerIR/SYCLUtils.h is the generic SYCL grab-bag, and everything else in it lives under sycl::utils. SYCLLowerIR/SanitizerPostOptimizer.h is already the sanitizer-owned header in this component and declaring them there breaks the cycle. Could you please consider it?

A new SYCLLowerIR/SanitizerUtils.h might be an even cleaner solution. Additional argument for SYCLLowerIR/SanitizerUtils.h:
__AsanKernelMetadata / __MsanKernelMetadata / __TsanKernelMetadata now appear as raw literals in SYCLUtils.cpp, SanitizerPostOptimizer.cpp, SanitizerPostSplitProcessing.cpp, clang/lib/Driver/OffloadBundler.cpp, plus the producers in {Address,Memory,Thread}Sanitizer.cpp. New SanitizerUtils.h could be used to also expose constexpr StringRef ASAN_KERNEL_METADATA_PREFIX etc. to have single definition of prefixes in addition to keeping the predicates.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

These three predicates are sanitizer-specific, but SYCLLowerIR/SYCLUtils.h is the generic SYCL grab-bag, and everything else in it lives under sycl::utils. SYCLLowerIR/SanitizerPostOptimizer.h is already the sanitizer-owned header in this component and declaring them there breaks the cycle. Could you please consider it?

A new SYCLLowerIR/SanitizerUtils.h might be an even cleaner solution. Additional argument for SYCLLowerIR/SanitizerUtils.h: __AsanKernelMetadata / __MsanKernelMetadata / __TsanKernelMetadata now appear as raw literals in SYCLUtils.cpp, SanitizerPostOptimizer.cpp, SanitizerPostSplitProcessing.cpp, clang/lib/Driver/OffloadBundler.cpp, plus the producers in {Address,Memory,Thread}Sanitizer.cpp. New SanitizerUtils.h could be used to also expose constexpr StringRef ASAN_KERNEL_METADATA_PREFIX etc. to have single definition of prefixes in addition to keeping the predicates.

thanks @YuriPlyakhin for the review. These are good points. Follow-up the ideas at #22915

namespace utils {
constexpr char ATTR_SYCL_MODULE_ID[] = "sycl-module-id";
constexpr char ATTR_SYCL_OPTLEVEL[] = "sycl-optlevel";
Expand Down
3 changes: 0 additions & 3 deletions llvm/include/llvm/SYCLPostLink/ComputeModuleRuntimeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ struct GlobalBinImageProps {
bool EmitImportedSymbols;
bool EmitDeviceGlobalPropSet;
};
bool isModuleUsingAsan(const Module &M);
bool isModuleUsingMsan(const Module &M);
bool isModuleUsingTsan(const Module &M);
using PropSetRegTy = llvm::util::PropertySetRegistry;
using EntryPointSet = SetVector<Function *>;

Expand Down
19 changes: 19 additions & 0 deletions llvm/lib/SYCLLowerIR/SYCLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@

namespace llvm {
namespace sycl {

bool isModuleUsingAsan(const Module &M) {
return any_of(M.globals(), [](const GlobalVariable &GV) {
return GV.getName().starts_with("__AsanKernelMetadata");
});
}

bool isModuleUsingMsan(const Module &M) {
return any_of(M.globals(), [](const GlobalVariable &GV) {
return GV.getName().starts_with("__MsanKernelMetadata");
});
}

bool isModuleUsingTsan(const Module &M) {
return any_of(M.globals(), [](const GlobalVariable &GV) {
return GV.getName().starts_with("__TsanKernelMetadata");
});
}

namespace utils {

using namespace llvm::esimd;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/SYCLLowerIR/SanitizerPostOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//

#include "llvm/SYCLLowerIR/SanitizerPostOptimizer.h"
#include "llvm/SYCLPostLink/ComputeModuleRuntimeInfo.h"
#include "llvm/SYCLLowerIR/SYCLUtils.h"

#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstVisitor.h"
Expand Down
18 changes: 0 additions & 18 deletions llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,6 @@ getSYCLESIMDSplitStatusFromMetadata(const Module &M) {
}
} // namespace

bool isModuleUsingAsan(const Module &M) {
return any_of(M.globals(), [](const GlobalVariable &GV) {
return GV.getName().starts_with("__AsanKernelMetadata");
});
}

bool isModuleUsingMsan(const Module &M) {
return any_of(M.globals(), [](const GlobalVariable &GV) {
return GV.getName().starts_with("__MsanKernelMetadata");
});
}

bool isModuleUsingTsan(const Module &M) {
return any_of(M.globals(), [](const GlobalVariable &GV) {
return GV.getName().starts_with("__TsanKernelMetadata");
});
}

// Gets 1- to 3-dimension work-group related information for function Func.
// Returns an empty vector if not present.
template <typename T>
Expand Down
1 change: 1 addition & 0 deletions sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <llvm/SYCLLowerIR/LowerInvokeSimd.h>
#include <llvm/SYCLLowerIR/SYCLDeviceLibBF16.h>
#include <llvm/SYCLLowerIR/SYCLJointMatrixTransform.h>
#include <llvm/SYCLLowerIR/SYCLUtils.h>
#include <llvm/SYCLPostLink/ComputeModuleRuntimeInfo.h>
#include <llvm/SYCLPostLink/ModuleSplitter.h>
#include <llvm/Support/BLAKE3.h>
Expand Down
Loading