From: Florian Hahn Date: Fri, 18 Jan 2019 10:00:38 +0000 (+0000) Subject: [SelectionDAG] Add static getMaxNumOperands function to SDNode. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f55e902740f42a6b8f36556aad1f2dc53d7d5019;p=llvm [SelectionDAG] Add static getMaxNumOperands function to SDNode. Summary: Use this helper to make sure we use the same value at various places. This will likely be needed at more places were we currently crash because we use more operands than possible. Also makes it easier to change in the future. Reviewers: RKSimon, craig.topper, efriedma, aemerson Reviewed By: RKSimon Subscribers: hiraditya, arsenm, llvm-commits Differential Revision: https://reviews.llvm.org/D56859 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351537 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/SelectionDAGNodes.h b/include/llvm/CodeGen/SelectionDAGNodes.h index 10f28417908..f7554ad6648 100644 --- a/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/include/llvm/CodeGen/SelectionDAGNodes.h @@ -898,6 +898,11 @@ public: /// Return the number of values used by this operation. unsigned getNumOperands() const { return NumOperands; } + /// Return the maximum number of operands that a SDNode can hold. + static constexpr size_t getMaxNumOperands() { + return std::numeric_limits::max(); + } + /// Helper method returns the integer value of a ConstantSDNode operand. inline uint64_t getConstantOperandVal(unsigned Num) const; diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 647496c1afc..af81216e344 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -9266,8 +9266,7 @@ SDNode *SelectionDAG::isConstantFPBuildVectorOrConstantFP(SDValue N) { void SelectionDAG::createOperands(SDNode *Node, ArrayRef Vals) { assert(!Node->OperandList && "Node already has operands"); - assert(std::numeric_limits::max() >= - Vals.size() && + assert(SDNode::getMaxNumOperands() >= Vals.size() && "too many operands to fit into SDNode"); SDUse *Ops = OperandRecycler.allocate( ArrayRecycler::Capacity::get(Vals.size()), OperandAllocator); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 3390703c7ba..9f09f25f2ff 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1035,7 +1035,7 @@ SDValue SelectionDAGBuilder::getRoot() { // If we have >= 2^16 loads then split across multiple token factors as // there's a 64k limit on the number of SDNode operands. SDValue Root; - size_t Limit = (1 << 16) - 1; + size_t Limit = SDNode::getMaxNumOperands(); while (PendingLoads.size() > Limit) { unsigned SliceIdx = PendingLoads.size() - Limit; auto ExtractedTFs = ArrayRef(PendingLoads).slice(SliceIdx, Limit);