Skip to content

Commit adadb0d

Browse files
committed
Restore sycl-opt-level attribute functionality after merge
1 parent b80c1c4 commit adadb0d

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

llvm/include/llvm/SYCLLowerIR/SYCLUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace llvm {
2222
namespace sycl {
2323
namespace utils {
2424
constexpr char ATTR_SYCL_MODULE_ID[] = "sycl-module-id";
25+
constexpr char ATTR_SYCL_OPTLEVEL[] = "sycl-optlevel";
2526

2627
using CallGraphNodeAction = ::std::function<void(Function *)>;
2728
using CallGraphFunctionFilter =

llvm/test/tools/sycl-post-link/sycl-opt-level.ll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
; RUN: FileCheck %s -input-file=%t.table
99
; RUN: FileCheck %s -input-file=%t_0.prop --check-prefixes CHECK-OPT-LEVEL-PROP-0
1010
; RUN: FileCheck %s -input-file=%t_1.prop --check-prefixes CHECK-OPT-LEVEL-PROP-1
11+
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-SYM-0
12+
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-SYM-1
1113

1214
; CHECK: [Code|Properties|Symbols]
1315
; CHECK: {{.*}}_0.ll|{{.*}}_0.prop|{{.*}}_0.sym
1416
; CHECK: {{.*}}_1.ll|{{.*}}_1.prop|{{.*}}_1.sym
17+
; CHECK-EMPTY:
1518

16-
; CHECK-OPT-LEVEL-PROP-0: optLevel=1|0
17-
; CHECK-OPT-LEVEL-PROP-1: optLevel=1|2
19+
; CHECK-OPT-LEVEL-PROP-0: optLevel=1|2
20+
; CHECK-OPT-LEVEL-PROP-1: optLevel=1|0
21+
; CHECK-SYM-0: _Z3fooii
22+
; CHECK-SYM-1: _Z3booii
1823

1924
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"
2025
target triple = "spir64-unknown-unknown"

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ constexpr char GLOBAL_SCOPE_NAME[] = "<GLOBAL>";
4343
constexpr char SYCL_SCOPE_NAME[] = "<SYCL>";
4444
constexpr char ESIMD_SCOPE_NAME[] = "<ESIMD>";
4545
constexpr char ESIMD_MARKER_MD[] = "sycl_explicit_simd";
46-
constexpr char ATTR_OPT_LEVEL[] = "sycl-optlevel";
4746

4847
bool hasIndirectFunctionsOrCalls(const Module &M) {
4948
for (const auto &F : M.functions()) {
@@ -595,7 +594,7 @@ void ModuleDesc::dump() const {
595594
llvm::errs() << "split_module::ModuleDesc[" << Name << "] {\n";
596595
llvm::errs() << " ESIMD:" << toString(EntryPoints.Props.HasESIMD)
597596
<< ", SpecConstMet:" << (Props.SpecConstsMet ? "YES" : "NO")
598-
<< ", OptLevel:" << EntryPoints.getOptLevel() << "\n";
597+
<< "\n";
599598
dumpEntryPoints(entries(), EntryPoints.GroupId.c_str(), 1);
600599
llvm::errs() << "}\n";
601600
}
@@ -851,6 +850,8 @@ getDeviceCodeSplitter(ModuleDesc &&MD, IRSplitMode Mode, bool IROutputOnly,
851850
::sycl::kernel_props::ATTR_LARGE_GRF, "large-grf");
852851
Categorizer.registerListOfIntegersInMetadataSortedRule("sycl_used_aspects");
853852
Categorizer.registerListOfIntegersInMetadataRule("reqd_work_group_size");
853+
Categorizer.registerSimpleStringAttributeRule(
854+
sycl::utils::ATTR_SYCL_OPTLEVEL);
854855
break;
855856
}
856857

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ struct EntryPointGroup {
5555
struct Properties {
5656
// Whether all EPs are ESIMD, SYCL or there are both kinds.
5757
SyclEsimdSplitStatus HasESIMD = SyclEsimdSplitStatus::SYCL_AND_ESIMD;
58-
// front-end opt level for kernel compilation
59-
int OptLevel = -1;
6058
// Scope represented by EPs in a group
6159
EntryPointsGroupScope Scope = Scope_Global;
6260

@@ -66,8 +64,6 @@ struct EntryPointGroup {
6664
? HasESIMD
6765
: SyclEsimdSplitStatus::SYCL_AND_ESIMD;
6866
// Scope remains global
69-
// OptLevel is expected to be the same for both merging EPGs
70-
assert(OptLevel == Other.OptLevel && "OptLevels are not same");
7167
return Res;
7268
}
7369
};
@@ -92,9 +88,6 @@ struct EntryPointGroup {
9288
return Props.HasESIMD == SyclEsimdSplitStatus::SYCL_ONLY;
9389
}
9490

95-
// Returns opt level
96-
int getOptLevel() const { return Props.OptLevel; }
97-
9891
void saveNames(std::vector<std::string> &Dest) const;
9992
void rebuildFromNames(const std::vector<std::string> &Names, const Module &M);
10093
void rebuild(const Module &M);
@@ -148,7 +141,6 @@ class ModuleDesc {
148141

149142
bool isESIMD() const { return EntryPoints.isEsimd(); }
150143
bool isSYCL() const { return EntryPoints.isSycl(); }
151-
int getOptLevel() const { return EntryPoints.getOptLevel(); }
152144

153145
const EntryPointSet &entries() const { return EntryPoints.Functions; }
154146
const EntryPointGroup &getEntryPointGroup() const { return EntryPoints; }

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "llvm/SYCLLowerIR/HostPipes.h"
4141
#include "llvm/SYCLLowerIR/LowerInvokeSimd.h"
4242
#include "llvm/SYCLLowerIR/LowerKernelProps.h"
43+
#include "llvm/SYCLLowerIR/SYCLUtils.h"
4344
#include "llvm/Support/CommandLine.h"
4445
#include "llvm/Support/FileSystem.h"
4546
#include "llvm/Support/InitLLVM.h"
@@ -462,9 +463,23 @@ std::string saveModuleProperties(module_split::ModuleDesc &MD,
462463
if (HasLargeGRF)
463464
PropSet[PropSetRegTy::SYCL_MISC_PROP].insert({"isLargeGRF", true});
464465
}
465-
if (MD.getOptLevel() != -1)
466-
PropSet[PropSetRegTy::SYCL_MISC_PROP].insert(
467-
{"optLevel", MD.getOptLevel()});
466+
{
467+
// Handle sycl-optlevel property
468+
int OptLevel = -1;
469+
for (const Function &F : M.functions()) {
470+
if (!F.hasFnAttribute(llvm::sycl::utils::ATTR_SYCL_OPTLEVEL))
471+
continue;
472+
473+
// getAsInteger returns true on error
474+
if (!F.getFnAttribute(llvm::sycl::utils::ATTR_SYCL_OPTLEVEL)
475+
.getValueAsString()
476+
.getAsInteger(10, OptLevel))
477+
break;
478+
}
479+
480+
if (OptLevel != -1)
481+
PropSet[PropSetRegTy::SYCL_MISC_PROP].insert({"optLevel", OptLevel});
482+
}
468483
{
469484
std::vector<StringRef> FuncNames = getKernelNamesUsingAssert(M);
470485
for (const StringRef &FName : FuncNames)

0 commit comments

Comments
 (0)