Skip to content

Commit

Permalink
[NFC] Remove unused GetUnderlyingObject paramenter
Browse files Browse the repository at this point in the history
 Depends on D84617.

Differential Revision: https://reviews.llvm.org/D84621
  • Loading branch information
vitalybuka committed Jul 31, 2020
1 parent 4d6eec8 commit b0eb40c
Show file tree
Hide file tree
Showing 44 changed files with 114 additions and 143 deletions.
9 changes: 4 additions & 5 deletions llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
Expand Up @@ -64,10 +64,9 @@ inline bool ModuleHasARC(const Module &M) {
/// This is a wrapper around getUnderlyingObject which also knows how to
/// look through objc_retain and objc_autorelease calls, which we know to return
/// their argument verbatim.
inline const Value *GetUnderlyingObjCPtr(const Value *V,
const DataLayout &DL) {
inline const Value *GetUnderlyingObjCPtr(const Value *V) {
for (;;) {
V = getUnderlyingObject(V, DL);
V = getUnderlyingObject(V);
if (!IsForwarding(GetBasicARCInstKind(V)))
break;
V = cast<CallInst>(V)->getArgOperand(0);
Expand All @@ -78,12 +77,12 @@ inline const Value *GetUnderlyingObjCPtr(const Value *V,

/// A wrapper for GetUnderlyingObjCPtr used for results memoization.
inline const Value *
GetUnderlyingObjCPtrCached(const Value *V, const DataLayout &DL,
GetUnderlyingObjCPtrCached(const Value *V,
DenseMap<const Value *, WeakTrackingVH> &Cache) {
if (auto InCache = Cache.lookup(V))
return InCache;

const Value *Computed = GetUnderlyingObjCPtr(V, DL);
const Value *Computed = GetUnderlyingObjCPtr(V);
Cache[V] = const_cast<Value *>(Computed);
return Computed;
}
Expand Down
13 changes: 5 additions & 8 deletions llvm/include/llvm/Analysis/ValueTracking.h
Expand Up @@ -368,11 +368,10 @@ class Value;
/// 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, const DataLayout &DL,
unsigned MaxLookup = 6);
inline const Value *getUnderlyingObject(const Value *V, const DataLayout &DL,
Value *getUnderlyingObject(Value *V, unsigned MaxLookup = 6);
inline const Value *getUnderlyingObject(const Value *V,
unsigned MaxLookup = 6) {
return getUnderlyingObject(const_cast<Value *>(V), DL, MaxLookup);
return getUnderlyingObject(const_cast<Value *>(V), MaxLookup);
}

/// This method is similar to getUnderlyingObject except that it can
Expand Down Expand Up @@ -405,14 +404,12 @@ class Value;
/// it shouldn't look through the phi above.
void getUnderlyingObjects(const Value *V,
SmallVectorImpl<const Value *> &Objects,
const DataLayout &DL, LoopInfo *LI = nullptr,
unsigned MaxLookup = 6);
LoopInfo *LI = nullptr, unsigned MaxLookup = 6);

/// This is a wrapper around getUnderlyingObjects and adds support for basic
/// ptrtoint+arithmetic+inttoptr sequences.
bool getUnderlyingObjectsForCodeGen(const Value *V,
SmallVectorImpl<Value *> &Objects,
const DataLayout &DL);
SmallVectorImpl<Value *> &Objects);

/// Finds alloca where the value comes from.
AllocaInst *findAllocaForValue(Value *V);
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Analysis/AliasAnalysis.cpp
Expand Up @@ -641,8 +641,7 @@ ModRefInfo AAResults::callCapturesBefore(const Instruction *I,
if (!DT)
return ModRefInfo::ModRef;

const Value *Object =
getUnderlyingObject(MemLoc.Ptr, I->getModule()->getDataLayout());
const Value *Object = getUnderlyingObject(MemLoc.Ptr);
if (!isIdentifiedObject(Object) || isa<GlobalValue>(Object) ||
isa<Constant>(Object))
return ModRefInfo::ModRef;
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Analysis/BasicAliasAnalysis.cpp
Expand Up @@ -661,7 +661,7 @@ bool BasicAAResult::pointsToConstantMemory(const MemoryLocation &Loc,
SmallVector<const Value *, 16> Worklist;
Worklist.push_back(Loc.Ptr);
do {
const Value *V = getUnderlyingObject(Worklist.pop_back_val(), DL);
const Value *V = getUnderlyingObject(Worklist.pop_back_val());
if (!Visited.insert(V).second) {
Visited.clear();
return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
Expand Down Expand Up @@ -875,7 +875,7 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call,
assert(notDifferentParent(Call, Loc.Ptr) &&
"AliasAnalysis query involving multiple functions!");

const Value *Object = getUnderlyingObject(Loc.Ptr, DL);
const Value *Object = getUnderlyingObject(Loc.Ptr);

// Calls marked 'tail' cannot read or write allocas from the current frame
// because the current frame might be destroyed by the time they run. However,
Expand Down Expand Up @@ -1309,7 +1309,7 @@ bool BasicAAResult::isGEPBaseAtNegativeOffset(const GEPOperator *GEPOp,
/// another pointer.
///
/// We know that V1 is a GEP, but we don't know anything about V2.
/// UnderlyingV1 is getUnderlyingObject(GEP1, DL), UnderlyingV2 is the same for
/// UnderlyingV1 is getUnderlyingObject(GEP1), UnderlyingV2 is the same for
/// V2.
AliasResult BasicAAResult::aliasGEP(
const GEPOperator *GEP1, LocationSize V1Size, const AAMDNodes &V1AAInfo,
Expand Down Expand Up @@ -1782,10 +1782,10 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,

// Figure out what objects these things are pointing to if we can.
if (O1 == nullptr)
O1 = getUnderlyingObject(V1, DL, MaxLookupSearchDepth);
O1 = getUnderlyingObject(V1, MaxLookupSearchDepth);

if (O2 == nullptr)
O2 = getUnderlyingObject(V2, DL, MaxLookupSearchDepth);
O2 = getUnderlyingObject(V2, MaxLookupSearchDepth);

// Null values in the default address space don't point to any object, so they
// don't alias any other pointer.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/ConstantFolding.cpp
Expand Up @@ -718,7 +718,7 @@ Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty,

// If this load comes from anywhere in a constant global, and if the global
// is all undef or zero, we know what it loads.
if (auto *GV = dyn_cast<GlobalVariable>(getUnderlyingObject(CE, DL))) {
if (auto *GV = dyn_cast<GlobalVariable>(getUnderlyingObject(CE))) {
if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
if (GV->getInitializer()->isNullValue())
return Constant::getNullValue(Ty);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/DependenceAnalysis.cpp
Expand Up @@ -659,8 +659,8 @@ static AliasResult underlyingObjectsAlias(AAResults *AA,
return NoAlias;

// Check the underlying objects are the same
const Value *AObj = getUnderlyingObject(LocA.Ptr, DL);
const Value *BObj = getUnderlyingObject(LocB.Ptr, DL);
const Value *AObj = getUnderlyingObject(LocA.Ptr);
const Value *BObj = getUnderlyingObject(LocB.Ptr);

// If the underlying objects are the same, they must alias
if (AObj == BObj)
Expand Down
27 changes: 13 additions & 14 deletions llvm/lib/Analysis/GlobalsModRef.cpp
Expand Up @@ -435,8 +435,7 @@ bool GlobalsAAResult::AnalyzeIndirectGlobalMemory(GlobalVariable *GV) {
continue;

// Check the value being stored.
Value *Ptr = getUnderlyingObject(SI->getOperand(0),
GV->getParent()->getDataLayout());
Value *Ptr = getUnderlyingObject(SI->getOperand(0));

if (!isAllocLikeFn(Ptr, &GetTLI(*SI->getFunction())))
return false; // Too hard to analyze.
Expand Down Expand Up @@ -661,12 +660,12 @@ static bool isNonEscapingGlobalNoAliasWithLoad(const GlobalValue *GV,
return false;

if (auto *LI = dyn_cast<LoadInst>(Input)) {
Inputs.push_back(getUnderlyingObject(LI->getPointerOperand(), DL));
Inputs.push_back(getUnderlyingObject(LI->getPointerOperand()));
continue;
}
if (auto *SI = dyn_cast<SelectInst>(Input)) {
const Value *LHS = getUnderlyingObject(SI->getTrueValue(), DL);
const Value *RHS = getUnderlyingObject(SI->getFalseValue(), DL);
const Value *LHS = getUnderlyingObject(SI->getTrueValue());
const Value *RHS = getUnderlyingObject(SI->getFalseValue());
if (Visited.insert(LHS).second)
Inputs.push_back(LHS);
if (Visited.insert(RHS).second)
Expand All @@ -675,7 +674,7 @@ static bool isNonEscapingGlobalNoAliasWithLoad(const GlobalValue *GV,
}
if (auto *PN = dyn_cast<PHINode>(Input)) {
for (const Value *Op : PN->incoming_values()) {
Op = getUnderlyingObject(Op, DL);
Op = getUnderlyingObject(Op);
if (Visited.insert(Op).second)
Inputs.push_back(Op);
}
Expand Down Expand Up @@ -774,16 +773,16 @@ bool GlobalsAAResult::isNonEscapingGlobalNoAlias(const GlobalValue *GV,
if (auto *LI = dyn_cast<LoadInst>(Input)) {
// A pointer loaded from a global would have been captured, and we know
// that the global is non-escaping, so no alias.
const Value *Ptr = getUnderlyingObject(LI->getPointerOperand(), DL);
const Value *Ptr = getUnderlyingObject(LI->getPointerOperand());
if (isNonEscapingGlobalNoAliasWithLoad(GV, Ptr, Depth, DL))
// The load does not alias with GV.
continue;
// Otherwise, a load could come from anywhere, so bail.
return false;
}
if (auto *SI = dyn_cast<SelectInst>(Input)) {
const Value *LHS = getUnderlyingObject(SI->getTrueValue(), DL);
const Value *RHS = getUnderlyingObject(SI->getFalseValue(), DL);
const Value *LHS = getUnderlyingObject(SI->getTrueValue());
const Value *RHS = getUnderlyingObject(SI->getFalseValue());
if (Visited.insert(LHS).second)
Inputs.push_back(LHS);
if (Visited.insert(RHS).second)
Expand All @@ -792,7 +791,7 @@ bool GlobalsAAResult::isNonEscapingGlobalNoAlias(const GlobalValue *GV,
}
if (auto *PN = dyn_cast<PHINode>(Input)) {
for (const Value *Op : PN->incoming_values()) {
Op = getUnderlyingObject(Op, DL);
Op = getUnderlyingObject(Op);
if (Visited.insert(Op).second)
Inputs.push_back(Op);
}
Expand Down Expand Up @@ -827,8 +826,8 @@ AliasResult GlobalsAAResult::alias(const MemoryLocation &LocA,
const MemoryLocation &LocB,
AAQueryInfo &AAQI) {
// Get the base object these pointers point to.
const Value *UV1 = getUnderlyingObject(LocA.Ptr, DL);
const Value *UV2 = getUnderlyingObject(LocB.Ptr, DL);
const Value *UV1 = getUnderlyingObject(LocA.Ptr);
const Value *UV2 = getUnderlyingObject(LocB.Ptr);

// If either of the underlying values is a global, they may be non-addr-taken
// globals, which we can answer queries about.
Expand Down Expand Up @@ -915,7 +914,7 @@ ModRefInfo GlobalsAAResult::getModRefInfoForArgument(const CallBase *Call,
// is based on GV, return the conservative result.
for (auto &A : Call->args()) {
SmallVector<const Value*, 4> Objects;
getUnderlyingObjects(A, Objects, DL);
getUnderlyingObjects(A, Objects);

// All objects must be identified.
if (!all_of(Objects, isIdentifiedObject) &&
Expand All @@ -942,7 +941,7 @@ ModRefInfo GlobalsAAResult::getModRefInfo(const CallBase *Call,
// If we are asking for mod/ref info of a direct call with a pointer to a
// global we are tracking, return information if we have it.
if (const GlobalValue *GV =
dyn_cast<GlobalValue>(getUnderlyingObject(Loc.Ptr, DL)))
dyn_cast<GlobalValue>(getUnderlyingObject(Loc.Ptr)))
// If GV is internal to this IR and there is no function with local linkage
// that has had their address taken, keep looking for a tighter ModRefInfo.
if (GV->hasLocalLinkage() && !UnknownFunctionsWithLocalLinkage)
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Expand Up @@ -2524,8 +2524,8 @@ computePointerICmp(const DataLayout &DL, const TargetLibraryInfo *TLI,
// memory within the lifetime of the current function (allocas, byval
// arguments, globals), then determine the comparison result here.
SmallVector<const Value *, 8> LHSUObjs, RHSUObjs;
getUnderlyingObjects(LHS, LHSUObjs, DL);
getUnderlyingObjects(RHS, RHSUObjs, DL);
getUnderlyingObjects(LHS, LHSUObjs);
getUnderlyingObjects(RHS, RHSUObjs);

// Is the set of underlying objects all noalias calls?
auto IsNAC = [](ArrayRef<const Value *> Objects) {
Expand Down
17 changes: 6 additions & 11 deletions llvm/lib/Analysis/LazyValueInfo.cpp
Expand Up @@ -606,13 +606,11 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueImpl(
static bool InstructionDereferencesPointer(Instruction *I, Value *Ptr) {
if (LoadInst *L = dyn_cast<LoadInst>(I)) {
return L->getPointerAddressSpace() == 0 &&
getUnderlyingObject(L->getPointerOperand(),
L->getModule()->getDataLayout()) == Ptr;
getUnderlyingObject(L->getPointerOperand()) == Ptr;
}
if (StoreInst *S = dyn_cast<StoreInst>(I)) {
return S->getPointerAddressSpace() == 0 &&
getUnderlyingObject(S->getPointerOperand(),
S->getModule()->getDataLayout()) == Ptr;
getUnderlyingObject(S->getPointerOperand()) == Ptr;
}
if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(I)) {
if (MI->isVolatile()) return false;
Expand All @@ -622,13 +620,11 @@ static bool InstructionDereferencesPointer(Instruction *I, Value *Ptr) {
if (!Len || Len->isZero()) return false;

if (MI->getDestAddressSpace() == 0)
if (getUnderlyingObject(MI->getRawDest(),
MI->getModule()->getDataLayout()) == Ptr)
if (getUnderlyingObject(MI->getRawDest()) == Ptr)
return true;
if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(MI))
if (MTI->getSourceAddressSpace() == 0)
if (getUnderlyingObject(MTI->getRawSource(),
MTI->getModule()->getDataLayout()) == Ptr)
if (getUnderlyingObject(MTI->getRawSource()) == Ptr)
return true;
}
return false;
Expand All @@ -641,11 +637,10 @@ static bool InstructionDereferencesPointer(Instruction *I, Value *Ptr) {
static bool isObjectDereferencedInBlock(Value *Val, BasicBlock *BB) {
assert(Val->getType()->isPointerTy());

const DataLayout &DL = BB->getModule()->getDataLayout();
Value *UnderlyingVal = getUnderlyingObject(Val, DL);
Value *UnderlyingVal = getUnderlyingObject(Val);
// If 'getUnderlyingObject' didn't converge, skip it. It won't converge
// inside InstructionDereferencesPointer either.
if (UnderlyingVal == getUnderlyingObject(UnderlyingVal, DL, 1))
if (UnderlyingVal == getUnderlyingObject(UnderlyingVal, 1))
for (Instruction &I : *BB)
if (InstructionDereferencesPointer(&I, UnderlyingVal))
return true;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/Lint.cpp
Expand Up @@ -673,7 +673,7 @@ Value *Lint::findValueImpl(Value *V, bool OffsetOk,
// TODO: Look through eliminable cast pairs.
// TODO: Look through calls with unique return values.
// TODO: Look through vector insert/extract/shuffle.
V = OffsetOk ? getUnderlyingObject(V, *DL) : V->stripPointerCasts();
V = OffsetOk ? getUnderlyingObject(V) : V->stripPointerCasts();
if (LoadInst *L = dyn_cast<LoadInst>(V)) {
BasicBlock::iterator BBI = L->getIterator();
BasicBlock *BB = L->getParent();
Expand Down
17 changes: 7 additions & 10 deletions llvm/lib/Analysis/LoopAccessAnalysis.cpp
Expand Up @@ -508,10 +508,10 @@ class AccessAnalysis {
typedef PointerIntPair<Value *, 1, bool> MemAccessInfo;
typedef SmallVector<MemAccessInfo, 8> MemAccessInfoList;

AccessAnalysis(const DataLayout &Dl, Loop *TheLoop, AAResults *AA,
LoopInfo *LI, MemoryDepChecker::DepCandidates &DA,
AccessAnalysis(Loop *TheLoop, AAResults *AA, LoopInfo *LI,
MemoryDepChecker::DepCandidates &DA,
PredicatedScalarEvolution &PSE)
: DL(Dl), TheLoop(TheLoop), AST(*AA), LI(LI), DepCands(DA),
: TheLoop(TheLoop), AST(*AA), LI(LI), DepCands(DA),
IsRTCheckAnalysisNeeded(false), PSE(PSE) {}

/// Register a load and whether it is only read from.
Expand Down Expand Up @@ -585,8 +585,6 @@ class AccessAnalysis {
/// Set of all accesses.
PtrAccessSet Accesses;

const DataLayout &DL;

/// The loop being checked.
const Loop *TheLoop;

Expand Down Expand Up @@ -938,7 +936,7 @@ void AccessAnalysis::processMemAccesses() {
typedef SmallVector<const Value *, 16> ValueVector;
ValueVector TempObjects;

getUnderlyingObjects(Ptr, TempObjects, DL, LI);
getUnderlyingObjects(Ptr, TempObjects, LI);
LLVM_DEBUG(dbgs()
<< "Underlying objects for pointer " << *Ptr << "\n");
for (const Value *UnderlyingObj : TempObjects) {
Expand Down Expand Up @@ -1142,7 +1140,7 @@ bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, const DataLayout &DL,
// first pointer in the array.
Value *Ptr0 = VL[0];
const SCEV *Scev0 = SE.getSCEV(Ptr0);
Value *Obj0 = getUnderlyingObject(Ptr0, DL);
Value *Obj0 = getUnderlyingObject(Ptr0);

llvm::SmallSet<int64_t, 4> Offsets;
for (auto *Ptr : VL) {
Expand All @@ -1153,7 +1151,7 @@ bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, const DataLayout &DL,
return false;
// If a pointer refers to a different underlying object, bail - the
// pointers are by definition incomparable.
Value *CurrObj = getUnderlyingObject(Ptr, DL);
Value *CurrObj = getUnderlyingObject(Ptr);
if (CurrObj != Obj0)
return false;

Expand Down Expand Up @@ -1947,8 +1945,7 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
}

MemoryDepChecker::DepCandidates DependentAccesses;
AccessAnalysis Accesses(TheLoop->getHeader()->getModule()->getDataLayout(),
TheLoop, AA, LI, DependentAccesses, *PSE);
AccessAnalysis Accesses(TheLoop, AA, LI, DependentAccesses, *PSE);

// Holds the analyzed pointers. We don't want to call getUnderlyingObjects
// multiple times on the same object. If the ptr is accessed twice, once
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
Expand Up @@ -406,8 +406,6 @@ MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom(
isInvariantLoad = true;
}

const DataLayout &DL = BB->getModule()->getDataLayout();

// Return "true" if and only if the instruction I is either a non-simple
// load or a non-simple store.
auto isNonSimpleLoadOrStore = [](Instruction *I) -> bool {
Expand Down Expand Up @@ -576,7 +574,7 @@ MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom(
// looking for a clobber in many cases; that's an alias property and is
// handled by BasicAA.
if (isa<AllocaInst>(Inst) || isNoAliasFn(Inst, &TLI)) {
const Value *AccessPtr = getUnderlyingObject(MemLoc.Ptr, DL);
const Value *AccessPtr = getUnderlyingObject(MemLoc.Ptr);
if (AccessPtr == Inst || AA.isMustAlias(Inst, AccessPtr))
return MemDepResult::getDef(Inst);
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp
Expand Up @@ -54,8 +54,8 @@ AliasResult ObjCARCAAResult::alias(const MemoryLocation &LocA,

// If that failed, climb to the underlying object, including climbing through
// ObjC-specific no-ops, and try making an imprecise alias query.
const Value *UA = GetUnderlyingObjCPtr(SA, DL);
const Value *UB = GetUnderlyingObjCPtr(SB, DL);
const Value *UA = GetUnderlyingObjCPtr(SA);
const Value *UB = GetUnderlyingObjCPtr(SB);
if (UA != SA || UB != SB) {
Result = AAResultBase::alias(MemoryLocation(UA), MemoryLocation(UB), AAQI);
// We can't use MustAlias or PartialAlias results here because
Expand Down Expand Up @@ -83,7 +83,7 @@ bool ObjCARCAAResult::pointsToConstantMemory(const MemoryLocation &Loc,

// If that failed, climb to the underlying object, including climbing through
// ObjC-specific no-ops, and try making an imprecise alias query.
const Value *U = GetUnderlyingObjCPtr(S, DL);
const Value *U = GetUnderlyingObjCPtr(S);
if (U != S)
return AAResultBase::pointsToConstantMemory(MemoryLocation(U), AAQI,
OrLocal);
Expand Down

0 comments on commit b0eb40c

Please sign in to comment.