Skip to content

Commit

Permalink
constify getUnderlyingObject implementation [nfc]
Browse files Browse the repository at this point in the history
  • Loading branch information
preames authored and arichardson committed Mar 30, 2021
2 parents 141d21c + d9a29a6 commit 3e8a899
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions llvm/include/llvm/Analysis/ValueTracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,11 @@ constexpr unsigned MaxAnalysisRecursionDepth = 6;
/// that the returned value has pointer type if the specified value does. If
/// the MaxLookup value is non-zero, it limits the number of instructions to
/// be stripped off.
Value *getUnderlyingObject(Value *V, unsigned MaxLookup = 6);
inline const Value *getUnderlyingObject(const Value *V,
unsigned MaxLookup = 6) {
return getUnderlyingObject(const_cast<Value *>(V), MaxLookup);
const Value *getUnderlyingObject(const Value *V, unsigned MaxLookup = 6);
inline Value *getUnderlyingObject(Value *V, unsigned MaxLookup = 6) {
// Force const to avoid infinite recursion.
const Value *VConst = V;
return const_cast<Value *>(getUnderlyingObject(VConst, MaxLookup));
}

/// This method is similar to getUnderlyingObject except that it can
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4299,18 +4299,18 @@ static bool isSameUnderlyingObjectInLoop(const PHINode *PN,
return true;
}

Value *llvm::getUnderlyingObject(Value *V, unsigned MaxLookup) {
const Value *llvm::getUnderlyingObject(const Value *V, unsigned MaxLookup) {
if (!V->getType()->isPointerTy())
return V;
for (unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
V = GEP->getPointerOperand();
} else if (Operator::getOpcode(V) == Instruction::BitCast ||
Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
V = cast<Operator>(V)->getOperand(0);
if (!V->getType()->isPointerTy())
return V;
} else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
} else if (auto *GA = dyn_cast<GlobalAlias>(V)) {
if (GA->isInterposable())
return V;
V = GA->getAliasee();
Expand Down

0 comments on commit 3e8a899

Please sign in to comment.