Skip to content

Commit d9a29a6

Browse files
committed
constify getUnderlyingObject implementation [nfc]
1 parent ebe6161 commit d9a29a6

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,11 @@ constexpr unsigned MaxAnalysisRecursionDepth = 6;
370370
/// that the returned value has pointer type if the specified value does. If
371371
/// the MaxLookup value is non-zero, it limits the number of instructions to
372372
/// be stripped off.
373-
Value *getUnderlyingObject(Value *V, unsigned MaxLookup = 6);
374-
inline const Value *getUnderlyingObject(const Value *V,
375-
unsigned MaxLookup = 6) {
376-
return getUnderlyingObject(const_cast<Value *>(V), MaxLookup);
373+
const Value *getUnderlyingObject(const Value *V, unsigned MaxLookup = 6);
374+
inline Value *getUnderlyingObject(Value *V, unsigned MaxLookup = 6) {
375+
// Force const to avoid infinite recursion.
376+
const Value *VConst = V;
377+
return const_cast<Value *>(getUnderlyingObject(VConst, MaxLookup));
377378
}
378379

379380
/// This method is similar to getUnderlyingObject except that it can

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4162,18 +4162,18 @@ static bool isSameUnderlyingObjectInLoop(const PHINode *PN,
41624162
return true;
41634163
}
41644164

4165-
Value *llvm::getUnderlyingObject(Value *V, unsigned MaxLookup) {
4165+
const Value *llvm::getUnderlyingObject(const Value *V, unsigned MaxLookup) {
41664166
if (!V->getType()->isPointerTy())
41674167
return V;
41684168
for (unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
4169-
if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
4169+
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
41704170
V = GEP->getPointerOperand();
41714171
} else if (Operator::getOpcode(V) == Instruction::BitCast ||
41724172
Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
41734173
V = cast<Operator>(V)->getOperand(0);
41744174
if (!V->getType()->isPointerTy())
41754175
return V;
4176-
} else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
4176+
} else if (auto *GA = dyn_cast<GlobalAlias>(V)) {
41774177
if (GA->isInterposable())
41784178
return V;
41794179
V = GA->getAliasee();

0 commit comments

Comments
 (0)