Skip to content
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

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Nov 29, 2023

Use ArrayRef to avoid a vector copy.
Replace a push_back loop with a call to std::vector::insert.

Use ArrayRef to avoid a vector copy.
Replace a push_back loop with a call to std::vector::insert.
@topperc topperc requested review from preames and BeMg November 29, 2023 20:25
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:RISC-V clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 29, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 29, 2023

@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-clang

Author: Craig Topper (topperc)

Changes

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 --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);
Copy link
Collaborator Author

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.

Copy link
Contributor

@asb asb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@topperc topperc merged commit 0123608 into llvm:main Nov 29, 2023
5 of 6 checks passed
@topperc topperc deleted the pr/target-attribute branch November 29, 2023 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:RISC-V clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants