From 79fca6fea87be7221843031870bbf2c9ae1fc555 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 3 Aug 2010 21:48:53 +0000 Subject: [PATCH] Thread const correctness through a bunch of AliasAnalysis interfaces and eliminate several const_casts. Make CallSite implicitly convertible to ImmutableCallSite. Rename the getModRefBehavior for intrinsic IDs to getIntrinsicModRefBehavior to avoid overload ambiguity with CallSite, which happens to be implicitly convertible to bool. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110155 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/AliasAnalysis.h | 53 ++++++++-------- include/llvm/Analysis/LibCallAliasAnalysis.h | 11 ++-- include/llvm/Analysis/LibCallSemantics.h | 5 +- include/llvm/Support/CallSite.h | 21 ++++--- lib/Analysis/AliasAnalysis.cpp | 28 +++++---- lib/Analysis/AliasAnalysisCounter.cpp | 9 ++- lib/Analysis/AliasDebugger.cpp | 6 +- lib/Analysis/AliasSetTracker.cpp | 2 +- lib/Analysis/BasicAliasAnalysis.cpp | 24 +++++--- lib/Analysis/IPA/GlobalsModRef.cpp | 65 +++++++++++--------- lib/Analysis/LibCallAliasAnalysis.cpp | 7 ++- lib/Analysis/LibCallSemantics.cpp | 3 +- lib/Transforms/IPO/FunctionAttrs.cpp | 2 +- 13 files changed, 133 insertions(+), 103 deletions(-) diff --git a/include/llvm/Analysis/AliasAnalysis.h b/include/llvm/Analysis/AliasAnalysis.h index fbfdda53490..178049f554f 100644 --- a/include/llvm/Analysis/AliasAnalysis.h +++ b/include/llvm/Analysis/AliasAnalysis.h @@ -178,17 +178,17 @@ public: }; /// getModRefBehavior - Return the behavior when calling the given call site. - virtual ModRefBehavior getModRefBehavior(CallSite CS, + virtual ModRefBehavior getModRefBehavior(ImmutableCallSite CS, std::vector *Info = 0); /// getModRefBehavior - Return the behavior when calling the given function. /// For use when the call site is not known. - virtual ModRefBehavior getModRefBehavior(Function *F, + virtual ModRefBehavior getModRefBehavior(const Function *F, std::vector *Info = 0); - /// getModRefBehavior - Return the modref behavior of the intrinsic with the - /// given id. - static ModRefBehavior getModRefBehavior(unsigned iid); + /// getIntrinsicModRefBehavior - Return the modref behavior of the intrinsic + /// with the given id. + static ModRefBehavior getIntrinsicModRefBehavior(unsigned iid); /// doesNotAccessMemory - If the specified call is known to never read or /// write memory, return true. If the call only reads from known-constant @@ -201,14 +201,14 @@ public: /// /// This property corresponds to the GCC 'const' attribute. /// - bool doesNotAccessMemory(CallSite CS) { + bool doesNotAccessMemory(ImmutableCallSite CS) { return getModRefBehavior(CS) == DoesNotAccessMemory; } /// doesNotAccessMemory - If the specified function is known to never read or /// write memory, return true. For use when the call site is not known. /// - bool doesNotAccessMemory(Function *F) { + bool doesNotAccessMemory(const Function *F) { return getModRefBehavior(F) == DoesNotAccessMemory; } @@ -221,7 +221,7 @@ public: /// /// This property corresponds to the GCC 'pure' attribute. /// - bool onlyReadsMemory(CallSite CS) { + bool onlyReadsMemory(ImmutableCallSite CS) { ModRefBehavior MRB = getModRefBehavior(CS); return MRB == DoesNotAccessMemory || MRB == OnlyReadsMemory; } @@ -230,7 +230,7 @@ public: /// non-volatile memory (or not access memory at all), return true. For use /// when the call site is not known. /// - bool onlyReadsMemory(Function *F) { + bool onlyReadsMemory(const Function *F) { ModRefBehavior MRB = getModRefBehavior(F); return MRB == DoesNotAccessMemory || MRB == OnlyReadsMemory; } @@ -244,7 +244,8 @@ public: /// a particular call site modifies or reads the memory specified by the /// pointer. /// - virtual ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size); + virtual ModRefResult getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size); /// getModRefInfo - Return information about whether two call sites may refer /// to the same set of memory locations. This function returns NoModRef if @@ -252,28 +253,32 @@ public: /// written by CS2, Mod if CS1 writes to memory read or written by CS2, or /// ModRef if CS1 might read or write memory accessed by CS2. /// - virtual ModRefResult getModRefInfo(CallSite CS1, CallSite CS2); + virtual ModRefResult getModRefInfo(ImmutableCallSite CS1, + ImmutableCallSite CS2); public: /// Convenience functions... - ModRefResult getModRefInfo(LoadInst *L, Value *P, unsigned Size); - ModRefResult getModRefInfo(StoreInst *S, Value *P, unsigned Size); - ModRefResult getModRefInfo(CallInst *C, Value *P, unsigned Size) { - return getModRefInfo(CallSite(C), P, Size); + ModRefResult getModRefInfo(const LoadInst *L, const Value *P, unsigned Size); + ModRefResult getModRefInfo(const StoreInst *S, const Value *P, unsigned Size); + ModRefResult getModRefInfo(const CallInst *C, const Value *P, unsigned Size) { + return getModRefInfo(ImmutableCallSite(C), P, Size); } - ModRefResult getModRefInfo(InvokeInst *I, Value *P, unsigned Size) { - return getModRefInfo(CallSite(I), P, Size); + ModRefResult getModRefInfo(const InvokeInst *I, + const Value *P, unsigned Size) { + return getModRefInfo(ImmutableCallSite(I), P, Size); } - ModRefResult getModRefInfo(VAArgInst* I, Value* P, unsigned Size) { + ModRefResult getModRefInfo(const VAArgInst* I, + const Value* P, unsigned Size) { return AliasAnalysis::ModRef; } - ModRefResult getModRefInfo(Instruction *I, Value *P, unsigned Size) { + ModRefResult getModRefInfo(const Instruction *I, + const Value *P, unsigned Size) { switch (I->getOpcode()) { - case Instruction::VAArg: return getModRefInfo((VAArgInst*)I, P, Size); - case Instruction::Load: return getModRefInfo((LoadInst*)I, P, Size); - case Instruction::Store: return getModRefInfo((StoreInst*)I, P, Size); - case Instruction::Call: return getModRefInfo((CallInst*)I, P, Size); - case Instruction::Invoke: return getModRefInfo((InvokeInst*)I, P, Size); + case Instruction::VAArg: return getModRefInfo((const VAArgInst*)I, P,Size); + case Instruction::Load: return getModRefInfo((const LoadInst*)I, P, Size); + case Instruction::Store: return getModRefInfo((const StoreInst*)I, P,Size); + case Instruction::Call: return getModRefInfo((const CallInst*)I, P, Size); + case Instruction::Invoke: return getModRefInfo((const InvokeInst*)I,P,Size); default: return NoModRef; } } diff --git a/include/llvm/Analysis/LibCallAliasAnalysis.h b/include/llvm/Analysis/LibCallAliasAnalysis.h index c256230fc5d..37abb77dc2f 100644 --- a/include/llvm/Analysis/LibCallAliasAnalysis.h +++ b/include/llvm/Analysis/LibCallAliasAnalysis.h @@ -35,11 +35,13 @@ namespace llvm { } ~LibCallAliasAnalysis(); - ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size); + ModRefResult getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size); - ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) { + ModRefResult getModRefInfo(ImmutableCallSite CS1, + ImmutableCallSite CS2) { // TODO: Could compare two direct calls against each other if we cared to. - return AliasAnalysis::getModRefInfo(CS1,CS2); + return AliasAnalysis::getModRefInfo(CS1, CS2); } virtual void getAnalysisUsage(AnalysisUsage &AU) const; @@ -61,7 +63,8 @@ namespace llvm { private: ModRefResult AnalyzeLibCallDetails(const LibCallFunctionInfo *FI, - CallSite CS, Value *P, unsigned Size); + ImmutableCallSite CS, + const Value *P, unsigned Size); }; } // End of llvm namespace diff --git a/include/llvm/Analysis/LibCallSemantics.h b/include/llvm/Analysis/LibCallSemantics.h index 74e8401a1fe..31d7cc56ce5 100644 --- a/include/llvm/Analysis/LibCallSemantics.h +++ b/include/llvm/Analysis/LibCallSemantics.h @@ -47,7 +47,8 @@ namespace llvm { enum LocResult { Yes, No, Unknown }; - LocResult (*isLocation)(CallSite CS, const Value *Ptr, unsigned Size); + LocResult (*isLocation)(ImmutableCallSite CS, + const Value *Ptr, unsigned Size); }; /// LibCallFunctionInfo - Each record in the array of FunctionInfo structs @@ -142,7 +143,7 @@ namespace llvm { /// getFunctionInfo - Return the LibCallFunctionInfo object corresponding to /// the specified function if we have it. If not, return null. - const LibCallFunctionInfo *getFunctionInfo(Function *F) const; + const LibCallFunctionInfo *getFunctionInfo(const Function *F) const; //===------------------------------------------------------------------===// diff --git a/include/llvm/Support/CallSite.h b/include/llvm/Support/CallSite.h index d66e3cb6e4b..5c6632bdf3f 100644 --- a/include/llvm/Support/CallSite.h +++ b/include/llvm/Support/CallSite.h @@ -271,16 +271,6 @@ private: } }; -/// ImmutableCallSite - establish a view to a call site for examination -class ImmutableCallSite : public CallSiteBase<> { - typedef CallSiteBase<> Base; -public: - ImmutableCallSite(const Value* V) : Base(V) {} - ImmutableCallSite(const CallInst *CI) : Base(CI) {} - ImmutableCallSite(const InvokeInst *II) : Base(II) {} - ImmutableCallSite(const Instruction *II) : Base(II) {} -}; - class CallSite : public CallSiteBase { typedef CallSiteBase { + typedef CallSiteBase<> Base; +public: + ImmutableCallSite(const Value* V) : Base(V) {} + ImmutableCallSite(const CallInst *CI) : Base(CI) {} + ImmutableCallSite(const InvokeInst *II) : Base(II) {} + ImmutableCallSite(const Instruction *II) : Base(II) {} + ImmutableCallSite(CallSite CS) : Base(CS.getInstruction()) {} +}; + } // End llvm namespace #endif diff --git a/lib/Analysis/AliasAnalysis.cpp b/lib/Analysis/AliasAnalysis.cpp index 60ea2b4ba90..2ed5f37d415 100644 --- a/lib/Analysis/AliasAnalysis.cpp +++ b/lib/Analysis/AliasAnalysis.cpp @@ -65,7 +65,7 @@ void AliasAnalysis::copyValue(Value *From, Value *To) { } AliasAnalysis::ModRefResult -AliasAnalysis::getModRefInfo(CallSite CS1, CallSite CS2) { +AliasAnalysis::getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2) { // FIXME: we can do better. assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!"); return AA->getModRefInfo(CS1, CS2); @@ -77,7 +77,7 @@ AliasAnalysis::getModRefInfo(CallSite CS1, CallSite CS2) { //===----------------------------------------------------------------------===// AliasAnalysis::ModRefResult -AliasAnalysis::getModRefInfo(LoadInst *L, Value *P, unsigned Size) { +AliasAnalysis::getModRefInfo(const LoadInst *L, const Value *P, unsigned Size) { // If the load address doesn't alias the given address, it doesn't read // or write the specified memory. if (!alias(L->getOperand(0), getTypeStoreSize(L->getType()), P, Size)) @@ -92,7 +92,7 @@ AliasAnalysis::getModRefInfo(LoadInst *L, Value *P, unsigned Size) { } AliasAnalysis::ModRefResult -AliasAnalysis::getModRefInfo(StoreInst *S, Value *P, unsigned Size) { +AliasAnalysis::getModRefInfo(const StoreInst *S, const Value *P, unsigned Size) { // If the stored address cannot alias the pointer in question, then the // pointer cannot be modified by the store. if (!alias(S->getOperand(1), @@ -113,7 +113,7 @@ AliasAnalysis::getModRefInfo(StoreInst *S, Value *P, unsigned Size) { } AliasAnalysis::ModRefBehavior -AliasAnalysis::getModRefBehavior(CallSite CS, +AliasAnalysis::getModRefBehavior(ImmutableCallSite CS, std::vector *Info) { if (CS.doesNotAccessMemory()) // Can't do better than this. @@ -125,7 +125,7 @@ AliasAnalysis::getModRefBehavior(CallSite CS, } AliasAnalysis::ModRefBehavior -AliasAnalysis::getModRefBehavior(Function *F, +AliasAnalysis::getModRefBehavior(const Function *F, std::vector *Info) { if (F) { if (F->doesNotAccessMemory()) @@ -134,19 +134,21 @@ AliasAnalysis::getModRefBehavior(Function *F, if (F->onlyReadsMemory()) return OnlyReadsMemory; if (unsigned id = F->getIntrinsicID()) - return getModRefBehavior(id); + return getIntrinsicModRefBehavior(id); } return UnknownModRefBehavior; } -AliasAnalysis::ModRefBehavior AliasAnalysis::getModRefBehavior(unsigned iid) { +AliasAnalysis::ModRefBehavior +AliasAnalysis::getIntrinsicModRefBehavior(unsigned iid) { #define GET_INTRINSIC_MODREF_BEHAVIOR #include "llvm/Intrinsics.gen" #undef GET_INTRINSIC_MODREF_BEHAVIOR } AliasAnalysis::ModRefResult -AliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) { +AliasAnalysis::getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size) { ModRefBehavior MRB = getModRefBehavior(CS); if (MRB == DoesNotAccessMemory) return NoModRef; @@ -156,7 +158,7 @@ AliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) { Mask = Ref; else if (MRB == AliasAnalysis::AccessesArguments) { bool doesAlias = false; - for (CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end(); + for (ImmutableCallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end(); AI != AE; ++AI) if (!isNoAlias(*AI, ~0U, P, Size)) { doesAlias = true; @@ -223,12 +225,12 @@ bool AliasAnalysis::canInstructionRangeModify(const Instruction &I1, const Value *Ptr, unsigned Size) { assert(I1.getParent() == I2.getParent() && "Instructions not in same basic block!"); - BasicBlock::iterator I = const_cast(&I1); - BasicBlock::iterator E = const_cast(&I2); + BasicBlock::const_iterator I = &I1; + BasicBlock::const_iterator E = &I2; ++E; // Convert from inclusive to exclusive range. for (; I != E; ++I) // Check every instruction in range - if (getModRefInfo(I, const_cast(Ptr), Size) & Mod) + if (getModRefInfo(I, Ptr, Size) & Mod) return true; return false; } @@ -237,7 +239,7 @@ bool AliasAnalysis::canInstructionRangeModify(const Instruction &I1, /// function. bool llvm::isNoAliasCall(const Value *V) { if (isa(V) || isa(V)) - return CallSite(const_cast(cast(V))) + return ImmutableCallSite(cast(V)) .paramHasAttr(0, Attribute::NoAlias); return false; } diff --git a/lib/Analysis/AliasAnalysisCounter.cpp b/lib/Analysis/AliasAnalysisCounter.cpp index 25786c78637..7631e3655f3 100644 --- a/lib/Analysis/AliasAnalysisCounter.cpp +++ b/lib/Analysis/AliasAnalysisCounter.cpp @@ -103,8 +103,10 @@ namespace { AliasResult alias(const Value *V1, unsigned V1Size, const Value *V2, unsigned V2Size); - ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size); - ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) { + ModRefResult getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size); + ModRefResult getModRefInfo(ImmutableCallSite CS1, + ImmutableCallSite CS2) { return AliasAnalysis::getModRefInfo(CS1,CS2); } }; @@ -145,7 +147,8 @@ AliasAnalysisCounter::alias(const Value *V1, unsigned V1Size, } AliasAnalysis::ModRefResult -AliasAnalysisCounter::getModRefInfo(CallSite CS, Value *P, unsigned Size) { +AliasAnalysisCounter::getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size) { ModRefResult R = getAnalysis().getModRefInfo(CS, P, Size); const char *MRString; diff --git a/lib/Analysis/AliasDebugger.cpp b/lib/Analysis/AliasDebugger.cpp index 79bc99e2006..8209bb624a2 100644 --- a/lib/Analysis/AliasDebugger.cpp +++ b/lib/Analysis/AliasDebugger.cpp @@ -99,12 +99,14 @@ namespace { return AliasAnalysis::alias(V1, V1Size, V2, V2Size); } - ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) { + ModRefResult getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size) { assert(Vals.find(P) != Vals.end() && "Never seen value in AA before"); return AliasAnalysis::getModRefInfo(CS, P, Size); } - ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) { + ModRefResult getModRefInfo(ImmutableCallSite CS1, + ImmutableCallSite CS2) { return AliasAnalysis::getModRefInfo(CS1,CS2); } diff --git a/lib/Analysis/AliasSetTracker.cpp b/lib/Analysis/AliasSetTracker.cpp index 8581f5911d9..7e11ce6360b 100644 --- a/lib/Analysis/AliasSetTracker.cpp +++ b/lib/Analysis/AliasSetTracker.cpp @@ -155,7 +155,7 @@ bool AliasSet::aliasesPointer(const Value *Ptr, unsigned Size, // Check the call sites list and invoke list... if (!CallSites.empty()) { for (unsigned i = 0, e = CallSites.size(); i != e; ++i) - if (AA.getModRefInfo(CallSites[i], const_cast(Ptr), Size) + if (AA.getModRefInfo(CallSites[i], Ptr, Size) != AliasAnalysis::NoModRef) return true; } diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index d314ebee8dd..6bb84d4e458 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -153,10 +153,12 @@ namespace { } virtual bool pointsToConstantMemory(const Value *P) { return false; } - virtual ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) { + virtual ModRefResult getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size) { return ModRef; } - virtual ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) { + virtual ModRefResult getModRefInfo(ImmutableCallSite CS1, + ImmutableCallSite CS2) { return ModRef; } @@ -225,8 +227,10 @@ namespace { return Alias; } - ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size); - ModRefResult getModRefInfo(CallSite CS1, CallSite CS2); + ModRefResult getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size); + ModRefResult getModRefInfo(ImmutableCallSite CS1, + ImmutableCallSite CS2); /// pointsToConstantMemory - Chase pointers until we find a (constant /// global) or not. @@ -295,7 +299,8 @@ bool BasicAliasAnalysis::pointsToConstantMemory(const Value *P) { /// function, we really can't say much about this query. We do, however, use /// simple "address taken" analysis on local objects. AliasAnalysis::ModRefResult -BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) { +BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size) { assert(notDifferentParent(CS.getInstruction(), P) && "AliasAnalysis query involving multiple functions!"); @@ -307,7 +312,7 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) { // the current function not to the current function, and a tail callee // may reference them. if (isa(Object)) - if (CallInst *CI = dyn_cast(CS.getInstruction())) + if (const CallInst *CI = dyn_cast(CS.getInstruction())) if (CI->isTailCall()) return NoModRef; @@ -318,7 +323,7 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) { isNonEscapingLocalObject(Object)) { bool PassedAsArg = false; unsigned ArgNo = 0; - for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end(); + for (ImmutableCallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end(); CI != CE; ++CI, ++ArgNo) { // Only look at the no-capture pointer arguments. if (!(*CI)->getType()->isPointerTy() || @@ -340,7 +345,7 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) { } // Finally, handle specific knowledge of intrinsics. - IntrinsicInst *II = dyn_cast(CS.getInstruction()); + const IntrinsicInst *II = dyn_cast(CS.getInstruction()); if (II == 0) return AliasAnalysis::getModRefInfo(CS, P, Size); @@ -411,7 +416,8 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) { AliasAnalysis::ModRefResult -BasicAliasAnalysis::getModRefInfo(CallSite CS1, CallSite CS2) { +BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS1, + ImmutableCallSite CS2) { // If CS1 or CS2 are readnone, they don't interact. ModRefBehavior CS1B = AliasAnalysis::getModRefBehavior(CS1); if (CS1B == DoesNotAccessMemory) return NoModRef; diff --git a/lib/Analysis/IPA/GlobalsModRef.cpp b/lib/Analysis/IPA/GlobalsModRef.cpp index f13deea41d4..4c2272eb7fa 100644 --- a/lib/Analysis/IPA/GlobalsModRef.cpp +++ b/lib/Analysis/IPA/GlobalsModRef.cpp @@ -47,14 +47,15 @@ namespace { /// GlobalInfo - Maintain mod/ref info for all of the globals without /// addresses taken that are read or written (transitively) by this /// function. - std::map GlobalInfo; + std::map GlobalInfo; /// MayReadAnyGlobal - May read global variables, but it is not known which. bool MayReadAnyGlobal; - unsigned getInfoForGlobal(GlobalValue *GV) const { + unsigned getInfoForGlobal(const GlobalValue *GV) const { unsigned Effect = MayReadAnyGlobal ? AliasAnalysis::Ref : 0; - std::map::const_iterator I = GlobalInfo.find(GV); + std::map::const_iterator I = + GlobalInfo.find(GV); if (I != GlobalInfo.end()) Effect |= I->second; return Effect; @@ -71,19 +72,19 @@ namespace { class GlobalsModRef : public ModulePass, public AliasAnalysis { /// NonAddressTakenGlobals - The globals that do not have their addresses /// taken. - std::set NonAddressTakenGlobals; + std::set NonAddressTakenGlobals; /// IndirectGlobals - The memory pointed to by this global is known to be /// 'owned' by the global. - std::set IndirectGlobals; + std::set IndirectGlobals; /// AllocsForIndirectGlobals - If an instruction allocates memory for an /// indirect global, this map indicates which one. - std::map AllocsForIndirectGlobals; + std::map AllocsForIndirectGlobals; /// FunctionInfo - For each function, keep track of what globals are /// modified or read. - std::map FunctionInfo; + std::map FunctionInfo; public: static char ID; @@ -107,16 +108,18 @@ namespace { // AliasResult alias(const Value *V1, unsigned V1Size, const Value *V2, unsigned V2Size); - ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size); - ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) { - return AliasAnalysis::getModRefInfo(CS1,CS2); + ModRefResult getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size); + ModRefResult getModRefInfo(ImmutableCallSite CS1, + ImmutableCallSite CS2) { + return AliasAnalysis::getModRefInfo(CS1, CS2); } /// 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. - ModRefBehavior getModRefBehavior(Function *F, - std::vector *Info) { + ModRefBehavior getModRefBehavior(const Function *F, + std::vector *Info) { if (FunctionRecord *FR = getFunctionInfo(F)) { if (FR->FunctionEffect == 0) return DoesNotAccessMemory; @@ -129,9 +132,9 @@ namespace { /// 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. - ModRefBehavior getModRefBehavior(CallSite CS, - std::vector *Info) { - Function* F = CS.getCalledFunction(); + ModRefBehavior getModRefBehavior(ImmutableCallSite CS, + std::vector *Info) { + const Function* F = CS.getCalledFunction(); if (!F) return AliasAnalysis::getModRefBehavior(CS, Info); if (FunctionRecord *FR = getFunctionInfo(F)) { if (FR->FunctionEffect == 0) @@ -158,8 +161,9 @@ namespace { private: /// getFunctionInfo - Return the function info for the function, or null if /// we don't have anything useful to say about it. - FunctionRecord *getFunctionInfo(Function *F) { - std::map::iterator I = FunctionInfo.find(F); + FunctionRecord *getFunctionInfo(const Function *F) { + std::map::iterator I = + FunctionInfo.find(F); if (I != FunctionInfo.end()) return &I->second; return 0; @@ -409,7 +413,7 @@ void GlobalsModRef::AnalyzeCallGraph(CallGraph &CG, Module &M) { FunctionEffect |= CalleeFR->FunctionEffect; // Incorporate callee's effects on globals into our info. - for (std::map::iterator GI = + for (std::map::iterator GI = CalleeFR->GlobalInfo.begin(), E = CalleeFR->GlobalInfo.end(); GI != E; ++GI) FR.GlobalInfo[GI->first] |= GI->second; @@ -477,13 +481,13 @@ AliasAnalysis::AliasResult GlobalsModRef::alias(const Value *V1, unsigned V1Size, const Value *V2, unsigned V2Size) { // Get the base object these pointers point to. - Value *UV1 = const_cast(V1->getUnderlyingObject()); - Value *UV2 = const_cast(V2->getUnderlyingObject()); + const Value *UV1 = V1->getUnderlyingObject(); + const Value *UV2 = V2->getUnderlyingObject(); // If either of the underlying values is a global, they may be non-addr-taken // globals, which we can answer queries about. - GlobalValue *GV1 = dyn_cast(UV1); - GlobalValue *GV2 = dyn_cast(UV2); + const GlobalValue *GV1 = dyn_cast(UV1); + const GlobalValue *GV2 = dyn_cast(UV2); if (GV1 || GV2) { // If the global's address is taken, pretend we don't know it's a pointer to // the global. @@ -503,12 +507,12 @@ GlobalsModRef::alias(const Value *V1, unsigned V1Size, // so, we may be able to handle this. First check to see if the base pointer // is a direct load from an indirect global. GV1 = GV2 = 0; - if (LoadInst *LI = dyn_cast(UV1)) + if (const LoadInst *LI = dyn_cast(UV1)) if (GlobalVariable *GV = dyn_cast(LI->getOperand(0))) if (IndirectGlobals.count(GV)) GV1 = GV; - if (LoadInst *LI = dyn_cast(UV2)) - if (GlobalVariable *GV = dyn_cast(LI->getOperand(0))) + if (const LoadInst *LI = dyn_cast(UV2)) + if (const GlobalVariable *GV = dyn_cast(LI->getOperand(0))) if (IndirectGlobals.count(GV)) GV2 = GV; @@ -530,16 +534,17 @@ GlobalsModRef::alias(const Value *V1, unsigned V1Size, } AliasAnalysis::ModRefResult -GlobalsModRef::getModRefInfo(CallSite CS, Value *P, unsigned Size) { +GlobalsModRef::getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size) { unsigned Known = ModRef; // 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 (GlobalValue *GV = dyn_cast(P->getUnderlyingObject())) + if (const GlobalValue *GV = dyn_cast(P->getUnderlyingObject())) if (GV->hasLocalLinkage()) - if (Function *F = CS.getCalledFunction()) + if (const Function *F = CS.getCalledFunction()) if (NonAddressTakenGlobals.count(GV)) - if (FunctionRecord *FR = getFunctionInfo(F)) + if (const FunctionRecord *FR = getFunctionInfo(F)) Known = FR->getInfoForGlobal(GV); if (Known == NoModRef) @@ -558,7 +563,7 @@ void GlobalsModRef::deleteValue(Value *V) { // any AllocRelatedValues for it. if (IndirectGlobals.erase(GV)) { // Remove any entries in AllocsForIndirectGlobals for this global. - for (std::map::iterator + for (std::map::iterator I = AllocsForIndirectGlobals.begin(), E = AllocsForIndirectGlobals.end(); I != E; ) { if (I->second == GV) { diff --git a/lib/Analysis/LibCallAliasAnalysis.cpp b/lib/Analysis/LibCallAliasAnalysis.cpp index 9dca93f9e76..7f51202ecb5 100644 --- a/lib/Analysis/LibCallAliasAnalysis.cpp +++ b/lib/Analysis/LibCallAliasAnalysis.cpp @@ -43,7 +43,7 @@ void LibCallAliasAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { /// vs the specified pointer/size. AliasAnalysis::ModRefResult LibCallAliasAnalysis::AnalyzeLibCallDetails(const LibCallFunctionInfo *FI, - CallSite CS, Value *P, + ImmutableCallSite CS, const Value *P, unsigned Size) { // If we have a function, check to see what kind of mod/ref effects it // has. Start by including any info globally known about the function. @@ -117,13 +117,14 @@ LibCallAliasAnalysis::AnalyzeLibCallDetails(const LibCallFunctionInfo *FI, // specified memory object. // AliasAnalysis::ModRefResult -LibCallAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) { +LibCallAliasAnalysis::getModRefInfo(ImmutableCallSite CS, + const Value *P, unsigned Size) { ModRefResult MRInfo = ModRef; // If this is a direct call to a function that LCI knows about, get the // information about the runtime function. if (LCI) { - if (Function *F = CS.getCalledFunction()) { + if (const Function *F = CS.getCalledFunction()) { if (const LibCallFunctionInfo *FI = LCI->getFunctionInfo(F)) { MRInfo = ModRefResult(MRInfo & AnalyzeLibCallDetails(FI, CS, P, Size)); if (MRInfo == NoModRef) return NoModRef; diff --git a/lib/Analysis/LibCallSemantics.cpp b/lib/Analysis/LibCallSemantics.cpp index e0060c3e89b..81b0f46f374 100644 --- a/lib/Analysis/LibCallSemantics.cpp +++ b/lib/Analysis/LibCallSemantics.cpp @@ -40,7 +40,8 @@ const LibCallLocationInfo &LibCallInfo::getLocationInfo(unsigned LocID) const { /// getFunctionInfo - Return the LibCallFunctionInfo object corresponding to /// the specified function if we have it. If not, return null. -const LibCallFunctionInfo *LibCallInfo::getFunctionInfo(Function *F) const { +const LibCallFunctionInfo * +LibCallInfo::getFunctionInfo(const Function *F) const { StringMap *Map = getMap(Impl); /// If this is the first time we are querying for this info, lazily construct diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp index 0bf150e6e3f..d5c35ea59d6 100644 --- a/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/lib/Transforms/IPO/FunctionAttrs.cpp @@ -169,7 +169,7 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) { continue; // Ignore intrinsics that only access local memory. if (unsigned id = CS.getCalledFunction()->getIntrinsicID()) - if (AliasAnalysis::getModRefBehavior(id) == + if (AliasAnalysis::getIntrinsicModRefBehavior(id) == AliasAnalysis::AccessesArguments) { // Check that all pointer arguments point to local memory. for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();