[llvm] a9e546c - [TableGen][NFC] convert TreePatternNode pointers to references (#81134)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 9 05:35:47 PST 2024
Author: Tomas Matheson
Date: 2024-02-09T13:35:42Z
New Revision: a9e546cc71e72f9febda174ed1ada70c584628c2
URL: https://github.com/llvm/llvm-project/commit/a9e546cc71e72f9febda174ed1ada70c584628c2
DIFF: https://github.com/llvm/llvm-project/commit/a9e546cc71e72f9febda174ed1ada70c584628c2.diff
LOG: [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 (1b465767d6ca69f4b7201503f5f21e6125fe049a)
for `TreePatternNode::getChild()` but that was reverted.
Added:
Modified:
llvm/utils/TableGen/CodeGenDAGPatterns.cpp
llvm/utils/TableGen/CodeGenDAGPatterns.h
llvm/utils/TableGen/DAGISelEmitter.cpp
llvm/utils/TableGen/DAGISelMatcher.cpp
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
llvm/utils/TableGen/DAGISelMatcherGen.cpp
llvm/utils/TableGen/DAGISelMatcherOpt.cpp
llvm/utils/TableGen/FastISelEmitter.cpp
llvm/utils/TableGen/GlobalISelEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index 62e048216e79c..a9046e09a6297 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -1406,10 +1406,10 @@ std::string TreePredicateFn::getCodeToRunOnSDNode() const {
// PatternToMatch implementation
//
-static bool isImmAllOnesAllZerosMatch(const TreePatternNode *P) {
- if (!P->isLeaf())
+static bool isImmAllOnesAllZerosMatch(const TreePatternNode &P) {
+ if (!P.isLeaf())
return false;
- DefInit *DI = dyn_cast<DefInit>(P->getLeafValue());
+ DefInit *DI = dyn_cast<DefInit>(P.getLeafValue());
if (!DI)
return false;
@@ -1420,15 +1420,15 @@ static bool isImmAllOnesAllZerosMatch(const TreePatternNode *P) {
/// getPatternSize - Return the 'size' of this pattern. We want to match large
/// patterns before small ones. This is used to determine the size of a
/// pattern.
-static unsigned getPatternSize(const TreePatternNode *P,
+static unsigned getPatternSize(const TreePatternNode &P,
const CodeGenDAGPatterns &CGP) {
unsigned Size = 3; // The node itself.
// If the root node is a ConstantSDNode, increases its size.
// e.g. (set R32:$dst, 0).
- if (P->isLeaf() && isa<IntInit>(P->getLeafValue()))
+ if (P.isLeaf() && isa<IntInit>(P.getLeafValue()))
Size += 2;
- if (const ComplexPattern *AM = P->getComplexPatternInfo(CGP)) {
+ if (const ComplexPattern *AM = P.getComplexPatternInfo(CGP)) {
Size += AM->getComplexity();
// We don't want to count any children twice, so return early.
return Size;
@@ -1436,14 +1436,14 @@ static unsigned getPatternSize(const TreePatternNode *P,
// If this node has some predicate function that must match, it adds to the
// complexity of this node.
- if (!P->getPredicateCalls().empty())
+ if (!P.getPredicateCalls().empty())
++Size;
// Count children in the count if they are also nodes.
- for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i) {
- const TreePatternNode *Child = P->getChild(i);
- if (!Child->isLeaf() && Child->getNumTypes()) {
- const TypeSetByHwMode &T0 = Child->getExtType(0);
+ for (unsigned i = 0, e = P.getNumChildren(); i != e; ++i) {
+ const TreePatternNode &Child = P.getChild(i);
+ if (!Child.isLeaf() && Child.getNumTypes()) {
+ const TypeSetByHwMode &T0 = Child.getExtType(0);
// At this point, all variable type sets should be simple, i.e. only
// have a default mode.
if (T0.getMachineValueType() != MVT::Other) {
@@ -1451,14 +1451,14 @@ static unsigned getPatternSize(const TreePatternNode *P,
continue;
}
}
- if (Child->isLeaf()) {
- if (isa<IntInit>(Child->getLeafValue()))
+ if (Child.isLeaf()) {
+ if (isa<IntInit>(Child.getLeafValue()))
Size += 5; // Matches a ConstantSDNode (+3) and a specific value (+2).
- else if (Child->getComplexPatternInfo(CGP))
+ else if (Child.getComplexPatternInfo(CGP))
Size += getPatternSize(Child, CGP);
else if (isImmAllOnesAllZerosMatch(Child))
Size += 4; // Matches a build_vector(+3) and a predicate (+1).
- else if (!Child->getPredicateCalls().empty())
+ else if (!Child.getPredicateCalls().empty())
++Size;
}
}
@@ -1582,7 +1582,7 @@ SDTypeConstraint::SDTypeConstraint(Record *R, const CodeGenHwModes &CGH) {
/// getOperandNum - Return the node corresponding to operand #OpNo in tree
/// N, and the result number in ResNo.
-static TreePatternNode *getOperandNum(unsigned OpNo, TreePatternNode *N,
+static TreePatternNode &getOperandNum(unsigned OpNo, TreePatternNode &N,
const SDNodeInfo &NodeInfo,
unsigned &ResNo) {
unsigned NumResults = NodeInfo.getNumResults();
@@ -1593,120 +1593,120 @@ static TreePatternNode *getOperandNum(unsigned OpNo, TreePatternNode *N,
OpNo -= NumResults;
- if (OpNo >= N->getNumChildren()) {
+ if (OpNo >= N.getNumChildren()) {
std::string S;
raw_string_ostream OS(S);
OS << "Invalid operand number in type constraint " << (OpNo + NumResults)
<< " ";
- N->print(OS);
+ N.print(OS);
PrintFatalError(S);
}
- return N->getChild(OpNo);
+ return N.getChild(OpNo);
}
/// ApplyTypeConstraint - Given a node in a pattern, apply this type
/// constraint to the nodes operands. This returns true if it makes a
/// change, false otherwise. If a type contradiction is found, flag an error.
-bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
+bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode &N,
const SDNodeInfo &NodeInfo,
TreePattern &TP) const {
if (TP.hasError())
return false;
unsigned ResNo = 0; // The result number being referenced.
- TreePatternNode *NodeToApply = getOperandNum(OperandNo, N, NodeInfo, ResNo);
+ TreePatternNode &NodeToApply = getOperandNum(OperandNo, N, NodeInfo, ResNo);
TypeInfer &TI = TP.getInfer();
switch (ConstraintType) {
case SDTCisVT:
// Operand must be a particular type.
- return NodeToApply->UpdateNodeType(ResNo, VVT, TP);
+ return NodeToApply.UpdateNodeType(ResNo, VVT, TP);
case SDTCisPtrTy:
// Operand must be same as target pointer type.
- return NodeToApply->UpdateNodeType(ResNo, MVT::iPTR, TP);
+ return NodeToApply.UpdateNodeType(ResNo, MVT::iPTR, TP);
case SDTCisInt:
// Require it to be one of the legal integer VTs.
- return TI.EnforceInteger(NodeToApply->getExtType(ResNo));
+ return TI.EnforceInteger(NodeToApply.getExtType(ResNo));
case SDTCisFP:
// Require it to be one of the legal fp VTs.
- return TI.EnforceFloatingPoint(NodeToApply->getExtType(ResNo));
+ return TI.EnforceFloatingPoint(NodeToApply.getExtType(ResNo));
case SDTCisVec:
// Require it to be one of the legal vector VTs.
- return TI.EnforceVector(NodeToApply->getExtType(ResNo));
+ return TI.EnforceVector(NodeToApply.getExtType(ResNo));
case SDTCisSameAs: {
unsigned OResNo = 0;
- TreePatternNode *OtherNode =
+ TreePatternNode &OtherNode =
getOperandNum(x.SDTCisSameAs_Info.OtherOperandNum, N, NodeInfo, OResNo);
- return (int)NodeToApply->UpdateNodeType(ResNo,
- OtherNode->getExtType(OResNo), TP) |
- (int)OtherNode->UpdateNodeType(OResNo,
- NodeToApply->getExtType(ResNo), TP);
+ return (int)NodeToApply.UpdateNodeType(ResNo, OtherNode.getExtType(OResNo),
+ TP) |
+ (int)OtherNode.UpdateNodeType(OResNo, NodeToApply.getExtType(ResNo),
+ TP);
}
case SDTCisVTSmallerThanOp: {
// The NodeToApply must be a leaf node that is a VT. OtherOperandNum must
// have an integer type that is smaller than the VT.
- if (!NodeToApply->isLeaf() || !isa<DefInit>(NodeToApply->getLeafValue()) ||
- !cast<DefInit>(NodeToApply->getLeafValue())
+ if (!NodeToApply.isLeaf() || !isa<DefInit>(NodeToApply.getLeafValue()) ||
+ !cast<DefInit>(NodeToApply.getLeafValue())
->getDef()
->isSubClassOf("ValueType")) {
- TP.error(N->getOperator()->getName() + " expects a VT operand!");
+ TP.error(N.getOperator()->getName() + " expects a VT operand!");
return false;
}
- DefInit *DI = cast<DefInit>(NodeToApply->getLeafValue());
+ DefInit *DI = cast<DefInit>(NodeToApply.getLeafValue());
const CodeGenTarget &T = TP.getDAGPatterns().getTargetInfo();
auto VVT = getValueTypeByHwMode(DI->getDef(), T.getHwModes());
TypeSetByHwMode TypeListTmp(VVT);
unsigned OResNo = 0;
- TreePatternNode *OtherNode = getOperandNum(
+ TreePatternNode &OtherNode = getOperandNum(
x.SDTCisVTSmallerThanOp_Info.OtherOperandNum, N, NodeInfo, OResNo);
- return TI.EnforceSmallerThan(TypeListTmp, OtherNode->getExtType(OResNo),
+ return TI.EnforceSmallerThan(TypeListTmp, OtherNode.getExtType(OResNo),
/*SmallIsVT*/ true);
}
case SDTCisOpSmallerThanOp: {
unsigned BResNo = 0;
- TreePatternNode *BigOperand = getOperandNum(
+ TreePatternNode &BigOperand = getOperandNum(
x.SDTCisOpSmallerThanOp_Info.BigOperandNum, N, NodeInfo, BResNo);
- return TI.EnforceSmallerThan(NodeToApply->getExtType(ResNo),
- BigOperand->getExtType(BResNo));
+ return TI.EnforceSmallerThan(NodeToApply.getExtType(ResNo),
+ BigOperand.getExtType(BResNo));
}
case SDTCisEltOfVec: {
unsigned VResNo = 0;
- TreePatternNode *VecOperand = getOperandNum(
+ TreePatternNode &VecOperand = getOperandNum(
x.SDTCisEltOfVec_Info.OtherOperandNum, N, NodeInfo, VResNo);
// Filter vector types out of VecOperand that don't have the right element
// type.
- return TI.EnforceVectorEltTypeIs(VecOperand->getExtType(VResNo),
- NodeToApply->getExtType(ResNo));
+ return TI.EnforceVectorEltTypeIs(VecOperand.getExtType(VResNo),
+ NodeToApply.getExtType(ResNo));
}
case SDTCisSubVecOfVec: {
unsigned VResNo = 0;
- TreePatternNode *BigVecOperand = getOperandNum(
+ TreePatternNode &BigVecOperand = getOperandNum(
x.SDTCisSubVecOfVec_Info.OtherOperandNum, N, NodeInfo, VResNo);
// Filter vector types out of BigVecOperand that don't have the
// right subvector type.
- return TI.EnforceVectorSubVectorTypeIs(BigVecOperand->getExtType(VResNo),
- NodeToApply->getExtType(ResNo));
+ return TI.EnforceVectorSubVectorTypeIs(BigVecOperand.getExtType(VResNo),
+ NodeToApply.getExtType(ResNo));
}
case SDTCVecEltisVT: {
- return TI.EnforceVectorEltTypeIs(NodeToApply->getExtType(ResNo), VVT);
+ return TI.EnforceVectorEltTypeIs(NodeToApply.getExtType(ResNo), VVT);
}
case SDTCisSameNumEltsAs: {
unsigned OResNo = 0;
- TreePatternNode *OtherNode = getOperandNum(
+ TreePatternNode &OtherNode = getOperandNum(
x.SDTCisSameNumEltsAs_Info.OtherOperandNum, N, NodeInfo, OResNo);
- return TI.EnforceSameNumElts(OtherNode->getExtType(OResNo),
- NodeToApply->getExtType(ResNo));
+ return TI.EnforceSameNumElts(OtherNode.getExtType(OResNo),
+ NodeToApply.getExtType(ResNo));
}
case SDTCisSameSizeAs: {
unsigned OResNo = 0;
- TreePatternNode *OtherNode = getOperandNum(
+ TreePatternNode &OtherNode = getOperandNum(
x.SDTCisSameSizeAs_Info.OtherOperandNum, N, NodeInfo, OResNo);
- return TI.EnforceSameSize(OtherNode->getExtType(OResNo),
- NodeToApply->getExtType(ResNo));
+ return TI.EnforceSameSize(OtherNode.getExtType(OResNo),
+ NodeToApply.getExtType(ResNo));
}
}
llvm_unreachable("Invalid ConstraintType!");
@@ -1751,7 +1751,7 @@ bool TreePatternNode::ContainsUnresolvedType(TreePattern &TP) const {
if (!TP.getInfer().isConcrete(Types[i], true))
return true;
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
- if (getChild(i)->ContainsUnresolvedType(TP))
+ if (getChild(i).ContainsUnresolvedType(TP))
return true;
return false;
}
@@ -1929,7 +1929,7 @@ void TreePatternNode::print(raw_ostream &OS) const {
ListSeparator LS;
for (unsigned i = 0, e = getNumChildren(); i != e; ++i) {
OS << LS;
- getChild(i)->print(OS);
+ getChild(i).print(OS);
}
}
OS << ")";
@@ -1958,37 +1958,37 @@ void TreePatternNode::dump() const { print(errs()); }
/// the assigned name is present in the dependent variable set, then
/// the assigned name is considered significant and the node is
/// isomorphic if the names match.
-bool TreePatternNode::isIsomorphicTo(const TreePatternNode *N,
+bool TreePatternNode::isIsomorphicTo(const TreePatternNode &N,
const MultipleUseVarSet &DepVars) const {
- if (N == this)
+ if (&N == this)
return true;
- if (N->isLeaf() != isLeaf())
+ if (N.isLeaf() != isLeaf())
return false;
// Check operator of non-leaves early since it can be cheaper than checking
// types.
if (!isLeaf())
- if (N->getOperator() != getOperator() ||
- N->getNumChildren() != getNumChildren())
+ if (N.getOperator() != getOperator() ||
+ N.getNumChildren() != getNumChildren())
return false;
- if (getExtTypes() != N->getExtTypes() ||
- getPredicateCalls() != N->getPredicateCalls() ||
- getTransformFn() != N->getTransformFn())
+ if (getExtTypes() != N.getExtTypes() ||
+ getPredicateCalls() != N.getPredicateCalls() ||
+ getTransformFn() != N.getTransformFn())
return false;
if (isLeaf()) {
if (DefInit *DI = dyn_cast<DefInit>(getLeafValue())) {
- if (DefInit *NDI = dyn_cast<DefInit>(N->getLeafValue())) {
+ if (DefInit *NDI = dyn_cast<DefInit>(N.getLeafValue())) {
return ((DI->getDef() == NDI->getDef()) &&
- (!DepVars.contains(getName()) || getName() == N->getName()));
+ (!DepVars.contains(getName()) || getName() == N.getName()));
}
}
- return getLeafValue() == N->getLeafValue();
+ return getLeafValue() == N.getLeafValue();
}
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
- if (!getChild(i)->isIsomorphicTo(N->getChild(i), DepVars))
+ if (!getChild(i).isIsomorphicTo(N.getChild(i), DepVars))
return false;
return true;
}
@@ -2003,7 +2003,7 @@ TreePatternNodePtr TreePatternNode::clone() const {
std::vector<TreePatternNodePtr> CChildren;
CChildren.reserve(Children.size());
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
- CChildren.push_back(getChild(i)->clone());
+ CChildren.push_back(getChild(i).clone());
New = makeIntrusiveRefCnt<TreePatternNode>(
getOperator(), std::move(CChildren), getNumTypes());
}
@@ -2023,7 +2023,7 @@ void TreePatternNode::RemoveAllTypes() {
if (isLeaf())
return;
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
- getChild(i)->RemoveAllTypes();
+ getChild(i).RemoveAllTypes();
}
/// SubstituteFormalArguments - Replace the formal arguments in this tree
@@ -2034,24 +2034,24 @@ void TreePatternNode::SubstituteFormalArguments(
return;
for (unsigned i = 0, e = getNumChildren(); i != e; ++i) {
- TreePatternNode *Child = getChild(i);
- if (Child->isLeaf()) {
- Init *Val = Child->getLeafValue();
+ TreePatternNode &Child = getChild(i);
+ if (Child.isLeaf()) {
+ Init *Val = Child.getLeafValue();
// Note that, when substituting into an output pattern, Val might be an
// UnsetInit.
if (isa<UnsetInit>(Val) ||
(isa<DefInit>(Val) &&
cast<DefInit>(Val)->getDef()->getName() == "node")) {
// We found a use of a formal argument, replace it with its value.
- TreePatternNodePtr NewChild = ArgMap[Child->getName()];
+ TreePatternNodePtr NewChild = ArgMap[Child.getName()];
assert(NewChild && "Couldn't find formal argument!");
- assert((Child->getPredicateCalls().empty() ||
- NewChild->getPredicateCalls() == Child->getPredicateCalls()) &&
+ assert((Child.getPredicateCalls().empty() ||
+ NewChild->getPredicateCalls() == Child.getPredicateCalls()) &&
"Non-empty child predicate clobbered!");
setChild(i, std::move(NewChild));
}
} else {
- getChild(i)->SubstituteFormalArguments(ArgMap);
+ getChild(i).SubstituteFormalArguments(ArgMap);
}
}
}
@@ -2325,7 +2325,7 @@ TreePatternNode::getIntrinsicInfo(const CodeGenDAGPatterns &CDP) const {
getOperator() != CDP.get_intrinsic_wo_chain_sdnode())
return nullptr;
- unsigned IID = cast<IntInit>(getChild(0)->getLeafValue())->getValue();
+ unsigned IID = cast<IntInit>(getChild(0).getLeafValue())->getValue();
return &CDP.getIntrinsicInfo(IID);
}
@@ -2397,7 +2397,7 @@ bool TreePatternNode::TreeHasProperty(SDNP Property,
if (NodeHasProperty(Property, CGP))
return true;
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
- if (getChild(i)->TreeHasProperty(Property, CGP))
+ if (getChild(i).TreeHasProperty(Property, CGP))
return true;
return false;
}
@@ -2411,11 +2411,11 @@ bool TreePatternNode::isCommutativeIntrinsic(
return false;
}
-static bool isOperandClass(const TreePatternNode *N, StringRef Class) {
- if (!N->isLeaf())
- return N->getOperator()->isSubClassOf(Class);
+static bool isOperandClass(const TreePatternNode &N, StringRef Class) {
+ if (!N.isLeaf())
+ return N.getOperator()->isSubClassOf(Class);
- DefInit *DI = dyn_cast<DefInit>(N->getLeafValue());
+ DefInit *DI = dyn_cast<DefInit>(N.getLeafValue());
if (DI && DI->getDef()->isSubClassOf(Class))
return true;
@@ -2506,15 +2506,15 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
}
// Apply type info to the intrinsic ID.
- MadeChange |= getChild(0)->UpdateNodeType(0, MVT::iPTR, TP);
+ MadeChange |= getChild(0).UpdateNodeType(0, MVT::iPTR, TP);
for (unsigned i = 0, e = getNumChildren() - 1; i != e; ++i) {
- MadeChange |= getChild(i + 1)->ApplyTypeConstraints(TP, NotRegisters);
+ MadeChange |= getChild(i + 1).ApplyTypeConstraints(TP, NotRegisters);
MVT::SimpleValueType OpVT =
getValueType(Int->IS.ParamTys[i]->getValueAsDef("VT"));
- assert(getChild(i + 1)->getNumTypes() == 1 && "Unhandled case");
- MadeChange |= getChild(i + 1)->UpdateNodeType(0, OpVT, TP);
+ assert(getChild(i + 1).getNumTypes() == 1 && "Unhandled case");
+ MadeChange |= getChild(i + 1).UpdateNodeType(0, OpVT, TP);
}
return MadeChange;
}
@@ -2532,8 +2532,8 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
bool MadeChange = false;
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
- MadeChange |= getChild(i)->ApplyTypeConstraints(TP, NotRegisters);
- MadeChange |= NI.ApplyTypeConstraints(this, TP);
+ MadeChange |= getChild(i).ApplyTypeConstraints(TP, NotRegisters);
+ MadeChange |= NI.ApplyTypeConstraints(*this, TP);
return MadeChange;
}
@@ -2568,9 +2568,9 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
// If this is an INSERT_SUBREG, constrain the source and destination VTs to
// be the same.
if (getOperator()->getName() == "INSERT_SUBREG") {
- assert(getChild(0)->getNumTypes() == 1 && "FIXME: Unhandled");
- MadeChange |= UpdateNodeType(0, getChild(0)->getExtType(0), TP);
- MadeChange |= getChild(0)->UpdateNodeType(0, getExtType(0), TP);
+ assert(getChild(0).getNumTypes() == 1 && "FIXME: Unhandled");
+ MadeChange |= UpdateNodeType(0, getChild(0).getExtType(0), TP);
+ MadeChange |= getChild(0).UpdateNodeType(0, getExtType(0), TP);
} else if (getOperator()->getName() == "REG_SEQUENCE") {
// We need to do extra, custom typechecking for REG_SEQUENCE since it is
// variadic.
@@ -2592,7 +2592,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
}
for (unsigned I = 1; I < NChild; I += 2) {
- TreePatternNode *SubIdxChild = getChild(I + 1);
+ TreePatternNode &SubIdxChild = getChild(I + 1);
if (!isOperandClass(SubIdxChild, "SubRegIndex")) {
TP.error("REG_SEQUENCE requires a SubRegIndex for operand " +
Twine(I + 1) + "!");
@@ -2637,7 +2637,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
return false;
}
- TreePatternNode *Child = getChild(ChildNo++);
+ TreePatternNode *Child = &getChild(ChildNo++);
unsigned ChildResNo = 0; // Instructions always use res #0 of their op.
// If the operand has sub-operands, they may be provided by distinct
@@ -2660,7 +2660,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
getNumChildren());
return false;
}
- Child = getChild(ChildNo++);
+ Child = &getChild(ChildNo++);
SubRec = cast<DefInit>(MIOpInfo->getArg(Arg))->getDef();
MadeChange |=
@@ -2683,7 +2683,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
}
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
- MadeChange |= getChild(i)->ApplyTypeConstraints(TP, NotRegisters);
+ MadeChange |= getChild(i).ApplyTypeConstraints(TP, NotRegisters);
return MadeChange;
}
@@ -2707,7 +2707,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
}
for (unsigned i = 0; i < getNumChildren(); ++i)
- MadeChange |= getChild(i)->ApplyTypeConstraints(TP, NotRegisters);
+ MadeChange |= getChild(i).ApplyTypeConstraints(TP, NotRegisters);
return MadeChange;
}
@@ -2721,16 +2721,16 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
return false;
}
- bool MadeChange = getChild(0)->ApplyTypeConstraints(TP, NotRegisters);
+ bool MadeChange = getChild(0).ApplyTypeConstraints(TP, NotRegisters);
return MadeChange;
}
/// OnlyOnRHSOfCommutative - Return true if this value is only allowed on the
/// RHS of a commutative operation, not the on LHS.
-static bool OnlyOnRHSOfCommutative(TreePatternNode *N) {
- if (!N->isLeaf() && N->getOperator()->getName() == "imm")
+static bool OnlyOnRHSOfCommutative(TreePatternNode &N) {
+ if (!N.isLeaf() && N.getOperator()->getName() == "imm")
return true;
- if (N->isLeaf() && isa<IntInit>(N->getLeafValue()))
+ if (N.isLeaf() && isa<IntInit>(N.getLeafValue()))
return true;
if (isImmAllOnesAllZerosMatch(N))
return true;
@@ -2748,7 +2748,7 @@ bool TreePatternNode::canPatternMatch(std::string &Reason,
return true;
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
- if (!getChild(i)->canPatternMatch(Reason, CDP))
+ if (!getChild(i).canPatternMatch(Reason, CDP))
return false;
// If this is an intrinsic, handle cases that would make it not match. For
@@ -2818,15 +2818,15 @@ void TreePattern::error(const Twine &Msg) {
void TreePattern::ComputeNamedNodes() {
for (TreePatternNodePtr &Tree : Trees)
- ComputeNamedNodes(Tree.get());
+ ComputeNamedNodes(*Tree);
}
-void TreePattern::ComputeNamedNodes(TreePatternNode *N) {
- if (!N->getName().empty())
- NamedNodes[N->getName()].push_back(N);
+void TreePattern::ComputeNamedNodes(TreePatternNode &N) {
+ if (!N.getName().empty())
+ NamedNodes[N.getName()].push_back(&N);
- for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
- ComputeNamedNodes(N->getChild(i));
+ for (unsigned i = 0, e = N.getNumChildren(); i != e; ++i)
+ ComputeNamedNodes(N.getChild(i));
}
TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
@@ -3031,7 +3031,7 @@ static bool SimplifyTree(TreePatternNodePtr &N) {
if (N->getOperator()->getName() == "bitconvert" &&
N->getExtType(0).isValueTypeByHwMode(false) &&
!N->getExtType(0).empty() &&
- N->getExtType(0) == N->getChild(0)->getExtType(0) &&
+ N->getExtType(0) == N->getChild(0).getExtType(0) &&
N->getName().empty()) {
N = N->getChildShared(0);
SimplifyTree(N);
@@ -3451,11 +3451,11 @@ void CodeGenDAGPatterns::FindPatternInputsAndOutputs(
if (Pat->getOperator()->getName() == "implicit") {
for (unsigned i = 0, e = Pat->getNumChildren(); i != e; ++i) {
- TreePatternNode *Dest = Pat->getChild(i);
- if (!Dest->isLeaf())
+ TreePatternNode &Dest = Pat->getChild(i);
+ if (!Dest.isLeaf())
I.error("implicitly defined value should be a register!");
- DefInit *Val = dyn_cast<DefInit>(Dest->getLeafValue());
+ DefInit *Val = dyn_cast<DefInit>(Dest.getLeafValue());
if (!Val || !Val->getDef()->isSubClassOf("Register"))
I.error("implicitly defined value should be a register!");
if (Val)
@@ -3468,7 +3468,7 @@ void CodeGenDAGPatterns::FindPatternInputsAndOutputs(
// If this is not a set, verify that the children nodes are not void typed,
// and recurse.
for (unsigned i = 0, e = Pat->getNumChildren(); i != e; ++i) {
- if (Pat->getChild(i)->getNumTypes() == 0)
+ if (Pat->getChild(i).getNumTypes() == 0)
I.error("Cannot have void nodes inside of patterns!");
FindPatternInputsAndOutputs(I, Pat->getChildShared(i), InstInputs,
InstResults, InstImpResults);
@@ -3550,35 +3550,35 @@ class InstAnalyzer {
isBitcast(false), isVariadic(false), hasChain(false) {}
void Analyze(const PatternToMatch &Pat) {
- const TreePatternNode *N = Pat.getSrcPattern();
+ const TreePatternNode &N = Pat.getSrcPattern();
AnalyzeNode(N);
// These properties are detected only on the root node.
isBitcast = IsNodeBitcast(N);
}
private:
- bool IsNodeBitcast(const TreePatternNode *N) const {
+ bool IsNodeBitcast(const TreePatternNode &N) const {
if (hasSideEffects || mayLoad || mayStore || isVariadic)
return false;
- if (N->isLeaf())
+ if (N.isLeaf())
return false;
- if (N->getNumChildren() != 1 || !N->getChild(0)->isLeaf())
+ if (N.getNumChildren() != 1 || !N.getChild(0).isLeaf())
return false;
- if (N->getOperator()->isSubClassOf("ComplexPattern"))
+ if (N.getOperator()->isSubClassOf("ComplexPattern"))
return false;
- const SDNodeInfo &OpInfo = CDP.getSDNodeInfo(N->getOperator());
+ const SDNodeInfo &OpInfo = CDP.getSDNodeInfo(N.getOperator());
if (OpInfo.getNumResults() != 1 || OpInfo.getNumOperands() != 1)
return false;
return OpInfo.getEnumName() == "ISD::BITCAST";
}
public:
- void AnalyzeNode(const TreePatternNode *N) {
- if (N->isLeaf()) {
- if (DefInit *DI = dyn_cast<DefInit>(N->getLeafValue())) {
+ void AnalyzeNode(const TreePatternNode &N) {
+ if (N.isLeaf()) {
+ if (DefInit *DI = dyn_cast<DefInit>(N.getLeafValue())) {
Record *LeafRec = DI->getDef();
// Handle ComplexPattern leaves.
if (LeafRec->isSubClassOf("ComplexPattern")) {
@@ -3595,22 +3595,22 @@ class InstAnalyzer {
}
// Analyze children.
- for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
- AnalyzeNode(N->getChild(i));
+ for (unsigned i = 0, e = N.getNumChildren(); i != e; ++i)
+ AnalyzeNode(N.getChild(i));
// Notice properties of the node.
- if (N->NodeHasProperty(SDNPMayStore, CDP))
+ if (N.NodeHasProperty(SDNPMayStore, CDP))
mayStore = true;
- if (N->NodeHasProperty(SDNPMayLoad, CDP))
+ if (N.NodeHasProperty(SDNPMayLoad, CDP))
mayLoad = true;
- if (N->NodeHasProperty(SDNPSideEffect, CDP))
+ if (N.NodeHasProperty(SDNPSideEffect, CDP))
hasSideEffects = true;
- if (N->NodeHasProperty(SDNPVariadic, CDP))
+ if (N.NodeHasProperty(SDNPVariadic, CDP))
isVariadic = true;
- if (N->NodeHasProperty(SDNPHasChain, CDP))
+ if (N.NodeHasProperty(SDNPHasChain, CDP))
hasChain = true;
- if (const CodeGenIntrinsic *IntInfo = N->getIntrinsicInfo(CDP)) {
+ if (const CodeGenIntrinsic *IntInfo = N.getIntrinsicInfo(CDP)) {
ModRefInfo MR = IntInfo->ME.getModRef();
// If this is an intrinsic, analyze it.
if (isRefSet(MR))
@@ -3723,14 +3723,14 @@ static bool hasNullFragReference(ListInit *LI) {
}
/// Get all the instructions in a tree.
-static void getInstructionsInTree(TreePatternNode *Tree,
+static void getInstructionsInTree(TreePatternNode &Tree,
SmallVectorImpl<Record *> &Instrs) {
- if (Tree->isLeaf())
+ if (Tree.isLeaf())
return;
- if (Tree->getOperator()->isSubClassOf("Instruction"))
- Instrs.push_back(Tree->getOperator());
- for (unsigned i = 0, e = Tree->getNumChildren(); i != e; ++i)
- getInstructionsInTree(Tree->getChild(i), Instrs);
+ if (Tree.getOperator()->isSubClassOf("Instruction"))
+ Instrs.push_back(Tree.getOperator());
+ for (unsigned i = 0, e = Tree.getNumChildren(); i != e; ++i)
+ getInstructionsInTree(Tree.getChild(i), Instrs);
}
/// Check the class of a pattern leaf node against the instruction operand it
@@ -3917,7 +3917,7 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
TreePatternNodePtr Pattern = I.getTree(0);
TreePatternNodePtr SrcPattern;
if (Pattern->getOperator()->getName() == "set") {
- SrcPattern = Pattern->getChild(Pattern->getNumChildren() - 1)->clone();
+ SrcPattern = Pattern->getChild(Pattern->getNumChildren() - 1).clone();
} else {
// Not a set (store or something?)
SrcPattern = Pattern;
@@ -3995,22 +3995,22 @@ void CodeGenDAGPatterns::ParseInstructions() {
typedef std::pair<TreePatternNode *, unsigned> NameRecord;
-static void FindNames(TreePatternNode *P,
+static void FindNames(TreePatternNode &P,
std::map<std::string, NameRecord> &Names,
TreePattern *PatternTop) {
- if (!P->getName().empty()) {
- NameRecord &Rec = Names[P->getName()];
+ if (!P.getName().empty()) {
+ NameRecord &Rec = Names[P.getName()];
// If this is the first instance of the name, remember the node.
if (Rec.second++ == 0)
- Rec.first = P;
- else if (Rec.first->getExtTypes() != P->getExtTypes())
- PatternTop->error("repetition of value: $" + P->getName() +
+ Rec.first = &P;
+ else if (Rec.first->getExtTypes() != P.getExtTypes())
+ PatternTop->error("repetition of value: $" + P.getName() +
" where
diff erent uses have
diff erent types!");
}
- if (!P->isLeaf()) {
- for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
- FindNames(P->getChild(i), Names, PatternTop);
+ if (!P.isLeaf()) {
+ for (unsigned i = 0, e = P.getNumChildren(); i != e; ++i)
+ FindNames(P.getChild(i), Names, PatternTop);
}
}
@@ -4018,7 +4018,7 @@ void CodeGenDAGPatterns::AddPatternToMatch(TreePattern *Pattern,
PatternToMatch &&PTM) {
// Do some sanity checking on the pattern we're about to match.
std::string Reason;
- if (!PTM.getSrcPattern()->canPatternMatch(Reason, *this)) {
+ if (!PTM.getSrcPattern().canPatternMatch(Reason, *this)) {
PrintWarning(Pattern->getRecord()->getLoc(),
Twine("Pattern can never match: ") + Reason);
return;
@@ -4027,7 +4027,7 @@ void CodeGenDAGPatterns::AddPatternToMatch(TreePattern *Pattern,
// If the source pattern's root is a complex pattern, that complex pattern
// must specify the nodes it can potentially match.
if (const ComplexPattern *CP =
- PTM.getSrcPattern()->getComplexPatternInfo(*this))
+ PTM.getSrcPattern().getComplexPatternInfo(*this))
if (CP->getRootNodes().empty())
Pattern->error("ComplexPattern at root must specify list of opcodes it"
" could match");
@@ -4189,27 +4189,27 @@ void CodeGenDAGPatterns::VerifyInstructionFlags() {
/// Given a pattern result with an unresolved type, see if we can find one
/// instruction with an unresolved result type. Force this result type to an
/// arbitrary element if it's possible types to converge results.
-static bool ForceArbitraryInstResultType(TreePatternNode *N, TreePattern &TP) {
- if (N->isLeaf())
+static bool ForceArbitraryInstResultType(TreePatternNode &N, TreePattern &TP) {
+ if (N.isLeaf())
return false;
// Analyze children.
- for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
- if (ForceArbitraryInstResultType(N->getChild(i), TP))
+ for (unsigned i = 0, e = N.getNumChildren(); i != e; ++i)
+ if (ForceArbitraryInstResultType(N.getChild(i), TP))
return true;
- if (!N->getOperator()->isSubClassOf("Instruction"))
+ if (!N.getOperator()->isSubClassOf("Instruction"))
return false;
// If this type is already concrete or completely unknown we can't do
// anything.
TypeInfer &TI = TP.getInfer();
- for (unsigned i = 0, e = N->getNumTypes(); i != e; ++i) {
- if (N->getExtType(i).empty() || TI.isConcrete(N->getExtType(i), false))
+ for (unsigned i = 0, e = N.getNumTypes(); i != e; ++i) {
+ if (N.getExtType(i).empty() || TI.isConcrete(N.getExtType(i), false))
continue;
// Otherwise, force its type to an arbitrary choice.
- if (TI.forceArbitrary(N->getExtType(i)))
+ if (TI.forceArbitrary(N.getExtType(i)))
return true;
}
@@ -4285,7 +4285,7 @@ void CodeGenDAGPatterns::ParseOnePattern(
// arbitrary types to the result pattern's nodes.
if (!IterateInference && InferredAllPatternTypes && !InferredAllResultTypes)
IterateInference =
- ForceArbitraryInstResultType(Result.getTree(0).get(), Result);
+ ForceArbitraryInstResultType(*Result.getTree(0), Result);
} while (IterateInference);
// Verify that we inferred enough types that we can do something with the
@@ -4372,13 +4372,13 @@ void CodeGenDAGPatterns::ParsePatterns() {
}
}
-static void collectModes(std::set<unsigned> &Modes, const TreePatternNode *N) {
- for (const TypeSetByHwMode &VTS : N->getExtTypes())
+static void collectModes(std::set<unsigned> &Modes, const TreePatternNode &N) {
+ for (const TypeSetByHwMode &VTS : N.getExtTypes())
for (const auto &I : VTS)
Modes.insert(I.first);
- for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
- collectModes(Modes, N->getChild(i));
+ for (unsigned i = 0, e = N.getNumChildren(); i != e; ++i)
+ collectModes(Modes, N.getChild(i));
}
void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
@@ -4391,8 +4391,8 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
auto AppendPattern = [this](PatternToMatch &P, unsigned Mode,
StringRef Check) {
- TreePatternNodePtr NewSrc = P.getSrcPattern()->clone();
- TreePatternNodePtr NewDst = P.getDstPattern()->clone();
+ TreePatternNodePtr NewSrc = P.getSrcPattern().clone();
+ TreePatternNodePtr NewDst = P.getDstPattern().clone();
if (!NewSrc->setDefaultMode(Mode) || !NewDst->setDefaultMode(Mode)) {
return;
}
@@ -4405,10 +4405,10 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
for (PatternToMatch &P : Copy) {
const TreePatternNode *SrcP = nullptr, *DstP = nullptr;
- if (P.getSrcPattern()->hasProperTypeByHwMode())
- SrcP = P.getSrcPattern();
- if (P.getDstPattern()->hasProperTypeByHwMode())
- DstP = P.getDstPattern();
+ if (P.getSrcPattern().hasProperTypeByHwMode())
+ SrcP = &P.getSrcPattern();
+ if (P.getDstPattern().hasProperTypeByHwMode())
+ DstP = &P.getDstPattern();
if (!SrcP && !DstP) {
PatternsToMatch.push_back(P);
continue;
@@ -4416,9 +4416,9 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
std::set<unsigned> Modes;
if (SrcP)
- collectModes(Modes, SrcP);
+ collectModes(Modes, *SrcP);
if (DstP)
- collectModes(Modes, DstP);
+ collectModes(Modes, *DstP);
// The predicate for the default mode needs to be constructed for each
// pattern separately.
@@ -4458,18 +4458,18 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
/// Dependent variable map for CodeGenDAGPattern variant generation
typedef StringMap<int> DepVarMap;
-static void FindDepVarsOf(TreePatternNode *N, DepVarMap &DepMap) {
- if (N->isLeaf()) {
- if (N->hasName() && isa<DefInit>(N->getLeafValue()))
- DepMap[N->getName()]++;
+static void FindDepVarsOf(TreePatternNode &N, DepVarMap &DepMap) {
+ if (N.isLeaf()) {
+ if (N.hasName() && isa<DefInit>(N.getLeafValue()))
+ DepMap[N.getName()]++;
} else {
- for (size_t i = 0, e = N->getNumChildren(); i != e; ++i)
- FindDepVarsOf(N->getChild(i), DepMap);
+ for (size_t i = 0, e = N.getNumChildren(); i != e; ++i)
+ FindDepVarsOf(N.getChild(i), DepMap);
}
}
/// Find dependent variables within child patterns
-static void FindDepVars(TreePatternNode *N, MultipleUseVarSet &DepVars) {
+static void FindDepVars(TreePatternNode &N, MultipleUseVarSet &DepVars) {
DepVarMap depcounts;
FindDepVarsOf(N, depcounts);
for (const auto &Pair : depcounts) {
@@ -4543,7 +4543,7 @@ static void CombineChildVariants(
// which are the same pattern. Ignore the dups.
if (R->canPatternMatch(ErrString, CDP) &&
none_of(OutVariants, [&](TreePatternNodePtr Variant) {
- return R->isIsomorphicTo(Variant.get(), DepVars);
+ return R->isIsomorphicTo(*Variant, DepVars);
}))
OutVariants.push_back(R);
@@ -4589,12 +4589,12 @@ GatherChildrenOfAssociativeOpcode(TreePatternNodePtr N,
return;
}
- if (N->getChild(0)->isLeaf() || N->getChild(0)->getOperator() != Operator)
+ if (N->getChild(0).isLeaf() || N->getChild(0).getOperator() != Operator)
Children.push_back(N->getChildShared(0));
else
GatherChildrenOfAssociativeOpcode(N->getChildShared(0), Children);
- if (N->getChild(1)->isLeaf() || N->getChild(1)->getOperator() != Operator)
+ if (N->getChild(1).isLeaf() || N->getChild(1).getOperator() != Operator)
Children.push_back(N->getChildShared(1));
else
GatherChildrenOfAssociativeOpcode(N->getChildShared(1), Children);
@@ -4688,9 +4688,9 @@ static void GenerateVariantsOf(TreePatternNodePtr N,
unsigned i = 0 + Skip;
unsigned e = 2 + Skip;
for (; i != e; ++i) {
- TreePatternNode *Child = N->getChild(i);
- if (Child->isLeaf())
- if (DefInit *DI = dyn_cast<DefInit>(Child->getLeafValue())) {
+ TreePatternNode &Child = N->getChild(i);
+ if (Child.isLeaf())
+ if (DefInit *DI = dyn_cast<DefInit>(Child.getLeafValue())) {
Record *RR = DI->getDef();
if (RR->isSubClassOf("Register"))
NoRegisters = false;
@@ -4738,7 +4738,7 @@ void CodeGenDAGPatterns::GenerateVariants() {
continue;
LLVM_DEBUG(errs() << "FOUND VARIANTS OF: ";
- PatternsToMatch[i].getSrcPattern()->dump(); errs() << "\n");
+ PatternsToMatch[i].getSrcPattern().dump(); errs() << "\n");
for (unsigned v = 0, e = Variants.size(); v != e; ++v) {
TreePatternNodePtr Variant = Variants[v];
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.h b/llvm/utils/TableGen/CodeGenDAGPatterns.h
index ea6219c56edfe..823c40c922cbe 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.h
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.h
@@ -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;
};
@@ -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
@@ -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];
}
@@ -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
diff ering 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
@@ -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,
@@ -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; }
@@ -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)
diff --git a/llvm/utils/TableGen/DAGISelEmitter.cpp b/llvm/utils/TableGen/DAGISelEmitter.cpp
index 32b274607a27f..336cee09b90c3 100644
--- a/llvm/utils/TableGen/DAGISelEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelEmitter.cpp
@@ -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;
}
@@ -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 < = 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();
@@ -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";
});
diff --git a/llvm/utils/TableGen/DAGISelMatcher.cpp b/llvm/utils/TableGen/DAGISelMatcher.cpp
index 54614811db977..3298965ab41d7 100644
--- a/llvm/utils/TableGen/DAGISelMatcher.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcher.cpp
@@ -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 {
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index 8d002e5a649d9..b475c98d30a6e 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -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;
}
@@ -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';
@@ -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;
diff --git a/llvm/utils/TableGen/DAGISelMatcherGen.cpp b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
index 8ca7aaef1d31c..956cb5e4a65aa 100644
--- a/llvm/utils/TableGen/DAGISelMatcherGen.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
@@ -113,10 +113,10 @@ class MatcherGen {
void InferPossibleTypes();
// Matcher Generation.
- void EmitMatchCode(const TreePatternNode *N, TreePatternNode *NodeNoTypes);
- void EmitLeafMatchCode(const TreePatternNode *N);
- void EmitOperatorMatchCode(const TreePatternNode *N,
- TreePatternNode *NodeNoTypes);
+ void EmitMatchCode(const TreePatternNode &N, TreePatternNode &NodeNoTypes);
+ void EmitLeafMatchCode(const TreePatternNode &N);
+ void EmitOperatorMatchCode(const TreePatternNode &N,
+ TreePatternNode &NodeNoTypes);
/// If this is the first time a node with unique identifier Name has been
/// seen, record it. Otherwise, emit a check to make sure this is the same
@@ -131,15 +131,15 @@ class MatcherGen {
return VarMapEntry - 1;
}
- void EmitResultOperand(const TreePatternNode *N,
+ void EmitResultOperand(const TreePatternNode &N,
SmallVectorImpl<unsigned> &ResultOps);
- void EmitResultOfNamedOperand(const TreePatternNode *N,
+ void EmitResultOfNamedOperand(const TreePatternNode &N,
SmallVectorImpl<unsigned> &ResultOps);
- void EmitResultLeafAsOperand(const TreePatternNode *N,
+ void EmitResultLeafAsOperand(const TreePatternNode &N,
SmallVectorImpl<unsigned> &ResultOps);
- void EmitResultInstructionAsOperand(const TreePatternNode *N,
+ void EmitResultInstructionAsOperand(const TreePatternNode &N,
SmallVectorImpl<unsigned> &ResultOps);
- void EmitResultSDNodeXFormAsOperand(const TreePatternNode *N,
+ void EmitResultSDNodeXFormAsOperand(const TreePatternNode &N,
SmallVectorImpl<unsigned> &ResultOps);
};
@@ -162,7 +162,7 @@ MatcherGen::MatcherGen(const PatternToMatch &pattern,
// apply the type to the tree, then rerun type inference. Iterate until all
// types are resolved.
//
- PatWithNoTypes = Pattern.getSrcPattern()->clone();
+ PatWithNoTypes = Pattern.getSrcPattern().clone();
PatWithNoTypes->RemoveAllTypes();
// If there are types that are manifestly known, infer them.
@@ -198,15 +198,15 @@ void MatcherGen::AddMatcher(Matcher *NewNode) {
//===----------------------------------------------------------------------===//
/// EmitLeafMatchCode - Generate matching code for leaf nodes.
-void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
- assert(N->isLeaf() && "Not a leaf?");
+void MatcherGen::EmitLeafMatchCode(const TreePatternNode &N) {
+ assert(N.isLeaf() && "Not a leaf?");
// Direct match against an integer constant.
- if (IntInit *II = dyn_cast<IntInit>(N->getLeafValue())) {
+ if (IntInit *II = dyn_cast<IntInit>(N.getLeafValue())) {
// If this is the root of the dag we're matching, we emit a redundant opcode
// check to ensure that this gets folded into the normal top-level
// OpcodeSwitch.
- if (N == Pattern.getSrcPattern()) {
+ if (&N == &Pattern.getSrcPattern()) {
const SDNodeInfo &NI = CGP.getSDNodeInfo(CGP.getSDNodeNamed("imm"));
AddMatcher(new CheckOpcodeMatcher(NI));
}
@@ -215,14 +215,14 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
}
// An UnsetInit represents a named node without any constraints.
- if (isa<UnsetInit>(N->getLeafValue())) {
- assert(N->hasName() && "Unnamed ? leaf");
+ if (isa<UnsetInit>(N.getLeafValue())) {
+ assert(N.hasName() && "Unnamed ? leaf");
return;
}
- DefInit *DI = dyn_cast<DefInit>(N->getLeafValue());
+ DefInit *DI = dyn_cast<DefInit>(N.getLeafValue());
if (!DI) {
- errs() << "Unknown leaf kind: " << *N << "\n";
+ errs() << "Unknown leaf kind: " << N << "\n";
abort();
}
@@ -232,7 +232,7 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
// unnamed.
if (LeafRec->isSubClassOf("ValueType")) {
// A named ValueType leaf always matches: (add i32:$a, i32:$b).
- if (N->hasName())
+ if (N.hasName())
return;
// An unnamed ValueType as in (sext_inreg GPR:$foo, i8).
return AddMatcher(new CheckValueTypeMatcher(LeafRec->getName()));
@@ -262,17 +262,17 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
if (LeafRec->isSubClassOf("ComplexPattern")) {
// We can't model ComplexPattern uses that don't have their name taken yet.
// The OPC_CheckComplexPattern operation implicitly records the results.
- if (N->getName().empty()) {
+ if (N.getName().empty()) {
std::string S;
raw_string_ostream OS(S);
- OS << "We expect complex pattern uses to have names: " << *N;
+ OS << "We expect complex pattern uses to have names: " << N;
PrintFatalError(S);
}
// Remember this ComplexPattern so that we can emit it after all the other
// structural matches are done.
- unsigned InputOperand = VariableMap[N->getName()] - 1;
- MatchedComplexPatterns.push_back(std::make_pair(N, InputOperand));
+ unsigned InputOperand = VariableMap[N.getName()] - 1;
+ MatchedComplexPatterns.push_back(std::make_pair(&N, InputOperand));
return;
}
@@ -281,8 +281,8 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
// If this is the root of the dag we're matching, we emit a redundant opcode
// check to ensure that this gets folded into the normal top-level
// OpcodeSwitch.
- if (N == Pattern.getSrcPattern()) {
- MVT VT = N->getSimpleType(0);
+ if (&N == &Pattern.getSrcPattern()) {
+ MVT VT = N.getSimpleType(0);
StringRef Name = VT.isScalableVector() ? "splat_vector" : "build_vector";
const SDNodeInfo &NI = CGP.getSDNodeInfo(CGP.getSDNodeNamed(Name));
AddMatcher(new CheckOpcodeMatcher(NI));
@@ -294,33 +294,33 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
return;
}
- errs() << "Unknown leaf kind: " << *N << "\n";
+ errs() << "Unknown leaf kind: " << N << "\n";
abort();
}
-void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
- TreePatternNode *NodeNoTypes) {
- assert(!N->isLeaf() && "Not an operator?");
+void MatcherGen::EmitOperatorMatchCode(const TreePatternNode &N,
+ TreePatternNode &NodeNoTypes) {
+ assert(!N.isLeaf() && "Not an operator?");
- if (N->getOperator()->isSubClassOf("ComplexPattern")) {
+ if (N.getOperator()->isSubClassOf("ComplexPattern")) {
// The "name" of a non-leaf complex pattern (MY_PAT $op1, $op2) is
// "MY_PAT:op1:op2". We should already have validated that the uses are
// consistent.
- std::string PatternName = std::string(N->getOperator()->getName());
- for (unsigned i = 0; i < N->getNumChildren(); ++i) {
+ std::string PatternName = std::string(N.getOperator()->getName());
+ for (unsigned i = 0; i < N.getNumChildren(); ++i) {
PatternName += ":";
- PatternName += N->getChild(i)->getName();
+ PatternName += N.getChild(i).getName();
}
if (recordUniqueNode(PatternName)) {
- auto NodeAndOpNum = std::make_pair(N, NextRecordedOperandNo - 1);
+ auto NodeAndOpNum = std::make_pair(&N, NextRecordedOperandNo - 1);
MatchedComplexPatterns.push_back(NodeAndOpNum);
}
return;
}
- const SDNodeInfo &CInfo = CGP.getSDNodeInfo(N->getOperator());
+ const SDNodeInfo &CInfo = CGP.getSDNodeInfo(N.getOperator());
// If this is an 'and R, 1234' where the operation is AND/OR and the RHS is
// a constant without a predicate fn that has more than one bit set, handle
@@ -332,28 +332,28 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
// them from the mask in the dag. For example, it might turn 'AND X, 255'
// into 'AND X, 254' if it knows the low bit is set. Emit code that checks
// to handle this.
- if ((N->getOperator()->getName() == "and" ||
- N->getOperator()->getName() == "or") &&
- N->getChild(1)->isLeaf() && N->getChild(1)->getPredicateCalls().empty() &&
- N->getPredicateCalls().empty()) {
- if (IntInit *II = dyn_cast<IntInit>(N->getChild(1)->getLeafValue())) {
+ if ((N.getOperator()->getName() == "and" ||
+ N.getOperator()->getName() == "or") &&
+ N.getChild(1).isLeaf() && N.getChild(1).getPredicateCalls().empty() &&
+ N.getPredicateCalls().empty()) {
+ if (IntInit *II = dyn_cast<IntInit>(N.getChild(1).getLeafValue())) {
if (!llvm::has_single_bit<uint32_t>(
II->getValue())) { // Don't bother with single bits.
// If this is at the root of the pattern, we emit a redundant
// CheckOpcode so that the following checks get factored properly under
// a single opcode check.
- if (N == Pattern.getSrcPattern())
+ if (&N == &Pattern.getSrcPattern())
AddMatcher(new CheckOpcodeMatcher(CInfo));
// Emit the CheckAndImm/CheckOrImm node.
- if (N->getOperator()->getName() == "and")
+ if (N.getOperator()->getName() == "and")
AddMatcher(new CheckAndImmMatcher(II->getValue()));
else
AddMatcher(new CheckOrImmMatcher(II->getValue()));
// Match the LHS of the AND as appropriate.
AddMatcher(new MoveChildMatcher(0));
- EmitMatchCode(N->getChild(0), NodeNoTypes->getChild(0));
+ EmitMatchCode(N.getChild(0), NodeNoTypes.getChild(0));
AddMatcher(new MoveParentMatcher());
return;
}
@@ -365,15 +365,15 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
// If this node has memory references (i.e. is a load or store), tell the
// interpreter to capture them in the memref array.
- if (N->NodeHasProperty(SDNPMemOperand, CGP))
+ if (N.NodeHasProperty(SDNPMemOperand, CGP))
AddMatcher(new RecordMemRefMatcher());
// If this node has a chain, then the chain is operand #0 is the SDNode, and
// the child numbers of the node are all offset by one.
unsigned OpNo = 0;
- if (N->NodeHasProperty(SDNPHasChain, CGP)) {
+ if (N.NodeHasProperty(SDNPHasChain, CGP)) {
// Record the node and remember it in our chained nodes list.
- AddMatcher(new RecordMatcher("'" + N->getOperator()->getName().str() +
+ AddMatcher(new RecordMatcher("'" + N.getOperator()->getName().str() +
"' chained node",
NextRecordedOperandNo));
// Remember all of the input chains our pattern will match.
@@ -404,22 +404,22 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
// To prevent this, we emit a dynamic check for legality before allowing
// this to be folded.
//
- const TreePatternNode *Root = Pattern.getSrcPattern();
- if (N != Root) { // Not the root of the pattern.
+ const TreePatternNode &Root = Pattern.getSrcPattern();
+ if (&N != &Root) { // Not the root of the pattern.
// If there is a node between the root and this node, then we definitely
// need to emit the check.
- bool NeedCheck = !Root->hasChild(N);
+ bool NeedCheck = !Root.hasChild(&N);
// If it *is* an immediate child of the root, we can still need a check if
// the root SDNode has multiple inputs. For us, this means that it is an
// intrinsic, has multiple operands, or has other inputs like chain or
// glue).
if (!NeedCheck) {
- const SDNodeInfo &PInfo = CGP.getSDNodeInfo(Root->getOperator());
+ const SDNodeInfo &PInfo = CGP.getSDNodeInfo(Root.getOperator());
NeedCheck =
- Root->getOperator() == CGP.get_intrinsic_void_sdnode() ||
- Root->getOperator() == CGP.get_intrinsic_w_chain_sdnode() ||
- Root->getOperator() == CGP.get_intrinsic_wo_chain_sdnode() ||
+ Root.getOperator() == CGP.get_intrinsic_void_sdnode() ||
+ Root.getOperator() == CGP.get_intrinsic_w_chain_sdnode() ||
+ Root.getOperator() == CGP.get_intrinsic_wo_chain_sdnode() ||
PInfo.getNumOperands() > 1 || PInfo.hasProperty(SDNPHasChain) ||
PInfo.hasProperty(SDNPInGlue) || PInfo.hasProperty(SDNPOptInGlue);
}
@@ -430,26 +430,26 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
}
// If this node has an output glue and isn't the root, remember it.
- if (N->NodeHasProperty(SDNPOutGlue, CGP) && N != Pattern.getSrcPattern()) {
+ if (N.NodeHasProperty(SDNPOutGlue, CGP) && &N != &Pattern.getSrcPattern()) {
// TODO: This redundantly records nodes with both glues and chains.
// Record the node and remember it in our chained nodes list.
- AddMatcher(new RecordMatcher("'" + N->getOperator()->getName().str() +
+ AddMatcher(new RecordMatcher("'" + N.getOperator()->getName().str() +
"' glue output node",
NextRecordedOperandNo));
}
// If this node is known to have an input glue or if it *might* have an input
// glue, capture it as the glue input of the pattern.
- if (N->NodeHasProperty(SDNPOptInGlue, CGP) ||
- N->NodeHasProperty(SDNPInGlue, CGP))
+ if (N.NodeHasProperty(SDNPOptInGlue, CGP) ||
+ N.NodeHasProperty(SDNPInGlue, CGP))
AddMatcher(new CaptureGlueInputMatcher());
- for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i, ++OpNo) {
+ for (unsigned i = 0, e = N.getNumChildren(); i != e; ++i, ++OpNo) {
// Get the code suitable for matching this child. Move to the child, check
// it then move back to the parent.
AddMatcher(new MoveChildMatcher(OpNo));
- EmitMatchCode(N->getChild(i), NodeNoTypes->getChild(i));
+ EmitMatchCode(N.getChild(i), NodeNoTypes.getChild(i));
AddMatcher(new MoveParentMatcher());
}
}
@@ -489,17 +489,17 @@ bool MatcherGen::recordUniqueNode(ArrayRef<std::string> Names) {
return NewRecord;
}
-void MatcherGen::EmitMatchCode(const TreePatternNode *N,
- TreePatternNode *NodeNoTypes) {
+void MatcherGen::EmitMatchCode(const TreePatternNode &N,
+ TreePatternNode &NodeNoTypes) {
// If N and NodeNoTypes don't agree on a type, then this is a case where we
// need to do a type check. Emit the check, apply the type to NodeNoTypes and
// reinfer any correlated types.
SmallVector<unsigned, 2> ResultsToTypeCheck;
- for (unsigned i = 0, e = NodeNoTypes->getNumTypes(); i != e; ++i) {
- if (NodeNoTypes->getExtType(i) == N->getExtType(i))
+ for (unsigned i = 0, e = NodeNoTypes.getNumTypes(); i != e; ++i) {
+ if (NodeNoTypes.getExtType(i) == N.getExtType(i))
continue;
- NodeNoTypes->setType(i, N->getExtType(i));
+ NodeNoTypes.setType(i, N.getExtType(i));
InferPossibleTypes();
ResultsToTypeCheck.push_back(i);
}
@@ -507,10 +507,10 @@ void MatcherGen::EmitMatchCode(const TreePatternNode *N,
// If this node has a name associated with it, capture it in VariableMap. If
// we already saw this in the pattern, emit code to verify dagness.
SmallVector<std::string, 4> Names;
- if (!N->getName().empty())
- Names.push_back(N->getName());
+ if (!N.getName().empty())
+ Names.push_back(N.getName());
- for (const ScopedName &Name : N->getNamesAsPredicateArg()) {
+ for (const ScopedName &Name : N.getNamesAsPredicateArg()) {
Names.push_back(
("pred:" + Twine(Name.getScope()) + ":" + Name.getIdentifier()).str());
}
@@ -520,14 +520,14 @@ void MatcherGen::EmitMatchCode(const TreePatternNode *N,
return;
}
- if (N->isLeaf())
+ if (N.isLeaf())
EmitLeafMatchCode(N);
else
EmitOperatorMatchCode(N, NodeNoTypes);
// If there are node predicates for this node, generate their checks.
- for (unsigned i = 0, e = N->getPredicateCalls().size(); i != e; ++i) {
- const TreePredicateCall &Pred = N->getPredicateCalls()[i];
+ for (unsigned i = 0, e = N.getPredicateCalls().size(); i != e; ++i) {
+ const TreePredicateCall &Pred = N.getPredicateCalls()[i];
SmallVector<unsigned, 4> Operands;
if (Pred.Fn.usesOperands()) {
TreePattern *TP = Pred.Fn.getOrigPatFragRecord();
@@ -541,7 +541,7 @@ void MatcherGen::EmitMatchCode(const TreePatternNode *N,
}
for (unsigned i = 0, e = ResultsToTypeCheck.size(); i != e; ++i)
- AddMatcher(new CheckTypeMatcher(N->getSimpleType(ResultsToTypeCheck[i]),
+ AddMatcher(new CheckTypeMatcher(N.getSimpleType(ResultsToTypeCheck[i]),
ResultsToTypeCheck[i]));
}
@@ -554,7 +554,7 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) {
// Depending on which variant we're generating code for, emit the root opcode
// check.
if (const ComplexPattern *CP =
- Pattern.getSrcPattern()->getComplexPatternInfo(CGP)) {
+ Pattern.getSrcPattern().getComplexPatternInfo(CGP)) {
const std::vector<Record *> &OpNodes = CP->getRootNodes();
assert(!OpNodes.empty() &&
"Complex Pattern must specify what it can match");
@@ -568,7 +568,7 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) {
}
// Emit the matcher for the pattern structure and types.
- EmitMatchCode(Pattern.getSrcPattern(), PatWithNoTypes.get());
+ EmitMatchCode(Pattern.getSrcPattern(), *PatWithNoTypes);
// If the pattern has a predicate on it (e.g. only enabled when a subtarget
// feature is around, do the check).
@@ -581,28 +581,28 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) {
// because they are generally more expensive to evaluate and more
diff icult to
// factor.
for (unsigned i = 0, e = MatchedComplexPatterns.size(); i != e; ++i) {
- auto N = MatchedComplexPatterns[i].first;
+ auto &N = *MatchedComplexPatterns[i].first;
// Remember where the results of this match get stuck.
- if (N->isLeaf()) {
- NamedComplexPatternOperands[N->getName()] = NextRecordedOperandNo + 1;
+ if (N.isLeaf()) {
+ NamedComplexPatternOperands[N.getName()] = NextRecordedOperandNo + 1;
} else {
unsigned CurOp = NextRecordedOperandNo;
- for (unsigned i = 0; i < N->getNumChildren(); ++i) {
- NamedComplexPatternOperands[N->getChild(i)->getName()] = CurOp + 1;
- CurOp += N->getChild(i)->getNumMIResults(CGP);
+ for (unsigned i = 0; i < N.getNumChildren(); ++i) {
+ NamedComplexPatternOperands[N.getChild(i).getName()] = CurOp + 1;
+ CurOp += N.getChild(i).getNumMIResults(CGP);
}
}
// Get the slot we recorded the value in from the name on the node.
unsigned RecNodeEntry = MatchedComplexPatterns[i].second;
- const ComplexPattern *CP = N->getComplexPatternInfo(CGP);
+ const ComplexPattern *CP = N.getComplexPatternInfo(CGP);
assert(CP && "Not a valid ComplexPattern!");
// Emit a CheckComplexPat operation, which does the match (aborting if it
// fails) and pushes the matched operands onto the recorded nodes list.
- AddMatcher(new CheckComplexPatMatcher(*CP, RecNodeEntry, N->getName(),
+ AddMatcher(new CheckComplexPatMatcher(*CP, RecNodeEntry, N.getName(),
NextRecordedOperandNo));
// Record the right number of operands.
@@ -631,25 +631,25 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) {
//===----------------------------------------------------------------------===//
void MatcherGen::EmitResultOfNamedOperand(
- const TreePatternNode *N, SmallVectorImpl<unsigned> &ResultOps) {
- assert(!N->getName().empty() && "Operand not named!");
+ const TreePatternNode &N, SmallVectorImpl<unsigned> &ResultOps) {
+ assert(!N.getName().empty() && "Operand not named!");
- if (unsigned SlotNo = NamedComplexPatternOperands[N->getName()]) {
+ if (unsigned SlotNo = NamedComplexPatternOperands[N.getName()]) {
// Complex operands have already been completely selected, just find the
// right slot ant add the arguments directly.
- for (unsigned i = 0; i < N->getNumMIResults(CGP); ++i)
+ for (unsigned i = 0; i < N.getNumMIResults(CGP); ++i)
ResultOps.push_back(SlotNo - 1 + i);
return;
}
- unsigned SlotNo = getNamedArgumentSlot(N->getName());
+ unsigned SlotNo = getNamedArgumentSlot(N.getName());
// If this is an 'imm' or 'fpimm' node, make sure to convert it to the target
// version of the immediate so that it doesn't get selected due to some other
// node use.
- if (!N->isLeaf()) {
- StringRef OperatorName = N->getOperator()->getName();
+ if (!N.isLeaf()) {
+ StringRef OperatorName = N.getOperator()->getName();
if (OperatorName == "imm" || OperatorName == "fpimm") {
AddMatcher(new EmitConvertToTargetMatcher(SlotNo));
ResultOps.push_back(NextRecordedOperandNo++);
@@ -657,38 +657,38 @@ void MatcherGen::EmitResultOfNamedOperand(
}
}
- for (unsigned i = 0; i < N->getNumMIResults(CGP); ++i)
+ for (unsigned i = 0; i < N.getNumMIResults(CGP); ++i)
ResultOps.push_back(SlotNo + i);
}
-void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N,
+void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
SmallVectorImpl<unsigned> &ResultOps) {
- assert(N->isLeaf() && "Must be a leaf");
+ assert(N.isLeaf() && "Must be a leaf");
- if (IntInit *II = dyn_cast<IntInit>(N->getLeafValue())) {
- AddMatcher(new EmitIntegerMatcher(II->getValue(), N->getSimpleType(0)));
+ if (IntInit *II = dyn_cast<IntInit>(N.getLeafValue())) {
+ AddMatcher(new EmitIntegerMatcher(II->getValue(), N.getSimpleType(0)));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}
// If this is an explicit register reference, handle it.
- if (DefInit *DI = dyn_cast<DefInit>(N->getLeafValue())) {
+ if (DefInit *DI = dyn_cast<DefInit>(N.getLeafValue())) {
Record *Def = DI->getDef();
if (Def->isSubClassOf("Register")) {
const CodeGenRegister *Reg = CGP.getTargetInfo().getRegBank().getReg(Def);
- AddMatcher(new EmitRegisterMatcher(Reg, N->getSimpleType(0)));
+ AddMatcher(new EmitRegisterMatcher(Reg, N.getSimpleType(0)));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}
if (Def->getName() == "zero_reg") {
- AddMatcher(new EmitRegisterMatcher(nullptr, N->getSimpleType(0)));
+ AddMatcher(new EmitRegisterMatcher(nullptr, N.getSimpleType(0)));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}
if (Def->getName() == "undef_tied_input") {
- MVT::SimpleValueType ResultVT = N->getSimpleType(0);
+ MVT::SimpleValueType ResultVT = N.getSimpleType(0);
auto IDOperandNo = NextRecordedOperandNo++;
Record *ImpDef = Def->getRecords().getDef("IMPLICIT_DEF");
CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(ImpDef);
@@ -741,23 +741,23 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N,
}
errs() << "unhandled leaf node:\n";
- N->dump();
+ N.dump();
}
-static bool mayInstNodeLoadOrStore(const TreePatternNode *N,
+static bool mayInstNodeLoadOrStore(const TreePatternNode &N,
const CodeGenDAGPatterns &CGP) {
- Record *Op = N->getOperator();
+ Record *Op = N.getOperator();
const CodeGenTarget &CGT = CGP.getTargetInfo();
CodeGenInstruction &II = CGT.getInstruction(Op);
return II.mayLoad || II.mayStore;
}
-static unsigned numNodesThatMayLoadOrStore(const TreePatternNode *N,
+static unsigned numNodesThatMayLoadOrStore(const TreePatternNode &N,
const CodeGenDAGPatterns &CGP) {
- if (N->isLeaf())
+ if (N.isLeaf())
return 0;
- Record *OpRec = N->getOperator();
+ Record *OpRec = N.getOperator();
if (!OpRec->isSubClassOf("Instruction"))
return 0;
@@ -765,31 +765,31 @@ static unsigned numNodesThatMayLoadOrStore(const TreePatternNode *N,
if (mayInstNodeLoadOrStore(N, CGP))
++Count;
- for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
- Count += numNodesThatMayLoadOrStore(N->getChild(i), CGP);
+ for (unsigned i = 0, e = N.getNumChildren(); i != e; ++i)
+ Count += numNodesThatMayLoadOrStore(N.getChild(i), CGP);
return Count;
}
void MatcherGen::EmitResultInstructionAsOperand(
- const TreePatternNode *N, SmallVectorImpl<unsigned> &OutputOps) {
- Record *Op = N->getOperator();
+ const TreePatternNode &N, SmallVectorImpl<unsigned> &OutputOps) {
+ Record *Op = N.getOperator();
const CodeGenTarget &CGT = CGP.getTargetInfo();
CodeGenInstruction &II = CGT.getInstruction(Op);
const DAGInstruction &Inst = CGP.getInstruction(Op);
- bool isRoot = N == Pattern.getDstPattern();
+ bool isRoot = &N == &Pattern.getDstPattern();
// TreeHasOutGlue - True if this tree has glue.
bool TreeHasInGlue = false, TreeHasOutGlue = false;
if (isRoot) {
- const TreePatternNode *SrcPat = Pattern.getSrcPattern();
- TreeHasInGlue = SrcPat->TreeHasProperty(SDNPOptInGlue, CGP) ||
- SrcPat->TreeHasProperty(SDNPInGlue, CGP);
+ const TreePatternNode &SrcPat = Pattern.getSrcPattern();
+ TreeHasInGlue = SrcPat.TreeHasProperty(SDNPOptInGlue, CGP) ||
+ SrcPat.TreeHasProperty(SDNPInGlue, CGP);
// FIXME2: this is checking the entire pattern, not just the node in
// question, doing this just for the root seems like a total hack.
- TreeHasOutGlue = SrcPat->TreeHasProperty(SDNPOutGlue, CGP);
+ TreeHasOutGlue = SrcPat.TreeHasProperty(SDNPOutGlue, CGP);
}
// NumResults - This is the number of results produced by the instruction in
@@ -826,13 +826,13 @@ void MatcherGen::EmitResultInstructionAsOperand(
// Determine what to emit for this operand.
Record *OperandNode = II.Operands[InstOpNo].Rec;
if (CGP.operandHasDefault(OperandNode) &&
- (InstOpNo < NonOverridableOperands || ChildNo >= N->getNumChildren())) {
+ (InstOpNo < NonOverridableOperands || ChildNo >= N.getNumChildren())) {
// This is a predicate or optional def operand which the pattern has not
// overridden, or which we aren't letting it override; emit the 'default
// ops' operands.
const DAGDefaultOperand &DefaultOp = CGP.getDefaultOperand(OperandNode);
for (unsigned i = 0, e = DefaultOp.DefaultOps.size(); i != e; ++i)
- EmitResultOperand(DefaultOp.DefaultOps[i].get(), InstOps);
+ EmitResultOperand(*DefaultOp.DefaultOps[i], InstOps);
continue;
}
@@ -851,14 +851,14 @@ void MatcherGen::EmitResultInstructionAsOperand(
unsigned FinalNumOps = InstOps.size() + NumSubOps;
while (InstOps.size() < FinalNumOps) {
- const TreePatternNode *Child = N->getChild(ChildNo);
+ const TreePatternNode &Child = N.getChild(ChildNo);
unsigned BeforeAddingNumOps = InstOps.size();
EmitResultOperand(Child, InstOps);
assert(InstOps.size() > BeforeAddingNumOps && "Didn't add any operands");
// If the operand is an instruction and it produced multiple results, just
// take the first one.
- if (!Child->isLeaf() && Child->getOperator()->isSubClassOf("Instruction"))
+ if (!Child.isLeaf() && Child.getOperator()->isSubClassOf("Instruction"))
InstOps.resize(BeforeAddingNumOps + 1);
++ChildNo;
@@ -871,8 +871,8 @@ void MatcherGen::EmitResultInstructionAsOperand(
// above. Emit the remaining instructions implicitly added by the use for
// variable_ops.
if (II.Operands.isVariadic) {
- for (unsigned I = ChildNo, E = N->getNumChildren(); I < E; ++I)
- EmitResultOperand(N->getChild(I), InstOps);
+ for (unsigned I = ChildNo, E = N.getNumChildren(); I < E; ++I)
+ EmitResultOperand(N.getChild(I), InstOps);
}
// If this node has input glue or explicitly specified input physregs, we
@@ -896,8 +896,8 @@ void MatcherGen::EmitResultInstructionAsOperand(
// Determine the result types.
SmallVector<MVT::SimpleValueType, 4> ResultVTs;
- for (unsigned i = 0, e = N->getNumTypes(); i != e; ++i)
- ResultVTs.push_back(N->getSimpleType(i));
+ for (unsigned i = 0, e = N.getNumTypes(); i != e; ++i)
+ ResultVTs.push_back(N.getSimpleType(i));
// If this is the root instruction of a pattern that has physical registers in
// its result pattern, add output VTs for them. For example, X86 has:
@@ -922,8 +922,8 @@ void MatcherGen::EmitResultInstructionAsOperand(
// a node that is variadic, mark the generated node as variadic so that it
// gets the excess operands from the input DAG.
int NumFixedArityOperands = -1;
- if (isRoot && Pattern.getSrcPattern()->NodeHasProperty(SDNPVariadic, CGP))
- NumFixedArityOperands = Pattern.getSrcPattern()->getNumChildren();
+ if (isRoot && Pattern.getSrcPattern().NodeHasProperty(SDNPVariadic, CGP))
+ NumFixedArityOperands = Pattern.getSrcPattern().getNumChildren();
// If this is the root node and multiple matched nodes in the input pattern
// have MemRefs in them, have the interpreter collect them and plop them onto
@@ -933,7 +933,7 @@ void MatcherGen::EmitResultInstructionAsOperand(
// FIXME3: This is actively incorrect for result patterns with multiple
// memory-referencing instructions.
bool PatternHasMemOperands =
- Pattern.getSrcPattern()->TreeHasProperty(SDNPMemOperand, CGP);
+ Pattern.getSrcPattern().TreeHasProperty(SDNPMemOperand, CGP);
bool NodeHasMemRefs = false;
if (PatternHasMemOperands) {
@@ -948,7 +948,7 @@ void MatcherGen::EmitResultInstructionAsOperand(
// Determine whether we need to attach a chain to this node.
bool NodeHasChain = false;
- if (Pattern.getSrcPattern()->TreeHasProperty(SDNPHasChain, CGP)) {
+ if (Pattern.getSrcPattern().TreeHasProperty(SDNPHasChain, CGP)) {
// For some instructions, we were able to infer from the pattern whether
// they should have a chain. Otherwise, attach the chain to the root.
//
@@ -982,8 +982,8 @@ void MatcherGen::EmitResultInstructionAsOperand(
}
void MatcherGen::EmitResultSDNodeXFormAsOperand(
- const TreePatternNode *N, SmallVectorImpl<unsigned> &ResultOps) {
- assert(N->getOperator()->isSubClassOf("SDNodeXForm") && "Not SDNodeXForm?");
+ const TreePatternNode &N, SmallVectorImpl<unsigned> &ResultOps) {
+ assert(N.getOperator()->isSubClassOf("SDNodeXForm") && "Not SDNodeXForm?");
// Emit the operand.
SmallVector<unsigned, 8> InputOps;
@@ -991,31 +991,31 @@ void MatcherGen::EmitResultSDNodeXFormAsOperand(
// FIXME2: Could easily generalize this to support multiple inputs and outputs
// to the SDNodeXForm. For now we just support one input and one output like
// the old instruction selector.
- assert(N->getNumChildren() == 1);
- EmitResultOperand(N->getChild(0), InputOps);
+ assert(N.getNumChildren() == 1);
+ EmitResultOperand(N.getChild(0), InputOps);
// The input currently must have produced exactly one result.
assert(InputOps.size() == 1 && "Unexpected input to SDNodeXForm");
- AddMatcher(new EmitNodeXFormMatcher(InputOps[0], N->getOperator()));
+ AddMatcher(new EmitNodeXFormMatcher(InputOps[0], N.getOperator()));
ResultOps.push_back(NextRecordedOperandNo++);
}
-void MatcherGen::EmitResultOperand(const TreePatternNode *N,
+void MatcherGen::EmitResultOperand(const TreePatternNode &N,
SmallVectorImpl<unsigned> &ResultOps) {
// This is something selected from the pattern we matched.
- if (!N->getName().empty())
+ if (!N.getName().empty())
return EmitResultOfNamedOperand(N, ResultOps);
- if (N->isLeaf())
+ if (N.isLeaf())
return EmitResultLeafAsOperand(N, ResultOps);
- Record *OpRec = N->getOperator();
+ Record *OpRec = N.getOperator();
if (OpRec->isSubClassOf("Instruction"))
return EmitResultInstructionAsOperand(N, ResultOps);
if (OpRec->isSubClassOf("SDNodeXForm"))
return EmitResultSDNodeXFormAsOperand(N, ResultOps);
- errs() << "Unknown result node to emit code for: " << *N << '\n';
+ errs() << "Unknown result node to emit code for: " << N << '\n';
PrintFatalError("Unknown node in result pattern!");
}
@@ -1036,18 +1036,17 @@ void MatcherGen::EmitResultCode() {
// just lop them off. This doesn't need to worry about glue or chains, just
// explicit results.
//
- unsigned NumSrcResults = Pattern.getSrcPattern()->getNumTypes();
+ unsigned NumSrcResults = Pattern.getSrcPattern().getNumTypes();
// If the pattern also has (implicit) results, count them as well.
if (!Pattern.getDstRegs().empty()) {
// If the root came from an implicit def in the instruction handling stuff,
// don't re-add it.
Record *HandledReg = nullptr;
- const TreePatternNode *DstPat = Pattern.getDstPattern();
- if (!DstPat->isLeaf() &&
- DstPat->getOperator()->isSubClassOf("Instruction")) {
+ const TreePatternNode &DstPat = Pattern.getDstPattern();
+ if (!DstPat.isLeaf() && DstPat.getOperator()->isSubClassOf("Instruction")) {
const CodeGenTarget &CGT = CGP.getTargetInfo();
- CodeGenInstruction &II = CGT.getInstruction(DstPat->getOperator());
+ CodeGenInstruction &II = CGT.getInstruction(DstPat.getOperator());
if (II.HasOneImplicitDefWithKnownVT(CGT) != MVT::Other)
HandledReg = II.ImplicitDefs[0];
@@ -1063,9 +1062,9 @@ void MatcherGen::EmitResultCode() {
SmallVector<unsigned, 8> Results(Ops);
// Apply result permutation.
- for (unsigned ResNo = 0; ResNo < Pattern.getDstPattern()->getNumResults();
+ for (unsigned ResNo = 0; ResNo < Pattern.getDstPattern().getNumResults();
++ResNo) {
- Results[ResNo] = Ops[Pattern.getDstPattern()->getResultIndex(ResNo)];
+ Results[ResNo] = Ops[Pattern.getDstPattern().getResultIndex(ResNo)];
}
Results.resize(NumSrcResults);
diff --git a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
index b137492072f1d..f786d41c88d7c 100644
--- a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
@@ -99,7 +99,7 @@ static void ContractNodes(std::unique_ptr<Matcher> &MatcherPtr,
const PatternToMatch &Pattern = CM->getPattern();
if (!EN->hasChain() &&
- Pattern.getSrcPattern()->NodeHasProperty(SDNPHasChain, CGP))
+ Pattern.getSrcPattern().NodeHasProperty(SDNPHasChain, CGP))
ResultsMatch = false;
// If the matched node has glue and the output root doesn't, we can't
@@ -109,7 +109,7 @@ static void ContractNodes(std::unique_ptr<Matcher> &MatcherPtr,
// because the code in the pattern generator doesn't handle it right. We
// do it anyway for thoroughness.
if (!EN->hasOutGlue() &&
- Pattern.getSrcPattern()->NodeHasProperty(SDNPOutGlue, CGP))
+ Pattern.getSrcPattern().NodeHasProperty(SDNPOutGlue, CGP))
ResultsMatch = false;
#if 0
diff --git a/llvm/utils/TableGen/FastISelEmitter.cpp b/llvm/utils/TableGen/FastISelEmitter.cpp
index dff6503e67730..00a165030d36b 100644
--- a/llvm/utils/TableGen/FastISelEmitter.cpp
+++ b/llvm/utils/TableGen/FastISelEmitter.cpp
@@ -200,36 +200,36 @@ struct OperandsSignature {
/// of the Operands array accordingly. Return true if all the operands
/// are supported, false otherwise.
///
- bool initialize(TreePatternNode *InstPatNode, const CodeGenTarget &Target,
+ bool initialize(TreePatternNode &InstPatNode, const CodeGenTarget &Target,
MVT::SimpleValueType VT, ImmPredicateSet &ImmediatePredicates,
const CodeGenRegisterClass *OrigDstRC) {
- if (InstPatNode->isLeaf())
+ if (InstPatNode.isLeaf())
return false;
- if (InstPatNode->getOperator()->getName() == "imm") {
+ if (InstPatNode.getOperator()->getName() == "imm") {
Operands.push_back(OpKind::getImm(0));
return true;
}
- if (InstPatNode->getOperator()->getName() == "fpimm") {
+ if (InstPatNode.getOperator()->getName() == "fpimm") {
Operands.push_back(OpKind::getFP());
return true;
}
const CodeGenRegisterClass *DstRC = nullptr;
- for (unsigned i = 0, e = InstPatNode->getNumChildren(); i != e; ++i) {
- TreePatternNode *Op = InstPatNode->getChild(i);
+ for (unsigned i = 0, e = InstPatNode.getNumChildren(); i != e; ++i) {
+ TreePatternNode &Op = InstPatNode.getChild(i);
// Handle imm operands specially.
- if (!Op->isLeaf() && Op->getOperator()->getName() == "imm") {
+ if (!Op.isLeaf() && Op.getOperator()->getName() == "imm") {
unsigned PredNo = 0;
- if (!Op->getPredicateCalls().empty()) {
- TreePredicateFn PredFn = Op->getPredicateCalls()[0].Fn;
+ if (!Op.getPredicateCalls().empty()) {
+ TreePredicateFn PredFn = Op.getPredicateCalls()[0].Fn;
// If there is more than one predicate weighing in on this operand
// then we don't handle it. This doesn't typically happen for
// immediates anyway.
- if (Op->getPredicateCalls().size() > 1 ||
+ if (Op.getPredicateCalls().size() > 1 ||
!PredFn.isImmediatePattern() || PredFn.usesOperands())
return false;
// Ignore any instruction with 'FastIselShouldIgnore', these are
@@ -249,11 +249,11 @@ struct OperandsSignature {
// For now, filter out any operand with a predicate.
// For now, filter out any operand with multiple values.
- if (!Op->getPredicateCalls().empty() || Op->getNumTypes() != 1)
+ if (!Op.getPredicateCalls().empty() || Op.getNumTypes() != 1)
return false;
- if (!Op->isLeaf()) {
- if (Op->getOperator()->getName() == "fpimm") {
+ if (!Op.isLeaf()) {
+ if (Op.getOperator()->getName() == "fpimm") {
Operands.push_back(OpKind::getFP());
continue;
}
@@ -261,15 +261,15 @@ struct OperandsSignature {
return false;
}
- assert(Op->hasConcreteType(0) && "Type infererence not done?");
+ assert(Op.hasConcreteType(0) && "Type infererence not done?");
// For now, all the operands must have the same type (if they aren't
// immediates). Note that this causes us to reject variable sized shifts
// on X86.
- if (Op->getSimpleType(0) != VT)
+ if (Op.getSimpleType(0) != VT)
return false;
- DefInit *OpDI = dyn_cast<DefInit>(Op->getLeafValue());
+ DefInit *OpDI = dyn_cast<DefInit>(Op.getLeafValue());
if (!OpDI)
return false;
Record *OpLeafRec = OpDI->getDef();
@@ -430,14 +430,14 @@ static std::string getLegalCName(std::string OpName) {
FastISelMap::FastISelMap(StringRef instns) : InstNS(instns) {}
-static std::string PhyRegForNode(TreePatternNode *Op,
+static std::string PhyRegForNode(TreePatternNode &Op,
const CodeGenTarget &Target) {
std::string PhysReg;
- if (!Op->isLeaf())
+ if (!Op.isLeaf())
return PhysReg;
- Record *OpLeafRec = cast<DefInit>(Op->getLeafValue())->getDef();
+ Record *OpLeafRec = cast<DefInit>(Op.getLeafValue())->getDef();
if (!OpLeafRec->isSubClassOf("Register"))
return PhysReg;
@@ -458,10 +458,10 @@ void FastISelMap::collectPatterns(CodeGenDAGPatterns &CGP) {
// For now, just look at Instructions, so that we don't have to worry
// about emitting multiple instructions for a pattern.
- TreePatternNode *Dst = Pattern.getDstPattern();
- if (Dst->isLeaf())
+ TreePatternNode &Dst = Pattern.getDstPattern();
+ if (Dst.isLeaf())
continue;
- Record *Op = Dst->getOperator();
+ Record *Op = Dst.getOperator();
if (!Op->isSubClassOf("Instruction"))
continue;
CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(Op);
@@ -477,11 +477,11 @@ void FastISelMap::collectPatterns(CodeGenDAGPatterns &CGP) {
// For now, ignore multi-instruction patterns.
bool MultiInsts = false;
- for (unsigned i = 0, e = Dst->getNumChildren(); i != e; ++i) {
- TreePatternNode *ChildOp = Dst->getChild(i);
- if (ChildOp->isLeaf())
+ for (unsigned i = 0, e = Dst.getNumChildren(); i != e; ++i) {
+ TreePatternNode &ChildOp = Dst.getChild(i);
+ if (ChildOp.isLeaf())
continue;
- if (ChildOp->getOperator()->isSubClassOf("Instruction")) {
+ if (ChildOp.getOperator()->isSubClassOf("Instruction")) {
MultiInsts = true;
break;
}
@@ -505,40 +505,38 @@ void FastISelMap::collectPatterns(CodeGenDAGPatterns &CGP) {
} else {
// If this isn't a leaf, then continue since the register classes are
// a bit too complicated for now.
- if (!Dst->getChild(1)->isLeaf())
+ if (!Dst.getChild(1).isLeaf())
continue;
- DefInit *SR = dyn_cast<DefInit>(Dst->getChild(1)->getLeafValue());
+ DefInit *SR = dyn_cast<DefInit>(Dst.getChild(1).getLeafValue());
if (SR)
SubRegNo = getQualifiedName(SR->getDef());
else
- SubRegNo = Dst->getChild(1)->getLeafValue()->getAsString();
+ SubRegNo = Dst.getChild(1).getLeafValue()->getAsString();
}
// Inspect the pattern.
- TreePatternNode *InstPatNode = Pattern.getSrcPattern();
- if (!InstPatNode)
- continue;
- if (InstPatNode->isLeaf())
+ TreePatternNode &InstPatNode = Pattern.getSrcPattern();
+ if (InstPatNode.isLeaf())
continue;
// Ignore multiple result nodes for now.
- if (InstPatNode->getNumTypes() > 1)
+ if (InstPatNode.getNumTypes() > 1)
continue;
- Record *InstPatOp = InstPatNode->getOperator();
+ Record *InstPatOp = InstPatNode.getOperator();
std::string OpcodeName = getOpcodeName(InstPatOp, CGP);
MVT::SimpleValueType RetVT = MVT::isVoid;
- if (InstPatNode->getNumTypes())
- RetVT = InstPatNode->getSimpleType(0);
+ if (InstPatNode.getNumTypes())
+ RetVT = InstPatNode.getSimpleType(0);
MVT::SimpleValueType VT = RetVT;
- if (InstPatNode->getNumChildren()) {
- assert(InstPatNode->getChild(0)->getNumTypes() == 1);
- VT = InstPatNode->getChild(0)->getSimpleType(0);
+ if (InstPatNode.getNumChildren()) {
+ assert(InstPatNode.getChild(0).getNumTypes() == 1);
+ VT = InstPatNode.getChild(0).getSimpleType(0);
}
// For now, filter out any instructions with predicates.
- if (!InstPatNode->getPredicateCalls().empty())
+ if (!InstPatNode.getPredicateCalls().empty())
continue;
// Check all the operands.
@@ -548,20 +546,20 @@ void FastISelMap::collectPatterns(CodeGenDAGPatterns &CGP) {
continue;
std::vector<std::string> PhysRegInputs;
- if (InstPatNode->getOperator()->getName() == "imm" ||
- InstPatNode->getOperator()->getName() == "fpimm")
+ if (InstPatNode.getOperator()->getName() == "imm" ||
+ InstPatNode.getOperator()->getName() == "fpimm")
PhysRegInputs.push_back("");
else {
// Compute the PhysRegs used by the given pattern, and check that
// the mapping from the src to dst patterns is simple.
bool FoundNonSimplePattern = false;
unsigned DstIndex = 0;
- for (unsigned i = 0, e = InstPatNode->getNumChildren(); i != e; ++i) {
- std::string PhysReg = PhyRegForNode(InstPatNode->getChild(i), Target);
+ for (unsigned i = 0, e = InstPatNode.getNumChildren(); i != e; ++i) {
+ std::string PhysReg = PhyRegForNode(InstPatNode.getChild(i), Target);
if (PhysReg.empty()) {
- if (DstIndex >= Dst->getNumChildren() ||
- Dst->getChild(DstIndex)->getName() !=
- InstPatNode->getChild(i)->getName()) {
+ if (DstIndex >= Dst.getNumChildren() ||
+ Dst.getChild(DstIndex).getName() !=
+ InstPatNode.getChild(i).getName()) {
FoundNonSimplePattern = true;
break;
}
@@ -571,7 +569,7 @@ void FastISelMap::collectPatterns(CodeGenDAGPatterns &CGP) {
PhysRegInputs.push_back(PhysReg);
}
- if (Op->getName() != "EXTRACT_SUBREG" && DstIndex < Dst->getNumChildren())
+ if (Op->getName() != "EXTRACT_SUBREG" && DstIndex < Dst.getNumChildren())
FoundNonSimplePattern = true;
if (FoundNonSimplePattern)
@@ -591,7 +589,7 @@ void FastISelMap::collectPatterns(CodeGenDAGPatterns &CGP) {
std::string PredicateCheck = Pattern.getPredicateCheck();
// Ok, we found a pattern that we can handle. Remember it.
- InstructionMemo Memo(Pattern.getDstPattern()->getOperator()->getName(),
+ InstructionMemo Memo(Pattern.getDstPattern().getOperator()->getName(),
DstRC, SubRegNo, PhysRegInputs, PredicateCheck);
int complexity = Pattern.getPatternComplexity(CGP);
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index 22e7785275bd7..13f2384efc9ce 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -90,10 +90,10 @@ static cl::opt<bool> OptimizeMatchTable(
namespace {
-static std::string explainPredicates(const TreePatternNode *N) {
+static std::string explainPredicates(const TreePatternNode &N) {
std::string Explanation;
StringRef Separator = "";
- for (const TreePredicateCall &Call : N->getPredicateCalls()) {
+ for (const TreePredicateCall &Call : N.getPredicateCalls()) {
const TreePredicateFn &P = Call.Fn;
Explanation +=
(Separator + P.getOrigPatFragRecord()->getRecord()->getName()).str();
@@ -194,12 +194,12 @@ static Error failedImport(const Twine &Reason) {
return make_error<StringError>(Reason, inconvertibleErrorCode());
}
-static Error isTrivialOperatorNode(const TreePatternNode *N) {
+static Error isTrivialOperatorNode(const TreePatternNode &N) {
std::string Explanation;
std::string Separator;
bool HasUnsupportedPredicate = false;
- for (const TreePredicateCall &Call : N->getPredicateCalls()) {
+ for (const TreePredicateCall &Call : N.getPredicateCalls()) {
const TreePredicateFn &Predicate = Call.Fn;
if (Predicate.isAlwaysTrue())
@@ -288,8 +288,8 @@ static std::string getMangledRootDefName(StringRef DefOperandName) {
//===- GlobalISelEmitter class --------------------------------------------===//
-static Expected<LLTCodeGen> getInstResultType(const TreePatternNode *Dst) {
- ArrayRef<TypeSetByHwMode> ChildTypes = Dst->getExtTypes();
+static Expected<LLTCodeGen> getInstResultType(const TreePatternNode &Dst) {
+ ArrayRef<TypeSetByHwMode> ChildTypes = Dst.getExtTypes();
if (ChildTypes.size() != 1)
return failedImport("Dst pattern child has multiple results");
@@ -372,40 +372,40 @@ class GlobalISelEmitter final : public GlobalISelMatchTableExecutorEmitter {
Record *findNodeEquiv(Record *N) const;
const CodeGenInstruction *getEquivNode(Record &Equiv,
- const TreePatternNode *N) const;
+ const TreePatternNode &N) const;
Error importRulePredicates(RuleMatcher &M, ArrayRef<Record *> Predicates);
Expected<InstructionMatcher &>
createAndImportSelDAGMatcher(RuleMatcher &Rule,
InstructionMatcher &InsnMatcher,
- const TreePatternNode *Src, unsigned &TempOpIdx);
+ const TreePatternNode &Src, unsigned &TempOpIdx);
Error importComplexPatternOperandMatcher(OperandMatcher &OM, Record *R,
unsigned &TempOpIdx) const;
Error importChildMatcher(RuleMatcher &Rule, InstructionMatcher &InsnMatcher,
- const TreePatternNode *SrcChild,
+ const TreePatternNode &SrcChild,
bool OperandIsAPointer, bool OperandIsImmArg,
unsigned OpIdx, unsigned &TempOpIdx);
Expected<BuildMIAction &> createAndImportInstructionRenderer(
RuleMatcher &M, InstructionMatcher &InsnMatcher,
- const TreePatternNode *Src, const TreePatternNode *Dst);
+ const TreePatternNode &Src, const TreePatternNode &Dst);
Expected<action_iterator> createAndImportSubInstructionRenderer(
- action_iterator InsertPt, RuleMatcher &M, const TreePatternNode *Dst,
- const TreePatternNode *Src, unsigned TempReg);
+ action_iterator InsertPt, RuleMatcher &M, const TreePatternNode &Dst,
+ const TreePatternNode &Src, unsigned TempReg);
Expected<action_iterator>
createInstructionRenderer(action_iterator InsertPt, RuleMatcher &M,
- const TreePatternNode *Dst);
+ const TreePatternNode &Dst);
Expected<action_iterator> importExplicitDefRenderers(
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
- const TreePatternNode *Src, const TreePatternNode *Dst);
+ const TreePatternNode &Src, const TreePatternNode &Dst);
Expected<action_iterator> importExplicitUseRenderers(
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
- const llvm::TreePatternNode *Dst, const TreePatternNode *Src);
+ const llvm::TreePatternNode &Dst, const TreePatternNode &Src);
Expected<action_iterator> importExplicitUseRenderer(
action_iterator InsertPt, RuleMatcher &Rule, BuildMIAction &DstMIBuilder,
- const TreePatternNode *DstChild, const TreePatternNode *Src);
+ const TreePatternNode &DstChild, const TreePatternNode &Src);
Error importDefaultOperandRenderers(action_iterator InsertPt, RuleMatcher &M,
BuildMIAction &DstMIBuilder,
const DAGDefaultOperand &DefaultOp) const;
@@ -430,25 +430,25 @@ class GlobalISelEmitter final : public GlobalISelMatchTableExecutorEmitter {
/// If no register class is found, return std::nullopt.
std::optional<const CodeGenRegisterClass *>
inferSuperRegisterClassForNode(const TypeSetByHwMode &Ty,
- const TreePatternNode *SuperRegNode,
- const TreePatternNode *SubRegIdxNode);
+ const TreePatternNode &SuperRegNode,
+ const TreePatternNode &SubRegIdxNode);
std::optional<CodeGenSubRegIndex *>
- inferSubRegIndexForNode(const TreePatternNode *SubRegIdxNode);
+ inferSubRegIndexForNode(const TreePatternNode &SubRegIdxNode);
/// Infer a CodeGenRegisterClass which suppoorts \p Ty and \p SubRegIdxNode.
/// Return std::nullopt if no such class exists.
std::optional<const CodeGenRegisterClass *>
inferSuperRegisterClass(const TypeSetByHwMode &Ty,
- const TreePatternNode *SubRegIdxNode);
+ const TreePatternNode &SubRegIdxNode);
/// Return the CodeGenRegisterClass associated with \p Leaf if it has one.
std::optional<const CodeGenRegisterClass *>
- getRegClassFromLeaf(const TreePatternNode *Leaf);
+ getRegClassFromLeaf(const TreePatternNode &Leaf);
/// Return a CodeGenRegisterClass for \p N if one can be found. Return
/// std::nullopt otherwise.
std::optional<const CodeGenRegisterClass *>
- inferRegClassFromPattern(const TreePatternNode *N);
+ inferRegClassFromPattern(const TreePatternNode &N);
/// Return the size of the MemoryVT in this predicate, if possible.
std::optional<unsigned>
@@ -498,19 +498,19 @@ Record *GlobalISelEmitter::findNodeEquiv(Record *N) const {
}
const CodeGenInstruction *
-GlobalISelEmitter::getEquivNode(Record &Equiv, const TreePatternNode *N) const {
- if (N->getNumChildren() >= 1) {
+GlobalISelEmitter::getEquivNode(Record &Equiv, const TreePatternNode &N) const {
+ if (N.getNumChildren() >= 1) {
// setcc operation maps to two
diff erent G_* instructions based on the type.
if (!Equiv.isValueUnset("IfFloatingPoint") &&
- MVT(N->getChild(0)->getSimpleType(0)).isFloatingPoint())
+ MVT(N.getChild(0).getSimpleType(0)).isFloatingPoint())
return &Target.getInstruction(Equiv.getValueAsDef("IfFloatingPoint"));
}
if (!Equiv.isValueUnset("IfConvergent") &&
- N->getIntrinsicInfo(CGP)->isConvergent)
+ N.getIntrinsicInfo(CGP)->isConvergent)
return &Target.getInstruction(Equiv.getValueAsDef("IfConvergent"));
- for (const TreePredicateCall &Call : N->getPredicateCalls()) {
+ for (const TreePredicateCall &Call : N.getPredicateCalls()) {
const TreePredicateFn &Predicate = Call.Fn;
if (!Equiv.isValueUnset("IfSignExtend") &&
(Predicate.isLoad() || Predicate.isAtomic()) &&
@@ -707,15 +707,15 @@ Expected<InstructionMatcher &> GlobalISelEmitter::addBuiltinPredicates(
Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
RuleMatcher &Rule, InstructionMatcher &InsnMatcher,
- const TreePatternNode *Src, unsigned &TempOpIdx) {
- const auto SavedFlags = Rule.setGISelFlags(Src->getGISelFlagsRecord());
+ const TreePatternNode &Src, unsigned &TempOpIdx) {
+ const auto SavedFlags = Rule.setGISelFlags(Src.getGISelFlagsRecord());
Record *SrcGIEquivOrNull = nullptr;
const CodeGenInstruction *SrcGIOrNull = nullptr;
// Start with the defined operands (i.e., the results of the root operator).
- if (Src->isLeaf()) {
- Init *SrcInit = Src->getLeafValue();
+ if (Src.isLeaf()) {
+ Init *SrcInit = Src.getLeafValue();
if (isa<IntInit>(SrcInit)) {
InsnMatcher.addPredicate<InstructionOpcodeMatcher>(
&Target.getInstruction(RK.getDef("G_CONSTANT")));
@@ -723,10 +723,10 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
return failedImport(
"Unable to deduce gMIR opcode to handle Src (which is a leaf)");
} else {
- SrcGIEquivOrNull = findNodeEquiv(Src->getOperator());
+ SrcGIEquivOrNull = findNodeEquiv(Src.getOperator());
if (!SrcGIEquivOrNull)
return failedImport("Pattern operator lacks an equivalent Instruction" +
- explainOperator(Src->getOperator()));
+ explainOperator(Src.getOperator()));
SrcGIOrNull = getEquivNode(*SrcGIEquivOrNull, Src);
// The operators look good: match the opcode
@@ -734,7 +734,7 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
}
unsigned OpIdx = 0;
- for (const TypeSetByHwMode &VTy : Src->getExtTypes()) {
+ for (const TypeSetByHwMode &VTy : Src.getExtTypes()) {
// Results don't have a name unless they are the root node. The caller will
// set the name if appropriate.
const bool OperandIsAPointer =
@@ -745,7 +745,7 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
" for result of Src pattern operator");
}
- for (const TreePredicateCall &Call : Src->getPredicateCalls()) {
+ for (const TreePredicateCall &Call : Src.getPredicateCalls()) {
const TreePredicateFn &Predicate = Call.Fn;
bool HasAddedBuiltinMatcher = true;
if (Predicate.isAlwaysTrue())
@@ -800,11 +800,11 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
"Unordered", AtomicOrderingMMOPredicateMatcher::AO_OrStronger);
}
- if (Src->isLeaf()) {
- Init *SrcInit = Src->getLeafValue();
+ if (Src.isLeaf()) {
+ Init *SrcInit = Src.getLeafValue();
if (IntInit *SrcIntInit = dyn_cast<IntInit>(SrcInit)) {
OperandMatcher &OM =
- InsnMatcher.addOperand(OpIdx++, Src->getName(), TempOpIdx);
+ InsnMatcher.addOperand(OpIdx++, Src.getName(), TempOpIdx);
OM.addPredicate<LiteralIntOperandMatcher>(SrcIntInit->getValue());
} else
return failedImport(
@@ -825,19 +825,19 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
// predicate operand needs to be swapped from the last operand to the first
// source.
- unsigned NumChildren = Src->getNumChildren();
+ unsigned NumChildren = Src.getNumChildren();
bool IsFCmp = SrcGIOrNull->TheDef->getName() == "G_FCMP";
if (IsFCmp || SrcGIOrNull->TheDef->getName() == "G_ICMP") {
- const TreePatternNode *SrcChild = Src->getChild(NumChildren - 1);
- if (SrcChild->isLeaf()) {
- DefInit *DI = dyn_cast<DefInit>(SrcChild->getLeafValue());
+ const TreePatternNode &SrcChild = Src.getChild(NumChildren - 1);
+ if (SrcChild.isLeaf()) {
+ DefInit *DI = dyn_cast<DefInit>(SrcChild.getLeafValue());
Record *CCDef = DI ? DI->getDef() : nullptr;
if (!CCDef || !CCDef->isSubClassOf("CondCode"))
return failedImport("Unable to handle CondCode");
OperandMatcher &OM =
- InsnMatcher.addOperand(OpIdx++, SrcChild->getName(), TempOpIdx);
+ InsnMatcher.addOperand(OpIdx++, SrcChild.getName(), TempOpIdx);
StringRef PredType = IsFCmp ? CCDef->getValueAsString("FCmpPredicate")
: CCDef->getValueAsString("ICmpPredicate");
@@ -856,12 +856,12 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
SrcGIOrNull->TheDef->getName() == "G_INTRINSIC_CONVERGENT" ||
SrcGIOrNull->TheDef->getName() ==
"G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS";
- const CodeGenIntrinsic *II = Src->getIntrinsicInfo(CGP);
+ const CodeGenIntrinsic *II = Src.getIntrinsicInfo(CGP);
if (IsIntrinsic && !II)
return failedImport("Expected IntInit containing intrinsic ID)");
for (unsigned i = 0; i != NumChildren; ++i) {
- const TreePatternNode *SrcChild = Src->getChild(i);
+ const TreePatternNode &SrcChild = Src.getChild(i);
// We need to determine the meaning of a literal integer based on the
// context. If this is a field required to be an immediate (such as an
@@ -884,7 +884,7 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
// following the defs is an intrinsic ID.
if (i == 0) {
OperandMatcher &OM =
- InsnMatcher.addOperand(OpIdx++, SrcChild->getName(), TempOpIdx);
+ InsnMatcher.addOperand(OpIdx++, SrcChild.getName(), TempOpIdx);
OM.addPredicate<IntrinsicIDOperandMatcher>(II);
continue;
}
@@ -921,11 +921,11 @@ Error GlobalISelEmitter::importComplexPatternOperandMatcher(
// Get the name to use for a pattern operand. For an anonymous physical register
// input, this should use the register name.
-static StringRef getSrcChildName(const TreePatternNode *SrcChild,
+static StringRef getSrcChildName(const TreePatternNode &SrcChild,
Record *&PhysReg) {
- StringRef SrcChildName = SrcChild->getName();
- if (SrcChildName.empty() && SrcChild->isLeaf()) {
- if (auto *ChildDefInit = dyn_cast<DefInit>(SrcChild->getLeafValue())) {
+ StringRef SrcChildName = SrcChild.getName();
+ if (SrcChildName.empty() && SrcChild.isLeaf()) {
+ if (auto *ChildDefInit = dyn_cast<DefInit>(SrcChild.getLeafValue())) {
auto *ChildRec = ChildDefInit->getDef();
if (ChildRec->isSubClassOf("Register")) {
SrcChildName = ChildRec->getName();
@@ -939,19 +939,19 @@ static StringRef getSrcChildName(const TreePatternNode *SrcChild,
Error GlobalISelEmitter::importChildMatcher(
RuleMatcher &Rule, InstructionMatcher &InsnMatcher,
- const TreePatternNode *SrcChild, bool OperandIsAPointer,
+ const TreePatternNode &SrcChild, bool OperandIsAPointer,
bool OperandIsImmArg, unsigned OpIdx, unsigned &TempOpIdx) {
Record *PhysReg = nullptr;
std::string SrcChildName = std::string(getSrcChildName(SrcChild, PhysReg));
- if (!SrcChild->isLeaf() &&
- SrcChild->getOperator()->isSubClassOf("ComplexPattern")) {
+ if (!SrcChild.isLeaf() &&
+ SrcChild.getOperator()->isSubClassOf("ComplexPattern")) {
// The "name" of a non-leaf complex pattern (MY_PAT $op1, $op2) is
// "MY_PAT:op1:op2" and the ones with same "name" represent same operand.
- std::string PatternName = std::string(SrcChild->getOperator()->getName());
- for (unsigned i = 0; i < SrcChild->getNumChildren(); ++i) {
+ std::string PatternName = std::string(SrcChild.getOperator()->getName());
+ for (unsigned i = 0; i < SrcChild.getNumChildren(); ++i) {
PatternName += ":";
- PatternName += SrcChild->getChild(i)->getName();
+ PatternName += SrcChild.getChild(i).getName();
}
SrcChildName = PatternName;
}
@@ -962,23 +962,23 @@ Error GlobalISelEmitter::importChildMatcher(
if (OM.isSameAsAnotherOperand())
return Error::success();
- ArrayRef<TypeSetByHwMode> ChildTypes = SrcChild->getExtTypes();
+ ArrayRef<TypeSetByHwMode> ChildTypes = SrcChild.getExtTypes();
if (ChildTypes.size() != 1)
return failedImport("Src pattern child has multiple results");
// Check MBB's before the type check since they are not a known type.
- if (!SrcChild->isLeaf()) {
- if (SrcChild->getOperator()->isSubClassOf("SDNode")) {
- auto &ChildSDNI = CGP.getSDNodeInfo(SrcChild->getOperator());
+ if (!SrcChild.isLeaf()) {
+ if (SrcChild.getOperator()->isSubClassOf("SDNode")) {
+ auto &ChildSDNI = CGP.getSDNodeInfo(SrcChild.getOperator());
if (ChildSDNI.getSDClassName() == "BasicBlockSDNode") {
OM.addPredicate<MBBOperandMatcher>();
return Error::success();
}
- if (SrcChild->getOperator()->getName() == "timm") {
+ if (SrcChild.getOperator()->getName() == "timm") {
OM.addPredicate<ImmOperandMatcher>();
// Add predicates, if any
- for (const TreePredicateCall &Call : SrcChild->getPredicateCalls()) {
+ for (const TreePredicateCall &Call : SrcChild.getPredicateCalls()) {
const TreePredicateFn &Predicate = Call.Fn;
// Only handle immediate patterns for now
@@ -998,12 +998,12 @@ Error GlobalISelEmitter::importChildMatcher(
if (auto Error =
OM.addTypeCheckPredicate(ChildTypes.front(), OperandIsAPointer))
return failedImport(toString(std::move(Error)) + " for Src operand (" +
- to_string(*SrcChild) + ")");
+ to_string(SrcChild) + ")");
}
// Try look up SrcChild for a (named) predicate operand if there is any.
if (WaitingForNamedOperands) {
- auto &ScopedNames = SrcChild->getNamesAsPredicateArg();
+ auto &ScopedNames = SrcChild.getNamesAsPredicateArg();
if (!ScopedNames.empty()) {
auto PA = ScopedNames.begin();
std::string Name = getScopedName(PA->getScope(), PA->getIdentifier());
@@ -1013,22 +1013,22 @@ Error GlobalISelEmitter::importChildMatcher(
}
// Check for nested instructions.
- if (!SrcChild->isLeaf()) {
- if (SrcChild->getOperator()->isSubClassOf("ComplexPattern")) {
+ if (!SrcChild.isLeaf()) {
+ if (SrcChild.getOperator()->isSubClassOf("ComplexPattern")) {
// When a ComplexPattern is used as an operator, it should do the same
// thing as when used as a leaf. However, the children of the operator
// name the sub-operands that make up the complex operand and we must
// prepare to reference them in the renderer too.
unsigned RendererID = TempOpIdx;
if (auto Error = importComplexPatternOperandMatcher(
- OM, SrcChild->getOperator(), TempOpIdx))
+ OM, SrcChild.getOperator(), TempOpIdx))
return Error;
- for (unsigned i = 0, e = SrcChild->getNumChildren(); i != e; ++i) {
- auto *SubOperand = SrcChild->getChild(i);
- if (!SubOperand->getName().empty()) {
+ for (unsigned i = 0, e = SrcChild.getNumChildren(); i != e; ++i) {
+ auto &SubOperand = SrcChild.getChild(i);
+ if (!SubOperand.getName().empty()) {
if (auto Error = Rule.defineComplexSubOperand(
- SubOperand->getName(), SrcChild->getOperator(), RendererID, i,
+ SubOperand.getName(), SrcChild.getOperator(), RendererID, i,
SrcChildName))
return Error;
}
@@ -1038,7 +1038,7 @@ Error GlobalISelEmitter::importChildMatcher(
}
auto MaybeInsnOperand = OM.addPredicate<InstructionOperandMatcher>(
- InsnMatcher.getRuleMatcher(), SrcChild->getName());
+ InsnMatcher.getRuleMatcher(), SrcChild.getName());
if (!MaybeInsnOperand) {
// This isn't strictly true. If the user were to provide exactly the same
// matchers as the original operand then we could allow it. However, it's
@@ -1057,11 +1057,11 @@ Error GlobalISelEmitter::importChildMatcher(
return Error::success();
}
- if (SrcChild->hasAnyPredicate())
+ if (SrcChild.hasAnyPredicate())
return failedImport("Src pattern child has unsupported predicate");
// Check for constant immediates.
- if (auto *ChildInt = dyn_cast<IntInit>(SrcChild->getLeafValue())) {
+ if (auto *ChildInt = dyn_cast<IntInit>(SrcChild.getLeafValue())) {
if (OperandIsImmArg) {
// Checks for argument directly in operand list
OM.addPredicate<LiteralIntOperandMatcher>(ChildInt->getValue());
@@ -1073,7 +1073,7 @@ Error GlobalISelEmitter::importChildMatcher(
}
// Check for def's like register classes or ComplexPattern's.
- if (auto *ChildDefInit = dyn_cast<DefInit>(SrcChild->getLeafValue())) {
+ if (auto *ChildDefInit = dyn_cast<DefInit>(SrcChild.getLeafValue())) {
auto *ChildRec = ChildDefInit->getDef();
// Check for register classes.
@@ -1121,7 +1121,7 @@ Error GlobalISelEmitter::importChildMatcher(
const bool ImmAllOnesV = ChildRec->getName() == "immAllOnesV";
if (ImmAllOnesV || ChildRec->getName() == "immAllZerosV") {
auto MaybeInsnOperand = OM.addPredicate<InstructionOperandMatcher>(
- InsnMatcher.getRuleMatcher(), SrcChild->getName(), false);
+ InsnMatcher.getRuleMatcher(), SrcChild.getName(), false);
InstructionOperandMatcher &InsnOperand = **MaybeInsnOperand;
ValueTypeByHwMode VTy = ChildTypes.front().getValueTypeByHwMode();
@@ -1161,45 +1161,44 @@ Error GlobalISelEmitter::importChildMatcher(
Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderer(
action_iterator InsertPt, RuleMatcher &Rule, BuildMIAction &DstMIBuilder,
- const TreePatternNode *DstChild, const TreePatternNode *Src) {
+ const TreePatternNode &DstChild, const TreePatternNode &Src) {
- const auto &SubOperand = Rule.getComplexSubOperand(DstChild->getName());
+ const auto &SubOperand = Rule.getComplexSubOperand(DstChild.getName());
if (SubOperand) {
DstMIBuilder.addRenderer<RenderComplexPatternOperand>(
- *std::get<0>(*SubOperand), DstChild->getName(),
- std::get<1>(*SubOperand), std::get<2>(*SubOperand));
+ *std::get<0>(*SubOperand), DstChild.getName(), std::get<1>(*SubOperand),
+ std::get<2>(*SubOperand));
return InsertPt;
}
- if (!DstChild->isLeaf()) {
- if (DstChild->getOperator()->isSubClassOf("SDNodeXForm")) {
- auto Child = DstChild->getChild(0);
- auto I = SDNodeXFormEquivs.find(DstChild->getOperator());
+ if (!DstChild.isLeaf()) {
+ if (DstChild.getOperator()->isSubClassOf("SDNodeXForm")) {
+ auto &Child = DstChild.getChild(0);
+ auto I = SDNodeXFormEquivs.find(DstChild.getOperator());
if (I != SDNodeXFormEquivs.end()) {
- Record *XFormOpc = DstChild->getOperator()->getValueAsDef("Opcode");
+ Record *XFormOpc = DstChild.getOperator()->getValueAsDef("Opcode");
if (XFormOpc->getName() == "timm") {
// If this is a TargetConstant, there won't be a corresponding
// instruction to transform. Instead, this will refer directly to an
// operand in an instruction's operand list.
DstMIBuilder.addRenderer<CustomOperandRenderer>(*I->second,
- Child->getName());
+ Child.getName());
} else {
- DstMIBuilder.addRenderer<CustomRenderer>(*I->second,
- Child->getName());
+ DstMIBuilder.addRenderer<CustomRenderer>(*I->second, Child.getName());
}
return InsertPt;
}
- return failedImport("SDNodeXForm " + Child->getName() +
+ return failedImport("SDNodeXForm " + Child.getName() +
" has no custom renderer");
}
// We accept 'bb' here. It's an operator because BasicBlockSDNode isn't
// inline, but in MI it's just another operand.
- if (DstChild->getOperator()->isSubClassOf("SDNode")) {
- auto &ChildSDNI = CGP.getSDNodeInfo(DstChild->getOperator());
+ if (DstChild.getOperator()->isSubClassOf("SDNode")) {
+ auto &ChildSDNI = CGP.getSDNodeInfo(DstChild.getOperator());
if (ChildSDNI.getSDClassName() == "BasicBlockSDNode") {
- DstMIBuilder.addRenderer<CopyRenderer>(DstChild->getName());
+ DstMIBuilder.addRenderer<CopyRenderer>(DstChild.getName());
return InsertPt;
}
}
@@ -1208,19 +1207,19 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderer(
// rendered as operands.
// FIXME: The target should be able to choose sign-extended when appropriate
// (e.g. on Mips).
- if (DstChild->getOperator()->getName() == "timm") {
- DstMIBuilder.addRenderer<CopyRenderer>(DstChild->getName());
+ if (DstChild.getOperator()->getName() == "timm") {
+ DstMIBuilder.addRenderer<CopyRenderer>(DstChild.getName());
return InsertPt;
- } else if (DstChild->getOperator()->getName() == "imm") {
- DstMIBuilder.addRenderer<CopyConstantAsImmRenderer>(DstChild->getName());
+ } else if (DstChild.getOperator()->getName() == "imm") {
+ DstMIBuilder.addRenderer<CopyConstantAsImmRenderer>(DstChild.getName());
return InsertPt;
- } else if (DstChild->getOperator()->getName() == "fpimm") {
+ } else if (DstChild.getOperator()->getName() == "fpimm") {
DstMIBuilder.addRenderer<CopyFConstantAsFPImmRenderer>(
- DstChild->getName());
+ DstChild.getName());
return InsertPt;
}
- if (DstChild->getOperator()->isSubClassOf("Instruction")) {
+ if (DstChild.getOperator()->isSubClassOf("Instruction")) {
auto OpTy = getInstResultType(DstChild);
if (!OpTy)
return OpTy.takeError();
@@ -1238,22 +1237,22 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderer(
}
return failedImport("Dst pattern child isn't a leaf node or an MBB" +
- llvm::to_string(*DstChild));
+ llvm::to_string(DstChild));
}
// It could be a specific immediate in which case we should just check for
// that immediate.
if (const IntInit *ChildIntInit =
- dyn_cast<IntInit>(DstChild->getLeafValue())) {
+ dyn_cast<IntInit>(DstChild.getLeafValue())) {
DstMIBuilder.addRenderer<ImmRenderer>(ChildIntInit->getValue());
return InsertPt;
}
// Otherwise, we're looking for a bog-standard RegisterClass operand.
- if (auto *ChildDefInit = dyn_cast<DefInit>(DstChild->getLeafValue())) {
+ if (auto *ChildDefInit = dyn_cast<DefInit>(DstChild.getLeafValue())) {
auto *ChildRec = ChildDefInit->getDef();
- ArrayRef<TypeSetByHwMode> ChildTypes = DstChild->getExtTypes();
+ ArrayRef<TypeSetByHwMode> ChildTypes = DstChild.getExtTypes();
if (ChildTypes.size() != 1)
return failedImport("Dst pattern child has multiple results");
@@ -1274,11 +1273,11 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderer(
if (ChildRec->isSubClassOf("RegisterOperand") &&
!ChildRec->isValueUnset("GIZeroRegister")) {
DstMIBuilder.addRenderer<CopyOrAddZeroRegRenderer>(
- DstChild->getName(), ChildRec->getValueAsDef("GIZeroRegister"));
+ DstChild.getName(), ChildRec->getValueAsDef("GIZeroRegister"));
return InsertPt;
}
- DstMIBuilder.addRenderer<CopyRenderer>(DstChild->getName());
+ DstMIBuilder.addRenderer<CopyRenderer>(DstChild.getName());
return InsertPt;
}
@@ -1294,9 +1293,9 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderer(
return failedImport(
"SelectionDAG ComplexPattern not mapped to GlobalISel");
- const OperandMatcher &OM = Rule.getOperandMatcher(DstChild->getName());
+ const OperandMatcher &OM = Rule.getOperandMatcher(DstChild.getName());
DstMIBuilder.addRenderer<RenderComplexPatternOperand>(
- *ComplexPattern->second, DstChild->getName(),
+ *ComplexPattern->second, DstChild.getName(),
OM.getAllocatedTemporariesBaseID());
return InsertPt;
}
@@ -1307,10 +1306,10 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderer(
// Handle the case where the MVT/register class is omitted in the dest pattern
// but MVT exists in the source pattern.
- if (isa<UnsetInit>(DstChild->getLeafValue())) {
- for (unsigned NumOp = 0; NumOp < Src->getNumChildren(); NumOp++)
- if (Src->getChild(NumOp)->getName() == DstChild->getName()) {
- DstMIBuilder.addRenderer<CopyRenderer>(Src->getChild(NumOp)->getName());
+ if (isa<UnsetInit>(DstChild.getLeafValue())) {
+ for (unsigned NumOp = 0; NumOp < Src.getNumChildren(); NumOp++)
+ if (Src.getChild(NumOp).getName() == DstChild.getName()) {
+ DstMIBuilder.addRenderer<CopyRenderer>(Src.getChild(NumOp).getName());
return InsertPt;
}
}
@@ -1318,8 +1317,8 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderer(
}
Expected<BuildMIAction &> GlobalISelEmitter::createAndImportInstructionRenderer(
- RuleMatcher &M, InstructionMatcher &InsnMatcher, const TreePatternNode *Src,
- const TreePatternNode *Dst) {
+ RuleMatcher &M, InstructionMatcher &InsnMatcher, const TreePatternNode &Src,
+ const TreePatternNode &Dst) {
auto InsertPtOrError = createInstructionRenderer(M.actions_end(), M, Dst);
if (auto Error = InsertPtOrError.takeError())
return std::move(Error);
@@ -1353,8 +1352,8 @@ Expected<BuildMIAction &> GlobalISelEmitter::createAndImportInstructionRenderer(
Expected<action_iterator>
GlobalISelEmitter::createAndImportSubInstructionRenderer(
- const action_iterator InsertPt, RuleMatcher &M, const TreePatternNode *Dst,
- const TreePatternNode *Src, unsigned TempRegID) {
+ const action_iterator InsertPt, RuleMatcher &M, const TreePatternNode &Dst,
+ const TreePatternNode &Src, unsigned TempRegID) {
auto InsertPtOrError = createInstructionRenderer(InsertPt, M, Dst);
// TODO: Assert there's exactly one result.
@@ -1376,15 +1375,15 @@ GlobalISelEmitter::createAndImportSubInstructionRenderer(
// We need to make sure that when we import an INSERT_SUBREG as a
// subinstruction that it ends up being constrained to the correct super
// register and subregister classes.
- auto OpName = Target.getInstruction(Dst->getOperator()).TheDef->getName();
+ auto OpName = Target.getInstruction(Dst.getOperator()).TheDef->getName();
if (OpName == "INSERT_SUBREG") {
- auto SubClass = inferRegClassFromPattern(Dst->getChild(1));
+ auto SubClass = inferRegClassFromPattern(Dst.getChild(1));
if (!SubClass)
return failedImport(
"Cannot infer register class from INSERT_SUBREG operand #1");
std::optional<const CodeGenRegisterClass *> SuperClass =
- inferSuperRegisterClassForNode(Dst->getExtType(0), Dst->getChild(0),
- Dst->getChild(2));
+ inferSuperRegisterClassForNode(Dst.getExtType(0), Dst.getChild(0),
+ Dst.getChild(2));
if (!SuperClass)
return failedImport(
"Cannot infer register class for INSERT_SUBREG operand #0");
@@ -1404,12 +1403,12 @@ GlobalISelEmitter::createAndImportSubInstructionRenderer(
// instructions, the result register class is controlled by the
// subregisters of the operand. As a result, we must constrain the result
// class rather than check that it's already the right one.
- auto SuperClass = inferRegClassFromPattern(Dst->getChild(0));
+ auto SuperClass = inferRegClassFromPattern(Dst.getChild(0));
if (!SuperClass)
return failedImport(
"Cannot infer register class from EXTRACT_SUBREG operand #0");
- auto SubIdx = inferSubRegIndexForNode(Dst->getChild(1));
+ auto SubIdx = inferSubRegIndexForNode(Dst.getChild(1));
if (!SubIdx)
return failedImport("EXTRACT_SUBREG child #1 is not a subreg index");
@@ -1429,12 +1428,12 @@ GlobalISelEmitter::createAndImportSubInstructionRenderer(
// Similar to INSERT_SUBREG, we also have to handle SUBREG_TO_REG as a
// subinstruction.
if (OpName == "SUBREG_TO_REG") {
- auto SubClass = inferRegClassFromPattern(Dst->getChild(1));
+ auto SubClass = inferRegClassFromPattern(Dst.getChild(1));
if (!SubClass)
return failedImport(
"Cannot infer register class from SUBREG_TO_REG child #1");
auto SuperClass =
- inferSuperRegisterClass(Dst->getExtType(0), Dst->getChild(2));
+ inferSuperRegisterClass(Dst.getExtType(0), Dst.getChild(2));
if (!SuperClass)
return failedImport(
"Cannot infer register class for SUBREG_TO_REG operand #0");
@@ -1446,13 +1445,13 @@ GlobalISelEmitter::createAndImportSubInstructionRenderer(
}
if (OpName == "REG_SEQUENCE") {
- auto SuperClass = inferRegClassFromPattern(Dst->getChild(0));
+ auto SuperClass = inferRegClassFromPattern(Dst.getChild(0));
M.insertAction<ConstrainOperandToRegClassAction>(
InsertPt, DstMIBuilder.getInsnID(), 0, **SuperClass);
- unsigned Num = Dst->getNumChildren();
+ unsigned Num = Dst.getNumChildren();
for (unsigned I = 1; I != Num; I += 2) {
- const TreePatternNode *SubRegChild = Dst->getChild(I + 1);
+ const TreePatternNode &SubRegChild = Dst.getChild(I + 1);
auto SubIdx = inferSubRegIndexForNode(SubRegChild);
if (!SubIdx)
@@ -1474,8 +1473,8 @@ GlobalISelEmitter::createAndImportSubInstructionRenderer(
}
Expected<action_iterator> GlobalISelEmitter::createInstructionRenderer(
- action_iterator InsertPt, RuleMatcher &M, const TreePatternNode *Dst) {
- Record *DstOp = Dst->getOperator();
+ action_iterator InsertPt, RuleMatcher &M, const TreePatternNode &Dst) {
+ Record *DstOp = Dst.getOperator();
if (!DstOp->isSubClassOf("Instruction")) {
if (DstOp->isSubClassOf("ValueType"))
return failedImport(
@@ -1496,9 +1495,9 @@ Expected<action_iterator> GlobalISelEmitter::createInstructionRenderer(
Expected<action_iterator> GlobalISelEmitter::importExplicitDefRenderers(
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
- const TreePatternNode *Src, const TreePatternNode *Dst) {
+ const TreePatternNode &Src, const TreePatternNode &Dst) {
const CodeGenInstruction *DstI = DstMIBuilder.getCGI();
- const unsigned SrcNumDefs = Src->getExtTypes().size();
+ const unsigned SrcNumDefs = Src.getExtTypes().size();
const unsigned DstNumDefs = DstI->Operands.NumDefs;
if (DstNumDefs == 0)
return InsertPt;
@@ -1513,11 +1512,11 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitDefRenderers(
// Some instructions have multiple defs, but are missing a type entry
// (e.g. s_cc_out operands).
- if (Dst->getExtTypes().size() < DstNumDefs)
+ if (Dst.getExtTypes().size() < DstNumDefs)
return failedImport("unhandled discarded def");
for (unsigned I = SrcNumDefs; I < DstNumDefs; ++I) {
- const TypeSetByHwMode &ExtTy = Dst->getExtType(I);
+ const TypeSetByHwMode &ExtTy = Dst.getExtType(I);
if (!ExtTy.isMachineValueType())
return failedImport("unsupported typeset");
@@ -1536,24 +1535,24 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitDefRenderers(
Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
- const llvm::TreePatternNode *Dst, const llvm::TreePatternNode *Src) {
+ const llvm::TreePatternNode &Dst, const llvm::TreePatternNode &Src) {
const CodeGenInstruction *DstI = DstMIBuilder.getCGI();
- CodeGenInstruction *OrigDstI = &Target.getInstruction(Dst->getOperator());
+ CodeGenInstruction *OrigDstI = &Target.getInstruction(Dst.getOperator());
StringRef Name = OrigDstI->TheDef->getName();
- unsigned ExpectedDstINumUses = Dst->getNumChildren();
+ unsigned ExpectedDstINumUses = Dst.getNumChildren();
// EXTRACT_SUBREG needs to use a subregister COPY.
if (Name == "EXTRACT_SUBREG") {
- if (!Dst->getChild(1)->isLeaf())
+ if (!Dst.getChild(1).isLeaf())
return failedImport("EXTRACT_SUBREG child #1 is not a leaf");
- DefInit *SubRegInit = dyn_cast<DefInit>(Dst->getChild(1)->getLeafValue());
+ DefInit *SubRegInit = dyn_cast<DefInit>(Dst.getChild(1).getLeafValue());
if (!SubRegInit)
return failedImport("EXTRACT_SUBREG child #1 is not a subreg index");
CodeGenSubRegIndex *SubIdx = CGRegs.getSubRegIdx(SubRegInit->getDef());
- const TreePatternNode *ValChild = Dst->getChild(0);
- if (!ValChild->isLeaf()) {
+ const TreePatternNode &ValChild = Dst.getChild(0);
+ if (!ValChild.isLeaf()) {
// We really have to handle the source instruction, and then insert a
// copy from the subregister.
auto ExtractSrcTy = getInstResultType(ValChild);
@@ -1574,7 +1573,7 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
}
// If this is a source operand, this is just a subregister copy.
- Record *RCDef = getInitValueAsRegClass(ValChild->getLeafValue());
+ Record *RCDef = getInitValueAsRegClass(ValChild.getLeafValue());
if (!RCDef)
return failedImport("EXTRACT_SUBREG child #0 could not "
"be coerced to a register class");
@@ -1589,7 +1588,7 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
return failedImport("EXTRACT_SUBREG requires an additional COPY");
}
- StringRef RegOperandName = Dst->getChild(0)->getName();
+ StringRef RegOperandName = Dst.getChild(0).getName();
if (const auto &SubOperand = M.getComplexSubOperand(RegOperandName)) {
DstMIBuilder.addRenderer<RenderComplexPatternOperand>(
*std::get<0>(*SubOperand), RegOperandName, std::get<1>(*SubOperand),
@@ -1602,10 +1601,10 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
}
if (Name == "REG_SEQUENCE") {
- if (!Dst->getChild(0)->isLeaf())
+ if (!Dst.getChild(0).isLeaf())
return failedImport("REG_SEQUENCE child #0 is not a leaf");
- Record *RCDef = getInitValueAsRegClass(Dst->getChild(0)->getLeafValue());
+ Record *RCDef = getInitValueAsRegClass(Dst.getChild(0).getLeafValue());
if (!RCDef)
return failedImport("REG_SEQUENCE child #0 could not "
"be coerced to a register class");
@@ -1614,11 +1613,10 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
return failedImport("Malformed REG_SEQUENCE");
for (unsigned I = 1; I != ExpectedDstINumUses; I += 2) {
- const TreePatternNode *ValChild = Dst->getChild(I);
- const TreePatternNode *SubRegChild = Dst->getChild(I + 1);
+ const TreePatternNode &ValChild = Dst.getChild(I);
+ const TreePatternNode &SubRegChild = Dst.getChild(I + 1);
- if (DefInit *SubRegInit =
- dyn_cast<DefInit>(SubRegChild->getLeafValue())) {
+ if (DefInit *SubRegInit = dyn_cast<DefInit>(SubRegChild.getLeafValue())) {
CodeGenSubRegIndex *SubIdx = CGRegs.getSubRegIdx(SubRegInit->getDef());
auto InsertPtOrError =
@@ -1676,7 +1674,7 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
// If the operand has default values, introduce them now.
if (CGP.operandHasDefault(OperandNode) &&
- (InstOpNo < NonOverridableOperands || Child >= Dst->getNumChildren())) {
+ (InstOpNo < NonOverridableOperands || Child >= Dst.getNumChildren())) {
// This is a predicate or optional def operand which the pattern has not
// overridden, or which we aren't letting it override; emit the 'default
// ops' operands.
@@ -1691,7 +1689,7 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
}
auto InsertPtOrError = importExplicitUseRenderer(InsertPt, M, DstMIBuilder,
- Dst->getChild(Child), Src);
+ Dst.getChild(Child), Src);
if (auto Error = InsertPtOrError.takeError())
return std::move(Error);
InsertPt = InsertPtOrError.get();
@@ -1712,14 +1710,14 @@ Error GlobalISelEmitter::importDefaultOperandRenderers(
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
const DAGDefaultOperand &DefaultOp) const {
for (const auto &Op : DefaultOp.DefaultOps) {
- const auto *N = Op.get();
- if (!N->isLeaf())
+ const auto &N = *Op;
+ if (!N.isLeaf())
return failedImport("Could not add default op");
- const auto *DefaultOp = N->getLeafValue();
+ const auto *DefaultOp = N.getLeafValue();
if (const DefInit *DefaultDefOp = dyn_cast<DefInit>(DefaultOp)) {
- std::optional<LLTCodeGen> OpTyOrNone = MVTToLLT(N->getSimpleType(0));
+ std::optional<LLTCodeGen> OpTyOrNone = MVTToLLT(N.getSimpleType(0));
auto Def = DefaultDefOp->getDef();
if (Def->getName() == "undef_tied_input") {
unsigned TempRegID = M.allocateTempRegID();
@@ -1758,10 +1756,9 @@ Error GlobalISelEmitter::importImplicitDefRenderers(
}
std::optional<const CodeGenRegisterClass *>
-GlobalISelEmitter::getRegClassFromLeaf(const TreePatternNode *Leaf) {
- assert(Leaf && "Expected node?");
- assert(Leaf->isLeaf() && "Expected leaf?");
- Record *RCRec = getInitValueAsRegClass(Leaf->getLeafValue());
+GlobalISelEmitter::getRegClassFromLeaf(const TreePatternNode &Leaf) {
+ assert(Leaf.isLeaf() && "Expected leaf?");
+ Record *RCRec = getInitValueAsRegClass(Leaf.getLeafValue());
if (!RCRec)
return std::nullopt;
CodeGenRegisterClass *RC = CGRegs.getRegClass(RCRec);
@@ -1771,20 +1768,17 @@ GlobalISelEmitter::getRegClassFromLeaf(const TreePatternNode *Leaf) {
}
std::optional<const CodeGenRegisterClass *>
-GlobalISelEmitter::inferRegClassFromPattern(const TreePatternNode *N) {
- if (!N)
- return std::nullopt;
-
- if (N->isLeaf())
+GlobalISelEmitter::inferRegClassFromPattern(const TreePatternNode &N) {
+ if (N.isLeaf())
return getRegClassFromLeaf(N);
// We don't have a leaf node, so we have to try and infer something. Check
// that we have an instruction that we an infer something from.
// Only handle things that produce a single type.
- if (N->getNumTypes() != 1)
+ if (N.getNumTypes() != 1)
return std::nullopt;
- Record *OpRec = N->getOperator();
+ Record *OpRec = N.getOperator();
// We only want instructions.
if (!OpRec->isSubClassOf("Instruction"))
@@ -1803,21 +1797,21 @@ GlobalISelEmitter::inferRegClassFromPattern(const TreePatternNode *N) {
if (IsRegSequence || InstName == "COPY_TO_REGCLASS") {
// If we have a COPY_TO_REGCLASS, then we need to handle it specially. It
// has the desired register class as the first child.
- const TreePatternNode *RCChild = N->getChild(IsRegSequence ? 0 : 1);
- if (!RCChild->isLeaf())
+ const TreePatternNode &RCChild = N.getChild(IsRegSequence ? 0 : 1);
+ if (!RCChild.isLeaf())
return std::nullopt;
return getRegClassFromLeaf(RCChild);
}
if (InstName == "INSERT_SUBREG") {
- const TreePatternNode *Child0 = N->getChild(0);
- assert(Child0->getNumTypes() == 1 && "Unexpected number of types!");
- const TypeSetByHwMode &VTy = Child0->getExtType(0);
- return inferSuperRegisterClassForNode(VTy, Child0, N->getChild(2));
+ const TreePatternNode &Child0 = N.getChild(0);
+ assert(Child0.getNumTypes() == 1 && "Unexpected number of types!");
+ const TypeSetByHwMode &VTy = Child0.getExtType(0);
+ return inferSuperRegisterClassForNode(VTy, Child0, N.getChild(2));
}
if (InstName == "EXTRACT_SUBREG") {
- assert(N->getNumTypes() == 1 && "Unexpected number of types!");
- const TypeSetByHwMode &VTy = N->getExtType(0);
- return inferSuperRegisterClass(VTy, N->getChild(1));
+ assert(N.getNumTypes() == 1 && "Unexpected number of types!");
+ const TypeSetByHwMode &VTy = N.getExtType(0);
+ return inferSuperRegisterClass(VTy, N.getChild(1));
}
// Handle destination record types that we can safely infer a register class
@@ -1840,14 +1834,13 @@ GlobalISelEmitter::inferRegClassFromPattern(const TreePatternNode *N) {
std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::inferSuperRegisterClass(
- const TypeSetByHwMode &Ty, const TreePatternNode *SubRegIdxNode) {
- assert(SubRegIdxNode && "Expected subregister index node!");
+ const TypeSetByHwMode &Ty, const TreePatternNode &SubRegIdxNode) {
// We need a ValueTypeByHwMode for getSuperRegForSubReg.
if (!Ty.isValueTypeByHwMode(false))
return std::nullopt;
- if (!SubRegIdxNode->isLeaf())
+ if (!SubRegIdxNode.isLeaf())
return std::nullopt;
- DefInit *SubRegInit = dyn_cast<DefInit>(SubRegIdxNode->getLeafValue());
+ DefInit *SubRegInit = dyn_cast<DefInit>(SubRegIdxNode.getLeafValue());
if (!SubRegInit)
return std::nullopt;
CodeGenSubRegIndex *SubIdx = CGRegs.getSubRegIdx(SubRegInit->getDef());
@@ -1864,9 +1857,8 @@ GlobalISelEmitter::inferSuperRegisterClass(
std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::inferSuperRegisterClassForNode(
- const TypeSetByHwMode &Ty, const TreePatternNode *SuperRegNode,
- const TreePatternNode *SubRegIdxNode) {
- assert(SuperRegNode && "Expected super register node!");
+ const TypeSetByHwMode &Ty, const TreePatternNode &SuperRegNode,
+ const TreePatternNode &SubRegIdxNode) {
// Check if we already have a defined register class for the super register
// node. If we do, then we should preserve that rather than inferring anything
// from the subregister index node. We can assume that whoever wrote the
@@ -1879,11 +1871,11 @@ GlobalISelEmitter::inferSuperRegisterClassForNode(
}
std::optional<CodeGenSubRegIndex *> GlobalISelEmitter::inferSubRegIndexForNode(
- const TreePatternNode *SubRegIdxNode) {
- if (!SubRegIdxNode->isLeaf())
+ const TreePatternNode &SubRegIdxNode) {
+ if (!SubRegIdxNode.isLeaf())
return std::nullopt;
- DefInit *SubRegInit = dyn_cast<DefInit>(SubRegIdxNode->getLeafValue());
+ DefInit *SubRegInit = dyn_cast<DefInit>(SubRegIdxNode.getLeafValue());
if (!SubRegInit)
return std::nullopt;
return CGRegs.getSubRegIdx(SubRegInit->getDef());
@@ -1894,9 +1886,9 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
int Score = P.getPatternComplexity(CGP);
RuleMatcher M(P.getSrcRecord()->getLoc());
RuleMatcherScores[M.getRuleID()] = Score;
- M.addAction<DebugCommentAction>(llvm::to_string(*P.getSrcPattern()) +
+ M.addAction<DebugCommentAction>(llvm::to_string(P.getSrcPattern()) +
" => " +
- llvm::to_string(*P.getDstPattern()));
+ llvm::to_string(P.getDstPattern()));
SmallVector<Record *, 4> Predicates;
P.getPredicateRecords(Predicates);
@@ -1907,8 +1899,8 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
M.addHwModeIdx(declareHwModeCheck(P.getHwModeFeatures()));
// Next, analyze the pattern operators.
- TreePatternNode *Src = P.getSrcPattern();
- TreePatternNode *Dst = P.getDstPattern();
+ TreePatternNode &Src = P.getSrcPattern();
+ TreePatternNode &Dst = P.getDstPattern();
// If the root of either pattern isn't a simple operator, ignore it.
if (auto Err = isTrivialOperatorNode(Dst))
@@ -1939,7 +1931,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
// the capture accross rules. The downside is that it would
// introduce a dependency between predicates (captures must happen
// before their first use.)
- InstructionMatcher &InsnMatcherTemp = M.addInstructionMatcher(Src->getName());
+ InstructionMatcher &InsnMatcherTemp = M.addInstructionMatcher(Src.getName());
unsigned TempOpIdx = 0;
const auto SavedFlags = M.setGISelFlags(P.getSrcRecord());
@@ -1950,8 +1942,8 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
return std::move(Error);
InstructionMatcher &InsnMatcher = InsnMatcherOrError.get();
- if (Dst->isLeaf()) {
- Record *RCDef = getInitValueAsRegClass(Dst->getLeafValue());
+ if (Dst.isLeaf()) {
+ Record *RCDef = getInitValueAsRegClass(Dst.getLeafValue());
if (RCDef) {
const CodeGenRegisterClass &RC = Target.getRegisterClass(RCDef);
@@ -1969,7 +1961,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
auto &DstMIBuilder =
M.addAction<BuildMIAction>(M.allocateOutputInsnID(), &DstI);
DstMIBuilder.addRenderer<CopyRenderer>(DstIOperand.Name);
- DstMIBuilder.addRenderer<CopyRenderer>(Dst->getName());
+ DstMIBuilder.addRenderer<CopyRenderer>(Dst.getName());
M.addAction<ConstrainOperandToRegClassAction>(0, 0, RC);
// Erase the root.
@@ -1986,7 +1978,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
}
// Start with the defined operands (i.e., the results of the root operator).
- Record *DstOp = Dst->getOperator();
+ Record *DstOp = Dst.getOperator();
if (!DstOp->isSubClassOf("Instruction"))
return failedImport("Pattern operator isn't an instruction");
@@ -1994,7 +1986,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
StringRef DstIName = DstI.TheDef->getName();
unsigned DstNumDefs = DstI.Operands.NumDefs,
- SrcNumDefs = Src->getExtTypes().size();
+ SrcNumDefs = Src.getExtTypes().size();
if (DstNumDefs < SrcNumDefs) {
if (DstNumDefs != 0)
return failedImport("Src pattern result has more defs than dst MI (" +
@@ -2017,23 +2009,23 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
unsigned OpIdx = 0;
unsigned N = std::min(DstNumDefs, SrcNumDefs);
for (unsigned I = 0; I < N; ++I) {
- const TypeSetByHwMode &VTy = Src->getExtType(I);
+ const TypeSetByHwMode &VTy = Src.getExtType(I);
const auto &DstIOperand = DstI.Operands[OpIdx];
PointerUnion<Record *, const CodeGenRegisterClass *> MatchedRC =
DstIOperand.Rec;
if (DstIName == "COPY_TO_REGCLASS") {
- MatchedRC = getInitValueAsRegClass(Dst->getChild(1)->getLeafValue());
+ MatchedRC = getInitValueAsRegClass(Dst.getChild(1).getLeafValue());
if (MatchedRC.isNull())
return failedImport(
"COPY_TO_REGCLASS operand #1 isn't a register class");
} else if (DstIName == "REG_SEQUENCE") {
- MatchedRC = getInitValueAsRegClass(Dst->getChild(0)->getLeafValue());
+ MatchedRC = getInitValueAsRegClass(Dst.getChild(0).getLeafValue());
if (MatchedRC.isNull())
return failedImport("REG_SEQUENCE operand #0 isn't a register class");
} else if (DstIName == "EXTRACT_SUBREG") {
- auto InferredClass = inferRegClassFromPattern(Dst->getChild(0));
+ auto InferredClass = inferRegClassFromPattern(Dst.getChild(0));
if (!InferredClass)
return failedImport(
"Could not infer class for EXTRACT_SUBREG operand #0");
@@ -2042,8 +2034,8 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
// register.
MatchedRC = (*InferredClass)->getDef();
} else if (DstIName == "INSERT_SUBREG") {
- auto MaybeSuperClass = inferSuperRegisterClassForNode(
- VTy, Dst->getChild(0), Dst->getChild(2));
+ auto MaybeSuperClass =
+ inferSuperRegisterClassForNode(VTy, Dst.getChild(0), Dst.getChild(2));
if (!MaybeSuperClass)
return failedImport(
"Cannot infer register class for INSERT_SUBREG operand #0");
@@ -2052,7 +2044,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
// set DstIOpRec using this.
MatchedRC = *MaybeSuperClass;
} else if (DstIName == "SUBREG_TO_REG") {
- auto MaybeRegClass = inferSuperRegisterClass(VTy, Dst->getChild(2));
+ auto MaybeRegClass = inferSuperRegisterClass(VTy, Dst.getChild(2));
if (!MaybeRegClass)
return failedImport(
"Cannot infer register class for SUBREG_TO_REG operand #0");
@@ -2060,8 +2052,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
} else if (MatchedRC.get<Record *>()->isSubClassOf("RegisterOperand"))
MatchedRC = MatchedRC.get<Record *>()->getValueAsDef("RegClass");
else if (!MatchedRC.get<Record *>()->isSubClassOf("RegisterClass"))
- return failedImport("Dst MI def isn't a register class" +
- to_string(*Dst));
+ return failedImport("Dst MI def isn't a register class" + to_string(Dst));
OperandMatcher &OM = InsnMatcher.getOperand(OpIdx);
// The operand names declared in the DstI instruction are unrelated to
@@ -2095,8 +2086,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
if (DstIName == "COPY_TO_REGCLASS") {
// COPY_TO_REGCLASS does not provide operand constraints itself but the
// result is constrained to the class given by the second child.
- Record *DstIOpRec =
- getInitValueAsRegClass(Dst->getChild(1)->getLeafValue());
+ Record *DstIOpRec = getInitValueAsRegClass(Dst.getChild(1).getLeafValue());
if (DstIOpRec == nullptr)
return failedImport("COPY_TO_REGCLASS operand #1 isn't a register class");
@@ -2104,12 +2094,12 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
M.addAction<ConstrainOperandToRegClassAction>(
0, 0, Target.getRegisterClass(DstIOpRec));
} else if (DstIName == "EXTRACT_SUBREG") {
- auto SuperClass = inferRegClassFromPattern(Dst->getChild(0));
+ auto SuperClass = inferRegClassFromPattern(Dst.getChild(0));
if (!SuperClass)
return failedImport(
"Cannot infer register class from EXTRACT_SUBREG operand #0");
- auto SubIdx = inferSubRegIndexForNode(Dst->getChild(1));
+ auto SubIdx = inferSubRegIndexForNode(Dst.getChild(1));
if (!SubIdx)
return failedImport("EXTRACT_SUBREG child #1 is not a subreg index");
@@ -2119,7 +2109,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
//
// FIXME: This may introduce an extra copy if the chosen class doesn't
// actually contain the subregisters.
- assert(Src->getExtTypes().size() == 1 &&
+ assert(Src.getExtTypes().size() == 1 &&
"Expected Src of EXTRACT_SUBREG to have one result type");
const auto SrcRCDstRCPair =
@@ -2134,16 +2124,16 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
*SrcRCDstRCPair->second);
M.addAction<ConstrainOperandToRegClassAction>(0, 1, *SrcRCDstRCPair->first);
} else if (DstIName == "INSERT_SUBREG") {
- assert(Src->getExtTypes().size() == 1 &&
+ assert(Src.getExtTypes().size() == 1 &&
"Expected Src of INSERT_SUBREG to have one result type");
// We need to constrain the destination, a super regsister source, and a
// subregister source.
- auto SubClass = inferRegClassFromPattern(Dst->getChild(1));
+ auto SubClass = inferRegClassFromPattern(Dst.getChild(1));
if (!SubClass)
return failedImport(
"Cannot infer register class from INSERT_SUBREG operand #1");
auto SuperClass = inferSuperRegisterClassForNode(
- Src->getExtType(0), Dst->getChild(0), Dst->getChild(2));
+ Src.getExtType(0), Dst.getChild(0), Dst.getChild(2));
if (!SuperClass)
return failedImport(
"Cannot infer register class for INSERT_SUBREG operand #0");
@@ -2152,32 +2142,32 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
M.addAction<ConstrainOperandToRegClassAction>(0, 2, **SubClass);
} else if (DstIName == "SUBREG_TO_REG") {
// We need to constrain the destination and subregister source.
- assert(Src->getExtTypes().size() == 1 &&
+ assert(Src.getExtTypes().size() == 1 &&
"Expected Src of SUBREG_TO_REG to have one result type");
// Attempt to infer the subregister source from the first child. If it has
// an explicitly given register class, we'll use that. Otherwise, we will
// fail.
- auto SubClass = inferRegClassFromPattern(Dst->getChild(1));
+ auto SubClass = inferRegClassFromPattern(Dst.getChild(1));
if (!SubClass)
return failedImport(
"Cannot infer register class from SUBREG_TO_REG child #1");
// We don't have a child to look at that might have a super register node.
auto SuperClass =
- inferSuperRegisterClass(Src->getExtType(0), Dst->getChild(2));
+ inferSuperRegisterClass(Src.getExtType(0), Dst.getChild(2));
if (!SuperClass)
return failedImport(
"Cannot infer register class for SUBREG_TO_REG operand #0");
M.addAction<ConstrainOperandToRegClassAction>(0, 0, **SuperClass);
M.addAction<ConstrainOperandToRegClassAction>(0, 2, **SubClass);
} else if (DstIName == "REG_SEQUENCE") {
- auto SuperClass = inferRegClassFromPattern(Dst->getChild(0));
+ auto SuperClass = inferRegClassFromPattern(Dst.getChild(0));
M.addAction<ConstrainOperandToRegClassAction>(0, 0, **SuperClass);
- unsigned Num = Dst->getNumChildren();
+ unsigned Num = Dst.getNumChildren();
for (unsigned I = 1; I != Num; I += 2) {
- TreePatternNode *SubRegChild = Dst->getChild(I + 1);
+ TreePatternNode &SubRegChild = Dst.getChild(I + 1);
auto SubIdx = inferSubRegIndexForNode(SubRegChild);
if (!SubIdx)
More information about the llvm-commits
mailing list