Skip to content

Commit

Permalink
Revert r315148 [TableGen] Avoid unnecessary std::string creations
Browse files Browse the repository at this point in the history
I'm about to commit a patch that makes them necessary for getPredCode() and
it would be strange for getPredCode() and getImmCode() to require different
usage.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315733 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dsandersllvm committed Oct 13, 2017
1 parent fb7d705 commit 0431295
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions utils/TableGen/CodeGenDAGPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,11 @@ TreePredicateFn::TreePredicateFn(TreePattern *N) : PatFragRec(N) {
".td file corrupt: can't have a node predicate *and* an imm predicate");
}

StringRef TreePredicateFn::getPredCode() const {
std::string TreePredicateFn::getPredCode() const {
return PatFragRec->getRecord()->getValueAsString("PredicateCode");
}

StringRef TreePredicateFn::getImmCode() const {
std::string TreePredicateFn::getImmCode() const {
return PatFragRec->getRecord()->getValueAsString("ImmediateCode");
}

Expand All @@ -880,16 +880,16 @@ std::string TreePredicateFn::getFnName() const {
/// appropriate.
std::string TreePredicateFn::getCodeToRunOnSDNode() const {
// Handle immediate predicates first.
StringRef ImmCode = getImmCode();
std::string ImmCode = getImmCode();
if (!ImmCode.empty()) {
std::string Result =
" int64_t Imm = cast<ConstantSDNode>(Node)->getSExtValue();\n";
return Result + ImmCode.str();
return Result + ImmCode;
}

// Handle arbitrary node predicates.
assert(!getPredCode().empty() && "Don't have any predicate code!");
StringRef ClassName;
std::string ClassName;
if (PatFragRec->getOnlyTree()->isLeaf())
ClassName = "SDNode";
else {
Expand All @@ -900,9 +900,9 @@ std::string TreePredicateFn::getCodeToRunOnSDNode() const {
if (ClassName == "SDNode")
Result = " SDNode *N = Node;\n";
else
Result = " auto *N = cast<" + ClassName.str() + ">(Node);\n";
Result = " auto *N = cast<" + ClassName + ">(Node);\n";

return Result + getPredCode().str();
return Result + getPredCode();
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -2564,7 +2564,7 @@ CodeGenDAGPatterns::CodeGenDAGPatterns(RecordKeeper &R) :
VerifyInstructionFlags();
}

Record *CodeGenDAGPatterns::getSDNodeNamed(StringRef Name) const {
Record *CodeGenDAGPatterns::getSDNodeNamed(const std::string &Name) const {
Record *N = Records.getDef(Name);
if (!N || !N->isSubClassOf("SDNode"))
PrintFatalError("Error getting SDNode '" + Name + "'!");
Expand Down
10 changes: 5 additions & 5 deletions utils/TableGen/CodeGenDAGPatterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ class TreePredicateFn {
/// 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.
StringRef getImmediatePredicateCode() const {
StringRef Result = getImmCode();
std::string getImmediatePredicateCode() const {
std::string Result = getImmCode();
assert(!Result.empty() && "Isn't an immediate pattern!");
return Result;
}
Expand All @@ -476,8 +476,8 @@ class TreePredicateFn {
std::string getCodeToRunOnSDNode() const;

private:
StringRef getPredCode() const;
StringRef getImmCode() const;
std::string getPredCode() const;
std::string getImmCode() const;
};


Expand Down Expand Up @@ -995,7 +995,7 @@ class CodeGenDAGPatterns {
const CodeGenTarget &getTargetInfo() const { return Target; }
const TypeSetByHwMode &getLegalTypes() const { return LegalVTS; }

Record *getSDNodeNamed(StringRef Name) const;
Record *getSDNodeNamed(const std::string &Name) const;

const SDNodeInfo &getSDNodeInfo(Record *R) const {
auto F = SDNodes.find(R);
Expand Down

0 comments on commit 0431295

Please sign in to comment.