From: Craig Topper Date: Tue, 18 Apr 2023 08:19:29 +0000 (-0700) Subject: [TableGen] Const-correct TreePatternNode::getChild. NFC X-Git-Tag: upstream/17.0.6~11235 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46b536f82251c74db1bc57e9da3fd555128fa041;p=platform%2Fupstream%2Fllvm.git [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*. --- diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.h b/llvm/utils/TableGen/CodeGenDAGPatterns.h index 998ba96..d03695f 100644 --- a/llvm/utils/TableGen/CodeGenDAGPatterns.h +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.h @@ -726,7 +726,10 @@ public: } 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 592dd38..21043bc 100644 --- a/llvm/utils/TableGen/GlobalISelEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp @@ -3712,7 +3712,7 @@ private: Expected 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 @@ private: /// If no register class is found, return std::nullopt. std::optional inferSuperRegisterClassForNode(const TypeSetByHwMode &Ty, - TreePatternNode *SuperRegNode, - TreePatternNode *SubRegIdxNode); + const TreePatternNode *SuperRegNode, + const TreePatternNode *SubRegIdxNode); std::optional - 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 inferSuperRegisterClass(const TypeSetByHwMode &Ty, - TreePatternNode *SubRegIdxNode); + const TreePatternNode *SubRegIdxNode); /// Return the CodeGenRegisterClass associated with \p Leaf if it has one. std::optional - getRegClassFromLeaf(TreePatternNode *Leaf); + getRegClassFromLeaf(const TreePatternNode *Leaf); /// Return a CodeGenRegisterClass for \p N if one can be found. Return /// std::nullopt otherwise. std::optional - inferRegClassFromPattern(TreePatternNode *N); + inferRegClassFromPattern(const TreePatternNode *N); /// Return the size of the MemoryVT in this predicate, if possible. std::optional @@ -4166,7 +4166,7 @@ Expected 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(SrcChild->getLeafValue()); Record *CCDef = DI ? DI->getDef() : nullptr; @@ -4194,8 +4194,8 @@ Expected 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 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 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 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 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(SubRegChild->getLeafValue())) { @@ -5098,7 +5098,7 @@ Error GlobalISelEmitter::importImplicitDefRenderers( } std::optional -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 -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 -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 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 -GlobalISelEmitter::inferSubRegIndexForNode(TreePatternNode *SubRegIdxNode) { +std::optional GlobalISelEmitter::inferSubRegIndexForNode( + const TreePatternNode *SubRegIdxNode) { if (!SubRegIdxNode->isLeaf()) return std::nullopt;