Skip to content

Commit 4a67f2a

Browse files
authored
[SYCL] Implement fixed target property generation (#7095)
In scope of implementation of the "SYCL/Device requirements" property set we need to create a "fixed_target" property if the "!sycl_fixed_targets" metadata is present in the IR and fill it with the corresponding aspects.
1 parent c0a4a56 commit 4a67f2a

File tree

4 files changed

+57
-17
lines changed

4 files changed

+57
-17
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: sycl-post-link -split=auto %s -o %t.files.table
2+
; RUN: FileCheck %s -input-file=%t.files_0.prop
3+
4+
; CHECK: [SYCL/device requirements]
5+
; CHECK: fixed_target=2|gAAAAAAAAAQAAAAA
6+
7+
source_filename = "main.cpp"
8+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
9+
target triple = "spir64-unknown-unknown"
10+
11+
$_ZTSZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_EUlvE_ = comdat any
12+
13+
; Function Attrs: convergent mustprogress noinline norecurse optnone
14+
define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_EUlvE_() #0 comdat {
15+
entry:
16+
call spir_func void @_Z3foov()
17+
ret void
18+
}
19+
20+
; Function Attrs: convergent mustprogress noinline norecurse nounwind optnone
21+
define dso_local spir_func void @_Z3foov() !sycl_fixed_targets !3 {
22+
entry:
23+
ret void
24+
}
25+
26+
attributes #0 = { "sycl-module-id"="main.cpp" }
27+
28+
!sycl_aspects = !{!1, !2}
29+
30+
!1 = !{!"cpu", i32 1}
31+
!2 = !{!"fp64", i32 6}
32+
!3 = !{i32 1}

llvm/tools/sycl-post-link/SYCLDeviceRequirements.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,34 @@
1616

1717
using namespace llvm;
1818

19-
std::map<StringRef, std::vector<uint32_t>>
20-
llvm::getSYCLDeviceRequirements(const Module &M) {
21-
std::map<StringRef, std::vector<uint32_t>> Result;
19+
void llvm::getSYCLDeviceRequirements(
20+
const Module &M, std::map<StringRef, std::vector<uint32_t>> &Requirements) {
2221
auto ExtractIntegerFromMDNodeOperand = [=](const MDNode *N,
2322
unsigned OpNo) -> unsigned {
2423
Constant *C =
2524
cast<ConstantAsMetadata>(N->getOperand(OpNo).get())->getValue();
2625
return static_cast<uint32_t>(C->getUniqueInteger().getZExtValue());
2726
};
28-
std::set<uint32_t> Aspects;
29-
for (const Function &F : M) {
30-
if (!F.hasMetadata("sycl_used_aspects"))
31-
continue;
3227

33-
const MDNode *MD = F.getMetadata("sycl_used_aspects");
34-
for (size_t I = 0, E = MD->getNumOperands(); I < E; ++I) {
35-
Aspects.insert(ExtractIntegerFromMDNodeOperand(MD, I));
28+
// { LLVM-IR metadata name , [SYCL/Device requirements] property name }, see:
29+
// https://github.com/intel/llvm/blob/sycl/sycl/doc/design/OptionalDeviceFeatures.md#create-the-sycldevice-requirements-property-set
30+
// Scan the module and if the metadata is present fill the corresponing
31+
// property with metadata's aspects
32+
constexpr std::pair<const char *, const char *> ReqdMDs[] = {
33+
{"sycl_used_aspects", "aspects"}, {"sycl_fixed_targets", "fixed_target"}};
34+
35+
for (const auto &MD : ReqdMDs) {
36+
std::set<uint32_t> Aspects;
37+
for (const Function &F : M) {
38+
if (const MDNode *MDN = F.getMetadata(MD.first)) {
39+
for (size_t I = 0, E = MDN->getNumOperands(); I < E; ++I)
40+
Aspects.insert(ExtractIntegerFromMDNodeOperand(MDN, I));
41+
}
3642
}
43+
// We don't need the "fixed_target" property if it's empty
44+
if (std::string(MD.first) == "sycl_fixed_targets" && Aspects.empty())
45+
continue;
46+
Requirements[MD.second] =
47+
std::vector<uint32_t>(Aspects.begin(), Aspects.end());
3748
}
38-
39-
Result["aspects"] = std::vector<uint32_t>(Aspects.begin(), Aspects.end());
40-
return Result;
4149
}

llvm/tools/sycl-post-link/SYCLDeviceRequirements.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace llvm {
1717
class Module;
1818
class StringRef;
1919

20-
std::map<StringRef, std::vector<uint32_t>>
21-
getSYCLDeviceRequirements(const Module &M);
20+
void getSYCLDeviceRequirements(
21+
const Module &M, std::map<StringRef, std::vector<uint32_t>> &Requirements);
2222

2323
} // namespace llvm

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ std::string saveModuleProperties(module_split::ModuleDesc &MD,
365365
PropSet.add(PropSetRegTy::SYCL_DEVICELIB_REQ_MASK, RMEntry);
366366
}
367367
{
368-
std::map<StringRef, std::vector<uint32_t>> Requirements =
369-
getSYCLDeviceRequirements(M);
368+
std::map<StringRef, std::vector<uint32_t>> Requirements;
369+
getSYCLDeviceRequirements(M, Requirements);
370370
PropSet.add(PropSetRegTy::SYCL_DEVICE_REQUIREMENTS, Requirements);
371371
}
372372
if (MD.Props.SpecConstsMet) {

0 commit comments

Comments
 (0)