aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/Driver.cpp
diff options
context:
space:
mode:
authorYaxun (Sam) Liu <yaxun.liu@amd.com>2023-03-07 00:25:01 -0500
committerYaxun (Sam) Liu <yaxun.liu@amd.com>2023-03-09 21:41:58 -0500
commit1f8a3ce325be51a1004657b08a607825447fee1b (patch)
tree8262ad17853b8a33d2e8f7ea5feb2274d6494e84 /clang/lib/Driver/Driver.cpp
parentd32f71a91a432db2d9ea32694a8308534b6697ec (diff)
downloadllvm-1f8a3ce325be51a1004657b08a607825447fee1b.zip
llvm-1f8a3ce325be51a1004657b08a607825447fee1b.tar.gz
llvm-1f8a3ce325be51a1004657b08a607825447fee1b.tar.bz2
[HIP] Fix temporary files
Currently HIP toolchain uses Driver::GetTemporaryDirectory to create a temporary directory for some temporary files during compilation. The temporary directories are not automatically deleted after compilation. This slows down compilation on Windows. Switch to use GetTemporaryPath which only creates temporay files which will be deleted automatically. Keep the original input file name convention for Darwin host toolchain since it is needed for deterministic binary (https://reviews.llvm.org/D111269) Fixes: SWDEV-386058 Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D145509
Diffstat (limited to 'clang/lib/Driver/Driver.cpp')
-rw-r--r--clang/lib/Driver/Driver.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 05674412..0f5f35c 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5545,7 +5545,8 @@ static bool HasPreprocessOutput(const Action &JA) {
const char *Driver::CreateTempFile(Compilation &C, StringRef Prefix,
StringRef Suffix, bool MultipleArchs,
- StringRef BoundArch) const {
+ StringRef BoundArch,
+ bool NeedUniqueDirectory) const {
SmallString<128> TmpName;
Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
std::optional<std::string> CrashDirectory =
@@ -5565,9 +5566,15 @@ const char *Driver::CreateTempFile(Compilation &C, StringRef Prefix,
}
} else {
if (MultipleArchs && !BoundArch.empty()) {
- TmpName = GetTemporaryDirectory(Prefix);
- llvm::sys::path::append(TmpName,
- Twine(Prefix) + "-" + BoundArch + "." + Suffix);
+ if (NeedUniqueDirectory) {
+ TmpName = GetTemporaryDirectory(Prefix);
+ llvm::sys::path::append(TmpName,
+ Twine(Prefix) + "-" + BoundArch + "." + Suffix);
+ } else {
+ TmpName =
+ GetTemporaryPath((Twine(Prefix) + "-" + BoundArch).str(), Suffix);
+ }
+
} else {
TmpName = GetTemporaryPath(Prefix, Suffix);
}
@@ -5683,7 +5690,16 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
StringRef Name = llvm::sys::path::filename(BaseInput);
std::pair<StringRef, StringRef> Split = Name.split('.');
const char *Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode());
- return CreateTempFile(C, Split.first, Suffix, MultipleArchs, BoundArch);
+ // The non-offloading toolchain on Darwin requires deterministic input
+ // file name for binaries to be deterministic, therefore it needs unique
+ // directory.
+ llvm::Triple Triple(C.getDriver().getTargetTriple());
+ bool NeedUniqueDirectory =
+ (JA.getOffloadingDeviceKind() == Action::OFK_None ||
+ JA.getOffloadingDeviceKind() == Action::OFK_Host) &&
+ Triple.isOSDarwin();
+ return CreateTempFile(C, Split.first, Suffix, MultipleArchs, BoundArch,
+ NeedUniqueDirectory);
}
SmallString<128> BasePath(BaseInput);