Skip to content

Commit 25b75ea

Browse files
authored
[SYCL][FPGA] Allow tablegen handle mutually exclusive decl attrs (SYCLIntelRegister and SYCLIntelMemory) (#13164)
This patch uses MutualExclusions tablegen support to allow us to remove a custom diagnostic checking codes with FPGA attributes: [[intel:fpga_register]] and [[intel::fpga_memory]].
1 parent b0ecb56 commit 25b75ea

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,6 +2779,7 @@ def SYCLIntelForcePow2Depth : InheritableAttr {
27792779
let Documentation = [SYCLIntelForcePow2DepthAttrDocs];
27802780
}
27812781
def : MutualExclusions<[SYCLIntelRegister, SYCLIntelForcePow2Depth]>;
2782+
def : MutualExclusions<[SYCLIntelRegister, SYCLIntelMemory]>;
27822783

27832784
def Naked : InheritableAttr {
27842785
let Spellings = [GCC<"naked">, Declspec<"naked">];

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7615,9 +7615,6 @@ static void handleSYCLIntelDoublePumpAttr(Sema &S, Decl *D,
76157615
/// Handle the [[intel::fpga_memory]] attribute.
76167616
/// This is incompatible with the [[intel::fpga_register]] attribute.
76177617
static void handleSYCLIntelMemoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
7618-
if (checkAttrMutualExclusion<SYCLIntelRegisterAttr>(S, D, AL))
7619-
return;
7620-
76217618
SYCLIntelMemoryAttr::MemoryKind Kind;
76227619
if (AL.getNumArgs() == 0)
76237620
Kind = SYCLIntelMemoryAttr::Default;
@@ -7663,19 +7660,6 @@ static void handleSYCLIntelMemoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
76637660
D->addAttr(::new (S.Context) SYCLIntelMemoryAttr(S.Context, AL, Kind));
76647661
}
76657662

7666-
/// Check for and diagnose attributes incompatible with register.
7667-
/// return true if any incompatible attributes exist.
7668-
static bool checkIntelFPGARegisterAttrCompatibility(Sema &S, Decl *D,
7669-
const ParsedAttr &Attr) {
7670-
bool InCompat = false;
7671-
if (auto *MA = D->getAttr<SYCLIntelMemoryAttr>())
7672-
if (!MA->isImplicit() &&
7673-
checkAttrMutualExclusion<SYCLIntelMemoryAttr>(S, D, Attr))
7674-
InCompat = true;
7675-
7676-
return InCompat;
7677-
}
7678-
76797663
/// Handle the [[intel::fpga_register]] attribute.
76807664
/// This is incompatible with most of the other memory attributes.
76817665
static void handleSYCLIntelRegisterAttr(Sema &S, Decl *D,
@@ -7703,10 +7687,7 @@ static void handleSYCLIntelRegisterAttr(Sema &S, Decl *D,
77037687
return;
77047688
}
77057689

7706-
if (checkIntelFPGARegisterAttrCompatibility(S, D, A))
7707-
return;
7708-
7709-
handleSimpleAttribute<SYCLIntelRegisterAttr>(S, D, A);
7690+
D->addAttr(::new (S.Context) SYCLIntelRegisterAttr(S.Context, A));
77107691
}
77117692

77127693
/// Handle the [[intel::bankwidth]] and [[intel::numbanks]] attributes.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ void diagnostics()
6767
//expected-note@-2 {{conflicting attribute is here}}
6868
unsigned int reg_dpump[64];
6969

70-
//expected-error@+2{{attributes are not compatible}}
70+
//expected-error@+2{{'fpga_memory' and 'fpga_register' attributes are not compatible}}
7171
[[intel::fpga_register]]
7272
[[intel::fpga_memory]]
7373
//expected-note@-2 {{conflicting attribute is here}}
7474
unsigned int reg_memory[64];
7575

76+
//expected-error@+2{{'fpga_register' and 'fpga_memory' attributes are not compatible}}
77+
[[intel::fpga_memory]]
78+
[[intel::fpga_register]]
79+
//expected-note@-2 {{conflicting attribute is here}}
80+
unsigned int reg_fp_memory[64];
81+
7682
//expected-error@+2{{'bank_bits' and 'fpga_register' attributes are not compatible}}
7783
[[intel::fpga_register]]
7884
[[intel::bank_bits(4, 5)]]

0 commit comments

Comments
 (0)