[llvm] r315148 - [TableGen] Avoid unnecessary std::string creations
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 7 05:08:43 PDT 2017
Author: rksimon
Date: Sat Oct 7 05:08:43 2017
New Revision: 315148
URL: http://llvm.org/viewvc/llvm-project?rev=315148&view=rev
Log:
[TableGen] Avoid unnecessary std::string creations
Avoid unnecessary std::string creations in the TreePredicateFn getters and in CodeGenDAGPatterns::getSDNodeNamed
Differential Revision: https://reviews.llvm.org/D38624
Modified:
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=315148&r1=315147&r2=315148&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Sat Oct 7 05:08:43 2017
@@ -854,11 +854,11 @@ TreePredicateFn::TreePredicateFn(TreePat
".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 @@ std::string TreePredicateFn::getFnName()
/// 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 @@ std::string TreePredicateFn::getCodeToRu
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 @@ CodeGenDAGPatterns::CodeGenDAGPatterns(R
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 + "'!");
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h?rev=315148&r1=315147&r2=315148&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h Sat Oct 7 05:08:43 2017
@@ -452,8 +452,8 @@ public:
/// 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 @@ public:
std::string getCodeToRunOnSDNode() const;
private:
- std::string getPredCode() const;
- std::string getImmCode() const;
+ StringRef getPredCode() const;
+ StringRef getImmCode() const;
};
@@ -995,7 +995,7 @@ public:
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!");
More information about the llvm-commits
mailing list