Skip to content

Commit 4f80a26

Browse files
authored
[Comgr] Create new SAVE_TEMPS env var for Clang Driver temps (llvm#612)
Forwarding '--save-temps=obj' to the Clang Driver and generating the associated temps slightly changes the behavior of the compilation. For example, the compilation may be broken up into several steps to generate the intermediate files. In many cases, a user may only want the Comgr temps without modifying the compilation behavior. To enable this, we introduce a new Comgr environment variable: AMD_COMGR_SAVE_LLVM_TEMPS With this change, '--save-temps=obj' is only forwarded if the above is set to non-zero. And AMD_COMGR_SAVE_TEMPS now only saves Comgr temps.
1 parent 0c4a848 commit 4f80a26

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

amd/comgr/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ include:
122122
the current working directory, but are instead left in a platform-specific
123123
temporary directory (typically `/tmp` on Linux and `C:\Temp` or the path
124124
found in the `TEMP` environment variable on Windows).
125+
* `AMD_COMGR_SAVE_LLVM_TEMPS`: If this is set, Comgr forwards `--save-temps=obj`
126+
to Clang Driver invocations.
125127
* `AMD_COMGR_REDIRECT_LOGS`: If this is not set, or is set to "0", logs are
126128
returned to the caller as normal. If this is set to "stdout"/"-" or "stderr",
127129
logs are instead redirected to the standard output or error stream,

amd/comgr/include/amd_comgr.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ extern "C" {
148148
* These files do not appear in the current working directory, but are
149149
* instead left in a platform-specific temporary directory (/tmp on Linux and
150150
* C:\Temp or the path found in the TEMP environment variable on Windows).
151+
* - @p AMD_COMGR_SAVE_LLVM_TEMPS: If this is set, and is not "0", Comgr
152+
* forwards "--save-temps=obj" to Clang Driver invocations
151153
* - @p AMD_COMGR_REDIRECT_LOGS: If this is not set, or is set to "0", logs are
152154
* returned to the caller as normal. If this is set to "stdout"/"-" or
153155
* "stderr", logs are instead redirected to the standard output or error

amd/comgr/src/comgr-compiler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,8 @@ amd_comgr_status_t AMDGPUCompiler::processFile(const char *InputFilePath,
878878
Argv.push_back("-nogpulib");
879879
}
880880

881-
if (getLanguage() == AMD_COMGR_LANGUAGE_HIP && env::shouldSaveTemps()) {
881+
// TODO: Enable this for OpenCL as well (SWDEV-377546)
882+
if (getLanguage() == AMD_COMGR_LANGUAGE_HIP && env::shouldSaveLLVMTemps()) {
882883
Argv.push_back("-save-temps=obj");
883884
}
884885

amd/comgr/src/comgr-env.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ bool shouldSaveTemps() {
5151
return SaveTemps && StringRef(SaveTemps) != "0";
5252
}
5353

54+
bool shouldSaveLLVMTemps() {
55+
static char *SaveTemps = getenv("AMD_COMGR_SAVE_LLVM_TEMPS");
56+
return SaveTemps && StringRef(SaveTemps) != "0";
57+
}
58+
5459
std::optional<StringRef> getRedirectLogs() {
5560
static char *RedirectLogs = getenv("AMD_COMGR_REDIRECT_LOGS");
5661
if (!RedirectLogs || StringRef(RedirectLogs) == "0") {

amd/comgr/src/comgr-env.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace env {
4343

4444
/// Return whether the environment requests temps be saved.
4545
bool shouldSaveTemps();
46+
bool shouldSaveLLVMTemps();
4647

4748
/// If the environment requests logs be redirected, return the string identifier
4849
/// of where to redirect. Otherwise return @p None.

0 commit comments

Comments
 (0)