diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index a069a645a8..8be0142d10 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -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), diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index c169151bab..24b114c677 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -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( @@ -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; } diff --git a/test/transcoding/annotate_attribute.ll b/test/transcoding/annotate_attribute.ll index 025a5096e6..fdee185942 100644 --- a/test/transcoding/annotate_attribute.ll +++ b/test/transcoding/annotate_attribute.ll @@ -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}"