Skip to content

Commit 02d3ed7

Browse files
MrSidimsvladimirlaz
authored andcommitted
Enforce UserSemantic decoration if no FPGA decorations found
Signed-off-by: Dmitry Sidorov <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@a4ac292
1 parent 59f7707 commit 02d3ed7

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3426,7 +3426,7 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
34263426
isStaticMemoryAttribute
34273427
? llvm::Intrinsic::getDeclaration(M, Intrinsic::var_annotation)
34283428
: llvm::Intrinsic::getDeclaration(M, Intrinsic::ptr_annotation,
3429-
AllocatedTy);
3429+
BaseInst->getType());
34303430

34313431
llvm::Value *Args[] = {BaseInst,
34323432
Builder.CreateBitCast(GS, Int8PtrTyPrivate),

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,11 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
23282328
RegexIterT DecorationsIt(AnnotatedCode.begin(), AnnotatedCode.end(),
23292329
DecorationRegex);
23302330
RegexIterT DecorationsEnd;
2331+
// If we didn't find any FPGA specific annotations then add a UserSemantic
2332+
// decoration
2333+
if (DecorationsIt == DecorationsEnd)
2334+
Decorates.MemoryAttributesVec.emplace_back(DecorationUserSemantic,
2335+
AnnotatedCode.str());
23312336
for (; DecorationsIt != DecorationsEnd; ++DecorationsIt) {
23322337
// Drop the braces surrounding the actual decoration
23332338
const StringRef AnnotatedDecoration = AnnotatedCode.substr(
@@ -2375,7 +2380,7 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
23752380
.Case("force_pow2_depth", DecorationForcePow2DepthINTEL)
23762381
.Default(DecorationUserSemantic);
23772382
if (Dec == DecorationUserSemantic)
2378-
Annotation = AnnotatedDecoration;
2383+
Annotation = AnnotatedCode;
23792384
else
23802385
Annotation = ValueStr;
23812386
}

llvm-spirv/test/transcoding/annotate_attribute.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
66
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
77

8+
; Check that even when FPGA memory extensions are enabled - yet we have
9+
; UserSemantic decoration be generated
10+
; RUN: llvm-as %s -o %t.bc
11+
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_fpga_memory_accesses,+SPV_INTEL_fpga_memory_attributes -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
12+
813
; CHECK-SPIRV: Decorate {{[0-9]+}} UserSemantic "42"
914
; CHECK-SPIRV: Decorate {{[0-9]+}} UserSemantic "bar"
1015
; CHECK-SPIRV: Decorate {{[0-9]+}} UserSemantic "{FOO}"

0 commit comments

Comments
 (0)