[llvm] 46b536f - [TableGen] Const-correct TreePatternNode::getChild. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 18 01:22:01 PDT 2023
Author: Craig Topper
Date: 2023-04-18T01:20:42-07:00
New Revision: 46b536f82251c74db1bc57e9da3fd555128fa041
URL: https://github.com/llvm/llvm-project/commit/46b536f82251c74db1bc57e9da3fd555128fa041
DIFF: https://github.com/llvm/llvm-project/commit/46b536f82251c74db1bc57e9da3fd555128fa041.diff
LOG: [TableGen] Const-correct TreePatternNode::getChild. NFC
Make the const version return a const TreePatterNode* and add a non-const
version to return a non-const TreePatternNode*.
Added:
Modified:
llvm/utils/TableGen/CodeGenDAGPatterns.h
llvm/utils/TableGen/GlobalISelEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.h b/llvm/utils/TableGen/CodeGenDAGPatterns.h
index 998ba968f072..d03695fd54e3 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.h
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.h
@@ -726,7 +726,10 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
}
unsigned getNumChildren() const { return Children.size(); }
- 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(); }
const TreePatternNodePtr &getChildShared(unsigned N) const {
return Children[N];
}
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index 592dd38582ab..21043bca6643 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -3712,7 +3712,7 @@ class GlobalISelEmitter {
Expected<action_iterator>
importExplicitUseRenderer(action_iterator InsertPt, RuleMatcher &Rule,
BuildMIAction &DstMIBuilder,
- TreePatternNode *DstChild);
+ const TreePatternNode *DstChild);
Error importDefaultOperandRenderers(action_iterator InsertPt, RuleMatcher &M,
BuildMIAction &DstMIBuilder,
DagInit *DefaultOps) const;
@@ -3745,25 +3745,25 @@ class GlobalISelEmitter {
/// If no register class is found, return std::nullopt.
std::optional<const CodeGenRegisterClass *>
inferSuperRegisterClassForNode(const TypeSetByHwMode &Ty,
- TreePatternNode *SuperRegNode,
- TreePatternNode *SubRegIdxNode);
+ const TreePatternNode *SuperRegNode,
+ const TreePatternNode *SubRegIdxNode);
std::optional<CodeGenSubRegIndex *>
- inferSubRegIndexForNode(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,
- TreePatternNode *SubRegIdxNode);
+ const TreePatternNode *SubRegIdxNode);
/// Return the CodeGenRegisterClass associated with \p Leaf if it has one.
std::optional<const CodeGenRegisterClass *>
- getRegClassFromLeaf(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(TreePatternNode *N);
+ inferRegClassFromPattern(const TreePatternNode *N);
/// Return the size of the MemoryVT in this predicate, if possible.
std::optional<unsigned>
@@ -4166,7 +4166,7 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
bool IsFCmp = SrcGIOrNull->TheDef->getName() == "G_FCMP";
if (IsFCmp || SrcGIOrNull->TheDef->getName() == "G_ICMP") {
- TreePatternNode *SrcChild = Src->getChild(NumChildren - 1);
+ const TreePatternNode *SrcChild = Src->getChild(NumChildren - 1);
if (SrcChild->isLeaf()) {
DefInit *DI = dyn_cast<DefInit>(SrcChild->getLeafValue());
Record *CCDef = DI ? DI->getDef() : nullptr;
@@ -4194,8 +4194,8 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
if (IsAtomic && SrcGIOrNull->TheDef->getName() == "G_STORE") {
assert(NumChildren == 2 && "wrong operands for atomic store");
- TreePatternNode *PtrChild = Src->getChild(0);
- TreePatternNode *ValueChild = Src->getChild(1);
+ const TreePatternNode *PtrChild = Src->getChild(0);
+ const TreePatternNode *ValueChild = Src->getChild(1);
if (auto Error = importChildMatcher(Rule, InsnMatcher, PtrChild, true,
false, 1, TempOpIdx))
@@ -4216,7 +4216,7 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
return failedImport("Expected IntInit containing intrinsic ID)");
for (unsigned i = 0; i != NumChildren; ++i) {
- 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
@@ -4510,7 +4510,7 @@ Error GlobalISelEmitter::importChildMatcher(
Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderer(
action_iterator InsertPt, RuleMatcher &Rule, BuildMIAction &DstMIBuilder,
- TreePatternNode *DstChild) {
+ const TreePatternNode *DstChild) {
const auto &SubOperand = Rule.getComplexSubOperand(DstChild->getName());
if (SubOperand) {
@@ -4790,7 +4790,7 @@ GlobalISelEmitter::createAndImportSubInstructionRenderer(
unsigned Num = Dst->getNumChildren();
for (unsigned I = 1; I != Num; I += 2) {
- TreePatternNode *SubRegChild = Dst->getChild(I + 1);
+ const TreePatternNode *SubRegChild = Dst->getChild(I + 1);
auto SubIdx = inferSubRegIndexForNode(SubRegChild);
if (!SubIdx)
@@ -4885,7 +4885,7 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
return failedImport("EXTRACT_SUBREG child #1 is not a subreg index");
CodeGenSubRegIndex *SubIdx = CGRegs.getSubRegIdx(SubRegInit->getDef());
- TreePatternNode *ValChild = Dst->getChild(0);
+ 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.
@@ -4947,8 +4947,8 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
return failedImport("Malformed REG_SEQUENCE");
for (unsigned I = 1; I != ExpectedDstINumUses; I += 2) {
- TreePatternNode *ValChild = Dst->getChild(I);
- 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())) {
@@ -5098,7 +5098,7 @@ Error GlobalISelEmitter::importImplicitDefRenderers(
}
std::optional<const CodeGenRegisterClass *>
-GlobalISelEmitter::getRegClassFromLeaf(TreePatternNode *Leaf) {
+GlobalISelEmitter::getRegClassFromLeaf(const TreePatternNode *Leaf) {
assert(Leaf && "Expected node?");
assert(Leaf->isLeaf() && "Expected leaf?");
Record *RCRec = getInitValueAsRegClass(Leaf->getLeafValue());
@@ -5111,7 +5111,7 @@ GlobalISelEmitter::getRegClassFromLeaf(TreePatternNode *Leaf) {
}
std::optional<const CodeGenRegisterClass *>
-GlobalISelEmitter::inferRegClassFromPattern(TreePatternNode *N) {
+GlobalISelEmitter::inferRegClassFromPattern(const TreePatternNode *N) {
if (!N)
return std::nullopt;
@@ -5143,13 +5143,13 @@ GlobalISelEmitter::inferRegClassFromPattern(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.
- TreePatternNode *RCChild = N->getChild(IsRegSequence ? 0 : 1);
+ const TreePatternNode *RCChild = N->getChild(IsRegSequence ? 0 : 1);
if (!RCChild->isLeaf())
return std::nullopt;
return getRegClassFromLeaf(RCChild);
}
if (InstName == "INSERT_SUBREG") {
- TreePatternNode *Child0 = N->getChild(0);
+ 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));
@@ -5179,8 +5179,8 @@ GlobalISelEmitter::inferRegClassFromPattern(TreePatternNode *N) {
}
std::optional<const CodeGenRegisterClass *>
-GlobalISelEmitter::inferSuperRegisterClass(const TypeSetByHwMode &Ty,
- TreePatternNode *SubRegIdxNode) {
+GlobalISelEmitter::inferSuperRegisterClass(
+ const TypeSetByHwMode &Ty, const TreePatternNode *SubRegIdxNode) {
assert(SubRegIdxNode && "Expected subregister index node!");
// We need a ValueTypeByHwMode for getSuperRegForSubReg.
if (!Ty.isValueTypeByHwMode(false))
@@ -5204,8 +5204,8 @@ GlobalISelEmitter::inferSuperRegisterClass(const TypeSetByHwMode &Ty,
std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::inferSuperRegisterClassForNode(
- const TypeSetByHwMode &Ty, TreePatternNode *SuperRegNode,
- TreePatternNode *SubRegIdxNode) {
+ const TypeSetByHwMode &Ty, const TreePatternNode *SuperRegNode,
+ const TreePatternNode *SubRegIdxNode) {
assert(SuperRegNode && "Expected super register node!");
// 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
@@ -5218,8 +5218,8 @@ GlobalISelEmitter::inferSuperRegisterClassForNode(
return inferSuperRegisterClass(Ty, SubRegIdxNode);
}
-std::optional<CodeGenSubRegIndex *>
-GlobalISelEmitter::inferSubRegIndexForNode(TreePatternNode *SubRegIdxNode) {
+std::optional<CodeGenSubRegIndex *> GlobalISelEmitter::inferSubRegIndexForNode(
+ const TreePatternNode *SubRegIdxNode) {
if (!SubRegIdxNode->isLeaf())
return std::nullopt;
More information about the llvm-commits
mailing list