[clang] [RISCV] Minor improvements/cleanup to target attribute handling. NFC (PR #73851)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 29 12:26:08 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
Use ArrayRef to avoid a vector copy.
Replace a push_back loop with a call to std::vector::insert.
---
Full diff: https://github.com/llvm/llvm-project/pull/73851.diff
1 Files Affected:
- (modified) clang/lib/Basic/Targets/RISCV.cpp (+4-6)
``````````diff
diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp
index d1d9cc1c770e361..2e9ce468b5d3e36 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -236,8 +236,7 @@ ArrayRef<Builtin::Info> RISCVTargetInfo::getTargetBuiltins() const {
}
static std::vector<std::string>
-collectNonISAExtFeature(const std::vector<std::string> &FeaturesNeedOverride,
- int XLen) {
+collectNonISAExtFeature(ArrayRef<std::string> FeaturesNeedOverride, int XLen) {
auto ParseResult =
llvm::RISCVISAInfo::parseFeatures(XLen, FeaturesNeedOverride);
@@ -265,11 +264,11 @@ resolveTargetAttrOverride(const std::vector<std::string> &FeaturesVec,
if (I == FeaturesVec.end())
return FeaturesVec;
- const std::vector<std::string> FeaturesNeedOverride(FeaturesVec.begin(), I);
+ ArrayRef<std::string> FeaturesNeedOverride(&*FeaturesVec.begin(), &*I);
std::vector<std::string> NonISAExtFeature =
collectNonISAExtFeature(FeaturesNeedOverride, XLen);
- auto ResolvedFeature = std::vector<std::string>(++I, FeaturesVec.end());
+ std::vector<std::string> ResolvedFeature(++I, FeaturesVec.end());
ResolvedFeature.insert(ResolvedFeature.end(), NonISAExtFeature.begin(),
NonISAExtFeature.end());
@@ -415,8 +414,7 @@ static void handleFullArchString(StringRef FullArchStr,
Features.push_back("+" + FullArchStr.str());
} else {
std::vector<std::string> FeatStrings = (*RII)->toFeatureVector();
- for (auto FeatString : FeatStrings)
- Features.push_back(FeatString);
+ Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end());
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/73851
More information about the cfe-commits
mailing list