-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Add support to propagate compile flags to device backend compiler #8763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fb3bebd
d3a9e24
395d550
0467da0
1cc4d14
5c529d2
570d720
992614e
e2e678a
d89738e
67ac752
87a6f14
97fdae7
1f2015e
2cc0bca
b77fc0f
aa878cc
6e52273
d427727
41984be
a34e009
e14db04
6359987
b021163
f2d98a2
22f034b
ce810ee
a9c01b7
15f4abb
14e882a
476a2f0
1cfa88b
ad50e96
36dda04
7f91227
2f50ba0
e25105c
8ffca4b
f1fadc4
ef009ff
b5b1b75
3937a2a
d038d4e
581d22a
821a549
c26c2fd
a1ce60f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// RUN: %clangxx %s -O0 -S -o %t.ll -fsycl-device-only | ||
// RUN: FileCheck %s --input-file %t.ll -check-prefixes=CHECK-IR | ||
// CHECK-IR: define {{.*}} spir_kernel void @{{.*}}main{{.*}}sycl{{.*}}handler{{.*}}() #[[ATTR:[0-9]+]] | ||
// CHECK-IR: attributes #[[ATTR]] = { {{.*}} "sycl-optlevel"="0" {{.*}}} | ||
|
||
// This test checks adding of the attribute 'sycl-optlevel' | ||
// by the clang front-end | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
int main() { | ||
sycl::queue q; | ||
q.submit([&](sycl::handler &h) { | ||
h.single_task([=]() {}); | ||
}); | ||
return 0; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===----- SYCLAddOptLevelAttribute.h - SYCLAddOptLevelAttribute Pass -----===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Pass adds 'sycl-optlevel' function attribute based on optimization level | ||
// passed in. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
#ifndef LLVM_SYCL_ADD_OPT_LEVEL_ATTRIBUTE_H | ||
#define LLVM_SYCL_ADD_OPT_LEVEL_ATTRIBUTE_H | ||
|
||
#include "llvm/IR/PassManager.h" | ||
|
||
namespace llvm { | ||
|
||
class SYCLAddOptLevelAttributePass | ||
: public PassInfoMixin<SYCLAddOptLevelAttributePass> { | ||
public: | ||
SYCLAddOptLevelAttributePass(int OptLevel = -1) : OptLevel{OptLevel} {}; | ||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &); | ||
|
||
private: | ||
int OptLevel; | ||
}; | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_SYCL_ADD_OPT_LEVEL_ATTRIBUTE_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//===---- SYCLAddOptLevelAttribute.cpp - SYCLAddOptLevelAttribute Pass ---===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===---------------------------------------------------------------------===// | ||
// | ||
// Pass adds 'sycl-optlevel' function attribute based on optimization level | ||
// passed in. | ||
//===---------------------------------------------------------------------===// | ||
|
||
#include "llvm/SYCLLowerIR/SYCLAddOptLevelAttribute.h" | ||
|
||
#include "llvm/IR/Module.h" | ||
|
||
using namespace llvm; | ||
|
||
PreservedAnalyses | ||
SYCLAddOptLevelAttributePass::run(Module &M, ModuleAnalysisManager &MAM) { | ||
// Here, we add a function attribute 'sycl-optlevel' to store the | ||
// optimization level. | ||
assert(OptLevel >= 0 && "Invalid optimization level!"); | ||
for (Function &F : M.functions()) { | ||
if (F.isDeclaration()) | ||
continue; | ||
F.addFnAttr("sycl-optlevel", std::to_string(OptLevel)); | ||
} | ||
return PreservedAnalyses::all(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,29 +10,29 @@ | |
; RUN: sycl-post-link -split=auto -symbols -S < %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-M0-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-M1-IR \ | ||
; RUN: FileCheck %s -input-file=%t_2.ll --check-prefixes CHECK-M1-IR \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These test updates were triggered by the fact that the order of the entries in the .table file changed due to the addition of the new entry in the list optional kernel features. A better way to NOT depend on the order of the entries is required in the long run. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: that unstable ordering is going to be fixed in #8833. That PR will also allow to simplify your changes to device code split down to a single line of code |
||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_2.ll --check-prefixes CHECK-M2-IR \ | ||
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-M2-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-M0-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-M1-SYMS \ | ||
; RUN: FileCheck %s -input-file=%t_2.sym --check-prefixes CHECK-M1-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_2.sym --check-prefixes CHECK-M2-SYMS \ | ||
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-M2-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
|
||
; RUN: sycl-post-link -split=source -symbols -S < %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-M0-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-M1-IR \ | ||
; RUN: FileCheck %s -input-file=%t_2.ll --check-prefixes CHECK-M1-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_2.ll --check-prefixes CHECK-M2-IR \ | ||
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-M2-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-M0-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-M1-SYMS \ | ||
; RUN: FileCheck %s -input-file=%t_2.sym --check-prefixes CHECK-M1-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_2.sym --check-prefixes CHECK-M2-SYMS \ | ||
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-M2-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
|
||
; RUN: sycl-post-link -split=kernel -symbols -S < %s -o %t.table | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
; This test checks parsing of the attribute 'sycl-optlevel' | ||
; by the sycl-post-link-tool: | ||
; In addition to splitting requested by user, the kernels are also split based | ||
; on their optimization levels. | ||
; sycl-post-link adds 'optLevel' property to the device binary | ||
|
||
; RUN: sycl-post-link -split=source -symbols -S < %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t.table | ||
; RUN: FileCheck %s -input-file=%t_0.prop --check-prefixes CHECK-OPT-LEVEL-PROP-0 | ||
; RUN: FileCheck %s -input-file=%t_1.prop --check-prefixes CHECK-OPT-LEVEL-PROP-1 | ||
|
||
; CHECK: [Code|Properties|Symbols] | ||
; CHECK: {{.*}}_0.ll|{{.*}}_0.prop|{{.*}}_0.sym | ||
; CHECK: {{.*}}_1.ll|{{.*}}_1.prop|{{.*}}_1.sym | ||
|
||
; CHECK-OPT-LEVEL-PROP-0: optLevel=1|0 | ||
; CHECK-OPT-LEVEL-PROP-1: optLevel=1|2 | ||
|
||
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" | ||
target triple = "spir64-unknown-unknown" | ||
|
||
define dso_local spir_func noundef i32 @_Z3fooii(i32 noundef %a, i32 noundef %b) local_unnamed_addr #0 { | ||
entry: | ||
%sub = sub nsw i32 %a, %b | ||
ret i32 %sub | ||
} | ||
|
||
define dso_local spir_func noundef i32 @_Z3booii(i32 noundef %a, i32 noundef %b) #1 { | ||
entry: | ||
%retval = alloca i32, align 4 | ||
%a.addr = alloca i32, align 4 | ||
%b.addr = alloca i32, align 4 | ||
%retval.ascast = addrspacecast i32* %retval to i32 addrspace(4)* | ||
%a.addr.ascast = addrspacecast i32* %a.addr to i32 addrspace(4)* | ||
%b.addr.ascast = addrspacecast i32* %b.addr to i32 addrspace(4)* | ||
store i32 %a, i32 addrspace(4)* %a.addr.ascast, align 4 | ||
store i32 %b, i32 addrspace(4)* %b.addr.ascast, align 4 | ||
%0 = load i32, i32 addrspace(4)* %a.addr.ascast, align 4 | ||
%1 = load i32, i32 addrspace(4)* %b.addr.ascast, align 4 | ||
%add = add nsw i32 %0, %1 | ||
ret i32 %add | ||
} | ||
|
||
attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) "sycl-module-id"="test3.cpp" "sycl-optlevel"="2" } | ||
attributes #1 = { convergent mustprogress noinline norecurse nounwind optnone "sycl-module-id"="test2.cpp" "sycl-optlevel"="0" } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need an additional test with explicit
__attribute__((optnone))
on the kernel/device function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My changes do not interact with this attribute. The backend should be responsible to decide whether the attribute or the option takes precedence.
Thanks