Skip to content

Commit 34fad4e

Browse files
committed
Merge remote-tracking branch 'intel_llvm/sycl' into llvmspirv_pulldown
2 parents b2e452a + 934f73a commit 34fad4e

File tree

97 files changed

+3825
-1268
lines changed

Some content is hidden

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

97 files changed

+3825
-1268
lines changed

buildbot/dependency.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ ocl_cpu_rt_ver_win=2021.13.11.0.23
77
# https://github.com/intel/compute-runtime/releases/tag/21.46.21636
88
ocl_gpu_rt_ver=21.46.21636
99
# Same GPU driver supports Level Zero and OpenCL
10-
# https://downloadmirror.intel.com/685037/igfx_win_101.1069.zip
11-
ocl_gpu_rt_ver_win=30.0.101.1069
10+
# https://downloadmirror.intel.com/691496/igfx_win_101.1191.zip
11+
ocl_gpu_rt_ver_win=101.1191
1212
intel_sycl_ver=build
1313

1414
# TBB binaries can be built from sources following instructions under
@@ -25,13 +25,13 @@ ocl_fpga_emu_ver=2021.13.11.0.23
2525
ocl_fpga_emu_ver_win=2021.13.11.0.23
2626
fpga_ver=20211014_000004
2727
fpga_ver_win=20211014_000004
28-
ocloc_ver_win=27.20.100.9168
28+
ocloc_ver_win=101.1191
2929

3030
[DRIVER VERSIONS]
3131
cpu_driver_lin=2021.13.11.0.23
3232
cpu_driver_win=2021.13.11.0.23
3333
gpu_driver_lin=21.46.21636
34-
gpu_driver_win=30.0.101.1069
34+
gpu_driver_win=101.1191
3535
fpga_driver_lin=2021.13.11.0.23
3636
fpga_driver_win=2021.13.11.0.23
3737
# NVidia CUDA driver

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,10 +2245,10 @@ def SYCLFPGAPipe : TypeAttr {
22452245
let Documentation = [SYCLFPGAPipeDocs];
22462246
}
22472247

2248-
def SYCLIntelPipeIO : Attr {
2248+
def SYCLIntelPipeIO : InheritableAttr {
22492249
let Spellings = [GNU<"io_pipe_id">];
22502250
let Args = [ExprArgument<"ID">];
2251-
let LangOpts = [SYCLIsDevice, SYCLIsHost];
2251+
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
22522252
let Subjects = SubjectList<[Var]>;
22532253
let Documentation = [SYCLIntelPipeIOAttrDocs];
22542254
}

clang/include/clang/Driver/Action.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class Action {
8282
BackendCompileJobClass,
8383
FileTableTformJobClass,
8484
AppendFooterJobClass,
85+
SpirvToIrWrapperJobClass,
8586
StaticLibJobClass,
8687

8788
JobClassFirst = PreprocessJobClass,
@@ -858,6 +859,17 @@ class AppendFooterJobAction : public JobAction {
858859
}
859860
};
860861

862+
class SpirvToIrWrapperJobAction : public JobAction {
863+
void anchor() override;
864+
865+
public:
866+
SpirvToIrWrapperJobAction(Action *Input, types::ID Type);
867+
868+
static bool classof(const Action *A) {
869+
return A->getKind() == SpirvToIrWrapperJobClass;
870+
}
871+
};
872+
861873
class StaticLibJobAction : public JobAction {
862874
void anchor() override;
863875

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,10 +2687,16 @@ defm sycl_id_queries_fit_in_int: BoolFOption<"sycl-id-queries-fit-in-int",
26872687
LangOpts<"SYCLValueFitInMaxInt">, DefaultTrue,
26882688
PosFlag<SetTrue, [], "Assume">, NegFlag<SetFalse, [], "Do not assume">,
26892689
BothFlags<[CC1Option, CoreOption], " that SYCL ID queries fit within MAX_INT.">>;
2690+
def fsycl_device_obj_EQ : Joined<["-"], "fsycl-device-obj=">,
2691+
Flags<[CoreOption]>, Values<"spirv,llvmir">, HelpText<"Specify format of "
2692+
"device code stored in the resulting object. Valid values are: spirv, llvmir "
2693+
"(default)">;
26902694
def fsycl_use_bitcode : Flag<["-"], "fsycl-use-bitcode">,
2691-
Flags<[CC1Option, CoreOption]>, HelpText<"Use LLVM bitcode instead of SPIR-V in fat objects">;
2695+
Alias<fsycl_device_obj_EQ>, AliasArgs<["llvmir"]>, Flags<[CoreOption]>,
2696+
HelpText<"Use LLVM bitcode instead of SPIR-V in fat objects">;
26922697
def fno_sycl_use_bitcode : Flag<["-"], "fno-sycl-use-bitcode">,
2693-
Flags<[CC1Option, CoreOption]>, HelpText<"Use SPIR-V instead of LLVM bitcode in fat objects">;
2698+
Alias<fsycl_device_obj_EQ>, AliasArgs<["spirv"]>, Flags<[CoreOption]>,
2699+
HelpText<"Use SPIR-V instead of LLVM bitcode in fat objects">;
26942700
def fsycl_link_EQ : Joined<["-"], "fsycl-link=">,
26952701
Flags<[CC1Option, CoreOption]>, HelpText<"Generate partially linked device and host object to be used at various stages of compilation">, Values<"image,early">;
26962702
def fsycl_link : Flag<["-"], "fsycl-link">, Alias<fsycl_link_EQ>,

clang/include/clang/Driver/ToolChain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class ToolChain {
158158
mutable std::unique_ptr<Tool> BackendCompiler;
159159
mutable std::unique_ptr<Tool> AppendFooter;
160160
mutable std::unique_ptr<Tool> FileTableTform;
161+
mutable std::unique_ptr<Tool> SpirvToIrWrapper;
161162

162163
Tool *getClang() const;
163164
Tool *getFlang() const;
@@ -175,6 +176,7 @@ class ToolChain {
175176
Tool *getBackendCompiler() const;
176177
Tool *getAppendFooter() const;
177178
Tool *getTableTform() const;
179+
Tool *getSpirvToIrWrapper() const;
178180

179181
mutable bool SanitizerArgsChecked = false;
180182
mutable std::unique_ptr<XRayArgs> XRayArguments;

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10612,6 +10612,8 @@ class Sema final {
1061210612
/// addSYCLIntelPipeIOAttr - Adds a pipe I/O attribute to a particular
1061310613
/// declaration.
1061410614
void addSYCLIntelPipeIOAttr(Decl *D, const AttributeCommonInfo &CI, Expr *ID);
10615+
SYCLIntelPipeIOAttr *MergeSYCLIntelPipeIOAttr(Decl *D,
10616+
const SYCLIntelPipeIOAttr &A);
1061510617

1061610618
/// AddSYCLIntelFPGAMaxConcurrencyAttr - Adds a max_concurrency attribute to a
1061710619
/// particular declaration.

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
328328
case OCLTK_Queue:
329329
case OCLTK_ReserveID:
330330
return LangAS::opencl_global;
331+
case OCLTK_Event:
332+
return LangAS::opencl_private;
331333

332334
default:
333335
return TargetInfo::getOpenCLTypeAddrSpace(TK);

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4154,11 +4154,10 @@ static void maybeEmitPipeStorageMetadata(const VarDecl *D,
41544154
if (!PipeTy->isStructureType())
41554155
return;
41564156

4157-
if (auto *IOAttr = D->getAttr<SYCLIntelPipeIOAttr>()) {
4158-
Optional<llvm::APSInt> ID =
4159-
IOAttr->getID()->getIntegerConstantExpr(D->getASTContext());
4157+
if (const auto *IOAttr = D->getAttr<SYCLIntelPipeIOAttr>()) {
4158+
const auto *CE = cast<ConstantExpr>(IOAttr->getID());
4159+
Optional<llvm::APSInt> ID = CE->getResultAsAPSInt();
41604160
llvm::LLVMContext &Context = CGM.getLLVMContext();
4161-
assert(bool(ID) && "Not an integer constant expression");
41624161

41634162
llvm::Metadata *AttrMDArgs[] = {
41644163
llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(

clang/lib/Driver/Action.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const char *Action::getClassName(ActionClass AC) {
6161
return "static-lib-linker";
6262
case ForEachWrappingClass:
6363
return "foreach";
64+
case SpirvToIrWrapperJobClass:
65+
return "spirv-to-ir-wrapper";
6466
}
6567

6668
llvm_unreachable("invalid class");
@@ -544,6 +546,12 @@ void StaticLibJobAction::anchor() {}
544546
StaticLibJobAction::StaticLibJobAction(ActionList &Inputs, types::ID Type)
545547
: JobAction(StaticLibJobClass, Inputs, Type) {}
546548

549+
void SpirvToIrWrapperJobAction::anchor() {}
550+
551+
SpirvToIrWrapperJobAction::SpirvToIrWrapperJobAction(Action *Input,
552+
types::ID Type)
553+
: JobAction(SpirvToIrWrapperJobClass, Input, Type) {}
554+
547555
ForEachWrappingAction::ForEachWrappingAction(JobAction *TFormInput,
548556
JobAction *Job)
549557
: Action(ForEachWrappingClass, {TFormInput, Job}, Job->getType()) {}

clang/lib/Driver/Driver.cpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,14 @@ bool Driver::checkForOffloadStaticLib(Compilation &C,
30943094
return false;
30953095
}
30963096

3097+
/// Check whether the given input tree contains any clang-offload-dependency
3098+
/// actions.
3099+
static bool ContainsOffloadDepsAction(const Action *A) {
3100+
if (isa<OffloadDepsJobAction>(A))
3101+
return true;
3102+
return llvm::any_of(A->inputs(), ContainsOffloadDepsAction);
3103+
}
3104+
30973105
namespace {
30983106
/// Provides a convenient interface for different programming models to generate
30993107
/// the required device actions.
@@ -4199,19 +4207,22 @@ class OffloadingActionBuilder final {
41994207
if ((SYCLDeviceOnly || Args.hasArg(options::OPT_emit_llvm)) &&
42004208
Args.hasArg(options::OPT_S))
42014209
OutputType = types::TY_LLVM_IR;
4202-
if (SYCLDeviceOnly) {
4203-
if (Args.hasFlag(options::OPT_fno_sycl_use_bitcode,
4204-
options::OPT_fsycl_use_bitcode, false)) {
4205-
auto *CompileAction =
4206-
C.MakeAction<CompileJobAction>(A, types::TY_LLVM_BC);
4207-
A = C.MakeAction<SPIRVTranslatorJobAction>(CompileAction,
4208-
types::TY_SPIRV);
4210+
// Use of -fsycl-device-obj=spirv converts the original LLVM-IR
4211+
// file to SPIR-V for later consumption.
4212+
if ((SYCLDeviceOnly || FinalPhase != phases::Link) &&
4213+
Args.getLastArgValue(options::OPT_fsycl_device_obj_EQ)
4214+
.equals_insensitive("spirv")) {
4215+
auto *CompileAction =
4216+
C.MakeAction<CompileJobAction>(A, types::TY_LLVM_BC);
4217+
A = C.MakeAction<SPIRVTranslatorJobAction>(CompileAction,
4218+
types::TY_SPIRV);
4219+
if (SYCLDeviceOnly)
42094220
continue;
4210-
}
4221+
} else {
4222+
if (Args.hasArg(options::OPT_fsyntax_only))
4223+
OutputType = types::TY_Nothing;
4224+
A = C.MakeAction<CompileJobAction>(A, OutputType);
42114225
}
4212-
if (Args.hasArg(options::OPT_fsyntax_only))
4213-
OutputType = types::TY_Nothing;
4214-
A = C.MakeAction<CompileJobAction>(A, OutputType);
42154226
DeviceCompilerInput = A;
42164227
}
42174228
const DeviceTargetInfo &DevTarget = SYCLTargetInfoList.back();
@@ -4619,7 +4630,19 @@ class OffloadingActionBuilder final {
46194630
DA.add(*DeviceWrappingAction, *TC, BoundArch, Action::OFK_SYCL);
46204631
continue;
46214632
} else if (!types::isFPGA(Input->getType())) {
4622-
LinkObjects.push_back(Input);
4633+
// No need for any conversion if we are coming in from the
4634+
// clang-offload-deps or regular compilation path.
4635+
if (isNVPTX || isAMDGCN || ContainsOffloadDepsAction(Input) ||
4636+
ContainsCompileOrAssembleAction(Input)) {
4637+
LinkObjects.push_back(Input);
4638+
continue;
4639+
}
4640+
Action *ConvertSPIRVAction =
4641+
C.MakeAction<SpirvToIrWrapperJobAction>(
4642+
Input, Input->getType() == types::TY_Archive
4643+
? types::TY_Tempfilelist
4644+
: types::TY_LLVM_BC);
4645+
LinkObjects.push_back(ConvertSPIRVAction);
46234646
}
46244647
}
46254648
if (LinkObjects.empty())

clang/lib/Driver/ToolChain.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,12 @@ Tool *ToolChain::getTableTform() const {
370370
return FileTableTform.get();
371371
}
372372

373+
Tool *ToolChain::getSpirvToIrWrapper() const {
374+
if (!SpirvToIrWrapper)
375+
SpirvToIrWrapper.reset(new tools::SpirvToIrWrapper(*this));
376+
return SpirvToIrWrapper.get();
377+
}
378+
373379
Tool *ToolChain::getTool(Action::ActionClass AC) const {
374380
switch (AC) {
375381
case Action::AssembleJobClass:
@@ -430,6 +436,9 @@ Tool *ToolChain::getTool(Action::ActionClass AC) const {
430436

431437
case Action::FileTableTformJobClass:
432438
return getTableTform();
439+
440+
case Action::SpirvToIrWrapperJobClass:
441+
return getSpirvToIrWrapper();
433442
}
434443

435444
llvm_unreachable("Invalid tool kind.");

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8593,6 +8593,9 @@ void OffloadBundler::ConstructJobMultipleOutputs(
85938593
if (IsFPGADepUnbundle)
85948594
TypeArg = "o";
85958595

8596+
if (InputType == types::TY_Archive && getToolChain().getTriple().isSPIR())
8597+
TypeArg = "aoo";
8598+
85968599
// Get the type.
85978600
CmdArgs.push_back(TCArgs.MakeArgString(Twine("-type=") + TypeArg));
85988601

@@ -9021,7 +9024,7 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
90219024
std::string DefaultExtArg =
90229025
",+SPV_EXT_shader_atomic_float_add,+SPV_EXT_shader_atomic_float_min_max"
90239026
",+SPV_KHR_no_integer_wrap_decoration,+SPV_KHR_float_controls"
9024-
",+SPV_KHR_expect_assume";
9027+
",+SPV_KHR_expect_assume,+SPV_KHR_linkonce_odr";
90259028
std::string INTELExtArg =
90269029
",+SPV_INTEL_subgroups,+SPV_INTEL_media_block_io"
90279030
",+SPV_INTEL_device_side_avc_motion_estimation"
@@ -9396,3 +9399,38 @@ void AppendFooter::ConstructJob(Compilation &C, const JobAction &JA,
93969399
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
93979400
CmdArgs, None));
93989401
}
9402+
9403+
void SpirvToIrWrapper::ConstructJob(Compilation &C, const JobAction &JA,
9404+
const InputInfo &Output,
9405+
const InputInfoList &Inputs,
9406+
const llvm::opt::ArgList &TCArgs,
9407+
const char *LinkingOutput) const {
9408+
InputInfoList ForeachInputs;
9409+
ArgStringList CmdArgs;
9410+
9411+
assert(Inputs.size() == 1 &&
9412+
"Only one input expected to spirv-to-ir-wrapper");
9413+
9414+
// Input File
9415+
for (const auto &I : Inputs) {
9416+
if (I.getType() == types::TY_Archive)
9417+
ForeachInputs.push_back(I);
9418+
addArgs(CmdArgs, TCArgs, {I.getFilename()});
9419+
}
9420+
9421+
// Output File
9422+
addArgs(CmdArgs, TCArgs, {"-o", Output.getFilename()});
9423+
9424+
auto Cmd = std::make_unique<Command>(
9425+
JA, *this, ResponseFileSupport::None(),
9426+
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
9427+
CmdArgs, None);
9428+
if (!ForeachInputs.empty()) {
9429+
StringRef ParallelJobs =
9430+
TCArgs.getLastArgValue(options::OPT_fsycl_max_parallel_jobs_EQ);
9431+
tools::SYCL::constructLLVMForeachCommand(
9432+
C, JA, std::move(Cmd), ForeachInputs, Output, this, "",
9433+
types::getTypeTempSuffix(types::TY_Tempfilelist), ParallelJobs);
9434+
} else
9435+
C.addCommand(std::move(Cmd));
9436+
}

clang/lib/Driver/ToolChains/Clang.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,21 @@ class LLVM_LIBRARY_VISIBILITY AppendFooter final : public Tool {
266266
const char *LinkingOutput) const override;
267267
};
268268

269+
/// SPIR-V to LLVM-IR wrapper tool
270+
class LLVM_LIBRARY_VISIBILITY SpirvToIrWrapper final : public Tool {
271+
public:
272+
SpirvToIrWrapper(const ToolChain &TC)
273+
: Tool("Convert SPIR-V to LLVM-IR if needed", "spirv-to-ir-wrapper", TC) {
274+
}
275+
276+
bool hasIntegratedCPP() const override { return false; }
277+
bool hasGoodDiagnostics() const override { return true; }
278+
void ConstructJob(Compilation &C, const JobAction &JA,
279+
const InputInfo &Output, const InputInfoList &Inputs,
280+
const llvm::opt::ArgList &TCArgs,
281+
const char *LinkingOutput) const override;
282+
};
283+
269284
} // end namespace tools
270285

271286
} // end namespace driver

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
186186
const ArgList &Args, StringRef SubArchName, StringRef OutputFilePrefix,
187187
const InputInfoList &InputFiles) const {
188188
// Split inputs into libraries which have 'archive' type and other inputs
189-
// which can be either objects or list files. Objects/list files are linked
190-
// together in a usual way, but the libraries need to be linked differently.
189+
// which can be either objects or list files. Object files are linked together
190+
// in a usual way, but the libraries/list files need to be linked differently.
191191
// We need to fetch only required symbols from the libraries. With the current
192192
// llvm-link command line interface that can be achieved with two step
193193
// linking: at the first step we will link objects into an intermediate
@@ -236,7 +236,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
236236
if (II.getType() == types::TY_Tempfilelist) {
237237
// Pass the unbundled list with '@' to be processed.
238238
std::string FileName(II.getFilename());
239-
Objs.push_back(C.getArgs().MakeArgString("@" + FileName));
239+
Libs.push_back(C.getArgs().MakeArgString("@" + FileName));
240240
} else if (II.getType() == types::TY_Archive && !LinkSYCLDeviceLibs) {
241241
Libs.push_back(II.getFilename());
242242
} else
@@ -350,9 +350,8 @@ void SYCL::Linker::ConstructJob(Compilation &C, const JobAction &JA,
350350
for (const auto &II : Inputs) {
351351
if (!II.isFilename())
352352
continue;
353-
if (Args.hasFlag(options::OPT_fsycl_use_bitcode,
354-
options::OPT_fno_sycl_use_bitcode, true) ||
355-
Args.hasArg(options::OPT_foffload_static_lib_EQ))
353+
if (!Args.getLastArgValue(options::OPT_fsycl_device_obj_EQ)
354+
.equals_insensitive("spirv"))
356355
SpirvInputs.push_back(II);
357356
else {
358357
const char *LLVMSpirvOutputFile = constructLLVMSpirvCommand(

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,8 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
27302730
NewAttr = S.MergeSYCLDeviceHasAttr(D, *A);
27312731
else if (const auto *A = dyn_cast<SYCLUsesAspectsAttr>(Attr))
27322732
NewAttr = S.MergeSYCLUsesAspectsAttr(D, *A);
2733+
else if (const auto *A = dyn_cast<SYCLIntelPipeIOAttr>(Attr))
2734+
NewAttr = S.MergeSYCLIntelPipeIOAttr(D, *A);
27332735
else if (Attr->shouldInheritEvenIfAlreadyPresent() || !DeclHasAttr(D, Attr))
27342736
NewAttr = cast<InheritableAttr>(Attr->clone(S.Context));
27352737

0 commit comments

Comments
 (0)