Skip to content

[TableGen][NFC] convert TreePatternNode pointers to references #81134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
364 changes: 182 additions & 182 deletions llvm/utils/TableGen/CodeGenDAGPatterns.cpp

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions llvm/utils/TableGen/CodeGenDAGPatterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ struct SDTypeConstraint {
/// constraint to the nodes operands. This returns true if it makes a
/// change, false otherwise. If a type contradiction is found, an error
/// is flagged.
bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
bool ApplyTypeConstraint(TreePatternNode &N, const SDNodeInfo &NodeInfo,
TreePattern &TP) const;
};

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

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

unsigned getNumChildren() const { return Children.size(); }
const TreePatternNode *getChild(unsigned N) const {
return Children[N].get();
const TreePatternNode &getChild(unsigned N) const {
return *Children[N].get();
}
TreePatternNode *getChild(unsigned N) { return Children[N].get(); }
TreePatternNode &getChild(unsigned N) { return *Children[N].get(); }
const TreePatternNodePtr &getChildShared(unsigned N) const {
return Children[N];
}
Expand Down Expand Up @@ -812,7 +812,7 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
/// the specified node. For this comparison, all of the state of the node
/// is considered, except for the assigned name. Nodes with differing names
/// that are otherwise identical are considered isomorphic.
bool isIsomorphicTo(const TreePatternNode *N,
bool isIsomorphicTo(const TreePatternNode &N,
const MultipleUseVarSet &DepVars) const;

/// SubstituteFormalArguments - Replace the formal arguments in this tree
Expand Down Expand Up @@ -974,7 +974,7 @@ class TreePattern {
private:
TreePatternNodePtr ParseTreePattern(Init *DI, StringRef OpName);
void ComputeNamedNodes();
void ComputeNamedNodes(TreePatternNode *N);
void ComputeNamedNodes(TreePatternNode &N);
};

inline bool TreePatternNode::UpdateNodeType(unsigned ResNo,
Expand Down Expand Up @@ -1071,9 +1071,9 @@ class PatternToMatch {

Record *getSrcRecord() const { return SrcRecord; }
ListInit *getPredicates() const { return Predicates; }
TreePatternNode *getSrcPattern() const { return SrcPattern.get(); }
TreePatternNode &getSrcPattern() const { return *SrcPattern; }
TreePatternNodePtr getSrcPatternShared() const { return SrcPattern; }
TreePatternNode *getDstPattern() const { return DstPattern.get(); }
TreePatternNode &getDstPattern() const { return *DstPattern; }
TreePatternNodePtr getDstPatternShared() const { return DstPattern; }
const std::vector<Record *> &getDstRegs() const { return Dstregs; }
StringRef getHwModeFeatures() const { return HwModeFeatures; }
Expand Down Expand Up @@ -1250,7 +1250,7 @@ class CodeGenDAGPatterns {
std::vector<Record *> &InstImpResults);
};

inline bool SDNodeInfo::ApplyTypeConstraints(TreePatternNode *N,
inline bool SDNodeInfo::ApplyTypeConstraints(TreePatternNode &N,
TreePattern &TP) const {
bool MadeChange = false;
for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)
Expand Down
38 changes: 19 additions & 19 deletions llvm/utils/TableGen/DAGISelEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,41 @@ class DAGISelEmitter {
// DAGISelEmitter Helper methods
//

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

unsigned Cost = 0;
Record *Op = P->getOperator();
Record *Op = P.getOperator();
if (Op->isSubClassOf("Instruction")) {
Cost++;
CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(Op);
if (II.usesCustomInserter)
Cost += 10;
}
for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
Cost += getResultPatternCost(P->getChild(i), CGP);
for (unsigned i = 0, e = P.getNumChildren(); i != e; ++i)
Cost += getResultPatternCost(P.getChild(i), CGP);
return Cost;
}

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

unsigned Cost = 0;
Record *Op = P->getOperator();
Record *Op = P.getOperator();
if (Op->isSubClassOf("Instruction")) {
Cost += Op->getValueAsInt("CodeSize");
}
for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
Cost += getResultPatternSize(P->getChild(i), CGP);
for (unsigned i = 0, e = P.getNumChildren(); i != e; ++i)
Cost += getResultPatternSize(P.getChild(i), CGP);
return Cost;
}

Expand All @@ -85,11 +85,11 @@ struct PatternSortingPredicate {
CodeGenDAGPatterns &CGP;

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

MVT LHSVT = LT->getNumTypes() != 0 ? LT->getSimpleType(0) : MVT::Other;
MVT RHSVT = RT->getNumTypes() != 0 ? RT->getSimpleType(0) : MVT::Other;
MVT LHSVT = LT.getNumTypes() != 0 ? LT.getSimpleType(0) : MVT::Other;
MVT RHSVT = RT.getNumTypes() != 0 ? RT.getSimpleType(0) : MVT::Other;
if (LHSVT.isVector() != RHSVT.isVector())
return RHSVT.isVector();

Expand Down Expand Up @@ -156,9 +156,9 @@ void DAGISelEmitter::run(raw_ostream &OS) {
E = CGP.ptm_end();
I != E; ++I) {
errs() << "PATTERN: ";
I->getSrcPattern()->dump();
I->getSrcPattern().dump();
errs() << "\nRESULT: ";
I->getDstPattern()->dump();
I->getDstPattern().dump();
errs() << "\n";
});

Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/DAGISelMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {

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

bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
Expand Down
12 changes: 6 additions & 6 deletions llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ class MatcherTableEmitter {
};
} // end anonymous namespace.

static std::string GetPatFromTreePatternNode(const TreePatternNode *N) {
static std::string GetPatFromTreePatternNode(const TreePatternNode &N) {
std::string str;
raw_string_ostream Stream(str);
Stream << *N;
Stream << N;
return str;
}

Expand Down Expand Up @@ -983,11 +983,11 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,

if (const MorphNodeToMatcher *SNT = dyn_cast<MorphNodeToMatcher>(N)) {
OS.indent(FullIndexWidth + Indent)
<< "// Src: " << *SNT->getPattern().getSrcPattern()
<< "// Src: " << SNT->getPattern().getSrcPattern()
<< " - Complexity = " << SNT->getPattern().getPatternComplexity(CGP)
<< '\n';
OS.indent(FullIndexWidth + Indent)
<< "// Dst: " << *SNT->getPattern().getDstPattern() << '\n';
<< "// Dst: " << SNT->getPattern().getDstPattern() << '\n';
}
} else
OS << '\n';
Expand Down Expand Up @@ -1019,11 +1019,11 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
OS << '\n';
if (!OmitComments) {
OS.indent(FullIndexWidth + Indent)
<< " // Src: " << *CM->getPattern().getSrcPattern()
<< " // Src: " << CM->getPattern().getSrcPattern()
<< " - Complexity = " << CM->getPattern().getPatternComplexity(CGP)
<< '\n';
OS.indent(FullIndexWidth + Indent)
<< " // Dst: " << *CM->getPattern().getDstPattern();
<< " // Dst: " << CM->getPattern().getDstPattern();
}
OS << '\n';
return 2 + NumResultBytes + NumCoveredBytes;
Expand Down
Loading