Skip to content

Commit b04e6a0

Browse files
authored
[SYCL] Rename [[intel::ii]] to [[intel::initiation_interval]] (#3151)
"ii" is a low-quality name that is difficult for users to discover the meaning of, so rename to a more descriptive name. We also warn that the old name is deprecated and provide a fix-it to migrate to the new name.
1 parent ced4e34 commit b04e6a0

File tree

10 files changed

+106
-59
lines changed

10 files changed

+106
-59
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,13 +1846,14 @@ def SYCLIntelFPGAIVDep : Attr {
18461846
let Documentation = [SYCLIntelFPGAIVDepAttrDocs];
18471847
}
18481848

1849-
def SYCLIntelFPGAII : Attr {
1849+
def SYCLIntelFPGAInitiationInterval : StmtAttr {
18501850
let Spellings = [CXX11<"intelfpga","ii">,
1851-
CXX11<"intel","ii">];
1851+
CXX11<"intel","ii">,
1852+
CXX11<"intel", "initiation_interval">];
18521853
let Args = [ExprArgument<"IntervalExpr">];
18531854
let LangOpts = [SYCLIsDevice, SYCLIsHost];
18541855
let HasCustomTypeTransform = 1;
1855-
let Documentation = [SYCLIntelFPGAIIAttrDocs];
1856+
let Documentation = [SYCLIntelFPGAInitiationIntervalAttrDocs];
18561857
}
18571858

18581859
def SYCLIntelFPGAMaxConcurrency : Attr {

clang/include/clang/Basic/AttrDocs.td

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,24 +2749,27 @@ the no-array ivdep's safelen, with the correspondent treatment by the backend.
27492749
}];
27502750
}
27512751

2752-
def SYCLIntelFPGAIIAttrDocs : Documentation {
2752+
def SYCLIntelFPGAInitiationIntervalAttrDocs : Documentation {
27532753
let Category = DocCatVariable;
2754-
let Heading = "intel::ii";
2754+
let Heading = "intel::initiation_interval";
27552755
let Content = [{
27562756
This attribute applies to a loop. Indicates that the loop should be pipelined
27572757
with an initiation interval of N. N must be a positive integer. Cannot be
27582758
applied multiple times to the same loop.
27592759

2760+
The ``[[intel::ii]]`` attribute spelling is a deprecated synonym for
2761+
``[[intel::initiation_interval]]`` and will be removed in the future.
2762+
27602763
.. code-block:: c++
27612764

27622765
void foo() {
27632766
int var = 0;
2764-
[[intel::ii(4)]] for (int i = 0; i < 10; ++i) var++;
2767+
[[intel::initiation_interval(4)]] for (int i = 0; i < 10; ++i) var++;
27652768
}
27662769

27672770
template<int N>
27682771
void bar() {
2769-
[[intel::ii(N)]] for(;;) { }
2772+
[[intel::initiation_interval(N)]] for(;;) { }
27702773
}
27712774

27722775
}];

clang/include/clang/Sema/Sema.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12998,6 +12998,11 @@ class Sema final {
1299812998
void MarkDevice();
1299912999
void MarkSyclSimd();
1300013000

13001+
/// Emit a diagnostic about the given attribute having a deprecated name, and
13002+
/// also emit a fixit hint to generate the new attribute name.
13003+
void DiagnoseDeprecatedAttribute(const ParsedAttr &A, StringRef NewScope,
13004+
StringRef NewName);
13005+
1300113006
/// Diagnoses an attribute in the 'intelfpga' namespace and suggests using
1300213007
/// the attribute in the 'intel' namespace instead.
1300313008
void CheckDeprecatedSYCLAttributeSpelling(const ParsedAttr &A,
@@ -13252,7 +13257,7 @@ FPGALoopAttrT *Sema::BuildSYCLIntelFPGALoopAttr(const AttributeCommonInfo &A,
1325213257

1325313258
int Val = ArgVal->getSExtValue();
1325413259

13255-
if (A.getParsedKind() == ParsedAttr::AT_SYCLIntelFPGAII ||
13260+
if (A.getParsedKind() == ParsedAttr::AT_SYCLIntelFPGAInitiationInterval ||
1325613261
A.getParsedKind() == ParsedAttr::AT_SYCLIntelFPGALoopCoalesce) {
1325713262
if (Val <= 0) {
1325813263
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)

clang/lib/CodeGen/CGLoopInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,8 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
10171017
addSYCLIVDepInfo(Header->getContext(), IntelFPGAIVDep->getSafelenValue(),
10181018
IntelFPGAIVDep->getArrayDecl());
10191019

1020-
if (const auto *IntelFPGAII = dyn_cast<SYCLIntelFPGAIIAttr>(A))
1020+
if (const auto *IntelFPGAII =
1021+
dyn_cast<SYCLIntelFPGAInitiationIntervalAttr>(A))
10211022
setSYCLIInterval(IntelFPGAII->getIntervalExpr()
10221023
->getIntegerConstantExpr(Ctx)
10231024
->getSExtValue());

clang/lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,8 @@ bool Parser::ParseSYCLLoopAttributes(ParsedAttributes &Attrs) {
25732573
return true;
25742574

25752575
if (Attrs.begin()->getKind() != ParsedAttr::AT_SYCLIntelFPGAIVDep &&
2576-
Attrs.begin()->getKind() != ParsedAttr::AT_SYCLIntelFPGAII &&
2576+
Attrs.begin()->getKind() !=
2577+
ParsedAttr::AT_SYCLIntelFPGAInitiationInterval &&
25772578
Attrs.begin()->getKind() != ParsedAttr::AT_SYCLIntelFPGAMaxConcurrency &&
25782579
Attrs.begin()->getKind() != ParsedAttr::AT_SYCLIntelFPGALoopCoalesce &&
25792580
Attrs.begin()->getKind() !=

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -320,26 +320,52 @@ static bool checkAttrMutualExclusion(Sema &S, Decl *D, const Attr &AL) {
320320
return false;
321321
}
322322

323+
void Sema::DiagnoseDeprecatedAttribute(const ParsedAttr &A, StringRef NewScope,
324+
StringRef NewName) {
325+
assert((!NewName.empty() || !NewScope.empty()) &&
326+
"Deprecated attribute with no new scope or name?");
327+
Diag(A.getLoc(), diag::warn_attribute_spelling_deprecated)
328+
<< "'" + A.getNormalizedFullName() + "'";
329+
330+
FixItHint Fix;
331+
std::string NewFullName;
332+
if (NewScope.empty() && !NewName.empty()) {
333+
// Only have a new name.
334+
Fix = FixItHint::CreateReplacement(A.getLoc(), NewName);
335+
NewFullName =
336+
((A.hasScope() ? A.getScopeName()->getName() : StringRef("")) +
337+
"::" + NewName)
338+
.str();
339+
} else if (NewName.empty() && !NewScope.empty()) {
340+
// Only have a new scope.
341+
Fix = FixItHint::CreateReplacement(A.getScopeLoc(), NewScope);
342+
NewFullName = (NewScope + "::" + A.getAttrName()->getName()).str();
343+
} else {
344+
// Have both a new name and a new scope.
345+
NewFullName = (NewScope + "::" + NewName).str();
346+
Fix = FixItHint::CreateReplacement(A.getRange(), NewFullName);
347+
}
348+
349+
Diag(A.getLoc(), diag::note_spelling_suggestion)
350+
<< "'" + NewFullName + "'" << Fix;
351+
}
352+
323353
void Sema::CheckDeprecatedSYCLAttributeSpelling(const ParsedAttr &A,
324354
StringRef NewName) {
355+
// Additionally, diagnose the old [[intel::ii]] spelling.
356+
if (A.getKind() == ParsedAttr::AT_SYCLIntelFPGAInitiationInterval &&
357+
A.getAttrName()->isStr("ii")) {
358+
DiagnoseDeprecatedAttribute(A, "intel", "initiation_interval");
359+
return;
360+
}
361+
325362
// All attributes in the intelfpga vendor namespace are deprecated in favor
326363
// of a name in the intel vendor namespace. By default, assume the attribute
327364
// retains its original name but changes the namespace. However, some
328365
// attributes were renamed, so we support supplying a new name as well.
329366
if (A.hasScope() && A.getScopeName()->isStr("intelfpga")) {
330-
Diag(A.getLoc(), diag::warn_attribute_spelling_deprecated)
331-
<< "'" + A.getNormalizedFullName() + "'";
332-
333-
FixItHint Fix = NewName.empty()
334-
? FixItHint::CreateReplacement(A.getScopeLoc(), "intel")
335-
: FixItHint::CreateReplacement(
336-
A.getRange(), ("intel::" + NewName).str());
337-
338-
Diag(A.getLoc(), diag::note_spelling_suggestion)
339-
<< (llvm::Twine("'intel::") +
340-
(NewName.empty() ? A.getAttrName()->getName() : NewName) + "'")
341-
.str()
342-
<< Fix;
367+
DiagnoseDeprecatedAttribute(A, "intel", NewName);
368+
return;
343369
}
344370
}
345371

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static Attr *handleIntelFPGALoopAttr(Sema &S, const ParsedAttr &A) {
8787
}
8888

8989
if (NumArgs == 0) {
90-
if (A.getKind() == ParsedAttr::AT_SYCLIntelFPGAII ||
90+
if (A.getKind() == ParsedAttr::AT_SYCLIntelFPGAInitiationInterval ||
9191
A.getKind() == ParsedAttr::AT_SYCLIntelFPGAMaxConcurrency ||
9292
A.getKind() == ParsedAttr::AT_SYCLIntelFPGAMaxInterleaving ||
9393
A.getKind() == ParsedAttr::AT_SYCLIntelFPGASpeculatedIterations) {
@@ -639,7 +639,8 @@ static void CheckMutualExclusionSYCLLoopAttribute(
639639

640640
static void CheckForIncompatibleSYCLLoopAttributes(
641641
Sema &S, const SmallVectorImpl<const Attr *> &Attrs) {
642-
CheckForDuplicationSYCLLoopAttribute<SYCLIntelFPGAIIAttr>(S, Attrs);
642+
CheckForDuplicationSYCLLoopAttribute<SYCLIntelFPGAInitiationIntervalAttr>(
643+
S, Attrs);
643644
CheckForDuplicationSYCLLoopAttribute<SYCLIntelFPGAMaxConcurrencyAttr>(S,
644645
Attrs);
645646
CheckForDuplicationSYCLLoopAttribute<SYCLIntelFPGALoopCoalesceAttr>(S, Attrs);
@@ -657,7 +658,8 @@ static void CheckForIncompatibleSYCLLoopAttributes(
657658
SYCLIntelFPGASpeculatedIterationsAttr>(
658659
S, Attrs);
659660
CheckMutualExclusionSYCLLoopAttribute<SYCLIntelFPGADisableLoopPipeliningAttr,
660-
SYCLIntelFPGAIIAttr>(S, Attrs);
661+
SYCLIntelFPGAInitiationIntervalAttr>(
662+
S, Attrs);
661663
CheckMutualExclusionSYCLLoopAttribute<SYCLIntelFPGADisableLoopPipeliningAttr,
662664
SYCLIntelFPGAIVDepAttr>(S, Attrs);
663665
CheckMutualExclusionSYCLLoopAttribute<SYCLIntelFPGADisableLoopPipeliningAttr,
@@ -770,8 +772,8 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
770772
return handleLoopHintAttr(S, St, A, Range);
771773
case ParsedAttr::AT_SYCLIntelFPGAIVDep:
772774
return handleIntelFPGAIVDepAttr(S, A);
773-
case ParsedAttr::AT_SYCLIntelFPGAII:
774-
return handleIntelFPGALoopAttr<SYCLIntelFPGAIIAttr>(S, A);
775+
case ParsedAttr::AT_SYCLIntelFPGAInitiationInterval:
776+
return handleIntelFPGALoopAttr<SYCLIntelFPGAInitiationIntervalAttr>(S, A);
775777
case ParsedAttr::AT_SYCLIntelFPGAMaxConcurrency:
776778
return handleIntelFPGALoopAttr<SYCLIntelFPGAMaxConcurrencyAttr>(S, A);
777779
case ParsedAttr::AT_SYCLIntelFPGALoopCoalesce:

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,8 +1077,9 @@ namespace {
10771077
const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH);
10781078
const SYCLIntelFPGAIVDepAttr *
10791079
TransformSYCLIntelFPGAIVDepAttr(const SYCLIntelFPGAIVDepAttr *IV);
1080-
const SYCLIntelFPGAIIAttr *
1081-
TransformSYCLIntelFPGAIIAttr(const SYCLIntelFPGAIIAttr *II);
1080+
const SYCLIntelFPGAInitiationIntervalAttr *
1081+
TransformSYCLIntelFPGAInitiationIntervalAttr(
1082+
const SYCLIntelFPGAInitiationIntervalAttr *II);
10821083
const SYCLIntelFPGAMaxConcurrencyAttr *
10831084
TransformSYCLIntelFPGAMaxConcurrencyAttr(
10841085
const SYCLIntelFPGAMaxConcurrencyAttr *MC);
@@ -1568,12 +1569,14 @@ TemplateInstantiator::TransformSYCLIntelFPGAIVDepAttr(
15681569
return getSema().BuildSYCLIntelFPGAIVDepAttr(*IVDep, Expr1, Expr2);
15691570
}
15701571

1571-
const SYCLIntelFPGAIIAttr *TemplateInstantiator::TransformSYCLIntelFPGAIIAttr(
1572-
const SYCLIntelFPGAIIAttr *II) {
1572+
const SYCLIntelFPGAInitiationIntervalAttr *
1573+
TemplateInstantiator::TransformSYCLIntelFPGAInitiationIntervalAttr(
1574+
const SYCLIntelFPGAInitiationIntervalAttr *II) {
15731575
Expr *TransformedExpr =
15741576
getDerived().TransformExpr(II->getIntervalExpr()).get();
1575-
return getSema().BuildSYCLIntelFPGALoopAttr<SYCLIntelFPGAIIAttr>(
1576-
*II, TransformedExpr);
1577+
return getSema()
1578+
.BuildSYCLIntelFPGALoopAttr<SYCLIntelFPGAInitiationIntervalAttr>(
1579+
*II, TransformedExpr);
15771580
}
15781581

15791582
const SYCLIntelFPGAMaxConcurrencyAttr *

clang/test/SemaSYCL/intel-fpga-loops.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
void foo() {
55
// expected-error@+1 {{intelfpga loop attributes must be applied to for, while, or do statements}}
66
[[intel::ivdep]] int a[10];
7-
// expected-error@+1 {{ loop attributes must be applied to for, while, or do statements}}
7+
// expected-error@+1 {{intelfpga loop attributes must be applied to for, while, or do statements}}
88
[[intel::ivdep(2)]] int b[10];
99
// expected-error@+1 {{intelfpga loop attributes must be applied to for, while, or do statements}}
10-
[[intel::ii(2)]] int c[10];
10+
[[intel::initiation_interval(2)]] int c[10];
1111
// expected-error@+1 {{intelfpga loop attributes must be applied to for, while, or do statements}}
1212
[[intel::max_concurrency(2)]] int d[10];
1313

@@ -38,10 +38,15 @@ void foo_deprecated() {
3838
a[i] = 0;
3939

4040
// expected-warning@+2 {{attribute 'intelfpga::ii' is deprecated}}
41-
// expected-note@+1 {{did you mean to use 'intel::ii' instead?}}
41+
// expected-note@+1 {{did you mean to use 'intel::initiation_interval' instead?}}
4242
[[intelfpga::ii(2)]] for (int i = 0; i != 10; ++i)
4343
a[i] = 0;
4444

45+
// expected-warning@+2 {{attribute 'intel::ii' is deprecated}}
46+
// expected-note@+1 {{did you mean to use 'intel::initiation_interval' instead?}}
47+
[[intel::ii(2)]] for (int i = 0; i != 10; ++i)
48+
a[i] = 0;
49+
4550
// expected-warning@+2 {{attribute 'intelfpga::max_concurrency' is deprecated}}
4651
// expected-note@+1 {{did you mean to use 'intel::max_concurrency' instead?}}
4752
[[intelfpga::max_concurrency(4)]] for (int i = 0; i != 10; ++i)
@@ -75,11 +80,11 @@ void boo() {
7580
// expected-error@+1 {{duplicate argument to 'ivdep'; attribute requires one or both of a safelen and array}}
7681
[[intel::ivdep(2, 2)]] for (int i = 0; i != 10; ++i)
7782
a[i] = 0;
78-
// expected-warning@+1 {{'ii' attribute takes at least 1 argument; attribute ignored}}
79-
[[intel::ii]] for (int i = 0; i != 10; ++i)
83+
// expected-warning@+1 {{'initiation_interval' attribute takes at least 1 argument; attribute ignored}}
84+
[[intel::initiation_interval]] for (int i = 0; i != 10; ++i)
8085
a[i] = 0;
81-
// expected-warning@+1 {{'ii' attribute takes no more than 1 argument; attribute ignored}}
82-
[[intel::ii(2, 2)]] for (int i = 0; i != 10; ++i)
86+
// expected-warning@+1 {{'initiation_interval' attribute takes no more than 1 argument; attribute ignored}}
87+
[[intel::initiation_interval(2, 2)]] for (int i = 0; i != 10; ++i)
8388
a[i] = 0;
8489
// expected-warning@+1 {{'max_concurrency' attribute takes at least 1 argument; attribute ignored}}
8590
[[intel::max_concurrency]] for (int i = 0; i != 10; ++i)
@@ -133,8 +138,8 @@ void goo() {
133138
// expected-error@+1 {{'ivdep' attribute requires a positive integral compile time constant expression}}
134139
[[intel::ivdep(0)]] for (int i = 0; i != 10; ++i)
135140
a[i] = 0;
136-
// expected-error@+1 {{'ii' attribute requires a positive integral compile time constant expression}}
137-
[[intel::ii(0)]] for (int i = 0; i != 10; ++i)
141+
// expected-error@+1 {{'initiation_interval' attribute requires a positive integral compile time constant expression}}
142+
[[intel::initiation_interval(0)]] for (int i = 0; i != 10; ++i)
138143
a[i] = 0;
139144
// expected-error@+1 {{'max_concurrency' attribute requires a non-negative integral compile time constant expression}}
140145
[[intel::max_concurrency(-1)]] for (int i = 0; i != 10; ++i)
@@ -151,8 +156,8 @@ void goo() {
151156
// expected-error@+1 {{unknown argument to 'ivdep'; expected integer or array variable}}
152157
[[intel::ivdep("test123")]] for (int i = 0; i != 10; ++i)
153158
a[i] = 0;
154-
// expected-error@+1 {{'ii' attribute requires an integer constant}}
155-
[[intel::ii("test123")]] for (int i = 0; i != 10; ++i)
159+
// expected-error@+1 {{'initiation_interval' attribute requires an integer constant}}
160+
[[intel::initiation_interval("test123")]] for (int i = 0; i != 10; ++i)
156161
a[i] = 0;
157162
// expected-error@+1 {{'max_concurrency' attribute requires an integer constant}}
158163
[[intel::max_concurrency("test123")]] for (int i = 0; i != 10; ++i)
@@ -224,14 +229,14 @@ void zoo() {
224229
// expected-error@+1 {{duplicate Intel FPGA loop attribute 'max_concurrency'}}
225230
[[intel::max_concurrency(2)]] for (int i = 0; i != 10; ++i)
226231
a[i] = 0;
227-
[[intel::ii(2)]]
228-
// expected-error@+1 {{duplicate Intel FPGA loop attribute 'ii'}}
229-
[[intel::ii(2)]] for (int i = 0; i != 10; ++i)
232+
[[intel::initiation_interval(2)]]
233+
// expected-error@+1 {{duplicate Intel FPGA loop attribute 'initiation_interval'}}
234+
[[intel::initiation_interval(2)]] for (int i = 0; i != 10; ++i)
230235
a[i] = 0;
231-
[[intel::ii(2)]]
232-
// expected-error@+2 {{duplicate Intel FPGA loop attribute 'ii'}}
236+
[[intel::initiation_interval(2)]]
237+
// expected-error@+2 {{duplicate Intel FPGA loop attribute 'initiation_interval'}}
233238
[[intel::max_concurrency(2)]]
234-
[[intel::ii(2)]] for (int i = 0; i != 10; ++i)
239+
[[intel::initiation_interval(2)]] for (int i = 0; i != 10; ++i)
235240
a[i] = 0;
236241
[[intel::disable_loop_pipelining]]
237242
// expected-error@+1 {{duplicate Intel FPGA loop attribute 'disable_loop_pipelining'}}
@@ -325,8 +330,8 @@ void loop_attrs_compatibility() {
325330
[[intel::disable_loop_pipelining]]
326331
[[intel::max_concurrency(0)]] for (int i = 0; i != 10; ++i)
327332
a[i] = 0;
328-
// expected-error@+2 {{'ii' and 'disable_loop_pipelining' attributes are not compatible}}
329-
[[intel::ii(10)]]
333+
// expected-error@+2 {{'initiation_interval' and 'disable_loop_pipelining' attributes are not compatible}}
334+
[[intel::initiation_interval(10)]]
330335
[[intel::disable_loop_pipelining]] for (int i = 0; i != 10; ++i)
331336
a[i] = 0;
332337
// expected-error@+2 {{'disable_loop_pipelining' and 'ivdep' attributes are not compatible}}
@@ -374,13 +379,13 @@ void ivdep_dependent() {
374379
template <int A, int B, int C>
375380
void ii_dependent() {
376381
int a[10];
377-
// expected-error@+1 {{'ii' attribute requires a positive integral compile time constant expression}}
378-
[[intel::ii(C)]] for (int i = 0; i != 10; ++i)
382+
// expected-error@+1 {{'initiation_interval' attribute requires a positive integral compile time constant expression}}
383+
[[intel::initiation_interval(C)]] for (int i = 0; i != 10; ++i)
379384
a[i] = 0;
380385

381-
// expected-error@+2 {{duplicate Intel FPGA loop attribute 'ii'}}
382-
[[intel::ii(A)]]
383-
[[intel::ii(B)]] for (int i = 0; i != 10; ++i)
386+
// expected-error@+2 {{duplicate Intel FPGA loop attribute 'initiation_interval'}}
387+
[[intel::initiation_interval(A)]]
388+
[[intel::initiation_interval(B)]] for (int i = 0; i != 10; ++i)
384389
a[i] = 0;
385390
}
386391

clang/test/SemaSYCL/loop_unroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void foo() {
3939

4040
// no error expected
4141
[[clang::loop_unroll(4)]]
42-
[[intel::ii(2)]] for (int i = 0; i < 10; ++i);
42+
[[intel::initiation_interval(2)]] for (int i = 0; i < 10; ++i);
4343

4444
// expected-error@+2 {{'loop_unroll' attribute requires an integer constant}}
4545
int b = 4;

0 commit comments

Comments
 (0)