Skip to content

Commit b38f07b

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web'
2 parents 1d0d565 + 6cc97d2 commit b38f07b

File tree

71 files changed

+1374
-373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1374
-373
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,10 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
797797
// the -fsycl-targets, -fsycl-add-targets or -fsycl-link-targets option.
798798
// If -fsycl is supplied without any of these we will assume SPIR-V.
799799
// Use of -fsycl-device-only overrides -fsycl.
800-
bool HasValidSYCLRuntime = (C.getInputArgs().hasFlag(options::OPT_fsycl,
801-
options::OPT_fno_sycl, false) &&
802-
!C.getInputArgs().hasArg(options::OPT_fsycl_device_only));
800+
bool HasValidSYCLRuntime =
801+
(C.getInputArgs().hasFlag(options::OPT_fsycl, options::OPT_fno_sycl,
802+
false) ||
803+
C.getInputArgs().hasArg(options::OPT_fsycl_device_only));
803804

804805
// A mechanism for retrieving SYCL-specific options, erroring out
805806
// if SYCL offloading wasn't enabled prior to that
@@ -918,11 +919,18 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
918919
} else {
919920
// If -fsycl is supplied without -fsycl-*targets we will assume SPIR-V
920921
// unless -fintelfpga is supplied, which uses SPIR-V with fpga AOT.
921-
if (HasValidSYCLRuntime) {
922+
// For -fsycl-device-only, we also setup the implied triple as needed.
923+
StringRef SYCLTargetArch;
924+
if (C.getInputArgs().hasArg(options::OPT_fsycl_device_only))
925+
if (C.getDefaultToolChain().getTriple().getArch() == llvm::Triple::x86)
926+
SYCLTargetArch = "spir";
927+
else
928+
SYCLTargetArch = "spir64";
929+
else if (HasValidSYCLRuntime)
922930
// Triple for -fintelfpga is spir64_fpga-unknown-unknown-sycldevice.
923-
const char *SYCLTargetArch = SYCLfpga ? "spir64_fpga" : "spir64";
931+
SYCLTargetArch = SYCLfpga ? "spir64_fpga" : "spir64";
932+
if (!SYCLTargetArch.empty())
924933
UniqueSYCLTriplesVec.push_back(MakeSYCLDeviceTriple(SYCLTargetArch));
925-
}
926934
}
927935
// We'll need to use the SYCL and host triples as the key into
928936
// getOffloadingDeviceToolChain, because the device toolchains we're
@@ -3712,10 +3720,24 @@ class OffloadingActionBuilder final {
37123720
// The host depends on the generated integrated header from the device
37133721
// compilation.
37143722
if (CurPhase == phases::Compile) {
3723+
bool SYCLDeviceOnly = Args.hasArg(options::OPT_fsycl_device_only);
37153724
for (Action *&A : SYCLDeviceActions) {
37163725
DeviceCompilerInput =
37173726
C.MakeAction<CompileJobAction>(A, types::TY_SYCL_Header);
3718-
A = C.MakeAction<CompileJobAction>(A, types::TY_LLVM_BC);
3727+
types::ID OutputType = types::TY_LLVM_BC;
3728+
if (SYCLDeviceOnly) {
3729+
if (Args.hasArg(options::OPT_S))
3730+
OutputType = types::TY_LLVM_IR;
3731+
if (Args.hasFlag(options::OPT_fno_sycl_use_bitcode,
3732+
options::OPT_fsycl_use_bitcode, false)) {
3733+
auto *CompileAction =
3734+
C.MakeAction<CompileJobAction>(A, types::TY_LLVM_BC);
3735+
A = C.MakeAction<SPIRVTranslatorJobAction>(CompileAction,
3736+
types::TY_SPIRV);
3737+
continue;
3738+
}
3739+
}
3740+
A = C.MakeAction<CompileJobAction>(A, OutputType);
37193741
}
37203742
const auto *TC = ToolChains.front();
37213743
const char *BoundArch = nullptr;
@@ -3725,7 +3747,7 @@ class OffloadingActionBuilder final {
37253747
// Clear the input file, it is already a dependence to a host
37263748
// action.
37273749
DeviceCompilerInput = nullptr;
3728-
return ABRT_Success;
3750+
return SYCLDeviceOnly ? ABRT_Ignore_Host : ABRT_Success;
37293751
}
37303752

37313753
// Backend/Assemble actions are obsolete for the SYCL device side
@@ -4363,8 +4385,8 @@ class OffloadingActionBuilder final {
43634385
Arg *SYCLTargets =
43644386
C.getInputArgs().getLastArg(options::OPT_fsycl_targets_EQ);
43654387
Arg *SYCLAddTargets = Args.getLastArg(options::OPT_fsycl_add_targets_EQ);
4366-
bool HasValidSYCLRuntime = C.getInputArgs().hasFlag(options::OPT_fsycl,
4367-
options::OPT_fno_sycl, false);
4388+
bool HasValidSYCLRuntime = C.getInputArgs().hasFlag(
4389+
options::OPT_fsycl, options::OPT_fno_sycl, false);
43684390
bool SYCLfpgaTriple = false;
43694391
if (SYCLTargets || SYCLAddTargets) {
43704392
if (SYCLTargets) {
@@ -5423,19 +5445,6 @@ Action *Driver::ConstructPhaseAction(
54235445
Args.hasArg(options::OPT_S) ? types::TY_LLVM_IR : types::TY_LLVM_BC;
54245446
return C.MakeAction<BackendJobAction>(Input, Output);
54255447
}
5426-
if (Args.hasArg(options::OPT_fsycl_device_only)) {
5427-
types::ID OutputType =
5428-
Args.hasArg(options::OPT_S) ? types::TY_LLVM_IR : types::TY_LLVM_BC;
5429-
if (Args.hasFlag(options::OPT_fsycl_use_bitcode,
5430-
options::OPT_fno_sycl_use_bitcode, true))
5431-
return C.MakeAction<BackendJobAction>(Input, OutputType);
5432-
// Use of -fsycl-device-only creates a bitcode file, we need to translate
5433-
// that to a SPIR-V file with -fno-sycl-use-bitcode
5434-
auto *BackendAction =
5435-
C.MakeAction<BackendJobAction>(Input, types::TY_LLVM_BC);
5436-
return C.MakeAction<SPIRVTranslatorJobAction>(BackendAction,
5437-
types::TY_SPIRV);
5438-
}
54395448
return C.MakeAction<BackendJobAction>(Input, types::TY_PP_Asm);
54405449
}
54415450
case phases::Assemble:

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,12 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11361136
if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
11371137
DepFile = MF->getValue();
11381138
C.addFailureResultFile(DepFile, &JA);
1139+
// Populate the named dependency file to be used in the bundle
1140+
// or passed to the offline compilation.
1141+
if (Args.hasArg(options::OPT_fintelfpga) &&
1142+
JA.isDeviceOffloading(Action::OFK_SYCL))
1143+
C.getDriver().addFPGATempDepFile(
1144+
DepFile, Clang::getBaseInputName(Args, Inputs[0]));
11391145
} else if (Output.getType() == types::TY_Dependencies) {
11401146
DepFile = Output.getFilename();
11411147
} else if (!ArgMD) {
@@ -1232,8 +1238,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
12321238
if (JA.isOffloading(Action::OFK_HIP))
12331239
getToolChain().AddHIPIncludeArgs(Args, CmdArgs);
12341240

1235-
if (JA.isOffloading(Action::OFK_SYCL) ||
1236-
Args.hasArg(options::OPT_fsycl_device_only))
1241+
if (JA.isOffloading(Action::OFK_SYCL))
12371242
toolchains::SYCLToolChain::AddSYCLIncludeArgs(D, Args, CmdArgs);
12381243

12391244
// If we are offloading to a target via OpenMP we need to include the
@@ -4074,24 +4079,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
40744079
const ArgList &Args, const char *LinkingOutput) const {
40754080
const auto &TC = getToolChain();
40764081
const llvm::Triple &RawTriple = TC.getTriple();
4077-
llvm::Triple Triple = TC.getEffectiveTriple();
4082+
const llvm::Triple &Triple = TC.getEffectiveTriple();
4083+
const std::string &TripleStr = Triple.getTriple();
40784084

40794085
bool KernelOrKext =
40804086
Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
40814087
const Driver &D = TC.getDriver();
40824088
ArgStringList CmdArgs;
40834089

4084-
// -fsycl-device-only implies a SPIRV arch triple. Do not set if current
4085-
// effective triple is SYCLDevice
4086-
if (Args.hasArg(options::OPT_fsycl_device_only) &&
4087-
Triple.getEnvironment() != llvm::Triple::SYCLDevice) {
4088-
const char *SYCLTargetArch = "spir64";
4089-
if (C.getDefaultToolChain().getTriple().getArch() == llvm::Triple::x86)
4090-
SYCLTargetArch = "spir";
4091-
Triple = C.getDriver().MakeSYCLDeviceTriple(SYCLTargetArch);
4092-
}
4093-
const std::string &TripleStr = Triple.getTriple();
4094-
40954090
// Check number of inputs for sanity. We need at least one input.
40964091
assert(Inputs.size() >= 1 && "Must have at least one input.");
40974092
// CUDA/HIP compilation may have multiple inputs (source file + results of
@@ -4106,8 +4101,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41064101
bool IsHIP = JA.isOffloading(Action::OFK_HIP);
41074102
bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);
41084103
bool IsSYCLOffloadDevice = JA.isDeviceOffloading(Action::OFK_SYCL);
4109-
bool IsSYCL = JA.isOffloading(Action::OFK_SYCL) ||
4110-
Args.hasArg(options::OPT_fsycl_device_only);
4104+
bool IsSYCL = JA.isOffloading(Action::OFK_SYCL);
41114105
bool IsHeaderModulePrecompile = isa<HeaderModulePrecompileJobAction>(JA);
41124106
assert((IsCuda || IsHIP || (IsOpenMPDevice && Inputs.size() == 2) || IsSYCL ||
41134107
IsHeaderModulePrecompile || Inputs.size() == 1) &&
@@ -4163,9 +4157,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41634157
// step, and being part of the SYCL tool chain causes the incorrect target.
41644158
// FIXME - Is it possible to retain host environment when on a target
41654159
// device toolchain.
4166-
bool UseSYCLTriple =
4167-
IsSYCLDevice && (!IsSYCL || IsSYCLOffloadDevice ||
4168-
Args.hasArg(options::OPT_fsycl_device_only));
4160+
bool UseSYCLTriple = IsSYCLDevice && (!IsSYCL || IsSYCLOffloadDevice);
41694161

41704162
// Adjust IsWindowsXYZ for CUDA/HIP/SYCL compilations. Even when compiling in
41714163
// device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not
@@ -4267,9 +4259,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
42674259

42684260
// Pass the triple of host when doing SYCL
42694261
llvm::Triple AuxT = C.getDefaultToolChain().getTriple();
4270-
if (Args.hasArg(options::OPT_fsycl_device_only) &&
4271-
RawTriple.getEnvironment() == llvm::Triple::SYCLDevice)
4272-
AuxT = llvm::Triple(llvm::sys::getProcessTriple());
42734262
std::string NormalizedTriple = AuxT.normalize();
42744263
CmdArgs.push_back("-aux-triple");
42754264
CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
@@ -6410,8 +6399,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
64106399
// SYCL library is guaranteed to work correctly only with dynamic
64116400
// MSVC runtime.
64126401
llvm::Triple AuxT = C.getDefaultToolChain().getTriple();
6413-
if (Args.hasFlag(options::OPT_fsycl_device_only, OptSpecifier(), false))
6414-
AuxT = llvm::Triple(llvm::sys::getProcessTriple());
64156402
if (AuxT.isWindowsMSVCEnvironment()) {
64166403
CmdArgs.push_back("-D_MT");
64176404
CmdArgs.push_back("-D_DLL");
@@ -6936,7 +6923,6 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
69366923
unsigned RTOptionID = options::OPT__SLASH_MT;
69376924
bool isNVPTX = getToolChain().getTriple().isNVPTX();
69386925
bool isSYCLDevice =
6939-
Args.hasArg(options::OPT_fsycl_device_only) ||
69406926
getToolChain().getTriple().getEnvironment() == llvm::Triple::SYCLDevice;
69416927
bool isSYCL = Args.hasArg(options::OPT_fsycl) || isSYCLDevice;
69426928
// For SYCL Windows, /MD is the default.
@@ -7951,8 +7937,7 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
79517937

79527938
TranslatorArgs.push_back("-o");
79537939
TranslatorArgs.push_back(Output.getFilename());
7954-
if (getToolChain().getTriple().isSYCLDeviceEnvironment() ||
7955-
TCArgs.hasArg(options::OPT_fsycl_device_only)) {
7940+
if (getToolChain().getTriple().isSYCLDeviceEnvironment()) {
79567941
TranslatorArgs.push_back("-spirv-max-version=1.1");
79577942
TranslatorArgs.push_back("-spirv-debug-info-version=legacy");
79587943
// Prevent crash in the translator if input IR contains DIExpression

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ void CudaToolChain::addClangTargetOptions(
709709
CC1Args);
710710
}
711711

712-
auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv);
712+
auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv,
713+
options::OPT_fsycl_device_only);
713714
if (DeviceOffloadingKind == Action::OFK_SYCL && !NoLibSpirv) {
714715
std::string LibSpirvFile;
715716

clang/test/Driver/sycl-offload-intelfpga.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@
269269
// RUN: touch %t-1.cpp
270270
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga %t-1.cpp -c -o dummy.o 2>&1 \
271271
// RUN: | FileCheck -check-prefixes=CHK-FPGA-DEP-FILES3,CHK-FPGA-DEP-FILES3-LIN %s
272+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga %t-1.cpp -c -MMD -MF"dummy.d" 2>&1 \
273+
// RUN: | FileCheck -check-prefixes=CHK-FPGA-DEP-FILES3,CHK-FPGA-DEP-FILES3-LIN %s
272274
// RUN: %clang_cl -### -fsycl -fintelfpga %t-1.cpp -c -Fodummy.obj 2>&1 \
273275
// RUN: | FileCheck -check-prefixes=CHK-FPGA-DEP-FILES3,CHK-FPGA-DEP-FILES3-WIN %s
274276
// CHK-FPGA-DEP-FILES3: clang{{.*}} "-dependency-file" "[[OUTPUT:.+\.d]]"

clang/test/Driver/sycl.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
// RUN: %clang -### -fsycl-device-only -c -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=COMBINED
3737
// RUN: %clangxx -### -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
3838
// RUN: %clang_cl -### -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
39+
// RUN: %clangxx -### -fsycl-device-only -fsycl-unnamed-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-LAMBDA
40+
// RUN: %clang_cl -### -fsycl-device-only -fsycl-unnamed-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-LAMBDA
3941

40-
// DEFAULT: "-triple" "spir64-unknown-{{.*}}-sycldevice{{.*}}" "-fsycl-is-device"{{.*}} "-emit-llvm-bc"
42+
// DEFAULT: "-triple" "spir64-unknown-{{.*}}-sycldevice{{.*}}" "-fsycl-is-device"{{.*}} "-sycl-std=2020"{{.*}} "-emit-llvm-bc"
4143
// DEFAULT: "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"
4244
// DEFAULT: "-internal-isystem" "{{.*lib.*clang.*include}}"
4345
// DEFAULT: "-std=c++17"
@@ -49,6 +51,7 @@
4951
// TARGET: "-triple" "spir64-unknown-linux-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-emit-llvm-bc"
5052
// COMBINED: "-triple" "spir64-unknown-{{.*}}-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-emit-llvm-bc"
5153
// TEXTUAL: "-triple" "spir64-unknown-{{.*}}-sycldevice{{.*}}" "-fsycl-is-device"{{.*}} "-emit-llvm"
54+
// CHECK-LAMBDA: "-fsycl-unnamed-lambda"
5255

5356
/// -fsycl-device-only triple checks
5457
// RUN: %clang -fsycl-device-only -target x86_64-unknown-linux-gnu -### %s 2>&1 \
@@ -70,10 +73,10 @@
7073

7174
/// Verify -fsycl-device-only phases
7275
// RUN: %clang -### -ccc-print-phases -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT-PHASES
73-
// DEFAULT-PHASES: 0: input, "{{.*}}", c++
74-
// DEFAULT-PHASES: 1: preprocessor, {0}, c++-cpp-output
75-
// DEFAULT-PHASES: 2: compiler, {1}, ir
76-
// DEFAULT-PHASES: 3: backend, {2}, ir
76+
// DEFAULT-PHASES: 0: input, "{{.*}}", c++, (device-sycl)
77+
// DEFAULT-PHASES: 1: preprocessor, {0}, c++-cpp-output, (device-sycl)
78+
// DEFAULT-PHASES: 2: compiler, {1}, ir, (device-sycl)
79+
// DEFAULT-PHASES: 3: offload, "device-sycl (spir64-unknown-unknown-sycldevice)" {2}, ir
7780
// DEFAULT-PHASES-NOT: linker
7881

7982
// -fsycl-help tests

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function(add_libclc_sycl_binding OUT_LIST)
219219
COMMAND ${CMAKE_COMMAND} -E make_directory
220220
${CMAKE_CURRENT_BINARY_DIR}/sycldevice-binding-${ARG_TRIPLE}
221221
COMMAND ${LLVM_CLANG}
222-
-target ${ARG_TRIPLE}-sycldevice
222+
-fsycl-targets=${ARG_TRIPLE}-sycldevice
223223
-fsycl
224224
-fsycl-device-only
225225
-Dcl_khr_fp64

llvm-spirv/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,-llvm-header-guard'
2+
WarningsAsErrors: 'llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,-llvm-header-guard'
23
CheckOptions:
34
- key: readability-identifier-naming.ClassCase
45
value: CamelCase

llvm-spirv/.github/workflows/check-code-style.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ env:
2525

2626
jobs:
2727
clang-format-and-tidy:
28-
name: Run clang-format & clang-tidy
28+
name: clang-format & clang-tidy
2929
runs-on: ubuntu-latest
3030
steps:
3131
- name: Checkout sources
@@ -96,6 +96,28 @@ jobs:
9696
sed -i '/^$/d' clang-tidy.log
9797
if [ -s clang-tidy.log ]; then
9898
if ! grep -q "No relevant changes found." clang-tidy.log; then
99+
# Emit annotations
100+
while read -r line; do
101+
type="error"
102+
if [[ $line == *"warning:"* ]]; then
103+
type="warning"
104+
elif [[ $line == *"error:"* ]]; then
105+
type="error"
106+
else
107+
continue
108+
fi
109+
110+
absolute_path=$(echo $line | grep -Po "^[\w\d-./]+(?=:)")
111+
relative_path=${absolute_path##"${{ github.workspace }}"}
112+
113+
line_number=$(echo $line | grep -Po "(?<=:)\d+(?=:\d)")
114+
115+
message=$(echo $line | grep -Po "(?<=${type}: ).*$")
116+
117+
# see [workflow-commands] for documentation
118+
echo "::${type} file=${relative_path},line=${line_number}::${message}"
119+
done < clang-tidy.log
120+
99121
echo "clang-tidy found incorrectly written code:"
100122
cat clang-tidy.log
101123
exit 1

llvm-spirv/lib/SPIRV/SPIRVLowerConstExpr.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,21 @@ void SPIRVLowerConstExpr::visit(Module *M) {
170170
}
171171
II->replaceUsesOfWith(Op, Repl);
172172
WorkList.splice(WorkList.begin(), ReplList);
173-
} else if (auto CE = dyn_cast<ConstantExpr>(Op))
173+
} else if (auto CE = dyn_cast<ConstantExpr>(Op)) {
174174
WorkList.push_front(cast<Instruction>(LowerOp(CE)));
175+
} else if (auto MDAsVal = dyn_cast<MetadataAsValue>(Op)) {
176+
Metadata *MD = MDAsVal->getMetadata();
177+
if (auto ConstMD = dyn_cast<ConstantAsMetadata>(MD)) {
178+
Constant *C = ConstMD->getValue();
179+
if (auto CE = dyn_cast<ConstantExpr>(C)) {
180+
Value *RepInst = LowerOp(CE);
181+
Metadata *RepMD = ValueAsMetadata::get(RepInst);
182+
Value *RepMDVal = MetadataAsValue::get(M->getContext(), RepMD);
183+
II->setOperand(OI, RepMDVal);
184+
WorkList.push_front(cast<Instruction>(RepInst));
185+
}
186+
}
187+
}
175188
}
176189
}
177190
}

0 commit comments

Comments
 (0)