#ifndef LLVM_ANALYSIS_GLOBALSMODREF_H
#define LLVM_ANALYSIS_GLOBALSMODREF_H
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Pass.h"
#include <list>
namespace llvm {
class CallGraph;
class Function;
class GlobalsAAResult : public AAResultBase<GlobalsAAResult> {
friend AAResultBase<GlobalsAAResult>;
class FunctionInfo;
const DataLayout &DL;
std::function<const TargetLibraryInfo &(Function &F)> GetTLI;
SmallPtrSet<const GlobalValue *, 8> NonAddressTakenGlobals;
bool UnknownFunctionsWithLocalLinkage = false;
SmallPtrSet<const GlobalValue *, 8> IndirectGlobals;
DenseMap<const Value *, const GlobalValue *> AllocsForIndirectGlobals;
DenseMap<const Function *, FunctionInfo> FunctionInfos;
DenseMap<const Function *, unsigned> FunctionToSCCMap;
struct DeletionCallbackHandle final : CallbackVH {
GlobalsAAResult *GAR;
std::list<DeletionCallbackHandle>::iterator I;
DeletionCallbackHandle(GlobalsAAResult &GAR, Value *V)
: CallbackVH(V), GAR(&GAR) {}
void deleted() override;
};
std::list<DeletionCallbackHandle> Handles;
explicit GlobalsAAResult(
const DataLayout &DL,
std::function<const TargetLibraryInfo &(Function &F)> GetTLI);
friend struct RecomputeGlobalsAAPass;
public:
GlobalsAAResult(GlobalsAAResult &&Arg);
~GlobalsAAResult();
bool invalidate(Module &M, const PreservedAnalyses &PA,
ModuleAnalysisManager::Invalidator &);
static GlobalsAAResult
analyzeModule(Module &M,
std::function<const TargetLibraryInfo &(Function &F)> GetTLI,
CallGraph &CG);
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
AAQueryInfo &AAQI);
using AAResultBase::getModRefInfo;
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
AAQueryInfo &AAQI);
using AAResultBase::getModRefBehavior;
FunctionModRefBehavior getModRefBehavior(const Function *F);
private:
FunctionInfo *getFunctionInfo(const Function *F);
void AnalyzeGlobals(Module &M);
void AnalyzeCallGraph(CallGraph &CG, Module &M);
bool AnalyzeUsesOfPointer(Value *V,
SmallPtrSetImpl<Function *> *Readers = nullptr,
SmallPtrSetImpl<Function *> *Writers = nullptr,
GlobalValue *OkayStoreDest = nullptr);
bool AnalyzeIndirectGlobalMemory(GlobalVariable *GV);
void CollectSCCMembership(CallGraph &CG);
bool isNonEscapingGlobalNoAlias(const GlobalValue *GV, const Value *V);
ModRefInfo getModRefInfoForArgument(const CallBase *Call,
const GlobalValue *GV, AAQueryInfo &AAQI);
};
class GlobalsAA : public AnalysisInfoMixin<GlobalsAA> {
friend AnalysisInfoMixin<GlobalsAA>;
static AnalysisKey Key;
public:
typedef GlobalsAAResult Result;
GlobalsAAResult run(Module &M, ModuleAnalysisManager &AM);
};
struct RecomputeGlobalsAAPass : PassInfoMixin<RecomputeGlobalsAAPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
class GlobalsAAWrapperPass : public ModulePass {
std::unique_ptr<GlobalsAAResult> Result;
public:
static char ID;
GlobalsAAWrapperPass();
GlobalsAAResult &getResult() { return *Result; }
const GlobalsAAResult &getResult() const { return *Result; }
bool runOnModule(Module &M) override;
bool doFinalization(Module &M) override;
void getAnalysisUsage(AnalysisUsage &AU) const override;
};
ModulePass *createGlobalsAAWrapperPass();
}
#endif