[llvm] 40e356d - [TableGen] Replace std::shared_ptr with InstrusiveRefCntPtr for TreePatternNode. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 14 10:57:21 PDT 2023
Author: Craig Topper
Date: 2023-04-14T10:56:36-07:00
New Revision: 40e356d67fb258ab6c3b8f6bedea3982f93e0b57
URL: https://github.com/llvm/llvm-project/commit/40e356d67fb258ab6c3b8f6bedea3982f93e0b57
DIFF: https://github.com/llvm/llvm-project/commit/40e356d67fb258ab6c3b8f6bedea3982f93e0b57.diff
LOG: [TableGen] Replace std::shared_ptr with InstrusiveRefCntPtr for TreePatternNode. NFC
An intrusive reference counter uses less memory than the control
block of std::shared_ptr.
This should allow some additional code simplifications if we
don't need to pass around shared_ptr in order to create new
shared_ptrs.
Added:
Modified:
llvm/utils/TableGen/CodeGenDAGPatterns.cpp
llvm/utils/TableGen/CodeGenDAGPatterns.h
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index 3d2883c1cdf62..c01b41249f74f 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -2010,13 +2010,13 @@ bool TreePatternNode::isIsomorphicTo(const TreePatternNode *N,
TreePatternNodePtr TreePatternNode::clone() const {
TreePatternNodePtr New;
if (isLeaf()) {
- New = std::make_shared<TreePatternNode>(getLeafValue(), getNumTypes());
+ New = makeIntrusiveRefCnt<TreePatternNode>(getLeafValue(), getNumTypes());
} else {
std::vector<TreePatternNodePtr> CChildren;
CChildren.reserve(Children.size());
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
CChildren.push_back(getChild(i)->clone());
- New = std::make_shared<TreePatternNode>(getOperator(), std::move(CChildren),
+ New = makeIntrusiveRefCnt<TreePatternNode>(getOperator(), std::move(CChildren),
getNumTypes());
}
New->setName(getName());
@@ -2119,7 +2119,7 @@ void TreePatternNode::InlinePatternFragments(
NewChildren.reserve(ChildAlternatives.size());
for (unsigned i = 0, e = ChildAlternatives.size(); i != e; ++i)
NewChildren.push_back(ChildAlternatives[i][Idxs[i]]);
- TreePatternNodePtr R = std::make_shared<TreePatternNode>(
+ TreePatternNodePtr R = makeIntrusiveRefCnt<TreePatternNode>(
T->getOperator(), std::move(NewChildren), T->getNumTypes());
// Copy over properties.
@@ -2862,7 +2862,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
OpName);
// Input argument?
- TreePatternNodePtr Res = std::make_shared<TreePatternNode>(DI, 1);
+ TreePatternNodePtr Res = makeIntrusiveRefCnt<TreePatternNode>(DI, 1);
if (R->getName() == "node" && !OpName.empty()) {
if (OpName.empty())
error("'node' argument requires a name to match with operand list");
@@ -2877,7 +2877,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
if (isa<UnsetInit>(TheInit)) {
if (OpName.empty())
error("'?' argument requires a name to match with operand list");
- TreePatternNodePtr Res = std::make_shared<TreePatternNode>(TheInit, 1);
+ TreePatternNodePtr Res = makeIntrusiveRefCnt<TreePatternNode>(TheInit, 1);
Args.push_back(std::string(OpName));
Res->setName(OpName);
return Res;
@@ -2888,7 +2888,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
error("Constant int or bit argument should not have a name!");
if (isa<BitInit>(TheInit))
TheInit = TheInit->convertInitializerTo(IntRecTy::get(RK));
- return std::make_shared<TreePatternNode>(TheInit, 1);
+ return makeIntrusiveRefCnt<TreePatternNode>(TheInit, 1);
}
if (BitsInit *BI = dyn_cast<BitsInit>(TheInit)) {
@@ -2992,7 +2992,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
else // Otherwise, no chain.
Operator = getDAGPatterns().get_intrinsic_wo_chain_sdnode();
- Children.insert(Children.begin(), std::make_shared<TreePatternNode>(
+ Children.insert(Children.begin(), makeIntrusiveRefCnt<TreePatternNode>(
IntInit::get(RK, IID), 1));
}
@@ -3018,7 +3018,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
}
TreePatternNodePtr Result =
- std::make_shared<TreePatternNode>(Operator, std::move(Children),
+ makeIntrusiveRefCnt<TreePatternNode>(Operator, std::move(Children),
NumResults);
Result->setName(OpName);
@@ -3903,7 +3903,7 @@ void CodeGenDAGPatterns::parseInstructionPattern(
OpNode->setTransformFn(nullptr);
std::vector<TreePatternNodePtr> Children;
Children.push_back(OpNode);
- OpNode = std::make_shared<TreePatternNode>(Xform, std::move(Children),
+ OpNode = makeIntrusiveRefCnt<TreePatternNode>(Xform, std::move(Children),
OpNode->getNumTypes());
}
@@ -3914,7 +3914,7 @@ void CodeGenDAGPatterns::parseInstructionPattern(
I.error("Input operand $" + InstInputs.begin()->first +
" occurs in pattern but not in operands list!");
- TreePatternNodePtr ResultPattern = std::make_shared<TreePatternNode>(
+ TreePatternNodePtr ResultPattern = makeIntrusiveRefCnt<TreePatternNode>(
I.getRecord(), std::move(ResultNodeOperands),
GetNumNodeResults(I.getRecord(), *this));
// Copy fully inferred output node types to instruction result pattern.
@@ -4234,7 +4234,7 @@ static TreePatternNodePtr PromoteXForms(TreePatternNodePtr N) {
N->setTransformFn(nullptr);
std::vector<TreePatternNodePtr> Children;
Children.push_back(PromoteXForms(N));
- return std::make_shared<TreePatternNode>(Xform, std::move(Children),
+ return makeIntrusiveRefCnt<TreePatternNode>(Xform, std::move(Children),
N->getNumTypes());
}
@@ -4522,7 +4522,7 @@ static void CombineChildVariants(
std::vector<TreePatternNodePtr> NewChildren;
for (unsigned i = 0, e = ChildVariants.size(); i != e; ++i)
NewChildren.push_back(ChildVariants[i][Idxs[i]]);
- TreePatternNodePtr R = std::make_shared<TreePatternNode>(
+ TreePatternNodePtr R = makeIntrusiveRefCnt<TreePatternNode>(
Orig->getOperator(), std::move(NewChildren), Orig->getNumTypes());
// Copy over properties.
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.h b/llvm/utils/TableGen/CodeGenDAGPatterns.h
index 1fb7100eb4aa3..87cb37e581afd 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.h
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.h
@@ -17,6 +17,7 @@
#include "CodeGenIntrinsics.h"
#include "CodeGenTarget.h"
#include "SDNodeProperties.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
@@ -42,7 +43,7 @@ class TreePatternNode;
class CodeGenDAGPatterns;
/// Shared pointer for TreePatternNode.
-using TreePatternNodePtr = std::shared_ptr<TreePatternNode>;
+using TreePatternNodePtr = IntrusiveRefCntPtr<TreePatternNode>;
/// This represents a set of MVTs. Since the underlying type for the MVT
/// is uint8_t, there are at most 256 values. To reduce the number of memory
@@ -623,7 +624,7 @@ struct TreePredicateCall {
}
};
-class TreePatternNode {
+class TreePatternNode : public RefCountedBase<TreePatternNode> {
/// The type of each node result. Before and during type inference, each
/// result may be a set of possible types. After (successful) type inference,
/// each is a single concrete type.
More information about the llvm-commits
mailing list