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

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 27 00:20:47 PST 2022


craig.topper created this revision.
craig.topper added reviewers: kito-cheng, eopXD.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
craig.topper requested review of this revision.
Herald added subscribers: pcwang-thead, MaskRay.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118326

Files:
  llvm/lib/Support/RISCVISAInfo.cpp


Index: llvm/lib/Support/RISCVISAInfo.cpp
===================================================================
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -308,7 +308,7 @@
 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 @@
   // 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::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::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 @@
   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::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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118326.403526.patch
Type: text/x-patch
Size: 1861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220127/0526a24b/attachment.bin>


More information about the llvm-commits mailing list