[clang] 0123608 - [RISCV] Minor improvements/cleanup to target attribute handling. NFC (#73851)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 29 12:57:53 PST 2023


Author: Craig Topper
Date: 2023-11-29T12:57:48-08:00
New Revision: 0123608822a7b58d6deca528eef8dc958420acd1

URL: https://github.com/llvm/llvm-project/commit/0123608822a7b58d6deca528eef8dc958420acd1
DIFF: https://github.com/llvm/llvm-project/commit/0123608822a7b58d6deca528eef8dc958420acd1.diff

LOG: [RISCV] Minor improvements/cleanup to target attribute handling. NFC (#73851)

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

Added: 
    

Modified: 
    clang/lib/Basic/Targets/RISCV.cpp

Removed: 
    


################################################################################
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());
   }
 }
 


        


More information about the cfe-commits mailing list