Skip to content

Commit

Permalink
Enforce UserSemantic decoration if no FPGA decorations found (#1)
Browse files Browse the repository at this point in the history
Change-Id: I09ced3ba5ca03ac196c6dc87f3cbc0e63b74a01d
Signed-off-by: Dmitry Sidorov <[email protected]>
  • Loading branch information
MrSidims authored Sep 15, 2021
1 parent d2dcd0d commit a15d232
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3624,7 +3624,7 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
isStaticMemoryAttribute
? llvm::Intrinsic::getDeclaration(M, Intrinsic::var_annotation)
: llvm::Intrinsic::getDeclaration(M, Intrinsic::ptr_annotation,
AllocatedTy);
BaseInst->getType());

llvm::Value *Args[] = {BaseInst,
Builder.CreateBitCast(GS, Int8PtrTyPrivate),
Expand Down
7 changes: 6 additions & 1 deletion lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2330,6 +2330,11 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
RegexIterT DecorationsIt(AnnotatedCode.begin(), AnnotatedCode.end(),
DecorationRegex);
RegexIterT DecorationsEnd;
// If we didn't find any FPGA specific annotations then add a UserSemantic
// decoration
if (DecorationsIt == DecorationsEnd)
Decorates.MemoryAttributesVec.emplace_back(DecorationUserSemantic,
AnnotatedCode.str());
for (; DecorationsIt != DecorationsEnd; ++DecorationsIt) {
// Drop the braces surrounding the actual decoration
const StringRef AnnotatedDecoration = AnnotatedCode.substr(
Expand Down Expand Up @@ -2377,7 +2382,7 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
.Case("force_pow2_depth", DecorationForcePow2DepthINTEL)
.Default(DecorationUserSemantic);
if (Dec == DecorationUserSemantic)
Annotation = AnnotatedDecoration;
Annotation = AnnotatedCode;
else
Annotation = ValueStr;
}
Expand Down
5 changes: 5 additions & 0 deletions test/transcoding/annotate_attribute.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM

; Check that even when FPGA memory extensions are enabled - yet we have
; UserSemantic decoration be generated
; RUN: llvm-as %s -o %t.bc
; 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

; CHECK-SPIRV: Decorate {{[0-9]+}} UserSemantic "42"
; CHECK-SPIRV: Decorate {{[0-9]+}} UserSemantic "bar"
; CHECK-SPIRV: Decorate {{[0-9]+}} UserSemantic "{FOO}"
Expand Down

0 comments on commit a15d232

Please sign in to comment.