From e1cee964d1c1e6d491f96f93d3cbf601af82cd96 Mon Sep 17 00:00:00 2001 From: DmitryBushev Date: Thu, 8 Oct 2020 14:16:15 +0300 Subject: [PATCH] Implementing VectorComputeCallableFunctionINTEL decoration Added following decoration and bidirectional translation it to "VCCallable" attribute --- lib/SPIRV/SPIRVReader.cpp | 2 ++ lib/SPIRV/SPIRVWriter.cpp | 4 ++++ lib/SPIRV/VectorComputeUtil.h | 1 + lib/SPIRV/libSPIRV/SPIRVEnum.h | 2 ++ lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h | 1 + lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h | 2 ++ lib/SPIRV/libSPIRV/spirv.hpp | 1 + test/callable-attribute-decoration.ll | 19 +++++++++++++++++++ 8 files changed, 32 insertions(+) create mode 100644 test/callable-attribute-decoration.ll diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index f02a746b0d..1c9ab91a45 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -3749,6 +3749,8 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) { SPIRVWord SIMTMode = 0; if (BF->hasDecorate(DecorationSIMTCallINTEL, 0, &SIMTMode)) F->addFnAttr(kVCMetadata::VCSIMTCall, std::to_string(SIMTMode)); + if (BF->hasDecorate(DecorationVectorComputeCallableFunctionINTEL)) + F->addFnAttr(kVCMetadata::VCCallable); for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I) { diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index 18c091142f..e37d39d144 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -613,6 +613,10 @@ void LLVMToSPIRV::transVectorComputeMetadata(Function *F) { BF->addDecorate(DecorationSIMTCallINTEL, SIMTMode); } + if (Attrs.hasFnAttribute(kVCMetadata::VCCallable)) { + BF->addDecorate(DecorationVectorComputeCallableFunctionINTEL); + } + for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I) { auto ArgNo = I->getArgNo(); diff --git a/lib/SPIRV/VectorComputeUtil.h b/lib/SPIRV/VectorComputeUtil.h index 978d5ab096..fcf082d802 100755 --- a/lib/SPIRV/VectorComputeUtil.h +++ b/lib/SPIRV/VectorComputeUtil.h @@ -108,6 +108,7 @@ const static char VCGlobalVariable[] = "VCGlobalVariable"; const static char VCVolatile[] = "VCVolatile"; const static char VCByteOffset[] = "VCByteOffset"; const static char VCSIMTCall[] = "VCSIMTCall"; +const static char VCCallable[] = "VCCallable"; } // namespace kVCMetadata namespace kVCType { diff --git a/lib/SPIRV/libSPIRV/SPIRVEnum.h b/lib/SPIRV/libSPIRV/SPIRVEnum.h index 839ca216f4..49c6e1a0d1 100644 --- a/lib/SPIRV/libSPIRV/SPIRVEnum.h +++ b/lib/SPIRV/libSPIRV/SPIRVEnum.h @@ -410,6 +410,8 @@ template <> inline void SPIRVMap::init() { {CapabilityFunctionFloatControlINTEL}); ADD_VEC_INIT(DecorationFunctionFloatingPointModeINTEL, {CapabilityFunctionFloatControlINTEL}); + ADD_VEC_INIT(DecorationVectorComputeCallableFunctionINTEL, + {CapabilityVectorComputeINTEL}); } template <> inline void SPIRVMap::init() { diff --git a/lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h b/lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h index 99257b6714..c16c8c9714 100644 --- a/lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h +++ b/lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h @@ -437,6 +437,7 @@ inline bool isValid(spv::Decoration V) { case DecorationFunctionRoundingModeINTEL: case DecorationFunctionDenormModeINTEL: case DecorationFunctionFloatingPointModeINTEL: + case DecorationVectorComputeCallableFunctionINTEL: return true; default: return false; diff --git a/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h b/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h index 3ee67713fc..f85b2a07c9 100644 --- a/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h +++ b/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h @@ -379,6 +379,8 @@ template <> inline void SPIRVMap::init() { add(DecorationFunctionDenormModeINTEL, "FunctionDenormModeINTEL"); add(DecorationFunctionFloatingPointModeINTEL, "FunctionFloatingPointModeINTEL"); + add(DecorationVectorComputeCallableFunctionINTEL, + "VectorComputeCallableFunctionINTEL"); add(DecorationMax, "Max"); } SPIRV_DEF_NAMEMAP(Decoration, SPIRVDecorationNameMap) diff --git a/lib/SPIRV/libSPIRV/spirv.hpp b/lib/SPIRV/libSPIRV/spirv.hpp index 01fae5578c..39dea0068b 100644 --- a/lib/SPIRV/libSPIRV/spirv.hpp +++ b/lib/SPIRV/libSPIRV/spirv.hpp @@ -521,6 +521,7 @@ enum Decoration { DecorationBufferLocationINTEL = 5921, DecorationIOPipeStorageINTEL = 5944, DecorationFunctionFloatingPointModeINTEL = 6080, + DecorationVectorComputeCallableFunctionINTEL = 6087, DecorationMax = 0x7fffffff, }; diff --git a/test/callable-attribute-decoration.ll b/test/callable-attribute-decoration.ll new file mode 100644 index 0000000000..2abdfd632f --- /dev/null +++ b/test/callable-attribute-decoration.ll @@ -0,0 +1,19 @@ +; RUN: llvm-as %s -o %t.bc +; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_INTEL_vector_compute +; RUN: llvm-spirv %t.spv -o %t.spt --to-text +; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV +; RUN: llvm-spirv %t.spv -o %t.bc -r +; RUN: llvm-dis %t.bc -o %t.ll +; RUN: FileCheck < %t.ll %s --check-prefix=CHECK-LLVM +target triple = "spir64" + + +define dso_local <4 x i32> @foo(<4 x i32> %a, <4 x i32> %b) #0 { +entry: + ret <4 x i32> %a +} +; CHECK-SPIRV: 3 Decorate {{[0-9]+}} VectorComputeCallableFunctionINTEL +; CHECK-LLVM: attributes +; CHECK-LLVM-SAME: "VCCallable" + +attributes #0 = { "VCCallable" "VCFunction" }