From 40e356d67fb258ab6c3b8f6bedea3982f93e0b57 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 14 Apr 2023 10:37:14 -0700 Subject: [PATCH] [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. --- llvm/utils/TableGen/CodeGenDAGPatterns.cpp | 24 ++++++++++++------------ llvm/utils/TableGen/CodeGenDAGPatterns.h | 5 +++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp index 3d2883c..c01b412 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(getLeafValue(), getNumTypes()); + New = makeIntrusiveRefCnt(getLeafValue(), getNumTypes()); } else { std::vector CChildren; CChildren.reserve(Children.size()); for (unsigned i = 0, e = getNumChildren(); i != e; ++i) CChildren.push_back(getChild(i)->clone()); - New = std::make_shared(getOperator(), std::move(CChildren), + New = makeIntrusiveRefCnt(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( + TreePatternNodePtr R = makeIntrusiveRefCnt( 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(DI, 1); + TreePatternNodePtr Res = makeIntrusiveRefCnt(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(TheInit)) { if (OpName.empty()) error("'?' argument requires a name to match with operand list"); - TreePatternNodePtr Res = std::make_shared(TheInit, 1); + TreePatternNodePtr Res = makeIntrusiveRefCnt(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(TheInit)) TheInit = TheInit->convertInitializerTo(IntRecTy::get(RK)); - return std::make_shared(TheInit, 1); + return makeIntrusiveRefCnt(TheInit, 1); } if (BitsInit *BI = dyn_cast(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( + Children.insert(Children.begin(), makeIntrusiveRefCnt( IntInit::get(RK, IID), 1)); } @@ -3018,7 +3018,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit, } TreePatternNodePtr Result = - std::make_shared(Operator, std::move(Children), + makeIntrusiveRefCnt(Operator, std::move(Children), NumResults); Result->setName(OpName); @@ -3903,7 +3903,7 @@ void CodeGenDAGPatterns::parseInstructionPattern( OpNode->setTransformFn(nullptr); std::vector Children; Children.push_back(OpNode); - OpNode = std::make_shared(Xform, std::move(Children), + OpNode = makeIntrusiveRefCnt(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( + TreePatternNodePtr ResultPattern = makeIntrusiveRefCnt( 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 Children; Children.push_back(PromoteXForms(N)); - return std::make_shared(Xform, std::move(Children), + return makeIntrusiveRefCnt(Xform, std::move(Children), N->getNumTypes()); } @@ -4522,7 +4522,7 @@ static void CombineChildVariants( std::vector NewChildren; for (unsigned i = 0, e = ChildVariants.size(); i != e; ++i) NewChildren.push_back(ChildVariants[i][Idxs[i]]); - TreePatternNodePtr R = std::make_shared( + TreePatternNodePtr R = makeIntrusiveRefCnt( 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 1fb7100..87cb37e 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; +using TreePatternNodePtr = IntrusiveRefCntPtr; /// 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 { /// 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. -- 2.7.4