[llvm] 1053e0b - [RISCV] Use a lambda to avoid having the Support library depend on Option library.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 18 13:43:59 PDT 2021


Author: Craig Topper
Date: 2021-10-18T13:39:37-07:00
New Revision: 1053e0b27ce135ce2da63af01aa986b9425386ee

URL: https://github.com/llvm/llvm-project/commit/1053e0b27ce135ce2da63af01aa986b9425386ee
DIFF: https://github.com/llvm/llvm-project/commit/1053e0b27ce135ce2da63af01aa986b9425386ee.diff

LOG: [RISCV] Use a lambda to avoid having the Support library depend on Option library.

RISCVISAInfo::toFeatures needs to allocate strings using
ArgList::MakeArgString, but toFeatures lives in Support and
MakeArgString lives in Option.

toFeature only has one caller, so the simple fix is to have that
caller pass a lamdba that wraps MakeArgString to break the
dependency.

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

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Arch/RISCV.cpp
    llvm/include/llvm/Support/RISCVISAInfo.h
    llvm/lib/Support/RISCVISAInfo.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 6cb6d0b2d1fcc..323f588c8269c 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -41,7 +41,8 @@ static bool getArchFeatures(const Driver &D, StringRef Arch,
     return false;
   }
 
-  (*ISAInfo)->toFeatures(Args, Features);
+  (*ISAInfo)->toFeatures(
+      Features, [&Args](const Twine &Str) { return Args.MakeArgString(Str); });
   return true;
 }
 

diff  --git a/llvm/include/llvm/Support/RISCVISAInfo.h b/llvm/include/llvm/Support/RISCVISAInfo.h
index fe8599e1e04be..7110de601123f 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -19,9 +19,6 @@
 #include <vector>
 
 namespace llvm {
-namespace opt {
-class ArgList;
-}
 struct RISCVExtensionInfo {
   std::string ExtName;
   unsigned MajorVersion;
@@ -57,8 +54,8 @@ class RISCVISAInfo {
   parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
 
   /// Convert RISCV ISA info to a feature vector.
-  void toFeatures(const llvm::opt::ArgList &Args,
-                  std::vector<StringRef> &Features) const;
+  void toFeatures(std::vector<StringRef> &Features,
+                  std::function<StringRef(const Twine &)> StrAlloc) const;
 
   const OrderedExtensionMap &getExtensions() const { return Exts; };
 

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp
index 795d77defc984..8bbfc757f0755 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Option/ArgList.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
@@ -252,8 +251,9 @@ bool RISCVISAInfo::compareExtension(const std::string &LHS,
   return LHS < RHS;
 }
 
-void RISCVISAInfo::toFeatures(const llvm::opt::ArgList &Args,
-                              std::vector<StringRef> &Features) const {
+void RISCVISAInfo::toFeatures(
+    std::vector<StringRef> &Features,
+    std::function<StringRef(const Twine &)> StrAlloc) const {
   for (auto &Ext : Exts) {
     StringRef ExtName = Ext.first;
 
@@ -268,9 +268,9 @@ void RISCVISAInfo::toFeatures(const llvm::opt::ArgList &Args,
       Features.push_back("+experimental-zvlsseg");
       Features.push_back("+experimental-zvamo");
     } else if (isExperimentalExtension(ExtName)) {
-      Features.push_back(Args.MakeArgString("+experimental-" + ExtName));
+      Features.push_back(StrAlloc("+experimental-" + ExtName));
     } else {
-      Features.push_back(Args.MakeArgString("+" + ExtName));
+      Features.push_back(StrAlloc("+" + ExtName));
     }
   }
 }


        


More information about the llvm-commits mailing list