[PATCH] D85077: [clang][Tooling] Optimize addTargetAndMode in case of invalid modes
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 3 04:51:47 PDT 2020
kadircet updated this revision to Diff 282584.
kadircet added a comment.
- Change bitwise assignment to logical operators, as bitwise operators do not have short-circuting.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85077/new/
https://reviews.llvm.org/D85077
Files:
clang/lib/Tooling/Tooling.cpp
Index: clang/lib/Tooling/Tooling.cpp
===================================================================
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -258,22 +258,23 @@
// --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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85077.282584.patch
Type: text/x-patch
Size: 1644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200803/f9ae5331/attachment-0001.bin>
More information about the cfe-commits
mailing list