Skip to content

Commit a9e546c

Browse files
[TableGen][NFC] convert TreePatternNode pointers to references (#81134)
Almost all uses of `*TreePatternNode` expect it to be non-null. There was the occasional check that it wasn't, which I have removed. Making them references makes it clear that they exist. This was attempted in 2018 (1b46576) for `TreePatternNode::getChild()` but that was reverted.
1 parent 413e82a commit a9e546c

9 files changed

+615
-628
lines changed

llvm/utils/TableGen/CodeGenDAGPatterns.cpp

Lines changed: 182 additions & 182 deletions
Large diffs are not rendered by default.

llvm/utils/TableGen/CodeGenDAGPatterns.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ struct SDTypeConstraint {
406406
/// constraint to the nodes operands. This returns true if it makes a
407407
/// change, false otherwise. If a type contradiction is found, an error
408408
/// is flagged.
409-
bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
409+
bool ApplyTypeConstraint(TreePatternNode &N, const SDNodeInfo &NodeInfo,
410410
TreePattern &TP) const;
411411
};
412412

@@ -474,7 +474,7 @@ class SDNodeInfo {
474474
/// constraints for this node to the operands of the node. This returns
475475
/// true if it makes a change, false otherwise. If a type contradiction is
476476
/// found, an error is flagged.
477-
bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const;
477+
bool ApplyTypeConstraints(TreePatternNode &N, TreePattern &TP) const;
478478
};
479479

480480
/// TreePredicateFn - This is an abstraction that represents the predicates on
@@ -722,10 +722,10 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
722722
}
723723

724724
unsigned getNumChildren() const { return Children.size(); }
725-
const TreePatternNode *getChild(unsigned N) const {
726-
return Children[N].get();
725+
const TreePatternNode &getChild(unsigned N) const {
726+
return *Children[N].get();
727727
}
728-
TreePatternNode *getChild(unsigned N) { return Children[N].get(); }
728+
TreePatternNode &getChild(unsigned N) { return *Children[N].get(); }
729729
const TreePatternNodePtr &getChildShared(unsigned N) const {
730730
return Children[N];
731731
}
@@ -812,7 +812,7 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
812812
/// the specified node. For this comparison, all of the state of the node
813813
/// is considered, except for the assigned name. Nodes with differing names
814814
/// that are otherwise identical are considered isomorphic.
815-
bool isIsomorphicTo(const TreePatternNode *N,
815+
bool isIsomorphicTo(const TreePatternNode &N,
816816
const MultipleUseVarSet &DepVars) const;
817817

818818
/// SubstituteFormalArguments - Replace the formal arguments in this tree
@@ -974,7 +974,7 @@ class TreePattern {
974974
private:
975975
TreePatternNodePtr ParseTreePattern(Init *DI, StringRef OpName);
976976
void ComputeNamedNodes();
977-
void ComputeNamedNodes(TreePatternNode *N);
977+
void ComputeNamedNodes(TreePatternNode &N);
978978
};
979979

980980
inline bool TreePatternNode::UpdateNodeType(unsigned ResNo,
@@ -1071,9 +1071,9 @@ class PatternToMatch {
10711071

10721072
Record *getSrcRecord() const { return SrcRecord; }
10731073
ListInit *getPredicates() const { return Predicates; }
1074-
TreePatternNode *getSrcPattern() const { return SrcPattern.get(); }
1074+
TreePatternNode &getSrcPattern() const { return *SrcPattern; }
10751075
TreePatternNodePtr getSrcPatternShared() const { return SrcPattern; }
1076-
TreePatternNode *getDstPattern() const { return DstPattern.get(); }
1076+
TreePatternNode &getDstPattern() const { return *DstPattern; }
10771077
TreePatternNodePtr getDstPatternShared() const { return DstPattern; }
10781078
const std::vector<Record *> &getDstRegs() const { return Dstregs; }
10791079
StringRef getHwModeFeatures() const { return HwModeFeatures; }
@@ -1250,7 +1250,7 @@ class CodeGenDAGPatterns {
12501250
std::vector<Record *> &InstImpResults);
12511251
};
12521252

1253-
inline bool SDNodeInfo::ApplyTypeConstraints(TreePatternNode *N,
1253+
inline bool SDNodeInfo::ApplyTypeConstraints(TreePatternNode &N,
12541254
TreePattern &TP) const {
12551255
bool MadeChange = false;
12561256
for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)

llvm/utils/TableGen/DAGISelEmitter.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,41 @@ class DAGISelEmitter {
3838
// DAGISelEmitter Helper methods
3939
//
4040

41-
/// getResultPatternCost - Compute the number of instructions for this pattern.
41+
/// Compute the number of instructions for this pattern.
4242
/// This is a temporary hack. We should really include the instruction
4343
/// latencies in this calculation.
44-
static unsigned getResultPatternCost(TreePatternNode *P,
45-
CodeGenDAGPatterns &CGP) {
46-
if (P->isLeaf())
44+
static unsigned getResultPatternCost(TreePatternNode &P,
45+
const CodeGenDAGPatterns &CGP) {
46+
if (P.isLeaf())
4747
return 0;
4848

4949
unsigned Cost = 0;
50-
Record *Op = P->getOperator();
50+
Record *Op = P.getOperator();
5151
if (Op->isSubClassOf("Instruction")) {
5252
Cost++;
5353
CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(Op);
5454
if (II.usesCustomInserter)
5555
Cost += 10;
5656
}
57-
for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
58-
Cost += getResultPatternCost(P->getChild(i), CGP);
57+
for (unsigned i = 0, e = P.getNumChildren(); i != e; ++i)
58+
Cost += getResultPatternCost(P.getChild(i), CGP);
5959
return Cost;
6060
}
6161

6262
/// getResultPatternCodeSize - Compute the code size of instructions for this
6363
/// pattern.
64-
static unsigned getResultPatternSize(TreePatternNode *P,
65-
CodeGenDAGPatterns &CGP) {
66-
if (P->isLeaf())
64+
static unsigned getResultPatternSize(TreePatternNode &P,
65+
const CodeGenDAGPatterns &CGP) {
66+
if (P.isLeaf())
6767
return 0;
6868

6969
unsigned Cost = 0;
70-
Record *Op = P->getOperator();
70+
Record *Op = P.getOperator();
7171
if (Op->isSubClassOf("Instruction")) {
7272
Cost += Op->getValueAsInt("CodeSize");
7373
}
74-
for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
75-
Cost += getResultPatternSize(P->getChild(i), CGP);
74+
for (unsigned i = 0, e = P.getNumChildren(); i != e; ++i)
75+
Cost += getResultPatternSize(P.getChild(i), CGP);
7676
return Cost;
7777
}
7878

@@ -85,11 +85,11 @@ struct PatternSortingPredicate {
8585
CodeGenDAGPatterns &CGP;
8686

8787
bool operator()(const PatternToMatch *LHS, const PatternToMatch *RHS) {
88-
const TreePatternNode *LT = LHS->getSrcPattern();
89-
const TreePatternNode *RT = RHS->getSrcPattern();
88+
const TreePatternNode &LT = LHS->getSrcPattern();
89+
const TreePatternNode &RT = RHS->getSrcPattern();
9090

91-
MVT LHSVT = LT->getNumTypes() != 0 ? LT->getSimpleType(0) : MVT::Other;
92-
MVT RHSVT = RT->getNumTypes() != 0 ? RT->getSimpleType(0) : MVT::Other;
91+
MVT LHSVT = LT.getNumTypes() != 0 ? LT.getSimpleType(0) : MVT::Other;
92+
MVT RHSVT = RT.getNumTypes() != 0 ? RT.getSimpleType(0) : MVT::Other;
9393
if (LHSVT.isVector() != RHSVT.isVector())
9494
return RHSVT.isVector();
9595

@@ -156,9 +156,9 @@ void DAGISelEmitter::run(raw_ostream &OS) {
156156
E = CGP.ptm_end();
157157
I != E; ++I) {
158158
errs() << "PATTERN: ";
159-
I->getSrcPattern()->dump();
159+
I->getSrcPattern().dump();
160160
errs() << "\nRESULT: ";
161-
I->getDstPattern()->dump();
161+
I->getDstPattern().dump();
162162
errs() << "\n";
163163
});
164164

llvm/utils/TableGen/DAGISelMatcher.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
302302

303303
void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
304304
OS.indent(indent) << "CompleteMatch <todo args>\n";
305-
OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
306-
OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
305+
OS.indent(indent) << "Src = " << Pattern.getSrcPattern() << "\n";
306+
OS.indent(indent) << "Dst = " << Pattern.getDstPattern() << "\n";
307307
}
308308

309309
bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {

llvm/utils/TableGen/DAGISelMatcherEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ class MatcherTableEmitter {
214214
};
215215
} // end anonymous namespace.
216216

217-
static std::string GetPatFromTreePatternNode(const TreePatternNode *N) {
217+
static std::string GetPatFromTreePatternNode(const TreePatternNode &N) {
218218
std::string str;
219219
raw_string_ostream Stream(str);
220-
Stream << *N;
220+
Stream << N;
221221
return str;
222222
}
223223

@@ -983,11 +983,11 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
983983

984984
if (const MorphNodeToMatcher *SNT = dyn_cast<MorphNodeToMatcher>(N)) {
985985
OS.indent(FullIndexWidth + Indent)
986-
<< "// Src: " << *SNT->getPattern().getSrcPattern()
986+
<< "// Src: " << SNT->getPattern().getSrcPattern()
987987
<< " - Complexity = " << SNT->getPattern().getPatternComplexity(CGP)
988988
<< '\n';
989989
OS.indent(FullIndexWidth + Indent)
990-
<< "// Dst: " << *SNT->getPattern().getDstPattern() << '\n';
990+
<< "// Dst: " << SNT->getPattern().getDstPattern() << '\n';
991991
}
992992
} else
993993
OS << '\n';
@@ -1019,11 +1019,11 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
10191019
OS << '\n';
10201020
if (!OmitComments) {
10211021
OS.indent(FullIndexWidth + Indent)
1022-
<< " // Src: " << *CM->getPattern().getSrcPattern()
1022+
<< " // Src: " << CM->getPattern().getSrcPattern()
10231023
<< " - Complexity = " << CM->getPattern().getPatternComplexity(CGP)
10241024
<< '\n';
10251025
OS.indent(FullIndexWidth + Indent)
1026-
<< " // Dst: " << *CM->getPattern().getDstPattern();
1026+
<< " // Dst: " << CM->getPattern().getDstPattern();
10271027
}
10281028
OS << '\n';
10291029
return 2 + NumResultBytes + NumCoveredBytes;

0 commit comments

Comments
 (0)