diff --git a/include/llvm/Analysis/ValueTracking.h b/include/llvm/Analysis/ValueTracking.h index d380ad5527a..bc6be583307 100644 --- a/include/llvm/Analysis/ValueTracking.h +++ b/include/llvm/Analysis/ValueTracking.h @@ -351,7 +351,8 @@ class Value; /// Since A[i] and A[i-1] are independent pointers, getUnderlyingObjects /// should not assume that Curr and Prev share the same underlying object thus /// it shouldn't look through the phi above. - void GetUnderlyingObjects(Value *V, SmallVectorImpl &Objects, + void GetUnderlyingObjects(const Value *V, + SmallVectorImpl &Objects, const DataLayout &DL, LoopInfo *LI = nullptr, unsigned MaxLookup = 6); diff --git a/lib/Analysis/GlobalsModRef.cpp b/lib/Analysis/GlobalsModRef.cpp index 2c967c87458..0d6c0ffb18a 100644 --- a/lib/Analysis/GlobalsModRef.cpp +++ b/lib/Analysis/GlobalsModRef.cpp @@ -896,13 +896,13 @@ ModRefInfo GlobalsAAResult::getModRefInfoForArgument(const CallBase *Call, // Iterate through all the arguments to the called function. If any argument // is based on GV, return the conservative result. for (auto &A : Call->args()) { - SmallVector Objects; + SmallVector Objects; GetUnderlyingObjects(A, Objects, DL); // All objects must be identified. if (!all_of(Objects, isIdentifiedObject) && // Try ::alias to see if all objects are known not to alias GV. - !all_of(Objects, [&](Value *V) { + !all_of(Objects, [&](const Value *V) { return this->alias(MemoryLocation(V), MemoryLocation(GV), AAQI) == NoAlias; })) diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index f41256b8bb2..87e0df29bbd 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -2281,12 +2281,12 @@ computePointerICmp(const DataLayout &DL, const TargetLibraryInfo *TLI, // come from a pointer that cannot overlap with dynamically-allocated // memory within the lifetime of the current function (allocas, byval // arguments, globals), then determine the comparison result here. - SmallVector LHSUObjs, RHSUObjs; + SmallVector LHSUObjs, RHSUObjs; GetUnderlyingObjects(LHS, LHSUObjs, DL); GetUnderlyingObjects(RHS, RHSUObjs, DL); // Is the set of underlying objects all noalias calls? - auto IsNAC = [](ArrayRef Objects) { + auto IsNAC = [](ArrayRef Objects) { return all_of(Objects, isNoAliasCall); }; @@ -2296,8 +2296,8 @@ computePointerICmp(const DataLayout &DL, const TargetLibraryInfo *TLI, // live with the compared-to allocation). For globals, we exclude symbols // that might be resolve lazily to symbols in another dynamically-loaded // library (and, thus, could be malloc'ed by the implementation). - auto IsAllocDisjoint = [](ArrayRef Objects) { - return all_of(Objects, [](Value *V) { + auto IsAllocDisjoint = [](ArrayRef Objects) { + return all_of(Objects, [](const Value *V) { if (const AllocaInst *AI = dyn_cast(V)) return AI->getParent() && AI->getFunction() && AI->isStaticAlloca(); if (const GlobalValue *GV = dyn_cast(V)) diff --git a/lib/Analysis/LoopAccessAnalysis.cpp b/lib/Analysis/LoopAccessAnalysis.cpp index 6ec138c42a4..d6fbf6f2827 100644 --- a/lib/Analysis/LoopAccessAnalysis.cpp +++ b/lib/Analysis/LoopAccessAnalysis.cpp @@ -842,7 +842,7 @@ void AccessAnalysis::processMemAccesses() { bool SetHasWrite = false; // Map of pointers to last access encountered. - typedef DenseMap UnderlyingObjToAccessMap; + typedef DenseMap UnderlyingObjToAccessMap; UnderlyingObjToAccessMap ObjToLastAccess; // Set of access to check after all writes have been processed. @@ -903,13 +903,13 @@ void AccessAnalysis::processMemAccesses() { // Create sets of pointers connected by a shared alias set and // underlying object. - typedef SmallVector ValueVector; + typedef SmallVector ValueVector; ValueVector TempObjects; GetUnderlyingObjects(Ptr, TempObjects, DL, LI); LLVM_DEBUG(dbgs() << "Underlying objects for pointer " << *Ptr << "\n"); - for (Value *UnderlyingObj : TempObjects) { + for (const Value *UnderlyingObj : TempObjects) { // nullptr never alias, don't join sets for pointer that have "null" // in their UnderlyingObjects list. if (isa(UnderlyingObj) && diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index 3b08a2dc7a1..7c16b21c928 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -3771,26 +3771,27 @@ Value *llvm::GetUnderlyingObject(Value *V, const DataLayout &DL, return V; } -void llvm::GetUnderlyingObjects(Value *V, SmallVectorImpl &Objects, +void llvm::GetUnderlyingObjects(const Value *V, + SmallVectorImpl &Objects, const DataLayout &DL, LoopInfo *LI, unsigned MaxLookup) { - SmallPtrSet Visited; - SmallVector Worklist; + SmallPtrSet Visited; + SmallVector Worklist; Worklist.push_back(V); do { - Value *P = Worklist.pop_back_val(); + const Value *P = Worklist.pop_back_val(); P = GetUnderlyingObject(P, DL, MaxLookup); if (!Visited.insert(P).second) continue; - if (SelectInst *SI = dyn_cast(P)) { + if (auto *SI = dyn_cast(P)) { Worklist.push_back(SI->getTrueValue()); Worklist.push_back(SI->getFalseValue()); continue; } - if (PHINode *PN = dyn_cast(P)) { + if (auto *PN = dyn_cast(P)) { // If this PHI changes the underlying object in every iteration of the // loop, don't look through it. Consider: // int **A; @@ -3851,10 +3852,10 @@ bool llvm::getUnderlyingObjectsForCodeGen(const Value *V, do { V = Working.pop_back_val(); - SmallVector Objs; - GetUnderlyingObjects(const_cast(V), Objs, DL); + SmallVector Objs; + GetUnderlyingObjects(V, Objs, DL); - for (Value *V : Objs) { + for (const Value *V : Objs) { if (!Visited.insert(V).second) continue; if (Operator::getOpcode(V) == Instruction::IntToPtr) { diff --git a/lib/CodeGen/GlobalISel/IRTranslator.cpp b/lib/CodeGen/GlobalISel/IRTranslator.cpp index 01823527f1f..f32ae787d3f 100644 --- a/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -846,13 +846,13 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID, // Get the underlying objects for the location passed on the lifetime // marker. - SmallVector Allocas; + SmallVector Allocas; GetUnderlyingObjects(CI.getArgOperand(1), Allocas, *DL); // Iterate over each underlying object, creating lifetime markers for each // static alloca. Quit if we find a non-static alloca. - for (Value *V : Allocas) { - AllocaInst *AI = dyn_cast(V); + for (const Value *V : Allocas) { + const AllocaInst *AI = dyn_cast(V); if (!AI) continue; diff --git a/lib/CodeGen/MachinePipeliner.cpp b/lib/CodeGen/MachinePipeliner.cpp index 62760d222a8..9c1a5a73375 100644 --- a/lib/CodeGen/MachinePipeliner.cpp +++ b/lib/CodeGen/MachinePipeliner.cpp @@ -541,16 +541,16 @@ static bool isDependenceBarrier(MachineInstr &MI, AliasAnalysis *AA) { /// Return the underlying objects for the memory references of an instruction. /// This function calls the code in ValueTracking, but first checks that the /// instruction has a memory operand. -static void getUnderlyingObjects(MachineInstr *MI, - SmallVectorImpl &Objs, +static void getUnderlyingObjects(const MachineInstr *MI, + SmallVectorImpl &Objs, const DataLayout &DL) { if (!MI->hasOneMemOperand()) return; MachineMemOperand *MM = *MI->memoperands_begin(); if (!MM->getValue()) return; - GetUnderlyingObjects(const_cast(MM->getValue()), Objs, DL); - for (Value *V : Objs) { + GetUnderlyingObjects(MM->getValue(), Objs, DL); + for (const Value *V : Objs) { if (!isIdentifiedObject(V)) { Objs.clear(); return; @@ -564,7 +564,7 @@ static void getUnderlyingObjects(MachineInstr *MI, /// dependence. This code is very similar to the code in ScheduleDAGInstrs /// but that code doesn't create loop carried dependences. void SwingSchedulerDAG::addLoopCarriedDependences(AliasAnalysis *AA) { - MapVector> PendingLoads; + MapVector> PendingLoads; Value *UnknownValue = UndefValue::get(Type::getVoidTy(MF.getFunction().getContext())); for (auto &SU : SUnits) { @@ -572,7 +572,7 @@ void SwingSchedulerDAG::addLoopCarriedDependences(AliasAnalysis *AA) { if (isDependenceBarrier(MI, AA)) PendingLoads.clear(); else if (MI.mayLoad()) { - SmallVector Objs; + SmallVector Objs; getUnderlyingObjects(&MI, Objs, MF.getDataLayout()); if (Objs.empty()) Objs.push_back(UnknownValue); @@ -581,12 +581,12 @@ void SwingSchedulerDAG::addLoopCarriedDependences(AliasAnalysis *AA) { SUs.push_back(&SU); } } else if (MI.mayStore()) { - SmallVector Objs; + SmallVector Objs; getUnderlyingObjects(&MI, Objs, MF.getDataLayout()); if (Objs.empty()) Objs.push_back(UnknownValue); for (auto V : Objs) { - MapVector>::iterator I = + MapVector>::iterator I = PendingLoads.find(V); if (I == PendingLoads.end()) continue; diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 818f1ada04b..46dd0bf1316 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -6463,12 +6463,12 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) { const int64_t ObjectSize = cast(I.getArgOperand(0))->getSExtValue(); Value *const ObjectPtr = I.getArgOperand(1); - SmallVector Allocas; + SmallVector Allocas; GetUnderlyingObjects(ObjectPtr, Allocas, *DL); - for (SmallVectorImpl::iterator Object = Allocas.begin(), + for (SmallVectorImpl::iterator Object = Allocas.begin(), E = Allocas.end(); Object != E; ++Object) { - AllocaInst *LifetimeObject = dyn_cast_or_null(*Object); + const AllocaInst *LifetimeObject = dyn_cast_or_null(*Object); // Could not find an Alloca. if (!LifetimeObject) diff --git a/lib/Target/Mips/MipsDelaySlotFiller.cpp b/lib/Target/Mips/MipsDelaySlotFiller.cpp index a05c3870f02..25c80f747e1 100644 --- a/lib/Target/Mips/MipsDelaySlotFiller.cpp +++ b/lib/Target/Mips/MipsDelaySlotFiller.cpp @@ -540,10 +540,10 @@ getUnderlyingObjects(const MachineInstr &MI, const Value *V = (*MI.memoperands_begin())->getValue(); - SmallVector Objs; - GetUnderlyingObjects(const_cast(V), Objs, DL); + SmallVector Objs; + GetUnderlyingObjects(V, Objs, DL); - for (SmallVectorImpl::iterator I = Objs.begin(), E = Objs.end(); + for (SmallVectorImpl::iterator I = Objs.begin(), E = Objs.end(); I != E; ++I) { if (!isIdentifiedObject(V)) return false; diff --git a/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp b/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp index d6e44b785ea..4542e60c97e 100644 --- a/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp +++ b/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp @@ -701,11 +701,11 @@ static bool canLowerToLDG(MemSDNode *N, const NVPTXSubtarget &Subtarget, // We use GetUnderlyingObjects() here instead of GetUnderlyingObject() mainly // because the former looks through phi nodes while the latter does not. We // need to look through phi nodes to handle pointer induction variables. - SmallVector Objs; - GetUnderlyingObjects(const_cast(N->getMemOperand()->getValue()), + SmallVector Objs; + GetUnderlyingObjects(N->getMemOperand()->getValue(), Objs, F->getDataLayout()); - return all_of(Objs, [&](Value *V) { + return all_of(Objs, [&](const Value *V) { if (auto *A = dyn_cast(V)) return IsKernelFn && A->onlyReadsMemory() && A->hasNoAliasAttr(); if (auto *GV = dyn_cast(V)) diff --git a/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp index 3f166b11341..a5776a47af7 100644 --- a/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -1190,10 +1190,10 @@ Value *DFSanFunction::loadShadow(Value *Addr, uint64_t Size, uint64_t Align, } uint64_t ShadowAlign = Align * DFS.ShadowWidth / 8; - SmallVector Objs; + SmallVector Objs; GetUnderlyingObjects(Addr, Objs, Pos->getModule()->getDataLayout()); bool AllConstants = true; - for (Value *Obj : Objs) { + for (const Value *Obj : Objs) { if (isa(Obj) || isa(Obj)) continue; if (isa(Obj) && cast(Obj)->isConstant()) diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index 502148ba798..75206c28dde 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -99,7 +99,7 @@ static void deleteDeadInstruction(Instruction *I, BasicBlock::iterator *BBI, MemoryDependenceResults &MD, const TargetLibraryInfo &TLI, InstOverlapIntervalsTy &IOL, OrderedBasicBlock &OBB, - SmallSetVector *ValueSet = nullptr) { + SmallSetVector *ValueSet = nullptr) { SmallVector NowDeadInsts; NowDeadInsts.push_back(I); @@ -713,7 +713,7 @@ static bool handleFree(CallInst *F, AliasAnalysis *AA, /// the DeadStackObjects set. If so, they become live because the location is /// being loaded. static void removeAccessedObjects(const MemoryLocation &LoadedLoc, - SmallSetVector &DeadStackObjects, + SmallSetVector &DeadStackObjects, const DataLayout &DL, AliasAnalysis *AA, const TargetLibraryInfo *TLI, const Function *F) { @@ -726,12 +726,12 @@ static void removeAccessedObjects(const MemoryLocation &LoadedLoc, // If the kill pointer can be easily reduced to an alloca, don't bother doing // extraneous AA queries. if (isa(UnderlyingPointer) || isa(UnderlyingPointer)) { - DeadStackObjects.remove(const_cast(UnderlyingPointer)); + DeadStackObjects.remove(UnderlyingPointer); return; } // Remove objects that could alias LoadedLoc. - DeadStackObjects.remove_if([&](Value *I) { + DeadStackObjects.remove_if([&](const Value *I) { // See if the loaded location could alias the stack location. MemoryLocation StackLoc(I, getPointerSize(I, DL, *TLI, F)); return !AA->isNoAlias(StackLoc, LoadedLoc); @@ -753,7 +753,7 @@ static bool handleEndBlock(BasicBlock &BB, AliasAnalysis *AA, // Keep track of all of the stack objects that are dead at the end of the // function. - SmallSetVector DeadStackObjects; + SmallSetVector DeadStackObjects; // Find all of the alloca'd pointers in the entry block. BasicBlock &Entry = BB.getParent()->front(); @@ -782,12 +782,12 @@ static bool handleEndBlock(BasicBlock &BB, AliasAnalysis *AA, // If we find a store, check to see if it points into a dead stack value. if (hasAnalyzableMemoryWrite(&*BBI, *TLI) && isRemovable(&*BBI)) { // See through pointer-to-pointer bitcasts - SmallVector Pointers; + SmallVector Pointers; GetUnderlyingObjects(getStoredPointerOperand(&*BBI), Pointers, DL); // Stores to stack values are valid candidates for removal. bool AllDead = true; - for (Value *Pointer : Pointers) + for (const Value *Pointer : Pointers) if (!DeadStackObjects.count(Pointer)) { AllDead = false; break; @@ -798,7 +798,8 @@ static bool handleEndBlock(BasicBlock &BB, AliasAnalysis *AA, LLVM_DEBUG(dbgs() << "DSE: Dead Store at End of Block:\n DEAD: " << *Dead << "\n Objects: "; - for (SmallVectorImpl::iterator I = Pointers.begin(), + for (SmallVectorImpl::iterator I = + Pointers.begin(), E = Pointers.end(); I != E; ++I) { dbgs() << **I; @@ -847,7 +848,7 @@ static bool handleEndBlock(BasicBlock &BB, AliasAnalysis *AA, // If the call might load from any of our allocas, then any store above // the call is live. - DeadStackObjects.remove_if([&](Value *I) { + DeadStackObjects.remove_if([&](const Value *I) { // See if the call site touches the value. return isRefSet(AA->getModRefInfo( Call, I, getPointerSize(I, DL, *TLI, BB.getParent()))); diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index a29fbc81c4c..6438d2d9f3b 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -1041,11 +1041,10 @@ static void AddAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap, SmallSetVector NAPtrArgs; for (const Value *V : PtrArgs) { - SmallVector Objects; - GetUnderlyingObjects(const_cast(V), - Objects, DL, /* LI = */ nullptr); + SmallVector Objects; + GetUnderlyingObjects(V, Objects, DL, /* LI = */ nullptr); - for (Value *O : Objects) + for (const Value *O : Objects) ObjSet.insert(O); }