[llvm] 886dd11 - [RISCV] Use const reference when looping over Exts in RISCVISAInfo.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 27 09:24:31 PST 2022


Author: Craig Topper
Date: 2022-01-27T09:24:24-08:00
New Revision: 886dd1179572e62c8f83f4cdb61044b232ccda4b

URL: https://github.com/llvm/llvm-project/commit/886dd1179572e62c8f83f4cdb61044b232ccda4b
DIFF: https://github.com/llvm/llvm-project/commit/886dd1179572e62c8f83f4cdb61044b232ccda4b.diff

LOG: [RISCV] Use const reference when looping over Exts in RISCVISAInfo.

Exts is a map of keyed by std::string with a extension info as
a value. Making copies of this wouldn't be cheap.

We had a mix of references and copies. This makes everything
consistently use a const reference to make it clear we aren't
modifying it.

Differential Revision: https://reviews.llvm.org/D118326

Added: 
    

Modified: 
    llvm/lib/Support/RISCVISAInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp
index a78c7057c881b..6c59d8a7ef047 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -308,7 +308,7 @@ bool RISCVISAInfo::compareExtension(const std::string &LHS,
 void RISCVISAInfo::toFeatures(
     std::vector<StringRef> &Features,
     std::function<StringRef(const Twine &)> StrAlloc) const {
-  for (auto &Ext : Exts) {
+  for (auto const &Ext : Exts) {
     StringRef ExtName = Ext.first;
 
     if (ExtName == "i")
@@ -825,7 +825,7 @@ void RISCVISAInfo::updateImplication() {
   // This loop may execute over 1 iteration since implication can be layered
   // Exits loop if no more implication is applied
   SmallSetVector<StringRef, 16> WorkList;
-  for (auto &Ext : Exts)
+  for (auto const &Ext : Exts)
     WorkList.insert(Ext.first);
 
   while (!WorkList.empty()) {
@@ -855,7 +855,7 @@ void RISCVISAInfo::updateFLen() {
 }
 
 void RISCVISAInfo::updateMinVLen() {
-  for (auto Ext : Exts) {
+  for (auto const &Ext : Exts) {
     StringRef ExtName = Ext.first;
     bool IsZvlExt = ExtName.consume_front("zvl") && ExtName.consume_back("b");
     if (IsZvlExt) {
@@ -868,7 +868,7 @@ void RISCVISAInfo::updateMinVLen() {
 
 void RISCVISAInfo::updateMaxELen() {
   // handles EEW restriction by sub-extension zve
-  for (auto Ext : Exts) {
+  for (auto const &Ext : Exts) {
     StringRef ExtName = Ext.first;
     bool IsZveExt = ExtName.consume_front("zve");
     if (IsZveExt) {
@@ -896,7 +896,7 @@ std::string RISCVISAInfo::toString() const {
   Arch << "rv" << XLen;
 
   ListSeparator LS("_");
-  for (auto &Ext : Exts) {
+  for (auto const &Ext : Exts) {
     StringRef ExtName = Ext.first;
     auto ExtInfo = Ext.second;
     Arch << LS << ExtName;
@@ -908,7 +908,7 @@ std::string RISCVISAInfo::toString() const {
 
 std::vector<std::string> RISCVISAInfo::toFeatureVector() const {
   std::vector<std::string> FeatureVector;
-  for (auto Ext : Exts) {
+  for (auto const &Ext : Exts) {
     std::string ExtName = Ext.first;
     if (ExtName == "i") // i is not recognized in clang -cc1
       continue;


        


More information about the llvm-commits mailing list