Skip to content

[SYCL] Remove manual diagnostic checking for stmt attrs. #3442

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

Merged
merged 9 commits into from
Apr 6, 2021
Merged
6 changes: 3 additions & 3 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ def SYCLIntelFPGAInitiationInterval : DeclOrStmtAttr {
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt, Function],
ErrorDiag,
"'for', 'while', 'do' statements, and functions">;
let Args = [ExprArgument<"IntervalExpr", /*opt*/1>];
let Args = [ExprArgument<"IntervalExpr">];
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
let HasCustomTypeTransform = 1;
let Documentation = [SYCLIntelFPGAInitiationIntervalAttrDocs];
Expand Down Expand Up @@ -1928,7 +1928,7 @@ def SYCLIntelFPGAMaxInterleaving : StmtAttr {
CXX11<"intel","max_interleaving">];
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
ErrorDiag, "'for', 'while', and 'do' statements">;
let Args = [ExprArgument<"NExpr", /*opt*/1>];
let Args = [ExprArgument<"NExpr">];
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
let HasCustomTypeTransform = 1;
let Documentation = [SYCLIntelFPGAMaxInterleavingAttrDocs];
Expand All @@ -1939,7 +1939,7 @@ def SYCLIntelFPGASpeculatedIterations : StmtAttr {
CXX11<"intel","speculated_iterations">];
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
ErrorDiag, "'for', 'while', and 'do' statements">;
let Args = [ExprArgument<"NExpr", /*opt*/1>];
let Args = [ExprArgument<"NExpr">];
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
let HasCustomTypeTransform = 1;
let Documentation = [SYCLIntelFPGASpeculatedIterationsAttrDocs];
Expand Down
12 changes: 0 additions & 12 deletions clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2823,18 +2823,6 @@ class Parser : public CodeCompletionHandler {
void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
/// Parses opencl_unroll_hint attribute if language is OpenCL v2.0
/// or higher.
/// \return false if error happens.
bool MaybeParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs) {
if (getLangOpts().OpenCL)
return ParseOpenCLUnrollHintAttribute(Attrs);
return true;
}
/// Parses opencl_unroll_hint attribute.
/// \return false if error happens.
bool ParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs);

void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
VersionTuple ParseVersionTuple(SourceRange &Range);
void ParseAvailabilityAttribute(IdentifierInfo &Availability,
Expand Down
63 changes: 5 additions & 58 deletions clang/lib/Sema/SemaStmtAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,40 +70,15 @@ static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,

template <typename FPGALoopAttrT>
static Attr *handleIntelFPGALoopAttr(Sema &S, Stmt *St, const ParsedAttr &A) {
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
<< A << "'for', 'while', and 'do' statements";
return nullptr;
}

unsigned NumArgs = A.getNumArgs();
if (NumArgs == 0) {
if (A.getKind() == ParsedAttr::AT_SYCLIntelFPGAInitiationInterval ||
A.getKind() == ParsedAttr::AT_SYCLIntelFPGAMaxConcurrency ||
A.getKind() == ParsedAttr::AT_SYCLIntelFPGAMaxInterleaving ||
A.getKind() == ParsedAttr::AT_SYCLIntelFPGASpeculatedIterations) {
S.Diag(A.getLoc(), diag::warn_attribute_too_few_arguments) << A << 1;
return nullptr;
}
}

S.CheckDeprecatedSYCLAttributeSpelling(A);

return S.BuildSYCLIntelFPGALoopAttr<FPGALoopAttrT>(
A, A.getNumArgs() ? A.getArgAsExpr(0) : nullptr);
}

template <>
Attr *handleIntelFPGALoopAttr<SYCLIntelFPGADisableLoopPipeliningAttr>(
Sema &S, Stmt *St, const ParsedAttr &A) {
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
<< A << "'for', 'while', and 'do' statements";
return nullptr;
}

static Attr *handleSYCLIntelFPGADisableLoopPipeliningAttr(Sema &S, Stmt *,
const ParsedAttr &A) {
S.CheckDeprecatedSYCLAttributeSpelling(A);

return new (S.Context) SYCLIntelFPGADisableLoopPipeliningAttr(S.Context, A);
}

Expand Down Expand Up @@ -259,12 +234,6 @@ CheckRedundantSYCLIntelFPGAIVDepAttrs(Sema &S, ArrayRef<const Attr *> Attrs) {
}

static Attr *handleIntelFPGAIVDepAttr(Sema &S, Stmt *St, const ParsedAttr &A) {
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
<< A << "'for', 'while', and 'do' statements";
return nullptr;
}

unsigned NumArgs = A.getNumArgs();

S.CheckDeprecatedSYCLAttributeSpelling(A);
Expand All @@ -276,12 +245,6 @@ static Attr *handleIntelFPGAIVDepAttr(Sema &S, Stmt *St, const ParsedAttr &A) {

static Attr *handleIntelFPGANofusionAttr(Sema &S, Stmt *St,
const ParsedAttr &A) {
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
<< A << "'for', 'while', and 'do' statements";
return nullptr;
}

return new (S.Context) SYCLIntelFPGANofusionAttr(S.Context, A);
}

Expand Down Expand Up @@ -726,28 +689,13 @@ static Attr *handleLoopUnrollHint(Sema &S, Stmt *St, const ParsedAttr &A,
// determines unrolling factor) or 1 argument (the unroll factor provided
// by the user).

if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
<< A << "'for', 'while', and 'do' statements";
return nullptr;
}

Expr *E = A.getNumArgs() ? A.getArgAsExpr(0) : nullptr;
if (A.getParsedKind() == ParsedAttr::AT_OpenCLUnrollHint)
return S.BuildOpenCLLoopUnrollHintAttr(A, E);
else if (A.getParsedKind() == ParsedAttr::AT_LoopUnrollHint) {
// FIXME: this should be hoisted up to the top level, but can't be placed
// there until the opencl attribute has its parsing error converted into a
// semantic error. See: Parser::ParseOpenCLUnrollHintAttribute().
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
<< A << "'for', 'while', and 'do' statements";
return nullptr;
}
if (A.getParsedKind() == ParsedAttr::AT_LoopUnrollHint)
return S.BuildLoopUnrollHintAttr(A, E);
}

return nullptr;
llvm_unreachable("Unknown loop unroll hint");
}

static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
Expand Down Expand Up @@ -788,8 +736,7 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
case ParsedAttr::AT_SYCLIntelFPGALoopCoalesce:
return handleIntelFPGALoopAttr<SYCLIntelFPGALoopCoalesceAttr>(S, St, A);
case ParsedAttr::AT_SYCLIntelFPGADisableLoopPipelining:
return handleIntelFPGALoopAttr<SYCLIntelFPGADisableLoopPipeliningAttr>(
S, St, A);
return handleSYCLIntelFPGADisableLoopPipeliningAttr(S, St, A);
case ParsedAttr::AT_SYCLIntelFPGAMaxInterleaving:
return handleIntelFPGALoopAttr<SYCLIntelFPGAMaxInterleavingAttr>(S, St, A);
case ParsedAttr::AT_SYCLIntelFPGASpeculatedIterations:
Expand Down
2 changes: 1 addition & 1 deletion clang/test/SemaSYCL/initiation_interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[[intel::initiation_interval(-1)]] void func1() {} // expected-error{{'initiation_interval' attribute requires a positive integral compile time constant expression}}

[[intel::initiation_interval(0, 1)]] void func2() {} // expected-error{{'initiation_interval' attribute takes no more than 1 argument}}
[[intel::initiation_interval(0, 1)]] void func2() {} // expected-error{{'initiation_interval' attribute takes one argument}}

// Tests for Intel FPGA initiation_interval function attribute duplication.
// No diagnostic is emitted because the arguments match. Duplicate attribute is silently ignored.
Expand Down
12 changes: 6 additions & 6 deletions clang/test/SemaSYCL/intel-fpga-loops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ void boo() {
// expected-error@+1 {{duplicate argument to 'ivdep'; attribute requires one or both of a safelen and array}}
[[intel::ivdep(2, 2)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-warning@+1 {{'initiation_interval' attribute takes at least 1 argument; attribute ignored}}
// expected-error@+1 {{'initiation_interval' attribute takes one argument}}
[[intel::initiation_interval]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'initiation_interval' attribute takes no more than 1 argument}}
// expected-error@+1 {{'initiation_interval' attribute takes one argument}}
[[intel::initiation_interval(2, 2)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'max_concurrency' attribute takes one argument}}
Expand All @@ -104,16 +104,16 @@ void boo() {
// expected-error@+1 {{'loop_coalesce' attribute takes no more than 1 argument}}
[[intel::loop_coalesce(2, 3)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-warning@+1 {{'max_interleaving' attribute takes at least 1 argument; attribute ignored}}
// expected-error@+1 {{'max_interleaving' attribute takes one argument}}
[[intel::max_interleaving]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'max_interleaving' attribute takes no more than 1 argument}}
// expected-error@+1 {{'max_interleaving' attribute takes one argument}}
[[intel::max_interleaving(2, 4)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-warning@+1 {{'speculated_iterations' attribute takes at least 1 argument; attribute ignored}}
// expected-error@+1 {{'speculated_iterations' attribute takes one argument}}
[[intel::speculated_iterations]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'speculated_iterations' attribute takes no more than 1 argument}}
// expected-error@+1 {{'speculated_iterations' attribute takes one argument}}
[[intel::speculated_iterations(1, 2)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'nofusion' attribute takes no arguments}}
Expand Down