From 02f6d68ae3fbf884a74de449b0619192958874e5 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarev Date: Tue, 19 Mar 2019 16:33:24 +0300 Subject: [PATCH] [SYCL] Sync with 23c581c8c2be4cdc51b9b234ca4a77e9ac49cde8 SPIRV translator commit Signed-off-by: Vladimir Lazarev --- llvm-spirv/.travis.yml | 22 +- llvm-spirv/CMakeLists.txt | 2 +- llvm-spirv/README.md | 2 +- llvm-spirv/include/LLVMSPIRVLib.h | 10 +- llvm-spirv/lib/SPIRV/CMakeLists.txt | 5 - llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp | 27 +- .../lib/SPIRV/Mangler/ManglingUtils.cpp | 192 +++++++++----- llvm-spirv/lib/SPIRV/Mangler/ParameterType.h | 48 +++- llvm-spirv/lib/SPIRV/OCL20To12.cpp | 1 - llvm-spirv/lib/SPIRV/OCL20ToSPIRV.cpp | 1 - llvm-spirv/lib/SPIRV/OCL21ToSPIRV.cpp | 1 - llvm-spirv/lib/SPIRV/OCLTypeToSPIRV.cpp | 1 - llvm-spirv/lib/SPIRV/OCLUtil.cpp | 63 +++-- llvm-spirv/lib/SPIRV/OCLUtil.h | 1 + llvm-spirv/lib/SPIRV/SPIRVLowerBool.cpp | 1 - llvm-spirv/lib/SPIRV/SPIRVLowerConstExpr.cpp | 1 - llvm-spirv/lib/SPIRV/SPIRVLowerMemmove.cpp | 1 - llvm-spirv/lib/SPIRV/SPIRVLowerOCLBlocks.cpp | 249 ++---------------- llvm-spirv/lib/SPIRV/SPIRVLowerSPIRBlocks.cpp | 10 +- llvm-spirv/lib/SPIRV/SPIRVReader.cpp | 101 ++++--- llvm-spirv/lib/SPIRV/SPIRVReader.h | 3 +- llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.cpp | 1 - llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp | 4 + llvm-spirv/lib/SPIRV/SPIRVToOCL20.cpp | 1 - llvm-spirv/lib/SPIRV/SPIRVUtil.cpp | 71 +++-- llvm-spirv/lib/SPIRV/SPIRVWriter.cpp | 22 +- llvm-spirv/lib/SPIRV/SPIRVWriterPass.cpp | 6 +- llvm-spirv/lib/SPIRV/SPIRVWriterPass.h | 7 +- llvm-spirv/lib/SPIRV/TransOCLMD.cpp | 1 - llvm-spirv/lib/SPIRV/libSPIRV/SPIRV.debug.h | 4 +- llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDebug.h | 7 - llvm-spirv/lib/SPIRV/libSPIRV/SPIRVFunction.h | 19 ++ llvm-spirv/lib/SPIRV/libSPIRV/SPIRVModule.cpp | 9 +- llvm-spirv/lib/SPIRV/libSPIRV/SPIRVOpCode.h | 3 +- llvm-spirv/lib/SPIRV/libSPIRV/SPIRVUtil.h | 5 - llvm-spirv/test/CMakeLists.txt | 1 - llvm-spirv/test/ContractionOff.ll | 30 ++- .../test/DebugInfo/BuiltinCallLocation.ll | 54 ++++ llvm-spirv/test/DebugInfo/DebugFunction.ll | 79 ++++++ llvm-spirv/test/DebugInfo/UnknownBaseType.ll | 52 ++++ .../test/DebugInfo/X86/dw_op_minus_direct.ll | 2 +- llvm-spirv/test/KernelArgTypeInOpString2.ll | 70 +++++ llvm-spirv/test/SampledImage.ll | 10 +- llvm-spirv/test/global_block.ll | 88 +++---- .../test/image_without_access_qualifier.spt | 2 +- llvm-spirv/test/literal-struct.ll | 31 ++- .../test/transcoding/OpConstantSampler.ll | 4 +- .../test/transcoding/OpControlBarrier_cl12.ll | 13 +- .../test/transcoding/OpControlBarrier_cl20.ll | 44 ++-- .../OpControlBarrier_cl20_subgroup.ll | 44 ++-- .../test/transcoding/OpControlBarrier_cl21.ll | 45 ++-- .../test/transcoding/OpImageQuerySize.ll | 166 ++++++------ llvm-spirv/test/transcoding/OpImageReadMS.ll | 22 +- .../transcoding/OpImageSampleExplicitLod.ll | 14 +- .../OpImageSampleExplicitLod_arg.ll | 23 +- llvm-spirv/test/transcoding/OpImageWrite.ll | 16 +- .../test/transcoding/block_w_struct_return.ll | 47 ++-- .../test/transcoding/check_ro_qualifier.ll | 18 +- .../test/transcoding/check_wo_qualifier.ll | 18 +- llvm-spirv/test/transcoding/cl-types.ll | 71 ++--- .../test/transcoding/cl_intel_sub_groups.ll | 2 +- llvm-spirv/test/transcoding/enqueue_kernel.ll | 237 ++++++++++------- llvm-spirv/test/transcoding/image_builtins.ll | 83 ++++++ llvm-spirv/test/transcoding/image_channel.ll | 16 +- .../image_get_size_with_access_qualifiers.ll | 2 +- .../image_with_access_qualifiers.ll | 2 +- .../test/transcoding/image_with_suffix.ll | 2 +- llvm-spirv/test/transcoding/spirv-types.ll | 50 ++-- llvm-spirv/tools/llvm-spirv/llvm-spirv.cpp | 22 +- 69 files changed, 1340 insertions(+), 942 deletions(-) create mode 100644 llvm-spirv/test/DebugInfo/BuiltinCallLocation.ll create mode 100644 llvm-spirv/test/DebugInfo/DebugFunction.ll create mode 100644 llvm-spirv/test/DebugInfo/UnknownBaseType.ll create mode 100644 llvm-spirv/test/KernelArgTypeInOpString2.ll create mode 100644 llvm-spirv/test/transcoding/image_builtins.ll diff --git a/llvm-spirv/.travis.yml b/llvm-spirv/.travis.yml index 5cad075ce20b4..a4932818a8b15 100644 --- a/llvm-spirv/.travis.yml +++ b/llvm-spirv/.travis.yml @@ -21,10 +21,10 @@ addons: key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' - ubuntu-toolchain-r-test packages: - - llvm-8-tools - - llvm-8-dev - - clang-format-8 - - clang-tidy-8 + - llvm-9-tools + - llvm-9-dev + - clang-format-9 + - clang-tidy-9 compiler: - gcc @@ -80,7 +80,7 @@ script: -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DBUILD_SHARED_LIBS=${SHARED_LIBS} \ -DLLVM_BUILD_TOOLS=ON \ - -DLLVM_EXTERNAL_LIT="/usr/lib/llvm-8/build/utils/lit/lit.py" \ + -DLLVM_EXTERNAL_LIT="/usr/lib/llvm-9/build/utils/lit/lit.py" \ -DLLVM_INCLUDE_TESTS=ON \ -DCMAKE_INSTALL_PREFIX=../install/ \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ @@ -99,7 +99,7 @@ script: fi - if [ $CHECK_FORMAT == "1" ]; then cd ..; - ln -s /usr/share/clang/clang-format-8/clang-format-diff.py utils/; + ln -s /usr/share/clang/clang-format-9/clang-format-diff.py utils/; ./utils/check_code_format.sh; elif [ $CHECK_TIDY == "1" ]; then cd ..; @@ -112,8 +112,11 @@ script: after_success: # Create tarball for deployment - if [[ "${BUILD_EXTERNAL}" == "1" && "${SHARED_LIBS}" == "ON" && "${repo_token}" != "" ]]; then - export TARBALL=SPIRV-LLVM-Translator-$(date +%F)-${TRAVIS_OS_NAME}-${BUILD_TYPE}.zip; - cd ../install && find . -print | zip -@ ${TARBALL}; + export TAG=dev-build; + export TARBALL=SPIRV-LLVM-Translator-${TAG}-${TRAVIS_OS_NAME}-${BUILD_TYPE}.zip; + cd ../install; + echo ${TRAVIS_COMMIT} > version.txt; + find . -print | zip -@ ${TARBALL}; fi before_deploy: @@ -121,7 +124,7 @@ before_deploy: # Travis CI relies on the tag name to push to the correct release. - git config --global user.name "Travis CI" - git config --global user.email "builds@travis-ci.org" - - git tag -f latest_build + - git tag -f ${TAG} - git push -f https://${repo_token}@github.com/${TRAVIS_REPO_SLUG} --tags deploy: @@ -131,6 +134,7 @@ deploy: branch: master condition: ${BUILD_EXTERNAL} == 1 && ${SHARED_LIBS} == ON && ${repo_token} file: ${TARBALL} + name: Latest development build $(date -u +'%F %R %Z') skip_cleanup: true overwrite: true prerelease: true diff --git a/llvm-spirv/CMakeLists.txt b/llvm-spirv/CMakeLists.txt index d632a50cd7e92..120874179453c 100644 --- a/llvm-spirv/CMakeLists.txt +++ b/llvm-spirv/CMakeLists.txt @@ -22,7 +22,7 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) ) endif(LLVM_INCLUDE_TESTS) - find_package(LLVM 8.0.0 REQUIRED + find_package(LLVM 9.0.0 REQUIRED COMPONENTS Analysis BitReader diff --git a/llvm-spirv/README.md b/llvm-spirv/README.md index bd9893114e548..c27aeb8925902 100644 --- a/llvm-spirv/README.md +++ b/llvm-spirv/README.md @@ -26,7 +26,7 @@ The translator can be built with the latest(nightly) package of LLVM. For Ubuntu ``` sudo add-apt-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main" sudo apt-get update -sudo apt-get install llvm-7-dev +sudo apt-get install llvm-9-dev ``` The installed version of LLVM will be used by default for out-of-tree build of the translator. ``` diff --git a/llvm-spirv/include/LLVMSPIRVLib.h b/llvm-spirv/include/LLVMSPIRVLib.h index b39c4bdce677a..aacf8eec389cd 100644 --- a/llvm-spirv/include/LLVMSPIRVLib.h +++ b/llvm-spirv/include/LLVMSPIRVLib.h @@ -76,7 +76,7 @@ bool isSpirvBinary(std::string &Img); /// This function is not thread safe and should not be used in multi-thread /// applications unless guarded by a critical section. /// \returns true if succeeds. -bool convertSpirv(std::istream &IS, llvm::raw_ostream &OS, std::string &ErrMsg, +bool convertSpirv(std::istream &IS, std::ostream &OS, std::string &ErrMsg, bool FromText, bool ToText); /// \brief Convert SPIR-V between binary and internel text formats. @@ -95,16 +95,16 @@ namespace llvm { /// \brief Translate LLVM module to SPIRV and write to ostream. /// \returns true if succeeds. -bool writeSpirv(llvm::Module *M, llvm::raw_ostream &OS, std::string &ErrMsg); +bool writeSpirv(Module *M, std::ostream &OS, std::string &ErrMsg); /// \brief Load SPIRV from istream and translate to LLVM module. /// \returns true if succeeds. -bool readSpirv(llvm::LLVMContext &C, std::istream &IS, llvm::Module *&M, +bool readSpirv(LLVMContext &C, std::istream &IS, Module *&M, std::string &ErrMsg); /// \brief Regularize LLVM module by removing entities not representable by /// SPIRV. -bool regularizeLlvmForSpirv(llvm::Module *M, std::string &ErrMsg); +bool regularizeLlvmForSpirv(Module *M, std::string &ErrMsg); /// \brief Mangle OpenCL builtin function function name. void mangleOpenClBuiltin(const std::string &UnmangledName, @@ -157,7 +157,7 @@ ModulePass *createTransOCLMD(); /// Create and return a pass that writes the module to the specified /// ostream. -ModulePass *createSPIRVWriterPass(llvm::raw_ostream &Str); +ModulePass *createSPIRVWriterPass(std::ostream &Str); } // namespace llvm diff --git a/llvm-spirv/lib/SPIRV/CMakeLists.txt b/llvm-spirv/lib/SPIRV/CMakeLists.txt index f9da60ed03448..9d031687b2c42 100644 --- a/llvm-spirv/lib/SPIRV/CMakeLists.txt +++ b/llvm-spirv/lib/SPIRV/CMakeLists.txt @@ -1,8 +1,3 @@ -option(SPIRV_USE_LLVM_API "Enable usage of LLVM API for libSPIRV." ON) -if(SPIRV_USE_LLVM_API) - add_definitions(-D_SPIRV_LLVM_API) -endif(SPIRV_USE_LLVM_API) - add_llvm_library(LLVMSPIRVLib LLVMToSPIRVDbgTran.cpp Mangler/FunctionDescriptor.cpp diff --git a/llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp b/llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp index 27c5aa05c5d77..21981fa7064f1 100644 --- a/llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp +++ b/llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp @@ -451,7 +451,9 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgBaseType(const DIBasicType *BT) { ConstantInt *Size = getUInt(M, BT->getSizeInBits()); Ops[SizeIdx] = SPIRVWriter->transValue(Size, nullptr)->getId(); auto Encoding = static_cast(BT->getEncoding()); - Ops[EncodingIdx] = SPIRV::DbgEncodingMap::map(Encoding); + SPIRVDebug::EncodingTag EncTag = SPIRVDebug::Unspecified; + SPIRV::DbgEncodingMap::find(Encoding, &EncTag); + Ops[EncodingIdx] = EncTag; return BM->addDebugInfo(SPIRVDebug::TypeBasic, getVoidTy(), Ops); } @@ -786,7 +788,11 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgFunction(const DISubprogram *Func) { Ops[SourceIdx] = getSource(Func)->getId(); Ops[LineIdx] = Func->getLine(); Ops[ColumnIdx] = 0; // This version of DISubprogram has no column number - Ops[ParentIdx] = getScope(Func->getScope())->getId(); + auto Scope = Func->getScope(); + if (Scope && isa(Scope)) + Ops[ParentIdx] = SPIRVCU->getId(); + else + Ops[ParentIdx] = getScope(Scope)->getId(); Ops[LinkageNameIdx] = BM->getString(Func->getLinkageName())->getId(); Ops[FlagsIdx] = transDebugFlags(Func); @@ -799,15 +805,14 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgFunction(const DISubprogram *Func) { Ops.resize(MinOperandCount); Ops[ScopeLineIdx] = Func->getScopeLine(); - llvm::Function *F = M->getFunction(Func->getName()); - if (!F) - F = M->getFunction(Func->getLinkageName()); - if (F) { - SPIRVValue *SPIRVFunc = SPIRVWriter->getTranslatedValue(F); - assert(SPIRVFunc && "All function must be already translated"); - Ops[FunctionIdIdx] = SPIRVFunc->getId(); - } else { - Ops[FunctionIdIdx] = getDebugInfoNoneId(); + Ops[FunctionIdIdx] = getDebugInfoNoneId(); + for (const llvm::Function &F : M->functions()) { + if (Func->describes(&F)) { + SPIRVValue *SPIRVFunc = SPIRVWriter->getTranslatedValue(&F); + assert(SPIRVFunc && "All function must be already translated"); + Ops[FunctionIdIdx] = SPIRVFunc->getId(); + break; + } } if (DISubprogram *FuncDecl = Func->getDeclaration()) diff --git a/llvm-spirv/lib/SPIRV/Mangler/ManglingUtils.cpp b/llvm-spirv/lib/SPIRV/Mangler/ManglingUtils.cpp index 8dca667f5ade9..39a452b50a4c8 100644 --- a/llvm-spirv/lib/SPIRV/Mangler/ManglingUtils.cpp +++ b/llvm-spirv/lib/SPIRV/Mangler/ManglingUtils.cpp @@ -30,18 +30,42 @@ static const char *PrimitiveNames[PRIMITIVE_NUM] = { "double", "void", "...", - "image1d_t", - "image1d_array_t", - "image1d_buffer_t", - "image2d_t", - "image2d_array_t", - "image3d_t", - "image2d_msaa_t", - "image2d_array_msaa_t", - "image2d_msaa_depth_t", - "image2d_array_msaa_depth_t", - "image2d_depth_t", - "image2d_array_depth_t", + "image1d_ro_t", + "image1d_array_ro_t", + "image1d_buffer_ro_t", + "image2d_ro_t", + "image2d_array_ro_t", + "image2d_depth_ro_t", + "image2d_array_depth_ro_t", + "image2d_msaa_ro_t", + "image2d_array_msaa_ro_t", + "image2d_msaa_depth_ro_t", + "image2d_array_msaa_depth_ro_t", + "image3d_ro_t", + "image1d_wo_t", + "image1d_array_wo_t", + "image1d_buffer_wo_t", + "image2d_wo_t", + "image2d_array_wo_t", + "image2d_depth_wo_t", + "image2d_array_depth_wo_t", + "image2d_msaa_wo_t", + "image2d_array_msaa_wo_t", + "image2d_msaa_depth_wo_t", + "image2d_array_msaa_depth_wo_t", + "image3d_wo_t", + "image1d_rw_t", + "image1d_array_rw_t", + "image1d_buffer_rw_t", + "image2d_rw_t", + "image2d_array_rw_t", + "image2d_depth_rw_t", + "image2d_array_depth_rw_t", + "image2d_msaa_rw_t", + "image2d_array_msaa_rw_t", + "image2d_msaa_depth_rw_t", + "image2d_array_msaa_depth_rw_t", + "image3d_rw_t", "event_t", "pipe_ro_t", "pipe_wo_t", @@ -56,42 +80,66 @@ static const char *PrimitiveNames[PRIMITIVE_NUM] = { "memory_scope"}; const char *MangledTypes[PRIMITIVE_NUM] = { - "b", // BOOL - "h", // UCHAR - "c", // CHAR - "t", // USHORT - "s", // SHORT - "j", // UINT - "i", // INT - "m", // ULONG - "l", // LONG - "Dh", // HALF - "f", // FLOAT - "d", // DOUBLE - "v", // VOID - "z", // VarArg - "11ocl_image1d", // PRIMITIVE_IMAGE_1D_T - "16ocl_image1darray", // PRIMITIVE_IMAGE_1D_ARRAY_T - "17ocl_image1dbuffer", // PRIMITIVE_IMAGE_1D_BUFFER_T - "11ocl_image2d", // PRIMITIVE_IMAGE_2D_T - "16ocl_image2darray", // PRIMITIVE_IMAGE_2D_ARRAY_T - "11ocl_image3d", // PRIMITIVE_IMAGE_3D_T - "15ocl_image2dmsaa", // PRIMITIVE_IMAGE_2D_MSAA_T - "20ocl_image2darraymsaa", // PRIMITIVE_IMAGE_2D_ARRAY_MSAA_T - "20ocl_image2dmsaadepth", // PRIMITIVE_IMAGE_2D_MSAA_DEPTH_T - "25ocl_image2darraymsaadepth", // PRIMITIVE_IMAGE_2D_ARRAY_MSAA_DEPTH_T - "16ocl_image2ddepth", // PRIMITIVE_IMAGE_2D_DEPTH_T - "21ocl_image2darraydepth", // PRIMITIVE_IMAGE_2D_ARRAY_DEPTH_T - "9ocl_event", // PRIMITIVE_EVENT_T - "11ocl_pipe_ro", // PRIMITIVE_PIPE_RO_T - "11ocl_pipe_wo", // PRIMITIVE_PIPE_WO_T - "13ocl_reserveid", // PRIMITIVE_RESERVE_ID_T - "9ocl_queue", // PRIMITIVE_QUEUE_T - "9ndrange_t", // PRIMITIVE_NDRANGE_T - "12ocl_clkevent", // PRIMITIVE_CLK_EVENT_T - "11ocl_sampler", // PRIMITIVE_SAMPLER_T - "i", // PRIMITIVE_KERNEL_ENQUEUE_FLAGS_T - "i", // PRIMITIVE_CLK_PROFILING_INFO + "b", // BOOL + "h", // UCHAR + "c", // CHAR + "t", // USHORT + "s", // SHORT + "j", // UINT + "i", // INT + "m", // ULONG + "l", // LONG + "Dh", // HALF + "f", // FLOAT + "d", // DOUBLE + "v", // VOID + "z", // VarArg + "14ocl_image1d_ro", // PRIMITIVE_IMAGE1D_RO_T + "20ocl_image1d_array_ro", // PRIMITIVE_IMAGE1D_ARRAY_RO_T + "21ocl_image1d_buffer_ro", // PRIMITIVE_IMAGE1D_BUFFER_RO_T + "14ocl_image2d_ro", // PRIMITIVE_IMAGE2D_RO_T + "20ocl_image2d_array_ro", // PRIMITIVE_IMAGE2D_ARRAY_RO_T + "20ocl_image2d_depth_ro", // PRIMITIVE_IMAGE2D_DEPTH_RO_T + "26ocl_image2d_array_depth_ro", // PRIMITIVE_IMAGE2D_ARRAY_DEPTH_RO_T + "19ocl_image2d_msaa_ro", // PRIMITIVE_IMAGE2D_MSAA_RO_T + "25ocl_image2d_array_msaa_ro", // PRIMITIVE_IMAGE2D_ARRAY_MSAA_RO_T + "25ocl_image2d_msaa_depth_ro", // PRIMITIVE_IMAGE2D_MSAA_DEPTH_RO_T + "31ocl_image2d_array_msaa_depth_ro", // PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_RO_T + "14ocl_image3d_ro", // PRIMITIVE_IMAGE3D_RO_T + "14ocl_image1d_wo", // PRIMITIVE_IMAGE1D_WO_T + "20ocl_image1d_array_wo", // PRIMITIVE_IMAGE1D_ARRAY_WO_T + "21ocl_image1d_buffer_wo", // PRIMITIVE_IMAGE1D_BUFFER_WO_T + "14ocl_image2d_wo", // PRIMITIVE_IMAGE2D_WO_T + "20ocl_image2d_array_wo", // PRIMITIVE_IMAGE2D_ARRAY_WO_T + "20ocl_image2d_depth_wo", // PRIMITIVE_IMAGE2D_DEPTH_WO_T + "26ocl_image2d_array_depth_wo", // PRIMITIVE_IMAGE2D_ARRAY_DEPTH_WO_T + "19ocl_image2d_msaa_wo", // PRIMITIVE_IMAGE2D_MSAA_WO_T + "25ocl_image2d_array_msaa_wo", // PRIMITIVE_IMAGE2D_ARRAY_MSAA_WO_T + "25ocl_image2d_msaa_depth_wo", // PRIMITIVE_IMAGE2D_MSAA_DEPTH_WO_T + "31ocl_image2d_array_msaa_depth_wo", // PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_WO_T + "14ocl_image3d_wo", // PRIMITIVE_IMAGE3D_WO_T + "14ocl_image1d_rw", // PRIMITIVE_IMAGE1D_RW_T + "20ocl_image1d_array_rw", // PRIMITIVE_IMAGE1D_ARRAY_RW_T + "21ocl_image1d_buffer_rw", // PRIMITIVE_IMAGE1D_BUFFER_RW_T + "14ocl_image2d_rw", // PRIMITIVE_IMAGE2D_RW_T + "20ocl_image2d_array_rw", // PRIMITIVE_IMAGE2D_ARRAY_RW_T + "20ocl_image2d_depth_rw", // PRIMITIVE_IMAGE2D_DEPTH_RW_T + "26ocl_image2d_array_depth_rw", // PRIMITIVE_IMAGE2D_ARRAY_DEPTH_RW_T + "19ocl_image2d_msaa_rw", // PRIMITIVE_IMAGE2D_MSAA_RW_T + "25ocl_image2d_array_msaa_rw", // PRIMITIVE_IMAGE2D_ARRAY_MSAA_RW_T + "25ocl_image2d_msaa_depth_rw", // PRIMITIVE_IMAGE2D_MSAA_DEPTH_RW_T + "31ocl_image2d_array_msaa_depth_rw", // PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_RW_T + "14ocl_image3d_rw", // PRIMITIVE_IMAGE3D_RW_T + "9ocl_event", // PRIMITIVE_EVENT_T + "11ocl_pipe_ro", // PRIMITIVE_PIPE_RO_T + "11ocl_pipe_wo", // PRIMITIVE_PIPE_WO_T + "13ocl_reserveid", // PRIMITIVE_RESERVE_ID_T + "9ocl_queue", // PRIMITIVE_QUEUE_T + "9ndrange_t", // PRIMITIVE_NDRANGE_T + "12ocl_clkevent", // PRIMITIVE_CLK_EVENT_T + "11ocl_sampler", // PRIMITIVE_SAMPLER_T + "i", // PRIMITIVE_KERNEL_ENQUEUE_FLAGS_T + "i", // PRIMITIVE_CLK_PROFILING_INFO #if defined(SPIRV_SPIR20_MANGLING_REQUIREMENTS) "i", // PRIMITIVE_MEMORY_ORDER "i", // PRIMITIVE_MEMORY_SCOPE @@ -126,18 +174,42 @@ static const SPIRversion PrimitiveSupportedVersions[PRIMITIVE_NUM] = { SPIR12, // DOUBLE SPIR12, // VOID SPIR12, // VarArg - SPIR12, // PRIMITIVE_IMAGE_1D_T - SPIR12, // PRIMITIVE_IMAGE_1D_ARRAY_T - SPIR12, // PRIMITIVE_IMAGE_1D_BUFFER_T - SPIR12, // PRIMITIVE_IMAGE_2D_T - SPIR12, // PRIMITIVE_IMAGE_2D_ARRAY_T - SPIR12, // PRIMITIVE_IMAGE_3D_T - SPIR12, // PRIMITIVE_IMAGE_2D_MSAA_T - SPIR12, // PRIMITIVE_IMAGE_2D_ARRAY_MSAA_T - SPIR12, // PRIMITIVE_IMAGE_2D_MSAA_DEPTH_T - SPIR12, // PRIMITIVE_IMAGE_2D_ARRAY_MSAA_DEPTH_T - SPIR12, // PRIMITIVE_IMAGE_2D_DEPTH_T - SPIR12, // PRIMITIVE_IMAGE_2D_ARRAY_DEPTH_T + SPIR12, // PRIMITIVE_IMAGE1D_RO_T + SPIR12, // PRIMITIVE_IMAGE1D_ARRAY_RO_T + SPIR12, // PRIMITIVE_IMAGE1D_BUFFER_RO_T + SPIR12, // PRIMITIVE_IMAGE2D_RO_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_RO_T + SPIR12, // PRIMITIVE_IMAGE2D_DEPTH_RO_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_DEPTH_RO_T + SPIR12, // PRIMITIVE_IMAGE2D_MSAA_RO_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_MSAA_RO_T + SPIR12, // PRIMITIVE_IMAGE2D_MSAA_DEPTH_RO_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_RO_T + SPIR12, // PRIMITIVE_IMAGE3D_RO_T + SPIR12, // PRIMITIVE_IMAGE1D_WO_T + SPIR12, // PRIMITIVE_IMAGE1D_ARRAY_WO_T + SPIR12, // PRIMITIVE_IMAGE1D_BUFFER_WO_T + SPIR12, // PRIMITIVE_IMAGE2D_WO_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_WO_T + SPIR12, // PRIMITIVE_IMAGE2D_DEPTH_WO_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_DEPTH_WO_T + SPIR12, // PRIMITIVE_IMAGE2D_MSAA_WO_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_MSAA_WO_T + SPIR12, // PRIMITIVE_IMAGE2D_MSAA_DEPTH_WO_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_WO_T + SPIR12, // PRIMITIVE_IMAGE3D_WO_T + SPIR12, // PRIMITIVE_IMAGE1D_RW_T + SPIR12, // PRIMITIVE_IMAGE1D_ARRAY_RW_T + SPIR12, // PRIMITIVE_IMAGE1D_BUFFER_RW_T + SPIR12, // PRIMITIVE_IMAGE2D_RW_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_RW_T + SPIR12, // PRIMITIVE_IMAGE2D_DEPTH_RW_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_DEPTH_RW_T + SPIR12, // PRIMITIVE_IMAGE2D_MSAA_RW_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_MSAA_RW_T + SPIR12, // PRIMITIVE_IMAGE2D_MSAA_DEPTH_RW_T + SPIR12, // PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_RW_T + SPIR12, // PRIMITIVE_IMAGE3D_RW_T SPIR12, // PRIMITIVE_EVENT_T SPIR20, // PRIMITIVE_PIPE_RO_T SPIR20, // PRIMITIVE_PIPE_WO_T diff --git a/llvm-spirv/lib/SPIRV/Mangler/ParameterType.h b/llvm-spirv/lib/SPIRV/Mangler/ParameterType.h index a79264e6ad42d..289bc1efb0967 100644 --- a/llvm-spirv/lib/SPIRV/Mangler/ParameterType.h +++ b/llvm-spirv/lib/SPIRV/Mangler/ParameterType.h @@ -48,18 +48,42 @@ enum TypePrimitiveEnum { PRIMITIVE_VOID, PRIMITIVE_VAR_ARG, PRIMITIVE_STRUCT_FIRST, - PRIMITIVE_IMAGE_1D_T = PRIMITIVE_STRUCT_FIRST, - PRIMITIVE_IMAGE_1D_ARRAY_T, - PRIMITIVE_IMAGE_1D_BUFFER_T, - PRIMITIVE_IMAGE_2D_T, - PRIMITIVE_IMAGE_2D_ARRAY_T, - PRIMITIVE_IMAGE_3D_T, - PRIMITIVE_IMAGE_2D_MSAA_T, - PRIMITIVE_IMAGE_2D_ARRAY_MSAA_T, - PRIMITIVE_IMAGE_2D_MSAA_DEPTH_T, - PRIMITIVE_IMAGE_2D_ARRAY_MSAA_DEPTH_T, - PRIMITIVE_IMAGE_2D_DEPTH_T, - PRIMITIVE_IMAGE_2D_ARRAY_DEPTH_T, + PRIMITIVE_IMAGE1D_RO_T = PRIMITIVE_STRUCT_FIRST, + PRIMITIVE_IMAGE1D_ARRAY_RO_T, + PRIMITIVE_IMAGE1D_BUFFER_RO_T, + PRIMITIVE_IMAGE2D_RO_T, + PRIMITIVE_IMAGE2D_ARRAY_RO_T, + PRIMITIVE_IMAGE2D_DEPTH_RO_T, + PRIMITIVE_IMAGE2D_ARRAY_DEPTH_RO_T, + PRIMITIVE_IMAGE2D_MSAA_RO_T, + PRIMITIVE_IMAGE2D_ARRAY_MSAA_RO_T, + PRIMITIVE_IMAGE2D_MSAA_DEPTH_RO_T, + PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_RO_T, + PRIMITIVE_IMAGE3D_RO_T, + PRIMITIVE_IMAGE1D_WO_T, + PRIMITIVE_IMAGE1D_ARRAY_WO_T, + PRIMITIVE_IMAGE1D_BUFFER_WO_T, + PRIMITIVE_IMAGE2D_WO_T, + PRIMITIVE_IMAGE2D_ARRAY_WO_T, + PRIMITIVE_IMAGE2D_DEPTH_WO_T, + PRIMITIVE_IMAGE2D_ARRAY_DEPTH_WO_T, + PRIMITIVE_IMAGE2D_MSAA_WO_T, + PRIMITIVE_IMAGE2D_ARRAY_MSAA_WO_T, + PRIMITIVE_IMAGE2D_MSAA_DEPTH_WO_T, + PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_WO_T, + PRIMITIVE_IMAGE3D_WO_T, + PRIMITIVE_IMAGE1D_RW_T, + PRIMITIVE_IMAGE1D_ARRAY_RW_T, + PRIMITIVE_IMAGE1D_BUFFER_RW_T, + PRIMITIVE_IMAGE2D_RW_T, + PRIMITIVE_IMAGE2D_ARRAY_RW_T, + PRIMITIVE_IMAGE2D_DEPTH_RW_T, + PRIMITIVE_IMAGE2D_ARRAY_DEPTH_RW_T, + PRIMITIVE_IMAGE2D_MSAA_RW_T, + PRIMITIVE_IMAGE2D_ARRAY_MSAA_RW_T, + PRIMITIVE_IMAGE2D_MSAA_DEPTH_RW_T, + PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_RW_T, + PRIMITIVE_IMAGE3D_RW_T, PRIMITIVE_EVENT_T, PRIMITIVE_PIPE_RO_T, PRIMITIVE_PIPE_WO_T, diff --git a/llvm-spirv/lib/SPIRV/OCL20To12.cpp b/llvm-spirv/lib/SPIRV/OCL20To12.cpp index 873d10453707a..69383bcebaf99 100644 --- a/llvm-spirv/lib/SPIRV/OCL20To12.cpp +++ b/llvm-spirv/lib/SPIRV/OCL20To12.cpp @@ -48,7 +48,6 @@ #include "llvm/PassSupport.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace SPIRV; diff --git a/llvm-spirv/lib/SPIRV/OCL20ToSPIRV.cpp b/llvm-spirv/lib/SPIRV/OCL20ToSPIRV.cpp index 934acdbe5362f..0e72bbbb801e6 100644 --- a/llvm-spirv/lib/SPIRV/OCL20ToSPIRV.cpp +++ b/llvm-spirv/lib/SPIRV/OCL20ToSPIRV.cpp @@ -51,7 +51,6 @@ #include "llvm/Pass.h" #include "llvm/PassSupport.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" #include #include diff --git a/llvm-spirv/lib/SPIRV/OCL21ToSPIRV.cpp b/llvm-spirv/lib/SPIRV/OCL21ToSPIRV.cpp index fb3f17db8b491..0cfc0b69ef52f 100644 --- a/llvm-spirv/lib/SPIRV/OCL21ToSPIRV.cpp +++ b/llvm-spirv/lib/SPIRV/OCL21ToSPIRV.cpp @@ -47,7 +47,6 @@ #include "llvm/Pass.h" #include "llvm/PassSupport.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" #include diff --git a/llvm-spirv/lib/SPIRV/OCLTypeToSPIRV.cpp b/llvm-spirv/lib/SPIRV/OCLTypeToSPIRV.cpp index 240bc7d66836b..2ef841bbb3a82 100644 --- a/llvm-spirv/lib/SPIRV/OCLTypeToSPIRV.cpp +++ b/llvm-spirv/lib/SPIRV/OCLTypeToSPIRV.cpp @@ -47,7 +47,6 @@ #include "llvm/Pass.h" #include "llvm/PassSupport.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" #include #include diff --git a/llvm-spirv/lib/SPIRV/OCLUtil.cpp b/llvm-spirv/lib/SPIRV/OCLUtil.cpp index e7d0312852649..5ab54f2b8cb48 100644 --- a/llvm-spirv/lib/SPIRV/OCLUtil.cpp +++ b/llvm-spirv/lib/SPIRV/OCLUtil.cpp @@ -51,7 +51,6 @@ #include "llvm/PassSupport.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace SPIRV; @@ -74,6 +73,10 @@ namespace OCLUtil { #define SPIRV_CLK_EVENT_T_ADDR_SPACE SPIRV_OCL_SPECIAL_TYPES_DEFAULT_ADDR_SPACE #endif +#ifndef SPIRV_SAMPLER_T_ADDR_SPACE +#define SPIRV_SAMPLER_T_ADDR_SPACE SPIRV_OCL_SPECIAL_TYPES_DEFAULT_ADDR_SPACE +#endif + #ifndef SPIRV_RESERVE_ID_T_ADDR_SPACE #define SPIRV_RESERVE_ID_T_ADDR_SPACE SPIRV_OCL_SPECIAL_TYPES_DEFAULT_ADDR_SPACE #endif @@ -326,6 +329,9 @@ SPIRAddressSpace getOCLOpaqueTypeAddrSpace(Op OpCode) { case OpTypeImage: case OpTypeSampledImage: return SPIRV_IMAGE_ADDR_SPACE; + case OpConstantSampler: + case OpTypeSampler: + return SPIRV_SAMPLER_T_ADDR_SPACE; default: assert(false && "No address space is determined for some OCL type"); return SPIRV_OCL_SPECIAL_TYPES_DEFAULT_ADDR_SPACE; @@ -364,18 +370,42 @@ getOCLOpaqueTypeAddrSpace(SPIR::TypePrimitiveEnum Prim) { case SPIR::PRIMITIVE_PIPE_RO_T: case SPIR::PRIMITIVE_PIPE_WO_T: return mapAddrSpaceEnums(SPIRV_PIPE_ADDR_SPACE); - case SPIR::PRIMITIVE_IMAGE_1D_T: - case SPIR::PRIMITIVE_IMAGE_1D_ARRAY_T: - case SPIR::PRIMITIVE_IMAGE_1D_BUFFER_T: - case SPIR::PRIMITIVE_IMAGE_2D_T: - case SPIR::PRIMITIVE_IMAGE_2D_ARRAY_T: - case SPIR::PRIMITIVE_IMAGE_3D_T: - case SPIR::PRIMITIVE_IMAGE_2D_MSAA_T: - case SPIR::PRIMITIVE_IMAGE_2D_ARRAY_MSAA_T: - case SPIR::PRIMITIVE_IMAGE_2D_MSAA_DEPTH_T: - case SPIR::PRIMITIVE_IMAGE_2D_ARRAY_MSAA_DEPTH_T: - case SPIR::PRIMITIVE_IMAGE_2D_DEPTH_T: - case SPIR::PRIMITIVE_IMAGE_2D_ARRAY_DEPTH_T: + case SPIR::PRIMITIVE_IMAGE1D_RO_T: + case SPIR::PRIMITIVE_IMAGE1D_ARRAY_RO_T: + case SPIR::PRIMITIVE_IMAGE1D_BUFFER_RO_T: + case SPIR::PRIMITIVE_IMAGE2D_RO_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_RO_T: + case SPIR::PRIMITIVE_IMAGE2D_DEPTH_RO_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_DEPTH_RO_T: + case SPIR::PRIMITIVE_IMAGE2D_MSAA_RO_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_RO_T: + case SPIR::PRIMITIVE_IMAGE2D_MSAA_DEPTH_RO_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_RO_T: + case SPIR::PRIMITIVE_IMAGE3D_RO_T: + case SPIR::PRIMITIVE_IMAGE1D_WO_T: + case SPIR::PRIMITIVE_IMAGE1D_ARRAY_WO_T: + case SPIR::PRIMITIVE_IMAGE1D_BUFFER_WO_T: + case SPIR::PRIMITIVE_IMAGE2D_WO_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_WO_T: + case SPIR::PRIMITIVE_IMAGE2D_DEPTH_WO_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_DEPTH_WO_T: + case SPIR::PRIMITIVE_IMAGE2D_MSAA_WO_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_WO_T: + case SPIR::PRIMITIVE_IMAGE2D_MSAA_DEPTH_WO_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_WO_T: + case SPIR::PRIMITIVE_IMAGE3D_WO_T: + case SPIR::PRIMITIVE_IMAGE1D_RW_T: + case SPIR::PRIMITIVE_IMAGE1D_ARRAY_RW_T: + case SPIR::PRIMITIVE_IMAGE1D_BUFFER_RW_T: + case SPIR::PRIMITIVE_IMAGE2D_RW_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_RW_T: + case SPIR::PRIMITIVE_IMAGE2D_DEPTH_RW_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_DEPTH_RW_T: + case SPIR::PRIMITIVE_IMAGE2D_MSAA_RW_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_RW_T: + case SPIR::PRIMITIVE_IMAGE2D_MSAA_DEPTH_RW_T: + case SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_RW_T: + case SPIR::PRIMITIVE_IMAGE3D_RW_T: return mapAddrSpaceEnums(SPIRV_IMAGE_ADDR_SPACE); default: llvm_unreachable("No address space is determined for a SPIR primitive"); @@ -698,11 +728,8 @@ void checkFpContract(BinaryOperator *B, SPIRVBasicBlock *BB) { if (auto *I = dyn_cast(Op)) { if (I->getOpcode() == Instruction::FMul) { SPIRVFunction *BF = BB->getParent(); - if (BB->getModule()->isEntryPoint(ExecutionModelKernel, BF->getId())) { - BF->addExecutionMode(BB->getModule()->add( - new SPIRVExecutionMode(BF, spv::ExecutionModeContractionOff))); - break; - } + BF->setUncontractedFMulAddFound(); + break; } } } diff --git a/llvm-spirv/lib/SPIRV/OCLUtil.h b/llvm-spirv/lib/SPIRV/OCLUtil.h index 4d4ef3ac9aa8e..4fdd5f1037850 100644 --- a/llvm-spirv/lib/SPIRV/OCLUtil.h +++ b/llvm-spirv/lib/SPIRV/OCLUtil.h @@ -835,6 +835,7 @@ template <> inline void SPIRVMap::init() { add("opencl.clk_event_t", OpTypeDeviceEvent); add("opencl.reserve_id_t", OpTypeReserveId); add("opencl.queue_t", OpTypeQueue); + add("opencl.sampler_t", OpTypeSampler); } } // namespace SPIRV diff --git a/llvm-spirv/lib/SPIRV/SPIRVLowerBool.cpp b/llvm-spirv/lib/SPIRV/SPIRVLowerBool.cpp index 6a044cb7747ac..ac7819fc49d2f 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVLowerBool.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVLowerBool.cpp @@ -46,7 +46,6 @@ #include "llvm/PassSupport.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace SPIRV; diff --git a/llvm-spirv/lib/SPIRV/SPIRVLowerConstExpr.cpp b/llvm-spirv/lib/SPIRV/SPIRVLowerConstExpr.cpp index 730f0d9b472c3..e843e31a70ffc 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVLowerConstExpr.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVLowerConstExpr.cpp @@ -52,7 +52,6 @@ #include "llvm/PassSupport.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" #include #include diff --git a/llvm-spirv/lib/SPIRV/SPIRVLowerMemmove.cpp b/llvm-spirv/lib/SPIRV/SPIRVLowerMemmove.cpp index 04be327db8907..84a939cb51e8c 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVLowerMemmove.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVLowerMemmove.cpp @@ -47,7 +47,6 @@ #include "llvm/PassSupport.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace SPIRV; diff --git a/llvm-spirv/lib/SPIRV/SPIRVLowerOCLBlocks.cpp b/llvm-spirv/lib/SPIRV/SPIRVLowerOCLBlocks.cpp index c80bf040ee6c9..b42a4ec9650b8 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVLowerOCLBlocks.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVLowerOCLBlocks.cpp @@ -40,207 +40,34 @@ // In both cases values with function type used as intermediate representation // for block literal structure. // -// This pass is designed to find such cases and simplify them to avoid any -// function pointer types occurrences in LLVM IR in 4 steps. -// -// 1. Find all function pointer allocas, like -// %block = alloca void () * -// -// Then find a single store to that alloca: -// %blockLit = alloca <{ i32, i32, ...}>, align 4 -// %0 = bitcast <{ i32, i32, ... }>* %blockLit to void ()* -// > store void ()* %0, void ()** %block, align 4 -// -// And replace the alloca users by new instructions which used stored value -// %blockLit itself instead of function pointer alloca %block. -// -// 2. Find consecutive casts from block literal type to i8 addrspace(4)* -// used function pointers as an intermediate type: -// %0 = bitcast <{ i32, i32 }> %block to void() * -// %1 = addrspacecast void() * %0 to i8 addrspace(4)* -// And simplify them: -// %2 = addrspacecast <{ i32, i32 }> %block to i8 addrspace(4)* -// -// 3. Find all unused instructions with function pointer type occured after -// pp.1-2 and remove them. -// -// 4. Find unused globals with function pointer type, like -// @block = constant void ()* -// bitcast ({ i32, i32 }* @__block_literal_global to void ()* -// -// And remove them. +// In LLVM IR produced by clang, blocks are represented with the following +// structure: +// %struct.__opencl_block_literal_generic = type { i32, i32, i8 addrspace(4)* } +// Pointers to block invoke functions are stored in the third field. Clang +// replaces inderect function calls in all cases except if block is passed as a +// function argument. Note that it is somewhat unclear if the OpenCL C spec +// should allow passing blocks as function argumernts. This pass is not supposed +// to work correctly with such functions. +// Clang though has to store function pointers to this structure. Purpose of +// this pass is to replace store of function pointers(not allowed in SPIR-V) +// with null pointers. // //===----------------------------------------------------------------------===// #define DEBUG_TYPE "spv-lower-ocl-blocks" -#include "OCLUtil.h" #include "SPIRVInternal.h" -#include "llvm/ADT/SetVector.h" -#include "llvm/Analysis/ValueTracking.h" -#include "llvm/IR/GlobalVariable.h" -#include "llvm/IR/InstIterator.h" #include "llvm/IR/Module.h" #include "llvm/Pass.h" -#include "llvm/PassSupport.h" -#include "llvm/Support/Casting.h" +#include "llvm/Support/Regex.h" using namespace llvm; namespace { -static void -removeUnusedFunctionPtrInst(Instruction *I, - SmallSetVector &FuncPtrInsts) { - for (unsigned OpIdx = 0, Ops = I->getNumOperands(); OpIdx != Ops; ++OpIdx) { - Instruction *OpI = dyn_cast(I->getOperand(OpIdx)); - I->setOperand(OpIdx, nullptr); - if (OpI && OpI != I && OpI->user_empty()) - FuncPtrInsts.insert(OpI); - } - I->eraseFromParent(); -} - -static bool isFuncPtrAlloca(const AllocaInst *AI) { - auto *ET = dyn_cast(AI->getAllocatedType()); - return ET && ET->getElementType()->isFunctionTy(); -} - -static bool hasFuncPtrType(const Value *V) { - auto *PT = dyn_cast(V->getType()); - return PT && PT->getElementType()->isFunctionTy(); -} - -static bool isFuncPtrInst(const Instruction *I) { - if (auto *AI = dyn_cast(I)) - return isFuncPtrAlloca(AI); - - for (auto &Op : I->operands()) { - if (auto *AI = dyn_cast(Op)) - return isFuncPtrAlloca(AI); - - auto *OpI = dyn_cast(&Op); - if (OpI && OpI != I && hasFuncPtrType(OpI)) - return true; - } - return false; -} - -static StoreInst *findSingleStore(AllocaInst *AI) { - StoreInst *Store = nullptr; - for (auto *U : AI->users()) { - if (!isa(U)) - continue; // not a store - if (Store) - return nullptr; // there are more than one stores - Store = dyn_cast(U); - } - return Store; -} - -static void fixFunctionPtrAllocaUsers(AllocaInst *AI) { - // Find and remove a single store to alloca - auto *SingleStore = findSingleStore(AI); - assert(SingleStore && "More than one store to the function pointer alloca"); - auto *StoredVal = SingleStore->getValueOperand(); - SingleStore->eraseFromParent(); - - // Find loads from the alloca and replace thier users - for (auto *U : AI->users()) { - auto *LI = dyn_cast(U); - if (!LI) - continue; - - for (auto *U : LI->users()) { - auto *UInst = cast(U); - auto *Cast = CastInst::CreatePointerBitCastOrAddrSpaceCast( - StoredVal, UInst->getType(), "", UInst); - UInst->replaceAllUsesWith(Cast); - } - } -} - -static int getBlockLiteralIdx(const Function &F) { - StringRef FName = F.getName(); - if (isEnqueueKernelBI(FName)) - return FName.contains("events") ? 7 : 4; - if (isKernelQueryBI(FName)) - return FName.contains("for_ndrange") ? 2 : 1; - if (FName.startswith("__") && FName.contains("_block_invoke")) - return F.hasStructRetAttr() ? 1 : 0; - - return -1; // No block literal argument -} - -static bool hasBlockLiteralArg(const Function &F) { - return getBlockLiteralIdx(F) != -1; -} - -static bool simplifyFunctionPtrCasts(Function &F) { - bool Changed = false; - int BlockLiteralIdx = getBlockLiteralIdx(F); - for (auto *U : F.users()) { - auto *Call = dyn_cast(U); - if (!Call) - continue; - if (Call->getFunction()->getName() == F.getName().str() + "_kernel") - continue; // Skip block invoke function calls inside block invoke kernels - - const DataLayout &DL = F.getParent()->getDataLayout(); - auto *BlockLiteral = Call->getOperand(BlockLiteralIdx); - auto *BlockLiteralVal = GetUnderlyingObject(BlockLiteral, DL); - if (isa(BlockLiteralVal)) - continue; // nothing to do with globals - - auto *BlockLiteralAlloca = cast(BlockLiteralVal); - assert(!BlockLiteralAlloca->getAllocatedType()->isFunctionTy() && - "Function type shouldn't be there"); - - auto *NewBlockLiteral = CastInst::CreatePointerBitCastOrAddrSpaceCast( - BlockLiteralAlloca, BlockLiteral->getType(), "", Call); - BlockLiteral->replaceAllUsesWith(NewBlockLiteral); - Changed |= true; - } - return Changed; -} - -static void -findFunctionPtrAllocas(Module &M, - SmallVectorImpl &FuncPtrAllocas) { - for (auto &F : M) { - if (F.isDeclaration()) - continue; - for (auto &I : instructions(F)) { - auto *AI = dyn_cast(&I); - if (!AI || !isFuncPtrAlloca(AI)) - continue; - FuncPtrAllocas.push_back(AI); - } - } -} - -static void -findUnusedFunctionPtrInsts(Module &M, - SmallSetVector &FuncPtrInsts) { - for (auto &F : M) { - if (F.isDeclaration()) - continue; - for (auto &I : instructions(F)) - if (I.user_empty() && isFuncPtrInst(&I)) - FuncPtrInsts.insert(&I); - } -} - -static void -findUnusedFunctionPtrGlbs(Module &M, - SmallVectorImpl &FuncPtrGlbs) { - for (auto &GV : M.globals()) { - if (!GV.user_empty()) - continue; - auto *GVType = dyn_cast(GV.getType()->getElementType()); - if (GVType && GVType->getElementType()->isFunctionTy()) - FuncPtrGlbs.push_back(&GV); - } +static bool isBlockInvoke(Function &F) { + static Regex BlockInvokeRegex("_block_invoke_?[0-9]*$"); + return BlockInvokeRegex.match(F.getName()); } class SPIRVLowerOCLBlocks : public ModulePass { @@ -250,44 +77,24 @@ class SPIRVLowerOCLBlocks : public ModulePass { bool runOnModule(Module &M) { bool Changed = false; - - // 1. Find function pointer allocas and fix their users - SmallVector FuncPtrAllocas; - findFunctionPtrAllocas(M, FuncPtrAllocas); - - Changed |= !FuncPtrAllocas.empty(); - for (auto *AI : FuncPtrAllocas) - fixFunctionPtrAllocaUsers(AI); - - // 2. Simplify consecutive casts which use function pointer types - for (auto &F : M) - if (hasBlockLiteralArg(F)) - Changed |= simplifyFunctionPtrCasts(F); - - // 3. Cleanup unused instructions with function pointer type - // which are occured after pp. 1-2 - SmallSetVector FuncPtrInsts; - findUnusedFunctionPtrInsts(M, FuncPtrInsts); - - Changed |= !FuncPtrInsts.empty(); - while (!FuncPtrInsts.empty()) { - Instruction *I = FuncPtrInsts.pop_back_val(); - removeUnusedFunctionPtrInst(I, FuncPtrInsts); + for (Function &F : M) { + if (!isBlockInvoke(F)) + continue; + for (User *U : F.users()) { + if (!isa(U)) + continue; + Constant *Null = Constant::getNullValue(U->getType()); + if (U != Null) { + U->replaceAllUsesWith(Null); + Changed = true; + } + } } - - // 4. Find and remove unused global variables with function pointer type - SmallVector FuncPtrGlbs; - findUnusedFunctionPtrGlbs(M, FuncPtrGlbs); - - Changed |= !FuncPtrGlbs.empty(); - for (auto *GV : FuncPtrGlbs) - GV->eraseFromParent(); - return Changed; } static char ID; -}; // class SPIRVLowerOCLBlocks +}; char SPIRVLowerOCLBlocks::ID = 0; diff --git a/llvm-spirv/lib/SPIRV/SPIRVLowerSPIRBlocks.cpp b/llvm-spirv/lib/SPIRV/SPIRVLowerSPIRBlocks.cpp index 295889a4873a0..a12947ff163b3 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVLowerSPIRBlocks.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVLowerSPIRBlocks.cpp @@ -42,12 +42,9 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SetVector.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/ADT/Triple.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/CallGraph.h" -#include "llvm/Bitcode/BitcodeWriter.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" @@ -60,8 +57,6 @@ #include "llvm/PassSupport.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/ToolOutputFile.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/GlobalStatus.h" #include @@ -106,7 +101,10 @@ class SPIRVLowerSPIRBlocks : public ModulePass { bool runOnModule(Module &Module) override { M = &Module; - lowerBlockBind(); + if (!lowerBlockBind()) { + // There are no SPIR2 blocks in the module. + return false; + } lowerGetBlockInvoke(); lowerGetBlockContext(); eraseUselessGlobalVars(); diff --git a/llvm-spirv/lib/SPIRV/SPIRVReader.cpp b/llvm-spirv/lib/SPIRV/SPIRVReader.cpp index 9ed45a5d924c9..1c87b334d64e3 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVReader.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVReader.cpp @@ -51,7 +51,6 @@ #include "SPIRVValue.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/StringSwitch.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" @@ -61,13 +60,11 @@ #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" -#include "llvm/IR/Operator.h" #include "llvm/IR/Type.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FileSystem.h" -#include "llvm/Support/raw_ostream.h" #include #include @@ -98,11 +95,6 @@ cl::opt SPIRVGenKernelArgNameMD( cl::desc("Enable generating OpenCL kernel argument name " "metadata")); -cl::opt SPIRVGenImgTypeAccQualPostfix( - "spirv-gen-image-type-acc-postfix", cl::init(false), - cl::desc("Enable generating access qualifier postfix" - " in OpenCL image type names")); - // Prefix for placeholder global variable name. const char *KPlaceholderPrefix = "placeholder."; @@ -333,8 +325,7 @@ Type *SPIRVToLLVM::transFPType(SPIRVType *T) { std::string SPIRVToLLVM::transOCLImageTypeName(SPIRV::SPIRVTypeImage *ST) { std::string Name = std::string(kSPR2TypeName::OCLPrefix) + rmap(ST->getDescriptor()); - if (SPIRVGenImgTypeAccQualPostfix) - SPIRVToLLVM::insertImageNameAccessQualifier(ST, Name); + SPIRVToLLVM::insertImageNameAccessQualifier(ST, Name); return Name; } @@ -418,8 +409,6 @@ Type *SPIRVToLLVM::transType(SPIRVType *T, bool IsClassMember) { llvm_unreachable("Unsupported image type"); return nullptr; } - case OpTypeSampler: - return mapType(T, Type::getInt32Ty(*Context)); case OpTypeSampledImage: { auto ST = static_cast(T); return mapType( @@ -597,7 +586,10 @@ void SPIRVToLLVM::setLLVMLoopMetadata(SPIRVLoopMerge *LM, BranchInst *BI) { void SPIRVToLLVM::insertImageNameAccessQualifier(SPIRV::SPIRVTypeImage *ST, std::string &Name) { - std::string QName = rmap(ST->getAccessQualifier()); + SPIRVAccessQualifierKind Acc = ST->hasAccessQualifier() + ? ST->getAccessQualifier() + : AccessQualifierReadOnly; + std::string QName = rmap(Acc); // transform: read_only -> ro, write_only -> wo, read_write -> rw QName = QName.substr(0, 1) + QName.substr(QName.find("_") + 1, 1) + "_"; assert(!Name.empty() && "image name should not be empty"); @@ -807,6 +799,20 @@ bool SPIRVToLLVM::postProcessOCLBuiltinWithArrayArguments( return true; } +static char getTypeSuffix(Type *T) { + char Suffix; + + Type *ST = T->getScalarType(); + if (ST->isHalfTy()) + Suffix = 'h'; + else if (ST->isFloatTy()) + Suffix = 'f'; + else + Suffix = 'i'; + + return Suffix; +} + // ToDo: Handle unsigned integer return type. May need spec change. Instruction *SPIRVToLLVM::postProcessOCLReadImage(SPIRVInstruction *BI, CallInst *CI, @@ -818,7 +824,7 @@ Instruction *SPIRVToLLVM::postProcessOCLReadImage(SPIRVInstruction *BI, if (isOCLImageType( (cast(CI->getOperand(0)))->getArgOperand(0)->getType(), &ImageTypeName)) - IsDepthImage = ImageTypeName.endswith("depth_t"); + IsDepthImage = ImageTypeName.contains("_depth_"); return mutateCallInstOCL( M, CI, [=](CallInst *, std::vector &Args, llvm::Type *&RetTy) { @@ -849,7 +855,7 @@ Instruction *SPIRVToLLVM::postProcessOCLReadImage(SPIRVInstruction *BI, T = VT->getElementType(); RetTy = IsDepthImage ? T : CI->getType(); return std::string(kOCLBuiltinName::SampledReadImage) + - (T->isFloatingPointTy() ? 'f' : 'i'); + getTypeSuffix(T); }, [=](CallInst *NewCI) -> Instruction * { if (IsDepthImage) @@ -882,8 +888,7 @@ SPIRVToLLVM::postProcessOCLWriteImage(SPIRVInstruction *BI, CallInst *CI, else std::swap(Args[2], Args[3]); } - return std::string(kOCLBuiltinName::WriteImage) + - (T->isFPOrFPVectorTy() ? 'f' : 'i'); + return std::string(kOCLBuiltinName::WriteImage) + getTypeSuffix(T); }, &Attrs); } @@ -940,10 +945,8 @@ Value *SPIRVToLLVM::mapValue(SPIRVValue *BV, Value *V) { "A value is translated twice"); // Replaces placeholders for PHI nodes LD->replaceAllUsesWith(V); - LD->dropAllReferences(); - LD->removeFromParent(); - Placeholder->dropAllReferences(); - Placeholder->removeFromParent(); + LD->eraseFromParent(); + Placeholder->eraseFromParent(); } ValueMap[BV] = V; return V; @@ -1006,11 +1009,20 @@ void SPIRVToLLVM::transGeneratorMD() { .done(); } -Value *SPIRVToLLVM::oclTransConstantSampler(SPIRV::SPIRVConstantSampler *BCS) { +Value *SPIRVToLLVM::oclTransConstantSampler(SPIRV::SPIRVConstantSampler *BCS, + BasicBlock *BB) { + auto *SamplerT = + getOrCreateOpaquePtrType(M, OCLOpaqueTypeOpCodeMap::rmap(OpTypeSampler), + getOCLOpaqueTypeAddrSpace(BCS->getOpCode())); + auto *I32Ty = IntegerType::getInt32Ty(*Context); + auto *FTy = FunctionType::get(SamplerT, {I32Ty}, false); + + FunctionCallee Func = M->getOrInsertFunction(SAMPLER_INIT, FTy); + auto Lit = (BCS->getAddrMode() << 1) | BCS->getNormalized() | ((BCS->getFilterMode() + 1) << 4); - auto Ty = IntegerType::getInt32Ty(*Context); - return ConstantInt::get(Ty, Lit); + + return CallInst::Create(Func, {ConstantInt::get(I32Ty, Lit)}, "", BB); } Value *SPIRVToLLVM::oclTransConstantPipeStorage( @@ -1146,7 +1158,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F, case OpConstantSampler: { auto BCS = static_cast(BV); - return mapValue(BV, oclTransConstantSampler(BCS)); + return mapValue(BV, oclTransConstantSampler(BCS, BB)); } case OpConstantPipeStorage: { @@ -1667,10 +1679,6 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F, return mapValue( BV, transSPIRVBuiltinFromInst(static_cast(BV), BB)); } - - SPIRVDBG(spvdbgs() << "Cannot translate " << *BV << '\n';) - llvm_unreachable("Translation of SPIRV instruction not implemented"); - return NULL; } } @@ -2066,8 +2074,14 @@ std::string SPIRVToLLVM::getOCLBuiltinName(SPIRVInstruction *BI) { } if (T && T->isTypeVector()) T = T->getVectorComponentType(); - if (T) - Name += T->isTypeFloat() ? 'f' : 'i'; + if (T) { + if (T->isTypeFloat(16)) + Name += 'h'; + else if (T->isTypeFloat(32)) + Name += 'f'; + else + Name += 'i'; + } return Name; } @@ -2232,11 +2246,27 @@ static bool transKernelArgTypeMedataFromString(LLVMContext *Ctx, std::string ArgTypeStr = (*ArgTypeStrIt)->getStr().substr(ArgTypePrefix.size()); std::vector TypeMDs; - std::string::size_type Start = 0, End = 0; - while ((Start = ArgTypeStr.find(',', End)) != std::string::npos) { - TypeMDs.push_back(MDString::get(*Ctx, ArgTypeStr.substr(End, Start - End))); - End = ++Start; + + int CountBraces = 0; + std::string::size_type Start = 0; + + for (std::string::size_type I = 0; I < ArgTypeStr.length(); I++) { + switch (ArgTypeStr[I]) { + case '<': + CountBraces++; + break; + case '>': + CountBraces--; + break; + case ',': + if (CountBraces == 0) { + TypeMDs.push_back( + MDString::get(*Ctx, ArgTypeStr.substr(Start, I - Start))); + Start = I + 1; + } + } } + Kernel->setMetadata(SPIR_MD_KERNEL_ARG_TYPE, MDNode::get(*Ctx, TypeMDs)); return true; } @@ -2508,6 +2538,7 @@ CallInst *SPIRVToLLVM::transOCLBarrier(BasicBlock *BB, SPIRVWord ExecScope, Func->setCallingConv(CallingConv::SPIR_FUNC); if (isFuncNoUnwind()) Func->addFnAttr(Attribute::NoUnwind); + Func->addFnAttr(Attribute::NoDuplicate); } return CallInst::Create(Func, Arg, "", BB); diff --git a/llvm-spirv/lib/SPIRV/SPIRVReader.h b/llvm-spirv/lib/SPIRV/SPIRVReader.h index 1cc16ce403014..23f2394db7ff4 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVReader.h +++ b/llvm-spirv/lib/SPIRV/SPIRVReader.h @@ -242,7 +242,8 @@ class SPIRVToLLVM { std::string transOCLImageTypeAccessQualifier(SPIRV::SPIRVTypeImage *ST); std::string transOCLPipeTypeAccessQualifier(SPIRV::SPIRVTypePipe *ST); - Value *oclTransConstantSampler(SPIRV::SPIRVConstantSampler *BCS); + Value *oclTransConstantSampler(SPIRV::SPIRVConstantSampler *BCS, + BasicBlock *BB); Value *oclTransConstantPipeStorage(SPIRV::SPIRVConstantPipeStorage *BCPS); void setName(llvm::Value *V, SPIRVValue *BV); void setLLVMLoopMetadata(SPIRVLoopMerge *LM, BranchInst *BI); diff --git a/llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.cpp b/llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.cpp index 84f7492855e89..7df4e894668f0 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.cpp @@ -52,7 +52,6 @@ #include "llvm/PassSupport.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" #include diff --git a/llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp b/llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp index a1a5d1975e04d..9b8bb748d5290 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp @@ -91,6 +91,10 @@ StringRef SPIRVToLLVMDbgTran::getString(const SPIRVId Id) { } void SPIRVToLLVMDbgTran::transDbgInfo(const SPIRVValue *SV, Value *V) { + // A constant sampler does not have a corresponding SPIRVInstruction. + if (SV->getOpCode() == OpConstantSampler) + return; + if (Instruction *I = dyn_cast(V)) { const SPIRVInstruction *SI = static_cast(SV); I->setDebugLoc(transDebugScope(SI)); diff --git a/llvm-spirv/lib/SPIRV/SPIRVToOCL20.cpp b/llvm-spirv/lib/SPIRV/SPIRVToOCL20.cpp index 273b88ed7656f..ccce0b075b8f9 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVToOCL20.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVToOCL20.cpp @@ -48,7 +48,6 @@ #include "llvm/PassSupport.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" #include diff --git a/llvm-spirv/lib/SPIRV/SPIRVUtil.cpp b/llvm-spirv/lib/SPIRV/SPIRVUtil.cpp index efa8bf7a76f94..97279cb6efbcc 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVUtil.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVUtil.cpp @@ -56,7 +56,6 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ToolOutputFile.h" -#include "llvm/Support/raw_ostream.h" #include #include @@ -627,6 +626,7 @@ CallInst *mutateCallInst( } auto NewCI = addCallInst(M, NewName, CI->getType(), Args, Attrs, CI, Mangle, InstName, TakeFuncName); + NewCI->setDebugLoc(CI->getDebugLoc()); LLVM_DEBUG(dbgs() << " => " << *NewCI << '\n'); CI->replaceAllUsesWith(NewCI); CI->eraseFromParent(); @@ -653,6 +653,7 @@ Instruction *mutateCallInst( InstName + ".tmp", TakeFuncName); auto NewI = RetMutate(NewCI); NewI->takeName(CI); + NewI->setDebugLoc(CI->getDebugLoc()); LLVM_DEBUG(dbgs() << " => " << *NewI << '\n'); CI->replaceAllUsesWith(NewI); CI->eraseFromParent(); @@ -914,22 +915,54 @@ bool isDecoratedSPIRVFunc(const Function *F, std::string *UndecoratedName) { /// Get TypePrimitiveEnum for special OpenCL type except opencl.block. SPIR::TypePrimitiveEnum getOCLTypePrimitiveEnum(StringRef TyName) { return StringSwitch(TyName) - .Case("opencl.image1d_t", SPIR::PRIMITIVE_IMAGE_1D_T) - .Case("opencl.image1d_array_t", SPIR::PRIMITIVE_IMAGE_1D_ARRAY_T) - .Case("opencl.image1d_buffer_t", SPIR::PRIMITIVE_IMAGE_1D_BUFFER_T) - .Case("opencl.image2d_t", SPIR::PRIMITIVE_IMAGE_2D_T) - .Case("opencl.image2d_array_t", SPIR::PRIMITIVE_IMAGE_2D_ARRAY_T) - .Case("opencl.image3d_t", SPIR::PRIMITIVE_IMAGE_3D_T) - .Case("opencl.image2d_msaa_t", SPIR::PRIMITIVE_IMAGE_2D_MSAA_T) - .Case("opencl.image2d_array_msaa_t", - SPIR::PRIMITIVE_IMAGE_2D_ARRAY_MSAA_T) - .Case("opencl.image2d_msaa_depth_t", - SPIR::PRIMITIVE_IMAGE_2D_MSAA_DEPTH_T) - .Case("opencl.image2d_array_msaa_depth_t", - SPIR::PRIMITIVE_IMAGE_2D_ARRAY_MSAA_DEPTH_T) - .Case("opencl.image2d_depth_t", SPIR::PRIMITIVE_IMAGE_2D_DEPTH_T) - .Case("opencl.image2d_array_depth_t", - SPIR::PRIMITIVE_IMAGE_2D_ARRAY_DEPTH_T) + .Case("opencl.image1d_ro_t", SPIR::PRIMITIVE_IMAGE1D_RO_T) + .Case("opencl.image1d_array_ro_t", SPIR::PRIMITIVE_IMAGE1D_ARRAY_RO_T) + .Case("opencl.image1d_buffer_ro_t", SPIR::PRIMITIVE_IMAGE1D_BUFFER_RO_T) + .Case("opencl.image2d_ro_t", SPIR::PRIMITIVE_IMAGE2D_RO_T) + .Case("opencl.image2d_array_ro_t", SPIR::PRIMITIVE_IMAGE2D_ARRAY_RO_T) + .Case("opencl.image2d_depth_ro_t", SPIR::PRIMITIVE_IMAGE2D_DEPTH_RO_T) + .Case("opencl.image2d_array_depth_ro_t", + SPIR::PRIMITIVE_IMAGE2D_ARRAY_DEPTH_RO_T) + .Case("opencl.image2d_msaa_ro_t", SPIR::PRIMITIVE_IMAGE2D_MSAA_RO_T) + .Case("opencl.image2d_array_msaa_ro_t", + SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_RO_T) + .Case("opencl.image2d_msaa_depth_ro_t", + SPIR::PRIMITIVE_IMAGE2D_MSAA_DEPTH_RO_T) + .Case("opencl.image2d_array_msaa_depth_ro_t", + SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_RO_T) + .Case("opencl.image3d_ro_t", SPIR::PRIMITIVE_IMAGE3D_RO_T) + .Case("opencl.image1d_wo_t", SPIR::PRIMITIVE_IMAGE1D_WO_T) + .Case("opencl.image1d_array_wo_t", SPIR::PRIMITIVE_IMAGE1D_ARRAY_WO_T) + .Case("opencl.image1d_buffer_wo_t", SPIR::PRIMITIVE_IMAGE1D_BUFFER_WO_T) + .Case("opencl.image2d_wo_t", SPIR::PRIMITIVE_IMAGE2D_WO_T) + .Case("opencl.image2d_array_wo_t", SPIR::PRIMITIVE_IMAGE2D_ARRAY_WO_T) + .Case("opencl.image2d_depth_wo_t", SPIR::PRIMITIVE_IMAGE2D_DEPTH_WO_T) + .Case("opencl.image2d_array_depth_wo_t", + SPIR::PRIMITIVE_IMAGE2D_ARRAY_DEPTH_WO_T) + .Case("opencl.image2d_msaa_wo_t", SPIR::PRIMITIVE_IMAGE2D_MSAA_WO_T) + .Case("opencl.image2d_array_msaa_wo_t", + SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_WO_T) + .Case("opencl.image2d_msaa_depth_wo_t", + SPIR::PRIMITIVE_IMAGE2D_MSAA_DEPTH_WO_T) + .Case("opencl.image2d_array_msaa_depth_wo_t", + SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_WO_T) + .Case("opencl.image3d_wo_t", SPIR::PRIMITIVE_IMAGE3D_WO_T) + .Case("opencl.image1d_rw_t", SPIR::PRIMITIVE_IMAGE1D_RW_T) + .Case("opencl.image1d_array_rw_t", SPIR::PRIMITIVE_IMAGE1D_ARRAY_RW_T) + .Case("opencl.image1d_buffer_rw_t", SPIR::PRIMITIVE_IMAGE1D_BUFFER_RW_T) + .Case("opencl.image2d_rw_t", SPIR::PRIMITIVE_IMAGE2D_RW_T) + .Case("opencl.image2d_array_rw_t", SPIR::PRIMITIVE_IMAGE2D_ARRAY_RW_T) + .Case("opencl.image2d_depth_rw_t", SPIR::PRIMITIVE_IMAGE2D_DEPTH_RW_T) + .Case("opencl.image2d_array_depth_rw_t", + SPIR::PRIMITIVE_IMAGE2D_ARRAY_DEPTH_RW_T) + .Case("opencl.image2d_msaa_rw_t", SPIR::PRIMITIVE_IMAGE2D_MSAA_RW_T) + .Case("opencl.image2d_array_msaa_rw_t", + SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_RW_T) + .Case("opencl.image2d_msaa_depth_rw_t", + SPIR::PRIMITIVE_IMAGE2D_MSAA_DEPTH_RW_T) + .Case("opencl.image2d_array_msaa_depth_rw_t", + SPIR::PRIMITIVE_IMAGE2D_ARRAY_MSAA_DEPTH_RW_T) + .Case("opencl.image3d_rw_t", SPIR::PRIMITIVE_IMAGE3D_RW_T) .Case("opencl.event_t", SPIR::PRIMITIVE_EVENT_T) .Case("opencl.pipe_ro_t", SPIR::PRIMITIVE_PIPE_RO_T) .Case("opencl.pipe_wo_t", SPIR::PRIMITIVE_PIPE_WO_T) @@ -1028,9 +1061,7 @@ static SPIR::RefParamType transTypeDesc(Type *Ty, } else if (auto StructTy = dyn_cast(ET)) { LLVM_DEBUG(dbgs() << "ptr to struct: " << *Ty << '\n'); auto TyName = StructTy->getStructName(); - if (TyName.startswith(kSPR2TypeName::ImagePrefix) || - TyName.startswith(kSPR2TypeName::PipeRO) || - TyName.startswith(kSPR2TypeName::PipeWO)) { + if (TyName.startswith(kSPR2TypeName::OCLPrefix)) { auto DelimPos = TyName.find_first_of(kSPR2TypeName::Delimiter, strlen(kSPR2TypeName::OCLPrefix)); if (DelimPos != StringRef::npos) diff --git a/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp b/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp index fdba9d97cbde4..748088fedb74a 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp @@ -55,9 +55,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SetVector.h" -#include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" -#include "llvm/Bitcode/BitcodeWriter.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DerivedTypes.h" @@ -75,8 +73,6 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ToolOutputFile.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Utils.h" // loop-simplify pass #include @@ -738,9 +734,12 @@ SPIRVValue *LLVMToSPIRV::transValueWithoutDecoration(Value *V, } Inst->dropAllReferences(); } + // Translate initializer first. + SPIRVValue *BVarInit = + (Init && !isa(Init)) ? transValue(Init, nullptr) : nullptr; + auto BVar = static_cast(BM->addVariable( - transType(Ty), GV->isConstant(), transLinkageType(GV), - (Init && !isa(Init)) ? transValue(Init, nullptr) : nullptr, + transType(Ty), GV->isConstant(), transLinkageType(GV), BVarInit, GV->getName(), SPIRSPIRVAddrSpaceMap::map( static_cast(Ty->getAddressSpace())), @@ -1125,6 +1124,7 @@ SPIRVValue *LLVMToSPIRV::transIntrinsicInst(IntrinsicInst *II, // For llvm.fmuladd.* fusion is not guaranteed. If a fused multiply-add // is required the corresponding llvm.fma.* intrinsic function should be // used instead. + BB->getParent()->setContractedFMulAddFound(); SPIRVType *Ty = transType(II->getType()); SPIRVValue *Mul = BM->addBinaryInst(OpFMul, Ty, transValue(II->getArgOperand(0), BB), @@ -1330,7 +1330,7 @@ void LLVMToSPIRV::mutateFuncArgType( } void LLVMToSPIRV::transFunction(Function *I) { - transFunctionDecl(I); + SPIRVFunction *BF = transFunctionDecl(I); // Creating all basic blocks before creating any instruction. for (auto &FI : *I) { transValue(&FI, nullptr); @@ -1342,6 +1342,12 @@ void LLVMToSPIRV::transFunction(Function *I) { transValue(&BI, BB, false); } } + + if (BF->getModule()->isEntryPoint(spv::ExecutionModelKernel, BF->getId()) && + BF->shouldFPContractBeDisabled()) { + BF->addExecutionMode(BF->getModule()->add( + new SPIRVExecutionMode(BF, spv::ExecutionModeContractionOff))); + } } bool LLVMToSPIRV::translate() { @@ -1689,7 +1695,7 @@ void addPassesForSPIRV(legacy::PassManager &PassMgr) { PassMgr.add(createSPIRVLowerMemmove()); } -bool llvm::writeSpirv(Module *M, llvm::raw_ostream &OS, std::string &ErrMsg) { +bool llvm::writeSpirv(Module *M, std::ostream &OS, std::string &ErrMsg) { std::unique_ptr BM(SPIRVModule::createSPIRVModule()); legacy::PassManager PassMgr; addPassesForSPIRV(PassMgr); diff --git a/llvm-spirv/lib/SPIRV/SPIRVWriterPass.cpp b/llvm-spirv/lib/SPIRV/SPIRVWriterPass.cpp index 56ed29daf5c6e..ffd0676045e41 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVWriterPass.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVWriterPass.cpp @@ -27,10 +27,10 @@ PreservedAnalyses SPIRVWriterPass::run(Module &M) { namespace { class WriteSPIRVPass : public ModulePass { - raw_ostream &OS; // raw_ostream to print on + std::ostream &OS; // std::ostream to print on public: static char ID; // Pass identification, replacement for typeid - explicit WriteSPIRVPass(raw_ostream &O) : ModulePass(ID), OS(O) {} + explicit WriteSPIRVPass(std::ostream &O) : ModulePass(ID), OS(O) {} StringRef getPassName() const override { return "SPIRV Writer"; } @@ -45,6 +45,6 @@ class WriteSPIRVPass : public ModulePass { char WriteSPIRVPass::ID = 0; -ModulePass *llvm::createSPIRVWriterPass(raw_ostream &Str) { +ModulePass *llvm::createSPIRVWriterPass(std::ostream &Str) { return new WriteSPIRVPass(Str); } diff --git a/llvm-spirv/lib/SPIRV/SPIRVWriterPass.h b/llvm-spirv/lib/SPIRV/SPIRVWriterPass.h index 5fab0a07a0c2b..b8005486bbaad 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVWriterPass.h +++ b/llvm-spirv/lib/SPIRV/SPIRVWriterPass.h @@ -20,24 +20,23 @@ namespace llvm { class Module; class ModulePass; -class raw_ostream; class PreservedAnalyses; /// \brief Create and return a pass that writes the module to the specified /// ostream. Note that this pass is designed for use with the legacy pass /// manager. -ModulePass *createSPIRVWriterPass(raw_ostream &Str); +ModulePass *createSPIRVWriterPass(std::ostream &Str); /// \brief Pass for writing a module of IR out to a SPIRV file. /// /// Note that this is intended for use with the new pass manager. To construct /// a pass for the legacy pass manager, use the function above. class SPIRVWriterPass { - raw_ostream &OS; + std::ostream &OS; public: /// \brief Construct a SPIRV writer pass around a particular output stream. - explicit SPIRVWriterPass(raw_ostream &OS) : OS(OS) {} + explicit SPIRVWriterPass(std::ostream &OS) : OS(OS) {} /// \brief Run the SPIRV writer pass, and output the module to the selected /// output stream. diff --git a/llvm-spirv/lib/SPIRV/TransOCLMD.cpp b/llvm-spirv/lib/SPIRV/TransOCLMD.cpp index 3dc303e1408de..b03f2333ae73b 100644 --- a/llvm-spirv/lib/SPIRV/TransOCLMD.cpp +++ b/llvm-spirv/lib/SPIRV/TransOCLMD.cpp @@ -50,7 +50,6 @@ #include "llvm/PassSupport.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace SPIRV; diff --git a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRV.debug.h b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRV.debug.h index 0c3d5a9d4641b..e2c07eed47c81 100644 --- a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRV.debug.h +++ b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRV.debug.h @@ -431,8 +431,8 @@ enum { }; static std::map OpCountMap { { Deref, 1 }, - { Plus, 2 }, - { Minus, 2 }, + { Plus, 1 }, + { Minus, 1 }, { PlusUconst, 2 }, { BitPiece, 3 }, { Swap, 1 }, diff --git a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDebug.h b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDebug.h index 7dc91d8b1d775..67cd224bd0c2c 100644 --- a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDebug.h +++ b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDebug.h @@ -41,9 +41,6 @@ #define SPIRV_LIBSPIRV_SPIRVDEBUG_H #include "SPIRVUtil.h" -#ifdef _SPIRV_LLVM_API -#include "llvm/Support/Debug.h" -#endif #include namespace SPIRV { @@ -67,11 +64,7 @@ extern bool SPIRVDbgAssertOnError; // Output stream for SPIRV debug information. inline spv_ostream &spvdbgs() { -#ifdef _SPIRV_LLVM_API - return llvm::dbgs(); -#else return std::cerr; -#endif } #else diff --git a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVFunction.h b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVFunction.h index d4af0729fa705..aebe969b42e83 100644 --- a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVFunction.h +++ b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVFunction.h @@ -135,6 +135,22 @@ class SPIRVFunction : public SPIRVValue, public SPIRVComponentExecutionModes { assert(FuncType && "Invalid func type"); } + bool shouldFPContractBeDisabled() const { + // We could find some instructions in LLVM IR which look exactly like an + // unfused fmuladd. So, we assume that FP_CONTRACT was disabled only if + // there are something that looks like uncointracted fmul + fadd, but there + // no calls to @llvm.fmuladd.* + return FoundUncontractedFMulAdd && !FoundContractedFMulAdd; + } + + void setUncontractedFMulAddFound(bool Value = true) { + FoundUncontractedFMulAdd = Value; + } + + void setContractedFMulAddFound(bool Value = true) { + FoundContractedFMulAdd = Value; + } + private: SPIRVFunctionParameter *addArgument(unsigned TheArgNo, SPIRVId TheId) { SPIRVFunctionParameter *Arg = new SPIRVFunctionParameter( @@ -156,6 +172,9 @@ class SPIRVFunction : public SPIRVValue, public SPIRVComponentExecutionModes { std::vector Parameters; typedef std::vector SPIRVLBasicBlockVector; SPIRVLBasicBlockVector BBVec; + + bool FoundUncontractedFMulAdd = false; + bool FoundContractedFMulAdd = false; }; typedef SPIRVEntryOpCodeOnly SPIRVFunctionEnd; diff --git a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVModule.cpp b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVModule.cpp index dcabd0ca06cc0..b5137ab91b02d 100644 --- a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVModule.cpp +++ b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVModule.cpp @@ -61,7 +61,7 @@ SPIRVModule::~SPIRVModule() {} class SPIRVModuleImpl : public SPIRVModule { public: SPIRVModuleImpl() - : SPIRVModule(), NextId(1), BoolType(NULL), SPIRVVersion(SPIRV_1_0), + : SPIRVModule(), NextId(1), SPIRVVersion(SPIRV_1_0), GeneratorId(SPIRVGEN_KhronosLLVMSPIRVTranslator), GeneratorVer(0), InstSchema(SPIRVISCH_Default), SrcLang(SourceLanguageOpenCL_C), SrcLangVer(102000) { @@ -372,7 +372,6 @@ class SPIRVModuleImpl : public SPIRVModule { private: SPIRVErrorLog ErrLog; SPIRVId NextId; - SPIRVTypeInt *BoolType; SPIRVWord SPIRVVersion; unsigned short GeneratorId; unsigned short GeneratorVer; @@ -1636,7 +1635,7 @@ bool isSpirvBinary(const std::string &Img) { #ifdef _SPIRV_SUPPORT_TEXT_FMT -bool convertSpirv(std::istream &IS, spv_ostream &OS, std::string &ErrMsg, +bool convertSpirv(std::istream &IS, std::ostream &OS, std::string &ErrMsg, bool FromText, bool ToText) { auto SaveOpt = SPIRVUseTextFormat; SPIRVUseTextFormat = FromText; @@ -1673,11 +1672,7 @@ bool convertSpirv(std::string &Input, std::string &Out, std::string &ErrMsg, return true; } std::istringstream IS(Input); -#ifdef _SPIRV_LLVM_API - llvm::raw_string_ostream OS(Out); -#else std::ostringstream OS; -#endif if (!convertSpirv(IS, OS, ErrMsg, FromText, ToText)) return false; Out = OS.str(); diff --git a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVOpCode.h b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVOpCode.h index 2868be76c907b..e280b40f3f98d 100644 --- a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVOpCode.h +++ b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVOpCode.h @@ -106,7 +106,8 @@ inline bool isCvtFromUnsignedOpCode(Op OpCode) { } inline bool isOpaqueGenericTypeOpCode(Op OpCode) { - return (unsigned)OpCode >= OpTypeEvent && (unsigned)OpCode <= OpTypeQueue; + return ((unsigned)OpCode >= OpTypeEvent && (unsigned)OpCode <= OpTypeQueue) || + OpCode == OpTypeSampler; } inline bool isGenericNegateOpCode(Op OpCode) { diff --git a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVUtil.h b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVUtil.h index b324df7fcd67a..84485482e7bfb 100644 --- a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVUtil.h +++ b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVUtil.h @@ -40,13 +40,8 @@ #ifndef SPIRV_LIBSPIRV_SPIRVUTIL_H #define SPIRV_LIBSPIRV_SPIRVUTIL_H -#ifdef _SPIRV_LLVM_API -#include "llvm/Support/raw_ostream.h" -#define spv_ostream llvm::raw_ostream -#else #include #define spv_ostream std::ostream -#endif #include #include diff --git a/llvm-spirv/test/CMakeLists.txt b/llvm-spirv/test/CMakeLists.txt index 0a3bf623ed0f6..6c847194c3fd3 100644 --- a/llvm-spirv/test/CMakeLists.txt +++ b/llvm-spirv/test/CMakeLists.txt @@ -35,7 +35,6 @@ add_lit_testsuite(check-llvm-spirv "Running the LLVM-SPIRV regression tests" --verbose DEPENDS ${LLVM_SPIRV_TEST_DEPS} - llvm-config llvm-spirv ) diff --git a/llvm-spirv/test/ContractionOff.ll b/llvm-spirv/test/ContractionOff.ll index 716b750e5eddd..692e88d6a38ee 100644 --- a/llvm-spirv/test/ContractionOff.ll +++ b/llvm-spirv/test/ContractionOff.ll @@ -7,19 +7,28 @@ ; void kernel k2 (float a, float b, float c) { ; float d = a * b + c; ; } +; +; void kernel k3 (float a, float b, float c) { +; float d = a * b; // a * b together with -d in the next statement look +; float e = a * c - d; // exactly like an unfused fmuladd in LLVM IR +; } +; +; IR generated using the following commands: +; clang -cc1 -x cl -emit-llvm -O2 -disable-llvm-passes -triple spir64 1.cl -o 1.ll +; opt -mem2reg 1.ll -S -o 1.o.ll ; RUN: llvm-as < %s | llvm-spirv -spirv-text -o %t ; RUN: FileCheck < %t %s ; CHECK: EntryPoint 6 [[K1:[0-9]+]] "k1" ; CHECK: EntryPoint 6 [[K2:[0-9]+]] "k2" +; CHECK: EntryPoint 6 [[K3:[0-9]+]] "k3" ; CHECK: ExecutionMode [[K1]] 31 ; CHECK-NOT: ExecutionMode [[K2]] 31 +; CHECK-NOT: ExecutionMode [[K3]] 31 -;ModuleID = '' -source_filename = "/tmp/tmp.cl" -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" -target triple = "spir" +target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir64" ; Function Attrs: convergent nounwind define spir_kernel void @k1(float %a, float %b, float %c) #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 { @@ -39,7 +48,16 @@ entry: ; Function Attrs: nounwind readnone speculatable declare float @llvm.fmuladd.f32(float, float, float) #2 -attributes #0 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" } +; Function Attrs: convergent nounwind +define spir_kernel void @k3(float %a, float %b, float %c) #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 { +entry: + %mul = fmul float %a, %b + %neg = fsub float -0.000000e+00, %mul + %0 = call float @llvm.fmuladd.f32(float %a, float %c, float %neg) + ret void +} + +attributes #0 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #1 = { argmemonly nounwind } attributes #2 = { nounwind readnone speculatable } @@ -51,7 +69,7 @@ attributes #2 = { nounwind readnone speculatable } !0 = !{i32 1, !"wchar_size", i32 4} !1 = !{i32 1, i32 0} !2 = !{i32 1, i32 2} -!3 = !{!"clang version 8.0.0"} +!3 = !{!"clang version 7.0.1"} !4 = !{i32 0, i32 0, i32 0} !5 = !{!"none", !"none", !"none"} !6 = !{!"float", !"float", !"float"} diff --git a/llvm-spirv/test/DebugInfo/BuiltinCallLocation.ll b/llvm-spirv/test/DebugInfo/BuiltinCallLocation.ll new file mode 100644 index 0000000000000..d4e6b7ce099fe --- /dev/null +++ b/llvm-spirv/test/DebugInfo/BuiltinCallLocation.ll @@ -0,0 +1,54 @@ +; Check that DebugLoc attached to a builtin call is preserverd after translation. +; Source: +; float f(float x) { +; return sin(x); +; } +; Command to get this IR: +; clang -cc1 -triple spir -finclude-default-header /tmp/tmp.cl -disable-llvm-passes -emit-llvm -o - -debug-info-kind=line-tables-only | opt -mem2reg -S -o test/DebugInfo/BuiltinCallLocation.ll + +; RUN: llvm-as < %s > %t.bc +; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV +; RUN: llvm-spirv %t.bc -o %t.spv +; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-LLVM + +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" +target triple = "spir" + +; Function Attrs: convergent nounwind +define spir_func float @f(float %x) #0 !dbg !8 { +entry: +; CHECK-SPIRV: Label +; CHECK-SPIRV: ExtInst {{.*}} DebugScope +; CHECK-SPIRV: ExtInst {{.*}} sin + %call = call spir_func float @_Z3sinf(float %x) #2, !dbg !11 +; CHECK-LLVM: call spir_func float @_Z3sinf(float %x) {{.*}} !dbg ![[loc:[0-9]+]] + ret float %call, !dbg !12 +} + +; Function Attrs: convergent nounwind readnone +declare spir_func float @_Z3sinf(float) #1 + +attributes #0 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { convergent nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { convergent nounwind readnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} +!opencl.ocl.version = !{!5} +!opencl.spir.version = !{!6} +!llvm.ident = !{!7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "/tmp/", directory: "/llvm/build") +!2 = !{} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !{i32 1, !"wchar_size", i32 4} +!5 = !{i32 1, i32 0} +!6 = !{i32 1, i32 2} +!7 = !{!"clang version 8.0.0 "} +!8 = distinct !DISubprogram(name: "f", scope: !9, file: !9, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2) +!9 = !DIFile(filename: "/tmp/tmp.cl", directory: "/llvm/build") +!10 = !DISubroutineType(types: !2) +!11 = !DILocation(line: 2, column: 10, scope: !8) +;CHECK-LLVM: ![[loc]] = !DILocation(line: 2, column: 10, scope: !{{.*}}) +!12 = !DILocation(line: 2, column: 3, scope: !8) diff --git a/llvm-spirv/test/DebugInfo/DebugFunction.ll b/llvm-spirv/test/DebugInfo/DebugFunction.ll new file mode 100644 index 0000000000000..94bd46d2bea56 --- /dev/null +++ b/llvm-spirv/test/DebugInfo/DebugFunction.ll @@ -0,0 +1,79 @@ +; Check for 2 thigs: +; - After round trip translation function definition has !dbg metadata attached +; specifically if -gline-tables-only was used for Clang +; - Parent operand of DebugFunction is DebugCompileUnit, not an OpString, even +; if in LLVM IR it points to a DIFile instead of DICompileUnit. + +; Source: +; float foo(int i) { +; return i * 3.14; +; } +; void kernel k() { +; float a = foo(2); +; } +; Command: +; clang -x cl -cl-std=c++ -emit-llvm -target spir -gline-tables-only -O0 + +; RUN: llvm-as %s -o - | llvm-spirv -o %t.spv +; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV +; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-LLVM + +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" +target triple = "spir" + +; CHECK-SPIRV: String [[foo:[0-9]+]] "foo" +; CHECK-SPIRV: String [[k:[0-9]+]] "k" +; CHECK-SPIRV: [[CU:[0-9]+]] {{[0-9]+}} DebugCompileUnit +; CHECK-SPIRV: DebugFunction [[foo]] {{.*}} [[CU]] {{.*}} [[foo_id:[0-9]+]] {{[0-9]+}} {{$}} +; CHECK-SPIRV: DebugFunction [[k]] {{.*}} [[CU]] {{.*}} [[k_id:[0-9]+]] {{[0-9]+}} {{$}} + +; CHECK-SPIRV: Function {{[0-9]+}} [[foo_id]] +; CHECK-LLVM: define spir_func float @_Z3fooi(i32) #{{[0-9]+}} !dbg !{{[0-9]+}} { +define dso_local spir_func float @_Z3fooi(i32) #0 !dbg !9 { + %2 = alloca i32, align 4 + store i32 %0, i32* %2, align 4 + %3 = load i32, i32* %2, align 4, !dbg !12 + %4 = sitofp i32 %3 to double, !dbg !12 + %5 = fmul double %4, 3.140000e+00, !dbg !13 + %6 = fptrunc double %5 to float, !dbg !12 + ret float %6, !dbg !14 +} + +; CHECK-SPIRV: Function {{[0-9]+}} [[k_id]] +; CHECK-LLVM: define spir_kernel void @_Z1kv() #{{[0-9]+}} !dbg !{{[0-9]+}} +define dso_local spir_kernel void @_Z1kv() #1 !dbg !15 !kernel_arg_addr_space !2 !kernel_arg_access_qual !2 !kernel_arg_type !2 !kernel_arg_base_type !2 !kernel_arg_type_qual !2 { + %1 = alloca float, align 4 + %2 = call spir_func float @_Z3fooi(i32 2) #2, !dbg !16 + store float %2, float* %1, align 4, !dbg !17 + ret void, !dbg !18 +} + +attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { convergent } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!opencl.ocl.version = !{!6} +!opencl.spir.version = !{!7} +!llvm.ident = !{!8} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 9.0.0 (trunk 354644)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "/tmp/compiler-explorer-compiler119127-62-o5mw53.ko2sg/example.cpp", directory: "/tmp/compiler-explorer-compiler119127-62-o5mw53.ko2sg") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{i32 0, i32 0} +!7 = !{i32 0, i32 2} +!8 = !{!"clang version 9.0.0 (trunk 354644)"} +!9 = distinct !DISubprogram(name: "foo", scope: !10, file: !10, line: 2, type: !11, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!10 = !DIFile(filename: "example.cpp", directory: "/tmp/compiler-explorer-compiler119127-62-o5mw53.ko2sg") +!11 = !DISubroutineType(types: !2) +!12 = !DILocation(line: 3, column: 12, scope: !9) +!13 = !DILocation(line: 3, column: 14, scope: !9) +!14 = !DILocation(line: 3, column: 5, scope: !9) +!15 = distinct !DISubprogram(name: "k", scope: !10, file: !10, line: 6, type: !11, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!16 = !DILocation(line: 7, column: 15, scope: !15) +!17 = !DILocation(line: 7, column: 11, scope: !15) +!18 = !DILocation(line: 8, column: 1, scope: !15) diff --git a/llvm-spirv/test/DebugInfo/UnknownBaseType.ll b/llvm-spirv/test/DebugInfo/UnknownBaseType.ll new file mode 100644 index 0000000000000..2a422ea38ad92 --- /dev/null +++ b/llvm-spirv/test/DebugInfo/UnknownBaseType.ll @@ -0,0 +1,52 @@ +; REQUIRES: object-emission + +; RUN: llvm-as < %s -o %t.bc +; RUN: llvm-spirv %t.bc -o %t.spv -spirv-mem2reg=false +; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o %t.ll + +; RUN: llc -mtriple=%triple < %t.ll -filetype=obj | llvm-dwarfdump -debug-info - | FileCheck %s + +; Check that translator doesn't crash when it encounter basic type encoding +; (e.g. DW_ATE_complex_float) which is missing in the spec. + +; CHECK: DW_TAG_unspecified_type +; CHECK-NEXT: DW_AT_name ("complex") + + +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" +target triple = "spir-unknown-unknown" + +; Function Attrs: convergent nounwind +define spir_func void @foo({ float, float }* byval align 4 %f) #0 !dbg !7 { +entry: + call void @llvm.dbg.declare(metadata { float, float }* %f, metadata !13, metadata !DIExpression()), !dbg !14 + ret void, !dbg !14 +} + +; Function Attrs: nounwind readnone speculatable +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +attributes #0 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone speculatable } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} +!opencl.ocl.version = !{!5} +!opencl.spir.version = !{!5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://llvm.org/git/clang 1b09e8845172eccc47c896f546fa30805da53d51) (https://llvm.org/git/llvm 384f64397f6ad95a361b72d62c07d7bac9f24163)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "", directory: "/tmp") +!2 = !{} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !{i32 1, !"wchar_size", i32 4} +!5 = !{i32 2, i32 0} +!6 = !{!"clang version 9.0.0"} +!7 = distinct !DISubprogram(name: "foo", scope: !8, file: !8, line: 1, type: !9, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12) +!8 = !DIFile(filename: "tmp.cl", directory: "/tmp") +!9 = !DISubroutineType(cc: DW_CC_LLVM_SpirFunction, types: !10) +!10 = !{null, !11} +!11 = !DIBasicType(name: "complex", size: 64, encoding: DW_ATE_complex_float) +!12 = !{!13} +!13 = !DILocalVariable(name: "f", arg: 1, scope: !7, file: !8, line: 1, type: !11) +!14 = !DILocation(line: 1, scope: !7) diff --git a/llvm-spirv/test/DebugInfo/X86/dw_op_minus_direct.ll b/llvm-spirv/test/DebugInfo/X86/dw_op_minus_direct.ll index e2d14039c28e7..82abcbdb19851 100644 --- a/llvm-spirv/test/DebugInfo/X86/dw_op_minus_direct.ll +++ b/llvm-spirv/test/DebugInfo/X86/dw_op_minus_direct.ll @@ -21,7 +21,7 @@ ; CHECK: .debug_loc contents: ; CHECK: 0x00000000: -; CHECK-NEXT: [0x0000000000000000, 0x0000000000000004): DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_lit1, DW_OP_minus, DW_OP_stack_value +; CHECK-NEXT: [0x0000000000000003, 0x0000000000000004): DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_lit1, DW_OP_minus, DW_OP_stack_value ; rax+0, constu 0xffffffff, and, constu 0x00000001, minus, stack-value source_filename = "minus.c" diff --git a/llvm-spirv/test/KernelArgTypeInOpString2.ll b/llvm-spirv/test/KernelArgTypeInOpString2.ll new file mode 100644 index 0000000000000..e3ca5f4c9c8ed --- /dev/null +++ b/llvm-spirv/test/KernelArgTypeInOpString2.ll @@ -0,0 +1,70 @@ +; Source: +; +; class cl { +; public: +; class tt { +; public: +; template +; class vec { +; public: +; T var[size]; +; }; +; }; +; }; +; void kernel foo(__global cl::tt::vec *in) +; { +; in->var[0] = 0.; +; } + + +; In LLVM -> SPIRV translation original names of types (typedefs) are missed, +; there is no defined possibility to keep a typedef name by SPIR-V spec. +; As a workaround we store original names in OpString instruction: +; OpString "kernel_arg_type.%kernel_name%.typename0,typename1,..." + +; RUN: llvm-as %s -o %t.bc +; RUN: llvm-spirv %t.bc -spirv-text -o %t.spv.txt +; RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV +; RUN: llvm-spirv %t.bc -o %t.spv +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc +; RUN: llvm-dis %t.rev.bc +; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM + +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" +target triple = "spir" + +; CHECK-SPIRV: String 17 "kernel_arg_type.foo.cl::tt::vec*," + +; CHECK-LLVM: !kernel_arg_type [[TYPE:![0-9]+]] +; CHECK-LLVM: [[TYPE]] = !{!"cl::tt::vec*"} + +%"class.cl::tt::vec" = type { [4 x float] } + +; Function Attrs: convergent noinline nounwind optnone + +define dso_local spir_kernel void @foo(%"class.cl::tt::vec" addrspace(1)* nocapture) local_unnamed_addr #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 { + %2 = getelementptr inbounds %"class.cl::tt::vec", %"class.cl::tt::vec" addrspace(1)* %0, i32 0, i32 0, i32 0 + store float 0.000000e+00, float addrspace(1)* %2, align 4, !tbaa !8 + ret void +} + +attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.module.flags = !{!0} +!opencl.ocl.version = !{!1} +!opencl.spir.version = !{!2} +!llvm.ident = !{!3} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 0, i32 0} +!2 = !{i32 0, i32 2} +!3 = !{!"clang version 7.0.0"} +!4 = !{i32 1} +!5 = !{!"none"} +!6 = !{!"cl::tt::vec*"} +!7 = !{!""} +!8 = !{!9, !9, i64 0} +!9 = !{!"float", !10, i64 0} +!10 = !{!"omnipotent char", !11, i64 0} +!11 = !{!"Simple C++ TBAA"} + diff --git a/llvm-spirv/test/SampledImage.ll b/llvm-spirv/test/SampledImage.ll index a06094903c752..840df35fab99a 100644 --- a/llvm-spirv/test/SampledImage.ll +++ b/llvm-spirv/test/SampledImage.ll @@ -36,34 +36,34 @@ target triple = "spir-unknown-unknown" ; CHECK-SPIRV: Function {{.*}} [[sample_kernel]] ; CHECK-SPIRV: FunctionParameter {{.*}} [[InputImage:[0-9]+]] ; CHECK-SPIRV: FunctionParameter [[TypeSampler]] [[argSampl:[0-9]+]] -; CHECK-LLVM: define spir_kernel void @sample_kernel(%opencl.image2d_t addrspace(1)* %input, <2 x float> %coords, <4 x float> addrspace(1)* nocapture %results, i32 %argSampl) +; CHECK-LLVM: define spir_kernel void @sample_kernel(%opencl.image2d_ro_t addrspace(1)* %input, <2 x float> %coords, <4 x float> addrspace(1)* nocapture %results, %opencl.sampler_t* %argSampl) define spir_kernel void @sample_kernel(%opencl.image2d_ro_t addrspace(1)* %input, <2 x float> %coords, <4 x float> addrspace(1)* nocapture %results, %opencl.sampler_t addrspace(2)* %argSampl) local_unnamed_addr #0 !kernel_arg_addr_space !5 !kernel_arg_access_qual !6 !kernel_arg_type !7 !kernel_arg_base_type !8 !kernel_arg_type_qual !9 { entry: %0 = tail call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 32) #2 ; CHECK-SPIRV: SampledImage [[SampledImageTy]] [[SampledImage1:[0-9]+]] [[InputImage]] [[ConstSampler1]] ; CHECK-SPIRV: ImageSampleExplicitLod {{.*}} [[SampledImage1]] -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_f(%opencl.image2d_t addrspace(1)* %input, i32 32, <2 x float> %coords) +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)* %input, %opencl.sampler_t* %0, <2 x float> %coords) %call = tail call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)* %input, %opencl.sampler_t addrspace(2)* %0, <2 x float> %coords) #3 store <4 x float> %call, <4 x float> addrspace(1)* %results, align 16, !tbaa !12 ; CHECK-SPIRV: SampledImage [[SampledImageTy]] [[SampledImage2:[0-9]+]] [[InputImage]] [[argSampl]] ; CHECK-SPIRV: ImageSampleExplicitLod {{.*}} [[SampledImage2]] -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_f(%opencl.image2d_t addrspace(1)* %input, i32 %argSampl, <2 x float> %coords) +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)* %input, %opencl.sampler_t* %argSampl, <2 x float> %coords) %call1 = tail call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)* %input, %opencl.sampler_t addrspace(2)* %argSampl, <2 x float> %coords) #3 store <4 x float> %call1, <4 x float> addrspace(1)* %results, align 16, !tbaa !12 %1 = tail call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 22) #2 ; CHECK-SPIRV: SampledImage [[SampledImageTy]] [[SampledImage3:[0-9]+]] [[InputImage]] [[ConstSampler2]] ; CHECK-SPIRV: ImageSampleExplicitLod {{.*}} [[SampledImage3]] -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_f(%opencl.image2d_t addrspace(1)* %input, i32 22, <2 x float> %coords) +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)* %input, %opencl.sampler_t* %{{[0-9]+}}, <2 x float> %coords) %call2 = tail call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)* %input, %opencl.sampler_t addrspace(2)* %1, <2 x float> %coords) #3 store <4 x float> %call2, <4 x float> addrspace(1)* %results, align 16, !tbaa !12 ret void } ; Function Attrs: convergent nounwind readonly -; CHECK-LLVM: declare spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_f(%opencl.image2d_t addrspace(1)*, i32, <2 x float>) +; CHECK-LLVM: declare spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)*, %opencl.sampler_t*, <2 x float>) declare spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)*, %opencl.sampler_t addrspace(2)*, <2 x float>) local_unnamed_addr #1 declare %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32) local_unnamed_addr diff --git a/llvm-spirv/test/global_block.ll b/llvm-spirv/test/global_block.ll index d1ede654a4a17..efb4cf3c68b7c 100644 --- a/llvm-spirv/test/global_block.ll +++ b/llvm-spirv/test/global_block.ll @@ -16,84 +16,66 @@ ; RUN: llvm-spirv %t.bc -o %t.spv ; RUN: llvm-spirv -r %t.spv -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-LLVM -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-n8:16:32:64" +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" target triple = "spir-unknown-unknown" ; CHECK-SPIRV: Name [[block_invoke:[0-9]+]] "_block_invoke" ; CHECK-SPIRV: TypeInt [[int:[0-9]+]] 32 +; CHECK-SPIRV: TypeInt [[int8:[0-9]+]] 8 ; CHECK-SPIRV: Constant [[int]] [[five:[0-9]+]] 5 -; CHECK-SPIRV: TypeFunction [[block_invoke_type:[0-9]+]] [[int]] [[int]] -;; Check that block invoke function has no block descriptor argument in SPIR-V -; CHECK-SPIRV-NOT: TypeFunction [[block_invoke_type]] [[int]] {{[0-9]+}} [[int]] +; CHECK-SPIRV: TypePointer [[int8Ptr:[0-9]+]] 8 [[int8]] +; CHECK-SPIRV: TypeFunction [[block_invoke_type:[0-9]+]] [[int]] [[int8Ptr]] [[int]] -;; This variable is not needed in SPIRV -; CHECK-SPIRV-NOT: Name {{[0-9]+}} block_kernel.b1 -; CHECK-LLVM-NOT: @block_kernel.b1 -@block_kernel.b1 = internal addrspace(2) constant i32 (i32) addrspace(4)* addrspacecast (i32 (i32) addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* @__block_literal_global to i32 (i32) addrspace(1)*) to i32 (i32) addrspace(4)*), align 8 +%struct.__opencl_block_literal_generic = type { i32, i32, i8 addrspace(4)* } -@__block_literal_global = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }, align 4 +@block_kernel.b1 = internal addrspace(2) constant %struct.__opencl_block_literal_generic addrspace(4)* addrspacecast (%struct.__opencl_block_literal_generic addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global to %struct.__opencl_block_literal_generic addrspace(1)*) to %struct.__opencl_block_literal_generic addrspace(4)*), align 4 +@__block_literal_global = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 12, i32 4, i8 addrspace(4)* addrspacecast (i8* bitcast (i32 (i8 addrspace(4)*, i32)* @_block_invoke to i8*) to i8 addrspace(4)*) }, align 4 -; Function Attrs: convergent nounwind -define spir_kernel void @block_kernel(i32 addrspace(1)* %res) #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 { +; Function Attrs: convergent noinline nounwind optnone +define spir_kernel void @block_kernel(i32 addrspace(1)* %res) #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !4 !kernel_arg_type !5 !kernel_arg_base_type !5 !kernel_arg_type_qual !6 { entry: - %res.addr = alloca i32 addrspace(1)*, align 8 - store i32 addrspace(1)* %res, i32 addrspace(1)** %res.addr, align 8, !tbaa !10 - -; CHECK-SPIRV: FunctionCall [[int]] {{[0-9]+}} [[block_invoke]] [[five]] -; CHECK-LLVM: %call = call spir_func i32 @_block_invoke(i32 5) - %call = call spir_func i32 @_block_invoke(i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* @__block_literal_global to i8 addrspace(1)*) to i8 addrspace(4)*), i32 5) #2 - - %0 = load i32 addrspace(1)*, i32 addrspace(1)** %res.addr, align 8, !tbaa !10 - store i32 %call, i32 addrspace(1)* %0, align 4, !tbaa !14 + %res.addr = alloca i32 addrspace(1)*, align 4 + store i32 addrspace(1)* %res, i32 addrspace(1)** %res.addr, align 4 +; CHECK-SPIRV: FunctionCall [[int]] {{[0-9]+}} [[block_invoke]] {{[0-9]+}} [[five]] +; CHECK-LLVM: %call = call spir_func i32 @_block_invoke(i8 addrspace(4)* {{.*}}, i32 5) + %call = call spir_func i32 @_block_invoke(i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global to i8 addrspace(1)*) to i8 addrspace(4)*), i32 5) #2 + %0 = load i32 addrspace(1)*, i32 addrspace(1)** %res.addr, align 4 + store i32 %call, i32 addrspace(1)* %0, align 4 ret void } -; CHECK-SPIRV: 5 Function [[int]] [[block_invoke]] 0 [[block_invoke_type]] +; CHECK-SPIRV: 5 Function [[int]] [[block_invoke]] 2 [[block_invoke_type]] +; CHECK-SPIRV-NEXT: 3 FunctionParameter [[int8Ptr]] {{[0-9]+}} ; CHECK-SPIRV-NEXT: 3 FunctionParameter [[int]] {{[0-9]+}} -; CHECK-LLVM: define internal spir_func i32 @_block_invoke(i32 %i) -; Function Attrs: convergent nounwind +; CHECK-LLVM: define internal spir_func i32 @_block_invoke(i8 addrspace(4)* {{.*}}, i32 %{{.*}}) +; Function Attrs: convergent noinline nounwind optnone define internal spir_func i32 @_block_invoke(i8 addrspace(4)* %.block_descriptor, i32 %i) #1 { entry: - %.block_descriptor.addr = alloca i8 addrspace(4)*, align 8 + %.block_descriptor.addr = alloca i8 addrspace(4)*, align 4 %i.addr = alloca i32, align 4 - store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 8 - -;; Instruction below is useless and should be removed. -; CHECK-SPIRV-NOT: Bitcast -; CHECK-LLVM-NOT: bitcast - %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32 }> addrspace(4)* - store i32 %i, i32* %i.addr, align 4, !tbaa !14 - %0 = load i32, i32* %i.addr, align 4, !tbaa !14 + %block.addr = alloca <{ i32, i32, i8 addrspace(4)* }> addrspace(4)*, align 4 + store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 4 + %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* + store i32 %i, i32* %i.addr, align 4 + store <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* %block, <{ i32, i32, i8 addrspace(4)* }> addrspace(4)** %block.addr, align 4 + %0 = load i32, i32* %i.addr, align 4 %add = add nsw i32 %0, 1 ret i32 %add } -attributes #0 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } -attributes #1 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #2 = { convergent } !llvm.module.flags = !{!0} -!opencl.enable.FP_CONTRACT = !{} !opencl.ocl.version = !{!1} !opencl.spir.version = !{!1} -!opencl.used.extensions = !{!2} -!opencl.used.optional.core.features = !{!2} -!opencl.compiler.options = !{!2} -!llvm.ident = !{!3} +!llvm.ident = !{!2} !0 = !{i32 1, !"wchar_size", i32 4} !1 = !{i32 2, i32 0} -!2 = !{} -!3 = !{!"clang version 7.0.0"} -!4 = !{i32 1} -!5 = !{!"none"} -!6 = !{!"int*"} -!7 = !{!""} -!8 = !{i1 false} -!9 = !{i32 0} -!10 = !{!11, !11, i64 0} -!11 = !{!"any pointer", !12, i64 0} -!12 = !{!"omnipotent char", !13, i64 0} -!13 = !{!"Simple C/C++ TBAA"} -!14 = !{!15, !15, i64 0} -!15 = !{!"int", !12, i64 0} +!2 = !{!"clang version 9.0.0 (https://llvm.org/git/clang 04fb8964a801a5c5d7baa5a22272243a7d183896) (https://llvm.org/git/llvm 384f64397f6ad95a361b72d62c07d7bac9f24163)"} +!3 = !{i32 1} +!4 = !{!"none"} +!5 = !{!"int*"} +!6 = !{!""} diff --git a/llvm-spirv/test/image_without_access_qualifier.spt b/llvm-spirv/test/image_without_access_qualifier.spt index 98c9dbf34bcf9..331c3df89e05f 100644 --- a/llvm-spirv/test/image_without_access_qualifier.spt +++ b/llvm-spirv/test/image_without_access_qualifier.spt @@ -68,5 +68,5 @@ ; RUN: llvm-spirv -r %t.spv -o %t.bc ; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-LLVM -; CHECK-LLVM: %opencl.image2d_t = type opaque +; CHECK-LLVM: %opencl.image2d_ro_t = type opaque ; CHECK-LLVM: !{{[0-9]*}} = !{!"read_only", !"none", !"none"} diff --git a/llvm-spirv/test/literal-struct.ll b/llvm-spirv/test/literal-struct.ll index c52170a5e7f6c..52a731a57d794 100644 --- a/llvm-spirv/test/literal-struct.ll +++ b/llvm-spirv/test/literal-struct.ll @@ -2,7 +2,7 @@ ; structs, i.e. structs whose type has no name. Typicaly clang generate such ; structs if the kernel contains OpenCL 2.0 blocks. The IR was produced with ; the following command: -; clang -cc1 -triple spir -cl-std=cl2.0 -O0 -finclude-default-header literal-struct.cl -emit-llvm -o test/literal-struct.ll +; clang -cc1 -triple spir -cl-std=cl2.0 -O0 literal-struct.cl -emit-llvm -o test/literal-struct.ll ; literal-struct.cl: ; void foo() @@ -14,25 +14,28 @@ ; RUN: llvm-as < %s | llvm-spirv -spirv-text -o %t ; RUN: FileCheck < %t %s -; CHECK-DAG: TypeInt [[Int:[0-9]+]] 32 0 -; CHECK-DAG: TypeStruct [[StructType:[0-9]+]] [[Int]] [[Int]] {{$}} +; CHECK: TypeInt [[Int:[0-9]+]] 32 0 +; CHECK: TypeInt [[Int8:[0-9]+]] 8 0 +; CHECK: TypePointer [[Int8Ptr:[0-9]+]] 8 [[Int8]] +; CHECK: TypeStruct [[StructType:[0-9]+]] [[Int]] [[Int]] [[Int8Ptr]] 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" target triple = "spir" -@__block_literal_global = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }, align 4 +%struct.__opencl_block_literal_generic = type { i32, i32, i8 addrspace(4)* } + +@__block_literal_global = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 12, i32 4, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* @__foo_block_invoke to i8*) to i8 addrspace(4)*) }, align 4 ; CHECK: ConstantComposite [[StructType]] -; This is artificial case is added to cover ConstantNull instrucitions with TypeStruct. -@__block_literal_global.1 = internal addrspace(1) constant { i32, i32 } zeroinitializer, align 4 +@__block_literal_global.1 = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } zeroinitializer, align 4 ; CHECK: ConstantNull [[StructType]] ; Function Attrs: convergent noinline nounwind optnone define spir_func void @foo() #0 { entry: - %myBlock = alloca void () addrspace(4)*, align 4 - store void () addrspace(4)* addrspacecast (void () addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* @__block_literal_global to void () addrspace(1)*) to void () addrspace(4)*), void () addrspace(4)** %myBlock, align 4 - call spir_func void @__foo_block_invoke(i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* @__block_literal_global to i8 addrspace(1)*) to i8 addrspace(4)*)) #1 + %myBlock = alloca %struct.__opencl_block_literal_generic addrspace(4)*, align 4 + store %struct.__opencl_block_literal_generic addrspace(4)* addrspacecast (%struct.__opencl_block_literal_generic addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global to %struct.__opencl_block_literal_generic addrspace(1)*) to %struct.__opencl_block_literal_generic addrspace(4)*), %struct.__opencl_block_literal_generic addrspace(4)** %myBlock, align 4 + call spir_func void @__foo_block_invoke(i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global to i8 addrspace(1)*) to i8 addrspace(4)*)) #1 ret void } @@ -40,14 +43,14 @@ entry: define internal spir_func void @__foo_block_invoke(i8 addrspace(4)* %.block_descriptor) #0 { entry: %.block_descriptor.addr = alloca i8 addrspace(4)*, align 4 - %block.addr = alloca <{ i32, i32 }> addrspace(4)*, align 4 + %block.addr = alloca <{ i32, i32, i8 addrspace(4)* }> addrspace(4)*, align 4 store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 4 - %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32 }> addrspace(4)* - store <{ i32, i32 }> addrspace(4)* %block, <{ i32, i32 }> addrspace(4)** %block.addr, align 4 + %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* + store <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* %block, <{ i32, i32, i8 addrspace(4)* }> addrspace(4)** %block.addr, align 4 ret void } -attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #1 = { convergent } !llvm.module.flags = !{!0} @@ -57,4 +60,4 @@ attributes #1 = { convergent } !0 = !{i32 1, !"wchar_size", i32 4} !1 = !{i32 2, i32 0} -!2 = !{!"clang version 8.0.0 "} +!2 = !{!"clang version 9.0.0 (https://llvm.org/git/clang 04fb8964a801a5c5d7baa5a22272243a7d183896) (https://llvm.org/git/llvm 384f64397f6ad95a361b72d62c07d7bac9f24163)"} diff --git a/llvm-spirv/test/transcoding/OpConstantSampler.ll b/llvm-spirv/test/transcoding/OpConstantSampler.ll index 3542184c62e04..38ea893946cd6 100644 --- a/llvm-spirv/test/transcoding/OpConstantSampler.ll +++ b/llvm-spirv/test/transcoding/OpConstantSampler.ll @@ -22,8 +22,8 @@ ; CHECK-SPIRV: SampledImage {{.*}} [[SamplerID0]] ; CHECK-SPIRV: SampledImage {{.*}} [[SamplerID1]] -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_f -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_f +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f 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" target triple = "spir" diff --git a/llvm-spirv/test/transcoding/OpControlBarrier_cl12.ll b/llvm-spirv/test/transcoding/OpControlBarrier_cl12.ll index 4940f99bf9b1c..9f2f7ef02374f 100644 --- a/llvm-spirv/test/transcoding/OpControlBarrier_cl12.ll +++ b/llvm-spirv/test/transcoding/OpControlBarrier_cl12.ll @@ -5,12 +5,13 @@ ; RUN: llvm-spirv -r %t.spv -o %t.rev.bc ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM -; CHECK-LLVM: call spir_func void @_Z7barrierj(i32 2) -; CHECK-LLVM-NEXT: call spir_func void @_Z7barrierj(i32 1) -; CHECK-LLVM-NEXT: call spir_func void @_Z7barrierj(i32 4) -; CHECK-LLVM-NEXT: call spir_func void @_Z7barrierj(i32 3) -; CHECK-LLVM-NEXT: call spir_func void @_Z7barrierj(i32 5) -; CHECK-LLVM-NEXT: call spir_func void @_Z7barrierj(i32 7) +; CHECK-LLVM: call spir_func void @_Z7barrierj(i32 2) [[attr:#[0-9]+]] +; CHECK-LLVM-NEXT: call spir_func void @_Z7barrierj(i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z7barrierj(i32 4) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z7barrierj(i32 3) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z7barrierj(i32 5) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z7barrierj(i32 7) [[attr]] +; CHECK-LLVM: attributes [[attr]] = { noduplicate nounwind } ; CHECK-SPIRV-DAG: 4 Constant {{[0-9]+}} [[MemSema1:[0-9]+]] 528 ; CHECK-SPIRV-DAG: 4 Constant {{[0-9]+}} [[MemSema2:[0-9]+]] 272 diff --git a/llvm-spirv/test/transcoding/OpControlBarrier_cl20.ll b/llvm-spirv/test/transcoding/OpControlBarrier_cl20.ll index c4fd3ffb4fd48..4d0c5a9ccccf8 100644 --- a/llvm-spirv/test/transcoding/OpControlBarrier_cl20.ll +++ b/llvm-spirv/test/transcoding/OpControlBarrier_cl20.ll @@ -6,27 +6,29 @@ ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM ; work_group_barrier with the default scope (memory_scope_work_group) -; CHECK-LLVM: call spir_func void @_Z18work_group_barrierji(i32 2, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 1, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 4, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 3, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 5, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 7, i32 1) #{{[0-9]+}} - -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 2, i32 0) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 2, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 2, i32 2) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 2, i32 3) #{{[0-9]+}} - -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 1, i32 0) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 1, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 1, i32 2) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 1, i32 3) #{{[0-9]+}} - -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 4, i32 0) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 4, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 4, i32 2) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 4, i32 3) #{{[0-9]+}} +; CHECK-LLVM: call spir_func void @_Z18work_group_barrierji(i32 2, i32 1) [[attr:#[0-9]+]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 1, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 4, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 3, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 5, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 7, i32 1) [[attr]] + +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 2, i32 0) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 2, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 2, i32 2) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 2, i32 3) [[attr]] + +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 1, i32 0) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 1, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 1, i32 2) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 1, i32 3) [[attr]] + +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 4, i32 0) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 4, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 4, i32 2) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z18work_group_barrierji(i32 4, i32 3) [[attr]] + +; CHECK-LLVM: attributes [[attr]] = { noduplicate nounwind } ; Both 'CrossDevice' memory scope and 'None' memory order enums have value equal to 0. ; CHECK-SPIRV-DAG: 4 Constant {{[0-9]+}} [[Null:[0-9]+]] 0 diff --git a/llvm-spirv/test/transcoding/OpControlBarrier_cl20_subgroup.ll b/llvm-spirv/test/transcoding/OpControlBarrier_cl20_subgroup.ll index bc54a858ea9ae..00447587b96be 100644 --- a/llvm-spirv/test/transcoding/OpControlBarrier_cl20_subgroup.ll +++ b/llvm-spirv/test/transcoding/OpControlBarrier_cl20_subgroup.ll @@ -5,27 +5,29 @@ ; RUN: llvm-spirv -r %t.spv -o %t.rev.bc ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM -; CHECK-LLVM: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 3, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 5, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 7, i32 1) #{{[0-9]+}} - -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 0) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 2) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 3) #{{[0-9]+}} - -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 0) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 2) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 3) #{{[0-9]+}} - -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 0) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 2) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 3) #{{[0-9]+}} +; CHECK-LLVM: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 1) [[attr:#[0-9]+]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 3, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 5, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 7, i32 1) [[attr]] + +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 0) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 2) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 3) [[attr]] + +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 0) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 2) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 3) [[attr]] + +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 0) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 2) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 3) [[attr]] + +; CHECK-LLVM: attributes [[attr]] = { noduplicate nounwind } ; CHECK-SPIRV-DAG: 4 Constant {{[0-9]+}} [[MemSema1:[0-9]+]] 528 ; CHECK-SPIRV-DAG: 4 Constant {{[0-9]+}} [[MemSema2:[0-9]+]] 272 diff --git a/llvm-spirv/test/transcoding/OpControlBarrier_cl21.ll b/llvm-spirv/test/transcoding/OpControlBarrier_cl21.ll index 3e5c03c51f0ab..01d7a28b401a1 100644 --- a/llvm-spirv/test/transcoding/OpControlBarrier_cl21.ll +++ b/llvm-spirv/test/transcoding/OpControlBarrier_cl21.ll @@ -5,28 +5,29 @@ ; RUN: llvm-spirv -r %t.spv -o %t.rev.bc ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM -; CHECK-LLVM: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 3, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 5, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 7, i32 1) #{{[0-9]+}} - -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 0) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 2) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 3) #{{[0-9]+}} - -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 0) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 2) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 3) #{{[0-9]+}} - -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 0) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 1) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 2) #{{[0-9]+}} -; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 3) #{{[0-9]+}} - +; CHECK-LLVM: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 1) [[attr:#[0-9]+]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 3, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 5, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 7, i32 1) [[attr]] + +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 0) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 2) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 2, i32 3) [[attr]] + +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 0) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 2) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 1, i32 3) [[attr]] + +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 0) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 1) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 2) [[attr]] +; CHECK-LLVM-NEXT: call spir_func void @_Z17sub_group_barrierji(i32 4, i32 3) [[attr]] + +; CHECK-LLVM: attributes [[attr]] = { noduplicate nounwind } ; CHECK-SPIRV-DAG: 4 Constant {{[0-9]+}} [[MemSema1:[0-9]+]] 528 ; CHECK-SPIRV-DAG: 4 Constant {{[0-9]+}} [[MemSema2:[0-9]+]] 272 diff --git a/llvm-spirv/test/transcoding/OpImageQuerySize.ll b/llvm-spirv/test/transcoding/OpImageQuerySize.ll index f5d6967d6d227..a7811d39912bd 100644 --- a/llvm-spirv/test/transcoding/OpImageQuerySize.ll +++ b/llvm-spirv/test/transcoding/OpImageQuerySize.ll @@ -15,48 +15,48 @@ target triple = "spir64-unknown-unknown" ; and subsequent extract or shufflevector instructions. Unfortunately there is ; no get_image_dim for 1D images and get_image_dim cannot replace get_image_array_size -; CHECK-DAG: %opencl.image1d_t = type opaque -; CHECK-DAG: %opencl.image1d_buffer_t = type opaque -; CHECK-DAG: %opencl.image1d_array_t = type opaque -; CHECK-DAG: %opencl.image2d_t = type opaque -; CHECK-DAG: %opencl.image2d_depth_t = type opaque -; CHECK-DAG: %opencl.image2d_array_t = type opaque +; CHECK-DAG: %opencl.image1d_ro_t = type opaque +; CHECK-DAG: %opencl.image1d_buffer_ro_t = type opaque +; CHECK-DAG: %opencl.image1d_array_ro_t = type opaque +; CHECK-DAG: %opencl.image2d_ro_t = type opaque +; CHECK-DAG: %opencl.image2d_depth_ro_t = type opaque +; CHECK-DAG: %opencl.image2d_array_ro_t = type opaque ; CHECK-SPIRV: 10 TypeImage [[ArrayTypeID:[0-9]+]] {{[0-9]+}} 0 0 1 0 0 0 0 -; CHECK-DAG: %opencl.image2d_array_depth_t = type opaque -; CHECK-DAG: %opencl.image3d_t = type opaque +; CHECK-DAG: %opencl.image2d_array_depth_ro_t = type opaque +; CHECK-DAG: %opencl.image3d_ro_t = type opaque -%opencl.image1d_t = type opaque -%opencl.image1d_buffer_t = type opaque -%opencl.image1d_array_t = type opaque -%opencl.image2d_t = type opaque -%opencl.image2d_depth_t = type opaque -%opencl.image2d_array_t = type opaque -%opencl.image2d_array_depth_t = type opaque -%opencl.image3d_t = type opaque +%opencl.image1d_ro_t = type opaque +%opencl.image1d_buffer_ro_t = type opaque +%opencl.image1d_array_ro_t = type opaque +%opencl.image2d_ro_t = type opaque +%opencl.image2d_depth_ro_t = type opaque +%opencl.image2d_array_ro_t = type opaque +%opencl.image2d_array_depth_ro_t = type opaque +%opencl.image3d_ro_t = type opaque -; CHECK: define {{.*}} @test_image1d +; CHECK-LABEL: define {{.*}} @test_image1d -; CHECK: call {{.*}} @_Z15get_image_width11ocl_image1d +; CHECK: call {{.*}} @_Z15get_image_width14ocl_image1d_ro -; CHECK: call {{.*}} @_Z15get_image_width17ocl_image1dbuffer +; CHECK: call {{.*}} @_Z15get_image_width21ocl_image1d_buffer_ro -; CHECK: call {{.*}} @_Z15get_image_width16ocl_image1darray +; CHECK: call {{.*}} @_Z15get_image_width20ocl_image1d_array_ro ; CHECK: insertelement <2 x i32> {{.*}} 0 -; CHECK: call {{.*}} i64 @_Z20get_image_array_size16ocl_image1darray +; CHECK: call {{.*}} i64 @_Z20get_image_array_size20ocl_image1d_array_ro ; CHECK: trunc i64 {{.*}} to i32 ; CHECK: insertelement <2 x i32> {{.*}} 1 -; CHECK: call {{.*}} i64 @_Z20get_image_array_size16ocl_image1darray +; CHECK: call {{.*}} i64 @_Z20get_image_array_size20ocl_image1d_array_ro ; CHECK-SPIRV: 3 FunctionParameter [[ArrayTypeID]] [[ArrayVarID:[0-9]+]] ; CHECK-SPIRV: ImageQuerySizeLod {{[0-9]+}} {{[0-9]+}} [[ArrayVarID]] ; CHECK-SPIRV-NOT: {{[0-9]*}} ExtInst {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} get_image_array_size ; Function Attrs: nounwind -define spir_kernel void @test_image1d(i32 addrspace(1)* nocapture %sizes, %opencl.image1d_t addrspace(1)* %img, %opencl.image1d_buffer_t addrspace(1)* %buffer, %opencl.image1d_array_t addrspace(1)* %array) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !5 !kernel_arg_type_qual !4 { - %1 = tail call spir_func i32 @_Z15get_image_width11ocl_image1d(%opencl.image1d_t addrspace(1)* %img) #1 - %2 = tail call spir_func i32 @_Z15get_image_width17ocl_image1dbuffer(%opencl.image1d_buffer_t addrspace(1)* %buffer) #1 - %3 = tail call spir_func i32 @_Z15get_image_width16ocl_image1darray(%opencl.image1d_array_t addrspace(1)* %array) #1 - %4 = tail call spir_func i64 @_Z20get_image_array_size16ocl_image1darray(%opencl.image1d_array_t addrspace(1)* %array) #1 +define spir_kernel void @test_image1d(i32 addrspace(1)* nocapture %sizes, %opencl.image1d_ro_t addrspace(1)* %img, %opencl.image1d_buffer_ro_t addrspace(1)* %buffer, %opencl.image1d_array_ro_t addrspace(1)* %array) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !5 !kernel_arg_type_qual !4 { + %1 = tail call spir_func i32 @_Z15get_image_width14ocl_image1d_ro(%opencl.image1d_ro_t addrspace(1)* %img) #1 + %2 = tail call spir_func i32 @_Z15get_image_width21ocl_image1d_buffer_ro(%opencl.image1d_buffer_ro_t addrspace(1)* %buffer) #1 + %3 = tail call spir_func i32 @_Z15get_image_width20ocl_image1d_array_ro(%opencl.image1d_array_ro_t addrspace(1)* %array) #1 + %4 = tail call spir_func i64 @_Z20get_image_array_size20ocl_image1d_array_ro(%opencl.image1d_array_ro_t addrspace(1)* %array) #1 %5 = trunc i64 %4 to i32 %6 = add nsw i32 %2, %1 %7 = add nsw i32 %6, %3 @@ -66,59 +66,59 @@ define spir_kernel void @test_image1d(i32 addrspace(1)* nocapture %sizes, %openc } ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z15get_image_width11ocl_image1d(%opencl.image1d_t addrspace(1)*) #1 +declare spir_func i32 @_Z15get_image_width14ocl_image1d_ro(%opencl.image1d_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z15get_image_width17ocl_image1dbuffer(%opencl.image1d_buffer_t addrspace(1)*) #1 +declare spir_func i32 @_Z15get_image_width21ocl_image1d_buffer_ro(%opencl.image1d_buffer_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z15get_image_width16ocl_image1darray(%opencl.image1d_array_t addrspace(1)*) #1 +declare spir_func i32 @_Z15get_image_width20ocl_image1d_array_ro(%opencl.image1d_array_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i64 @_Z20get_image_array_size16ocl_image1darray(%opencl.image1d_array_t addrspace(1)*) #1 +declare spir_func i64 @_Z20get_image_array_size20ocl_image1d_array_ro(%opencl.image1d_array_ro_t addrspace(1)*) #1 -; CHECK: define {{.*}} @test_image2d +; CHECK-LABEL: define {{.*}} @test_image2d -; CHECK: call {{.*}} @_Z13get_image_dim11ocl_image2d +; CHECK: call {{.*}} @_Z13get_image_dim14ocl_image2d_ro ; CHECK: extractelement <2 x i32> {{.*}} 0 -; CHECK: call {{.*}} @_Z13get_image_dim11ocl_image2d +; CHECK: call {{.*}} @_Z13get_image_dim14ocl_image2d_ro ; CHECK: extractelement <2 x i32> {{.*}} 1 -; CHECK: call {{.*}} @_Z13get_image_dim11ocl_image2d -; CHECK: call {{.*}} @_Z13get_image_dim16ocl_image2darray +; CHECK: call {{.*}} @_Z13get_image_dim14ocl_image2d_ro +; CHECK: call {{.*}} @_Z13get_image_dim20ocl_image2d_array_ro ; CHECK: shufflevector <2 x i32> {{.*}} <3 x i32> -; CHECK: call {{.*}} i64 @_Z20get_image_array_size16ocl_image2darray +; CHECK: call {{.*}} i64 @_Z20get_image_array_size20ocl_image2d_array_ro ; CHECK: trunc i64 {{.*}} to i32 ; CHECK: insertelement <3 x i32> {{.*}} i32 2 ; CHECK: extractelement <3 x i32> {{.*}} 0 -; CHECK: call {{.*}} @_Z13get_image_dim16ocl_image2darray +; CHECK: call {{.*}} @_Z13get_image_dim20ocl_image2d_array_ro ; CHECK: shufflevector <2 x i32> {{.*}} <3 x i32> -; CHECK: call {{.*}} i64 @_Z20get_image_array_size16ocl_image2darray +; CHECK: call {{.*}} i64 @_Z20get_image_array_size20ocl_image2d_array_ro ; CHECK: trunc i64 {{.*}} to i32 ; CHECK: insertelement <3 x i32> {{.*}} i32 2 ; CHECK: extractelement <3 x i32> {{.*}} 1 -; CHECK: call {{.*}} @_Z20get_image_array_size16ocl_image2darray +; CHECK: call {{.*}} @_Z20get_image_array_size20ocl_image2d_array_ro -; CHECK: call {{.*}} @_Z13get_image_dim16ocl_image2darray +; CHECK: call {{.*}} @_Z13get_image_dim20ocl_image2d_array_ro ; CHECK: shufflevector <2 x i32> {{.*}} <3 x i32> -; CHECK: call {{.*}} i64 @_Z20get_image_array_size16ocl_image2darray +; CHECK: call {{.*}} i64 @_Z20get_image_array_size20ocl_image2d_array_ro ; CHECK: trunc i64 {{.*}} to i32 ; CHECK: insertelement <3 x i32> {{.*}} i32 2 ; CHECK: shufflevector <3 x i32> {{.*}} <2 x i32> ; Function Attrs: nounwind -define spir_kernel void @test_image2d(i32 addrspace(1)* nocapture %sizes, %opencl.image2d_t addrspace(1)* %img, %opencl.image2d_depth_t addrspace(1)* nocapture %img_depth, %opencl.image2d_array_t addrspace(1)* %array, %opencl.image2d_array_depth_t addrspace(1)* nocapture %array_depth) #0 !kernel_arg_addr_space !7 !kernel_arg_access_qual !8 !kernel_arg_type !9 !kernel_arg_base_type !11 !kernel_arg_type_qual !10 { - %1 = tail call spir_func i32 @_Z15get_image_width11ocl_image2d(%opencl.image2d_t addrspace(1)* %img) #1 - %2 = tail call spir_func i32 @_Z16get_image_height11ocl_image2d(%opencl.image2d_t addrspace(1)* %img) #1 - %3 = tail call spir_func <2 x i32> @_Z13get_image_dim11ocl_image2d(%opencl.image2d_t addrspace(1)* %img) #1 - %4 = tail call spir_func i32 @_Z15get_image_width16ocl_image2darray(%opencl.image2d_array_t addrspace(1)* %array) #1 - %5 = tail call spir_func i32 @_Z16get_image_height16ocl_image2darray(%opencl.image2d_array_t addrspace(1)* %array) #1 - %6 = tail call spir_func i64 @_Z20get_image_array_size16ocl_image2darray(%opencl.image2d_array_t addrspace(1)* %array) #1 +define spir_kernel void @test_image2d(i32 addrspace(1)* nocapture %sizes, %opencl.image2d_ro_t addrspace(1)* %img, %opencl.image2d_depth_ro_t addrspace(1)* nocapture %img_depth, %opencl.image2d_array_ro_t addrspace(1)* %array, %opencl.image2d_array_depth_ro_t addrspace(1)* nocapture %array_depth) #0 !kernel_arg_addr_space !7 !kernel_arg_access_qual !8 !kernel_arg_type !9 !kernel_arg_base_type !11 !kernel_arg_type_qual !10 { + %1 = tail call spir_func i32 @_Z15get_image_width14ocl_image2d_ro(%opencl.image2d_ro_t addrspace(1)* %img) #1 + %2 = tail call spir_func i32 @_Z16get_image_height14ocl_image2d_ro(%opencl.image2d_ro_t addrspace(1)* %img) #1 + %3 = tail call spir_func <2 x i32> @_Z13get_image_dim14ocl_image2d_ro(%opencl.image2d_ro_t addrspace(1)* %img) #1 + %4 = tail call spir_func i32 @_Z15get_image_width20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)* %array) #1 + %5 = tail call spir_func i32 @_Z16get_image_height20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)* %array) #1 + %6 = tail call spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)* %array) #1 %7 = trunc i64 %6 to i32 - %8 = tail call spir_func <2 x i32> @_Z13get_image_dim16ocl_image2darray(%opencl.image2d_array_t addrspace(1)* %array) #1 + %8 = tail call spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)* %array) #1 %9 = add nsw i32 %2, %1 %10 = extractelement <2 x i32> %3, i32 0 %11 = add nsw i32 %9, %10 @@ -136,50 +136,50 @@ define spir_kernel void @test_image2d(i32 addrspace(1)* nocapture %sizes, %openc } ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z15get_image_width11ocl_image2d(%opencl.image2d_t addrspace(1)*) #1 +declare spir_func i32 @_Z15get_image_width14ocl_image2d_ro(%opencl.image2d_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z16get_image_height11ocl_image2d(%opencl.image2d_t addrspace(1)*) #1 +declare spir_func i32 @_Z16get_image_height14ocl_image2d_ro(%opencl.image2d_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func <2 x i32> @_Z13get_image_dim11ocl_image2d(%opencl.image2d_t addrspace(1)*) #1 +declare spir_func <2 x i32> @_Z13get_image_dim14ocl_image2d_ro(%opencl.image2d_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z15get_image_width16ocl_image2darray(%opencl.image2d_array_t addrspace(1)*) #1 +declare spir_func i32 @_Z15get_image_width20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z16get_image_height16ocl_image2darray(%opencl.image2d_array_t addrspace(1)*) #1 +declare spir_func i32 @_Z16get_image_height20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i64 @_Z20get_image_array_size16ocl_image2darray(%opencl.image2d_array_t addrspace(1)*) #1 +declare spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func <2 x i32> @_Z13get_image_dim16ocl_image2darray(%opencl.image2d_array_t addrspace(1)*) #1 +declare spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)*) #1 -; CHECK: define {{.*}} @test_image3d +; CHECK-LABEL: define {{.*}} @test_image3d -; CHECK: call {{.*}} @_Z13get_image_dim11ocl_image3d +; CHECK: call {{.*}} @_Z13get_image_dim14ocl_image3d_ro ; CHECK: shufflevector <4 x i32> {{.*}} <3 x i32> ; CHECK: extractelement <3 x i32> {{.*}} 0 -; CHECK: call {{.*}} @_Z13get_image_dim11ocl_image3d +; CHECK: call {{.*}} @_Z13get_image_dim14ocl_image3d_ro ; CHECK: shufflevector <4 x i32> {{.*}} <3 x i32> ; CHECK: extractelement <3 x i32> {{.*}} 1 -; CHECK: call {{.*}} @_Z13get_image_dim11ocl_image3d +; CHECK: call {{.*}} @_Z13get_image_dim14ocl_image3d_ro ; CHECK: shufflevector <4 x i32> {{.*}} <3 x i32> ; CHECK: extractelement <3 x i32> {{.*}} 2 -; CHECK: call {{.*}} @_Z13get_image_dim11ocl_image3d +; CHECK: call {{.*}} @_Z13get_image_dim14ocl_image3d_ro ; CHECK: shufflevector <4 x i32> {{.*}} <3 x i32> ; CHECK: shufflevector <3 x i32> {{.*}} <4 x i32> ; Function Attrs: nounwind -define spir_kernel void @test_image3d(i32 addrspace(1)* nocapture %sizes, %opencl.image3d_t addrspace(1)* %img) #0 !kernel_arg_addr_space !13 !kernel_arg_access_qual !14 !kernel_arg_type !15 !kernel_arg_base_type !17 !kernel_arg_type_qual !16 { - %1 = tail call spir_func i32 @_Z15get_image_width11ocl_image3d(%opencl.image3d_t addrspace(1)* %img) #1 - %2 = tail call spir_func i32 @_Z16get_image_height11ocl_image3d(%opencl.image3d_t addrspace(1)* %img) #1 - %3 = tail call spir_func i32 @_Z15get_image_depth11ocl_image3d(%opencl.image3d_t addrspace(1)* %img) #1 - %4 = tail call spir_func <4 x i32> @_Z13get_image_dim11ocl_image3d(%opencl.image3d_t addrspace(1)* %img) #1 +define spir_kernel void @test_image3d(i32 addrspace(1)* nocapture %sizes, %opencl.image3d_ro_t addrspace(1)* %img) #0 !kernel_arg_addr_space !13 !kernel_arg_access_qual !14 !kernel_arg_type !15 !kernel_arg_base_type !17 !kernel_arg_type_qual !16 { + %1 = tail call spir_func i32 @_Z15get_image_width14ocl_image3d_ro(%opencl.image3d_ro_t addrspace(1)* %img) #1 + %2 = tail call spir_func i32 @_Z16get_image_height14ocl_image3d_ro(%opencl.image3d_ro_t addrspace(1)* %img) #1 + %3 = tail call spir_func i32 @_Z15get_image_depth14ocl_image3d_ro(%opencl.image3d_ro_t addrspace(1)* %img) #1 + %4 = tail call spir_func <4 x i32> @_Z13get_image_dim14ocl_image3d_ro(%opencl.image3d_ro_t addrspace(1)* %img) #1 %5 = add nsw i32 %2, %1 %6 = add nsw i32 %5, %3 %7 = extractelement <4 x i32> %4, i32 0 @@ -195,38 +195,38 @@ define spir_kernel void @test_image3d(i32 addrspace(1)* nocapture %sizes, %openc } ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z15get_image_width11ocl_image3d(%opencl.image3d_t addrspace(1)*) #1 +declare spir_func i32 @_Z15get_image_width14ocl_image3d_ro(%opencl.image3d_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z16get_image_height11ocl_image3d(%opencl.image3d_t addrspace(1)*) #1 +declare spir_func i32 @_Z16get_image_height14ocl_image3d_ro(%opencl.image3d_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z15get_image_depth11ocl_image3d(%opencl.image3d_t addrspace(1)*) #1 +declare spir_func i32 @_Z15get_image_depth14ocl_image3d_ro(%opencl.image3d_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func <4 x i32> @_Z13get_image_dim11ocl_image3d(%opencl.image3d_t addrspace(1)*) #1 +declare spir_func <4 x i32> @_Z13get_image_dim14ocl_image3d_ro(%opencl.image3d_ro_t addrspace(1)*) #1 -; CHECK: define {{.*}} @test_image2d_array_depth_t +; CHECK-LABEL: define {{.*}} @test_image2d_array_depth_t -; CHECK: call {{.*}} <2 x i32> @_Z13get_image_dim21ocl_image2darraydepth +; CHECK: call {{.*}} <2 x i32> @_Z13get_image_dim26ocl_image2d_array_depth_ro ; CHECK: shufflevector <2 x i32> -; CHECK: call {{.*}} i64 @_Z20get_image_array_size21ocl_image2darraydepth +; CHECK: call {{.*}} i64 @_Z20get_image_array_size26ocl_image2d_array_depth_ro ; CHECK: trunc i64 {{.*}} to i32 ; CHECK: insertelement <3 x i32> {{.*}} 2 ; CHECK: extractelement <3 x i32> {{.*}} 0 -; CHECK: call {{.*}} <2 x i32> @_Z13get_image_dim21ocl_image2darraydepth +; CHECK: call {{.*}} <2 x i32> @_Z13get_image_dim26ocl_image2d_array_depth_ro ; CHECK: shufflevector <2 x i32> -; CHECK: call {{.*}} i64 @_Z20get_image_array_size21ocl_image2darraydepth +; CHECK: call {{.*}} i64 @_Z20get_image_array_size26ocl_image2d_array_depth_ro ; CHECK: trunc i64 {{.*}} to i32 ; CHECK: insertelement <3 x i32> {{.*}} 2 ; CHECK: extractelement <3 x i32> {{.*}} 1 ; Function Attrs: nounwind -define spir_kernel void @test_image2d_array_depth_t(i32 addrspace(1)* nocapture %sizes, %opencl.image2d_array_depth_t addrspace(1)* %array) #0 !kernel_arg_addr_space !27 !kernel_arg_access_qual !28 !kernel_arg_type !29 !kernel_arg_base_type !31 !kernel_arg_type_qual !30 { - %1 = tail call spir_func i32 @_Z15get_image_width21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)* %array) #1 - %2 = tail call spir_func i32 @_Z16get_image_height21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)* %array) #1 - %3 = tail call spir_func i64 @_Z20get_image_array_size21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)* %array) #1 +define spir_kernel void @test_image2d_array_depth_t(i32 addrspace(1)* nocapture %sizes, %opencl.image2d_array_depth_ro_t addrspace(1)* %array) #0 !kernel_arg_addr_space !27 !kernel_arg_access_qual !28 !kernel_arg_type !29 !kernel_arg_base_type !31 !kernel_arg_type_qual !30 { + %1 = tail call spir_func i32 @_Z15get_image_width26ocl_image2d_array_depth_ro(%opencl.image2d_array_depth_ro_t addrspace(1)* %array) #1 + %2 = tail call spir_func i32 @_Z16get_image_height26ocl_image2d_array_depth_ro(%opencl.image2d_array_depth_ro_t addrspace(1)* %array) #1 + %3 = tail call spir_func i64 @_Z20get_image_array_size26ocl_image2d_array_depth_ro(%opencl.image2d_array_depth_ro_t addrspace(1)* %array) #1 %4 = trunc i64 %3 to i32 %5 = add nsw i32 %2, %1 %6 = add nsw i32 %5, %4 @@ -235,13 +235,13 @@ define spir_kernel void @test_image2d_array_depth_t(i32 addrspace(1)* nocapture } ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z15get_image_width21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)*) #1 +declare spir_func i32 @_Z15get_image_width26ocl_image2d_array_depth_ro(%opencl.image2d_array_depth_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i32 @_Z16get_image_height21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)*) #1 +declare spir_func i32 @_Z16get_image_height26ocl_image2d_array_depth_ro(%opencl.image2d_array_depth_ro_t addrspace(1)*) #1 ; Function Attrs: nounwind readnone -declare spir_func i64 @_Z20get_image_array_size21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)*) #1 +declare spir_func i64 @_Z20get_image_array_size26ocl_image2d_array_depth_ro(%opencl.image2d_array_depth_ro_t addrspace(1)*) #1 attributes #0 = { nounwind } attributes #1 = { nounwind readnone } diff --git a/llvm-spirv/test/transcoding/OpImageReadMS.ll b/llvm-spirv/test/transcoding/OpImageReadMS.ll index 86a9dcabcce65..0e1bde9025c3d 100644 --- a/llvm-spirv/test/transcoding/OpImageReadMS.ll +++ b/llvm-spirv/test/transcoding/OpImageReadMS.ll @@ -5,23 +5,23 @@ ; RUN: llvm-spirv -r %t.spv -o %t.rev.bc ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef15ocl_image2dmsaaDv2_ii(%opencl.image2d_msaa_t +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef19ocl_image2d_msaa_roDv2_ii(%opencl.image2d_msaa_ro_t ; CHECK-SPIRV: 7 ImageRead {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} 64 {{[0-9]+}} 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" target triple = "spir-unknown-unknown" -%opencl.image2d_msaa_t = type opaque +%opencl.image2d_msaa_ro_t = type opaque ; Function Attrs: nounwind -define spir_kernel void @sample_test(%opencl.image2d_msaa_t addrspace(1)* %source, i32 %sampler, <4 x float> addrspace(1)* nocapture %results) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !4 !kernel_arg_type_qual !5 { +define spir_kernel void @sample_test(%opencl.image2d_msaa_ro_t addrspace(1)* %source, i32 %sampler, <4 x float> addrspace(1)* nocapture %results) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !4 !kernel_arg_type_qual !5 { entry: %call = tail call spir_func i32 @_Z13get_global_idj(i32 0) #2 %call1 = tail call spir_func i32 @_Z13get_global_idj(i32 1) #2 - %call2 = tail call spir_func i32 @_Z15get_image_width15ocl_image2dmsaa(%opencl.image2d_msaa_t addrspace(1)* %source) #2 - %call3 = tail call spir_func i32 @_Z16get_image_height15ocl_image2dmsaa(%opencl.image2d_msaa_t addrspace(1)* %source) #2 - %call4 = tail call spir_func i32 @_Z21get_image_num_samples15ocl_image2dmsaa(%opencl.image2d_msaa_t addrspace(1)* %source) #2 + %call2 = tail call spir_func i32 @_Z15get_image_width19ocl_image2d_msaa_ro(%opencl.image2d_msaa_ro_t addrspace(1)* %source) #2 + %call3 = tail call spir_func i32 @_Z16get_image_height19ocl_image2d_msaa_ro(%opencl.image2d_msaa_ro_t addrspace(1)* %source) #2 + %call4 = tail call spir_func i32 @_Z21get_image_num_samples19ocl_image2d_msaa_ro(%opencl.image2d_msaa_ro_t addrspace(1)* %source) #2 %cmp20 = icmp eq i32 %call4, 0 br i1 %cmp20, label %for.end, label %for.body.lr.ph @@ -36,7 +36,7 @@ for.body: ; preds = %for.body.lr.ph, %fo %tmp = add i32 %mul5, %call1 %tmp19 = mul i32 %tmp, %call2 %add7 = add i32 %tmp19, %call - %call9 = tail call spir_func <4 x float> @_Z11read_imagef15ocl_image2dmsaaDv2_ii(%opencl.image2d_msaa_t addrspace(1)* %source, <2 x i32> %vecinit8, i32 %sample.021) #2 + %call9 = tail call spir_func <4 x float> @_Z11read_imagef19ocl_image2d_msaa_roDv2_ii(%opencl.image2d_msaa_ro_t addrspace(1)* %source, <2 x i32> %vecinit8, i32 %sample.021) #2 %arrayidx = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %results, i32 %add7 store <4 x float> %call9, <4 x float> addrspace(1)* %arrayidx, align 16 %inc = add nuw i32 %sample.021, 1 @@ -52,13 +52,13 @@ for.end: ; preds = %for.end.loopexit, % declare spir_func i32 @_Z13get_global_idj(i32) #1 -declare spir_func i32 @_Z15get_image_width15ocl_image2dmsaa(%opencl.image2d_msaa_t addrspace(1)*) #1 +declare spir_func i32 @_Z15get_image_width19ocl_image2d_msaa_ro(%opencl.image2d_msaa_ro_t addrspace(1)*) #1 -declare spir_func i32 @_Z16get_image_height15ocl_image2dmsaa(%opencl.image2d_msaa_t addrspace(1)*) #1 +declare spir_func i32 @_Z16get_image_height19ocl_image2d_msaa_ro(%opencl.image2d_msaa_ro_t addrspace(1)*) #1 -declare spir_func i32 @_Z21get_image_num_samples15ocl_image2dmsaa(%opencl.image2d_msaa_t addrspace(1)*) #1 +declare spir_func i32 @_Z21get_image_num_samples19ocl_image2d_msaa_ro(%opencl.image2d_msaa_ro_t addrspace(1)*) #1 -declare spir_func <4 x float> @_Z11read_imagef15ocl_image2dmsaaDv2_ii(%opencl.image2d_msaa_t addrspace(1)*, <2 x i32>, i32) #1 +declare spir_func <4 x float> @_Z11read_imagef19ocl_image2d_msaa_roDv2_ii(%opencl.image2d_msaa_ro_t addrspace(1)*, <2 x i32>, i32) #1 attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } diff --git a/llvm-spirv/test/transcoding/OpImageSampleExplicitLod.ll b/llvm-spirv/test/transcoding/OpImageSampleExplicitLod.ll index 2ceb8a6ff18f3..657c176785c4d 100644 --- a/llvm-spirv/test/transcoding/OpImageSampleExplicitLod.ll +++ b/llvm-spirv/test/transcoding/OpImageSampleExplicitLod.ll @@ -5,7 +5,7 @@ ; RUN: llvm-spirv -r %t.spv -o %t.rev.bc ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM -; CHECK-LLVM: call spir_func float @_Z11read_imagef16ocl_image2ddepth11ocl_samplerDv2_i(%opencl.image2d_depth_t +; CHECK-LLVM: call spir_func float @_Z11read_imagef20ocl_image2d_depth_ro11ocl_samplerDv2_i(%opencl.image2d_depth_ro_t ; CHECK-SPIRV-DAG: 7 ImageSampleExplicitLod [[RetType:[0-9]+]] [[RetID:[0-9]+]] {{[0-9]+}} {{[0-9]+}} 2 {{[0-9]+}} ; CHECK-SPIRV-DAG: 4 TypeVector [[RetType]] {{[0-9]+}} 4 @@ -14,14 +14,14 @@ 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" target triple = "spir-unknown-unknown" -%opencl.image2d_depth_t = type opaque +%opencl.image2d_depth_ro_t = type opaque ; Function Attrs: nounwind -define spir_kernel void @sample_kernel(%opencl.image2d_depth_t addrspace(1)* %input, i32 %imageSampler, float addrspace(1)* %xOffsets, float addrspace(1)* %yOffsets, float addrspace(1)* %results) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !5 !kernel_arg_type_qual !4 { +define spir_kernel void @sample_kernel(%opencl.image2d_depth_ro_t addrspace(1)* %input, i32 %imageSampler, float addrspace(1)* %xOffsets, float addrspace(1)* %yOffsets, float addrspace(1)* %results) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !5 !kernel_arg_type_qual !4 { entry: %call = call spir_func i32 @_Z13get_global_idj(i32 0) #1 %call1 = call spir_func i32 @_Z13get_global_idj(i32 1) #1 - %call2.tmp1 = call spir_func <2 x i32> @_Z13get_image_dim16ocl_image2ddepth(%opencl.image2d_depth_t addrspace(1)* %input) + %call2.tmp1 = call spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_depth_ro(%opencl.image2d_depth_ro_t addrspace(1)* %input) %call2.old = extractelement <2 x i32> %call2.tmp1, i32 0 %mul = mul i32 %call1, %call2.old %add = add i32 %mul, %call @@ -33,20 +33,20 @@ entry: %1 = load float, float addrspace(1)* %arrayidx3, align 4 %conv4 = fptosi float %1 to i32 %vecinit5 = insertelement <2 x i32> %vecinit, i32 %conv4, i32 1 - %call6.tmp.tmp = call spir_func float @_Z11read_imagef16ocl_image2ddepth11ocl_samplerDv2_i(%opencl.image2d_depth_t addrspace(1)* %input, i32 %imageSampler, <2 x i32> %vecinit5) + %call6.tmp.tmp = call spir_func float @_Z11read_imagef20ocl_image2d_depth_ro11ocl_samplerDv2_i(%opencl.image2d_depth_ro_t addrspace(1)* %input, i32 %imageSampler, <2 x i32> %vecinit5) %arrayidx7 = getelementptr inbounds float, float addrspace(1)* %results, i32 %add store float %call6.tmp.tmp, float addrspace(1)* %arrayidx7, align 4 ret void } ; Function Attrs: nounwind -declare spir_func float @_Z11read_imagef16ocl_image2ddepth11ocl_samplerDv2_i(%opencl.image2d_depth_t addrspace(1)*, i32, <2 x i32>) #0 +declare spir_func float @_Z11read_imagef20ocl_image2d_depth_ro11ocl_samplerDv2_i(%opencl.image2d_depth_ro_t addrspace(1)*, i32, <2 x i32>) #0 ; Function Attrs: nounwind readnone declare spir_func i32 @_Z13get_global_idj(i32) #1 ; Function Attrs: nounwind -declare spir_func <2 x i32> @_Z13get_image_dim16ocl_image2ddepth(%opencl.image2d_depth_t addrspace(1)*) #0 +declare spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_depth_ro(%opencl.image2d_depth_ro_t addrspace(1)*) #0 attributes #0 = { nounwind } attributes #1 = { nounwind readnone } diff --git a/llvm-spirv/test/transcoding/OpImageSampleExplicitLod_arg.ll b/llvm-spirv/test/transcoding/OpImageSampleExplicitLod_arg.ll index fef9ffff98f0f..730ecd31604b6 100644 --- a/llvm-spirv/test/transcoding/OpImageSampleExplicitLod_arg.ll +++ b/llvm-spirv/test/transcoding/OpImageSampleExplicitLod_arg.ll @@ -36,31 +36,32 @@ 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" target triple = "spir-unknown-unknown" -%opencl.image2d_t = type opaque +%opencl.image2d_ro_t = type opaque +%opencl.sampler_t = type opaque ; Function Attrs: nounwind -define spir_kernel void @sample_kernel_read(<4 x float> addrspace(1)* %results, %opencl.image2d_t addrspace(1)* %image, i32 %imageSampler, <2 x float> %coord, <2 x float> %dx, <2 x float> %dy) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !4 !kernel_arg_type_qual !5 { +define spir_kernel void @sample_kernel_read(<4 x float> addrspace(1)* %results, %opencl.image2d_ro_t addrspace(1)* %image, %opencl.sampler_t* %imageSampler, <2 x float> %coord, <2 x float> %dx, <2 x float> %dy) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !4 !kernel_arg_type_qual !5 { entry: - %call = call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_f(%opencl.image2d_t addrspace(1)* %image, i32 %imageSampler, <2 x float> %coord) -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_f(%opencl.image2d_t addrspace(1)* %image, i32 %imageSampler, <2 x float> %coord) + %call = call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)* %image, %opencl.sampler_t* %imageSampler, <2 x float> %coord) +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)* %image, %opencl.sampler_t* %imageSampler, <2 x float> %coord) store <4 x float> %call, <4 x float> addrspace(1)* %results, align 16 - %call1 = call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_ff(%opencl.image2d_t addrspace(1)* %image, i32 %imageSampler, <2 x float> %coord, float 0x40091EB860000000) -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_ff(%opencl.image2d_t addrspace(1)* %image, i32 %imageSampler, <2 x float> %coord, float 0x40091EB860000000) + %call1 = call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_ff(%opencl.image2d_ro_t addrspace(1)* %image, %opencl.sampler_t* %imageSampler, <2 x float> %coord, float 0x40091EB860000000) +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_ff(%opencl.image2d_ro_t addrspace(1)* %image, %opencl.sampler_t* %imageSampler, <2 x float> %coord, float 0x40091EB860000000) store <4 x float> %call1, <4 x float> addrspace(1)* %results, align 16 - %call2 = call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_fDv2_fDv2_f(%opencl.image2d_t addrspace(1)* %image, i32 %imageSampler, <2 x float> %coord, <2 x float> %dx, <2 x float> %dy) -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_fS_S_(%opencl.image2d_t addrspace(1)* %image, i32 %imageSampler, <2 x float> %coord, <2 x float> %dx, <2 x float> %dy) + %call2 = call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_fDv2_fDv2_f(%opencl.image2d_ro_t addrspace(1)* %image, %opencl.sampler_t* %imageSampler, <2 x float> %coord, <2 x float> %dx, <2 x float> %dy) +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_fS_S_(%opencl.image2d_ro_t addrspace(1)* %image, %opencl.sampler_t* %imageSampler, <2 x float> %coord, <2 x float> %dx, <2 x float> %dy) store <4 x float> %call2, <4 x float> addrspace(1)* %results, align 16 ret void } -declare spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_f(%opencl.image2d_t addrspace(1)*, i32, <2 x float>) #1 +declare spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)*, %opencl.sampler_t*, <2 x float>) #1 -declare spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_ff(%opencl.image2d_t addrspace(1)*, i32, <2 x float>, float) #1 +declare spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_ff(%opencl.image2d_ro_t addrspace(1)*, %opencl.sampler_t*, <2 x float>, float) #1 -declare spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_fDv2_fDv2_f(%opencl.image2d_t addrspace(1)*, i32, <2 x float>, <2 x float>, <2 x float>) #1 +declare spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_fDv2_fDv2_f(%opencl.image2d_ro_t addrspace(1)*, %opencl.sampler_t*, <2 x float>, <2 x float>, <2 x float>) #1 attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } diff --git a/llvm-spirv/test/transcoding/OpImageWrite.ll b/llvm-spirv/test/transcoding/OpImageWrite.ll index 157b0dc8f3e9e..09a9fc086cb39 100644 --- a/llvm-spirv/test/transcoding/OpImageWrite.ll +++ b/llvm-spirv/test/transcoding/OpImageWrite.ll @@ -21,23 +21,23 @@ 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" target triple = "spir-unknown-unknown" -%opencl.image2d_t = type opaque +%opencl.image2d_wo_t = type opaque ; Function Attrs: nounwind -define spir_func void @sample_kernel_write(<4 x float> %input, %opencl.image2d_t addrspace(1)* %output, <2 x i32> %coord) #0 { +define spir_func void @sample_kernel_write(<4 x float> %input, %opencl.image2d_wo_t addrspace(1)* %output, <2 x i32> %coord) #0 { entry: - call spir_func void @_Z12write_imagef11ocl_image2dDv2_iiDv4_f(%opencl.image2d_t addrspace(1)* %output, <2 x i32> %coord, i32 5, <4 x float> %input) -; CHECK-LLVM: call spir_func void @_Z12write_imagef11ocl_image2dDv2_iiDv4_f(%opencl.image2d_t addrspace(1)* %output, <2 x i32> %coord, i32 5, <4 x float> %input) + call spir_func void @_Z12write_imagef14ocl_image2d_woDv2_iiDv4_f(%opencl.image2d_wo_t addrspace(1)* %output, <2 x i32> %coord, i32 5, <4 x float> %input) +; CHECK-LLVM: call spir_func void @_Z12write_imagef14ocl_image2d_woDv2_iiDv4_f(%opencl.image2d_wo_t addrspace(1)* %output, <2 x i32> %coord, i32 5, <4 x float> %input) - call spir_func void @_Z12write_imagef11ocl_image2dDv2_iDv4_f(%opencl.image2d_t addrspace(1)* %output, <2 x i32> %coord, <4 x float> %input) -; CHECK-LLVM: call spir_func void @_Z12write_imagef11ocl_image2dDv2_iDv4_f(%opencl.image2d_t addrspace(1)* %output, <2 x i32> %coord, <4 x float> %input) + call spir_func void @_Z12write_imagef14ocl_image2d_woDv2_iDv4_f(%opencl.image2d_wo_t addrspace(1)* %output, <2 x i32> %coord, <4 x float> %input) +; CHECK-LLVM: call spir_func void @_Z12write_imagef14ocl_image2d_woDv2_iDv4_f(%opencl.image2d_wo_t addrspace(1)* %output, <2 x i32> %coord, <4 x float> %input) ret void } -declare spir_func void @_Z12write_imagef11ocl_image2dDv2_iiDv4_f(%opencl.image2d_t addrspace(1)*, <2 x i32>, i32, <4 x float>) #1 +declare spir_func void @_Z12write_imagef14ocl_image2d_woDv2_iiDv4_f(%opencl.image2d_wo_t addrspace(1)*, <2 x i32>, i32, <4 x float>) #1 -declare spir_func void @_Z12write_imagef11ocl_image2dDv2_iDv4_f(%opencl.image2d_t addrspace(1)*, <2 x i32>, <4 x float>) #1 +declare spir_func void @_Z12write_imagef14ocl_image2d_woDv2_iDv4_f(%opencl.image2d_wo_t addrspace(1)*, <2 x i32>, <4 x float>) #1 attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } diff --git a/llvm-spirv/test/transcoding/block_w_struct_return.ll b/llvm-spirv/test/transcoding/block_w_struct_return.ll index 76e29f0ec8448..df89b13d779c6 100644 --- a/llvm-spirv/test/transcoding/block_w_struct_return.ll +++ b/llvm-spirv/test/transcoding/block_w_struct_return.ll @@ -16,6 +16,8 @@ ; res[tid] = kernelBlock(aa).a - 6; ; } +; clang -cc1 -triple spir -cl-std=cl2.0 -disable-llvm-passes -finclude-default-header block_w_struct_return.cl -emit-llvm -o test/transcoding/block_w_struct_return.ll + ; RUN: llvm-as %s -o %t.bc ; RUN: llvm-spirv %t.bc -spirv-text -o %t.spv.txt ; RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV @@ -27,12 +29,14 @@ ; CHECK-SPIRV: Name [[BlockInv:[0-9]+]] "__block_ret_struct_block_invoke" ; CHECK-SPIRV: 4 TypeInt [[IntTy:[0-9]+]] 32 +; CHECK-SPIRV: 4 TypeInt [[Int8Ty:[0-9]+]] 8 +; CHECK-SPIRV: 4 TypePointer [[Int8Ptr:[0-9]+]] 8 [[Int8Ty]] ; CHECK-SPIRV: 3 TypeStruct [[StructTy:[0-9]+]] [[IntTy]] ; CHECK-SPIRV: 4 TypePointer [[StructPtrTy:[0-9]+]] 7 [[StructTy]] ; CHECK-SPIRV: 4 Variable [[StructPtrTy]] [[StructArg:[0-9]+]] 7 ; CHECK-SPIRV: 4 Variable [[StructPtrTy]] [[StructRet:[0-9]+]] 7 -; CHECK-SPIRV: 4 PtrCastToGeneric {{[0-9]+}} [[BlockLit:[0-9]+]] {{[0-9]+}} +; CHECK-SPIRV: 4 PtrCastToGeneric [[Int8Ptr]] [[BlockLit:[0-9]+]] {{[0-9]+}} ; CHECK-SPIRV: 7 FunctionCall {{[0-9]+}} {{[0-9]+}} [[BlockInv]] [[StructRet]] [[BlockLit]] [[StructArg]] ; CHECK-LLVM: %[[StructA:.*]] = type { i32 } @@ -41,20 +45,21 @@ target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" target triple = "spir64-unknown-unknown" +%struct.__opencl_block_literal_generic = type { i32, i32, i8 addrspace(4)* } %struct.A = type { i32 } -@__block_literal_global = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }, align 4 +@__block_literal_global = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 16, i32 8, i8 addrspace(4)* addrspacecast (i8* bitcast (void (%struct.A*, i8 addrspace(4)*, %struct.A*)* @__block_ret_struct_block_invoke to i8*) to i8 addrspace(4)*) }, align 8 ; Function Attrs: convergent noinline nounwind optnone -define spir_kernel void @block_ret_struct(i32 addrspace(1)* %res) #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 !kernel_arg_host_accessible !8 !kernel_arg_pipe_depth !9 !kernel_arg_pipe_io !7 !kernel_arg_buffer_location !7 { +define spir_kernel void @block_ret_struct(i32 addrspace(1)* %res) #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !4 !kernel_arg_type !5 !kernel_arg_base_type !5 !kernel_arg_type_qual !6 { entry: %res.addr = alloca i32 addrspace(1)*, align 8 - %kernelBlock = alloca void (%struct.A*, %struct.A*) addrspace(4)*, align 8 + %kernelBlock = alloca %struct.__opencl_block_literal_generic addrspace(4)*, align 8 %tid = alloca i64, align 8 %aa = alloca %struct.A, align 4 %tmp = alloca %struct.A, align 4 store i32 addrspace(1)* %res, i32 addrspace(1)** %res.addr, align 8 - store void (%struct.A*, %struct.A*) addrspace(4)* addrspacecast (void (%struct.A*, %struct.A*) addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* @__block_literal_global to void (%struct.A*, %struct.A*) addrspace(1)*) to void (%struct.A*, %struct.A*) addrspace(4)*), void (%struct.A*, %struct.A*) addrspace(4)** %kernelBlock, align 8 + store %struct.__opencl_block_literal_generic addrspace(4)* addrspacecast (%struct.__opencl_block_literal_generic addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global to %struct.__opencl_block_literal_generic addrspace(1)*) to %struct.__opencl_block_literal_generic addrspace(4)*), %struct.__opencl_block_literal_generic addrspace(4)** %kernelBlock, align 8 %call = call spir_func i64 @_Z13get_global_idj(i32 0) #4 store i64 %call, i64* %tid, align 8 %0 = load i32 addrspace(1)*, i32 addrspace(1)** %res.addr, align 8 @@ -63,7 +68,7 @@ entry: store i32 -1, i32 addrspace(1)* %arrayidx, align 4 %a = getelementptr inbounds %struct.A, %struct.A* %aa, i32 0, i32 0 store i32 5, i32* %a, align 4 - call spir_func void @__block_ret_struct_block_invoke(%struct.A* sret %tmp, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* @__block_literal_global to i8 addrspace(1)*) to i8 addrspace(4)*), %struct.A* byval align 4 %aa) #5 + call spir_func void @__block_ret_struct_block_invoke(%struct.A* sret %tmp, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global to i8 addrspace(1)*) to i8 addrspace(4)*), %struct.A* byval align 4 %aa) #5 %a1 = getelementptr inbounds %struct.A, %struct.A* %tmp, i32 0, i32 0 %2 = load i32, i32* %a1, align 4 %sub = sub nsw i32 %2, 6 @@ -78,10 +83,10 @@ entry: define internal spir_func void @__block_ret_struct_block_invoke(%struct.A* noalias sret %agg.result, i8 addrspace(4)* %.block_descriptor, %struct.A* byval align 4 %a) #1 { entry: %.block_descriptor.addr = alloca i8 addrspace(4)*, align 8 - %block.addr = alloca <{ i32, i32 }> addrspace(4)*, align 8 + %block.addr = alloca <{ i32, i32, i8 addrspace(4)* }> addrspace(4)*, align 8 store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 8 - %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32 }> addrspace(4)* - store <{ i32, i32 }> addrspace(4)* %block, <{ i32, i32 }> addrspace(4)** %block.addr, align 8 + %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* + store <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* %block, <{ i32, i32, i8 addrspace(4)* }> addrspace(4)** %block.addr, align 8 %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0 store i32 6, i32* %a1, align 4 %0 = bitcast %struct.A* %agg.result to i8* @@ -96,30 +101,22 @@ declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture r ; Function Attrs: convergent nounwind readnone declare spir_func i64 @_Z13get_global_idj(i32) #3 -attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } -attributes #1 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #2 = { argmemonly nounwind } attributes #3 = { convergent nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #4 = { convergent nounwind readnone } attributes #5 = { convergent } !llvm.module.flags = !{!0} -!opencl.enable.FP_CONTRACT = !{} !opencl.ocl.version = !{!1} !opencl.spir.version = !{!1} -!opencl.used.extensions = !{!2} -!opencl.used.optional.core.features = !{!2} -!opencl.compiler.options = !{!2} -!llvm.ident = !{!3} +!llvm.ident = !{!2} !0 = !{i32 1, !"wchar_size", i32 4} !1 = !{i32 2, i32 0} -!2 = !{} -!3 = !{!"clang version 7.0.0"} -!4 = !{i32 1} -!5 = !{!"none"} -!6 = !{!"int*"} -!7 = !{!""} -!8 = !{i1 false} -!9 = !{i32 0} - +!2 = !{!"clang version 9.0.0 (https://llvm.org/git/clang 04fb8964a801a5c5d7baa5a22272243a7d183896) (https://llvm.org/git/llvm 384f64397f6ad95a361b72d62c07d7bac9f24163)"} +!3 = !{i32 1} +!4 = !{!"none"} +!5 = !{!"int*"} +!6 = !{!""} diff --git a/llvm-spirv/test/transcoding/check_ro_qualifier.ll b/llvm-spirv/test/transcoding/check_ro_qualifier.ll index 088d55db093d8..0450d8f7fedef 100644 --- a/llvm-spirv/test/transcoding/check_ro_qualifier.ll +++ b/llvm-spirv/test/transcoding/check_ro_qualifier.ll @@ -1,6 +1,6 @@ ; RUN: llvm-as %s -o %t.bc ; RUN: llvm-spirv %t.bc -o %t.spv -; RUN: llvm-spirv -r -spirv-gen-image-type-acc-postfix %t.spv -o %t.rev.bc +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM ; CHECK-LLVM: opencl.image2d_array_ro_t = type opaque @@ -9,10 +9,10 @@ ; CHECK-LLVM-SAME: !kernel_arg_type [[TYPE:![0-9]+]] ; CHECK-LLVM-SAME: !kernel_arg_base_type [[TYPE]] -; CHECK-LLVM: call spir_func <2 x i32> @_Z13get_image_dimPU3AS125opencl.image2d_array_ro_t(%opencl.image2d_array_ro_t addrspace(1) -; CHECK-LLVM: call spir_func i64 @_Z20get_image_array_sizePU3AS125opencl.image2d_array_ro_t(%opencl.image2d_array_ro_t addrspace(1) -; CHECK-LLVM: declare spir_func <2 x i32> @_Z13get_image_dimPU3AS125opencl.image2d_array_ro_t(%opencl.image2d_array_ro_t addrspace(1) -; CHECK-LLVM: declare spir_func i64 @_Z20get_image_array_sizePU3AS125opencl.image2d_array_ro_t(%opencl.image2d_array_ro_t addrspace(1) +; CHECK-LLVM: call spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1) +; CHECK-LLVM: call spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1) +; CHECK-LLVM: declare spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1) +; CHECK-LLVM: declare spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1) ; CHECK-LLVM-DAG: [[AQ]] = !{!"read_only"} ; CHECK-LLVM-DAG: [[TYPE]] = !{!"image2d_array_t"} @@ -26,9 +26,9 @@ target triple = "spir64-unknown-unknown" ; Function Attrs: nounwind define spir_kernel void @sample_kernel(%opencl.image2d_array_ro_t addrspace(1)* %input) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !5 !kernel_arg_type_qual !4 { entry: - %call.tmp1 = call spir_func <2 x i32> @_Z13get_image_dimPU3AS125opencl.image2d_array_ro_t(%opencl.image2d_array_ro_t addrspace(1)* %input) + %call.tmp1 = call spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)* %input) %call.tmp2 = shufflevector <2 x i32> %call.tmp1, <2 x i32> undef, <3 x i32> - %call.tmp3 = call spir_func i64 @_Z20get_image_array_sizePU3AS125opencl.image2d_array_ro_t(%opencl.image2d_array_ro_t addrspace(1)* %input) + %call.tmp3 = call spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)* %input) %call.tmp4 = trunc i64 %call.tmp3 to i32 %call.tmp5 = insertelement <3 x i32> %call.tmp2, i32 %call.tmp4, i32 2 %call.old = extractelement <3 x i32> %call.tmp5, i32 0 @@ -36,10 +36,10 @@ entry: } ; Function Attrs: nounwind -declare spir_func <2 x i32> @_Z13get_image_dimPU3AS125opencl.image2d_array_ro_t(%opencl.image2d_array_ro_t addrspace(1)*) #0 +declare spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)*) #0 ; Function Attrs: nounwind -declare spir_func i64 @_Z20get_image_array_sizePU3AS125opencl.image2d_array_ro_t(%opencl.image2d_array_ro_t addrspace(1)*) #0 +declare spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)*) #0 attributes #0 = { nounwind } diff --git a/llvm-spirv/test/transcoding/check_wo_qualifier.ll b/llvm-spirv/test/transcoding/check_wo_qualifier.ll index 79b3fd5a0de8b..44fea6b4737e6 100644 --- a/llvm-spirv/test/transcoding/check_wo_qualifier.ll +++ b/llvm-spirv/test/transcoding/check_wo_qualifier.ll @@ -1,6 +1,6 @@ ; RUN: llvm-as %s -o %t.bc ; RUN: llvm-spirv %t.bc -o %t.spv -; RUN: llvm-spirv -r -spirv-gen-image-type-acc-postfix %t.spv -o %t.rev.bc +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM ; CHECK-LLVM: opencl.image2d_array_wo_t = type opaque @@ -9,10 +9,10 @@ ; CHECK-LLVM-SAME: !kernel_arg_type [[TYPE:![0-9]+]] ; CHECK-LLVM-SAME: !kernel_arg_base_type [[TYPE]] -; CHECK-LLVM: call spir_func <2 x i32> @_Z13get_image_dimPU3AS125opencl.image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1) -; CHECK-LLVM: call spir_func i64 @_Z20get_image_array_sizePU3AS125opencl.image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1) -; CHECK-LLVM: declare spir_func <2 x i32> @_Z13get_image_dimPU3AS125opencl.image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1) -; CHECK-LLVM: declare spir_func i64 @_Z20get_image_array_sizePU3AS125opencl.image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1) +; CHECK-LLVM: call spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_wo(%opencl.image2d_array_wo_t addrspace(1) +; CHECK-LLVM: call spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_wo(%opencl.image2d_array_wo_t addrspace(1) +; CHECK-LLVM: declare spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_wo(%opencl.image2d_array_wo_t addrspace(1) +; CHECK-LLVM: declare spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_wo(%opencl.image2d_array_wo_t addrspace(1) ; CHECK-LLVM-DAG: [[AQ]] = !{!"write_only"} ; CHECK-LLVM-DAG: [[TYPE]] = !{!"image2d_array_t"} @@ -25,9 +25,9 @@ target triple = "spir64-unknown-unknown" ; Function Attrs: nounwind define spir_kernel void @sample_kernel(%opencl.image2d_array_wo_t addrspace(1)* %input) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !5 !kernel_arg_type_qual !4 { entry: - %call.tmp1 = call spir_func <2 x i32> @_Z13get_image_dimPU3AS125opencl.image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1)* %input) + %call.tmp1 = call spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1)* %input) %call.tmp2 = shufflevector <2 x i32> %call.tmp1, <2 x i32> undef, <3 x i32> - %call.tmp3 = call spir_func i64 @_Z20get_image_array_sizePU3AS125opencl.image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1)* %input) + %call.tmp3 = call spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1)* %input) %call.tmp4 = trunc i64 %call.tmp3 to i32 %call.tmp5 = insertelement <3 x i32> %call.tmp2, i32 %call.tmp4, i32 2 %call.old = extractelement <3 x i32> %call.tmp5, i32 0 @@ -35,10 +35,10 @@ entry: } ; Function Attrs: nounwind -declare spir_func <2 x i32> @_Z13get_image_dimPU3AS125opencl.image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1)*) #0 +declare spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1)*) #0 ; Function Attrs: nounwind -declare spir_func i64 @_Z20get_image_array_sizePU3AS125opencl.image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1)*) #0 +declare spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_wo_t(%opencl.image2d_array_wo_t addrspace(1)*) #0 attributes #0 = { nounwind } diff --git a/llvm-spirv/test/transcoding/cl-types.ll b/llvm-spirv/test/transcoding/cl-types.ll index 3361ab229d94a..a1e83e5e97fbb 100644 --- a/llvm-spirv/test/transcoding/cl-types.ll +++ b/llvm-spirv/test/transcoding/cl-types.ll @@ -49,19 +49,24 @@ target triple = "spir-unknown-unknown" ; CHECK-LLVM-DAG: %opencl.pipe_ro_t = type opaque ; CHECK-LLVM-DAG: %opencl.pipe_wo_t = type opaque -; CHECK-LLVM-DAG: %opencl.image3d_t = type opaque -; CHECK-LLVM-DAG: %opencl.image2d_array_t = type opaque -; CHECK-LLVM-DAG: %opencl.image1d_buffer_t = type opaque -; CHECK-LLVM-DAG: %opencl.image1d_t = type opaque -; CHECK-LLVM-DAG: %opencl.image2d_t = type opaque +; CHECK-LLVM-DAG: %opencl.image3d_ro_t = type opaque +; CHECK-LLVM-DAG: %opencl.image2d_array_ro_t = type opaque +; CHECK-LLVM-DAG: %opencl.image1d_buffer_ro_t = type opaque +; CHECK-LLVM-DAG: %opencl.image1d_ro_t = type opaque +; CHECK-LLVM-DAG: %opencl.image1d_wo_t = type opaque +; CHECK-LLVM-DAG: %opencl.image2d_rw_t = type opaque +; CHECK-LLVM-DAG: %opencl.image2d_ro_t = type opaque %opencl.pipe_ro_t = type opaque %opencl.pipe_wo_t = type opaque -%opencl.image3d_t = type opaque -%opencl.image2d_array_t = type opaque -%opencl.image1d_buffer_t = type opaque -%opencl.image1d_t = type opaque -%opencl.image2d_t = type opaque +%opencl.image3d_ro_t = type opaque +%opencl.image2d_array_ro_t = type opaque +%opencl.image1d_buffer_ro_t = type opaque +%opencl.image1d_ro_t = type opaque +%opencl.image1d_wo_t = type opaque +%opencl.image2d_rw_t = type opaque +%opencl.image2d_ro_t = type opaque +%opencl.sampler_t = type opaque ; CHECK-SPIRV: 3 FunctionParameter [[PIPE_RD]] {{[0-9]+}} ; CHECK-SPIRV: 3 FunctionParameter [[PIPE_WR]] {{[0-9]+}} @@ -77,14 +82,14 @@ target triple = "spir-unknown-unknown" ; CHECK-LLVM: define spir_kernel void @foo( ; CHECK-LLVM-SAME: %opencl.pipe_ro_t addrspace(1)* nocapture %a, ; CHECK-LLVM-SAME: %opencl.pipe_wo_t addrspace(1)* nocapture %b, -; CHECK-LLVM-SAME: %opencl.image1d_t addrspace(1)* nocapture %c1, -; CHECK-LLVM-SAME: %opencl.image2d_t addrspace(1)* nocapture %d1, -; CHECK-LLVM-SAME: %opencl.image3d_t addrspace(1)* nocapture %e1, -; CHECK-LLVM-SAME: %opencl.image2d_array_t addrspace(1)* nocapture %f1, -; CHECK-LLVM-SAME: %opencl.image1d_buffer_t addrspace(1)* nocapture %g1, -; CHECK-LLVM-SAME: %opencl.image1d_t addrspace(1)* nocapture %c2, -; CHECK-LLVM-SAME: %opencl.image2d_t addrspace(1)* nocapture %d3, -; CHECK-LLVM-SAME: i32 %s) +; CHECK-LLVM-SAME: %opencl.image1d_ro_t addrspace(1)* nocapture %c1, +; CHECK-LLVM-SAME: %opencl.image2d_ro_t addrspace(1)* nocapture %d1, +; CHECK-LLVM-SAME: %opencl.image3d_ro_t addrspace(1)* nocapture %e1, +; CHECK-LLVM-SAME: %opencl.image2d_array_ro_t addrspace(1)* nocapture %f1, +; CHECK-LLVM-SAME: %opencl.image1d_buffer_ro_t addrspace(1)* nocapture %g1, +; CHECK-LLVM-SAME: %opencl.image1d_wo_t addrspace(1)* nocapture %c2, +; CHECK-LLVM-SAME: %opencl.image2d_rw_t addrspace(1)* nocapture %d3, +; CHECK-LLVM-SAME: %opencl.sampler_t* %s) ; CHECK-LLVM-SAME: !kernel_arg_addr_space [[AS:![0-9]+]] ; CHECK-LLVM-SAME: !kernel_arg_access_qual [[AQ:![0-9]+]] ; CHECK-LLVM-SAME: !kernel_arg_type [[TYPE:![0-9]+]] @@ -95,28 +100,32 @@ target triple = "spir-unknown-unknown" define spir_kernel void @foo( %opencl.pipe_ro_t addrspace(1)* nocapture %a, %opencl.pipe_wo_t addrspace(1)* nocapture %b, - %opencl.image1d_t addrspace(1)* nocapture %c1, - %opencl.image2d_t addrspace(1)* nocapture %d1, - %opencl.image3d_t addrspace(1)* nocapture %e1, - %opencl.image2d_array_t addrspace(1)* nocapture %f1, - %opencl.image1d_buffer_t addrspace(1)* nocapture %g1, - %opencl.image1d_t addrspace(1)* nocapture %c2, - %opencl.image2d_t addrspace(1)* nocapture %d3, - i32 %s) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !4 !kernel_arg_type_qual !5 { + %opencl.image1d_ro_t addrspace(1)* nocapture %c1, + %opencl.image2d_ro_t addrspace(1)* nocapture %d1, + %opencl.image3d_ro_t addrspace(1)* nocapture %e1, + %opencl.image2d_array_ro_t addrspace(1)* nocapture %f1, + %opencl.image1d_buffer_ro_t addrspace(1)* nocapture %g1, + %opencl.image1d_wo_t addrspace(1)* nocapture %c2, + %opencl.image2d_rw_t addrspace(1)* nocapture %d3, + %opencl.sampler_t* %s) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !4 !kernel_arg_type_qual !5 { entry: ; CHECK-SPIRV: 5 SampledImage [[SAMPIMG]] [[SAMPIMG_VAR1:[0-9]+]] [[IMG_ARG]] [[SAMP_ARG]] ; CHECK-SPIRV: 7 ImageSampleExplicitLod {{[0-9]+}} {{[0-9]+}} [[SAMPIMG_VAR1]] -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv4_if(%opencl.image2d_t addrspace(1)* %d1, i32 %s, <4 x i32> zeroinitializer, float 1.000000e+00) - %.tmp = call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv4_if(%opencl.image2d_t addrspace(1)* %d1, i32 %s, <4 x i32> zeroinitializer, float 1.000000e+00) +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv4_if(%opencl.image2d_ro_t addrspace(1)* %d1, %opencl.sampler_t* %s, <4 x i32> zeroinitializer, float 1.000000e+00) + %.tmp = call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv4_if(%opencl.image2d_ro_t addrspace(1)* %d1, %opencl.sampler_t* %s, <4 x i32> zeroinitializer, float 1.000000e+00) ; CHECK-SPIRV: 5 SampledImage [[SAMPIMG]] [[SAMPIMG_VAR2:[0-9]+]] [[IMG_ARG]] [[SAMP_CONST]] ; CHECK-SPIRV: 7 ImageSampleExplicitLod {{[0-9]+}} {{[0-9]+}} [[SAMPIMG_VAR2]] -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv4_if(%opencl.image2d_t addrspace(1)* %d1, i32 32, <4 x i32> zeroinitializer, float 1.000000e+00) - %.tmp2 = call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv4_if(%opencl.image2d_t addrspace(1)* %d1, i32 32, <4 x i32> zeroinitializer, float 1.000000e+00) +; CHECK-LLVM: [[SAMP_VAR:%[0-9]+]] = call %opencl.sampler_t* @__translate_sampler_initializer(i32 32) +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv4_if(%opencl.image2d_ro_t addrspace(1)* %d1, %opencl.sampler_t* [[SAMP_VAR]], <4 x i32> zeroinitializer, float 1.000000e+00) + %0 = call %opencl.sampler_t* @__translate_sampler_initializer(i32 32) + %.tmp2 = call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv4_if(%opencl.image2d_ro_t addrspace(1)* %d1, %opencl.sampler_t* %0, <4 x i32> zeroinitializer, float 1.000000e+00) ret void } -declare spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv4_if(%opencl.image2d_t addrspace(1)*, i32, <4 x i32>, float) #1 +declare spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv4_if(%opencl.image2d_ro_t addrspace(1)*, %opencl.sampler_t*, <4 x i32>, float) #1 + +declare %opencl.sampler_t* @__translate_sampler_initializer(i32) attributes #0 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } diff --git a/llvm-spirv/test/transcoding/cl_intel_sub_groups.ll b/llvm-spirv/test/transcoding/cl_intel_sub_groups.ll index 1c95d89a4cc58..415b5b65aec58 100644 --- a/llvm-spirv/test/transcoding/cl_intel_sub_groups.ll +++ b/llvm-spirv/test/transcoding/cl_intel_sub_groups.ll @@ -22,7 +22,7 @@ ; RUN: llvm-as %s -o %t.bc ; RUN: llvm-spirv %t.bc -o - -spirv-text | FileCheck %s --check-prefix=CHECK-SPIRV ; RUN: llvm-spirv %t.bc -o %t.spv -; RUN: llvm-spirv -r -spirv-gen-image-type-acc-postfix %t.spv -o %t.rev.bc +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM ; CHECK-SPIRV: Capability SubgroupShuffleINTEL diff --git a/llvm-spirv/test/transcoding/enqueue_kernel.ll b/llvm-spirv/test/transcoding/enqueue_kernel.ll index 0d29c719a8662..435871db0b3b3 100644 --- a/llvm-spirv/test/transcoding/enqueue_kernel.ll +++ b/llvm-spirv/test/transcoding/enqueue_kernel.ll @@ -51,11 +51,12 @@ ; ModuleID = 'enqueue_kernel.cl' source_filename = "enqueue_kernel.cl" 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" -target triple = "spir-unknown-unknown" +target triple = "spir" %opencl.queue_t = type opaque %struct.ndrange_t = type { i32 } %opencl.clk_event_t = type opaque +%struct.__opencl_block_literal_generic = type { i32, i32, i8 addrspace(4)* } ; CHECK-SPIRV: EntryPoint {{[0-9]+}} [[BlockKer1:[0-9]+]] "__device_side_enqueue_block_invoke_kernel" ; CHECK-SPIRV: EntryPoint {{[0-9]+}} [[BlockKer2:[0-9]+]] "__device_side_enqueue_block_invoke_2_kernel" @@ -66,89 +67,123 @@ target triple = "spir-unknown-unknown" ; CHECK-SPIRV: TypeInt [[Int32Ty:[0-9]+]] 32 ; CHECK-SPIRV: TypeInt [[Int8Ty:[0-9]+]] 8 -; CHECK-SPIRV: Constant [[Int32Ty]] [[ConstInt8:[0-9]+]] 8 ; CHECK-SPIRV: Constant [[Int32Ty]] [[ConstInt0:[0-9]+]] 0 -; CHECK-SPIRV: Constant [[Int32Ty]] [[ConstInt17:[0-9]+]] 17 +; CHECK-SPIRV: Constant [[Int32Ty]] [[ConstInt17:[0-9]+]] 21 ; CHECK-SPIRV: Constant [[Int32Ty]] [[ConstInt2:[0-9]+]] 2 -; CHECK-SPIRV: Constant [[Int32Ty]] [[ConstInt20:[0-9]+]] 20 -; CHECK-SPIRV: TypeVoid [[VoidTy:[0-9]+]] +; CHECK-SPIRV: Constant [[Int32Ty]] [[ConstInt8:[0-9]+]] 8 +; CHECK-SPIRV: Constant [[Int32Ty]] [[ConstInt20:[0-9]+]] 24 ; CHECK-SPIRV: TypePointer {{[0-9]+}} 7 {{[0-9]+}} +; CHECK-SPIRV: TypePointer [[Int8PtrGenTy:[0-9]+]] 8 [[Int8Ty]] +; CHECK-SPIRV: TypeVoid [[VoidTy:[0-9]+]] ; CHECK-SPIRV: TypePointer [[Int32LocPtrTy:[0-9]+]] 7 [[Int32Ty]] ; CHECK-SPIRV: TypeDeviceEvent [[EventTy:[0-9]+]] -; CHECK-SPIRV: TypePointer [[Int8PtrGenTy:[0-9]+]] 8 [[Int8Ty]] ; CHECK-SPIRV: TypePointer [[EventPtrTy:[0-9]+]] 8 [[EventTy]] ; CHECK-SPIRV: TypeFunction [[BlockTy1:[0-9]+]] [[VoidTy]] [[Int8PtrGenTy]] ; CHECK-SPIRV: TypeFunction [[BlockTy2:[0-9]+]] [[VoidTy]] [[Int8PtrGenTy]] ; CHECK-SPIRV: TypeFunction [[BlockTy3:[0-9]+]] [[VoidTy]] [[Int8PtrGenTy]] ; CHECK-SPIRV: ConstantNull [[EventPtrTy]] [[EventNull:[0-9]+]] -; CHECK-LLVM: [[BlockTy1:%[0-9]+]] = type { i32, i32 } -; CHECK-LLVM: [[BlockTy2:%[0-9]+]] = type <{ i32, i32, i32 addrspace(1)*, i32, i8 }> -; CHECK-LLVM: [[BlockTy3:%[0-9]+]] = type <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }> -; CHECK-LLVM: [[BlockTy4:%[0-9]+]] = type <{ i32, i32 }> +; CHECK-LLVM: [[BlockTy1:%[0-9]+]] = type { i32, i32, i8 addrspace(4)* } +; CHECK-LLVM: [[BlockTy2:%[0-9]+]] = type <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }> +; CHECK-LLVM: [[BlockTy3:%[0-9]+]] = type <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }> +; CHECK-LLVM: [[BlockTy4:%[0-9]+]] = type <{ i32, i32, i8 addrspace(4)* }> -; CHECK-LLVM: @__block_literal_global = internal addrspace(1) constant [[BlockTy1]] { i32 8, i32 4 }, align 4 -; CHECK-LLVM: @__block_literal_global.1 = internal addrspace(1) constant [[BlockTy1]] { i32 8, i32 4 }, align 4 +; CHECK-LLVM: @__block_literal_global = internal addrspace(1) constant [[BlockTy1]] { i32 12, i32 4, i8 addrspace(4)* addrspacecast (i8* null to i8 addrspace(4)*) }, align 4 +; CHECK-LLVM: @__block_literal_global.1 = internal addrspace(1) constant [[BlockTy1]] { i32 12, i32 4, i8 addrspace(4)* addrspacecast (i8* null to i8 addrspace(4)*) }, align 4 -@__block_literal_global = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }, align 4 -@__block_literal_global.1 = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }, align 4 +@__block_literal_global = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 12, i32 4, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* @__device_side_enqueue_block_invoke_3 to i8*) to i8 addrspace(4)*) }, align 4 +@__block_literal_global.1 = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 12, i32 4, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*, i8 addrspace(3)*, i8 addrspace(3)*)* @__device_side_enqueue_block_invoke_4 to i8*) to i8 addrspace(4)*) }, align 4 ; Function Attrs: convergent noinline nounwind optnone -define spir_kernel void @device_side_enqueue(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 %i, i8 signext %c0) #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 { +define spir_kernel void @device_side_enqueue(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 %i, i8 signext %c0) #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !4 !kernel_arg_type !5 !kernel_arg_base_type !5 !kernel_arg_type_qual !6 { entry: + %a.addr = alloca i32 addrspace(1)*, align 4 + %b.addr = alloca i32 addrspace(1)*, align 4 + %i.addr = alloca i32, align 4 + %c0.addr = alloca i8, align 1 %default_queue = alloca %opencl.queue_t*, align 4 %flags = alloca i32, align 4 %ndrange = alloca %struct.ndrange_t, align 4 %clk_event = alloca %opencl.clk_event_t*, align 4 %event_wait_list = alloca %opencl.clk_event_t*, align 4 %event_wait_list2 = alloca [1 x %opencl.clk_event_t*], align 4 - %block = alloca <{ i32, i32, i32 addrspace(1)*, i32, i8 }>, align 4 - %block3 = alloca <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, align 4 + %block = alloca <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>, align 4 + %tmp = alloca %struct.ndrange_t, align 4 + %block3 = alloca <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, align 4 + %tmp4 = alloca %struct.ndrange_t, align 4 %c = alloca i8, align 1 + %tmp11 = alloca %struct.ndrange_t, align 4 + %block_sizes = alloca [1 x i32], align 4 + %tmp12 = alloca %struct.ndrange_t, align 4 + %block_sizes13 = alloca [3 x i32], align 4 + store i32 addrspace(1)* %a, i32 addrspace(1)** %a.addr, align 4 + store i32 addrspace(1)* %b, i32 addrspace(1)** %b.addr, align 4 + store i32 %i, i32* %i.addr, align 4 + store i8 %c0, i8* %c0.addr, align 1 store i32 0, i32* %flags, align 4 %arrayinit.begin = getelementptr inbounds [1 x %opencl.clk_event_t*], [1 x %opencl.clk_event_t*]* %event_wait_list2, i32 0, i32 0 %0 = load %opencl.clk_event_t*, %opencl.clk_event_t** %clk_event, align 4 store %opencl.clk_event_t* %0, %opencl.clk_event_t** %arrayinit.begin, align 4 %1 = load %opencl.queue_t*, %opencl.queue_t** %default_queue, align 4 %2 = load i32, i32* %flags, align 4 - %block.size = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 0 - store i32 17, i32* %block.size, align 4 - %block.align = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 1 + %3 = bitcast %struct.ndrange_t* %tmp to i8* + %4 = bitcast %struct.ndrange_t* %ndrange to i8* + call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %3, i8* align 4 %4, i32 4, i1 false) + %block.size = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 0 + store i32 21, i32* %block.size, align 4 + %block.align = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 1 store i32 4, i32* %block.align, align 4 - %block.captured = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 2 - store i32 addrspace(1)* %a, i32 addrspace(1)** %block.captured, align 4 - %block.captured1 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 3 - store i32 %i, i32* %block.captured1, align 4 - %block.captured2 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 4 - store i8 %c0, i8* %block.captured2, align 4 - %3 = bitcast <{ i32, i32, i32 addrspace(1)*, i32, i8 }>* %block to void ()* - %4 = addrspacecast void ()* %3 to i8 addrspace(4)* + %block.invoke = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 2 + store i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* @__device_side_enqueue_block_invoke to i8*) to i8 addrspace(4)*), i8 addrspace(4)** %block.invoke, align 4 + %block.captured = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 3 + %5 = load i32 addrspace(1)*, i32 addrspace(1)** %a.addr, align 4 + store i32 addrspace(1)* %5, i32 addrspace(1)** %block.captured, align 4 + %block.captured1 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 4 + %6 = load i32, i32* %i.addr, align 4 + store i32 %6, i32* %block.captured1, align 4 + %block.captured2 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>* %block, i32 0, i32 5 + %7 = load i8, i8* %c0.addr, align 1 + store i8 %7, i8* %block.captured2, align 4 + %8 = bitcast <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>* %block to %struct.__opencl_block_literal_generic* + %9 = addrspacecast %struct.__opencl_block_literal_generic* %8 to i8 addrspace(4)* ; CHECK-SPIRV: PtrCastToGeneric [[Int8PtrGenTy]] [[BlockLit1:[0-9]+]] ; CHECK-SPIRV: EnqueueKernel [[Int32Ty]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} ; [[ConstInt0]] [[EventNull]] [[EventNull]] ; [[BlockKer1]] [[BlockLit1]] [[ConstInt17]] [[ConstInt8]] -; CHECK-LLVM: [[Block2:%[0-9]+]] = addrspacecast [[BlockTy2]]* %block to i8 addrspace(4)* +; CHECK-LLVM: [[Block2:%[0-9]+]] = bitcast [[BlockTy2]]* %block to %struct.__opencl_block_literal_generic* +; CHECK-LLVM: [[Block2Ptr:%[0-9]+]] = addrspacecast %struct.__opencl_block_literal_generic* [[Block2]] to i8 addrspace(4)* ; CHECK-LLVM: [[BlockInv2:%[0-9]+]] = addrspacecast void (i8 addrspace(4)*)* @__device_side_enqueue_block_invoke_kernel to i8 addrspace(4)* -; CHECK-LLVM: call i32 @__enqueue_kernel_basic_events(%opencl.queue_t* {{.*}}, i32 {{.*}}, %struct.ndrange_t* {{.*}}, i32 0, %opencl.clk_event_t* addrspace(4)* null, %opencl.clk_event_t* addrspace(4)* null, i8 addrspace(4)* [[BlockInv2]], i8 addrspace(4)* [[Block2]]) - - %5 = call i32 @__enqueue_kernel_basic(%opencl.queue_t* %1, i32 %2, %struct.ndrange_t* byval %ndrange, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* @__device_side_enqueue_block_invoke_kernel to i8*) to i8 addrspace(4)*), i8 addrspace(4)* %4) - %6 = addrspacecast %opencl.clk_event_t** %event_wait_list to %opencl.clk_event_t* addrspace(4)* - %7 = addrspacecast %opencl.clk_event_t** %clk_event to %opencl.clk_event_t* addrspace(4)* - %block.size5 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 0 - store i32 20, i32* %block.size5, align 4 - %block.align6 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 1 +; CHECK-LLVM: call i32 @__enqueue_kernel_basic_events(%opencl.queue_t* {{.*}}, i32 {{.*}}, %struct.ndrange_t* {{.*}}, i32 0, %opencl.clk_event_t* addrspace(4)* null, %opencl.clk_event_t* addrspace(4)* null, i8 addrspace(4)* [[BlockInv2]], i8 addrspace(4)* [[Block2Ptr]]) + + %10 = call i32 @__enqueue_kernel_basic(%opencl.queue_t* %1, i32 %2, %struct.ndrange_t* byval %tmp, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* @__device_side_enqueue_block_invoke_kernel to i8*) to i8 addrspace(4)*), i8 addrspace(4)* %9) + %11 = load %opencl.queue_t*, %opencl.queue_t** %default_queue, align 4 + %12 = load i32, i32* %flags, align 4 + %13 = bitcast %struct.ndrange_t* %tmp4 to i8* + %14 = bitcast %struct.ndrange_t* %ndrange to i8* + call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %13, i8* align 4 %14, i32 4, i1 false) + %15 = addrspacecast %opencl.clk_event_t** %event_wait_list to %opencl.clk_event_t* addrspace(4)* + %16 = addrspacecast %opencl.clk_event_t** %clk_event to %opencl.clk_event_t* addrspace(4)* + %block.size5 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 0 + store i32 24, i32* %block.size5, align 4 + %block.align6 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 1 store i32 4, i32* %block.align6, align 4 - %block.captured7 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 2 - store i32 addrspace(1)* %a, i32 addrspace(1)** %block.captured7, align 4 - %block.captured8 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 3 - store i32 %i, i32* %block.captured8, align 4 - %block.captured9 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 4 - store i32 addrspace(1)* %b, i32 addrspace(1)** %block.captured9, align 4 - %8 = bitcast <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3 to void ()* - %9 = addrspacecast void ()* %8 to i8 addrspace(4)* + %block.invoke7 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 2 + store i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* @__device_side_enqueue_block_invoke_2 to i8*) to i8 addrspace(4)*), i8 addrspace(4)** %block.invoke7, align 4 + %block.captured8 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 3 + %17 = load i32 addrspace(1)*, i32 addrspace(1)** %a.addr, align 4 + store i32 addrspace(1)* %17, i32 addrspace(1)** %block.captured8, align 4 + %block.captured9 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 4 + %18 = load i32, i32* %i.addr, align 4 + store i32 %18, i32* %block.captured9, align 4 + %block.captured10 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3, i32 0, i32 5 + %19 = load i32 addrspace(1)*, i32 addrspace(1)** %b.addr, align 4 + store i32 addrspace(1)* %19, i32 addrspace(1)** %block.captured10, align 4 + %20 = bitcast <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block3 to %struct.__opencl_block_literal_generic* + %21 = addrspacecast %struct.__opencl_block_literal_generic* %20 to i8 addrspace(4)* + ; CHECK-SPIRV: PtrCastToGeneric [[EventPtrTy]] [[Event1:[0-9]+]] ; CHECK-SPIRV: PtrCastToGeneric [[EventPtrTy]] [[Event2:[0-9]+]] @@ -158,16 +193,24 @@ entry: ; [[ConstInt2]] [[Event1]] [[Event2]] ; [[BlockKer2]] [[BlockLit2]] [[ConstInt20]] [[ConstInt8]] -; CHECK-LLVM: [[Block3:%[0-9]+]] = addrspacecast [[BlockTy3]]* %block3 to i8 addrspace(4)* +; CHECK-LLVM: [[Block3:%[0-9]+]] = bitcast [[BlockTy3]]* %block3 to %struct.__opencl_block_literal_generic* +; CHECK-LLVM: [[Block3Ptr:%[0-9]+]] = addrspacecast %struct.__opencl_block_literal_generic* [[Block3]] to i8 addrspace(4) ; CHECK-LLVM: [[BlockInv3:%[0-9]+]] = addrspacecast void (i8 addrspace(4)*)* @__device_side_enqueue_block_invoke_2_kernel to i8 addrspace(4)* -; CHECK-LLVM: call i32 @__enqueue_kernel_basic_events(%opencl.queue_t* {{.*}}, i32 {{.*}}, %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t* addrspace(4)* {{.*}}, %opencl.clk_event_t* addrspace(4)* {{.*}}, i8 addrspace(4)* [[BlockInv3]], i8 addrspace(4)* [[Block3]]) - - %10 = call i32 @__enqueue_kernel_basic_events(%opencl.queue_t* %1, i32 %2, %struct.ndrange_t* %ndrange, i32 2, %opencl.clk_event_t* addrspace(4)* %6, %opencl.clk_event_t* addrspace(4)* %7, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* @__device_side_enqueue_block_invoke_2_kernel to i8*) to i8 addrspace(4)*), i8 addrspace(4)* %9) - %11 = alloca [1 x i32] - %12 = getelementptr [1 x i32], [1 x i32]* %11, i32 0, i32 0 - %13 = load i8, i8* %c, align 1 - %14 = zext i8 %13 to i32 - store i32 %14, i32* %12, align 4 +; CHECK-LLVM: call i32 @__enqueue_kernel_basic_events(%opencl.queue_t* {{.*}}, i32 {{.*}}, %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t* addrspace(4)* {{.*}}, %opencl.clk_event_t* addrspace(4)* {{.*}}, i8 addrspace(4)* [[BlockInv3]], i8 addrspace(4)* [[Block3Ptr]]) + + %22 = call i32 @__enqueue_kernel_basic_events(%opencl.queue_t* %11, i32 %12, %struct.ndrange_t* %tmp4, i32 2, %opencl.clk_event_t* addrspace(4)* %15, %opencl.clk_event_t* addrspace(4)* %16, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* @__device_side_enqueue_block_invoke_2_kernel to i8*) to i8 addrspace(4)*), i8 addrspace(4)* %21) + %23 = load %opencl.queue_t*, %opencl.queue_t** %default_queue, align 4 + %24 = load i32, i32* %flags, align 4 + %25 = bitcast %struct.ndrange_t* %tmp11 to i8* + %26 = bitcast %struct.ndrange_t* %ndrange to i8* + call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %25, i8* align 4 %26, i32 4, i1 false) + %arraydecay = getelementptr inbounds [1 x %opencl.clk_event_t*], [1 x %opencl.clk_event_t*]* %event_wait_list2, i32 0, i32 0 + %27 = addrspacecast %opencl.clk_event_t** %arraydecay to %opencl.clk_event_t* addrspace(4)* + %28 = addrspacecast %opencl.clk_event_t** %clk_event to %opencl.clk_event_t* addrspace(4)* + %29 = getelementptr [1 x i32], [1 x i32]* %block_sizes, i32 0, i32 0 + %30 = load i8, i8* %c, align 1 + %31 = zext i8 %30 to i32 + store i32 %31, i32* %29, align 4 ; CHECK-SPIRV: PtrAccessChain [[Int32LocPtrTy]] [[LocalBuf31:[0-9]+]] ; CHECK-SPIRV: Bitcast {{[0-9]+}} [[BlockLit3Tmp:[0-9]+]] [[BlockGlb1:[0-9]+]] @@ -182,14 +225,18 @@ entry: ; CHECK-LLVM: [[BlockInv0:%[0-9]+]] = addrspacecast void (i8 addrspace(4)*, i8 addrspace(3)*)* @__device_side_enqueue_block_invoke_3_kernel to i8 addrspace(4)* ; CHECK-LLVM: call i32 @__enqueue_kernel_events_varargs(%opencl.queue_t* {{.*}}, i32 {{.*}}, %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t* addrspace(4)* {{.*}}, %opencl.clk_event_t* addrspace(4)* {{.*}}, i8 addrspace(4)* [[BlockInv0]], i8 addrspace(4)* [[Block0]], i32 1, i32* {{.*}}) - %15 = call i32 @__enqueue_kernel_events_varargs(%opencl.queue_t* %1, i32 %2, %struct.ndrange_t* %ndrange, i32 2, %opencl.clk_event_t* addrspace(4)* %6, %opencl.clk_event_t* addrspace(4)* %7, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* @__device_side_enqueue_block_invoke_3_kernel to i8*) to i8 addrspace(4)*), i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* @__block_literal_global to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i32* %12) - %16 = alloca [3 x i32] - %17 = getelementptr [3 x i32], [3 x i32]* %16, i32 0, i32 0 - store i32 1, i32* %17, align 4 - %18 = getelementptr [3 x i32], [3 x i32]* %16, i32 0, i32 1 - store i32 2, i32* %18, align 4 - %19 = getelementptr [3 x i32], [3 x i32]* %16, i32 0, i32 2 - store i32 4, i32* %19, align 4 + %32 = call i32 @__enqueue_kernel_events_varargs(%opencl.queue_t* %23, i32 %24, %struct.ndrange_t* %tmp11, i32 2, %opencl.clk_event_t* addrspace(4)* %27, %opencl.clk_event_t* addrspace(4)* %28, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* @__device_side_enqueue_block_invoke_3_kernel to i8*) to i8 addrspace(4)*), i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i32* %29) + %33 = load %opencl.queue_t*, %opencl.queue_t** %default_queue, align 4 + %34 = load i32, i32* %flags, align 4 + %35 = bitcast %struct.ndrange_t* %tmp12 to i8* + %36 = bitcast %struct.ndrange_t* %ndrange to i8* + call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %35, i8* align 4 %36, i32 4, i1 false) + %37 = getelementptr [3 x i32], [3 x i32]* %block_sizes13, i32 0, i32 0 + store i32 1, i32* %37, align 4 + %38 = getelementptr [3 x i32], [3 x i32]* %block_sizes13, i32 0, i32 1 + store i32 2, i32* %38, align 4 + %39 = getelementptr [3 x i32], [3 x i32]* %block_sizes13, i32 0, i32 2 + store i32 4, i32* %39, align 4 ; CHECK-SPIRV: PtrAccessChain [[Int32LocPtrTy]] [[LocalBuf41:[0-9]+]] ; CHECK-SPIRV: PtrAccessChain [[Int32LocPtrTy]] [[LocalBuf42:[0-9]+]] @@ -206,24 +253,27 @@ entry: ; CHECK-LLVM: [[BlockInv1:%[0-9]+]] = addrspacecast void (i8 addrspace(4)*, i8 addrspace(3)*, i8 addrspace(3)*, i8 addrspace(3)*)* @__device_side_enqueue_block_invoke_4_kernel to i8 addrspace(4)* ; CHECK-LLVM: call i32 @__enqueue_kernel_events_varargs(%opencl.queue_t* {{.*}}, i32 {{.*}}, %struct.ndrange_t* {{.*}}, i32 0, %opencl.clk_event_t* addrspace(4)* null, %opencl.clk_event_t* addrspace(4)* null, i8 addrspace(4)* [[BlockInv1]], i8 addrspace(4)* [[Block1]], i32 3, i32* {{.*}}) - %20 = call i32 @__enqueue_kernel_varargs(%opencl.queue_t* %1, i32 %2, %struct.ndrange_t* %ndrange, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*, i8 addrspace(3)*, i8 addrspace(3)*)* @__device_side_enqueue_block_invoke_4_kernel to i8*) to i8 addrspace(4)*), i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* @__block_literal_global.1 to i8 addrspace(1)*) to i8 addrspace(4)*), i32 3, i32* %17) + %40 = call i32 @__enqueue_kernel_varargs(%opencl.queue_t* %33, i32 %34, %struct.ndrange_t* %tmp12, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*, i8 addrspace(3)*, i8 addrspace(3)*)* @__device_side_enqueue_block_invoke_4_kernel to i8*) to i8 addrspace(4)*), i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global.1 to i8 addrspace(1)*) to i8 addrspace(4)*), i32 3, i32* %37) ret void } +; Function Attrs: argmemonly nounwind +declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1) #1 + ; Function Attrs: convergent noinline nounwind optnone define internal spir_func void @__device_side_enqueue_block_invoke(i8 addrspace(4)* %.block_descriptor) #2 { entry: %.block_descriptor.addr = alloca i8 addrspace(4)*, align 4 - %block.addr = alloca <{ i32, i32, i32 addrspace(1)*, i32, i8 }> addrspace(4)*, align 4 + %block.addr = alloca <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }> addrspace(4)*, align 4 store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 4 - %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i32 addrspace(1)*, i32, i8 }> addrspace(4)* - store <{ i32, i32, i32 addrspace(1)*, i32, i8 }> addrspace(4)* %block, <{ i32, i32, i32 addrspace(1)*, i32, i8 }> addrspace(4)** %block.addr, align 4 - %block.capture.addr = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i32 addrspace(1)*, i32, i8 }> addrspace(4)* %block, i32 0, i32 4 + %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }> addrspace(4)* + store <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }> addrspace(4)* %block, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }> addrspace(4)** %block.addr, align 4 + %block.capture.addr = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }> addrspace(4)* %block, i32 0, i32 5 %0 = load i8, i8 addrspace(4)* %block.capture.addr, align 4 %conv = sext i8 %0 to i32 - %block.capture.addr1 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i32 addrspace(1)*, i32, i8 }> addrspace(4)* %block, i32 0, i32 2 + %block.capture.addr1 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }> addrspace(4)* %block, i32 0, i32 3 %1 = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(4)* %block.capture.addr1, align 4 - %block.capture.addr2 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i32 addrspace(1)*, i32, i8 }> addrspace(4)* %block, i32 0, i32 3 + %block.capture.addr2 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i8 }> addrspace(4)* %block, i32 0, i32 4 %2 = load i32, i32 addrspace(4)* %block.capture.addr2, align 4 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %1, i32 %2 store i32 %conv, i32 addrspace(1)* %arrayidx, align 4 @@ -243,19 +293,19 @@ declare i32 @__enqueue_kernel_basic(%opencl.queue_t*, i32, %struct.ndrange_t*, i define internal spir_func void @__device_side_enqueue_block_invoke_2(i8 addrspace(4)* %.block_descriptor) #2 { entry: %.block_descriptor.addr = alloca i8 addrspace(4)*, align 4 - %block.addr = alloca <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)*, align 4 + %block.addr = alloca <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)*, align 4 store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 4 - %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* - store <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* %block, <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)** %block.addr, align 4 - %block.capture.addr = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* %block, i32 0, i32 4 + %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* + store <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* %block, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)** %block.addr, align 4 + %block.capture.addr = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* %block, i32 0, i32 5 %0 = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(4)* %block.capture.addr, align 4 - %block.capture.addr1 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* %block, i32 0, i32 3 + %block.capture.addr1 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* %block, i32 0, i32 4 %1 = load i32, i32 addrspace(4)* %block.capture.addr1, align 4 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %0, i32 %1 %2 = load i32, i32 addrspace(1)* %arrayidx, align 4 - %block.capture.addr2 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* %block, i32 0, i32 2 + %block.capture.addr2 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* %block, i32 0, i32 3 %3 = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(4)* %block.capture.addr2, align 4 - %block.capture.addr3 = getelementptr inbounds <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* %block, i32 0, i32 3 + %block.capture.addr3 = getelementptr inbounds <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>, <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }> addrspace(4)* %block, i32 0, i32 4 %4 = load i32, i32 addrspace(4)* %block.capture.addr3, align 4 %arrayidx4 = getelementptr inbounds i32, i32 addrspace(1)* %3, i32 %4 store i32 %2, i32 addrspace(1)* %arrayidx4, align 4 @@ -276,11 +326,11 @@ define internal spir_func void @__device_side_enqueue_block_invoke_3(i8 addrspac entry: %.block_descriptor.addr = alloca i8 addrspace(4)*, align 4 %p.addr = alloca i8 addrspace(3)*, align 4 - %block.addr = alloca <{ i32, i32 }> addrspace(4)*, align 4 + %block.addr = alloca <{ i32, i32, i8 addrspace(4)* }> addrspace(4)*, align 4 store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 4 - %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32 }> addrspace(4)* + %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* store i8 addrspace(3)* %p, i8 addrspace(3)** %p.addr, align 4 - store <{ i32, i32 }> addrspace(4)* %block, <{ i32, i32 }> addrspace(4)** %block.addr, align 4 + store <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* %block, <{ i32, i32, i8 addrspace(4)* }> addrspace(4)** %block.addr, align 4 ret void } @@ -300,13 +350,13 @@ entry: %p1.addr = alloca i8 addrspace(3)*, align 4 %p2.addr = alloca i8 addrspace(3)*, align 4 %p3.addr = alloca i8 addrspace(3)*, align 4 - %block.addr = alloca <{ i32, i32 }> addrspace(4)*, align 4 + %block.addr = alloca <{ i32, i32, i8 addrspace(4)* }> addrspace(4)*, align 4 store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 4 - %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32 }> addrspace(4)* + %block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* store i8 addrspace(3)* %p1, i8 addrspace(3)** %p1.addr, align 4 store i8 addrspace(3)* %p2, i8 addrspace(3)** %p2.addr, align 4 store i8 addrspace(3)* %p3, i8 addrspace(3)** %p3.addr, align 4 - store <{ i32, i32 }> addrspace(4)* %block, <{ i32, i32 }> addrspace(4)** %block.addr, align 4 + store <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* %block, <{ i32, i32, i8 addrspace(4)* }> addrspace(4)** %block.addr, align 4 ret void } @@ -329,27 +379,20 @@ declare i32 @__enqueue_kernel_varargs(%opencl.queue_t*, i32, %struct.ndrange_t*, ; CHECK-LLVM-DAG: define spir_kernel void @__device_side_enqueue_block_invoke_3_kernel(i8 addrspace(4)*, i8 addrspace(3)*) ; CHECK-LLVM-DAG: define spir_kernel void @__device_side_enqueue_block_invoke_4_kernel(i8 addrspace(4)*, i8 addrspace(3)*, i8 addrspace(3)*, i8 addrspace(3)*) -attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #1 = { argmemonly nounwind } -attributes #2 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #3 = { nounwind } !llvm.module.flags = !{!0} -!opencl.enable.FP_CONTRACT = !{} !opencl.ocl.version = !{!1} !opencl.spir.version = !{!1} -!opencl.used.extensions = !{!2} -!opencl.used.optional.core.features = !{!2} -!opencl.compiler.options = !{!2} -!llvm.ident = !{!3} +!llvm.ident = !{!2} !0 = !{i32 1, !"wchar_size", i32 4} !1 = !{i32 2, i32 0} -!2 = !{} -!3 = !{!"clang version 7.0.0"} -!4 = !{i32 1, i32 1, i32 0, i32 0} -!5 = !{!"none", !"none", !"none", !"none"} -!6 = !{!"int*", !"int*", !"int", !"char"} -!7 = !{!"", !"", !"", !""} -!8 = !{i1 false, i1 false, i1 false, i1 false} -!9 = !{i32 0, i32 0, i32 0, i32 0} +!2 = !{!"clang version 9.0.0 (https://llvm.org/git/clang 04fb8964a801a5c5d7baa5a22272243a7d183896) (https://llvm.org/git/llvm 384f64397f6ad95a361b72d62c07d7bac9f24163)"} +!3 = !{i32 1, i32 1, i32 0, i32 0} +!4 = !{!"none", !"none", !"none", !"none"} +!5 = !{!"int*", !"int*", !"int", !"char"} +!6 = !{!"", !"", !"", !""} diff --git a/llvm-spirv/test/transcoding/image_builtins.ll b/llvm-spirv/test/transcoding/image_builtins.ll new file mode 100644 index 0000000000000..1a9fd6f6f5c3b --- /dev/null +++ b/llvm-spirv/test/transcoding/image_builtins.ll @@ -0,0 +1,83 @@ +; RUN: llvm-as %s -o %t.bc +; RUN: llvm-spirv %t.bc -o %t.spv +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc +; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM + +; ModuleID = 'image_builtins.cl' +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" +target triple = "spir-unknown-unknown" + +%opencl.image2d_ro_t = type opaque +%opencl.sampler_t = type opaque +%opencl.image2d_wo_t = type opaque + +; CHECK-LLVM-LABEL: @nosamp +; CHECK-LLVM: call spir_func <4 x half> @_Z11read_imageh14ocl_image2d_roDv2_i + +; CHECK-LLVM-LABEL: @withsamp +; CHECK-LLVM: call spir_func <4 x half> @_Z11read_imageh14ocl_image2d_ro11ocl_samplerDv2_i + +; CHECK-LLVM-LABEL: @writehalf +; CHECK-LLVM: call spir_func void @_Z12write_imageh14ocl_image2d_woDv2_iDv4_Dh + +; Function Attrs: convergent nounwind +define spir_kernel void @nosamp(%opencl.image2d_ro_t addrspace(1)* %im, <2 x i32> %coord, <4 x half> addrspace(1)* nocapture %res) local_unnamed_addr #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !4 !kernel_arg_type !5 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 { +entry: + %call = tail call spir_func <4 x half> @_Z11read_imageh14ocl_image2d_roDv2_i(%opencl.image2d_ro_t addrspace(1)* %im, <2 x i32> %coord) #3 + store <4 x half> %call, <4 x half> addrspace(1)* %res, align 8, !tbaa !8 + ret void +} + +; Function Attrs: convergent nounwind readonly +declare spir_func <4 x half> @_Z11read_imageh14ocl_image2d_roDv2_i(%opencl.image2d_ro_t addrspace(1)*, <2 x i32>) local_unnamed_addr #1 + +; Function Attrs: convergent nounwind +define spir_kernel void @withsamp(%opencl.image2d_ro_t addrspace(1)* %im, %opencl.sampler_t addrspace(2)* %smp, <2 x i32> %coord, <4 x half> addrspace(1)* nocapture %res) local_unnamed_addr #0 !kernel_arg_addr_space !11 !kernel_arg_access_qual !12 !kernel_arg_type !13 !kernel_arg_base_type !14 !kernel_arg_type_qual !15 { +entry: + %call = tail call spir_func <4 x half> @_Z11read_imageh14ocl_image2d_ro11ocl_samplerDv2_i(%opencl.image2d_ro_t addrspace(1)* %im, %opencl.sampler_t addrspace(2)* %smp, <2 x i32> %coord) #3 + store <4 x half> %call, <4 x half> addrspace(1)* %res, align 8, !tbaa !8 + ret void +} + +; Function Attrs: convergent nounwind readonly +declare spir_func <4 x half> @_Z11read_imageh14ocl_image2d_ro11ocl_samplerDv2_i(%opencl.image2d_ro_t addrspace(1)*, %opencl.sampler_t addrspace(2)*, <2 x i32>) local_unnamed_addr #1 + +; Function Attrs: convergent nounwind +define spir_kernel void @writehalf(%opencl.image2d_wo_t addrspace(1)* %im, <2 x i32> %coord, <4 x half> addrspace(1)* nocapture readonly %val) local_unnamed_addr #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !16 !kernel_arg_type !5 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 { +entry: + %0 = load <4 x half>, <4 x half> addrspace(1)* %val, align 8, !tbaa !8 + tail call spir_func void @_Z12write_imageh14ocl_image2d_woDv2_iDv4_Dh(%opencl.image2d_wo_t addrspace(1)* %im, <2 x i32> %coord, <4 x half> %0) #4 + ret void +} + +; Function Attrs: convergent +declare spir_func void @_Z12write_imageh14ocl_image2d_woDv2_iDv4_Dh(%opencl.image2d_wo_t addrspace(1)*, <2 x i32>, <4 x half>) local_unnamed_addr #2 + +attributes #0 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="64" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { convergent nounwind readonly "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { convergent "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #3 = { convergent nounwind readonly } +attributes #4 = { convergent nounwind } + +!llvm.module.flags = !{!0} +!opencl.ocl.version = !{!1} +!opencl.spir.version = !{!1} +!llvm.ident = !{!2} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 2, i32 0} +!2 = !{!"clang version 8.0.0"} +!3 = !{i32 1, i32 0, i32 1} +!4 = !{!"read_only", !"none", !"none"} +!5 = !{!"image2d_t", !"int2", !"half4*"} +!6 = !{!"image2d_t", !"int __attribute__((ext_vector_type(2)))", !"half __attribute__((ext_vector_type(4)))*"} +!7 = !{!"", !"", !""} +!8 = !{!9, !9, i64 0} +!9 = !{!"omnipotent char", !10, i64 0} +!10 = !{!"Simple C/C++ TBAA"} +!11 = !{i32 1, i32 0, i32 0, i32 1} +!12 = !{!"read_only", !"none", !"none", !"none"} +!13 = !{!"image2d_t", !"sampler_t", !"int2", !"half4*"} +!14 = !{!"image2d_t", !"sampler_t", !"int __attribute__((ext_vector_type(2)))", !"half __attribute__((ext_vector_type(4)))*"} +!15 = !{!"", !"", !"", !""} +!16 = !{!"write_only", !"none", !"none"} diff --git a/llvm-spirv/test/transcoding/image_channel.ll b/llvm-spirv/test/transcoding/image_channel.ll index e94b6c2c99a3f..1c51d22dbd1be 100644 --- a/llvm-spirv/test/transcoding/image_channel.ll +++ b/llvm-spirv/test/transcoding/image_channel.ll @@ -9,36 +9,36 @@ 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" target triple = "spir-unknown-unknown" -%opencl.image2d_t = type opaque +%opencl.image2d_ro_t = type opaque ; CHECK-SPIRV-DAG: 4 Constant {{[0-9]+}} [[DataTypeOffsetId:[0-9]+]] 4304 ; CHECK-SPIRV-DAG: 4 Constant {{[0-9]+}} [[OrderOffsetId:[0-9]+]] 4272 ; Function Attrs: nounwind -define spir_kernel void @f(%opencl.image2d_t addrspace(1)* %img, i32 addrspace(1)* nocapture %type, i32 addrspace(1)* nocapture %order) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !4 !kernel_arg_type_qual !5 { -; CHECK-LLVM-DAG: [[DTCALL:%.+]] ={{.*}} call spir_func i32 @_Z27get_image_channel_data_type11ocl_image2d +define spir_kernel void @f(%opencl.image2d_ro_t addrspace(1)* %img, i32 addrspace(1)* nocapture %type, i32 addrspace(1)* nocapture %order) #0 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !4 !kernel_arg_type_qual !5 { +; CHECK-LLVM-DAG: [[DTCALL:%.+]] ={{.*}} call spir_func i32 @_Z27get_image_channel_data_type14ocl_image2d_ro ; CHECK-LLVM: [[DTSUB:%.+]] = sub i32 [[DTCALL]], 4304 ; CHECK-LLVM: [[DTADD:%.+]] = add i32 [[DTSUB]], 4304 ; CHECK-LLVM: store i32 [[DTADD]] ; CHECK-SPIRV: 4 ImageQueryFormat {{[0-9]+}} [[DataTypeID:[0-9]+]] ; CHECK-SPIRV: 5 IAdd {{[0-9]+}} [[DTAddID:[0-9]+]] [[DataTypeID]] [[DataTypeOffsetId]] ; CHECK-SPIRV: 5 Store {{[0-9]+}} [[DTAddID]] - %1 = tail call spir_func i32 @_Z27get_image_channel_data_type11ocl_image2d(%opencl.image2d_t addrspace(1)* %img) #2 + %1 = tail call spir_func i32 @_Z27get_image_channel_data_type14ocl_image2d_ro(%opencl.image2d_ro_t addrspace(1)* %img) #2 store i32 %1, i32 addrspace(1)* %type, align 4 -; CHECK-LLVM-DAG: [[OCALL:%.+]] ={{.*}} call spir_func i32 @_Z23get_image_channel_order11ocl_image2d +; CHECK-LLVM-DAG: [[OCALL:%.+]] ={{.*}} call spir_func i32 @_Z23get_image_channel_order14ocl_image2d_ro ; CHECK-LLVM: [[OSUB:%.+]] = sub i32 [[OCALL]], 4272 ; CHECK-LLVM: [[OADD:%.+]] = add i32 [[OSUB]], 4272 ; CHECK-LLVM: store i32 [[OADD]] ; CHECK-SPIRV: 4 ImageQueryOrder {{[0-9]+}} [[OrderID:[0-9]+]] ; CHECK-SPIRV: 5 IAdd {{[0-9]+}} [[OrderAddID:[0-9]+]] [[OrderID]] [[OrderOffsetId]] ; CHECK-SPIRV: 5 Store {{[0-9]+}} [[OrderAddID]] - %2 = tail call spir_func i32 @_Z23get_image_channel_order11ocl_image2d(%opencl.image2d_t addrspace(1)* %img) #2 + %2 = tail call spir_func i32 @_Z23get_image_channel_order14ocl_image2d_ro(%opencl.image2d_ro_t addrspace(1)* %img) #2 store i32 %2, i32 addrspace(1)* %order, align 4 ret void } -declare spir_func i32 @_Z27get_image_channel_data_type11ocl_image2d(%opencl.image2d_t addrspace(1)*) #1 +declare spir_func i32 @_Z27get_image_channel_data_type14ocl_image2d_ro(%opencl.image2d_ro_t addrspace(1)*) #1 -declare spir_func i32 @_Z23get_image_channel_order11ocl_image2d(%opencl.image2d_t addrspace(1)*) #1 +declare spir_func i32 @_Z23get_image_channel_order14ocl_image2d_ro(%opencl.image2d_ro_t addrspace(1)*) #1 attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } diff --git a/llvm-spirv/test/transcoding/image_get_size_with_access_qualifiers.ll b/llvm-spirv/test/transcoding/image_get_size_with_access_qualifiers.ll index b7e0cf86d3978..db2477b4ddb4b 100644 --- a/llvm-spirv/test/transcoding/image_get_size_with_access_qualifiers.ll +++ b/llvm-spirv/test/transcoding/image_get_size_with_access_qualifiers.ll @@ -12,7 +12,7 @@ ; CHECK-SPIRV: FunctionParameter [[ImageTyID]] [[ImageArgID:[0-9]+]] ; CHECK-SPIRV: ImageQuerySizeLod [[VectorTyID]] {{[0-9]+}} [[ImageArgID]] -; CHECK-LLVM: call spir_func <2 x i32> @_Z13get_image_dim16ocl_image2darray(%opencl.image2d_array_t addrspace(1)* +; CHECK-LLVM: call spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)* target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" target triple = "spir64" diff --git a/llvm-spirv/test/transcoding/image_with_access_qualifiers.ll b/llvm-spirv/test/transcoding/image_with_access_qualifiers.ll index dcf42181cdc6d..8ca694870d5f1 100644 --- a/llvm-spirv/test/transcoding/image_with_access_qualifiers.ll +++ b/llvm-spirv/test/transcoding/image_with_access_qualifiers.ll @@ -6,7 +6,7 @@ ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM ; NOTE: access qualifier infomation is not preserved after round-trip conversion to LLVM -; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef11ocl_image1d11ocl_sampleri(%opencl.image1d_t +; CHECK-LLVM: call spir_func <4 x float> @_Z11read_imagef14ocl_image1d_rw11ocl_sampleri(%opencl.image1d_rw_t ; CHECK-SPIRV-DAG: 2 Capability ImageBasic ; CHECK-SPIRV-DAG: 2 Capability ImageReadWrite diff --git a/llvm-spirv/test/transcoding/image_with_suffix.ll b/llvm-spirv/test/transcoding/image_with_suffix.ll index fc5dd42f162e5..36640c712afdd 100644 --- a/llvm-spirv/test/transcoding/image_with_suffix.ll +++ b/llvm-spirv/test/transcoding/image_with_suffix.ll @@ -6,7 +6,7 @@ ; RUN: llvm-spirv -r %t.spv -o %t.rev.bc ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM -; CHECK-LLVM: call spir_func i32 @_Z15get_image_width11ocl_image1d +; CHECK-LLVM: call spir_func i32 @_Z15get_image_width14ocl_image1d_ro ; ModuleID = 'foo.ll' 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" diff --git a/llvm-spirv/test/transcoding/spirv-types.ll b/llvm-spirv/test/transcoding/spirv-types.ll index 92b6bc40c8f10..969f9f2178201 100644 --- a/llvm-spirv/test/transcoding/spirv-types.ll +++ b/llvm-spirv/test/transcoding/spirv-types.ll @@ -44,12 +44,14 @@ target triple = "spir-unknown-unknown" ; CHECK-LLVM-DAG: %opencl.pipe_ro_t = type opaque ; CHECK-LLVM-DAG: %opencl.pipe_wo_t = type opaque -; CHECK-LLVM-DAG: %opencl.image3d_t = type opaque -; CHECK-LLVM_DAG: %opencl.image2d_depth_t = type opaque -; CHECK-LLVM-DAG: %opencl.image2d_array_t = type opaque -; CHECK-LLVM-DAG: %opencl.image1d_buffer_t = type opaque -; CHECK-LLVM-DAG: %opencl.image1d_t = type opaque -; CHECK-LLVM-DAG: %opencl.image2d_t = type opaque +; CHECK-LLVM-DAG: %opencl.image3d_ro_t = type opaque +; CHECK-LLVM_DAG: %opencl.image2d_depth_ro_t = type opaque +; CHECK-LLVM-DAG: %opencl.image2d_array_ro_t = type opaque +; CHECK-LLVM-DAG: %opencl.image1d_buffer_ro_t = type opaque +; CHECK-LLVM-DAG: %opencl.image1d_ro_t = type opaque +; CHECK-LLVM-DAG: %opencl.image1d_wo_t = type opaque +; CHECK-LLVM-DAG: %opencl.image2d_ro_t = type opaque +; CHECK-LLVM-DAG: %opencl.image2d_rw_t = type opaque ; CHECK-LLVM-DAG: %opencl.clk_event_t = type opaque ; CHECK-LLVM-DAG: %opencl.event_t = type opaque ; CHECK-LLVM-DAG: %opencl.queue_t = type opaque @@ -57,14 +59,14 @@ target triple = "spir-unknown-unknown" %spirv.Pipe._0 = type opaque ; read_only pipe %spirv.Pipe._1 = type opaque ; write_only pipe -%spirv.Image._void_0_0_0_0_0_0_0 = type opaque ; read_only image1d_t -%spirv.Image._int_1_0_0_0_0_0_0 = type opaque ; read_only image2d_t -%spirv.Image._uint_2_0_0_0_0_0_0 = type opaque ; read_only image3d_t -%spirv.Image._float_1_1_0_0_0_0_0 = type opaque; read_only image2d_depth_t -%spirv.Image._half_1_0_1_0_0_0_0 = type opaque ; read_only image2d_array_t -%spirv.Image._float_5_0_0_0_0_0_0 = type opaque ; read_only image1d_buffer_t -%spirv.Image._void_0_0_0_0_0_0_1 = type opaque ; write_only image1d_t -%spirv.Image._void_1_0_0_0_0_0_2 = type opaque ; read_write image2d_t +%spirv.Image._void_0_0_0_0_0_0_0 = type opaque ; read_only image1d_ro_t +%spirv.Image._int_1_0_0_0_0_0_0 = type opaque ; read_only image2d_ro_t +%spirv.Image._uint_2_0_0_0_0_0_0 = type opaque ; read_only image3d_ro_t +%spirv.Image._float_1_1_0_0_0_0_0 = type opaque; read_only image2d_depth_ro_t +%spirv.Image._half_1_0_1_0_0_0_0 = type opaque ; read_only image2d_array_ro_t +%spirv.Image._float_5_0_0_0_0_0_0 = type opaque ; read_only image1d_buffer_ro_t +%spirv.Image._void_0_0_0_0_0_0_1 = type opaque ; write_only image1d_wo_t +%spirv.Image._void_1_0_0_0_0_0_2 = type opaque ; read_write image2d_rw_t %spirv.DeviceEvent = type opaque ; clk_event_t %spirv.Event = type opaque ; event_t %spirv.Queue = type opaque ; queue_t @@ -86,13 +88,13 @@ target triple = "spir-unknown-unknown" ; CHECK-LLVM: define spir_kernel void @foo( ; CHECK-LLVM-SAME: %opencl.pipe_ro_t addrspace(1)* nocapture %a, ; CHECK-LLVM-SAME: %opencl.pipe_wo_t addrspace(1)* nocapture %b, -; CHECK-LLVM-SAME: %opencl.image1d_t addrspace(1)* nocapture %c1, -; CHECK-LLVM-SAME: %opencl.image2d_t addrspace(1)* nocapture %d1, -; CHECK-LLVM-SAME: %opencl.image3d_t addrspace(1)* nocapture %e1, -; CHECK-LLVM-SAME: %opencl.image2d_array_t addrspace(1)* nocapture %f1, -; CHECK-LLVM-SAME: %opencl.image1d_buffer_t addrspace(1)* nocapture %g1, -; CHECK-LLVM-SAME: %opencl.image1d_t addrspace(1)* nocapture %c2, -; CHECK-LLVM-SAME: %opencl.image2d_t addrspace(1)* nocapture %d3) +; CHECK-LLVM-SAME: %opencl.image1d_ro_t addrspace(1)* nocapture %c1, +; CHECK-LLVM-SAME: %opencl.image2d_ro_t addrspace(1)* nocapture %d1, +; CHECK-LLVM-SAME: %opencl.image3d_ro_t addrspace(1)* nocapture %e1, +; CHECK-LLVM-SAME: %opencl.image2d_array_ro_t addrspace(1)* nocapture %f1, +; CHECK-LLVM-SAME: %opencl.image1d_buffer_ro_t addrspace(1)* nocapture %g1, +; CHECK-LLVM-SAME: %opencl.image1d_wo_t addrspace(1)* nocapture %c2, +; CHECK-LLVM-SAME: %opencl.image2d_rw_t addrspace(1)* nocapture %d3) ; CHECK-LLVM-SAME: !kernel_arg_addr_space [[AS:![0-9]+]] ; CHECK-LLVM-SAME: !kernel_arg_access_qual [[AQ:![0-9]+]] ; CHECK-LLVM-SAME: !kernel_arg_type [[TYPE:![0-9]+]] @@ -141,9 +143,9 @@ define spir_func void @bar( ; CHECK-SPIRV: 7 ImageSampleExplicitLod {{[0-9]+}} {{[0-9]+}} [[SAMPIMG_VAR]] ; CHECK-LLVM: define spir_func void @test_sampler( -; CHECK-LLVM: %opencl.image2d_depth_t addrspace(1)* %srcimg.coerce, -; CHECK-LLVM: i32 %s.coerce) -; CHECK-LLVM: call spir_func float @_Z11read_imagef16ocl_image2ddepth11ocl_samplerDv4_if(%opencl.image2d_depth_t addrspace(1)* %srcimg.coerce, i32 %s.coerce, <4 x i32> zeroinitializer, float 1.000000e+00) +; CHECK-LLVM: %opencl.image2d_depth_ro_t addrspace(1)* %srcimg.coerce, +; CHECK-LLVM: %opencl.sampler_t* %s.coerce) +; CHECK-LLVM: call spir_func float @_Z11read_imagef20ocl_image2d_depth_ro11ocl_samplerDv4_if(%opencl.image2d_depth_ro_t addrspace(1)* %srcimg.coerce, %opencl.sampler_t* %s.coerce, <4 x i32> zeroinitializer, float 1.000000e+00) define spir_func void @test_sampler(%spirv.Image._float_1_1_0_0_0_0_0 addrspace(1)* %srcimg.coerce, %spirv.Sampler addrspace(1)* %s.coerce) { diff --git a/llvm-spirv/tools/llvm-spirv/llvm-spirv.cpp b/llvm-spirv/tools/llvm-spirv/llvm-spirv.cpp index 8ca1e4e643321..537dc0e0d49ad 100644 --- a/llvm-spirv/tools/llvm-spirv/llvm-spirv.cpp +++ b/llvm-spirv/tools/llvm-spirv/llvm-spirv.cpp @@ -58,7 +58,6 @@ #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" #include "llvm/Support/ToolOutputFile.h" -#include "llvm/Support/raw_ostream.h" #ifndef _SPIRV_SUPPORT_TEXT_FMT #define _SPIRV_SUPPORT_TEXT_FMT @@ -137,11 +136,16 @@ static int convertLLVMToSPIRV() { (SPIRV::SPIRVUseTextFormat ? kExt::SpirvText : kExt::SpirvBinary); } - llvm::StringRef OutFile(OutputFile); - std::error_code EC; std::string Err; - llvm::raw_fd_ostream OFS(OutFile, EC, llvm::sys::fs::F_None); - if (!writeSpirv(M.get(), OFS, Err)) { + bool Success = false; + if (OutputFile != "-") { + std::ofstream OutFile(OutputFile); + Success = writeSpirv(M.get(), OutFile, Err); + } else { + Success = writeSpirv(M.get(), std::cout, Err); + } + + if (!Success) { errs() << "Fails to save LLVM as SPIRV: " << Err << '\n'; return -1; } @@ -204,7 +208,7 @@ static int convertSPIRV() { } } - auto Action = [&](llvm::raw_ostream &OFS) { + auto Action = [&](std::ostream &OFS) { std::string Err; if (!SPIRV::convertSpirv(IFS, OFS, Err, ToBinary, ToText)) { errs() << "Fails to convert SPIR-V : " << Err << '\n'; @@ -213,12 +217,10 @@ static int convertSPIRV() { return 0; }; if (OutputFile != "-") { - std::error_code EC; - llvm::raw_fd_ostream OFS(llvm::StringRef(OutputFile), EC, - llvm::sys::fs::F_None); + std::ofstream OFS(OutputFile); return Action(OFS); } else - return Action(outs()); + return Action(std::cout); } #endif