@@ -517,8 +517,9 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
517
517
518
518
static bool shouldIncludePTX (const ArgList &Args, StringRef InputArch) {
519
519
// The new driver does not include PTX by default to avoid overhead.
520
- bool includePTX = !Args.hasFlag (options::OPT_offload_new_driver,
521
- options::OPT_no_offload_new_driver, false ); // INTEL
520
+ bool includePTX =
521
+ !Args.hasFlag (options::OPT_offload_new_driver,
522
+ options::OPT_no_offload_new_driver, false ); // INTEL
522
523
for (Arg *A : Args.filtered (options::OPT_cuda_include_ptx_EQ,
523
524
options::OPT_no_cuda_include_ptx_EQ)) {
524
525
A->claim ();
@@ -614,8 +615,7 @@ void NVPTX::OpenMPLinker::ConstructJob(Compilation &C, const JobAction &JA,
614
615
if (Args.hasArg (options::OPT_v))
615
616
CmdArgs.push_back (" -v" );
616
617
617
- StringRef GPUArch =
618
- Args.getLastArgValue (options::OPT_march_EQ);
618
+ StringRef GPUArch = Args.getLastArgValue (options::OPT_march_EQ);
619
619
assert (!GPUArch.empty () && " At least one GPU Arch required for ptxas." );
620
620
621
621
CmdArgs.push_back (" -arch" );
@@ -948,7 +948,8 @@ void CudaToolChain::addClangTargetOptions(
948
948
assert ((DeviceOffloadingKind == Action::OFK_OpenMP ||
949
949
DeviceOffloadingKind == Action::OFK_SYCL ||
950
950
DeviceOffloadingKind == Action::OFK_Cuda) &&
951
- " Only OpenMP, SYCL or CUDA offloading kinds are supported for NVIDIA GPUs." );
951
+ " Only OpenMP, SYCL or CUDA offloading kinds are supported for NVIDIA "
952
+ " GPUs." );
952
953
953
954
// If we are compiling SYCL kernels for Nvidia GPUs, we do not support Cuda
954
955
// device code compatability, hence we do not set Cuda mode in that instance.
@@ -984,14 +985,37 @@ void CudaToolChain::addClangTargetOptions(
984
985
CC1Args.append ({" -std=c++17" , " -fsycl-is-host" });
985
986
}
986
987
988
+ StringRef OOpt = " 3" ;
989
+ if (Arg *A = DriverArgs.getLastArg (options::OPT_O_Group)) {
990
+ if (A->getOption ().matches (options::OPT_O4) ||
991
+ A->getOption ().matches (options::OPT_Ofast))
992
+ OOpt = " 3" ;
993
+ else if (A->getOption ().matches (options::OPT_O0))
994
+ OOpt = " 0" ;
995
+ else if (A->getOption ().matches (options::OPT_O)) {
996
+ // -Os, -Oz, and -O(anything else) map to -O2, for lack of better options.
997
+ OOpt = llvm::StringSwitch<const char *>(A->getValue ())
998
+ .Case (" 1" , " 1" )
999
+ .Case (" 2" , " 2" )
1000
+ .Case (" 3" , " 3" )
1001
+ .Case (" s" , " 2" )
1002
+ .Case (" z" , " 2" )
1003
+ .Default (" 2" );
1004
+ }
1005
+ }
1006
+ CC1Args.push_back (DriverArgs.MakeArgString (llvm::Twine (" -O" ) + OOpt));
1007
+
987
1008
auto NoLibSpirv = DriverArgs.hasArg (options::OPT_fno_sycl_libspirv) ||
988
1009
getDriver ().offloadDeviceOnly ();
989
1010
if (DeviceOffloadingKind == Action::OFK_SYCL && !NoLibSpirv) {
990
1011
std::string LibSpirvFile;
991
1012
992
1013
if (DriverArgs.hasArg (clang::driver::options::OPT_fsycl_libspirv_path_EQ)) {
993
1014
auto ProvidedPath =
994
- DriverArgs.getLastArgValue (clang::driver::options::OPT_fsycl_libspirv_path_EQ).str ();
1015
+ DriverArgs
1016
+ .getLastArgValue (
1017
+ clang::driver::options::OPT_fsycl_libspirv_path_EQ)
1018
+ .str ();
995
1019
if (llvm::sys::fs::exists (ProvidedPath))
996
1020
LibSpirvFile = ProvidedPath;
997
1021
} else {
0 commit comments