[PATCH] D147592: Replace `const std::string&` with StringRef in Target APIs.

Ondrej Sykora via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 5 01:12:25 PDT 2023


ondrasej created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
ondrasej requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147592

Files:
  llvm/include/llvm/MC/TargetRegistry.h
  llvm/lib/MC/TargetRegistry.cpp


Index: llvm/lib/MC/TargetRegistry.cpp
===================================================================
--- llvm/lib/MC/TargetRegistry.cpp
+++ llvm/lib/MC/TargetRegistry.cpp
@@ -21,7 +21,7 @@
   return make_range(iterator(FirstTarget), iterator());
 }
 
-const Target *TargetRegistry::lookupTarget(const std::string &ArchName,
+const Target *TargetRegistry::lookupTarget(StringRef ArchName,
                                            Triple &TheTriple,
                                            std::string &Error) {
   // Allocate target machine.  First, check whether the user has explicitly
@@ -33,7 +33,7 @@
                      [&](const Target &T) { return ArchName == T.getName(); });
 
     if (I == targets().end()) {
-      Error = "invalid target '" + ArchName + "'.\n";
+      Error = ("invalid target '" + ArchName + "'.\n").str();
       return nullptr;
     }
 
@@ -59,8 +59,7 @@
   return TheTarget;
 }
 
-const Target *TargetRegistry::lookupTarget(const std::string &TT,
-                                           std::string &Error) {
+const Target *TargetRegistry::lookupTarget(StringRef TT, std::string &Error) {
   // Provide special warning when no targets are initialized.
   if (targets().begin() == targets().end()) {
     Error = "Unable to find target for this triple (no targets are registered)";
@@ -71,7 +70,8 @@
   auto I = find_if(targets(), ArchMatch);
 
   if (I == targets().end()) {
-    Error = "No available targets are compatible with triple \"" + TT + "\"";
+    Error = ("No available targets are compatible with triple \"" + TT + "\"")
+                .str();
     return nullptr;
   }
 
Index: llvm/include/llvm/MC/TargetRegistry.h
===================================================================
--- llvm/include/llvm/MC/TargetRegistry.h
+++ llvm/include/llvm/MC/TargetRegistry.h
@@ -791,8 +791,7 @@
   /// \param Triple - The triple to use for finding a target.
   /// \param Error - On failure, an error string describing why no target was
   /// found.
-  static const Target *lookupTarget(const std::string &Triple,
-                                    std::string &Error);
+  static const Target *lookupTarget(StringRef Triple, std::string &Error);
 
   /// lookupTarget - Lookup a target based on an architecture name
   /// and a target triple.  If the architecture name is non-empty,
@@ -805,8 +804,8 @@
   /// by architecture is done.
   /// \param Error - On failure, an error string describing why no target was
   /// found.
-  static const Target *lookupTarget(const std::string &ArchName,
-                                    Triple &TheTriple, std::string &Error);
+  static const Target *lookupTarget(StringRef ArchName, Triple &TheTriple,
+                                    std::string &Error);
 
   /// @}
   /// @name Target Registration


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147592.511006.patch
Type: text/x-patch
Size: 2814 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230405/b2b90cab/attachment.bin>


More information about the llvm-commits mailing list