As commented on D67557 we have a lot of uses of depth checks all using magic numbers.
This patch adds the SelectionDAG::MaxRecursionDepth constant and moves over some general cases to use this explicitly.
Differential Revision: https://reviews.llvm.org/D67711
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372315
91177308-0d34-0410-b5e6-
96231b3b80d8
Node->OperandList = nullptr;
}
void CreateTopologicalOrder(std::vector<SDNode*>& Order);
+
public:
+ // Maximum depth for recursive analysis such as computeKnownBits, etc.
+ static constexpr unsigned MaxRecursionDepth = 6;
+
explicit SelectionDAG(const TargetMachine &TM, CodeGenOpt::Level);
SelectionDAG(const SelectionDAG &) = delete;
SelectionDAG &operator=(const SelectionDAG &) = delete;
return 0;
// Don't recurse exponentially.
- if (Depth > 6)
+ if (Depth > SelectionDAG::MaxRecursionDepth)
return 0;
switch (Op.getOpcode()) {
if (Op.getOpcode() == ISD::FNEG)
return Op.getOperand(0);
- assert(Depth <= 6 && "GetNegatedExpression doesn't match isNegatibleForFree");
+ assert(Depth <= SelectionDAG::MaxRecursionDepth &&
+ "GetNegatedExpression doesn't match isNegatibleForFree");
const TargetOptions &Options = DAG.getTarget().Options;
const SDNodeFlags Flags = Op->getFlags();
return Known;
}
- if (Depth >= 6)
+ if (Depth >= MaxRecursionDepth)
return Known; // Limit search depth.
KnownBits Known2;
return Val.getNumSignBits();
}
- if (Depth >= 6)
+ if (Depth >= MaxRecursionDepth)
return 1; // Limit search depth.
if (!DemandedElts)
if (getTarget().Options.NoNaNsFPMath || Op->getFlags().hasNoNaNs())
return true;
- if (Depth >= 6)
+ if (Depth >= MaxRecursionDepth)
return false; // Limit search depth.
// TODO: Handle vectors.
SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts,
SelectionDAG &DAG, unsigned Depth) const {
// Limit search depth.
- if (Depth >= 6)
+ if (Depth >= SelectionDAG::MaxRecursionDepth)
return SDValue();
// Ignore UNDEFs.
} else if (OriginalDemandedBits == 0 || OriginalDemandedElts == 0) {
// Not demanding any bits/elts from Op.
return TLO.CombineTo(Op, TLO.DAG.getUNDEF(VT));
- } else if (Depth >= 6) { // Limit search depth.
+ } else if (Depth >= SelectionDAG::MaxRecursionDepth) {
+ // Limit search depth.
return false;
}
}
// Limit search depth.
- if (Depth >= 6)
+ if (Depth >= SelectionDAG::MaxRecursionDepth)
return false;
SDLoc DL(Op);
}
static void getUsefulBits(SDValue Op, APInt &UsefulBits, unsigned Depth) {
- if (Depth >= 6)
+ if (Depth >= SelectionDAG::MaxRecursionDepth)
return;
// Initialize UsefulBits
if (!Depth) {