Skip to content

Commit aa5ebfd

Browse files
committed
[ValueLattice] Make mark* functions public, return if value changed.
This patch prepares ValueLatticeElement to be used by SCCP, by: * making the mark* functions public * make the mark* functions return a bool indicating if the value has changed. Reviewers: efriedma, davide, mssimpso, nikic Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D60581
1 parent 4abbace commit aa5ebfd

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

llvm/include/llvm/Analysis/ValueLattice.h

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class ValueLatticeElement {
140140
}
141141

142142
bool isUndefined() const { return Tag == undefined; }
143+
bool isUnknown() const { return Tag == undefined; }
143144
bool isConstant() const { return Tag == constant; }
144145
bool isNotConstant() const { return Tag == notconstant; }
145146
bool isConstantRange() const { return Tag == constantrange; }
@@ -170,71 +171,75 @@ class ValueLatticeElement {
170171
return None;
171172
}
172173

173-
private:
174-
void markOverdefined() {
174+
bool markOverdefined() {
175175
if (isOverdefined())
176-
return;
176+
return false;
177177
if (isConstant() || isNotConstant())
178178
ConstVal = nullptr;
179179
if (isConstantRange())
180180
Range.~ConstantRange();
181181
Tag = overdefined;
182+
return true;
182183
}
183184

184-
void markConstant(Constant *V) {
185-
assert(V && "Marking constant with NULL");
186-
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
187-
markConstantRange(ConstantRange(CI->getValue()));
188-
return;
189-
}
185+
bool markConstant(Constant *V) {
190186
if (isa<UndefValue>(V))
191-
return;
187+
return false;
188+
189+
if (isConstant()) {
190+
assert(getConstant() == V && "Marking constant with different value");
191+
return false;
192+
}
193+
194+
if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
195+
return markConstantRange(ConstantRange(CI->getValue()));
192196

193-
assert((!isConstant() || getConstant() == V) &&
194-
"Marking constant with different value");
195197
assert(isUndefined());
196198
Tag = constant;
197199
ConstVal = V;
200+
return true;
198201
}
199202

200-
void markNotConstant(Constant *V) {
203+
bool markNotConstant(Constant *V) {
201204
assert(V && "Marking constant with NULL");
202-
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
203-
markConstantRange(ConstantRange(CI->getValue() + 1, CI->getValue()));
204-
return;
205-
}
205+
if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
206+
return markConstantRange(
207+
ConstantRange(CI->getValue() + 1, CI->getValue()));
208+
206209
if (isa<UndefValue>(V))
207-
return;
210+
return false;
208211

209-
assert((!isConstant() || getConstant() != V) &&
210-
"Marking constant !constant with same value");
211-
assert((!isNotConstant() || getNotConstant() == V) &&
212-
"Marking !constant with different value");
213-
assert(isUndefined() || isConstant());
212+
if (isNotConstant()) {
213+
assert(getNotConstant() == V && "Marking !constant with different value");
214+
return false;
215+
}
216+
217+
assert(isUndefined());
214218
Tag = notconstant;
215219
ConstVal = V;
220+
return true;
216221
}
217222

218-
void markConstantRange(ConstantRange NewR) {
223+
bool markConstantRange(ConstantRange NewR) {
219224
if (isConstantRange()) {
220225
if (NewR.isEmptySet())
221226
markOverdefined();
222227
else {
228+
assert(NewR.contains(getConstantRange()) && "Existing range must be a subset of NewR");
223229
Range = std::move(NewR);
224230
}
225-
return;
231+
return true;
226232
}
227233

228234
assert(isUndefined());
229235
if (NewR.isEmptySet())
230-
markOverdefined();
231-
else {
232-
Tag = constantrange;
233-
new (&Range) ConstantRange(std::move(NewR));
234-
}
236+
return markOverdefined();
237+
238+
Tag = constantrange;
239+
new (&Range) ConstantRange(std::move(NewR));
240+
return true;
235241
}
236242

237-
public:
238243
/// Updates this object to approximate both this object and RHS. Returns
239244
/// true if this object has been changed.
240245
bool mergeIn(const ValueLatticeElement &RHS, const DataLayout &DL) {
@@ -273,12 +278,11 @@ class ValueLatticeElement {
273278
}
274279
ConstantRange NewR = getConstantRange().unionWith(RHS.getConstantRange());
275280
if (NewR.isFullSet())
276-
markOverdefined();
281+
return markOverdefined();
277282
else if (NewR == getConstantRange())
278283
return false;
279284
else
280-
markConstantRange(std::move(NewR));
281-
return true;
285+
return markConstantRange(std::move(NewR));
282286
}
283287

284288
/// Compares this symbolic value with Other using Pred and returns either

0 commit comments

Comments
 (0)