Skip to content

Commit 7242255

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web'
2 parents ca34f97 + 6504ba0 commit 7242255

File tree

72 files changed

+5972
-752
lines changed

Some content is hidden

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

72 files changed

+5972
-752
lines changed

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
clang/ @premanandrao @elizabethandrews @AaronBallman
55

66
# Driver
7-
clang/**/Driver @mdtoguchi @AGindinson
7+
clang/**/Driver @mdtoguchi @AGindinson @hchilama
88

99
# LLVM-SPIRV translator
1010
llvm-spirv/ @AlexeySotkin @AlexeySachkov

clang/include/clang/AST/PrettyPrinter.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ struct PrintingPolicy {
7575
MSVCFormatting(false), ConstantsAsWritten(false),
7676
SuppressImplicitBase(false), FullyQualifiedName(false),
7777
SuppressDefinition(false), SuppressDefaultTemplateArguments(false),
78-
PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true) {}
78+
PrintCanonicalTypes(false),
79+
SkipCanonicalizationOfTemplateTypeParms(false),
80+
PrintInjectedClassNameWithArguments(true) {}
7981

8082
/// Adjust this printing policy for cases where it's known that we're
8183
/// printing C++ code (for instance, if AST dumping reaches a C++-only
@@ -311,6 +313,20 @@ struct PrintingPolicy {
311313
/// Whether to print types as written or canonically.
312314
unsigned PrintCanonicalTypes : 1;
313315

316+
/// Whether to skip the canonicalization (when PrintCanonicalTypes is set) for
317+
/// TemplateTypeParmTypes. This has no effect if PrintCanonicalTypes isn't
318+
/// set. This is useful for non-type-template-parameters, since the canonical
319+
/// version of:
320+
/// \code
321+
/// TemplateTypeParmType '_Tp'
322+
/// TemplateTypeParm '_Tp'
323+
/// \endcode
324+
/// is:
325+
/// \code
326+
/// TemplateTypeParmType 'type-parameter-0-0'
327+
/// \endcode
328+
unsigned SkipCanonicalizationOfTemplateTypeParms : 1;
329+
314330
/// Whether to print an InjectedClassNameType with template arguments or as
315331
/// written. When a template argument is unnamed, printing it results in
316332
/// invalid C++ code.

clang/include/clang/Sema/Sema.h

+36-7
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,8 @@ class SYCLIntegrationHeader {
335335

336336
/// Signals that subsequent parameter descriptor additions will go to
337337
/// the kernel with given name. Starts new kernel invocation descriptor.
338-
void startKernel(StringRef KernelName, QualType KernelNameType,
339-
StringRef KernelStableName, SourceLocation Loc, bool IsESIMD,
340-
bool IsUnnamedKernel);
338+
void startKernel(const FunctionDecl *SyclKernel, QualType KernelNameType,
339+
SourceLocation Loc, bool IsESIMD, bool IsUnnamedKernel);
341340

342341
/// Adds a kernel parameter descriptor to current kernel invocation
343342
/// descriptor.
@@ -350,6 +349,17 @@ class SYCLIntegrationHeader {
350349
/// Registers a specialization constant to emit info for it into the header.
351350
void addSpecConstant(StringRef IDName, QualType IDType);
352351

352+
/// Update the names of a kernel description based on its SyclKernel.
353+
void updateKernelNames(const FunctionDecl *SyclKernel, StringRef Name,
354+
StringRef StableName) {
355+
auto Itr = llvm::find_if(KernelDescs, [SyclKernel](const KernelDesc &KD) {
356+
return KD.SyclKernel == SyclKernel;
357+
});
358+
359+
assert(Itr != KernelDescs.end() && "Unknown kernel description");
360+
Itr->updateKernelNames(Name, StableName);
361+
}
362+
353363
/// Note which free functions (this_id, this_item, etc) are called within the
354364
/// kernel
355365
void setCallsThisId(bool B);
@@ -385,6 +395,9 @@ class SYCLIntegrationHeader {
385395

386396
// Kernel invocation descriptor
387397
struct KernelDesc {
398+
/// sycl_kernel function associated with this kernel.
399+
const FunctionDecl *SyclKernel;
400+
388401
/// Kernel name.
389402
std::string Name;
390403

@@ -410,11 +423,15 @@ class SYCLIntegrationHeader {
410423
// hasn't provided an explicit name for.
411424
bool IsUnnamedKernel;
412425

413-
KernelDesc(StringRef Name, QualType NameType, StringRef StableName,
426+
KernelDesc(const FunctionDecl *SyclKernel, QualType NameType,
414427
SourceLocation KernelLoc, bool IsESIMD, bool IsUnnamedKernel)
415-
: Name(Name), NameType(NameType), StableName(StableName),
416-
KernelLocation(KernelLoc), IsESIMDKernel(IsESIMD),
417-
IsUnnamedKernel(IsUnnamedKernel) {}
428+
: SyclKernel(SyclKernel), NameType(NameType), KernelLocation(KernelLoc),
429+
IsESIMDKernel(IsESIMD), IsUnnamedKernel(IsUnnamedKernel) {}
430+
431+
void updateKernelNames(StringRef Name, StringRef StableName) {
432+
this->Name = Name.str();
433+
this->StableName = StableName.str();
434+
}
418435
};
419436

420437
/// Returns the latest invocation descriptor started by
@@ -13314,12 +13331,23 @@ class Sema final {
1331413331
std::unique_ptr<SYCLIntegrationHeader> SyclIntHeader;
1331513332
std::unique_ptr<SYCLIntegrationFooter> SyclIntFooter;
1331613333

13334+
// We need to store the list of the sycl_kernel functions and their associated
13335+
// generated OpenCL Kernels so we can go back and re-name these after the
13336+
// fact.
13337+
llvm::SmallVector<std::pair<const FunctionDecl *, FunctionDecl *>>
13338+
SyclKernelsToOpenCLKernels;
13339+
1331713340
// Used to suppress diagnostics during kernel construction, since these were
1331813341
// already emitted earlier. Diagnosing during Kernel emissions also skips the
1331913342
// useful notes that shows where the kernel was called.
1332013343
bool DiagnosingSYCLKernel = false;
1332113344

1332213345
public:
13346+
void addSyclOpenCLKernel(const FunctionDecl *SyclKernel,
13347+
FunctionDecl *OpenCLKernel) {
13348+
SyclKernelsToOpenCLKernels.emplace_back(SyclKernel, OpenCLKernel);
13349+
}
13350+
1332313351
void addSyclDeviceDecl(Decl *d) { SyclDeviceDecls.insert(d); }
1332413352
llvm::SetVector<Decl *> &syclDeviceDecls() { return SyclDeviceDecls; }
1332513353

@@ -13361,6 +13389,7 @@ class Sema final {
1336113389
void checkSYCLDeviceVarDecl(VarDecl *Var);
1336213390
void copySYCLKernelAttrs(const CXXRecordDecl *KernelObj);
1336313391
void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc, MangleContext &MC);
13392+
void SetSYCLKernelNames();
1336413393
void MarkDevices();
1336513394

1336613395
/// Get the number of fields or captures within the parsed type.

clang/lib/AST/TypePrinter.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
167167

168168
static SplitQualType splitAccordingToPolicy(QualType QT,
169169
const PrintingPolicy &Policy) {
170-
if (Policy.PrintCanonicalTypes)
170+
if ((!Policy.SkipCanonicalizationOfTemplateTypeParms ||
171+
!QT->isTemplateTypeParmType()) &&
172+
Policy.PrintCanonicalTypes)
171173
QT = QT.getCanonicalType();
172174
return QT.split();
173175
}

clang/lib/Driver/Driver.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -5351,6 +5351,14 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
53515351
llvm::sys::path::stem(SrcFileName).str() + "-footer", "h");
53525352
StringRef TmpFileFooter =
53535353
C.addTempFile(C.getArgs().MakeArgString(TmpFileNameFooter));
5354+
// Use of -fsycl-footer-path puts the integration footer into that
5355+
// specified location.
5356+
if (Arg *A = C.getArgs().getLastArg(options::OPT_fsycl_footer_path_EQ)) {
5357+
SmallString<128> OutName(A->getValue());
5358+
llvm::sys::path::append(OutName,
5359+
llvm::sys::path::filename(TmpFileNameFooter));
5360+
TmpFileFooter = C.addTempFile(C.getArgs().MakeArgString(OutName));
5361+
}
53545362
addIntegrationFiles(TmpFileHeader, TmpFileFooter, SrcFileName);
53555363
}
53565364
}

clang/lib/Driver/ToolChains/Clang.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -4654,13 +4654,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
46544654
CmdArgs.push_back("-fms-extensions");
46554655
CmdArgs.push_back("-fms-compatibility");
46564656
CmdArgs.push_back("-fdelayed-template-parsing");
4657-
VersionTuple MSVT = TC.computeMSVCVersion(&D, Args);
4657+
VersionTuple MSVT = C.getDefaultToolChain().computeMSVCVersion(&D, Args);
46584658
if (!MSVT.empty())
46594659
CmdArgs.push_back(Args.MakeArgString("-fms-compatibility-version=" +
46604660
MSVT.getAsString()));
46614661
else {
4662-
const char *LowestMSVCSupported =
4663-
"19.10.25017"; // VS2017 v15.0 (initial release)
4662+
const char *LowestMSVCSupported = "19.16.27023"; // VS2017 v15.9
46644663
CmdArgs.push_back(Args.MakeArgString(
46654664
Twine("-fms-compatibility-version=") + LowestMSVCSupported));
46664665
}

clang/lib/Sema/Sema.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,9 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
10921092
}
10931093

10941094
if (getLangOpts().SYCLIsDevice) {
1095+
// Set the names of the kernels, now that the names have settled down. This
1096+
// needs to happen before we generate the integration headers.
1097+
SetSYCLKernelNames();
10951098
// Emit SYCL integration header for current translation unit if needed
10961099
if (SyclIntHeader != nullptr)
10971100
SyclIntHeader->emit(getLangOpts().SYCLIntHeader);

0 commit comments

Comments
 (0)