Skip to content

Commit 803fa48

Browse files
authored
[SYCL][FPGA] Ignore duplicate memory attributes applied to declarations with different arguments (intel#12175)
This patch refactors [[intel::fpga_memory]] to handle duplicate vs conflicting attribute values properly and aligns with other upstream attributes. 1. Adds diagnostic if there's a duplicate attribute with different arguments already applied to the declaration. 2. No diagnostic is emitted if the arguments match. 3. Drops the duplicate attribute. --------- Signed-off-by: Soumi Manna <soumi.manna@intel.com>
1 parent a8d6290 commit 803fa48

File tree

3 files changed

+90
-9
lines changed

3 files changed

+90
-9
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7520,9 +7520,7 @@ static void handleSYCLIntelDoublePumpAttr(Sema &S, Decl *D,
75207520

75217521
/// Handle the [[intel::fpga_memory]] attribute.
75227522
/// This is incompatible with the [[intel::fpga_register]] attribute.
7523-
static void handleSYCLIntelMemoryAttr(Sema &S, Decl *D,
7524-
const ParsedAttr &AL) {
7525-
checkForDuplicateAttribute<SYCLIntelMemoryAttr>(S, D, AL);
7523+
static void handleSYCLIntelMemoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
75267524
if (checkAttrMutualExclusion<SYCLIntelRegisterAttr>(S, D, AL))
75277525
return;
75287526

@@ -7543,10 +7541,20 @@ static void handleSYCLIntelMemoryAttr(Sema &S, Decl *D,
75437541
}
75447542
}
75457543

7546-
// We are adding a user memory attribute, drop any implicit default.
7547-
if (auto *MA = D->getAttr<SYCLIntelMemoryAttr>())
7548-
if (MA->isImplicit())
7549-
D->dropAttr<SYCLIntelMemoryAttr>();
7544+
if (auto *MA = D->getAttr<SYCLIntelMemoryAttr>()) {
7545+
// Check to see if there's a duplicate memory attribute with different
7546+
// values already applied to the declaration.
7547+
if (!MA->isImplicit()) {
7548+
if (MA->getKind() != Kind) {
7549+
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << &AL;
7550+
S.Diag(MA->getLocation(), diag::note_previous_attribute);
7551+
}
7552+
// Drop the duplicate attribute.
7553+
return;
7554+
}
7555+
// We are adding a user memory attribute, drop any implicit default.
7556+
D->dropAttr<SYCLIntelMemoryAttr>();
7557+
}
75507558

75517559
D->addAttr(::new (S.Context) SYCLIntelMemoryAttr(S.Context, AL, Kind));
75527560
}

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,46 @@ void check_ast()
265265
[[intel::merge("mrg6", "depth")]]
266266
[[intel::merge("mrg6", "depth")]] unsigned int mrg_mrg6[4];
267267

268+
// Check to see if there's a duplicate attribute with different values
269+
// already applied to the declaration. Drop the duplicate attribute.
270+
// CHECK: VarDecl{{.*}}mem_block_ram
271+
// CHECK: SYCLIntelMemoryAttr{{.*}}MLAB
272+
// CHECK-NOT: SYCLIntelMemoryAttr
273+
[[intel::fpga_memory("MLAB")]]
274+
[[intel::fpga_memory("BLOCK_RAM")]] unsigned int mem_block_ram[32];
275+
276+
// Check to see if there's a duplicate attribute with same Default values
277+
// already applied to the declaration. Drop the duplicate attribute.
278+
// CHECK: VarDecl{{.*}}mem_memory
279+
// CHECK: SYCLIntelMemoryAttr{{.*}}Default
280+
// CHECK-NOT: SYCLIntelMemoryAttr
281+
[[intel::fpga_memory]]
282+
[[intel::fpga_memory]] unsigned int mem_memory[64];
283+
284+
// Check to see if there's a duplicate attribute with same values
285+
// already applied to the declaration. Drop the duplicate attribute.
286+
// CHECK: VarDecl{{.*}}mem_memory_block
287+
// CHECK: SYCLIntelMemoryAttr{{.*}}BlockRAM
288+
// CHECK-NOT: SYCLIntelMemoryAttr
289+
[[intel::fpga_memory("BLOCK_RAM")]]
290+
[[intel::fpga_memory("BLOCK_RAM")]] unsigned int mem_memory_block[64];
291+
292+
// Check to see if there's a duplicate attribute with different values
293+
// already applied to the declaration. Drop the duplicate attribute.
294+
// CHECK: VarDecl{{.*}}mem_mlabs
295+
// CHECK: SYCLIntelMemoryAttr{{.*}}Default
296+
// CHECK-NOT: SYCLIntelMemoryAttr
297+
[[intel::fpga_memory]]
298+
[[intel::fpga_memory("MLAB")]] unsigned int mem_mlabs[64];
299+
300+
// Check to see if there's a duplicate attribute with different values
301+
// already applied to the declaration. Drop the duplicate attribute.
302+
// CHECK: VarDecl{{.*}}mem_mlabs_block_ram
303+
// CHECK: SYCLIntelMemoryAttr{{.*}}BlockRAM
304+
// CHECK-NOT: SYCLIntelMemoryAttr
305+
[[intel::fpga_memory("BLOCK_RAM")]]
306+
[[intel::fpga_memory]] unsigned int mem_mlabs_block_ram[64];
307+
268308
// FIXME: Duplicate attribute should be ignored.
269309
// Both are applied at the moment.
270310
//CHECK: VarDecl{{.*}}bb_bb

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,45 @@ void diagnostics()
143143
//expected-note@-2 {{conflicting attribute is here}}
144144
unsigned int mem_reg[64];
145145

146-
//expected-warning@+1{{attribute 'fpga_memory' is already applied}}
147-
[[intel::fpga_memory]] [[intel::fpga_memory]] unsigned int mem_mem[64];
146+
// Check to see if there's a duplicate attribute with same Default values
147+
// already applied to the declaration.
148+
// No diagnostic is emitted because the arguments match.
149+
[[intel::fpga_memory]]
150+
[[intel::fpga_memory]] unsigned int mem_mem[64]; // OK
148151

149152
//expected-warning@+1 {{unknown attribute 'memory' ignored}}
150153
[[intelfpga::memory]] unsigned int memory_var[64];
151154

155+
// Check to see if there's a duplicate attribute with different values
156+
// already applied to the declaration.
157+
// Diagnostic is emitted because the arguments mismatch.
158+
//expected-warning@+2{{attribute 'fpga_memory' is already applied with different arguments}}
159+
[[intel::fpga_memory("MLAB")]] // expected-note {{previous attribute is here}}
160+
[[intel::fpga_memory("BLOCK_RAM")]] unsigned int mem_block_ram[32];
161+
162+
// Check to see if there's a duplicate attribute with same values
163+
// already applied to the declaration.
164+
// No diagnostic is emitted because the arguments match.
165+
[[intel::fpga_memory("MLAB")]]
166+
[[intel::fpga_memory("MLAB")]] unsigned int mem_mlab[32]; // OK
167+
168+
[[intel::fpga_memory("BLOCK_RAM")]]
169+
[[intel::fpga_memory("BLOCK_RAM")]] unsigned int mem_block[32]; // OK
170+
171+
// Check to see if there's a duplicate attribute with different values
172+
// already applied to the declaration.
173+
// Diagnostic is emitted because the arguments mismatch.
174+
//expected-warning@+2{{attribute 'fpga_memory' is already applied with different arguments}}
175+
[[intel::fpga_memory]] // expected-note {{previous attribute is here}}
176+
[[intel::fpga_memory("MLAB")]] unsigned int mem_mlabs[64];
177+
178+
// Check to see if there's a duplicate attribute with different values
179+
// already applied to the declaration.
180+
// Diagnostic is emitted because the arguments mismatch.
181+
//expected-warning@+2{{attribute 'fpga_memory' is already applied with different arguments}}
182+
[[intel::fpga_memory("BLOCK_RAM")]] // expected-note {{previous attribute is here}}
183+
[[intel::fpga_memory]] unsigned int mem_mlabs_block_ram[64];
184+
152185
// **bankwidth
153186
//expected-warning@+1 {{unknown attribute 'bankwidth' ignored}}
154187
[[intelfpga::bankwidth(4)]] unsigned int bankwidth_var[32];

0 commit comments

Comments
 (0)