[clang] 76c3ec8 - [clang][Tooling] Optimize addTargetAndMode in case of invalid modes
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 3 05:01:26 PDT 2020
Author: Kadir Cetinkaya
Date: 2020-08-03T13:58:27+02:00
New Revision: 76c3ec814dec8eef020490b5d3a640d873b5918b
URL: https://github.com/llvm/llvm-project/commit/76c3ec814dec8eef020490b5d3a640d873b5918b
DIFF: https://github.com/llvm/llvm-project/commit/76c3ec814dec8eef020490b5d3a640d873b5918b.diff
LOG: [clang][Tooling] Optimize addTargetAndMode in case of invalid modes
This skips searching for `target` related flags in the existing args if
we don't have a valid target to insert.
Depends on D85076
Differential Revision: https://reviews.llvm.org/D85077
Added:
Modified:
clang/lib/Tooling/Tooling.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 0593f0cc1d19..1ee8ce28c2ef 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -258,22 +258,23 @@ void addTargetAndModeForProgramName(std::vector<std::string> &CommandLine,
// --driver-mode=X
const std::string DriverModeOPT =
Table.getOption(driver::options::OPT_driver_mode).getPrefixedName();
- bool AlreadyHasTarget = false;
- bool AlreadyHasMode = false;
+ auto TargetMode =
+ driver::ToolChain::getTargetAndModeFromProgramName(InvokedAs);
+ // No need to search for target args if we don't have a target/mode to insert.
+ bool ShouldAddTarget = TargetMode.TargetIsValid;
+ bool ShouldAddMode = TargetMode.DriverMode != nullptr;
// Skip CommandLine[0].
for (auto Token = ++CommandLine.begin(); Token != CommandLine.end();
++Token) {
StringRef TokenRef(*Token);
- AlreadyHasTarget |=
- TokenRef.startswith(TargetOPT) || TokenRef.equals(TargetOPTLegacy);
- AlreadyHasMode |= TokenRef.startswith(DriverModeOPT);
+ ShouldAddTarget = ShouldAddTarget && !TokenRef.startswith(TargetOPT) &&
+ !TokenRef.equals(TargetOPTLegacy);
+ ShouldAddMode = ShouldAddMode && !TokenRef.startswith(DriverModeOPT);
}
- auto TargetMode =
- driver::ToolChain::getTargetAndModeFromProgramName(InvokedAs);
- if (!AlreadyHasMode && TargetMode.DriverMode) {
+ if (ShouldAddMode) {
CommandLine.insert(++CommandLine.begin(), TargetMode.DriverMode);
}
- if (!AlreadyHasTarget && TargetMode.TargetIsValid) {
+ if (ShouldAddTarget) {
CommandLine.insert(++CommandLine.begin(),
TargetOPT + TargetMode.TargetPrefix);
}
More information about the cfe-commits
mailing list