[llvm] r334656 - [TableGen] Make getOnlyTree return a const ref (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 13 13:59:53 PDT 2018
Author: fhahn
Date: Wed Jun 13 13:59:53 2018
New Revision: 334656
URL: http://llvm.org/viewvc/llvm-project?rev=334656&view=rev
Log:
[TableGen] Make getOnlyTree return a const ref (NFC)
This avoids some unnecessary copies of shared_ptrs.
Those changes were suggested post-commit for D47463.
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=334656&r1=334655&r2=334656&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Wed Jun 13 13:59:53 2018
@@ -4010,7 +4010,7 @@ void CodeGenDAGPatterns::ParsePatterns()
InstResults, InstImpResults);
// Promote the xform function to be an explicit node if set.
- TreePatternNodePtr DstPattern = Result.getOnlyTree();
+ const TreePatternNodePtr &DstPattern = Result.getOnlyTree();
std::vector<TreePatternNodePtr> ResultNodeOperands;
for (unsigned ii = 0, ee = DstPattern->getNumChildren(); ii != ee; ++ii) {
TreePatternNodePtr OpNode = DstPattern->getChildShared(ii);
@@ -4023,16 +4023,18 @@ void CodeGenDAGPatterns::ParsePatterns()
}
ResultNodeOperands.push_back(OpNode);
}
- DstPattern = Result.getOnlyTree();
- if (!DstPattern->isLeaf())
- DstPattern = std::make_shared<TreePatternNode>(DstPattern->getOperator(),
- ResultNodeOperands,
- DstPattern->getNumTypes());
+
+ TreePatternNodePtr DstShared =
+ DstPattern->isLeaf()
+ ? DstPattern
+ : std::make_shared<TreePatternNode>(DstPattern->getOperator(),
+ ResultNodeOperands,
+ DstPattern->getNumTypes());
for (unsigned i = 0, e = Result.getOnlyTree()->getNumTypes(); i != e; ++i)
- DstPattern->setType(i, Result.getOnlyTree()->getExtType(i));
+ DstShared->setType(i, Result.getOnlyTree()->getExtType(i));
- TreePattern Temp(Result.getRecord(), DstPattern, false, *this);
+ TreePattern Temp(Result.getRecord(), DstShared, false, *this);
Temp.InferAllTypes();
// A pattern may end up with an "impossible" type, i.e. a situation
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h?rev=334656&r1=334655&r2=334656&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h Wed Jun 13 13:59:53 2018
@@ -814,7 +814,7 @@ public:
unsigned getNumTrees() const { return Trees.size(); }
const TreePatternNodePtr &getTree(unsigned i) const { return Trees[i]; }
void setTree(unsigned i, TreePatternNodePtr Tree) { Trees[i] = Tree; }
- TreePatternNodePtr getOnlyTree() const {
+ const TreePatternNodePtr &getOnlyTree() const {
assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
return Trees[0];
}
More information about the llvm-commits
mailing list