|
59 | 59 | #include "llvm/IR/Intrinsics.h" |
60 | 60 | #include "llvm/IR/LLVMContext.h" |
61 | 61 | #include "llvm/IR/MDBuilder.h" |
| 62 | +#include "llvm/IR/Mangler.h" |
62 | 63 | #include "llvm/IR/Metadata.h" |
63 | 64 | #include "llvm/IR/Module.h" |
64 | 65 | #include "llvm/IR/Type.h" |
@@ -1327,13 +1328,25 @@ static GlobalVariable *GetOrCreateGlobalString(Module &M, StringRef Name, |
1327 | 1328 | return StringGV; |
1328 | 1329 | } |
1329 | 1330 |
|
| 1331 | +static std::string SYCLUniqueStableId(const GlobalValue *GV, |
| 1332 | + const DataLayout &DL) { |
| 1333 | + std::string Buffer; |
| 1334 | + llvm::raw_string_ostream Out(Buffer); |
| 1335 | + |
| 1336 | + Mangler Mgl; |
| 1337 | + Mgl.getNameWithPrefix(Out, GV, true); |
| 1338 | + |
| 1339 | + return Out.str(); |
| 1340 | +} |
| 1341 | + |
1330 | 1342 | // Append a new argument "launch_data" to user's spir_kernels |
1331 | 1343 | static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM) { |
1332 | 1344 | SmallVector<Function *> SpirFixupKernels; |
1333 | 1345 | SmallVector<Constant *, 8> SpirKernelsMetadata; |
1334 | 1346 | CallGraph CG(M); |
1335 | 1347 |
|
1336 | | - Type *IntptrTy = M.getDataLayout().getIntPtrType(M.getContext()); |
| 1348 | + auto DL = M.getDataLayout(); |
| 1349 | + Type *IntptrTy = DL.getIntPtrType(M.getContext()); |
1337 | 1350 |
|
1338 | 1351 | // SpirKernelsMetadata only saves fixed kernels, and is described by |
1339 | 1352 | // following structure: |
@@ -1379,6 +1392,13 @@ static void ExtendSpirKernelArgs(Module &M, FunctionAnalysisManager &FAM) { |
1379 | 1392 | MetadataInitializer, "__AsanKernelMetadata", nullptr, |
1380 | 1393 | GlobalValue::NotThreadLocal, 1); |
1381 | 1394 | AsanSpirKernelMetadata->setUnnamedAddr(GlobalValue::UnnamedAddr::Local); |
| 1395 | + // Add device global attributes |
| 1396 | + AsanSpirKernelMetadata->addAttribute( |
| 1397 | + "sycl-device-global-size", std::to_string(DL.getTypeAllocSize(ArrayTy))); |
| 1398 | + AsanSpirKernelMetadata->addAttribute("sycl-device-image-scope"); |
| 1399 | + AsanSpirKernelMetadata->addAttribute("sycl-host-access", "2"); |
| 1400 | + AsanSpirKernelMetadata->addAttribute("sycl-unique-id", |
| 1401 | + "_Z20__AsanKernelMetadata"); |
1382 | 1402 |
|
1383 | 1403 | // Handle SpirFixupKernels |
1384 | 1404 | SmallVector<std::pair<Function *, Function *>> SpirFuncs; |
|
0 commit comments