@@ -311,6 +311,14 @@ bool AssemblerInvocation::createFromArgs(AssemblerInvocation &Opts,
311
311
}
312
312
313
313
namespace {
314
+ bool needsPreprocessing (DataObject *O) {
315
+ if (O->DataKind != AMD_COMGR_DATA_KIND_SOURCE)
316
+ return false ;
317
+ StringRef Ext = path::extension (O->Name );
318
+ bool IsPreprocessedSource = Ext == " .i" ;
319
+ return !IsPreprocessedSource;
320
+ }
321
+
314
322
std::unique_ptr<raw_fd_ostream> getOutputStream (AssemblerInvocation &Opts,
315
323
DiagnosticsEngine &Diags,
316
324
bool Binary) {
@@ -941,7 +949,10 @@ AMDGPUCompiler::processFiles(amd_comgr_data_kind_t OutputKind,
941
949
ScopedDataObjectReleaser SDOR (OutputT);
942
950
943
951
DataObject *Output = DataObject::convert (OutputT);
944
- Output->setName (std::string (Input->Name ) + OutputSuffix);
952
+
953
+ SmallString<128 > OutputName (Input->Name );
954
+ sys::path::replace_extension (OutputName, OutputSuffix);
955
+ Output->setName (OutputName);
945
956
946
957
auto OutputFilePath = getFilePath (Output, OutputDir);
947
958
@@ -963,6 +974,28 @@ AMDGPUCompiler::processFiles(amd_comgr_data_kind_t OutputKind,
963
974
}
964
975
965
976
amd_comgr_status_t AMDGPUCompiler::addIncludeFlags () {
977
+ if (none_of (InSet->DataObjects , needsPreprocessing))
978
+ return AMD_COMGR_STATUS_SUCCESS;
979
+
980
+ switch (ActionInfo->Language ) {
981
+ case AMD_COMGR_LANGUAGE_OPENCL_1_2:
982
+ case AMD_COMGR_LANGUAGE_OPENCL_2_0: {
983
+ SmallString<128 > OpenCLCBasePath = IncludeDir;
984
+ sys::path::append (OpenCLCBasePath, " opencl-c-base.h" );
985
+ if (auto Status =
986
+ outputToFile (getOpenCLCBaseHeaderContents (), OpenCLCBasePath)) {
987
+ return Status;
988
+ }
989
+ Args.push_back (" -include" );
990
+ Args.push_back (Saver.save (OpenCLCBasePath.c_str ()).data ());
991
+ Args.push_back (" -Xclang" );
992
+ Args.push_back (" -fdeclare-opencl-builtins" );
993
+ break ;
994
+ }
995
+ default :
996
+ break ;
997
+ }
998
+
966
999
if (ActionInfo->Path ) {
967
1000
Args.push_back (" -I" );
968
1001
Args.push_back (ActionInfo->Path );
@@ -1023,22 +1056,24 @@ amd_comgr_status_t AMDGPUCompiler::addCompilationFlags() {
1023
1056
1024
1057
Args.push_back (" -x" );
1025
1058
1059
+ bool NeedsPreprocessing = any_of (InSet->DataObjects , needsPreprocessing);
1060
+
1026
1061
switch (ActionInfo->Language ) {
1027
1062
case AMD_COMGR_LANGUAGE_LLVM_IR:
1028
1063
Args.push_back (" ir" );
1029
1064
break ;
1030
1065
case AMD_COMGR_LANGUAGE_OPENCL_1_2:
1031
- Args.push_back (" cl" );
1066
+ Args.push_back (NeedsPreprocessing ? " cl" : " cl-cpp-output " );
1032
1067
Args.push_back (" -std=cl1.2" );
1033
1068
Args.push_back (" -cl-no-stdinc" );
1034
1069
break ;
1035
1070
case AMD_COMGR_LANGUAGE_OPENCL_2_0:
1036
- Args.push_back (" cl" );
1071
+ Args.push_back (NeedsPreprocessing ? " cl" : " cl-cpp-output " );
1037
1072
Args.push_back (" -std=cl2.0" );
1038
1073
Args.push_back (" -cl-no-stdinc" );
1039
1074
break ;
1040
1075
case AMD_COMGR_LANGUAGE_HIP:
1041
- Args.push_back (" hip" );
1076
+ Args.push_back (NeedsPreprocessing ? " hip" : " hip-cpp-output " );
1042
1077
Args.push_back (" --offload-device-only" );
1043
1078
// Pass a cuid that depends on the input files
1044
1079
// Otherwise, a random (which depends on the /tmp/comgr-xxxxx path) cuid is
0 commit comments