From 5a1de140677e9138625135514fc4ed0dc969d80c Mon Sep 17 00:00:00 2001 From: Ondrej Sykora Date: Sun, 21 May 2023 09:52:21 -0400 Subject: [PATCH] Replace `const std::string&` with StringRef in TargetRegistry APIs; NFC Differential Revision: https://reviews.llvm.org/D147592 --- llvm/include/llvm/MC/TargetRegistry.h | 7 +++---- llvm/lib/MC/TargetRegistry.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/llvm/include/llvm/MC/TargetRegistry.h b/llvm/include/llvm/MC/TargetRegistry.h index d9ecd21..3d44eaa 100644 --- a/llvm/include/llvm/MC/TargetRegistry.h +++ b/llvm/include/llvm/MC/TargetRegistry.h @@ -791,8 +791,7 @@ struct TargetRegistry { /// \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 @@ struct TargetRegistry { /// 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 diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp index b54853a..fa7aacc 100644 --- a/llvm/lib/MC/TargetRegistry.cpp +++ b/llvm/lib/MC/TargetRegistry.cpp @@ -21,7 +21,7 @@ iterator_range TargetRegistry::targets() { 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 *TargetRegistry::lookupTarget(const std::string &ArchName, [&](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 @@ const Target *TargetRegistry::lookupTarget(const std::string &ArchName, 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 @@ const Target *TargetRegistry::lookupTarget(const std::string &TT, 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; } -- 2.7.4