@@ -977,7 +977,8 @@ amd_comgr_status_t AMDGPUCompiler::addIncludeFlags() {
977
977
if (none_of (InSet->DataObjects , needsPreprocessing))
978
978
return AMD_COMGR_STATUS_SUCCESS;
979
979
980
- switch (ActionInfo->Language ) {
980
+ amd_comgr_language_t Language = ActionInfo->Language ;
981
+ switch (Language) {
981
982
case AMD_COMGR_LANGUAGE_OPENCL_1_2:
982
983
case AMD_COMGR_LANGUAGE_OPENCL_2_0: {
983
984
SmallString<128 > OpenCLCBasePath = IncludeDir;
@@ -1019,6 +1020,26 @@ amd_comgr_status_t AMDGPUCompiler::addIncludeFlags() {
1019
1020
Args.push_back (" -fno-validate-pch" );
1020
1021
}
1021
1022
1023
+ bool CacheEnabled = CommandCache::get (LogS) != nullptr ;
1024
+ if (PrecompiledHeaders.empty () && CacheEnabled) {
1025
+ // The -no-integrated-cpp is used to split the preprocessing stage from the
1026
+ // rest of the compilation jobs. The cache doesn't handle source-code input,
1027
+ // but can handle preprocessed input (to avoid dealing with includes).
1028
+ Args.push_back (" -no-integrated-cpp" );
1029
+ // The -dD option is used to keep the #define directives in the preprocessed
1030
+ // output. When -fdeclare-opencl-builtins is used, the opencl builtin
1031
+ // semantic analysis queries the preprocessor for macro definitions that
1032
+ // signal that an OpenCL feature is enabled. After preprocessing these
1033
+ // #define are gone, so the semantic analysis during the compilation stage
1034
+ // fails. This flag is used to keep them such that they are present during
1035
+ // the compilation stage.
1036
+ // Additionally, we need to keep the definitions for #pragma directives.
1037
+ // The preprocessor doesn't expand macro identifiers in #pragmas, and if we
1038
+ // do not pass -dD the definitions would be missing when clang parses the
1039
+ // code
1040
+ Args.push_back (" -dD" );
1041
+ }
1042
+
1022
1043
return AMD_COMGR_STATUS_SUCCESS;
1023
1044
}
1024
1045
0 commit comments