-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RISCV] Minor improvements/cleanup to target attribute handling. NFC #73851
Conversation
Use ArrayRef to avoid a vector copy. Replace a push_back loop with a call to std::vector::insert.
@llvm/pr-subscribers-backend-risc-v @llvm/pr-subscribers-clang Author: Craig Topper (topperc) ChangesUse ArrayRef to avoid a vector copy. Full diff: https://github.com/llvm/llvm-project/pull/73851.diff 1 Files Affected:
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());
}
}
|
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The &*
are here to convert from the std::vector pointer wrappers to raw pointers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Use ArrayRef to avoid a vector copy.
Replace a push_back loop with a call to std::vector::insert.