Skip to content

Commit 336248f

Browse files
committed
Don't emit UserSemantic with full annotation str if FPGA decorations found
#1206 with a change of 'AnnotatedDecoration' to 'AnnotatedCode' brought a regression, when the annotation information started to be duplicated in both UserSemantic decoration and FPGA-specific decorations. This patch fixes that. Yet if there is an annotation string that is split in blocks like Intel FPGA annotation, it's not necessarily an FPGA annotation. Translate the whole string as UserSemantic decoration in this case. Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 4d66fe7 commit 336248f

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,11 +2317,13 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
23172317
RegexIterT DecorationsIt(AnnotatedCode.begin(), AnnotatedCode.end(),
23182318
DecorationRegex);
23192319
RegexIterT DecorationsEnd;
2320-
// If we didn't find any FPGA specific annotations then add a UserSemantic
2321-
// decoration
2320+
// If we didn't find any FPGA specific annotations that are seprated as
2321+
// described above, then add a UserSemantic decoration
23222322
if (DecorationsIt == DecorationsEnd)
23232323
Decorates.MemoryAttributesVec.emplace_back(DecorationUserSemantic,
23242324
AnnotatedCode.str());
2325+
bool IntelFPGADecorationFound = false;
2326+
DecorationsInfoVec IntelFPGADecorationsVec;
23252327
for (; DecorationsIt != DecorationsEnd; ++DecorationsIt) {
23262328
// Drop the braces surrounding the actual decoration
23272329
const StringRef AnnotatedDecoration = AnnotatedCode.substr(
@@ -2331,12 +2333,14 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
23312333
StringRef Name = Split.first, ValueStr = Split.second;
23322334
if (AllowFPGAMemAccesses) {
23332335
if (Name == "params") {
2336+
IntelFPGADecorationFound = true;
23342337
unsigned ParamsBitMask = 0;
23352338
bool Failure = ValueStr.getAsInteger(10, ParamsBitMask);
23362339
assert(!Failure && "Non-integer LSU controls value");
23372340
(void)Failure;
23382341
LSUControls.setWithBitMask(ParamsBitMask);
23392342
} else if (Name == "cache-size") {
2343+
IntelFPGADecorationFound = true;
23402344
if (!LSUControls.CacheSizeInfo.hasValue())
23412345
continue;
23422346
unsigned CacheSizeValue = 0;
@@ -2350,12 +2354,15 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
23502354
StringRef Annotation;
23512355
Decoration Dec;
23522356
if (Name == "pump") {
2357+
IntelFPGADecorationFound = true;
23532358
Dec = llvm::StringSwitch<Decoration>(ValueStr)
23542359
.Case("1", DecorationSinglepumpINTEL)
23552360
.Case("2", DecorationDoublepumpINTEL);
23562361
} else if (Name == "register") {
2362+
IntelFPGADecorationFound = true;
23572363
Dec = DecorationRegisterINTEL;
23582364
} else if (Name == "simple_dual_port") {
2365+
IntelFPGADecorationFound = true;
23592366
Dec = DecorationSimpleDualPortINTEL;
23602367
} else {
23612368
Dec = llvm::StringSwitch<Decoration>(Name)
@@ -2369,14 +2376,25 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
23692376
.Case("force_pow2_depth", DecorationForcePow2DepthINTEL)
23702377
.Default(DecorationUserSemantic);
23712378
if (Dec == DecorationUserSemantic)
2372-
Annotation = AnnotatedCode;
2373-
else
2379+
Annotation = AnnotatedDecoration;
2380+
else {
2381+
IntelFPGADecorationFound = true;
23742382
Annotation = ValueStr;
2383+
}
23752384
}
2376-
Decorates.MemoryAttributesVec.emplace_back(Dec, Annotation.str());
2385+
IntelFPGADecorationsVec.emplace_back(Dec, Annotation.str());
23772386
}
23782387
}
2388+
// Even if there is an annotation string that is split in blocks like Intel
2389+
// FPGA annotation, it's not necessarily an FPGA annotation. Translate the
2390+
// whole string as UserSemantic decoration in this case.
2391+
if (IntelFPGADecorationFound)
2392+
Decorates.MemoryAttributesVec = IntelFPGADecorationsVec;
2393+
else
2394+
Decorates.MemoryAttributesVec.emplace_back(DecorationUserSemantic,
2395+
AnnotatedCode.str());
23792396
Decorates.MemoryAccessesVec = LSUControls.getDecorationsFromCurrentState();
2397+
23802398
return Decorates;
23812399
}
23822400

test/transcoding/IntelFPGAMemoryAttributes.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@
249249
; CHECK-SPIRV: Decorate {{[0-9]+}} ForcePow2DepthINTEL 0
250250
; CHECK-SPIRV: Decorate {{[0-9]+}} ForcePow2DepthINTEL 1
251251

252+
; CHECK-SPIRV-NOT: Decorate [[#]] UserSemantic "{memory:MLAB}{sizeinfo:4,500}"
253+
252254
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
253255
target triple = "spir"
254256

0 commit comments

Comments
 (0)