Skip to content

Commit

Permalink
[SYCL] Sync with 23c581c8c2be4cdc51b9b234ca4a77e9ac49cde8 SPIRV trans…
Browse files Browse the repository at this point in the history
…lator commit

Signed-off-by: Vladimir Lazarev <[email protected]>
  • Loading branch information
vladimirlaz committed Mar 22, 2019
1 parent 5c80a26 commit 02f6d68
Show file tree
Hide file tree
Showing 69 changed files with 1,340 additions and 942 deletions.
22 changes: 13 additions & 9 deletions llvm-spirv/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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 ..;
Expand All @@ -112,16 +112,19 @@ 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:
# Tag the current master top of the tree as "latest".
# 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 "[email protected]"
- git tag -f latest_build
- git tag -f ${TAG}
- git push -f https://${repo_token}@github.com/${TRAVIS_REPO_SLUG} --tags

deploy:
Expand All @@ -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
2 changes: 1 addition & 1 deletion llvm-spirv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm-spirv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
Expand Down
10 changes: 5 additions & 5 deletions llvm-spirv/include/LLVMSPIRVLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions llvm-spirv/lib/SPIRV/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 16 additions & 11 deletions llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<dwarf::TypeKind>(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);
}

Expand Down Expand Up @@ -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<DIFile>(Scope))
Ops[ParentIdx] = SPIRVCU->getId();
else
Ops[ParentIdx] = getScope(Scope)->getId();
Ops[LinkageNameIdx] = BM->getString(Func->getLinkageName())->getId();
Ops[FlagsIdx] = transDebugFlags(Func);

Expand All @@ -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())
Expand Down
192 changes: 132 additions & 60 deletions llvm-spirv/lib/SPIRV/Mangler/ManglingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 02f6d68

Please sign in to comment.