Skip to content

Commit 9ff0371

Browse files
authored
[Comgr][Cache] Cache source-code->bitcode actions (llvm#1664)
2 parents dc9ce46 + 073670b commit 9ff0371

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

amd/comgr/src/comgr-clang-command.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ SmallVector<StringRef, 1> getInputFiles(driver::Command &Command) {
9191
return Paths;
9292
}
9393

94-
bool isSourceCodeInput(const driver::InputInfo &II) {
95-
return driver::types::isSrcFile(II.getType());
96-
}
9794
} // namespace
9895
ClangCommand::ClangCommand(driver::Command &Command,
9996
DiagnosticOptions &DiagOpts, vfs::FileSystem &VFS,
@@ -150,13 +147,7 @@ bool ClangCommand::canCache() const {
150147
bool HasOneOutput = Command.getOutputFilenames().size() == 1;
151148
bool IsPreprocessorCommand = getClass() == driver::Action::PreprocessJobClass;
152149

153-
// This reduces the applicability of the cache, but it helps us deliver
154-
// something now and deal with the PCH issues later. The cache would still
155-
// help for spirv compilation (e.g. bitcode->asm) and for intermediate
156-
// compilation steps
157-
bool HasSourceCodeInput = any_of(Command.getInputInfos(), isSourceCodeInput);
158-
159-
return HasOneOutput && !IsPreprocessorCommand && !HasSourceCodeInput &&
150+
return HasOneOutput && !IsPreprocessorCommand &&
160151
!hasDebugOrProfileInfo(Command.getArguments());
161152
}
162153

amd/comgr/src/comgr-compiler.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,8 @@ amd_comgr_status_t AMDGPUCompiler::addIncludeFlags() {
977977
if (none_of(InSet->DataObjects, needsPreprocessing))
978978
return AMD_COMGR_STATUS_SUCCESS;
979979

980-
switch (ActionInfo->Language) {
980+
amd_comgr_language_t Language = ActionInfo->Language;
981+
switch (Language) {
981982
case AMD_COMGR_LANGUAGE_OPENCL_1_2:
982983
case AMD_COMGR_LANGUAGE_OPENCL_2_0: {
983984
SmallString<128> OpenCLCBasePath = IncludeDir;
@@ -1019,6 +1020,26 @@ amd_comgr_status_t AMDGPUCompiler::addIncludeFlags() {
10191020
Args.push_back("-fno-validate-pch");
10201021
}
10211022

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+
10221043
return AMD_COMGR_STATUS_SUCCESS;
10231044
}
10241045

amd/comgr/test-lit/cache-tests/compile-minimal-test-cached.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
// RUN: llvm-objdump -d %t_a.bin | FileCheck %S/../compile-minimal-test.cl
2525
// RUN: COUNT_BEFORE=$(ls "%t.cache" | wc -l)
2626

27-
// COM: One element for the tag, one for bc->obj another for obj->exec. No
28-
// COM: elements for src->bc since we currently not support it.
29-
// RUN: [ 3 -eq $COUNT_BEFORE ]
27+
// COM: One element for the tag, one for cli->bc, one for bc->obj another
28+
// COM: for obj->exec. No elements for src->cli since this is not supported.
29+
// RUN: [ 4 -eq $COUNT_BEFORE ]
3030
//
3131
// RUN: AMD_COMGR_CACHE_DIR=%t.cache compile-opencl-minimal \
3232
// RUN: %S/../compile-minimal-test.cl %t_b.bin 1.2

0 commit comments

Comments
 (0)