Skip to content

Commit

Permalink
[CallSite removal] Migrate all Alias Analysis APIs to use the newly
Browse files Browse the repository at this point in the history
minted `CallBase` class instead of the `CallSite` wrapper.

This moves the largest interwoven collection of APIs that traffic in
`CallSite`s. While a handful of these could have been migrated with
a minorly more shallow migration by converting from a `CallSite` to
a `CallBase`, it hardly seemed worth it. Most of the APIs needed to
migrate together because of the complex interplay of AA APIs and the
fact that converting from a `CallBase` to a `CallSite` isn't free in its
current implementation.

Out of tree users of these APIs can fairly reliably migrate with some
combination of `.getInstruction()` on the `CallSite` instance and
casting the resulting pointer. The most generic form will look like `CS`
-> `cast_or_null<CallBase>(CS.getInstruction())` but in most cases there
is a more elegant migration. Hopefully, this migrates enough APIs for
users to fully move from `CallSite` to the base class. All of the
in-tree users were easily migrated in that fashion.

Thanks for the review from Saleem!

Differential Revision: https://reviews.llvm.org/D55641

llvm-svn: 350503
  • Loading branch information
chandlerc committed Jan 7, 2019
1 parent f6f134e commit 363ac68
Show file tree
Hide file tree
Showing 32 changed files with 444 additions and 477 deletions.
110 changes: 44 additions & 66 deletions llvm/include/llvm/Analysis/AliasAnalysis.h
Expand Up @@ -43,7 +43,6 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
Expand Down Expand Up @@ -382,15 +381,15 @@ class AAResults {
/// \name Simple mod/ref information
/// @{

/// Get the ModRef info associated with a pointer argument of a callsite. The
/// Get the ModRef info associated with a pointer argument of a call. The
/// result's bits are set to indicate the allowed aliasing ModRef kinds. Note
/// that these bits do not necessarily account for the overall behavior of
/// the function, but rather only provide additional per-argument
/// information. This never sets ModRefInfo::Must.
ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx);
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx);

/// Return the behavior of the given call site.
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS);
FunctionModRefBehavior getModRefBehavior(const CallBase *Call);

/// Return the behavior when calling the given function.
FunctionModRefBehavior getModRefBehavior(const Function *F);
Expand All @@ -406,8 +405,8 @@ class AAResults {
/// property (e.g. calls to 'sin' and 'cos').
///
/// This property corresponds to the GCC 'const' attribute.
bool doesNotAccessMemory(ImmutableCallSite CS) {
return getModRefBehavior(CS) == FMRB_DoesNotAccessMemory;
bool doesNotAccessMemory(const CallBase *Call) {
return getModRefBehavior(Call) == FMRB_DoesNotAccessMemory;
}

/// Checks if the specified function is known to never read or write memory.
Expand All @@ -434,8 +433,8 @@ class AAResults {
/// absence of interfering store instructions, such as CSE of strlen calls.
///
/// This property corresponds to the GCC 'pure' attribute.
bool onlyReadsMemory(ImmutableCallSite CS) {
return onlyReadsMemory(getModRefBehavior(CS));
bool onlyReadsMemory(const CallBase *Call) {
return onlyReadsMemory(getModRefBehavior(Call));
}

/// Checks if the specified function is known to only read from non-volatile
Expand Down Expand Up @@ -500,36 +499,12 @@ class AAResults {

/// getModRefInfo (for call sites) - Return information about whether
/// a particular call site modifies or reads the specified memory location.
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc);
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);

/// getModRefInfo (for call sites) - A convenience wrapper.
ModRefInfo getModRefInfo(ImmutableCallSite CS, const Value *P,
LocationSize Size) {
return getModRefInfo(CS, MemoryLocation(P, Size));
}

/// getModRefInfo (for calls) - Return information about whether
/// a particular call modifies or reads the specified memory location.
ModRefInfo getModRefInfo(const CallInst *C, const MemoryLocation &Loc) {
return getModRefInfo(ImmutableCallSite(C), Loc);
}

/// getModRefInfo (for calls) - A convenience wrapper.
ModRefInfo getModRefInfo(const CallInst *C, const Value *P,
ModRefInfo getModRefInfo(const CallBase *Call, const Value *P,
LocationSize Size) {
return getModRefInfo(C, MemoryLocation(P, Size));
}

/// getModRefInfo (for invokes) - Return information about whether
/// a particular invoke modifies or reads the specified memory location.
ModRefInfo getModRefInfo(const InvokeInst *I, const MemoryLocation &Loc) {
return getModRefInfo(ImmutableCallSite(I), Loc);
}

/// getModRefInfo (for invokes) - A convenience wrapper.
ModRefInfo getModRefInfo(const InvokeInst *I, const Value *P,
LocationSize Size) {
return getModRefInfo(I, MemoryLocation(P, Size));
return getModRefInfo(Call, MemoryLocation(P, Size));
}

/// getModRefInfo (for loads) - Return information about whether
Expand Down Expand Up @@ -626,8 +601,8 @@ class AAResults {
ModRefInfo getModRefInfo(const Instruction *I,
const Optional<MemoryLocation> &OptLoc) {
if (OptLoc == None) {
if (auto CS = ImmutableCallSite(I)) {
return createModRefInfo(getModRefBehavior(CS));
if (const auto *Call = dyn_cast<CallBase>(I)) {
return createModRefInfo(getModRefBehavior(Call));
}
}

Expand Down Expand Up @@ -661,12 +636,12 @@ class AAResults {

/// Return information about whether a call and an instruction may refer to
/// the same memory locations.
ModRefInfo getModRefInfo(Instruction *I, ImmutableCallSite Call);
ModRefInfo getModRefInfo(Instruction *I, const CallBase *Call);

/// Return information about whether two call sites may refer to the same set
/// of memory locations. See the AA documentation for details:
/// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo
ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2);
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2);

/// Return information about whether a particular call site modifies
/// or reads the specified memory location \p MemLoc before instruction \p I
Expand Down Expand Up @@ -777,25 +752,25 @@ class AAResults::Concept {
/// that these bits do not necessarily account for the overall behavior of
/// the function, but rather only provide additional per-argument
/// information.
virtual ModRefInfo getArgModRefInfo(ImmutableCallSite CS,
virtual ModRefInfo getArgModRefInfo(const CallBase *Call,
unsigned ArgIdx) = 0;

/// Return the behavior of the given call site.
virtual FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS) = 0;
virtual FunctionModRefBehavior getModRefBehavior(const CallBase *Call) = 0;

/// Return the behavior when calling the given function.
virtual FunctionModRefBehavior getModRefBehavior(const Function *F) = 0;

/// getModRefInfo (for call sites) - Return information about whether
/// a particular call site modifies or reads the specified memory location.
virtual ModRefInfo getModRefInfo(ImmutableCallSite CS,
virtual ModRefInfo getModRefInfo(const CallBase *Call,
const MemoryLocation &Loc) = 0;

/// Return information about whether two call sites may refer to the same set
/// of memory locations. See the AA documentation for details:
/// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo
virtual ModRefInfo getModRefInfo(ImmutableCallSite CS1,
ImmutableCallSite CS2) = 0;
virtual ModRefInfo getModRefInfo(const CallBase *Call1,
const CallBase *Call2) = 0;

/// @}
};
Expand Down Expand Up @@ -827,26 +802,26 @@ template <typename AAResultT> class AAResults::Model final : public Concept {
return Result.pointsToConstantMemory(Loc, OrLocal);
}

ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx) override {
return Result.getArgModRefInfo(CS, ArgIdx);
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) override {
return Result.getArgModRefInfo(Call, ArgIdx);
}

FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
return Result.getModRefBehavior(CS);
FunctionModRefBehavior getModRefBehavior(const CallBase *Call) override {
return Result.getModRefBehavior(Call);
}

FunctionModRefBehavior getModRefBehavior(const Function *F) override {
return Result.getModRefBehavior(F);
}

ModRefInfo getModRefInfo(ImmutableCallSite CS,
ModRefInfo getModRefInfo(const CallBase *Call,
const MemoryLocation &Loc) override {
return Result.getModRefInfo(CS, Loc);
return Result.getModRefInfo(Call, Loc);
}

ModRefInfo getModRefInfo(ImmutableCallSite CS1,
ImmutableCallSite CS2) override {
return Result.getModRefInfo(CS1, CS2);
ModRefInfo getModRefInfo(const CallBase *Call1,
const CallBase *Call2) override {
return Result.getModRefInfo(Call1, Call2);
}
};

Expand Down Expand Up @@ -901,25 +876,28 @@ template <typename DerivedT> class AAResultBase {
: CurrentResult.pointsToConstantMemory(Loc, OrLocal);
}

ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx) {
return AAR ? AAR->getArgModRefInfo(CS, ArgIdx) : CurrentResult.getArgModRefInfo(CS, ArgIdx);
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) {
return AAR ? AAR->getArgModRefInfo(Call, ArgIdx)
: CurrentResult.getArgModRefInfo(Call, ArgIdx);
}

FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS) {
return AAR ? AAR->getModRefBehavior(CS) : CurrentResult.getModRefBehavior(CS);
FunctionModRefBehavior getModRefBehavior(const CallBase *Call) {
return AAR ? AAR->getModRefBehavior(Call)
: CurrentResult.getModRefBehavior(Call);
}

FunctionModRefBehavior getModRefBehavior(const Function *F) {
return AAR ? AAR->getModRefBehavior(F) : CurrentResult.getModRefBehavior(F);
}

ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc) {
return AAR ? AAR->getModRefInfo(CS, Loc)
: CurrentResult.getModRefInfo(CS, Loc);
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc) {
return AAR ? AAR->getModRefInfo(Call, Loc)
: CurrentResult.getModRefInfo(Call, Loc);
}

ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2) {
return AAR ? AAR->getModRefInfo(CS1, CS2) : CurrentResult.getModRefInfo(CS1, CS2);
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2) {
return AAR ? AAR->getModRefInfo(Call1, Call2)
: CurrentResult.getModRefInfo(Call1, Call2);
}
};

Expand Down Expand Up @@ -951,23 +929,23 @@ template <typename DerivedT> class AAResultBase {
return false;
}

ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx) {
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) {
return ModRefInfo::ModRef;
}

FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS) {
FunctionModRefBehavior getModRefBehavior(const CallBase *Call) {
return FMRB_UnknownModRefBehavior;
}

FunctionModRefBehavior getModRefBehavior(const Function *F) {
return FMRB_UnknownModRefBehavior;
}

ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc) {
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc) {
return ModRefInfo::ModRef;
}

ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2) {
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2) {
return ModRefInfo::ModRef;
}
};
Expand Down
10 changes: 5 additions & 5 deletions llvm/include/llvm/Analysis/BasicAliasAnalysis.h
Expand Up @@ -21,7 +21,7 @@
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
#include <algorithm>
Expand Down Expand Up @@ -84,18 +84,18 @@ class BasicAAResult : public AAResultBase<BasicAAResult> {

AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);

ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc);
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);

ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2);
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2);

/// Chases pointers until we find a (constant global) or not.
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);

/// Get the location associated with a pointer argument of a callsite.
ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx);
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx);

/// Returns the behavior when calling the given call site.
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS);
FunctionModRefBehavior getModRefBehavior(const CallBase *Call);

/// Returns the behavior when calling the given function. For use when the
/// call site is not known.
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/Analysis/GlobalsModRef.h
Expand Up @@ -88,7 +88,7 @@ class GlobalsAAResult : public AAResultBase<GlobalsAAResult> {
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);

using AAResultBase::getModRefInfo;
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc);
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);

/// getModRefBehavior - Return the behavior of the specified function if
/// called from the specified call site. The call site may be null in which
Expand All @@ -98,7 +98,7 @@ class GlobalsAAResult : public AAResultBase<GlobalsAAResult> {
/// getModRefBehavior - Return the behavior of the specified function if
/// called from the specified call site. The call site may be null in which
/// case the most generic behavior of this function should be returned.
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS);
FunctionModRefBehavior getModRefBehavior(const CallBase *Call);

private:
FunctionInfo *getFunctionInfo(const Function *F);
Expand All @@ -113,7 +113,7 @@ class GlobalsAAResult : public AAResultBase<GlobalsAAResult> {
void CollectSCCMembership(CallGraph &CG);

bool isNonEscapingGlobalNoAlias(const GlobalValue *GV, const Value *V);
ModRefInfo getModRefInfoForArgument(ImmutableCallSite CS,
ModRefInfo getModRefInfoForArgument(const CallBase *Call,
const GlobalValue *GV);
};

Expand Down
9 changes: 4 additions & 5 deletions llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h
Expand Up @@ -37,7 +37,6 @@
namespace llvm {

class AssumptionCache;
class CallSite;
class DominatorTree;
class Function;
class Instruction;
Expand Down Expand Up @@ -398,7 +397,7 @@ class MemoryDependenceResults {
/// invalidated on the next non-local query or when an instruction is
/// removed. Clients must copy this data if they want it around longer than
/// that.
const NonLocalDepInfo &getNonLocalCallDependency(CallSite QueryCS);
const NonLocalDepInfo &getNonLocalCallDependency(CallBase *QueryCall);

/// Perform a full dependency query for an access to the QueryInst's
/// specified memory location, returning the set of instructions that either
Expand Down Expand Up @@ -482,9 +481,9 @@ class MemoryDependenceResults {
void releaseMemory();

private:
MemDepResult getCallSiteDependencyFrom(CallSite C, bool isReadOnlyCall,
BasicBlock::iterator ScanIt,
BasicBlock *BB);
MemDepResult getCallDependencyFrom(CallBase *Call, bool isReadOnlyCall,
BasicBlock::iterator ScanIt,
BasicBlock *BB);
bool getNonLocalPointerDepFromBB(Instruction *QueryInst,
const PHITransAddr &Pointer,
const MemoryLocation &Loc, bool isLoad,
Expand Down
10 changes: 5 additions & 5 deletions llvm/include/llvm/Analysis/MemoryLocation.h
Expand Up @@ -16,9 +16,9 @@
#ifndef LLVM_ANALYSIS_MEMORYLOCATION_H
#define LLVM_ANALYSIS_MEMORYLOCATION_H

#include "llvm/ADT/Optional.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/IR/CallSite.h"
#include "llvm/ADT/Optional.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Metadata.h"

namespace llvm {
Expand Down Expand Up @@ -234,11 +234,11 @@ class MemoryLocation {
static MemoryLocation getForDest(const AnyMemIntrinsic *MI);

/// Return a location representing a particular argument of a call.
static MemoryLocation getForArgument(ImmutableCallSite CS, unsigned ArgIdx,
static MemoryLocation getForArgument(const CallBase *Call, unsigned ArgIdx,
const TargetLibraryInfo *TLI);
static MemoryLocation getForArgument(ImmutableCallSite CS, unsigned ArgIdx,
static MemoryLocation getForArgument(const CallBase *Call, unsigned ArgIdx,
const TargetLibraryInfo &TLI) {
return getForArgument(CS, ArgIdx, &TLI);
return getForArgument(Call, ArgIdx, &TLI);
}

explicit MemoryLocation(const Value *Ptr = nullptr,
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h
Expand Up @@ -60,7 +60,7 @@ class ObjCARCAAResult : public AAResultBase<ObjCARCAAResult> {
FunctionModRefBehavior getModRefBehavior(const Function *F);

using AAResultBase::getModRefInfo;
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc);
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);
};

/// Analysis pass providing a never-invalidated alias analysis result.
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/Analysis/ScopedNoAliasAA.h
Expand Up @@ -16,7 +16,7 @@
#define LLVM_ANALYSIS_SCOPEDNOALIASAA_H

#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
#include <memory>
Expand All @@ -41,8 +41,8 @@ class ScopedNoAliasAAResult : public AAResultBase<ScopedNoAliasAAResult> {
}

AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc);
ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2);
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2);

private:
bool mayAliasInScopes(const MDNode *Scopes, const MDNode *NoAlias) const;
Expand Down

0 comments on commit 363ac68

Please sign in to comment.