Skip to content

Commit bd6fd33

Browse files
committed
Merge remote-tracking branch 'origin/sycl' into newPM_add_itt_annot_pass_to_codegen
2 parents f139546 + 010c535 commit bd6fd33

File tree

107 files changed

+3438
-599
lines changed

Some content is hidden

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

107 files changed

+3438
-599
lines changed

buildbot/configure.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def do_configure(args):
3232
libclc_targets_to_build = ''
3333
libclc_gen_remangled_variants = 'OFF'
3434
sycl_build_pi_cuda = 'OFF'
35-
sycl_build_pi_esimd_emulator = 'OFF'
35+
sycl_build_pi_esimd_emulator = 'ON'
3636
sycl_build_pi_hip = 'OFF'
3737
sycl_build_pi_hip_platform = 'AMD'
3838
sycl_clang_extra_flags = ''
@@ -50,8 +50,8 @@ def do_configure(args):
5050
if args.arm:
5151
llvm_targets_to_build = 'ARM;AArch64'
5252

53-
if args.enable_esimd_cpu_emulation:
54-
sycl_build_pi_esimd_emulator = 'ON'
53+
if args.disable_esimd_emulator:
54+
sycl_build_pi_esimd_emulator = 'OFF'
5555

5656
if args.cuda or args.hip:
5757
llvm_enable_projects += ';libclc'
@@ -213,7 +213,7 @@ def main():
213213
parser.add_argument("--hip-platform", type=str, choices=['AMD', 'NVIDIA'], default='AMD', help="choose hardware platform for HIP backend")
214214
parser.add_argument("--hip-amd-arch", type=str, help="Sets AMD gpu architecture for llvm lit tests, this is only needed for the HIP backend and AMD platform")
215215
parser.add_argument("--arm", action='store_true', help="build ARM support rather than x86")
216-
parser.add_argument("--enable-esimd-cpu-emulation", action='store_true', help="build with ESIMD_CPU emulation support")
216+
parser.add_argument("--disable-esimd-emulator", action='store_true', help="exclude ESIMD_EMULATOR support")
217217
parser.add_argument("--no-assertions", action='store_true', help="build without assertions")
218218
parser.add_argument("--docs", action='store_true', help="build Doxygen documentation")
219219
parser.add_argument("--no-werror", action='store_true', help="Don't treat warnings as errors")

buildbot/dependency.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ 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+
# https://downloadmirror.intel.com/691496/igfx_win_101.1191.zip
2829
ocloc_ver_win=101.1191
2930

3031
[DRIVER VERSIONS]

clang/include/clang/Basic/Attr.td

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,15 +1280,17 @@ def SYCLRegisterNum : InheritableAttr {
12801280
let Documentation = [SYCLRegisterNumDocs];
12811281
}
12821282

1283-
// Used by FE to mark ESIMD kernel pointer parameters which correspond to the
1283+
// Used by FE to mark SYCL kernel pointer parameters which correspond to the
12841284
// original lambda's captured accessors. FE turns the attribute to some metadata
1285-
// required by the ESIMD Back-End.
1286-
// Not supposed to be used directly in the source - SYCL device compiler FE
1287-
// automatically adds it for ESIMD kernels, hence undocumented.
1288-
def SYCLSimdAccessorPtr : InheritableAttr {
1289-
// No spelling, as this attribute can't be created in the source code.
1285+
// required by the device back-end.
1286+
// This attribute does not require custom semantic handling
1287+
// hence we set the SemaHandler field to 0.
1288+
// The attribute is not for public consumption, and is an implicitly-created attribute
1289+
// that has no visible spelling, hence undocumented.
1290+
def SYCLAccessorPtr : Attr {
1291+
// This attribute has no spellings as it is only ever created implicitly.
12901292
let Spellings = [];
1291-
let Subjects = SubjectList<[ParmVar]>;
1293+
let SemaHandler = 0;
12921294
let Documentation = [Undocumented];
12931295
}
12941296

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11627,6 +11627,8 @@ def err_sycl_expected_finalize_method : Error<
1162711627
def ext_sycl_2020_attr_spelling : ExtWarn<
1162811628
"use of attribute %0 is a SYCL 2020 extension">,
1162911629
InGroup<Sycl2017Compat>;
11630+
def err_sycl_esimd_not_supported_for_type : Error<
11631+
"type %0 is not supported in ESIMD context">;
1163011632
def err_sycl_taking_address_of_wrong_function : Error<
1163111633
"taking address of a function not marked with "
1163211634
"'intel::device_indirectly_callable' attribute is not allowed in SYCL device "

clang/include/clang/Basic/Version.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#ifndef LLVM_CLANG_BASIC_VERSION_H
1616
#define LLVM_CLANG_BASIC_VERSION_H
1717

18+
#include "clang/Basic/LangOptions.h"
1819
#include "clang/Basic/Version.inc"
20+
#include "llvm/ADT/SmallVector.h"
1921
#include "llvm/ADT/StringRef.h"
2022

2123
namespace clang {
@@ -56,6 +58,11 @@ namespace clang {
5658
/// for use in the CPP __VERSION__ macro, which includes the clang version
5759
/// number, the repository version, and the vendor tag.
5860
std::string getClangFullCPPVersion();
61+
62+
/// Retrieves a string representing the SYCL standard version for use in
63+
/// the CL_SYCL_LANGUAGE_VERSION and SYCL_LANGUAGE_VERSION macros.
64+
llvm::SmallVector<std::pair<llvm::StringRef, llvm::StringRef>, 2>
65+
getSYCLVersionMacros(const LangOptions &LangOpts);
5966
}
6067

6168
#endif // LLVM_CLANG_BASIC_VERSION_H

clang/include/clang/Driver/Action.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ class OffloadUnbundlingJobAction final : public JobAction {
625625
public:
626626
// Offloading unbundling doesn't change the type of output.
627627
OffloadUnbundlingJobAction(Action *Input);
628+
OffloadUnbundlingJobAction(Action *Input, types::ID Type);
628629
OffloadUnbundlingJobAction(ActionList &Inputs, types::ID Type);
629630

630631
/// Register information about a dependent action.

clang/lib/Basic/Version.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,13 @@ std::string getClangFullCPPVersion() {
123123
return buf;
124124
}
125125

126+
llvm::SmallVector<std::pair<llvm::StringRef, llvm::StringRef>, 2>
127+
getSYCLVersionMacros(const LangOptions &LangOpts) {
128+
if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017)
129+
return {{"CL_SYCL_LANGUAGE_VERSION", "121"},
130+
{"SYCL_LANGUAGE_VERSION", "201707"}};
131+
if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
132+
return {{"SYCL_LANGUAGE_VERSION", "202001"}};
133+
llvm_unreachable("SYCL standard should be set");
134+
}
126135
} // end namespace clang

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,17 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
14881488
MPM.addPass(SPIRITTAnnotationsPass());
14891489
}
14901490

1491+
// Allocate static local memory in SYCL kernel scope for each allocation
1492+
// call. It should be called after inlining pass.
1493+
if (LangOpts.SYCLIsDevice) {
1494+
// Group local memory pass depends on inlining. Turn it on even in case if
1495+
// all llvm passes or SYCL early optimizations are disabled.
1496+
// FIXME: Remove this workaround when dependency on inlining is eliminated.
1497+
if (CodeGenOpts.DisableLLVMPasses)
1498+
MPM.addPass(AlwaysInlinerPass(false));
1499+
MPM.addPass(SYCLLowerWGLocalMemoryPass());
1500+
}
1501+
14911502
// Add a verifier pass if requested. We don't have to do this if the action
14921503
// requires code generation because there will already be a verifier pass in
14931504
// the code-generation pipeline.

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,10 +1728,16 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
17281728
// MDNode for the intel_buffer_location attribute.
17291729
SmallVector<llvm::Metadata *, 8> argSYCLBufferLocationAttr;
17301730

1731+
// MDNode for listing SYCL kernel pointer arguments originating from
1732+
// accessors.
1733+
SmallVector<llvm::Metadata *, 8> argSYCLKernelRuntimeAligned;
1734+
17311735
// MDNode for listing ESIMD kernel pointer arguments originating from
1732-
// accessors
1736+
// accessors.
17331737
SmallVector<llvm::Metadata *, 8> argESIMDAccPtrs;
17341738

1739+
bool isKernelArgAnAccessor = false;
1740+
17351741
if (FD && CGF)
17361742
for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) {
17371743
const ParmVarDecl *parm = FD->getParamDecl(i);
@@ -1835,17 +1841,38 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function *Fn,
18351841
SYCLBufferLocationAttr->getLocationID()))
18361842
: llvm::ConstantAsMetadata::get(CGF->Builder.getInt32(-1)));
18371843

1844+
// If a kernel pointer argument comes from an accessor, we generate
1845+
// a new metadata(kernel_arg_runtime_aligned) to the kernel to indicate
1846+
// that this pointer has runtime allocated alignment. The value of any
1847+
// "kernel_arg_runtime_aligned" metadata element is 'true' for any kernel
1848+
// arguments that corresponds to the base pointer of an accessor and
1849+
// 'false' otherwise.
1850+
if (parm->hasAttr<SYCLAccessorPtrAttr>()) {
1851+
isKernelArgAnAccessor = true;
1852+
argSYCLKernelRuntimeAligned.push_back(
1853+
llvm::ConstantAsMetadata::get(CGF->Builder.getTrue()));
1854+
} else {
1855+
argSYCLKernelRuntimeAligned.push_back(
1856+
llvm::ConstantAsMetadata::get(CGF->Builder.getFalse()));
1857+
}
1858+
18381859
if (FD->hasAttr<SYCLSimdAttr>())
18391860
argESIMDAccPtrs.push_back(llvm::ConstantAsMetadata::get(
1840-
CGF->Builder.getInt1(parm->hasAttr<SYCLSimdAccessorPtrAttr>())));
1861+
CGF->Builder.getInt1(parm->hasAttr<SYCLAccessorPtrAttr>())));
18411862
}
18421863

18431864
bool IsEsimdFunction = FD && FD->hasAttr<SYCLSimdAttr>();
18441865

1845-
if (LangOpts.SYCLIsDevice && !IsEsimdFunction)
1866+
if (LangOpts.SYCLIsDevice && !IsEsimdFunction) {
18461867
Fn->setMetadata("kernel_arg_buffer_location",
18471868
llvm::MDNode::get(VMContext, argSYCLBufferLocationAttr));
1848-
else {
1869+
// Generate this metadata only if atleast one kernel argument is an
1870+
// accessor.
1871+
if (isKernelArgAnAccessor)
1872+
Fn->setMetadata(
1873+
"kernel_arg_runtime_aligned",
1874+
llvm::MDNode::get(VMContext, argSYCLKernelRuntimeAligned));
1875+
} else {
18491876
Fn->setMetadata("kernel_arg_addr_space",
18501877
llvm::MDNode::get(VMContext, addressQuals));
18511878
Fn->setMetadata("kernel_arg_access_qual",

clang/lib/Driver/Action.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,12 @@ void OffloadUnbundlingJobAction::anchor() {}
439439
OffloadUnbundlingJobAction::OffloadUnbundlingJobAction(Action *Input)
440440
: JobAction(OffloadUnbundlingJobClass, Input, Input->getType()) {}
441441

442+
OffloadUnbundlingJobAction::OffloadUnbundlingJobAction(Action *Input,
443+
types::ID Type)
444+
: JobAction(OffloadUnbundlingJobClass, Input, Type) {}
445+
442446
OffloadUnbundlingJobAction::OffloadUnbundlingJobAction(ActionList &Inputs,
443-
types:: ID Type)
447+
types::ID Type)
444448
: JobAction(OffloadUnbundlingJobClass, Inputs, Type) {}
445449

446450
void OffloadWrapperJobAction::anchor() {}

clang/lib/Driver/Driver.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4645,7 +4645,7 @@ class OffloadingActionBuilder final {
46454645
}
46464646
Action *ConvertSPIRVAction =
46474647
C.MakeAction<SpirvToIrWrapperJobAction>(
4648-
Input, Input->getType() == types::TY_Archive
4648+
Input, Input->getType() == types::TY_Tempfilelist
46494649
? types::TY_Tempfilelist
46504650
: types::TY_LLVM_BC);
46514651
LinkObjects.push_back(ConvertSPIRVAction);
@@ -5313,11 +5313,15 @@ class OffloadingActionBuilder final {
53135313
HostAction->getType() == types::TY_PP_HIP)) {
53145314
ActionList HostActionList;
53155315
Action *A(HostAction);
5316+
bool HasSPIRTarget = false;
53165317
// Only check for FPGA device information when using fpga SubArch.
53175318
auto SYCLTCRange = C.getOffloadToolChains<Action::OFK_SYCL>();
5318-
for (auto TI = SYCLTCRange.first, TE = SYCLTCRange.second; TI != TE; ++TI)
5319+
for (auto TI = SYCLTCRange.first, TE = SYCLTCRange.second; TI != TE;
5320+
++TI) {
53195321
HasFPGATarget |= TI->second->getTriple().getSubArch() ==
53205322
llvm::Triple::SPIRSubArch_fpga;
5323+
HasSPIRTarget |= TI->second->getTriple().isSPIR();
5324+
}
53215325
bool isArchive = !(HostAction->getType() == types::TY_Object &&
53225326
isObjectFile(InputArg->getAsString(Args)));
53235327
if (!HasFPGATarget && isArchive &&
@@ -5326,7 +5330,10 @@ class OffloadingActionBuilder final {
53265330
return false;
53275331
if (HasFPGATarget && !updateInputForFPGA(A, InputArg, Args))
53285332
return false;
5329-
auto UnbundlingHostAction = C.MakeAction<OffloadUnbundlingJobAction>(A);
5333+
auto UnbundlingHostAction = C.MakeAction<OffloadUnbundlingJobAction>(
5334+
A, (HasSPIRTarget && HostAction->getType() == types::TY_Archive)
5335+
? types::TY_Tempfilelist
5336+
: A->getType());
53305337
UnbundlingHostAction->registerDependentActionInfo(
53315338
C.getSingleOffloadToolChain<Action::OFK_Host>(),
53325339
/*BoundArch=*/StringRef(), Action::OFK_Host);
@@ -6998,7 +7005,8 @@ InputInfo Driver::BuildJobsForActionNoCache(
69987005
EffectiveTriple.getSubArch() == llvm::Triple::SPIRSubArch_fpga &&
69997006
C.getInputArgs().hasArg(options::OPT_fsycl_link_EQ));
70007007
if (C.getDriver().getOffloadStaticLibSeen() &&
7001-
JA->getType() == types::TY_Archive) {
7008+
(JA->getType() == types::TY_Archive ||
7009+
JA->getType() == types::TY_Tempfilelist)) {
70027010
// Host part of the unbundled static archive is not used.
70037011
if (UI.DependentOffloadKind == Action::OFK_Host)
70047012
continue;
@@ -7007,10 +7015,11 @@ InputInfo Driver::BuildJobsForActionNoCache(
70077015
if (UI.DependentOffloadKind == Action::OFK_Host && IsFPGAObjLink)
70087016
continue;
70097017
std::string TmpFileName = C.getDriver().GetTemporaryPath(
7010-
llvm::sys::path::stem(BaseInput), "a");
7018+
llvm::sys::path::stem(BaseInput),
7019+
JA->getType() == types::TY_Archive ? "a" : "txt");
70117020
const char *TmpFile =
70127021
C.addTempFile(C.getArgs().MakeArgString(TmpFileName));
7013-
CurI = InputInfo(types::TY_Archive, TmpFile, TmpFile);
7022+
CurI = InputInfo(JA->getType(), TmpFile, TmpFile);
70147023
} else if (types::isFPGA(JA->getType())) {
70157024
std::string Ext(types::getTypeTempSuffix(JA->getType()));
70167025
types::ID TI = types::TY_Object;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5790,6 +5790,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57905790
CmdArgs.push_back("-treat-scalable-fixed-error-as-warning");
57915791
}
57925792

5793+
// Enable local accessor to shared memory pass for SYCL.
5794+
if (isa<BackendJobAction>(JA) && IsSYCL) {
5795+
CmdArgs.push_back("-mllvm");
5796+
CmdArgs.push_back("-sycl-enable-local-accessor");
5797+
}
57935798
// These two are potentially updated by AddClangCLArgs.
57945799
codegenoptions::DebugInfoKind DebugInfoKind = codegenoptions::NoDebugInfo;
57955800
bool EmitCodeView = false;
@@ -8593,7 +8598,11 @@ void OffloadBundler::ConstructJobMultipleOutputs(
85938598
if (IsFPGADepUnbundle)
85948599
TypeArg = "o";
85958600

8596-
if (InputType == types::TY_Archive && getToolChain().getTriple().isSPIR())
8601+
bool HasSPIRTarget = false;
8602+
auto SYCLTCRange = C.getOffloadToolChains<Action::OFK_SYCL>();
8603+
for (auto TI = SYCLTCRange.first, TE = SYCLTCRange.second; TI != TE; ++TI)
8604+
HasSPIRTarget |= TI->second->getTriple().isSPIR();
8605+
if (InputType == types::TY_Archive && HasSPIRTarget)
85978606
TypeArg = "aoo";
85988607

85998608
// Get the type.
@@ -9408,7 +9417,7 @@ void SpirvToIrWrapper::ConstructJob(Compilation &C, const JobAction &JA,
94089417

94099418
// Input File
94109419
for (const auto &I : Inputs) {
9411-
if (I.getType() == types::TY_Archive)
9420+
if (I.getType() == types::TY_Tempfilelist)
94129421
ForeachInputs.push_back(I);
94139422
addArgs(CmdArgs, TCArgs, {I.getFilename()});
94149423
}

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ CudaInstallationDetector::CudaInstallationDetector(
136136
Candidates.emplace_back(
137137
Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str());
138138
} else if (HostTriple.isOSWindows()) {
139+
// CUDA_PATH is set by the installer, prefer it over other versions that
140+
// might be present on the system.
141+
if (const char *CudaPathEnvVar = ::getenv("CUDA_PATH"))
142+
Candidates.emplace_back(CudaPathEnvVar);
143+
139144
for (const char *Ver : Versions)
140145
Candidates.emplace_back(
141146
D.SysRoot + "/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v" +

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
7878
const llvm::opt::ArgList &Args) const {
7979
// Construct lld command.
8080
// The output from ld.lld is an HSA code object file.
81-
ArgStringList LldArgs{"-flavor", "gnu", "--no-undefined", "-shared",
82-
"-plugin-opt=-amdgpu-internalize-symbols"};
81+
ArgStringList LldArgs{"-flavor",
82+
"gnu",
83+
"--no-undefined",
84+
"-shared",
85+
"-plugin-opt=-amdgpu-internalize-symbols",
86+
"-plugin-opt=-sycl-enable-local-accessor"};
8387

8488
auto &TC = getToolChain();
8589
auto &D = TC.getDriver();

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,9 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
491491

492492
if (LangOpts.SYCLIsDevice || LangOpts.SYCLIsHost) {
493493
// SYCL Version is set to a value when building SYCL applications
494-
if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017) {
495-
Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
496-
Builder.defineMacro("SYCL_LANGUAGE_VERSION", "201707");
497-
} else if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
498-
Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202001");
494+
for (const std::pair<StringRef, StringRef> &Macro :
495+
getSYCLVersionMacros(LangOpts))
496+
Builder.defineMacro(Macro.first, Macro.second);
499497

500498
if (LangOpts.SYCLValueFitInMaxInt)
501499
Builder.defineMacro("__SYCL_ID_QUERIES_FIT_IN_INT__");

clang/lib/Sema/Sema.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,8 +1770,15 @@ class DeferredDiagnosticsEmitter
17701770
// Emit any deferred diagnostics for FD
17711771
void emitDeferredDiags(FunctionDecl *FD, bool ShowCallStack) {
17721772
auto It = S.DeviceDeferredDiags.find(FD);
1773-
if (It == S.DeviceDeferredDiags.end())
1773+
if (It == S.DeviceDeferredDiags.end()) {
1774+
// If this is a template instantiation, check if its declaration
1775+
// is on the deferred diagnostics stack.
1776+
if (FD->isTemplateInstantiation()) {
1777+
FD = FD->getTemplateInstantiationPattern();
1778+
emitDeferredDiags(FD, ShowCallStack);
1779+
}
17741780
return;
1781+
}
17751782
bool HasWarningOrError = false;
17761783
bool FirstDiag = true;
17771784
for (Sema::DeviceDeferredDiagnostic &D : It->second) {

0 commit comments

Comments
 (0)