Skip to content

Commit 92978d4

Browse files
committed
Remove SPIRVSanitizerCommonUtils namespace
1 parent 7cac17b commit 92978d4

File tree

4 files changed

+39
-68
lines changed

4 files changed

+39
-68
lines changed

llvm/include/llvm/Transforms/Instrumentation/SPIRVSanitizerCommonUtils.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313
#define LLVM_TRANSFORMS_INSTRUMENTATION_SPIRVSANITIZERCOMMONUTILS_H
1414

1515
#include "llvm/IR/DerivedTypes.h"
16-
#include "llvm/IR/Instructions.h"
1716
#include "llvm/IR/Type.h"
1817
#include "llvm/IR/Value.h"
1918

2019
namespace llvm {
21-
namespace SPIRVSanitizerCommonUtils {
22-
2320
// Spir memory address space
2421
constexpr unsigned kSpirOffloadPrivateAS = 0;
2522
constexpr unsigned kSpirOffloadGlobalAS = 1;
@@ -29,7 +26,6 @@ constexpr unsigned kSpirOffloadGenericAS = 4;
2926

3027
TargetExtType *getTargetExtType(Type *Ty);
3128
bool isJointMatrixAccess(Value *V);
32-
} // namespace SPIRVSanitizerCommonUtils
3329
} // namespace llvm
3430

3531
#endif // LLVM_TRANSFORMS_INSTRUMENTATION_SPIRVSANITIZERCOMMONUTILS_H

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,8 @@ struct AddressSanitizer {
865865
Value *SizeArgument, uint32_t Exp,
866866
RuntimeCallInserter &RTCI);
867867
void instrumentMemIntrinsic(MemIntrinsic *MI, RuntimeCallInserter &RTCI);
868-
Value *memToShadow(
869-
Value *Shadow, IRBuilder<> &IRB,
870-
uint32_t AddressSpace = SPIRVSanitizerCommonUtils::kSpirOffloadPrivateAS);
868+
Value *memToShadow(Value *Shadow, IRBuilder<> &IRB,
869+
uint32_t AddressSpace = kSpirOffloadPrivateAS);
871870
bool suppressInstrumentationSiteForDebug(int &Instrumented);
872871
bool instrumentFunction(Function &F, const TargetLibraryInfo *TLI);
873872
bool maybeInsertAsanInitAtFunctionEntry(Function &F);
@@ -1398,8 +1397,7 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM,
13981397

13991398
auto KernelName = F.getName();
14001399
auto *KernelNameGV = GetOrCreateGlobalString(
1401-
M, "__asan_kernel", KernelName,
1402-
SPIRVSanitizerCommonUtils::kSpirOffloadConstantAS);
1400+
M, "__asan_kernel", KernelName, kSpirOffloadConstantAS);
14031401
SpirKernelsMetadata.emplace_back(ConstantStruct::get(
14041402
StructTy, ConstantExpr::getPointerCast(KernelNameGV, IntptrTy),
14051403
ConstantInt::get(IntptrTy, KernelName.size())));
@@ -1434,8 +1432,7 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM,
14341432
}
14351433

14361434
// New argument: uintptr_t as(1)*, which is allocated in shared USM buffer
1437-
Types.push_back(llvm::PointerType::get(
1438-
IntptrTy, SPIRVSanitizerCommonUtils::kSpirOffloadGlobalAS));
1435+
Types.push_back(llvm::PointerType::get(IntptrTy, kSpirOffloadGlobalAS));
14391436

14401437
FunctionType *NewFTy = FunctionType::get(F->getReturnType(), Types, false);
14411438

@@ -1493,9 +1490,9 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM,
14931490
FixupMetadata("kernel_arg_exclusive_ptr",
14941491
ConstantAsMetadata::get(Builder.getFalse()));
14951492

1496-
FixupMetadata("kernel_arg_addr_space",
1497-
ConstantAsMetadata::get(Builder.getInt32(
1498-
SPIRVSanitizerCommonUtils::kSpirOffloadGlobalAS)));
1493+
FixupMetadata(
1494+
"kernel_arg_addr_space",
1495+
ConstantAsMetadata::get(Builder.getInt32(kSpirOffloadGlobalAS)));
14991496
FixupMetadata("kernel_arg_access_qual",
15001497
MDString::get(M.getContext(), "read_write"));
15011498
FixupMetadata("kernel_arg_type", MDString::get(M.getContext(), "void*"));
@@ -1681,34 +1678,33 @@ static bool isUnsupportedSPIRAccess(Value *Addr, Instruction *Inst) {
16811678
// Ignore load/store for target ext type since we can't know exactly what size
16821679
// it is.
16831680
if (auto *SI = dyn_cast<StoreInst>(Inst))
1684-
if (SPIRVSanitizerCommonUtils::getTargetExtType(
1685-
SI->getValueOperand()->getType()) ||
1686-
SPIRVSanitizerCommonUtils::isJointMatrixAccess(SI->getPointerOperand()))
1681+
if (getTargetExtType(SI->getValueOperand()->getType()) ||
1682+
isJointMatrixAccess(SI->getPointerOperand()))
16871683
return true;
16881684

16891685
if (auto *LI = dyn_cast<LoadInst>(Inst))
1690-
if (SPIRVSanitizerCommonUtils::getTargetExtType(Inst->getType()) ||
1691-
SPIRVSanitizerCommonUtils::isJointMatrixAccess(LI->getPointerOperand()))
1686+
if (getTargetExtType(Inst->getType()) ||
1687+
isJointMatrixAccess(LI->getPointerOperand()))
16921688
return true;
16931689

16941690
Type *PtrTy = cast<PointerType>(Addr->getType()->getScalarType());
16951691
switch (PtrTy->getPointerAddressSpace()) {
1696-
case SPIRVSanitizerCommonUtils::kSpirOffloadPrivateAS: {
1692+
case kSpirOffloadPrivateAS: {
16971693
if (!ClSpirOffloadPrivates)
16981694
return true;
16991695
// Skip kernel arguments
17001696
return Inst->getFunction()->getCallingConv() == CallingConv::SPIR_KERNEL &&
17011697
isa<Argument>(Addr);
17021698
}
1703-
case SPIRVSanitizerCommonUtils::kSpirOffloadGlobalAS: {
1699+
case kSpirOffloadGlobalAS: {
17041700
return !ClSpirOffloadGlobals;
17051701
}
1706-
case SPIRVSanitizerCommonUtils::kSpirOffloadLocalAS: {
1702+
case kSpirOffloadLocalAS: {
17071703
if (!ClSpirOffloadLocals)
17081704
return true;
17091705
return Addr->getName().starts_with("__Asan");
17101706
}
1711-
case SPIRVSanitizerCommonUtils::kSpirOffloadGenericAS: {
1707+
case kSpirOffloadGenericAS: {
17121708
return !ClSpirOffloadGenerics;
17131709
}
17141710
}
@@ -1723,16 +1719,15 @@ void AddressSanitizer::AppendDebugInfoToArgs(Instruction *InsertBefore,
17231719
auto &Loc = InsertBefore->getDebugLoc();
17241720

17251721
// SPIR constant address space
1726-
PointerType *ConstASPtrTy = llvm::PointerType::get(
1727-
Type::getInt8Ty(C), SPIRVSanitizerCommonUtils::kSpirOffloadConstantAS);
1722+
PointerType *ConstASPtrTy =
1723+
llvm::PointerType::get(Type::getInt8Ty(C), kSpirOffloadConstantAS);
17281724

17291725
// File & Line
17301726
if (Loc) {
17311727
llvm::SmallString<128> Source = Loc->getDirectory();
17321728
sys::path::append(Source, Loc->getFilename());
1733-
auto *FileNameGV = GetOrCreateGlobalString(
1734-
*M, "__asan_file", Source,
1735-
SPIRVSanitizerCommonUtils::kSpirOffloadConstantAS);
1729+
auto *FileNameGV = GetOrCreateGlobalString(*M, "__asan_file", Source,
1730+
kSpirOffloadConstantAS);
17361731
Args.push_back(ConstantExpr::getPointerCast(FileNameGV, ConstASPtrTy));
17371732
Args.push_back(ConstantInt::get(Type::getInt32Ty(C), Loc.getLine()));
17381733
} else {
@@ -1743,8 +1738,7 @@ void AddressSanitizer::AppendDebugInfoToArgs(Instruction *InsertBefore,
17431738
// Function
17441739
auto FuncName = InsertBefore->getFunction()->getName();
17451740
auto *FuncNameGV = GetOrCreateGlobalString(
1746-
*M, "__asan_func", demangle(FuncName),
1747-
SPIRVSanitizerCommonUtils::kSpirOffloadConstantAS);
1741+
*M, "__asan_func", demangle(FuncName), kSpirOffloadConstantAS);
17481742
Args.push_back(ConstantExpr::getPointerCast(FuncNameGV, ConstASPtrTy));
17491743
}
17501744

@@ -1780,8 +1774,7 @@ bool AddressSanitizer::instrumentSyclDynamicLocalMemory(
17801774
SmallVector<Argument *> LocalArgs;
17811775
for (auto &Arg : F.args()) {
17821776
Type *PtrTy = dyn_cast<PointerType>(Arg.getType()->getScalarType());
1783-
if (PtrTy && PtrTy->getPointerAddressSpace() ==
1784-
SPIRVSanitizerCommonUtils::kSpirOffloadLocalAS)
1777+
if (PtrTy && PtrTy->getPointerAddressSpace() == kSpirOffloadLocalAS)
17851778
LocalArgs.push_back(&Arg);
17861779
}
17871780

@@ -1826,10 +1819,9 @@ void AddressSanitizer::instrumentInitAsanLaunchInfo(
18261819
// FIXME: if the initial value of "__AsanLaunchInfo" is zero, we'll not need
18271820
// this step
18281821
initializeCallbacks(TLI);
1829-
IRB.CreateStore(
1830-
ConstantPointerNull::get(llvm::PointerType::get(
1831-
IntptrTy, SPIRVSanitizerCommonUtils::kSpirOffloadGlobalAS)),
1832-
AsanLaunchInfo);
1822+
IRB.CreateStore(ConstantPointerNull::get(
1823+
llvm::PointerType::get(IntptrTy, kSpirOffloadGlobalAS)),
1824+
AsanLaunchInfo);
18331825
}
18341826

18351827
// Instrument memset/memmove/memcpy
@@ -1875,7 +1867,7 @@ bool AddressSanitizer::isInterestingAlloca(const AllocaInst &AI) {
18751867
!(SSGI && SSGI->isSafe(AI)) &&
18761868
// ignore alloc contains target ext type since we can't know exactly what
18771869
// size it is.
1878-
!SPIRVSanitizerCommonUtils::getTargetExtType(AI.getAllocatedType()));
1870+
!getTargetExtType(AI.getAllocatedType()));
18791871

18801872
It->second = IsInteresting;
18811873
return IsInteresting;
@@ -2848,8 +2840,7 @@ void ModuleAddressSanitizer::instrumentDeviceGlobal(IRBuilder<> &IRB) {
28482840
SmallVector<GlobalVariable *, 8> GlobalsToRemove;
28492841
SmallVector<Constant *, 8> DeviceGlobalMetadata;
28502842

2851-
Type *IntptrTy = M.getDataLayout().getIntPtrType(
2852-
*C, SPIRVSanitizerCommonUtils::kSpirOffloadGlobalAS);
2843+
Type *IntptrTy = M.getDataLayout().getIntPtrType(*C, kSpirOffloadGlobalAS);
28532844

28542845
// Device global meta data is described by a structure
28552846
// size_t device_global_size
@@ -3607,9 +3598,8 @@ void AddressSanitizer::initializeCallbacks(const TargetLibraryInfo *TLI) {
36073598
// char* func
36083599
// )
36093600
if (TargetTriple.isSPIROrSPIRV()) {
3610-
auto *Int8PtrTy = llvm::PointerType::get(
3611-
Type::getInt8Ty(*C),
3612-
SPIRVSanitizerCommonUtils::kSpirOffloadConstantAS);
3601+
auto *Int8PtrTy =
3602+
llvm::PointerType::get(Type::getInt8Ty(*C), kSpirOffloadConstantAS);
36133603

36143604
Args1.push_back(Int8PtrTy); // file
36153605
Args1.push_back(Type::getInt32Ty(*C)); // line
@@ -3710,16 +3700,11 @@ void AddressSanitizer::initializeCallbacks(const TargetLibraryInfo *TLI) {
37103700

37113701
AsanLaunchInfo = M.getOrInsertGlobal(
37123702
"__AsanLaunchInfo",
3713-
llvm::PointerType::get(IntptrTy,
3714-
SPIRVSanitizerCommonUtils::kSpirOffloadGlobalAS),
3715-
[&] {
3703+
llvm::PointerType::get(IntptrTy, kSpirOffloadGlobalAS), [&] {
37163704
return new GlobalVariable(
3717-
M,
3718-
llvm::PointerType::get(
3719-
IntptrTy, SPIRVSanitizerCommonUtils::kSpirOffloadGlobalAS),
3720-
false, GlobalVariable::ExternalLinkage, nullptr,
3721-
"__AsanLaunchInfo", nullptr, GlobalVariable::NotThreadLocal,
3722-
SPIRVSanitizerCommonUtils::kSpirOffloadLocalAS);
3705+
M, llvm::PointerType::get(IntptrTy, kSpirOffloadGlobalAS), false,
3706+
GlobalVariable::ExternalLinkage, nullptr, "__AsanLaunchInfo",
3707+
nullptr, GlobalVariable::NotThreadLocal, kSpirOffloadLocalAS);
37233708
});
37243709

37253710
AsanMemToShadow = M.getOrInsertFunction(kAsanMemToShadow, IntptrTy,
@@ -4504,8 +4489,8 @@ void FunctionStackPoisoner::processStaticAllocas() {
45044489
const auto &ShadowAfterScope = GetShadowBytesAfterScope(SVD, L);
45054490

45064491
// Poison the stack red zones at the entry.
4507-
Value *ShadowBase = ASan.memToShadow(
4508-
LocalStackBase, IRB, SPIRVSanitizerCommonUtils::kSpirOffloadPrivateAS);
4492+
Value *ShadowBase =
4493+
ASan.memToShadow(LocalStackBase, IRB, kSpirOffloadPrivateAS);
45094494
// As mask we must use most poisoned case: red zones and after scope.
45104495
// As bytes we can use either the same or just red zones only.
45114496
copyToShadow(ShadowAfterScope, ShadowAfterScope, IRB, ShadowBase,

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,6 @@ static const PlatformMemoryMapParams Intel_SPIR_MemoryMapParams = {
589589
&Intel_SPIR64_MemoryMapParams,
590590
};
591591

592-
// Spir memory address space
593-
static constexpr unsigned kSpirOffloadPrivateAS = 0;
594-
static constexpr unsigned kSpirOffloadGlobalAS = 1;
595-
static constexpr unsigned kSpirOffloadConstantAS = 2;
596-
static constexpr unsigned kSpirOffloadLocalAS = 3;
597-
static constexpr unsigned kSpirOffloadGenericAS = 4;
598-
599592
namespace {
600593

601594
class MemorySanitizerOnSpirv;
@@ -1750,14 +1743,13 @@ static bool isUnsupportedSPIRAccess(const Value *Addr, Instruction *I) {
17501743
// Ignore load/store for target ext type since we can't know exactly what size
17511744
// it is.
17521745
if (auto *SI = dyn_cast<StoreInst>(I))
1753-
if (SPIRVSanitizerCommonUtils::getTargetExtType(
1754-
SI->getValueOperand()->getType()) ||
1755-
SPIRVSanitizerCommonUtils::isJointMatrixAccess(SI->getPointerOperand()))
1746+
if (getTargetExtType(SI->getValueOperand()->getType()) ||
1747+
isJointMatrixAccess(SI->getPointerOperand()))
17561748
return true;
17571749

17581750
if (auto *LI = dyn_cast<LoadInst>(I))
1759-
if (SPIRVSanitizerCommonUtils::getTargetExtType(I->getType()) ||
1760-
SPIRVSanitizerCommonUtils::isJointMatrixAccess(LI->getPointerOperand()))
1751+
if (getTargetExtType(I->getType()) ||
1752+
isJointMatrixAccess(LI->getPointerOperand()))
17611753
return true;
17621754

17631755
Type *PtrTy = cast<PointerType>(Addr->getType()->getScalarType());

llvm/lib/Transforms/Instrumentation/SPIRVSanitizerCommonUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "llvm/Transforms/Instrumentation/SPIRVSanitizerCommonUtils.h"
14+
#include "llvm/IR/Instructions.h"
1415

1516
using namespace llvm;
1617

1718
namespace llvm {
18-
namespace SPIRVSanitizerCommonUtils {
19-
2019
TargetExtType *getTargetExtType(Type *Ty) {
2120
if (auto *TargetTy = dyn_cast<TargetExtType>(Ty))
2221
return TargetTy;
@@ -59,5 +58,4 @@ bool isJointMatrixAccess(Value *V) {
5958
}
6059
return false;
6160
}
62-
} // namespace SPIRVSanitizerCommonUtils
6361
} // namespace llvm

0 commit comments

Comments
 (0)