Skip to content

Commit fa77646

Browse files
Addressed review comments
1 parent c2b2f67 commit fa77646

File tree

6 files changed

+120
-10
lines changed

6 files changed

+120
-10
lines changed

clang/lib/CodeGen/CGSYCLRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool CGSYCLRuntime::actOnFunctionStart(const FunctionDecl &FD,
6666

6767
// Set the function attribute expected by the vector backend compiler.
6868
if (const auto *A = FD.getAttr<SYCLIntelESimdVectorizeAttr>())
69-
if (const auto *DeclExpr = dyn_cast<ConstantExpr>(A->getValue())) {
69+
if (const auto *DeclExpr = cast<ConstantExpr>(A->getValue())) {
7070
SmallString<2> Str;
7171
DeclExpr->getResultAsAPSInt().toString(Str);
7272
F.addFnAttr("CMGenxSIMT", Str);

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5100,12 +5100,6 @@ void Sema::AddSYCLIntelESimdVectorizeAttr(Decl *D,
51005100
return;
51015101
E = Res.get();
51025102

5103-
// This attribute requires a strictly positive value.
5104-
if (ArgVal <= 0) {
5105-
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
5106-
<< CI << /*positive*/ 0;
5107-
return;
5108-
}
51095103
if (ArgVal != 8 && ArgVal != 16 && ArgVal != 32) {
51105104
Diag(E->getExprLoc(), diag::err_sycl_esimd_vectorize_unsupported_value)
51115105
<< CI;

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,16 @@ static void instantiateSYCLIntelFPGAInitiationIntervalAttr(
733733
S.AddSYCLIntelFPGAInitiationIntervalAttr(New, *A, Result.getAs<Expr>());
734734
}
735735

736+
static void instantiateSYCLIntelESimdVectorizeAttr(
737+
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
738+
const SYCLIntelESimdVectorizeAttr *A, Decl *New) {
739+
EnterExpressionEvaluationContext Unevaluated(
740+
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
741+
ExprResult Result = S.SubstExpr(A->getValue(), TemplateArgs);
742+
if (!Result.isInvalid())
743+
S.AddSYCLIntelESimdVectorizeAttr(New, *A, Result.getAs<Expr>());
744+
}
745+
736746
/// Determine whether the attribute A might be relevent to the declaration D.
737747
/// If not, we can skip instantiating it. The attribute may or may not have
738748
/// been instantiated yet.
@@ -970,6 +980,12 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
970980
*this, TemplateArgs, SYCLIntelFPGAInitiationInterval, New);
971981
continue;
972982
}
983+
if (const auto *SYCLIntelESimdVectorize =
984+
dyn_cast<SYCLIntelESimdVectorizeAttr>(TmplAttr)) {
985+
instantiateSYCLIntelESimdVectorizeAttr(*this, TemplateArgs,
986+
SYCLIntelESimdVectorize, New);
987+
continue;
988+
}
973989
// Existing DLL attribute on the instantiation takes precedence.
974990
if (TmplAttr->getKind() == attr::DLLExport ||
975991
TmplAttr->getKind() == attr::DLLImport) {

clang/test/SemaSYCL/esimd-vectorize-attr-device.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
// expected-error@+1{{'sycl_esimd_vectorize' attribute argument must be 8, 16, or 32}}
66
[[intel::sycl_esimd_vectorize(17)]] void foo1() {}
7-
// expected-error@+1{{'sycl_esimd_vectorize' attribute requires a positive integral compile time constant expression}}
8-
[[intel::sycl_esimd_vectorize(-8)]] void foo2() {}
97
// expected-error@+1{{integral constant expression must have integral or unscoped enumeration type, not 'float'}}
108
[[intel::sycl_esimd_vectorize(3.f)]] void foo3() {}
119

1210
[[intel::sycl_esimd_vectorize(8)]] void foo4() {}
1311
[[intel::sycl_esimd_vectorize(16)]] void foo5() {}
1412
[[intel::sycl_esimd_vectorize(32)]] void foo6() {}
1513

14+
// We explicitly do not support a GNU spelling for this attribute, which is why it is
15+
// treated as an unknown attribute.
1616
// expected-warning@+1{{unknown attribute 'sycl_esimd_vectorize' ignored}}
1717
__attribute__((sycl_esimd_vectorize(8))) void foo7() {}
1818

@@ -43,3 +43,6 @@ struct Functor {
4343
void test() {
4444
auto f2 = []() [[intel::sycl_esimd_vectorize(8)]]{};
4545
}
46+
47+
template <int N>
48+
[[intel::sycl_esimd_vectorize(N)]] void templateFunc();

clang/test/SemaSYCL/esimd-vectorize-attr-host.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
// expected-warning@+1{{'sycl_esimd_vectorize' attribute ignored}}
66
[[intel::sycl_esimd_vectorize(17)]] void foo1() {}
77

8+
// We explicitly do not support a GNU spelling for this attribute, which is why it is
9+
// treated as an unknown attribute.
810
// expected-warning@+1{{unknown attribute 'sycl_esimd_vectorize' ignored}}
9-
__attribute__((sycl_esimd_vectorize(8))) void foo2() {}
11+
__attribute__((sycl_esimd_vectorize(8))) void foo2() {}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -ast-dump -verify -pedantic %s | FileCheck %s
2+
3+
// Test that checks template parameter support for 'sycl_esimd_vectorize' attribute on sycl device.
4+
5+
// Test wrong function template instantiation and ensure that the type
6+
// is checked properly when instantiating from the template definition.
7+
template <typename Ty>
8+
// expected-error@+3{{integral constant expression must have integral or unscoped enumeration type, not 'S'}}
9+
// expected-error@+2{{integral constant expression must have integral or unscoped enumeration type, not 'float'}}
10+
// expected-error@+1{{'sycl_esimd_vectorize' attribute argument must be 8, 16, or 32}}
11+
[[intel::sycl_esimd_vectorize(Ty{})]] void func() {}
12+
13+
struct S {};
14+
void test() {
15+
//expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}}
16+
func<S>();
17+
//expected-note@+1{{in instantiation of function template specialization 'func<float>' requested here}}
18+
func<float>();
19+
//expected-note@+1{{in instantiation of function template specialization 'func<int>' requested here}}
20+
func<int>();
21+
}
22+
23+
// Test a non-constant expression.
24+
// expected-note@+1{{declared here}}
25+
int foo();
26+
// expected-error@+2{{expression is not an integral constant expression}}
27+
// expected-note@+1{{non-constexpr function 'foo' cannot be used in a constant expression}}
28+
[[intel::sycl_esimd_vectorize(foo() + 12)]] void func1();
29+
30+
// Test a constant expression.
31+
constexpr int bar() { return 0; }
32+
[[intel::sycl_esimd_vectorize(bar() + 16)]] void func2(); // OK
33+
34+
// Test template parameter support on member function of class template.
35+
template <int SIZE>
36+
class KernelFunctor {
37+
public:
38+
// expected-error@+1{{'sycl_esimd_vectorize' attribute argument must be 8, 16, or 32}}
39+
[[intel::sycl_esimd_vectorize(SIZE)]] void operator()() {}
40+
};
41+
42+
int main() {
43+
//expected-note@+1{{in instantiation of template class 'KernelFunctor<-1>' requested here}}
44+
KernelFunctor<-1>();
45+
// no error expected
46+
KernelFunctor<8>();
47+
return 0;
48+
}
49+
50+
// CHECK: ClassTemplateDecl {{.*}} {{.*}} KernelFunctor
51+
// CHECK: ClassTemplateSpecializationDecl {{.*}} {{.*}} class KernelFunctor definition
52+
// CHECK: CXXRecordDecl {{.*}} {{.*}} implicit class KernelFunctor
53+
// CHECK: SYCLIntelESimdVectorizeAttr {{.*}}
54+
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
55+
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
56+
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}
57+
58+
// Test template parameter support on function.
59+
template <int N>
60+
// expected-error@+1{{'sycl_esimd_vectorize' attribute argument must be 8, 16, or 32}}
61+
[[intel::sycl_esimd_vectorize(N)]] void func3() {}
62+
63+
template <int N>
64+
[[intel::sycl_esimd_vectorize(32)]] void func4(); // expected-note {{previous attribute is here}}
65+
66+
template <int N>
67+
[[intel::sycl_esimd_vectorize(N)]] void func4() {} // expected-warning {{attribute 'sycl_esimd_vectorize' is already applied with different arguments}}
68+
69+
int check() {
70+
// no error expected.
71+
func3<8>();
72+
//expected-note@+1{{in instantiation of function template specialization 'func3<-1>' requested here}}
73+
func3<-1>();
74+
//expected-note@+1 {{in instantiation of function template specialization 'func4<16>' requested here}}
75+
func4<16>();
76+
return 0;
77+
}
78+
79+
// No diagnostic is emitted because the arguments match. Duplicate attribute is silently ignored.
80+
[[intel::sycl_esimd_vectorize(8)]]
81+
[[intel::sycl_esimd_vectorize(8)]] void func5() {}
82+
83+
// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3
84+
// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N
85+
// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()'
86+
// CHECK: SYCLIntelESimdVectorizeAttr {{.*}}
87+
// CHECK: SubstNonTypeTemplateParmExpr {{.*}}
88+
// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}
89+
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}
90+
91+
// CHECK: FunctionDecl {{.*}} {{.*}} func5 'void ()'
92+
// CHECK: SYCLIntelESimdVectorizeAttr {{.*}}
93+
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
94+
// CHECK-NEXT: value: Int 8
95+
// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}}

0 commit comments

Comments
 (0)