Skip to content

Commit 489fc1c

Browse files
committed
computeKnownBitsExhaustive + usecase + infinite recursion tracking
Change-Id: Icf0dac8c87812aa8edff53a1d5cdd664ab6d6d12
1 parent 0590e5e commit 489fc1c

File tree

12 files changed

+206
-65
lines changed

12 files changed

+206
-65
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,64 @@ template <typename T> class ArrayRef;
4545

4646
constexpr unsigned MaxAnalysisRecursionDepth = 6;
4747

48-
unsigned getAnalysisRecursionDepthLimit();
48+
class DepthLimit {
49+
public:
50+
static DepthLimit &get() {
51+
static DepthLimit Instance;
52+
return Instance;
53+
}
54+
55+
enum class VTCycle {
56+
KNOWNBIT = 0,
57+
KNOWNBITCOND = 1,
58+
NONZERO = 2,
59+
NONEQUAL = 3,
60+
IMPLIED = 4,
61+
FPCLASS = 5,
62+
RANGE = 6,
63+
SIGNBITS = 7,
64+
NOTUNDEFPOISON = 8,
65+
NONE = 9
66+
};
67+
68+
static unsigned getMaxRecursionDepth(VTCycle Cycle, const Value *I,
69+
unsigned Depth) {
70+
if (!get().RecursionDepthOverride || Cycle == VTCycle::NONE)
71+
return get().getMaxRecursionDepthImpl();
72+
73+
if (get().Encountered[Cycle].insert(I).second)
74+
return get().getMaxRecursionDepthImpl();
75+
76+
return Depth;
77+
}
78+
static unsigned getMaxRecursionDepth() {
79+
return get().getMaxRecursionDepthImpl();
80+
}
81+
static void setOverrideDepthLimit() { get().setOverrideDepthLimitImpl(); }
82+
static void resetOverrideDepthLimit() { get().resetOverrideDepthLimitImpl(); }
83+
84+
DepthLimit(const DepthLimit &) = delete;
85+
DepthLimit &operator=(const DepthLimit &) = delete;
86+
87+
private:
88+
DepthLimit() {}
89+
90+
const unsigned MaxAnalysisRecurionsDpeth = 6;
91+
bool RecursionDepthOverride = false;
92+
93+
DenseMap<VTCycle, SmallPtrSet<const Value *, 8>> Encountered;
94+
95+
unsigned getMaxRecursionDepthImpl() {
96+
return RecursionDepthOverride ? -1 : MaxAnalysisRecurionsDpeth;
97+
}
98+
99+
void setOverrideDepthLimitImpl() { RecursionDepthOverride = true; }
100+
101+
void resetOverrideDepthLimitImpl() {
102+
RecursionDepthOverride = false;
103+
Encountered.clear();
104+
}
105+
};
49106

50107
/// Determine which bits of V are known to be either zero or one and return
51108
/// them in the KnownZero/KnownOne bit sets.
@@ -88,6 +145,13 @@ LLVM_ABI KnownBits computeKnownBits(const Value *V, const SimplifyQuery &Q,
88145
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known,
89146
const SimplifyQuery &Q, unsigned Depth = 0);
90147

148+
void computeKnownBitsExhaustive(const Value *V, KnownBits &Known,
149+
const DataLayout &DL,
150+
AssumptionCache *AC = nullptr,
151+
const Instruction *CxtI = nullptr,
152+
const DominatorTree *DT = nullptr,
153+
bool UseInstrInfo = true);
154+
91155
/// Compute known bits from the range metadata.
92156
/// \p KnownZero the set of bits that are known to be zero
93157
/// \p KnownOne the set of bits that are known to be one

0 commit comments

Comments
 (0)