[llvm] 122c0e6 - [TableGen] Use StringRef instead of std::string to split up a string that's being parsed. NFCI

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 3 11:54:39 PDT 2021


Author: Craig Topper
Date: 2021-04-03T11:48:13-07:00
New Revision: 122c0e61f1331f7e6106cdb9dfa95cefad5b3653

URL: https://github.com/llvm/llvm-project/commit/122c0e61f1331f7e6106cdb9dfa95cefad5b3653
DIFF: https://github.com/llvm/llvm-project/commit/122c0e61f1331f7e6106cdb9dfa95cefad5b3653.diff

LOG: [TableGen] Use StringRef instead of std::string to split up a string that's being parsed. NFCI

Added: 
    

Modified: 
    llvm/utils/TableGen/CodeGenInstruction.cpp
    llvm/utils/TableGen/CodeGenInstruction.h

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/CodeGenInstruction.cpp b/llvm/utils/TableGen/CodeGenInstruction.cpp
index 960fe08677f7..3933ce6e1106 100644
--- a/llvm/utils/TableGen/CodeGenInstruction.cpp
+++ b/llvm/utils/TableGen/CodeGenInstruction.cpp
@@ -177,17 +177,17 @@ bool CGIOperandList::hasOperandNamed(StringRef Name, unsigned &OpIdx) const {
 }
 
 std::pair<unsigned,unsigned>
-CGIOperandList::ParseOperandName(const std::string &Op, bool AllowWholeOp) {
+CGIOperandList::ParseOperandName(StringRef Op, bool AllowWholeOp) {
   if (Op.empty() || Op[0] != '$')
     PrintFatalError(TheDef->getLoc(),
                     TheDef->getName() + ": Illegal operand name: '" + Op + "'");
 
-  std::string OpName = Op.substr(1);
-  std::string SubOpName;
+  StringRef OpName = Op.substr(1);
+  StringRef SubOpName;
 
   // Check to see if this is $foo.bar.
-  std::string::size_type DotIdx = OpName.find_first_of('.');
-  if (DotIdx != std::string::npos) {
+  StringRef::size_type DotIdx = OpName.find_first_of('.');
+  if (DotIdx != StringRef::npos) {
     SubOpName = OpName.substr(DotIdx+1);
     if (SubOpName.empty())
       PrintFatalError(TheDef->getLoc(),
@@ -231,16 +231,16 @@ CGIOperandList::ParseOperandName(const std::string &Op, bool AllowWholeOp) {
   return std::make_pair(0U, 0U);
 }
 
-static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops,
+static void ParseConstraint(StringRef CStr, CGIOperandList &Ops,
                             Record *Rec) {
   // EARLY_CLOBBER: @early $reg
-  std::string::size_type wpos = CStr.find_first_of(" \t");
-  std::string::size_type start = CStr.find_first_not_of(" \t");
-  std::string Tok = CStr.substr(start, wpos - start);
+  StringRef::size_type wpos = CStr.find_first_of(" \t");
+  StringRef::size_type start = CStr.find_first_not_of(" \t");
+  StringRef Tok = CStr.substr(start, wpos - start);
   if (Tok == "@earlyclobber") {
-    std::string Name = CStr.substr(wpos+1);
+    StringRef Name = CStr.substr(wpos+1);
     wpos = Name.find_first_not_of(" \t");
-    if (wpos == std::string::npos)
+    if (wpos == StringRef::npos)
       PrintFatalError(
         Rec->getLoc(), "Illegal format for @earlyclobber constraint in '" +
         Rec->getName() + "': '" + CStr + "'");
@@ -258,8 +258,8 @@ static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops,
   }
 
   // Only other constraint is "TIED_TO" for now.
-  std::string::size_type pos = CStr.find_first_of('=');
-  if (pos == std::string::npos)
+  StringRef::size_type pos = CStr.find_first_of('=');
+  if (pos == StringRef::npos)
     PrintFatalError(
       Rec->getLoc(), "Unrecognized constraint '" + CStr +
       "' in '" + Rec->getName() + "'");
@@ -267,20 +267,19 @@ static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops,
 
   // TIED_TO: $src1 = $dst
   wpos = CStr.find_first_of(" \t", start);
-  if (wpos == std::string::npos || wpos > pos)
+  if (wpos == StringRef::npos || wpos > pos)
     PrintFatalError(
       Rec->getLoc(), "Illegal format for tied-to constraint in '" +
       Rec->getName() + "': '" + CStr + "'");
-  std::string LHSOpName =
-      std::string(StringRef(CStr).substr(start, wpos - start));
+  StringRef LHSOpName = CStr.substr(start, wpos - start);
   std::pair<unsigned,unsigned> LHSOp = Ops.ParseOperandName(LHSOpName, false);
 
   wpos = CStr.find_first_not_of(" \t", pos + 1);
-  if (wpos == std::string::npos)
+  if (wpos == StringRef::npos)
     PrintFatalError(
       Rec->getLoc(), "Illegal format for tied-to constraint: '" + CStr + "'");
 
-  std::string RHSOpName = std::string(StringRef(CStr).substr(wpos));
+  StringRef RHSOpName = CStr.substr(wpos);
   std::pair<unsigned,unsigned> RHSOp = Ops.ParseOperandName(RHSOpName, false);
 
   // Sort the operands into order, which should put the output one
@@ -325,29 +324,27 @@ static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops,
   Ops[SrcOp.first].Constraints[SrcOp.second] = NewConstraint;
 }
 
-static void ParseConstraints(const std::string &CStr, CGIOperandList &Ops,
-                             Record *Rec) {
+static void ParseConstraints(StringRef CStr, CGIOperandList &Ops, Record *Rec) {
   if (CStr.empty()) return;
 
-  const std::string delims(",");
-  std::string::size_type bidx, eidx;
+  StringRef delims(",");
+  StringRef::size_type bidx, eidx;
 
   bidx = CStr.find_first_not_of(delims);
-  while (bidx != std::string::npos) {
+  while (bidx != StringRef::npos) {
     eidx = CStr.find_first_of(delims, bidx);
-    if (eidx == std::string::npos)
-      eidx = CStr.length();
+    if (eidx == StringRef::npos)
+      eidx = CStr.size();
 
     ParseConstraint(CStr.substr(bidx, eidx - bidx), Ops, Rec);
     bidx = CStr.find_first_not_of(delims, eidx);
   }
 }
 
-void CGIOperandList::ProcessDisableEncoding(std::string DisableEncoding) {
+void CGIOperandList::ProcessDisableEncoding(StringRef DisableEncoding) {
   while (1) {
-    std::pair<StringRef, StringRef> P = getToken(DisableEncoding, " ,\t");
-    std::string OpName = std::string(P.first);
-    DisableEncoding = std::string(P.second);
+    StringRef OpName;
+    std::tie(OpName, DisableEncoding) = getToken(DisableEncoding, " ,\t");
     if (OpName.empty()) break;
 
     // Figure out which operand this is.
@@ -427,12 +424,11 @@ CodeGenInstruction::CodeGenInstruction(Record *R)
   hasChain_Inferred = false;
 
   // Parse Constraints.
-  ParseConstraints(std::string(R->getValueAsString("Constraints")), Operands,
-                   R);
+  ParseConstraints(R->getValueAsString("Constraints"), Operands, R);
 
   // Parse the DisableEncoding field.
   Operands.ProcessDisableEncoding(
-      std::string(R->getValueAsString("DisableEncoding")));
+      R->getValueAsString("DisableEncoding"));
 
   // First check for a ComplexDeprecationPredicate.
   if (R->getValue("ComplexDeprecationPredicate")) {

diff  --git a/llvm/utils/TableGen/CodeGenInstruction.h b/llvm/utils/TableGen/CodeGenInstruction.h
index af851a11676b..e35d2191ea45 100644
--- a/llvm/utils/TableGen/CodeGenInstruction.h
+++ b/llvm/utils/TableGen/CodeGenInstruction.h
@@ -182,7 +182,7 @@ template <typename T> class ArrayRef;
     /// where $foo is a whole operand and $foo.bar refers to a suboperand.
     /// This aborts if the name is invalid.  If AllowWholeOp is true, references
     /// to operands with suboperands are allowed, otherwise not.
-    std::pair<unsigned,unsigned> ParseOperandName(const std::string &Op,
+    std::pair<unsigned,unsigned> ParseOperandName(StringRef Op,
                                                   bool AllowWholeOp = true);
 
     /// getFlattenedOperandNumber - Flatten a operand/suboperand pair into a
@@ -211,7 +211,7 @@ template <typename T> class ArrayRef;
       return false;
     }
 
-    void ProcessDisableEncoding(std::string Value);
+    void ProcessDisableEncoding(StringRef Value);
   };
 
 


        


More information about the llvm-commits mailing list