Skip to content

[SYCL][ESIMD] Prepare LLVM IR for OS spirv translator #2112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "llvm/CodeGen/RegAllocRegistry.h"
#include "llvm/CodeGen/SchedulerRegistry.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/GenXIntrinsics/GenXSPIRVWriterAdaptor.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LegacyPassManager.h"
Expand Down Expand Up @@ -890,6 +891,9 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
if (LangOpts.SYCLIsDevice && CodeGenOpts.DisableLLVMPasses)
PerModulePasses.add(createDeadCodeEliminationPass());

if (LangOpts.SYCLIsDevice && LangOpts.SYCLExplicitSIMD)
PerModulePasses.add(createGenXSPIRVWriterAdaptorPass());

switch (Action) {
case Backend_EmitNothing:
break;
Expand Down
14 changes: 14 additions & 0 deletions clang/lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ if (MSVC)
set_source_files_properties(CodeGenModule.cpp PROPERTIES COMPILE_FLAGS /bigobj)
endif()

get_property(LLVMGenXIntrinsics_SOURCE_DIR GLOBAL PROPERTY LLVMGenXIntrinsics_SOURCE_PROP)
get_property(LLVMGenXIntrinsics_BINARY_DIR GLOBAL PROPERTY LLVMGenXIntrinsics_BINARY_PROP)

include_directories(
${LLVMGenXIntrinsics_SOURCE_DIR}/GenXIntrinsics/include
${LLVMGenXIntrinsics_BINARY_DIR}/GenXIntrinsics/include)

add_clang_library(clangCodeGen
BackendUtil.cpp
CGAtomic.cpp
Expand Down Expand Up @@ -91,8 +98,14 @@ add_clang_library(clangCodeGen
TargetInfo.cpp
VarBypassDetector.cpp

ADDITIONAL_HEADER_DIRS
${LLVMGenXIntrinsics_SOURCE_DIR}/GenXIntrinsics/include
${LLVMGenXIntrinsics_BINARY_DIR}/GenXIntrinsics/include

DEPENDS
${codegen_deps}
intrinsics_gen
LLVMGenXIntrinsics

LINK_LIBS
clangAnalysis
Expand All @@ -102,4 +115,5 @@ add_clang_library(clangCodeGen
clangFrontend
clangLex
clangSerialization
LLVMGenXIntrinsics
)
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,12 @@ void CodeGenModule::Release() {
SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));
// We are trying to look like OpenCL C++ for SPIR-V translator.
// 4 - OpenCL_CPP, 100000 - OpenCL C++ version 1.0
// 6 - ESIMD, if any kernel or function is an explicit SIMD one
// 0 - ESIMD, if any kernel or function is an explicit SIMD one
int Lang = llvm::any_of(TheModule,
[](const auto &F) {
return F.getMetadata("sycl_explicit_simd");
})
? 6
? 0
: 4;

llvm::Metadata *SPIRVSourceElts[] = {
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7658,6 +7658,8 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
if (getToolChain().getTriple().isSYCLDeviceEnvironment()) {
TranslatorArgs.push_back("-spirv-max-version=1.1");
std::string ExtArg("-spirv-ext=+all");
if (C.getArgs().hasArg(options::OPT_fsycl_esimd))
TranslatorArgs.push_back("-spirv-allow-unknown-intrinsics");
// Disable SPV_INTEL_usm_storage_classes by default since it adds new
// storage classes that represent global_device and global_host address
// spaces, which are not supported for all targets. With the extension
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const char *SYCL::Linker::constructLLVMSpirvCommand(Compilation &C,
} else {
CmdArgs.push_back("-spirv-max-version=1.1");
CmdArgs.push_back("-spirv-ext=+all");
if (C.getArgs().hasArg(options::OPT_fsycl_esimd))
Copy link
Contributor

@MrSidims MrSidims Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in a scope of this patch, but I think we shall add another option to enable translation of unknown to the translator intrinsics for users, for example: #2122

CmdArgs.push_back("-spirv-allow-unknown-intrinsics");
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/esimd-private-global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ SYCL_EXTERNAL void init_vc(int x) {
vc = x;
// CHECK: store i32 %0, i32* @vc
}
// CHECK: attributes #0 = { "genx_byte_offset"="17" "genx_volatile" }
// CHECK: attributes #0 = {{.*"VCByteOffset"="17".*"VCVolatile"}}
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/esimd_metadata1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ void bar() {
}

// CHECK: !spirv.Source = !{[[LANG:![0-9]+]]}
// CHECK: [[LANG]] = !{i32 6, i32 100000}
// CHECK: [[LANG]] = !{i32 0, i32 {{[0-9]+}}}
// CHECK: ![[EMPTY]] = !{}
// CHECK: ![[REQD_SIZE]] = !{i32 1}
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/esimd_metadata2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ void bar() {
}

// CHECK: !spirv.Source = !{[[LANG:![0-9]+]]}
// CHECK: [[LANG]] = !{i32 6, i32 100000}
// CHECK: [[LANG]] = !{i32 0, i32 {{[0-9]+}}}
// CHECK-ESIMD: ![[SGSIZE1]] = !{i32 1}
4 changes: 4 additions & 0 deletions clang/test/Driver/sycl-offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,10 @@
// CHECK-LINK-SYCL-DEBUG: "{{.*}}link{{(.exe)?}}"
// CHECK-LINK-SYCL-DEBUG: "-defaultlib:sycld.lib"

/// Check "-spirv-allow-unknown-intrinsics" option is emitted for llvm-spirv tool for esimd mode
// RUN: %clangxx %s -fsycl -fsycl-explicit-simd -### 2>&1 | FileCheck %s --check-prefix=CHK-FSYCL-ESIMD
// CHK-FSYCL-ESIMD: llvm-spirv{{.*}}-spirv-allow-unknown-intrinsics

/// ###########################################################################

/// Check -Xsycl-target-backend triggers error when multiple triples are used.
Expand Down
5 changes: 4 additions & 1 deletion llvm/lib/SYCLLowerIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (NOT TARGET LLVMGenXIntrinsics)
include(FetchContent)
FetchContent_Declare(vc-intrinsics
GIT_REPOSITORY https://github.com/intel/vc-intrinsics.git
GIT_TAG cce6e48c28eb850d7dadd30841c0d95f009bbca1
GIT_TAG 5e35898100ebe3747ea50c91b05e679757b25703
)
FetchContent_MakeAvailable(vc-intrinsics)
FetchContent_GetProperties(vc-intrinsics)
Expand All @@ -28,6 +28,9 @@ if (NOT TARGET LLVMGenXIntrinsics)
)
endif()

set_property(GLOBAL PROPERTY LLVMGenXIntrinsics_SOURCE_PROP ${LLVMGenXIntrinsics_SOURCE_DIR})
set_property(GLOBAL PROPERTY LLVMGenXIntrinsics_BINARY_PROP ${LLVMGenXIntrinsics_BINARY_DIR})

add_llvm_component_library(LLVMSYCLLowerIR
LowerWGScope.cpp
LowerESIMD.cpp
Expand Down