[PATCH] D38624: [TableGen] Avoid unnecessary std::string creations

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 6 06:57:42 PDT 2017


RKSimon created this revision.

Avoid unnecessary std::string creations in the TreePredicateFn getters and in CodeGenDAGPatterns::getSDNodeNamed


Repository:
  rL LLVM

https://reviews.llvm.org/D38624

Files:
  utils/TableGen/CodeGenDAGPatterns.cpp
  utils/TableGen/CodeGenDAGPatterns.h


Index: utils/TableGen/CodeGenDAGPatterns.h
===================================================================
--- utils/TableGen/CodeGenDAGPatterns.h
+++ utils/TableGen/CodeGenDAGPatterns.h
@@ -452,8 +452,8 @@
   /// getImmediatePredicateCode - Return the code that evaluates this pattern if
   /// this is an immediate predicate.  It is an error to call this on a
   /// non-immediate pattern.
-  std::string getImmediatePredicateCode() const {
-    std::string Result = getImmCode();
+  StringRef getImmediatePredicateCode() const {
+    StringRef Result = getImmCode();
     assert(!Result.empty() && "Isn't an immediate pattern!");
     return Result;
   }
@@ -476,8 +476,8 @@
   std::string getCodeToRunOnSDNode() const;
 
 private:
-  std::string getPredCode() const;
-  std::string getImmCode() const;
+  StringRef getPredCode() const;
+  StringRef getImmCode() const;
 };
 
 
@@ -995,7 +995,7 @@
   const CodeGenTarget &getTargetInfo() const { return Target; }
   const TypeSetByHwMode &getLegalTypes() const { return LegalVTS; }
 
-  Record *getSDNodeNamed(const std::string &Name) const;
+  Record *getSDNodeNamed(StringRef Name) const;
 
   const SDNodeInfo &getSDNodeInfo(Record *R) const {
     assert(SDNodes.count(R) && "Unknown node!");
Index: utils/TableGen/CodeGenDAGPatterns.cpp
===================================================================
--- utils/TableGen/CodeGenDAGPatterns.cpp
+++ utils/TableGen/CodeGenDAGPatterns.cpp
@@ -854,11 +854,11 @@
         ".td file corrupt: can't have a node predicate *and* an imm predicate");
 }
 
-std::string TreePredicateFn::getPredCode() const {
+StringRef TreePredicateFn::getPredCode() const {
   return PatFragRec->getRecord()->getValueAsString("PredicateCode");
 }
 
-std::string TreePredicateFn::getImmCode() const {
+StringRef TreePredicateFn::getImmCode() const {
   return PatFragRec->getRecord()->getValueAsString("ImmediateCode");
 }
 
@@ -880,16 +880,16 @@
 /// appropriate.
 std::string TreePredicateFn::getCodeToRunOnSDNode() const {
   // Handle immediate predicates first.
-  std::string ImmCode = getImmCode();
+  StringRef ImmCode = getImmCode();
   if (!ImmCode.empty()) {
     std::string Result =
       "    int64_t Imm = cast<ConstantSDNode>(Node)->getSExtValue();\n";
-    return Result + ImmCode;
+    return Result + ImmCode.str();
   }
 
   // Handle arbitrary node predicates.
   assert(!getPredCode().empty() && "Don't have any predicate code!");
-  std::string ClassName;
+  StringRef ClassName;
   if (PatFragRec->getOnlyTree()->isLeaf())
     ClassName = "SDNode";
   else {
@@ -900,9 +900,9 @@
   if (ClassName == "SDNode")
     Result = "    SDNode *N = Node;\n";
   else
-    Result = "    auto *N = cast<" + ClassName + ">(Node);\n";
+    Result = "    auto *N = cast<" + ClassName.str() + ">(Node);\n";
 
-  return Result + getPredCode();
+  return Result + getPredCode().str();
 }
 
 //===----------------------------------------------------------------------===//
@@ -2564,7 +2564,7 @@
   VerifyInstructionFlags();
 }
 
-Record *CodeGenDAGPatterns::getSDNodeNamed(const std::string &Name) const {
+Record *CodeGenDAGPatterns::getSDNodeNamed(StringRef Name) const {
   Record *N = Records.getDef(Name);
   if (!N || !N->isSubClassOf("SDNode"))
     PrintFatalError("Error getting SDNode '" + Name + "'!");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38624.117990.patch
Type: text/x-patch
Size: 3388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171006/34eafc7b/attachment.bin>


More information about the llvm-commits mailing list