Skip to content

Commit

Permalink
Merge from 'sycl' to 'sycl-web' (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
iclsrc committed Oct 12, 2019
2 parents 2d5ba8e + 1d46bfe commit b36dc10
Show file tree
Hide file tree
Showing 69 changed files with 2,054 additions and 370 deletions.
3 changes: 3 additions & 0 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def do_configure(args):
else:
icd_loader_lib = os.path.join(args.obj_dir, "OpenCL-ICD-Loader", "build", "OpenCL.lib")

install_dir = os.path.join(args.obj_dir, "install")

cmake_cmd = ["cmake",
"-G", "Ninja",
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
Expand All @@ -30,6 +32,7 @@ def do_configure(args):
"-DLLVM_BUILD_TOOLS=OFF",
"-DSYCL_ENABLE_WERROR=ON",
"-DLLVM_ENABLE_ASSERTIONS=ON",
"-DCMAKE_INSTALL_PREFIX={}".format(install_dir),
llvm_dir]

print(cmake_cmd)
Expand Down
16 changes: 10 additions & 6 deletions llvm-spirv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.3)

set(LLVM_SPIRV_VERSION 0.2.1.0)

option(LLVM_SPIRV_INCLUDE_TESTS
"Generate build targets for the llvm-spirv lit tests."
${LLVM_INCLUDE_TESTS})

# check if we build inside llvm or not
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(BUILD_EXTERNAL YES)
Expand All @@ -12,17 +16,17 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
CXX
)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(LLVM_INCLUDE_TESTS)
if(LLVM_SPIRV_INCLUDE_TESTS)
set(LLVM_TEST_COMPONENTS
llvm-as
llvm-dis
)
endif(LLVM_INCLUDE_TESTS)
endif(LLVM_SPIRV_INCLUDE_TESTS)

find_package(LLVM 9.0.0 REQUIRED
find_package(LLVM 10.0.0 REQUIRED
COMPONENTS
Analysis
BitReader
Expand Down Expand Up @@ -56,9 +60,9 @@ set(LLVM_SPIRV_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_subdirectory(lib/SPIRV)
add_subdirectory(tools/llvm-spirv)
if(LLVM_INCLUDE_TESTS)
if(LLVM_SPIRV_INCLUDE_TESTS)
add_subdirectory(test)
endif(LLVM_INCLUDE_TESTS)
endif(LLVM_SPIRV_INCLUDE_TESTS)

install(
FILES
Expand Down
12 changes: 10 additions & 2 deletions 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-9-dev llvm-9-tools clang-9 libclang-9-dev
sudo apt-get install llvm-10-dev llvm-10-tools clang-10 libclang-10-dev
```
The installed version of LLVM will be used by default for out-of-tree build of the translator.
```
Expand Down Expand Up @@ -73,9 +73,12 @@ Execute the following command inside the build directory to run translator tests
make test
```
This requires that the `-DLLVM_INCLUDE_TESTS=ON` and
`-DLLVM_EXTERNAL_LIT="/usr/lib/llvm-9/build/utils/lit/lit.py"` arguments were
`-DLLVM_EXTERNAL_LIT="/usr/lib/llvm-10/build/utils/lit/lit.py"` arguments were
passed to CMake during the build step.

The translator test suite can be disabled by passing
`-DLLVM_SPIRV_INCLUDE_TESTS=OFF` to cmake.

## Run Instructions for `llvm-spirv`


Expand All @@ -100,6 +103,11 @@ To translate between LLVM IR and SPIR-V:
* `-spirv-text` - read/write SPIR-V in an internal textual format for debugging purpose. The textual format is not defined by SPIR-V spec.
* `-help` - to see full list of options
Translation from LLVM IR to SPIR-V and then back to LLVM IR is not guaranteed to
produce the original LLVM IR. In particular, LLVM intrinsic call instructions
may get replaced by function calls to OpenCL builtins and metadata may be
dropped.
### Handling SPIR-V versions generated by the translator
There is one option to control the behavior of the translator with respect to
Expand Down
12 changes: 10 additions & 2 deletions llvm-spirv/include/LLVMSPIRVOpts.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ class TranslatorOpts {

TranslatorOpts() = default;

TranslatorOpts(VersionNumber Max, const ExtensionsStatusMap &Map = {})
: MaxVersion(Max), ExtStatusMap(Map) {}
TranslatorOpts(VersionNumber Max, const ExtensionsStatusMap &Map = {},
bool ArgNameMD = false)
: MaxVersion(Max), ExtStatusMap(Map), GenKernelArgNameMD(ArgNameMD) {}

bool isAllowedToUseVersion(VersionNumber RequestedVersion) const {
return RequestedVersion <= MaxVersion;
Expand All @@ -88,15 +89,22 @@ class TranslatorOpts {

VersionNumber getMaxVersion() const { return MaxVersion; }

bool isGenArgNameMDEnabled() const { return GenKernelArgNameMD; }

void enableAllExtensions() {
#define EXT(X) ExtStatusMap[ExtensionID::X] = true;
#include "LLVMSPIRVExtensions.inc"
#undef EXT
}

void enableGenArgNameMD() { GenKernelArgNameMD = true; }

private:
// Common translation options
VersionNumber MaxVersion = VersionNumber::MaximumVersion;
ExtensionsStatusMap ExtStatusMap;
// SPIR-V to LLVM translation options
bool GenKernelArgNameMD;
};

} // namespace SPIRV
Expand Down
9 changes: 9 additions & 0 deletions llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ void LLVMToSPIRVDbgTran::transLocationInfo() {
LineNo = DL.getLine();
Col = DL.getCol();
V = SPIRVWriter->getTranslatedValue(&I);
// According to the spec, OpLine for an OpBranch/OpBranchConditional
// must precede the merge instruction and not the branch instruction
auto *VPrev = static_cast<SPIRVInstruction *>(V)->getPrevious();
if (VPrev->getOpCode() == OpLoopMerge ||
VPrev->getOpCode() == OpLoopControlINTEL) {
assert(V->getOpCode() == OpBranch ||
V->getOpCode() == OpBranchConditional);
V = VPrev;
}
BM->addLine(V, File ? File->getId() : getDebugInfoNone()->getId(),
LineNo, Col);
}
Expand Down
6 changes: 4 additions & 2 deletions llvm-spirv/lib/SPIRV/OCLUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ bool isSamplerTy(Type *Ty) {
return STy && STy->hasName() && STy->getName() == kSPR2TypeName::Sampler;
}

bool isPipeBI(const StringRef MangledName) {
bool isPipeOrAddressSpaceCastBI(const StringRef MangledName) {
return MangledName == "write_pipe_2" || MangledName == "read_pipe_2" ||
MangledName == "write_pipe_2_bl" || MangledName == "read_pipe_2_bl" ||
MangledName == "write_pipe_4" || MangledName == "read_pipe_4" ||
Expand All @@ -796,7 +796,9 @@ bool isPipeBI(const StringRef MangledName) {
MangledName == "sub_group_reserve_write_pipe" ||
MangledName == "sub_group_reserve_read_pipe" ||
MangledName == "sub_group_commit_write_pipe" ||
MangledName == "sub_group_commit_read_pipe";
MangledName == "sub_group_commit_read_pipe" ||
MangledName == "to_global" || MangledName == "to_local" ||
MangledName == "to_private";
}

bool isEnqueueKernelBI(const StringRef MangledName) {
Expand Down
4 changes: 2 additions & 2 deletions llvm-spirv/lib/SPIRV/OCLUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ bool isPipeStorageInitializer(Instruction *Inst);
/// Check (isSamplerInitializer || isPipeStorageInitializer)
bool isSpecialTypeInitializer(Instruction *Inst);

bool isPipeBI(const StringRef MangledName);
bool isPipeOrAddressSpaceCastBI(const StringRef MangledName);
bool isEnqueueKernelBI(const StringRef MangledName);
bool isKernelQueryBI(const StringRef MangledName);

Expand Down Expand Up @@ -751,7 +751,7 @@ template <> inline void SPIRVMap<std::string, Op, SPIRVInstruction>::init() {
}

template <> inline void SPIRVMap<std::string, Op, OCL12Builtin>::init() {
#define _SPIRV_OP(x, y) add("atomic_" #x, Op##y);
#define _SPIRV_OP(x, y) add(#x, Op##y);
_SPIRV_OP(add, AtomicIAdd)
_SPIRV_OP(sub, AtomicISub)
_SPIRV_OP(xchg, AtomicExchange)
Expand Down
Loading

0 comments on commit b36dc10

Please sign in to comment.