Skip to content

Commit a774038

Browse files
committed
Merge branch 'sycl' into peter/3channel
2 parents 718e917 + a8c60db commit a774038

File tree

383 files changed

+4162
-8609
lines changed

Some content is hidden

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

383 files changed

+4162
-8609
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,6 @@ CODEGENOPT(SkipRaxSetup, 1, 0)
459459
ENUM_CODEGENOPT(ZeroCallUsedRegs, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
460460
5, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind::Skip)
461461

462-
/// Whether to expect -main-file-name to be an absolute path to use it for
463-
/// checksum calculations or not.
464-
CODEGENOPT(SYCLUseMainFileName, 1, 0)
465-
466-
467462
/// Modify C++ ABI to returning `this` pointer from constructors and
468463
/// non-deleting destructors. (No effect on Microsoft ABI.)
469464
CODEGENOPT(CtorDtorReturnThis, 1, 0)

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
258258
/// file, for example with -save-temps.
259259
std::string MainFileName;
260260

261-
/// The user provided name for the "main file", with its full path.
262-
std::string FullMainFileName;
263-
264261
/// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
265262
/// attribute in the skeleton CU.
266263
std::string SplitDwarfFile;

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ def warn_drv_mismatch_fpga_archive : Warning<
219219
def warn_drv_sycl_native_cpu_and_targets: Warning<
220220
"-fsycl-targets=native_cpu overrides SYCL targets option">,
221221
InGroup<SyclNativeCPUTargets>;
222-
def err_drv_unsupported_opt_sycl : Error<
223-
"option '%0' not supported with SYCL compilation">;
224222
def err_drv_argument_only_allowed_with : Error<
225223
"invalid argument '%0' only allowed with '%1'">;
226224
def err_drv_opt_unsupported_input_type : Error<

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ LANGOPT(SYCLAllowFuncPtr , 1, 0, "Allow function pointers in SYCL device code")
302302
LANGOPT(SYCLStdLayoutKernelParams, 1, 0, "Enable standard layout requirement for SYCL kernel parameters")
303303
LANGOPT(SYCLUnnamedLambda , 1, 0, "Allow unnamed lambda SYCL kernels")
304304
LANGOPT(SYCLForceInlineKernelLambda , 1, 0, "Force inline SYCL kernel lambdas in entry point")
305+
LANGOPT(SYCLAllowAllFeaturesInConstexpr, 1, 0, "Allow all C++ features in SYCL device code in manifestly constant-evaluated expressions")
305306
LANGOPT(SYCLESIMDForceStatelessMem, 1, 0, "Make accessors use USM memory in ESIMD kernels")
306307
LANGOPT(SYCLESIMDBuildHostCode, 1, 1, "Build the host implementation of ESIMD functions")
307308
ENUM_LANGOPT(SYCLVersion , SYCLMajorVersion, 2, SYCL_None, "Version of the SYCL standard used")

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6779,7 +6779,7 @@ def fintelfpga : Flag<["-"], "fintelfpga">,
67796779
MarshallingInfoFlag<LangOpts<"IntelFPGA">>,
67806780
HelpText<"Perform ahead-of-time compilation for FPGA">;
67816781
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
6782-
HelpText<"Compile SYCL kernels for device">;
6782+
Alias<offload_device_only>, HelpText<"Compile SYCL kernels for device">;
67836783
def fsycl_embed_ir : Flag<["-"], "fsycl-embed-ir">,
67846784
HelpText<"Embed LLVM IR for runtime kernel fusion">;
67856785
defm sycl_esimd_force_stateless_mem : BoolFOption<"sycl-esimd-force-stateless-mem",
@@ -8173,10 +8173,6 @@ def main_file_name : Separate<["-"], "main-file-name">,
81738173
HelpText<"Main file name to use for debug info and source if missing">,
81748174
Visibility<[CC1Option, CC1AsOption]>,
81758175
MarshallingInfoString<CodeGenOpts<"MainFileName">>;
8176-
def full_main_file_name : Separate<["-"], "full-main-file-name">,
8177-
HelpText<"File name with full path to use for debug info during host and device compile">,
8178-
Visibility<[CC1Option, CC1AsOption]>,
8179-
MarshallingInfoString<CodeGenOpts<"FullMainFileName">>;
81808176
def split_dwarf_output : Separate<["-"], "split-dwarf-output">,
81818177
HelpText<"File name to use for split dwarf debug info output">,
81828178
Visibility<[CC1Option, CC1AsOption]>,
@@ -8564,14 +8560,15 @@ def fenable_sycl_dae : Flag<["-"], "fenable-sycl-dae">,
85648560
def fsycl_enable_int_header_diags: Flag<["-"], "fsycl-enable-int-header-diags">,
85658561
HelpText<"Enable diagnostics that require the SYCL integration header.">,
85668562
MarshallingInfoFlag<LangOpts<"SYCLEnableIntHeaderDiags">>;
8567-
def fsycl_use_main_file_name : Flag<["-"], "fsycl-use-main-file-name">,
8568-
HelpText<"Tells compiler that -main-file-name contains an absolute path and "
8569-
"file specified there should be used for checksum calculation.">,
8570-
MarshallingInfoFlag<CodeGenOpts<"SYCLUseMainFileName">>;
85718563
def fsycl_is_native_cpu : Flag<["-"], "fsycl-is-native-cpu">,
85728564
HelpText<"Perform device compilation for Native CPU.">,
85738565
Visibility<[CC1Option]>,
85748566
MarshallingInfoFlag<LangOpts<"SYCLIsNativeCPU">>;
8567+
defm sycl_allow_all_features_in_constexpr
8568+
: BoolFOption<
8569+
"sycl-allow-all-features-in-constexpr", LangOpts<"SYCLAllowAllFeaturesInConstexpr">,
8570+
DefaultFalse,
8571+
PosFlag<SetTrue, [], [CC1Option], "Allow all C++ features in SYCL device code in manifestly constant-evaluated expressions">, NegFlag<SetFalse>>;
85758572

85768573
} // let Visibility = [CC1Option]
85778574

clang/include/clang/Sema/Sema.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,11 @@ class Sema final : public SemaBase {
11331133
/// must be codegen'ed. Because handling these correctly adds overhead to
11341134
/// compilation, this is currently only enabled for CUDA compilations.
11351135
SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags;
1136+
/// Used to track deferred diagnostic that happened in an initializer of a
1137+
/// constexpr variable. When it is known that a variable doesn't have
1138+
/// constexpr initializer content of this container is pushed to
1139+
/// DeviceDeferredDiags.
1140+
SemaDiagnosticBuilder::DeferredDiagnosticsType MaybeDeviceDeferredDiags;
11361141

11371142
/// CurContext - This is the current declaration context of parsing.
11381143
DeclContext *CurContext;
@@ -2168,6 +2173,8 @@ class Sema final : public SemaBase {
21682173
/// ExpressionEvaluationContextRecord object.
21692174
bool isConstantEvaluatedOverride = false;
21702175

2176+
bool InConstexprVarInit = false;
2177+
21712178
bool isConstantEvaluatedContext() const {
21722179
return currentEvaluationContext().isConstantEvaluated() ||
21732180
isConstantEvaluatedOverride;

clang/lib/Analysis/CallGraph.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,27 @@ class CGBuilder : public StmtVisitor<CGBuilder> {
150150
StmtVisitor::VisitIfStmt(If);
151151
}
152152

153+
void VisitConstantExpr(ConstantExpr *CE) {
154+
if (G->shouldSkipConstantExpressions())
155+
return;
156+
StmtVisitor::VisitConstantExpr(CE);
157+
}
158+
159+
void VisitDeclStmt(DeclStmt *DS) {
160+
if (G->shouldSkipConstantExpressions()) {
161+
auto IsConstexprVarDecl = [this](Decl *D) {
162+
if (const auto *VD = dyn_cast<VarDecl>(D))
163+
return VD->isUsableInConstantExpressions(G->getASTContext());
164+
return false;
165+
};
166+
if (llvm::any_of(DS->decls(), IsConstexprVarDecl)) {
167+
return;
168+
}
169+
}
170+
171+
StmtVisitor::VisitDeclStmt(DS);
172+
}
173+
153174
void VisitChildren(Stmt *S) {
154175
for (Stmt *SubStmt : S->children())
155176
if (SubStmt)

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -397,40 +397,18 @@ std::optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM,
397397
return Source;
398398
}
399399

400-
// Compute valid FID for FileName.
401-
FileID ComputeValidFileID(SourceManager &SM, StringRef FileName) {
402-
FileID MainFileID = SM.getMainFileID();
403-
// Find the filename FileName and load it.
404-
llvm::Expected<FileEntryRef> ExpectedFileRef =
405-
SM.getFileManager().getFileRef(FileName);
406-
if (ExpectedFileRef) {
407-
MainFileID = SM.getOrCreateFileID(ExpectedFileRef.get(),
408-
SrcMgr::CharacteristicKind::C_User);
409-
}
410-
return MainFileID;
411-
}
412-
413400
llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
414401
SourceManager &SM = CGM.getContext().getSourceManager();
415402
StringRef FileName;
416403
FileID FID;
417404
std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
418405

419406
if (Loc.isInvalid()) {
420-
if (CGM.getCodeGenOpts().SYCLUseMainFileName &&
421-
CGM.getLangOpts().MacroPrefixMap.size() > 0) {
422-
// When fmacro-prefix-map is used, the original source file
423-
// file name is indicated by FullMainFileName instead of the CU.
424-
auto &CGO = CGM.getCodeGenOpts();
425-
FileName = CGO.FullMainFileName;
426-
FID = ComputeValidFileID(SM, CGO.FullMainFileName);
427-
} else {
428-
// The DIFile used by the CU is distinct from the main source file. Call
429-
// createFile() below for canonicalization if the source file was specified
430-
// with an absolute path.
431-
FileName = TheCU->getFile()->getFilename();
432-
CSInfo = TheCU->getFile()->getChecksum();
433-
}
407+
// The DIFile used by the CU is distinct from the main source file. Call
408+
// createFile() below for canonicalization if the source file was specified
409+
// with an absolute path.
410+
FileName = TheCU->getFile()->getFilename();
411+
CSInfo = TheCU->getFile()->getChecksum();
434412
} else {
435413
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
436414
FileName = PLoc.getFilename();
@@ -449,13 +427,6 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
449427
return cast<llvm::DIFile>(V);
450428
}
451429

452-
if (SM.getFileEntryForID(SM.getMainFileID()) &&
453-
CGM.getCodeGenOpts().SYCLUseMainFileName && FID.isInvalid())
454-
// When an integration footer is involved, the main file is a temporary
455-
// file generated by the compiler. FileName is pointing to original user
456-
// source file. We use it here to properly calculate its checksum.
457-
FID = ComputeValidFileID(SM, FileName);
458-
459430
// Put Checksum at a scope where it will persist past the createFile call.
460431
SmallString<64> Checksum;
461432
if (!CSInfo) {
@@ -565,25 +536,18 @@ void CGDebugInfo::CreateCompileUnit() {
565536
auto &CGO = CGM.getCodeGenOpts();
566537
const LangOptions &LO = CGM.getLangOpts();
567538
std::string MainFileName = CGO.MainFileName;
568-
std::string FullMainFileName = CGO.FullMainFileName;
569539
if (MainFileName.empty())
570540
MainFileName = "<stdin>";
571541

572542
// The main file name provided via the "-main-file-name" option contains just
573543
// the file name itself with no path information. This file name may have had
574544
// a relative path, so we look into the actual file entry for the main
575545
// file to determine the real absolute path for the file.
576-
// An exception here is workflow when integration footer is involved: in that
577-
// case driver passes an absolute path to the original user-provided source
578-
// file, whilst main file corresponds to a temporary file generated by the
579-
// compiler.
580546
std::string MainFileDir;
581547
if (OptionalFileEntryRef MainFile =
582548
SM.getFileEntryRefForID(SM.getMainFileID())) {
583549
MainFileDir = std::string(MainFile->getDir().getName());
584-
FileID MainFileID = SM.getMainFileID();
585-
if (!llvm::sys::path::is_absolute(MainFileName) &&
586-
!CGM.getCodeGenOpts().SYCLUseMainFileName) {
550+
if (!llvm::sys::path::is_absolute(MainFileName)) {
587551
llvm::SmallString<1024> MainFileDirSS(MainFileDir);
588552
llvm::sys::path::Style Style =
589553
LO.UseTargetPathSeparator
@@ -594,14 +558,6 @@ void CGDebugInfo::CreateCompileUnit() {
594558
llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
595559
MainFileName = std::string(
596560
llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
597-
} else if (CGM.getCodeGenOpts().SYCLUseMainFileName) {
598-
// When an integration footer is involved, the main file is a temporary
599-
// file generated by the compiler. FullMainFileName is pointing to
600-
// original user source file. We use it here to properly calculate its
601-
// checksum.
602-
MainFileID = ComputeValidFileID(SM, FullMainFileName);
603-
// Make sure the filename points to the original user source filename.
604-
MainFileName = FullMainFileName;
605561
}
606562
// If the main file name provided is identical to the input file name, and
607563
// if the input file is a preprocessed source, use the module name for
@@ -614,7 +570,7 @@ void CGDebugInfo::CreateCompileUnit() {
614570
.isPreprocessed()) {
615571
MainFileName = CGM.getModule().getName().str();
616572
} else {
617-
CSKind = computeChecksum(MainFileID, Checksum);
573+
CSKind = computeChecksum(SM.getMainFileID(), Checksum);
618574
}
619575
}
620576

clang/lib/Driver/Driver.cpp

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,7 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
393393
FinalPhase = phases::Compile;
394394

395395
// -S only runs up to the backend.
396-
} else if ((PhaseArg = DAL.getLastArg(options::OPT_S)) ||
397-
(PhaseArg = DAL.getLastArg(options::OPT_fsycl_device_only))) {
396+
} else if ((PhaseArg = DAL.getLastArg(options::OPT_S))) {
398397
FinalPhase = phases::Backend;
399398

400399
// -c compilation only runs up to the assembler.
@@ -855,6 +854,19 @@ static bool addSYCLDefaultTriple(Compilation &C,
855854
return true;
856855
}
857856

857+
// Special function that checks if -fsycl-device-only was passed on the
858+
// command line. -fsycl-device-only is an alias of --offload-device-only.
859+
static bool hasSYCLDeviceOnly(const ArgList &Args) {
860+
if (const Arg *SYCLDeviceOnlyArg =
861+
Args.getLastArg(options::OPT_offload_device_only)) {
862+
while (SYCLDeviceOnlyArg->getAlias())
863+
SYCLDeviceOnlyArg = SYCLDeviceOnlyArg->getAlias();
864+
if (SYCLDeviceOnlyArg->getSpelling().contains("sycl-device-only"))
865+
return true;
866+
}
867+
return false;
868+
}
869+
858870
void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
859871
InputList &Inputs) {
860872

@@ -1074,7 +1086,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
10741086
bool HasValidSYCLRuntime =
10751087
C.getInputArgs().hasFlag(options::OPT_fsycl, options::OPT_fno_sycl,
10761088
false) ||
1077-
C.getInputArgs().hasArg(options::OPT_fsycl_device_only);
1089+
hasSYCLDeviceOnly(C.getInputArgs());
10781090

10791091
Arg *SYCLfpga = C.getInputArgs().getLastArg(options::OPT_fintelfpga);
10801092

@@ -1118,8 +1130,8 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
11181130
if (!HasValidSYCLRuntime)
11191131
return;
11201132
if (Arg *IncompatArg = C.getInputArgs().getLastArg(OptId))
1121-
Diag(clang::diag::err_drv_unsupported_opt_sycl)
1122-
<< IncompatArg->getSpelling();
1133+
Diag(clang::diag::err_drv_argument_not_allowed_with)
1134+
<< IncompatArg->getSpelling() << "-fsycl";
11231135
};
11241136
// -static-libstdc++ is not compatible with -fsycl.
11251137
argSYCLIncompatible(options::OPT_static_libstdcxx);
@@ -1743,13 +1755,12 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
17431755
if (Args.getLastArg(options::OPT_fsycl_dump_device_code_EQ))
17441756
DumpDeviceCode = true;
17451757

1746-
if (const Arg *A = Args.getLastArg(
1747-
options::OPT_offload_host_only, options::OPT_offload_device_only,
1748-
options::OPT_offload_host_device, options::OPT_fsycl_device_only)) {
1758+
if (const Arg *A = Args.getLastArg(options::OPT_offload_host_only,
1759+
options::OPT_offload_device_only,
1760+
options::OPT_offload_host_device)) {
17491761
if (A->getOption().matches(options::OPT_offload_host_only))
17501762
Offload = OffloadHost;
1751-
else if (A->getOption().matches(options::OPT_offload_device_only) ||
1752-
A->getOption().matches(options::OPT_fsycl_device_only))
1763+
else if (A->getOption().matches(options::OPT_offload_device_only))
17531764
Offload = OffloadDevice;
17541765
else
17551766
Offload = OffloadHostDevice;
@@ -3124,7 +3135,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
31243135
Arg *InputTypeArg = nullptr;
31253136
bool IsSYCL =
31263137
Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) ||
3127-
Args.hasArg(options::OPT_fsycl_device_only);
3138+
hasSYCLDeviceOnly(Args);
31283139

31293140
// The last /TC or /TP option sets the input type to C or C++ globally.
31303141
if (Arg *TCTP = Args.getLastArgNoClaim(options::OPT__SLASH_TC,
@@ -5855,10 +5866,9 @@ class OffloadingActionBuilder final {
58555866
++NumOfDeviceLibLinked;
58565867
Arg *InputArg = MakeInputArg(Args, C.getDriver().getOpts(),
58575868
Args.MakeArgString(LibName));
5858-
if (TC->getTriple().isNVPTX() ||
5859-
(TC->getTriple().isSPIR() &&
5860-
TC->getTriple().getSubArch() ==
5861-
llvm::Triple::SPIRSubArch_fpga)) {
5869+
if (TC->getTriple().isSPIR() &&
5870+
TC->getTriple().getSubArch() ==
5871+
llvm::Triple::SPIRSubArch_fpga) {
58625872
auto *SYCLDeviceLibsInputAction =
58635873
C.MakeAction<InputAction>(*InputArg, types::TY_Object);
58645874
auto *SYCLDeviceLibsUnbundleAction =
@@ -6851,6 +6861,10 @@ class OffloadingActionBuilder final {
68516861
/// Offload deps output is then forwarded to active device action builders so
68526862
/// they can add it to the device linker inputs.
68536863
void addDeviceLinkDependenciesFromHost(ActionList &LinkerInputs) {
6864+
if (isSYCLNativeCPU(C.getArgs())) {
6865+
// SYCL Native CPU doesn't need deps from clang-offload-deps.
6866+
return;
6867+
}
68546868
// Link image for reading dependencies from it.
68556869
auto *LA = C.MakeAction<LinkJobAction>(LinkerInputs,
68566870
types::TY_Host_Dependencies_Image);

0 commit comments

Comments
 (0)