Skip to content
Open
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
8 changes: 0 additions & 8 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def do_configure(args, passthrough_args):
llvm_enable_projects = "clang;" + llvm_external_projects
libclc_build_native = "OFF"
libclc_targets_to_build = ""
libclc_gen_remangled_variants = "OFF"
sycl_build_ur_hip_platform = "AMD"
sycl_clang_extra_flags = ""
sycl_werror = "OFF"
Expand Down Expand Up @@ -91,7 +90,6 @@ def do_configure(args, passthrough_args):
if args.cuda:
llvm_targets_to_build += ";NVPTX"
libclc_targets_to_build = libclc_nvidia_target_names
libclc_gen_remangled_variants = "ON"
sycl_enabled_backends.append("cuda")

if args.hip:
Expand All @@ -102,7 +100,6 @@ def do_configure(args, passthrough_args):
elif args.hip_platform == "NVIDIA" and not args.cuda:
llvm_targets_to_build += ";NVPTX"
libclc_targets_to_build += libclc_nvidia_target_names
libclc_gen_remangled_variants = "ON"

sycl_build_ur_hip_platform = args.hip_platform
sycl_enabled_backends.append("hip")
Expand All @@ -112,7 +109,6 @@ def do_configure(args, passthrough_args):
libclc_targets_to_build += ";" + args.native_cpu_libclc_targets
else:
libclc_build_native = "ON"
libclc_gen_remangled_variants = "ON"
sycl_enabled_backends.append("native_cpu")

# all llvm compiler targets don't require 3rd party dependencies, so can be
Expand Down Expand Up @@ -161,7 +157,6 @@ def do_configure(args, passthrough_args):
# Add NVIDIA libclc targets
if libclc_nvidia_target_names not in libclc_targets_to_build:
libclc_targets_to_build += libclc_nvidia_target_names
libclc_gen_remangled_variants = "ON"
spirv_enable_dis = "ON"

if args.enable_backends:
Expand Down Expand Up @@ -240,9 +235,6 @@ def do_configure(args, passthrough_args):
cmake_cmd.extend(
[
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
"-DLIBCLC_GENERATE_REMANGLED_VARIANTS={}".format(
libclc_gen_remangled_variants
),
"-DLIBCLC_NATIVECPU_HOST_TARGET={}".format(libclc_build_native),
]
)
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ CODEGENOPT(DisableSYCLEarlyOpts, 1, 0, Benign)
/// which do not contain "user" code.
CODEGENOPT(OptimizeSYCLFramework, 1, 0, Benign)

/// Whether to remangle SPIR-V built-ins in libspirv for SYCL.
CODEGENOPT(SYCLRemangleLibspirv, 1, 0, Benign)

/// Whether to use alloca address space for `sret` arguments.
/// TODO: This option can be removed once a fix goes in that can
/// work with the community changes for using the alloca address space.
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/Options/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -9532,6 +9532,11 @@ defm offload_use_alloca_addrspace_for_srets : BoolFOption<"offload-use-alloca-ad
PosFlag<SetTrue, [], [CC1Option], "Use alloca address space for sret arguments for offloading targets">,
NegFlag<SetFalse>>;

def fsycl_remangle_libspirv
: Flag<["-"], "fsycl-remangle-libspirv">,
HelpText<"Remangle SPIR-V built-ins in libspirv for SYCL">,
MarshallingInfoFlag<CodeGenOpts<"SYCLRemangleLibspirv">>;

} // let Visibility = [CC1Option]

def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>,
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "llvm/SYCLLowerIR/SYCLOptimizeBarriers.h"
#include "llvm/SYCLLowerIR/SYCLPropagateAspectsUsage.h"
#include "llvm/SYCLLowerIR/SYCLPropagateJointMatrixUsage.h"
#include "llvm/SYCLLowerIR/SYCLRemangleLibspirv.h"
#include "llvm/SYCLLowerIR/SYCLVirtualFunctionsAnalysis.h"
#include "llvm/SYCLLowerIR/UtilsSYCLNativeCPU.h"
#include "llvm/Support/BuryPointer.h"
Expand Down Expand Up @@ -1103,6 +1104,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
});
}

if (CodeGenOpts.SYCLRemangleLibspirv) {
PB.registerOptimizerLastEPCallback(
[&](ModulePassManager &MPM, OptimizationLevel, ThinOrFullLTOPhase) {
MPM.addPass(SYCLRemangleLibspirvPass());
});
}

const bool PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
const bool PrepareForLTO = CodeGenOpts.PrepareForLTO;

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ getLibSpirvBasename(const llvm::Triple &HostTriple) {
// All known windows environments except Cygwin use 32-bit long.
llvm::SmallString<64> Result(HostTriple.isOSWindows() &&
!HostTriple.isWindowsCygwinEnvironment()
? "remangled-l32-signed_char.libspirv.bc"
: "remangled-l64-signed_char.libspirv.bc");
? "libspirv.l32.signed_char.bc"
: "libspirv.l64.signed_char.bc");
return Result;
}

Expand Down
16 changes: 16 additions & 0 deletions clang/test/CodeGen/sycl-remangle-libspirv-pipeline.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Test that -fsycl-remangle-libspirv flag enables SYCLRemangleLibspirvPass.

// RUN: %clang_cc1 -triple spir64-unknown-unknown -emit-llvm-bc -o /dev/null \
// RUN: -mllvm -print-pipeline-passes \
// RUN: %s 2>&1 | FileCheck --check-prefixes=DEFAULT %s

// DEFAULT-NOT: sycl-remangle-libspirv

// RUN: %clang_cc1 -triple spir64-unknown-unknown -emit-llvm-bc -o /dev/null \
// RUN: -mllvm -print-pipeline-passes \
// RUN: -fsycl-remangle-libspirv \
// RUN: %s 2>&1 | FileCheck --check-prefixes=ENABLED %s

// ENABLED: sycl-remangle-libspirv

void test() {}
2 changes: 1 addition & 1 deletion clang/test/Driver/sycl-cuda-rdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// UNSUPPORTED: system-windows

// RUN: %clangxx -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_61 -fgpu-rdc -nocudalib \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/lib/clang/resource_dir/lib/nvptx64-nvidia-cuda/remangled-l64-signed_char.libspirv.bc %s 2>&1 \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/lib/clang/resource_dir/lib/nvptx64-nvidia-cuda/libspirv.l64.signed_char.bc %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-SYCL_RDC_NVPTX

// Verify that ptxas does not pass "-c"
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Driver/sycl-device-obj-asm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@

/// -fsycl-device-obj=asm should always be accompanied by -fsycl-device-only
/// and -S, check that the compiler issues a correct warning message:
// RUN: %clang -### -nocudalib -fsycl-device-only -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_50 -fsycl-device-obj=asm %s 2>&1 -o - -fsycl-libspirv-path=%S/Inputs/SYCL/lib/clang/resource_dir/lib/nvptx64-nvidia-cuda/remangled-l64-signed_char.libspirv.bc | FileCheck %s --check-prefix=CHECK-NO-DEV-ONLY-NO-S
// RUN: %clang -### -nocudalib -fsycl-device-only -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_50 -fsycl-device-obj=asm %s 2>&1 -o - -fsycl-libspirv-path=%S/Inputs/SYCL/lib/clang/resource_dir/lib/nvptx64-nvidia-cuda/libspirv.bc | FileCheck %s --check-prefix=CHECK-NO-DEV-ONLY-NO-S
// CHECK-NO-DEV-ONLY-NO-S: warning: -fsycl-device-obj=asm flag has an effect only when compiling device code and emitting assembly, make sure both -fsycl-device-only and -S flags are present; will be ignored [-Wunused-command-line-argument]

/// -fsycl-device-obj=asm will finish at generating assembly stage, hence
/// inform users that generating library will not be possible (ignore -c)
// RUN: %clang -### -nocudalib -fsycl-device-only -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_50 -fsycl-device-obj=asm %s 2>&1 -fsycl-device-only -S -c -o - -fsycl-libspirv-path=%S/Inputs/SYCL/lib/clang/resource_dir/lib/nvptx64-nvidia-cuda/remangled-l64-signed_char.libspirv.bc | FileCheck %s --check-prefix=CHECK-DASH-C-IGNORE
// RUN: %clang -### -nocudalib -fsycl-device-only -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_50 -fsycl-device-obj=asm %s 2>&1 -fsycl-device-only -S -c -o - -fsycl-libspirv-path=%S/Inputs/SYCL/lib/clang/resource_dir/lib/nvptx64-nvidia-cuda/libspirv.bc | FileCheck %s --check-prefix=CHECK-DASH-C-IGNORE
// CHECK-DASH-C-IGNORE: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument]
10 changes: 5 additions & 5 deletions clang/test/Driver/sycl-libspirv-invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \
// RUN: | FileCheck --check-prefix=ERR-CUDA %s
// ERR-CUDA: cannot find 'remangled-l64-signed_char.libspirv.bc';
// ERR-CUDA: cannot find 'libspirv.l64.signed_char.bc';
// ERR-CUDA-SAME: provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv

// RUN: not %clangxx -### -std=c++11 -target x86_64-unknown-windows-msvc -fsycl -nocudalib \
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \
// RUN: | FileCheck --check-prefix=ERR-CUDA-WIN %s
// ERR-CUDA-WIN: cannot find 'remangled-l32-signed_char.libspirv.bc';
// ERR-CUDA-WIN: cannot find 'libspirv.l32.signed_char.bc';
// ERR-CUDA-WIN-SAME: provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv

// RUN: not %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl -nogpulib \
// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc %s 2>&1 \
// RUN: | FileCheck --check-prefix=ERR-HIP %s
// ERR-HIP: cannot find 'remangled-l64-signed_char.libspirv.bc';
// ERR-HIP: cannot find 'libspirv.l64.signed_char.bc';
// ERR-HIP-SAME: provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv

// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl \
// RUN: -fsycl-targets=nvptx64-nvidia-cuda --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc -fno-sycl-libspirv %s 2>&1 \
// RUN: | FileCheck --check-prefix=OK-CUDA %s
// OK-CUDA-NOT: cannot find suitable 'remangled-l64-signed_char.libspirv.bc'
// OK-CUDA-NOT: cannot find suitable 'libspirv.l64.signed_char.bc'

// RUN: %clangxx -### -std=c++11 -target x86_64-unknown-linux-gnu -fsycl -nogpulib \
// RUN: -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 \
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/no-libspirv-exists-here.bc -fno-sycl-libspirv %s 2>&1 \
// RUN: | FileCheck --check-prefix=OK-HIP %s
// OK-HIP-NOT: cannot find 'remangled-l64-signed_char.libspirv.bc'
// OK-HIP-NOT: cannot find 'libspirv.l64.signed_char.bc'
20 changes: 10 additions & 10 deletions clang/test/Driver/sycl-libspirv-toolchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@
// RUN: | FileCheck %s --check-prefixes=CHECK-WINDOWS
// RUN: %clang -### -resource-dir %{resource_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib -target x86_64-unknown-windows-gnu %s 2>&1 \
// RUN: | FileCheck %s --check-prefixes=CHECK-WINDOWS
// CHECK-WINDOWS: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-l32-signed_char.libspirv.bc"
// CHECK-WINDOWS: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}libspirv.l32.signed_char.bc"
//
// RUN: %clang -### -resource-dir %{resource_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib -target x86_64-unknown-linux-gnu %s 2>&1 \
// RUN: | FileCheck %s --check-prefixes=CHECK-LINUX
// RUN: %clang -### -resource-dir %{resource_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib -target x86_64-unknown-windows-cygnus %s 2>&1 \
// RUN: | FileCheck %s --check-prefixes=CHECK-LINUX
// CHECK-LINUX: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-l64-signed_char.libspirv.bc"
// CHECK-LINUX: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}libspirv.l64.signed_char.bc"
//
// RUN: %clang -### -resource-dir %{resource_dir} -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 -nogpulib -target x86_64-unknown-windows-msvc %s 2>&1 \
// RUN: | FileCheck %s --check-prefixes=CHECK-AMDGCN-WINDOWS
// CHECK-AMDGCN-WINDOWS: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-l32-signed_char.libspirv.bc"
// CHECK-AMDGCN-WINDOWS: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}libspirv.l32.signed_char.bc"
//
// RUN: %clang -### -resource-dir %{resource_dir} -fsycl -fsycl-device-only -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
// RUN: | FileCheck %s --check-prefixes=CHECK-DEVICE-ONLY
// CHECK-DEVICE-ONLY: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-{{.*}}.libspirv.bc"
// CHECK-DEVICE-ONLY: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}libspirv.l[[#]].signed_char.bc"
//
// Only link libspirv in SYCL language mode, `-fno-sycl-libspirv` should result in a warning
// RUN: %clang -### -x cu -fno-sycl-libspirv -nocudainc -nocudalib %s 2>&1 | FileCheck %s --check-prefixes=CHECK-CUDA
// CHECK-CUDA: warning: argument unused during compilation: '-fno-sycl-libspirv' [-Wunused-command-line-argument]
// CHECK-CUDA: "-cc1"{{.*}} "-fcuda-is-device"
// CHECK-CUDA-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv.bc"
// CHECK-CUDA-NOT: "-mlink-builtin-bitcode" "{{.*}}libspirv.l[[#]].signed_char.bc"
//
// The path to the remangled libspirv bitcode file is determined by the resource directory
// The path to the libspirv bitcode file is determined by the resource directory
// RUN: %clang -### -resource-dir %{resource_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
// RUN: | FileCheck %s -DRESOURCE_DIR=%{resource_dir} --check-prefixes=CHECK-DIR
// CHECK-DIR: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[RESOURCE_DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv.bc"
// CHECK-DIR: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[RESOURCE_DIR]]{{.*[\\/]}}libspirv.l[[#]].signed_char.bc"
//
// If libspirv path doesn't exist, error is reported.
// DEFINE: %{nonexistent_dir} = %/S/Inputs/SYCL/does_not_exist/lib/clang/resource_dir
// RUN: not %clang -### -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-HHH-NONEXISTENT
// CHECK-HHH-NONEXISTENT: error: cannot find 'remangled-{{.*}}.libspirv.bc'; provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv
// CHECK-HHH-NONEXISTENT: error: cannot find 'libspirv.l[[#]].signed_char.bc'; provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv
//
// RUN: not %clang -### -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 -nogpulib %s 2>&1 \
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-AMDGCN-HHH-NONEXISTENT
// CHECK-AMDGCN-HHH-NONEXISTENT: clang: error: cannot find 'remangled-{{.*}}.libspirv.bc'; provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv
// CHECK-AMDGCN-HHH-NONEXISTENT: clang: error: cannot find 'libspirv.l[[#]].signed_char.bc'; provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv
//
// RUN: not %clang -fdriver-only -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-DO-NONEXISTENT
// CHECK-DO-NONEXISTENT: error: cannot find 'remangled-{{.*}}.libspirv.bc'; provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv
// CHECK-DO-NONEXISTENT: error: cannot find 'libspirv.l[[#]].signed_char.bc'; provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv
2 changes: 1 addition & 1 deletion clang/test/Driver/sycl-nvptx-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

// CHECK: llvm-link
// CHECK-SAME: -only-needed
// CHECK-SAME: remangled-{{.*}}-signed_char.libspirv.bc
// CHECK-SAME: libspirv.l[[#]].signed_char.bc
// LIBDEVICE10-SAME: libdevice.10.bc
// LIBDEVICE30-SAME: libdevice.compute_30.10.bc
// LIBDEVICE35-SAME: libdevice.compute_35.10.bc
Expand Down
Loading
Loading