Skip to content

Commit

Permalink
[DeviceSanitizer] Change "TargetTriple.isSPIR()" to "TargetTriple.isS…
Browse files Browse the repository at this point in the history
…PIROrSPIRV()" in AddressSanitizer.cpp (#14413)

SYCL is going to switch to SPIR-V backend soon, this PR changed
"TargetTriple.isSPIR()" to "TargetTriple.isSPIROrSPIRV()" to improve
compatibility
  • Loading branch information
AllanZyne authored Jul 4, 2024
1 parent 9d4b5ef commit f57c921
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ PreservedAnalyses AddressSanitizerPass::run(Module &M,
const StackSafetyGlobalInfo *const SSGI =
ClUseStackSafety ? &MAM.getResult<StackSafetyGlobalAnalysis>(M) : nullptr;

if (Triple(M.getTargetTriple()).isSPIR()) {
if (Triple(M.getTargetTriple()).isSPIROrSPIRV()) {
bool HasESIMDKernel = false;

// ESIMD kernel doesn't support noinline functions, so we can't
Expand Down Expand Up @@ -1565,7 +1565,7 @@ void AddressSanitizer::AppendDebugInfoToArgs(Instruction *InsertBefore,

Value *AddressSanitizer::memToShadow(Value *Shadow, IRBuilder<> &IRB,
uint32_t AddressSpace) {
if (TargetTriple.isSPIR()) {
if (TargetTriple.isSPIROrSPIRV()) {
return IRB.CreateCall(
AsanMemToShadow,
{Shadow, ConstantInt::get(IRB.getInt32Ty(), AddressSpace)},
Expand Down Expand Up @@ -1718,7 +1718,7 @@ bool AddressSanitizer::isInterestingAlloca(const AllocaInst &AI) {

bool AddressSanitizer::ignoreAccess(Instruction *Inst, Value *Ptr) {
// SPIR has its own rules to filter the instrument accesses
if (TargetTriple.isSPIR()) {
if (TargetTriple.isSPIROrSPIRV()) {
if (isUnsupportedSPIRAccess(Ptr, Inst->getFunction()))
return true;
} else {
Expand Down Expand Up @@ -2212,7 +2212,7 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy);
if (UseCalls) {
if (Exp == 0) {
if (TargetTriple.isSPIR()) {
if (TargetTriple.isSPIROrSPIRV()) {
SmallVector<Value *, 5> Args;
Args.push_back(AddrLong);
AppendDebugInfoToArgs(InsertBefore, Addr, Args);
Expand Down Expand Up @@ -2294,7 +2294,7 @@ void AddressSanitizer::instrumentUnusualSizeOrAlignment(
Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy);
if (UseCalls) {
if (Exp == 0) {
if (TargetTriple.isSPIR()) {
if (TargetTriple.isSPIROrSPIRV()) {
SmallVector<Value *, 6> Args;
Args.push_back(AddrLong);
Args.push_back(Size);
Expand Down Expand Up @@ -3126,7 +3126,7 @@ bool ModuleAddressSanitizer::instrumentModule(Module &M) {
}
}

if (TargetTriple.isSPIR()) {
if (TargetTriple.isSPIROrSPIRV()) {
// Add module metadata "device.sanitizer" for sycl-post-link
LLVMContext &Ctx = M.getContext();
auto *MD = M.getOrInsertNamedMetadata("device.sanitizer");
Expand Down Expand Up @@ -3189,7 +3189,7 @@ void AddressSanitizer::initializeCallbacks(Module &M, const TargetLibraryInfo *T
// unsigned int line,
// char* func
// )
if (TargetTriple.isSPIR()) {
if (TargetTriple.isSPIROrSPIRV()) {
auto *Int8PtrTy =
Type::getInt8Ty(*C)->getPointerTo(kSpirOffloadConstantAS);

Expand Down Expand Up @@ -3250,7 +3250,7 @@ void AddressSanitizer::initializeCallbacks(Module &M, const TargetLibraryInfo *T
AsanShadowGlobal = M.getOrInsertGlobal("__asan_shadow",
ArrayType::get(IRB.getInt8Ty(), 0));

if (TargetTriple.isSPIR()) {
if (TargetTriple.isSPIROrSPIRV()) {
// __asan_set_shadow_static_local(
// uptr ptr,
// size_t size,
Expand Down Expand Up @@ -3375,7 +3375,7 @@ bool AddressSanitizer::instrumentFunction(Function &F,
if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) return false;
if (F.getName().starts_with("__asan_")) return false;

if (TargetTriple.isSPIR()) {
if (TargetTriple.isSPIROrSPIRV()) {
if (F.getName().contains("__sycl_service_kernel__"))
return false;
// Skip referenced-indirectly function as we insert access to shared local
Expand Down Expand Up @@ -3471,7 +3471,7 @@ bool AddressSanitizer::instrumentFunction(Function &F,
NoReturnCalls.push_back(CB);
}
if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
if (TargetTriple.isSPIR() && CI->getCalledFunction() &&
if (TargetTriple.isSPIROrSPIRV() && CI->getCalledFunction() &&
CI->getCalledFunction()->getCallingConv() ==
llvm::CallingConv::SPIR_FUNC &&
CI->getCalledFunction()->getName() ==
Expand Down Expand Up @@ -3501,7 +3501,7 @@ bool AddressSanitizer::instrumentFunction(Function &F,
F.getParent()->getDataLayout(), RTCI);
FunctionModified = true;
}
if (TargetTriple.isSPIR()) {
if (TargetTriple.isSPIROrSPIRV()) {
for (auto *CI : SyclAllocateLocalMemoryCalls) {
instrumentSyclStaticLocalMemory(CI);
FunctionModified = true;
Expand Down Expand Up @@ -4027,7 +4027,7 @@ void FunctionStackPoisoner::processStaticAllocas() {
// The left-most redzone has enough space for at least 4 pointers.
Value *BasePlus0 = IRB.CreateIntToPtr(LocalStackBase, IntptrPtrTy);
// SPIRV doesn't use the following metadata
if (!TargetTriple.isSPIR()) {
if (!TargetTriple.isSPIROrSPIRV()) {
// Write the Magic value to redzone[0].
IRB.CreateStore(ConstantInt::get(IntptrTy, kCurrentStackFrameMagic),
BasePlus0);
Expand Down

0 comments on commit f57c921

Please sign in to comment.