[Transforms] Qualify auto in range-based for loops (NFC)

Identified with readability-qualified-auto.
This commit is contained in:
Kazu Hirata 2022-08-14 12:51:58 -07:00
parent 9144e49334
commit 50724716cd
31 changed files with 94 additions and 94 deletions

View File

@ -977,7 +977,7 @@ bool IRPosition::getAttrsFromAssumes(Attribute::AttrKind AK,
MustBeExecutedContextExplorer &Explorer = MustBeExecutedContextExplorer &Explorer =
A.getInfoCache().getMustBeExecutedContextExplorer(); A.getInfoCache().getMustBeExecutedContextExplorer();
auto EIt = Explorer.begin(getCtxI()), EEnd = Explorer.end(getCtxI()); auto EIt = Explorer.begin(getCtxI()), EEnd = Explorer.end(getCtxI());
for (auto &It : A2K) for (const auto &It : A2K)
if (Explorer.findInContextOf(It.first, EIt, EEnd)) if (Explorer.findInContextOf(It.first, EIt, EEnd))
Attrs.push_back(Attribute::get(Ctx, AK, It.second.Max)); Attrs.push_back(Attribute::get(Ctx, AK, It.second.Max));
return AttrsSize != Attrs.size(); return AttrsSize != Attrs.size();
@ -1113,7 +1113,7 @@ bool Attributor::getAssumedSimplifiedValues(
// a non-null value that is different from the associated value, or None, we // a non-null value that is different from the associated value, or None, we
// assume it's simplified. // assume it's simplified.
const auto &SimplificationCBs = SimplificationCallbacks.lookup(IRP); const auto &SimplificationCBs = SimplificationCallbacks.lookup(IRP);
for (auto &CB : SimplificationCBs) { for (const auto &CB : SimplificationCBs) {
Optional<Value *> CBResult = CB(IRP, AA, UsedAssumedInformation); Optional<Value *> CBResult = CB(IRP, AA, UsedAssumedInformation);
if (!CBResult.has_value()) if (!CBResult.has_value())
continue; continue;
@ -2079,7 +2079,7 @@ ChangeStatus Attributor::cleanupIR() {
} }
} }
for (auto &V : InvokeWithDeadSuccessor) for (const auto &V : InvokeWithDeadSuccessor)
if (InvokeInst *II = dyn_cast_or_null<InvokeInst>(V)) { if (InvokeInst *II = dyn_cast_or_null<InvokeInst>(V)) {
assert(isRunOn(*II->getFunction()) && assert(isRunOn(*II->getFunction()) &&
"Cannot replace an invoke outside the current SCC!"); "Cannot replace an invoke outside the current SCC!");
@ -2112,7 +2112,7 @@ ChangeStatus Attributor::cleanupIR() {
CGModifiedFunctions.insert(I->getFunction()); CGModifiedFunctions.insert(I->getFunction());
ConstantFoldTerminator(I->getParent()); ConstantFoldTerminator(I->getParent());
} }
for (auto &V : ToBeChangedToUnreachableInsts) for (const auto &V : ToBeChangedToUnreachableInsts)
if (Instruction *I = dyn_cast_or_null<Instruction>(V)) { if (Instruction *I = dyn_cast_or_null<Instruction>(V)) {
LLVM_DEBUG(dbgs() << "[Attributor] Change to unreachable: " << *I LLVM_DEBUG(dbgs() << "[Attributor] Change to unreachable: " << *I
<< "\n"); << "\n");
@ -2122,7 +2122,7 @@ ChangeStatus Attributor::cleanupIR() {
changeToUnreachable(I); changeToUnreachable(I);
} }
for (auto &V : ToBeDeletedInsts) { for (const auto &V : ToBeDeletedInsts) {
if (Instruction *I = dyn_cast_or_null<Instruction>(V)) { if (Instruction *I = dyn_cast_or_null<Instruction>(V)) {
if (auto *CB = dyn_cast<CallBase>(I)) { if (auto *CB = dyn_cast<CallBase>(I)) {
assert(isRunOn(*I->getFunction()) && assert(isRunOn(*I->getFunction()) &&
@ -3190,7 +3190,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS,
if (!S.isValidState()) if (!S.isValidState())
OS << "full-set"; OS << "full-set";
else { else {
for (auto &It : S.getAssumedSet()) for (const auto &It : S.getAssumedSet())
OS << It << ", "; OS << It << ", ";
if (S.undefIsContained()) if (S.undefIsContained())
OS << "undef "; OS << "undef ";
@ -3206,7 +3206,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS,
if (!S.isValidState()) if (!S.isValidState())
OS << "full-set"; OS << "full-set";
else { else {
for (auto &It : S.getAssumedSet()) { for (const auto &It : S.getAssumedSet()) {
if (auto *F = dyn_cast<Function>(It.first.getValue())) if (auto *F = dyn_cast<Function>(It.first.getValue()))
OS << "@" << F->getName() << "[" << int(It.second) << "], "; OS << "@" << F->getName() << "[" << int(It.second) << "], ";
else else

View File

@ -891,7 +891,7 @@ protected:
if (!isValidState()) if (!isValidState())
return false; return false;
for (auto &It : AccessBins) { for (const auto &It : AccessBins) {
AAPointerInfo::OffsetAndSize ItOAS = It.getFirst(); AAPointerInfo::OffsetAndSize ItOAS = It.getFirst();
if (!OAS.mayOverlap(ItOAS)) if (!OAS.mayOverlap(ItOAS))
continue; continue;
@ -912,7 +912,7 @@ protected:
// First find the offset and size of I. // First find the offset and size of I.
AAPointerInfo::OffsetAndSize OAS(-1, -1); AAPointerInfo::OffsetAndSize OAS(-1, -1);
for (auto &It : AccessBins) { for (const auto &It : AccessBins) {
for (auto &Access : *It.getSecond()) { for (auto &Access : *It.getSecond()) {
if (Access.getRemoteInst() == &I) { if (Access.getRemoteInst() == &I) {
OAS = It.getFirst(); OAS = It.getFirst();
@ -1148,7 +1148,7 @@ struct AAPointerInfoImpl
// Combine the accesses bin by bin. // Combine the accesses bin by bin.
ChangeStatus Changed = ChangeStatus::UNCHANGED; ChangeStatus Changed = ChangeStatus::UNCHANGED;
for (auto &It : OtherAAImpl.getState()) { for (const auto &It : OtherAAImpl.getState()) {
OffsetAndSize OAS = OffsetAndSize::getUnknown(); OffsetAndSize OAS = OffsetAndSize::getUnknown();
if (Offset != OffsetAndSize::Unknown) if (Offset != OffsetAndSize::Unknown)
OAS = OffsetAndSize(It.first.getOffset() + Offset, It.first.getSize()); OAS = OffsetAndSize(It.first.getOffset() + Offset, It.first.getSize());
@ -1802,7 +1802,7 @@ bool AAReturnedValuesImpl::checkForAllReturnedValuesAndReturnInsts(
// Check all returned values but ignore call sites as long as we have not // Check all returned values but ignore call sites as long as we have not
// encountered an overdefined one during an update. // encountered an overdefined one during an update.
for (auto &It : ReturnedValues) { for (const auto &It : ReturnedValues) {
Value *RV = It.first; Value *RV = It.first;
if (!Pred(*RV, It.second)) if (!Pred(*RV, It.second))
return false; return false;
@ -3977,7 +3977,7 @@ identifyAliveSuccessors(Attributor &A, const SwitchInst &SI,
if (!C || isa_and_nonnull<UndefValue>(C.value())) { if (!C || isa_and_nonnull<UndefValue>(C.value())) {
// No value yet, assume all edges are dead. // No value yet, assume all edges are dead.
} else if (isa_and_nonnull<ConstantInt>(C.value())) { } else if (isa_and_nonnull<ConstantInt>(C.value())) {
for (auto &CaseIt : SI.cases()) { for (const auto &CaseIt : SI.cases()) {
if (CaseIt.getCaseValue() == C.value()) { if (CaseIt.getCaseValue() == C.value()) {
AliveSuccessors.push_back(&CaseIt.getCaseSuccessor()->front()); AliveSuccessors.push_back(&CaseIt.getCaseSuccessor()->front());
return UsedAssumedInformation; return UsedAssumedInformation;
@ -5141,7 +5141,7 @@ ChangeStatus AANoCaptureImpl::updateImpl(Attributor &A) {
if (!RVAA.getState().isValidState()) if (!RVAA.getState().isValidState())
return false; return false;
bool SeenConstant = false; bool SeenConstant = false;
for (auto &It : RVAA.returned_values()) { for (const auto &It : RVAA.returned_values()) {
if (isa<Constant>(It.first)) { if (isa<Constant>(It.first)) {
if (SeenConstant) if (SeenConstant)
return false; return false;
@ -5902,7 +5902,7 @@ struct AAHeapToStackFunction final : public AAHeapToStack {
STATS_DECL( STATS_DECL(
MallocCalls, Function, MallocCalls, Function,
"Number of malloc/calloc/aligned_alloc calls converted to allocas"); "Number of malloc/calloc/aligned_alloc calls converted to allocas");
for (auto &It : AllocationInfos) for (const auto &It : AllocationInfos)
if (It.second->Status != AllocationInfo::INVALID) if (It.second->Status != AllocationInfo::INVALID)
++BUILD_STAT_NAME(MallocCalls, Function); ++BUILD_STAT_NAME(MallocCalls, Function);
} }
@ -5919,7 +5919,7 @@ struct AAHeapToStackFunction final : public AAHeapToStack {
if (!isValidState()) if (!isValidState())
return false; return false;
for (auto &It : AllocationInfos) { for (const auto &It : AllocationInfos) {
AllocationInfo &AI = *It.second; AllocationInfo &AI = *It.second;
if (AI.Status == AllocationInfo::INVALID) if (AI.Status == AllocationInfo::INVALID)
continue; continue;
@ -8980,7 +8980,7 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl {
if (Undef) if (Undef)
unionAssumedWithUndef(); unionAssumedWithUndef();
else { else {
for (auto &It : *OpAA) for (const auto &It : *OpAA)
unionAssumed(It); unionAssumed(It);
} }
@ -8988,9 +8988,9 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl {
// select i1 *, undef , undef => undef // select i1 *, undef , undef => undef
unionAssumedWithUndef(); unionAssumedWithUndef();
} else { } else {
for (auto &It : LHSAAPVS) for (const auto &It : LHSAAPVS)
unionAssumed(It); unionAssumed(It);
for (auto &It : RHSAAPVS) for (const auto &It : RHSAAPVS)
unionAssumed(It); unionAssumed(It);
} }
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED
@ -9416,7 +9416,7 @@ struct AACallEdgesCallSite : public AACallEdgesImpl {
// Process callee metadata if available. // Process callee metadata if available.
if (auto *MD = getCtxI()->getMetadata(LLVMContext::MD_callees)) { if (auto *MD = getCtxI()->getMetadata(LLVMContext::MD_callees)) {
for (auto &Op : MD->operands()) { for (const auto &Op : MD->operands()) {
Function *Callee = mdconst::dyn_extract_or_null<Function>(Op); Function *Callee = mdconst::dyn_extract_or_null<Function>(Op);
if (Callee) if (Callee)
addCalledFunction(Callee, Change); addCalledFunction(Callee, Change);
@ -9571,7 +9571,7 @@ private:
} }
SmallVector<const AAFunctionReachability *, 8> Deps; SmallVector<const AAFunctionReachability *, 8> Deps;
for (auto &AAEdges : AAEdgesList) { for (const auto &AAEdges : AAEdgesList) {
const SetVector<Function *> &Edges = AAEdges->getOptimisticEdges(); const SetVector<Function *> &Edges = AAEdges->getOptimisticEdges();
for (Function *Edge : Edges) { for (Function *Edge : Edges) {
@ -9851,7 +9851,7 @@ struct AAPotentialValuesImpl : AAPotentialValues {
IRPosition ValIRP = IRPosition::value(V); IRPosition ValIRP = IRPosition::value(V);
if (auto *CB = dyn_cast_or_null<CallBase>(CtxI)) { if (auto *CB = dyn_cast_or_null<CallBase>(CtxI)) {
for (auto &U : CB->args()) { for (const auto &U : CB->args()) {
if (U.get() != &V) if (U.get() != &V)
continue; continue;
ValIRP = IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U)); ValIRP = IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U));
@ -9868,7 +9868,7 @@ struct AAPotentialValuesImpl : AAPotentialValues {
auto &PotentialConstantsAA = A.getAAFor<AAPotentialConstantValues>( auto &PotentialConstantsAA = A.getAAFor<AAPotentialConstantValues>(
*this, ValIRP, DepClassTy::OPTIONAL); *this, ValIRP, DepClassTy::OPTIONAL);
if (PotentialConstantsAA.isValidState()) { if (PotentialConstantsAA.isValidState()) {
for (auto &It : PotentialConstantsAA.getAssumedSet()) for (const auto &It : PotentialConstantsAA.getAssumedSet())
State.unionAssumed({{*ConstantInt::get(&Ty, It), nullptr}, S}); State.unionAssumed({{*ConstantInt::get(&Ty, It), nullptr}, S});
if (PotentialConstantsAA.undefIsContained()) if (PotentialConstantsAA.undefIsContained())
State.unionAssumed({{*UndefValue::get(&Ty), nullptr}, S}); State.unionAssumed({{*UndefValue::get(&Ty), nullptr}, S});
@ -9930,7 +9930,7 @@ struct AAPotentialValuesImpl : AAPotentialValues {
void giveUpOnIntraprocedural(Attributor &A) { void giveUpOnIntraprocedural(Attributor &A) {
auto NewS = StateType::getBestState(getState()); auto NewS = StateType::getBestState(getState());
for (auto &It : getAssumedSet()) { for (const auto &It : getAssumedSet()) {
if (It.second == AA::Intraprocedural) if (It.second == AA::Intraprocedural)
continue; continue;
addValue(A, NewS, *It.first.getValue(), It.first.getCtxI(), addValue(A, NewS, *It.first.getValue(), It.first.getCtxI(),
@ -9982,7 +9982,7 @@ struct AAPotentialValuesImpl : AAPotentialValues {
AA::ValueScope S) const override { AA::ValueScope S) const override {
if (!isValidState()) if (!isValidState())
return false; return false;
for (auto &It : getAssumedSet()) for (const auto &It : getAssumedSet())
if (It.second & S) if (It.second & S)
Values.push_back(It.first); Values.push_back(It.first);
assert(!undefIsContained() && "Undef should be an explicit value!"); assert(!undefIsContained() && "Undef should be an explicit value!");

View File

@ -517,7 +517,7 @@ bool llvm::thinLTOPropagateFunctionAttrs(
++NumThinLinkNoUnwind; ++NumThinLinkNoUnwind;
} }
for (auto &S : V.getSummaryList()) { for (const auto &S : V.getSummaryList()) {
if (auto *FS = dyn_cast<FunctionSummary>(S.get())) { if (auto *FS = dyn_cast<FunctionSummary>(S.get())) {
if (InferredFlags.NoRecurse) if (InferredFlags.NoRecurse)
FS->setNoRecurse(); FS->setNoRecurse();

View File

@ -2397,7 +2397,7 @@ static bool cxxDtorIsEmpty(const Function &Fn) {
if (Fn.isDeclaration()) if (Fn.isDeclaration())
return false; return false;
for (auto &I : Fn.getEntryBlock()) { for (const auto &I : Fn.getEntryBlock()) {
if (I.isDebugOrPseudoInst()) if (I.isDebugOrPseudoInst())
continue; continue;
if (isa<ReturnInst>(I)) if (isa<ReturnInst>(I))

View File

@ -539,7 +539,7 @@ BitSetInfo LowerTypeTestsModule::buildBitSet(
// Compute the byte offset of each address associated with this type // Compute the byte offset of each address associated with this type
// identifier. // identifier.
for (auto &GlobalAndOffset : GlobalLayout) { for (const auto &GlobalAndOffset : GlobalLayout) {
for (MDNode *Type : GlobalAndOffset.first->types()) { for (MDNode *Type : GlobalAndOffset.first->types()) {
if (Type->getOperand(1) != TypeId) if (Type->getOperand(1) != TypeId)
continue; continue;
@ -1912,7 +1912,7 @@ bool LowerTypeTestsModule::lower() {
for (auto &I : *ExportSummary) for (auto &I : *ExportSummary)
for (auto &GVS : I.second.SummaryList) for (auto &GVS : I.second.SummaryList)
if (GVS->isLive()) if (GVS->isLive())
for (auto &Ref : GVS->refs()) for (const auto &Ref : GVS->refs())
AddressTaken.insert(Ref.getGUID()); AddressTaken.insert(Ref.getGUID());
NamedMDNode *CfiFunctionsMD = M.getNamedMetadata("cfi.functions"); NamedMDNode *CfiFunctionsMD = M.getNamedMetadata("cfi.functions");
@ -1938,7 +1938,7 @@ bool LowerTypeTestsModule::lower() {
bool Exported = false; bool Exported = false;
if (auto VI = ExportSummary->getValueInfo(GUID)) if (auto VI = ExportSummary->getValueInfo(GUID))
for (auto &GVS : VI.getSummaryList()) for (const auto &GVS : VI.getSummaryList())
if (GVS->isLive() && !GlobalValue::isLocalLinkage(GVS->linkage())) if (GVS->isLive() && !GlobalValue::isLocalLinkage(GVS->linkage()))
Exported = true; Exported = true;

View File

@ -363,7 +363,7 @@ private:
FS->GUIDToFuncNameMap = Map; FS->GUIDToFuncNameMap = Map;
for (const auto &ICS : FS->getCallsiteSamples()) { for (const auto &ICS : FS->getCallsiteSamples()) {
const FunctionSamplesMap &FSMap = ICS.second; const FunctionSamplesMap &FSMap = ICS.second;
for (auto &IFS : FSMap) { for (const auto &IFS : FSMap) {
FunctionSamples &FS = const_cast<FunctionSamples &>(IFS.second); FunctionSamples &FS = const_cast<FunctionSamples &>(IFS.second);
FSToUpdate.push(&FS); FSToUpdate.push(&FS);
} }

View File

@ -387,7 +387,7 @@ bool mustBeUnreachableFunction(ValueInfo TheFnVI) {
return false; return false;
} }
for (auto &Summary : TheFnVI.getSummaryList()) { for (const auto &Summary : TheFnVI.getSummaryList()) {
// Conservatively returns false if any non-live functions are seen. // Conservatively returns false if any non-live functions are seen.
// In general either all summaries should be live or all should be dead. // In general either all summaries should be live or all should be dead.
if (!Summary->isLive()) if (!Summary->isLive())
@ -1048,7 +1048,7 @@ bool DevirtIndex::tryFindVirtualCallTargets(
// conservatively return false early. // conservatively return false early.
const GlobalVarSummary *VS = nullptr; const GlobalVarSummary *VS = nullptr;
bool LocalFound = false; bool LocalFound = false;
for (auto &S : P.VTableVI.getSummaryList()) { for (const auto &S : P.VTableVI.getSummaryList()) {
if (GlobalValue::isLocalLinkage(S->linkage())) { if (GlobalValue::isLocalLinkage(S->linkage())) {
if (LocalFound) if (LocalFound)
return false; return false;
@ -1278,7 +1278,7 @@ bool DevirtIndex::trySingleImplDevirt(MutableArrayRef<ValueInfo> TargetsForSlot,
// If the summary list contains multiple summaries where at least one is // If the summary list contains multiple summaries where at least one is
// a local, give up, as we won't know which (possibly promoted) name to use. // a local, give up, as we won't know which (possibly promoted) name to use.
for (auto &S : TheFn.getSummaryList()) for (const auto &S : TheFn.getSummaryList())
if (GlobalValue::isLocalLinkage(S->linkage()) && Size > 1) if (GlobalValue::isLocalLinkage(S->linkage()) && Size > 1)
return false; return false;
@ -2309,7 +2309,7 @@ void DevirtIndex::run() {
return; return;
DenseMap<GlobalValue::GUID, std::vector<StringRef>> NameByGUID; DenseMap<GlobalValue::GUID, std::vector<StringRef>> NameByGUID;
for (auto &P : ExportSummary.typeIdCompatibleVtableMap()) { for (const auto &P : ExportSummary.typeIdCompatibleVtableMap()) {
NameByGUID[GlobalValue::getGUID(P.first)].push_back(P.first); NameByGUID[GlobalValue::getGUID(P.first)].push_back(P.first);
} }

View File

@ -3218,7 +3218,7 @@ Instruction *InstCombinerImpl::visitSwitchInst(SwitchInst &SI) {
// Compute the number of leading bits we can ignore. // Compute the number of leading bits we can ignore.
// TODO: A better way to determine this would use ComputeNumSignBits(). // TODO: A better way to determine this would use ComputeNumSignBits().
for (auto &C : SI.cases()) { for (const auto &C : SI.cases()) {
LeadingKnownZeros = std::min( LeadingKnownZeros = std::min(
LeadingKnownZeros, C.getCaseValue()->getValue().countLeadingZeros()); LeadingKnownZeros, C.getCaseValue()->getValue().countLeadingZeros());
LeadingKnownOnes = std::min( LeadingKnownOnes = std::min(
@ -4377,7 +4377,7 @@ public:
const auto *MDScopeList = dyn_cast_or_null<MDNode>(ScopeList); const auto *MDScopeList = dyn_cast_or_null<MDNode>(ScopeList);
if (!MDScopeList || !Container.insert(MDScopeList).second) if (!MDScopeList || !Container.insert(MDScopeList).second)
return; return;
for (auto &MDOperand : MDScopeList->operands()) for (const auto &MDOperand : MDScopeList->operands())
if (auto *MDScope = dyn_cast<MDNode>(MDOperand)) if (auto *MDScope = dyn_cast<MDNode>(MDOperand))
Container.insert(MDScope); Container.insert(MDScope);
}; };

View File

@ -992,7 +992,7 @@ struct UseBBInfo : public BBInfo {
// Sum up the count values for all the edges. // Sum up the count values for all the edges.
static uint64_t sumEdgeCount(const ArrayRef<PGOUseEdge *> Edges) { static uint64_t sumEdgeCount(const ArrayRef<PGOUseEdge *> Edges) {
uint64_t Total = 0; uint64_t Total = 0;
for (auto &E : Edges) { for (const auto &E : Edges) {
if (E->Removed) if (E->Removed)
continue; continue;
Total += E->CountValue; Total += E->CountValue;
@ -1204,7 +1204,7 @@ static void annotateFunctionWithHashMismatch(Function &F,
auto *Existing = F.getMetadata(LLVMContext::MD_annotation); auto *Existing = F.getMetadata(LLVMContext::MD_annotation);
if (Existing) { if (Existing) {
MDTuple *Tuple = cast<MDTuple>(Existing); MDTuple *Tuple = cast<MDTuple>(Existing);
for (auto &N : Tuple->operands()) { for (const auto &N : Tuple->operands()) {
if (cast<MDString>(N.get())->getString() == MetadataName) if (cast<MDString>(N.get())->getString() == MetadataName)
return; return;
Names.push_back(N.get()); Names.push_back(N.get());

View File

@ -1503,7 +1503,7 @@ static void collectReleaseInsertPts(
const BlotMapVector<Value *, RRInfo> &Retains, const BlotMapVector<Value *, RRInfo> &Retains,
DenseMap<const Instruction *, SmallPtrSet<const Value *, 2>> DenseMap<const Instruction *, SmallPtrSet<const Value *, 2>>
&ReleaseInsertPtToRCIdentityRoots) { &ReleaseInsertPtToRCIdentityRoots) {
for (auto &P : Retains) { for (const auto &P : Retains) {
// Retains is a map from an objc_retain call to a RRInfo of the RC identity // Retains is a map from an objc_retain call to a RRInfo of the RC identity
// root of the call. Get the RC identity root of the objc_retain call. // root of the call. Get the RC identity root of the objc_retain call.
Instruction *Retain = cast<Instruction>(P.first); Instruction *Retain = cast<Instruction>(P.first);

View File

@ -295,7 +295,7 @@ void AggressiveDeadCodeElimination::initialize() {
// return of the function. // return of the function.
// We do this by seeing which of the postdomtree root children exit the // We do this by seeing which of the postdomtree root children exit the
// program, and for all others, mark the subtree live. // program, and for all others, mark the subtree live.
for (auto &PDTChild : children<DomTreeNode *>(PDT.getRootNode())) { for (const auto &PDTChild : children<DomTreeNode *>(PDT.getRootNode())) {
auto *BB = PDTChild->getBlock(); auto *BB = PDTChild->getBlock();
auto &Info = BlockInfo[BB]; auto &Info = BlockInfo[BB];
// Real function return // Real function return

View File

@ -165,7 +165,7 @@ static void recordConditions(CallBase &CB, BasicBlock *Pred,
} }
static void addConditions(CallBase &CB, const ConditionsTy &Conditions) { static void addConditions(CallBase &CB, const ConditionsTy &Conditions) {
for (auto &Cond : Conditions) { for (const auto &Cond : Conditions) {
Value *Arg = Cond.first->getOperand(0); Value *Arg = Cond.first->getOperand(0);
Constant *ConstVal = cast<Constant>(Cond.first->getOperand(1)); Constant *ConstVal = cast<Constant>(Cond.first->getOperand(1));
if (Cond.second == ICmpInst::ICMP_EQ) if (Cond.second == ICmpInst::ICMP_EQ)

View File

@ -1900,7 +1900,7 @@ bool GVNPass::processAssumeIntrinsic(AssumeInst *IntrinsicI) {
// after the found access or before the terminator if no such access is // after the found access or before the terminator if no such access is
// found. // found.
if (AL) { if (AL) {
for (auto &Acc : *AL) { for (const auto &Acc : *AL) {
if (auto *Current = dyn_cast<MemoryUseOrDef>(&Acc)) if (auto *Current = dyn_cast<MemoryUseOrDef>(&Acc))
if (!Current->getMemoryInst()->comesBefore(NewS)) { if (!Current->getMemoryInst()->comesBefore(NewS)) {
FirstNonDom = Current; FirstNonDom = Current;

View File

@ -435,7 +435,7 @@ private:
continue; continue;
const VNType &VN = R; const VNType &VN = R;
SmallPtrSet<BasicBlock *, 2> VNBlocks; SmallPtrSet<BasicBlock *, 2> VNBlocks;
for (auto &I : V) { for (const auto &I : V) {
BasicBlock *BBI = I->getParent(); BasicBlock *BBI = I->getParent();
if (!hasEH(BBI)) if (!hasEH(BBI))
VNBlocks.insert(BBI); VNBlocks.insert(BBI);
@ -563,7 +563,7 @@ bool GVNHoist::run(Function &F) {
for (const BasicBlock *BB : depth_first(&F.getEntryBlock())) { for (const BasicBlock *BB : depth_first(&F.getEntryBlock())) {
DFSNumber[BB] = ++BBI; DFSNumber[BB] = ++BBI;
unsigned I = 0; unsigned I = 0;
for (auto &Inst : *BB) for (const auto &Inst : *BB)
DFSNumber[&Inst] = ++I; DFSNumber[&Inst] = ++I;
} }

View File

@ -106,7 +106,7 @@ static bool isLoopDead(Loop *L, ScalarEvolution &SE,
// Make sure that no instructions in the block have potential side-effects. // Make sure that no instructions in the block have potential side-effects.
// This includes instructions that could write to memory, and loads that are // This includes instructions that could write to memory, and loads that are
// marked volatile. // marked volatile.
for (auto &I : L->blocks()) for (const auto &I : L->blocks())
if (any_of(*I, [](Instruction &I) { if (any_of(*I, [](Instruction &I) {
return I.mayHaveSideEffects() && !I.isDroppable(); return I.mayHaveSideEffects() && !I.isDroppable();
})) }))

View File

@ -633,7 +633,7 @@ public:
Accesses.append(Instructions.begin(), Instructions.end()); Accesses.append(Instructions.begin(), Instructions.end());
LLVM_DEBUG(dbgs() << "Backward dependences:\n"); LLVM_DEBUG(dbgs() << "Backward dependences:\n");
for (auto &Dep : Dependences) for (const auto &Dep : Dependences)
if (Dep.isPossiblyBackward()) { if (Dep.isPossiblyBackward()) {
// Note that the designations source and destination follow the program // Note that the designations source and destination follow the program
// order, i.e. source is always first. (The direction is given by the // order, i.e. source is always first. (The direction is given by the
@ -715,7 +715,7 @@ public:
*Dependences); *Dependences);
int NumUnsafeDependencesActive = 0; int NumUnsafeDependencesActive = 0;
for (auto &InstDep : MID) { for (const auto &InstDep : MID) {
Instruction *I = InstDep.Inst; Instruction *I = InstDep.Inst;
// We update NumUnsafeDependencesActive post-instruction, catch the // We update NumUnsafeDependencesActive post-instruction, catch the
// start of a dependence directly via NumUnsafeDependencesStartOrEnd. // start of a dependence directly via NumUnsafeDependencesStartOrEnd.

View File

@ -5980,7 +5980,7 @@ struct SCEVDbgValueBuilder {
"Expected arithmetic SCEV type"); "Expected arithmetic SCEV type");
bool Success = true; bool Success = true;
unsigned EmitOperator = 0; unsigned EmitOperator = 0;
for (auto &Op : CommExpr->operands()) { for (const auto &Op : CommExpr->operands()) {
Success &= pushSCEV(Op); Success &= pushSCEV(Op);
if (EmitOperator >= 1) if (EmitOperator >= 1)
@ -6490,7 +6490,7 @@ static void DbgGatherSalvagableDVI(
Loop *L, ScalarEvolution &SE, Loop *L, ScalarEvolution &SE,
SmallVector<std::unique_ptr<DVIRecoveryRec>, 2> &SalvageableDVISCEVs, SmallVector<std::unique_ptr<DVIRecoveryRec>, 2> &SalvageableDVISCEVs,
SmallSet<AssertingVH<DbgValueInst>, 2> &DVIHandles) { SmallSet<AssertingVH<DbgValueInst>, 2> &DVIHandles) {
for (auto &B : L->getBlocks()) { for (const auto &B : L->getBlocks()) {
for (auto &I : *B) { for (auto &I : *B) {
auto DVI = dyn_cast<DbgValueInst>(&I); auto DVI = dyn_cast<DbgValueInst>(&I);
if (!DVI) if (!DVI)
@ -6637,7 +6637,7 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU, ScalarEvolution &SE,
// Obtain relevant IVs and attempt to rewrite the salvageable DVIs with // Obtain relevant IVs and attempt to rewrite the salvageable DVIs with
// expressions composed using the derived iteration count. // expressions composed using the derived iteration count.
// TODO: Allow for multiple IV references for nested AddRecSCEVs // TODO: Allow for multiple IV references for nested AddRecSCEVs
for (auto &L : LI) { for (const auto &L : LI) {
if (llvm::PHINode *IV = GetInductionVariable(*L, SE, Reducer)) if (llvm::PHINode *IV = GetInductionVariable(*L, SE, Reducer))
DbgRewriteSalvageableDVIs(L, SE, IV, SalvageableDVIRecords); DbgRewriteSalvageableDVIs(L, SE, IV, SalvageableDVIRecords);
else { else {

View File

@ -1583,7 +1583,7 @@ PreservedAnalyses LoopUnrollPass::run(Function &F,
// legality and profitability checks. This means running the loop unroller // legality and profitability checks. This means running the loop unroller
// will simplify all loops, regardless of whether anything end up being // will simplify all loops, regardless of whether anything end up being
// unrolled. // unrolled.
for (auto &L : LI) { for (const auto &L : LI) {
Changed |= Changed |=
simplifyLoop(L, &DT, &LI, &SE, &AC, nullptr, false /* PreserveLCSSA */); simplifyLoop(L, &DT, &LI, &SE, &AC, nullptr, false /* PreserveLCSSA */);
Changed |= formLCSSARecursively(*L, DT, &LI, &SE); Changed |= formLCSSARecursively(*L, DT, &LI, &SE);

View File

@ -2176,7 +2176,7 @@ public:
// the inlinedAt chain. If the function does not have a DISubprogram, we // the inlinedAt chain. If the function does not have a DISubprogram, we
// only map them to the containing function. // only map them to the containing function.
MapVector<DISubprogram *, SmallVector<Value *, 8>> Subprog2Exprs; MapVector<DISubprogram *, SmallVector<Value *, 8>> Subprog2Exprs;
for (auto &KV : Inst2Matrix) { for (const auto &KV : Inst2Matrix) {
if (Func.getSubprogram()) { if (Func.getSubprogram()) {
auto *I = cast<Instruction>(KV.first); auto *I = cast<Instruction>(KV.first);
DILocation *Context = I->getDebugLoc(); DILocation *Context = I->getDebugLoc();

View File

@ -207,7 +207,7 @@ private:
Root[I] = ++DFSNum; Root[I] = ++DFSNum;
// Store the DFS Number we had before it possibly gets incremented. // Store the DFS Number we had before it possibly gets incremented.
unsigned int OurDFS = DFSNum; unsigned int OurDFS = DFSNum;
for (auto &Op : I->operands()) { for (const auto &Op : I->operands()) {
if (auto *InstOp = dyn_cast<Instruction>(Op)) { if (auto *InstOp = dyn_cast<Instruction>(Op)) {
if (Root.lookup(Op) == 0) if (Root.lookup(Op) == 0)
FindSCC(InstOp); FindSCC(InstOp);
@ -3218,7 +3218,7 @@ void NewGVN::verifyMemoryCongruency() const {
// We could have phi nodes which operands are all trivially dead, // We could have phi nodes which operands are all trivially dead,
// so we don't process them. // so we don't process them.
if (auto *MemPHI = dyn_cast<MemoryPhi>(Pair.first)) { if (auto *MemPHI = dyn_cast<MemoryPhi>(Pair.first)) {
for (auto &U : MemPHI->incoming_values()) { for (const auto &U : MemPHI->incoming_values()) {
if (auto *I = dyn_cast<Instruction>(&*U)) { if (auto *I = dyn_cast<Instruction>(&*U)) {
if (!isInstructionTriviallyDead(I)) if (!isInstructionTriviallyDead(I))
return true; return true;

View File

@ -1592,7 +1592,7 @@ deleteDeadClonedBlocks(Loop &L, ArrayRef<BasicBlock *> ExitBlocks,
// Find all the dead clones, and remove them from their successors. // Find all the dead clones, and remove them from their successors.
SmallVector<BasicBlock *, 16> DeadBlocks; SmallVector<BasicBlock *, 16> DeadBlocks;
for (BasicBlock *BB : llvm::concat<BasicBlock *const>(L.blocks(), ExitBlocks)) for (BasicBlock *BB : llvm::concat<BasicBlock *const>(L.blocks(), ExitBlocks))
for (auto &VMap : VMaps) for (const auto &VMap : VMaps)
if (BasicBlock *ClonedBB = cast_or_null<BasicBlock>(VMap->lookup(BB))) if (BasicBlock *ClonedBB = cast_or_null<BasicBlock>(VMap->lookup(BB)))
if (!DT.isReachableFromEntry(ClonedBB)) { if (!DT.isReachableFromEntry(ClonedBB)) {
for (BasicBlock *SuccBB : successors(ClonedBB)) for (BasicBlock *SuccBB : successors(ClonedBB))
@ -2247,7 +2247,7 @@ static void unswitchNontrivialInvariants(
assert(SI->getDefaultDest() == RetainedSuccBB && assert(SI->getDefaultDest() == RetainedSuccBB &&
"Not retaining default successor!"); "Not retaining default successor!");
SI->setDefaultDest(LoopPH); SI->setDefaultDest(LoopPH);
for (auto &Case : SI->cases()) for (const auto &Case : SI->cases())
if (Case.getCaseSuccessor() == RetainedSuccBB) if (Case.getCaseSuccessor() == RetainedSuccBB)
Case.setSuccessor(LoopPH); Case.setSuccessor(LoopPH);
else else
@ -2308,7 +2308,7 @@ static void unswitchNontrivialInvariants(
SwitchInst *NewSI = cast<SwitchInst>(NewTI); SwitchInst *NewSI = cast<SwitchInst>(NewTI);
assert(NewSI->getDefaultDest() == RetainedSuccBB && assert(NewSI->getDefaultDest() == RetainedSuccBB &&
"Not retaining default successor!"); "Not retaining default successor!");
for (auto &Case : NewSI->cases()) for (const auto &Case : NewSI->cases())
Case.getCaseSuccessor()->removePredecessor( Case.getCaseSuccessor()->removePredecessor(
ParentBB, ParentBB,
/*KeepOneInputPHIs*/ true); /*KeepOneInputPHIs*/ true);

View File

@ -666,7 +666,7 @@ private:
}); });
double Score = 0; double Score = 0;
for (auto &Jump : Jumps) { for (const auto &Jump : Jumps) {
const auto SrcBlock = Jump->Source; const auto SrcBlock = Jump->Source;
const auto DstBlock = Jump->Target; const auto DstBlock = Jump->Target;
Score += ::extTSPScore(SrcBlock->EstimatedAddr, SrcBlock->Size, Score += ::extTSPScore(SrcBlock->EstimatedAddr, SrcBlock->Size,
@ -711,7 +711,7 @@ private:
return; return;
// Apply the merge, compute the corresponding gain, and update the best // Apply the merge, compute the corresponding gain, and update the best
// value, if the merge is beneficial // value, if the merge is beneficial
for (auto &MergeType : MergeTypes) { for (const auto &MergeType : MergeTypes) {
Gain.updateIfLessThan( Gain.updateIfLessThan(
computeMergeGain(ChainPred, ChainSucc, Jumps, Offset, MergeType)); computeMergeGain(ChainPred, ChainSucc, Jumps, Offset, MergeType));
} }

View File

@ -226,7 +226,7 @@ void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) {
if (VI && ImportIndex.hasSyntheticEntryCounts()) { if (VI && ImportIndex.hasSyntheticEntryCounts()) {
if (Function *F = dyn_cast<Function>(&GV)) { if (Function *F = dyn_cast<Function>(&GV)) {
if (!F->isDeclaration()) { if (!F->isDeclaration()) {
for (auto &S : VI.getSummaryList()) { for (const auto &S : VI.getSummaryList()) {
auto *FS = cast<FunctionSummary>(S->getBaseObject()); auto *FS = cast<FunctionSummary>(S->getBaseObject());
if (FS->modulePath() == M.getModuleIdentifier()) { if (FS->modulePath() == M.getModuleIdentifier()) {
F->setEntryCount(Function::ProfileCount(FS->entryCount(), F->setEntryCount(Function::ProfileCount(FS->entryCount(),

View File

@ -417,7 +417,7 @@ bool llvm::formLCSSARecursively(Loop &L, const DominatorTree &DT,
static bool formLCSSAOnAllLoops(const LoopInfo *LI, const DominatorTree &DT, static bool formLCSSAOnAllLoops(const LoopInfo *LI, const DominatorTree &DT,
ScalarEvolution *SE) { ScalarEvolution *SE) {
bool Changed = false; bool Changed = false;
for (auto &L : *LI) for (const auto &L : *LI)
Changed |= formLCSSARecursively(*L, DT, LI, SE); Changed |= formLCSSARecursively(*L, DT, LI, SE);
return Changed; return Changed;
} }

View File

@ -1587,7 +1587,7 @@ bool llvm::LowerDbgDeclare(Function &F) {
WorkList.push_back(AI); WorkList.push_back(AI);
while (!WorkList.empty()) { while (!WorkList.empty()) {
const Value *V = WorkList.pop_back_val(); const Value *V = WorkList.pop_back_val();
for (auto &AIUse : V->uses()) { for (const auto &AIUse : V->uses()) {
User *U = AIUse.getUser(); User *U = AIUse.getUser();
if (StoreInst *SI = dyn_cast<StoreInst>(U)) { if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
if (AIUse.getOperandNo() == 1) if (AIUse.getOperandNo() == 1)

View File

@ -148,7 +148,7 @@ public:
/// Returns a list of pairs (target node, amount of flow to the target). /// Returns a list of pairs (target node, amount of flow to the target).
const std::vector<std::pair<uint64_t, int64_t>> getFlow(uint64_t Src) const { const std::vector<std::pair<uint64_t, int64_t>> getFlow(uint64_t Src) const {
std::vector<std::pair<uint64_t, int64_t>> Flow; std::vector<std::pair<uint64_t, int64_t>> Flow;
for (auto &Edge : Edges[Src]) { for (const auto &Edge : Edges[Src]) {
if (Edge.Flow > 0) if (Edge.Flow > 0)
Flow.push_back(std::make_pair(Edge.Dst, Edge.Flow)); Flow.push_back(std::make_pair(Edge.Dst, Edge.Flow));
} }
@ -158,7 +158,7 @@ public:
/// Get the total flow between a pair of nodes. /// Get the total flow between a pair of nodes.
int64_t getFlow(uint64_t Src, uint64_t Dst) const { int64_t getFlow(uint64_t Src, uint64_t Dst) const {
int64_t Flow = 0; int64_t Flow = 0;
for (auto &Edge : Edges[Src]) { for (const auto &Edge : Edges[Src]) {
if (Edge.Dst == Dst) { if (Edge.Dst == Dst) {
Flow += Edge.Flow; Flow += Edge.Flow;
} }
@ -1137,7 +1137,7 @@ void extractWeights(MinCostMaxFlow &Network, FlowFunction &Func) {
auto &Block = Func.Blocks[Src]; auto &Block = Func.Blocks[Src];
uint64_t SrcOut = 3 * Src + 1; uint64_t SrcOut = 3 * Src + 1;
int64_t Flow = 0; int64_t Flow = 0;
for (auto &Adj : Network.getFlow(SrcOut)) { for (const auto &Adj : Network.getFlow(SrcOut)) {
uint64_t DstIn = Adj.first; uint64_t DstIn = Adj.first;
int64_t DstFlow = Adj.second; int64_t DstFlow = Adj.second;
bool IsAuxNode = (DstIn < 3 * NumBlocks && DstIn % 3 == 2); bool IsAuxNode = (DstIn < 3 * NumBlocks && DstIn % 3 == 2);
@ -1176,7 +1176,7 @@ void verifyWeights(const FlowFunction &Func) {
const uint64_t NumBlocks = Func.Blocks.size(); const uint64_t NumBlocks = Func.Blocks.size();
auto InFlow = std::vector<uint64_t>(NumBlocks, 0); auto InFlow = std::vector<uint64_t>(NumBlocks, 0);
auto OutFlow = std::vector<uint64_t>(NumBlocks, 0); auto OutFlow = std::vector<uint64_t>(NumBlocks, 0);
for (auto &Jump : Func.Jumps) { for (const auto &Jump : Func.Jumps) {
InFlow[Jump.Target] += Jump.Flow; InFlow[Jump.Target] += Jump.Flow;
OutFlow[Jump.Source] += Jump.Flow; OutFlow[Jump.Source] += Jump.Flow;
} }
@ -1202,7 +1202,7 @@ void verifyWeights(const FlowFunction &Func) {
// One could modify FlowFunction to hold edges indexed by the sources, which // One could modify FlowFunction to hold edges indexed by the sources, which
// will avoid a creation of the object // will avoid a creation of the object
auto PositiveFlowEdges = std::vector<std::vector<uint64_t>>(NumBlocks); auto PositiveFlowEdges = std::vector<std::vector<uint64_t>>(NumBlocks);
for (auto &Jump : Func.Jumps) { for (const auto &Jump : Func.Jumps) {
if (Jump.Flow > 0) { if (Jump.Flow > 0) {
PositiveFlowEdges[Jump.Source].push_back(Jump.Target); PositiveFlowEdges[Jump.Source].push_back(Jump.Target);
} }

View File

@ -5272,7 +5272,7 @@ static bool eliminateDeadSwitchCases(SwitchInst *SI, DomTreeUpdater *DTU,
SmallVector<ConstantInt *, 8> DeadCases; SmallVector<ConstantInt *, 8> DeadCases;
SmallDenseMap<BasicBlock *, int, 8> NumPerSuccessorCases; SmallDenseMap<BasicBlock *, int, 8> NumPerSuccessorCases;
SmallVector<BasicBlock *, 8> UniqueSuccessors; SmallVector<BasicBlock *, 8> UniqueSuccessors;
for (auto &Case : SI->cases()) { for (const auto &Case : SI->cases()) {
auto *Successor = Case.getCaseSuccessor(); auto *Successor = Case.getCaseSuccessor();
if (DTU) { if (DTU) {
if (!NumPerSuccessorCases.count(Successor)) if (!NumPerSuccessorCases.count(Successor))
@ -5372,7 +5372,7 @@ static bool ForwardSwitchConditionToPHI(SwitchInst *SI) {
ForwardingNodesMap ForwardingNodes; ForwardingNodesMap ForwardingNodes;
BasicBlock *SwitchBlock = SI->getParent(); BasicBlock *SwitchBlock = SI->getParent();
bool Changed = false; bool Changed = false;
for (auto &Case : SI->cases()) { for (const auto &Case : SI->cases()) {
ConstantInt *CaseValue = Case.getCaseValue(); ConstantInt *CaseValue = Case.getCaseValue();
BasicBlock *CaseDest = Case.getCaseSuccessor(); BasicBlock *CaseDest = Case.getCaseSuccessor();
@ -5588,7 +5588,7 @@ static bool initializeUniqueCases(SwitchInst *SI, PHINode *&PHI,
const DataLayout &DL, const DataLayout &DL,
const TargetTransformInfo &TTI, const TargetTransformInfo &TTI,
uintptr_t MaxUniqueResults) { uintptr_t MaxUniqueResults) {
for (auto &I : SI->cases()) { for (const auto &I : SI->cases()) {
ConstantInt *CaseVal = I.getCaseValue(); ConstantInt *CaseVal = I.getCaseValue();
// Resulting value at phi nodes for this case value. // Resulting value at phi nodes for this case value.
@ -6494,7 +6494,7 @@ static bool ReduceSwitchRange(SwitchInst *SI, IRBuilder<> &Builder,
// cases such as a sequence crossing zero {-4,0,4,8} if we interpret case values // cases such as a sequence crossing zero {-4,0,4,8} if we interpret case values
// as signed. // as signed.
SmallVector<int64_t,4> Values; SmallVector<int64_t,4> Values;
for (auto &C : SI->cases()) for (const auto &C : SI->cases())
Values.push_back(C.getCaseValue()->getValue().getSExtValue()); Values.push_back(C.getCaseValue()->getValue().getSExtValue());
llvm::sort(Values); llvm::sort(Values);
@ -7043,7 +7043,7 @@ static bool removeUndefIntroducingPredecessor(BasicBlock *BB,
Builder.SetInsertPoint(Unreachable); Builder.SetInsertPoint(Unreachable);
// The new block contains only one instruction: Unreachable // The new block contains only one instruction: Unreachable
Builder.CreateUnreachable(); Builder.CreateUnreachable();
for (auto &Case : SI->cases()) for (const auto &Case : SI->cases())
if (Case.getCaseSuccessor() == BB) { if (Case.getCaseSuccessor() == BB) {
BB->removePredecessor(Predecessor); BB->removePredecessor(Predecessor);
Case.setSuccessor(Unreachable); Case.setSuccessor(Unreachable);

View File

@ -1364,7 +1364,7 @@ bool LoopVectorizationLegality::prepareToFoldTailByMasking() {
SmallPtrSet<const Value *, 8> ReductionLiveOuts; SmallPtrSet<const Value *, 8> ReductionLiveOuts;
for (auto &Reduction : getReductionVars()) for (const auto &Reduction : getReductionVars())
ReductionLiveOuts.insert(Reduction.second.getLoopExitInstr()); ReductionLiveOuts.insert(Reduction.second.getLoopExitInstr());
// TODO: handle non-reduction outside users when tail is folded by masking. // TODO: handle non-reduction outside users when tail is folded by masking.

View File

@ -2755,7 +2755,7 @@ void InnerLoopVectorizer::scalarizeInstruction(Instruction *Instr,
// Replace the operands of the cloned instructions with their scalar // Replace the operands of the cloned instructions with their scalar
// equivalents in the new loop. // equivalents in the new loop.
for (auto &I : enumerate(RepRecipe->operands())) { for (const auto &I : enumerate(RepRecipe->operands())) {
auto InputInstance = Instance; auto InputInstance = Instance;
VPValue *Operand = I.value(); VPValue *Operand = I.value();
VPReplicateRecipe *OperandR = dyn_cast<VPReplicateRecipe>(Operand); VPReplicateRecipe *OperandR = dyn_cast<VPReplicateRecipe>(Operand);
@ -3100,7 +3100,7 @@ void InnerLoopVectorizer::createInductionResumeValues(
// If we come from a bypass edge then we need to start from the original // If we come from a bypass edge then we need to start from the original
// start value. // start value.
Instruction *OldInduction = Legal->getPrimaryInduction(); Instruction *OldInduction = Legal->getPrimaryInduction();
for (auto &InductionEntry : Legal->getInductionVars()) { for (const auto &InductionEntry : Legal->getInductionVars()) {
PHINode *OrigPhi = InductionEntry.first; PHINode *OrigPhi = InductionEntry.first;
InductionDescriptor II = InductionEntry.second; InductionDescriptor II = InductionEntry.second;
@ -3655,7 +3655,7 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
// edge. // edge.
// Fix-up external users of the induction variables. // Fix-up external users of the induction variables.
for (auto &Entry : Legal->getInductionVars()) for (const auto &Entry : Legal->getInductionVars())
fixupIVUsers(Entry.first, Entry.second, fixupIVUsers(Entry.first, Entry.second,
getOrCreateVectorTripCount(VectorLoop->getLoopPreheader()), getOrCreateVectorTripCount(VectorLoop->getLoopPreheader()),
IVEndValues[Entry.first], LoopMiddleBlock, IVEndValues[Entry.first], LoopMiddleBlock,
@ -3665,7 +3665,7 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
// Fix LCSSA phis not already fixed earlier. Extracts may need to be generated // Fix LCSSA phis not already fixed earlier. Extracts may need to be generated
// in the exit block, so update the builder. // in the exit block, so update the builder.
State.Builder.SetInsertPoint(State.CFG.ExitBB->getFirstNonPHI()); State.Builder.SetInsertPoint(State.CFG.ExitBB->getFirstNonPHI());
for (auto &KV : Plan.getLiveOuts()) for (const auto &KV : Plan.getLiveOuts())
KV.second->fixPhi(Plan, State); KV.second->fixPhi(Plan, State);
for (Instruction *PI : PredicatedInstructions) for (Instruction *PI : PredicatedInstructions)
@ -4182,7 +4182,7 @@ void InnerLoopVectorizer::widenCallInstruction(CallInst &CI, VPValue *Def,
for (unsigned Part = 0; Part < UF; ++Part) { for (unsigned Part = 0; Part < UF; ++Part) {
SmallVector<Type *, 2> TysForDecl = {CI.getType()}; SmallVector<Type *, 2> TysForDecl = {CI.getType()};
SmallVector<Value *, 4> Args; SmallVector<Value *, 4> Args;
for (auto &I : enumerate(ArgOperands.operands())) { for (const auto &I : enumerate(ArgOperands.operands())) {
// Some intrinsics have a scalar argument - don't replace it with a // Some intrinsics have a scalar argument - don't replace it with a
// vector. // vector.
Value *Arg; Value *Arg;
@ -4359,7 +4359,7 @@ void LoopVectorizationCostModel::collectLoopScalars(ElementCount VF) {
// An induction variable will remain scalar if all users of the induction // An induction variable will remain scalar if all users of the induction
// variable and induction variable update remain scalar. // variable and induction variable update remain scalar.
for (auto &Induction : Legal->getInductionVars()) { for (const auto &Induction : Legal->getInductionVars()) {
auto *Ind = Induction.first; auto *Ind = Induction.first;
auto *IndUpdate = cast<Instruction>(Ind->getIncomingValueForBlock(Latch)); auto *IndUpdate = cast<Instruction>(Ind->getIncomingValueForBlock(Latch));
@ -4749,7 +4749,7 @@ void LoopVectorizationCostModel::collectLoopUniforms(ElementCount VF) {
// nodes separately. An induction variable will remain uniform if all users // nodes separately. An induction variable will remain uniform if all users
// of the induction variable and induction variable update remain uniform. // of the induction variable and induction variable update remain uniform.
// The code below handles both pointer and non-pointer induction variables. // The code below handles both pointer and non-pointer induction variables.
for (auto &Induction : Legal->getInductionVars()) { for (const auto &Induction : Legal->getInductionVars()) {
auto *Ind = Induction.first; auto *Ind = Induction.first;
auto *IndUpdate = cast<Instruction>(Ind->getIncomingValueForBlock(Latch)); auto *IndUpdate = cast<Instruction>(Ind->getIncomingValueForBlock(Latch));
@ -5381,7 +5381,7 @@ VectorizationFactor LoopVectorizationCostModel::selectVectorizationFactor(
raw_string_ostream OS(OutString); raw_string_ostream OS(OutString);
assert(!Subset.empty() && "Unexpected empty range"); assert(!Subset.empty() && "Unexpected empty range");
OS << "Instruction with invalid costs prevented vectorization at VF=("; OS << "Instruction with invalid costs prevented vectorization at VF=(";
for (auto &Pair : Subset) for (const auto &Pair : Subset)
OS << (Pair.second == Subset.front().second ? "" : ", ") OS << (Pair.second == Subset.front().second ? "" : ", ")
<< Pair.second; << Pair.second;
OS << "):"; OS << "):";
@ -5424,7 +5424,7 @@ bool LoopVectorizationCostModel::isCandidateForEpilogueVectorization(
// Phis with uses outside of the loop require special handling and are // Phis with uses outside of the loop require special handling and are
// currently unsupported. // currently unsupported.
for (auto &Entry : Legal->getInductionVars()) { for (const auto &Entry : Legal->getInductionVars()) {
// Look for uses of the value of the induction at the last iteration. // Look for uses of the value of the induction at the last iteration.
Value *PostInc = Entry.first->getIncomingValueForBlock(L.getLoopLatch()); Value *PostInc = Entry.first->getIncomingValueForBlock(L.getLoopLatch());
for (User *U : PostInc->users()) for (User *U : PostInc->users())
@ -5558,7 +5558,7 @@ LoopVectorizationCostModel::getSmallestAndWidestTypes() {
// Reset MaxWidth so that we can find the smallest type used by recurrences // Reset MaxWidth so that we can find the smallest type used by recurrences
// in the loop. // in the loop.
MaxWidth = -1U; MaxWidth = -1U;
for (auto &PhiDescriptorPair : Legal->getReductionVars()) { for (const auto &PhiDescriptorPair : Legal->getReductionVars()) {
const RecurrenceDescriptor &RdxDesc = PhiDescriptorPair.second; const RecurrenceDescriptor &RdxDesc = PhiDescriptorPair.second;
// When finding the min width used by the recurrence we need to account // When finding the min width used by the recurrence we need to account
// for casts on the input operands of the recurrence. // for casts on the input operands of the recurrence.
@ -7342,14 +7342,14 @@ void LoopVectorizationCostModel::collectValuesToIgnore() {
// Ignore type-promoting instructions we identified during reduction // Ignore type-promoting instructions we identified during reduction
// detection. // detection.
for (auto &Reduction : Legal->getReductionVars()) { for (const auto &Reduction : Legal->getReductionVars()) {
const RecurrenceDescriptor &RedDes = Reduction.second; const RecurrenceDescriptor &RedDes = Reduction.second;
const SmallPtrSetImpl<Instruction *> &Casts = RedDes.getCastInsts(); const SmallPtrSetImpl<Instruction *> &Casts = RedDes.getCastInsts();
VecValuesToIgnore.insert(Casts.begin(), Casts.end()); VecValuesToIgnore.insert(Casts.begin(), Casts.end());
} }
// Ignore type-casting instructions we identified during induction // Ignore type-casting instructions we identified during induction
// detection. // detection.
for (auto &Induction : Legal->getInductionVars()) { for (const auto &Induction : Legal->getInductionVars()) {
const InductionDescriptor &IndDes = Induction.second; const InductionDescriptor &IndDes = Induction.second;
const SmallVectorImpl<Instruction *> &Casts = IndDes.getCastInsts(); const SmallVectorImpl<Instruction *> &Casts = IndDes.getCastInsts();
VecValuesToIgnore.insert(Casts.begin(), Casts.end()); VecValuesToIgnore.insert(Casts.begin(), Casts.end());
@ -7357,7 +7357,7 @@ void LoopVectorizationCostModel::collectValuesToIgnore() {
} }
void LoopVectorizationCostModel::collectInLoopReductions() { void LoopVectorizationCostModel::collectInLoopReductions() {
for (auto &Reduction : Legal->getReductionVars()) { for (const auto &Reduction : Legal->getReductionVars()) {
PHINode *Phi = Reduction.first; PHINode *Phi = Reduction.first;
const RecurrenceDescriptor &RdxDesc = Reduction.second; const RecurrenceDescriptor &RdxDesc = Reduction.second;
@ -8721,18 +8721,18 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
// Mark instructions we'll need to sink later and their targets as // Mark instructions we'll need to sink later and their targets as
// ingredients whose recipe we'll need to record. // ingredients whose recipe we'll need to record.
for (auto &Entry : SinkAfter) { for (const auto &Entry : SinkAfter) {
RecipeBuilder.recordRecipeOf(Entry.first); RecipeBuilder.recordRecipeOf(Entry.first);
RecipeBuilder.recordRecipeOf(Entry.second); RecipeBuilder.recordRecipeOf(Entry.second);
} }
for (auto &Reduction : CM.getInLoopReductionChains()) { for (const auto &Reduction : CM.getInLoopReductionChains()) {
PHINode *Phi = Reduction.first; PHINode *Phi = Reduction.first;
RecurKind Kind = RecurKind Kind =
Legal->getReductionVars().find(Phi)->second.getRecurrenceKind(); Legal->getReductionVars().find(Phi)->second.getRecurrenceKind();
const SmallVector<Instruction *, 4> &ReductionOperations = Reduction.second; const SmallVector<Instruction *, 4> &ReductionOperations = Reduction.second;
RecipeBuilder.recordRecipeOf(Phi); RecipeBuilder.recordRecipeOf(Phi);
for (auto &R : ReductionOperations) { for (const auto &R : ReductionOperations) {
RecipeBuilder.recordRecipeOf(R); RecipeBuilder.recordRecipeOf(R);
// For min/max reductions, where we have a pair of icmp/select, we also // For min/max reductions, where we have a pair of icmp/select, we also
// need to record the ICmp recipe, so it can be removed later. // need to record the ICmp recipe, so it can be removed later.
@ -8913,7 +8913,7 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
} }
return nullptr; return nullptr;
}; };
for (auto &Entry : SinkAfter) { for (const auto &Entry : SinkAfter) {
VPRecipeBase *Sink = RecipeBuilder.getRecipe(Entry.first); VPRecipeBase *Sink = RecipeBuilder.getRecipe(Entry.first);
VPRecipeBase *Target = RecipeBuilder.getRecipe(Entry.second); VPRecipeBase *Target = RecipeBuilder.getRecipe(Entry.second);
@ -9112,7 +9112,7 @@ VPlanPtr LoopVectorizationPlanner::buildVPlan(VFRange &Range) {
void LoopVectorizationPlanner::adjustRecipesForReductions( void LoopVectorizationPlanner::adjustRecipesForReductions(
VPBasicBlock *LatchVPBB, VPlanPtr &Plan, VPRecipeBuilder &RecipeBuilder, VPBasicBlock *LatchVPBB, VPlanPtr &Plan, VPRecipeBuilder &RecipeBuilder,
ElementCount MinVF) { ElementCount MinVF) {
for (auto &Reduction : CM.getInLoopReductionChains()) { for (const auto &Reduction : CM.getInLoopReductionChains()) {
PHINode *Phi = Reduction.first; PHINode *Phi = Reduction.first;
const RecurrenceDescriptor &RdxDesc = const RecurrenceDescriptor &RdxDesc =
Legal->getReductionVars().find(Phi)->second; Legal->getReductionVars().find(Phi)->second;
@ -10496,7 +10496,7 @@ LoopVectorizeResult LoopVectorizePass::runImpl(
// legality and profitability checks. This means running the loop vectorizer // legality and profitability checks. This means running the loop vectorizer
// will simplify all loops, regardless of whether anything end up being // will simplify all loops, regardless of whether anything end up being
// vectorized. // vectorized.
for (auto &L : *LI) for (const auto &L : *LI)
Changed |= CFGChanged |= Changed |= CFGChanged |=
simplifyLoop(L, DT, LI, SE, AC, nullptr, false /* PreserveLCSSA */); simplifyLoop(L, DT, LI, SE, AC, nullptr, false /* PreserveLCSSA */);

View File

@ -768,7 +768,7 @@ void VPlan::print(raw_ostream &O) const {
if (!LiveOuts.empty()) if (!LiveOuts.empty())
O << "\n"; O << "\n";
for (auto &KV : LiveOuts) { for (const auto &KV : LiveOuts) {
O << "Live-out "; O << "Live-out ";
KV.second->getPhi()->printAsOperand(O); KV.second->getPhi()->printAsOperand(O);
O << " = "; O << " = ";

View File

@ -282,7 +282,7 @@ bool VPlanVerifier::verifyPlanIsValid(const VPlan &Plan) {
} }
} }
for (auto &KV : Plan.getLiveOuts()) for (const auto &KV : Plan.getLiveOuts())
if (KV.second->getNumOperands() != 1) { if (KV.second->getNumOperands() != 1) {
errs() << "live outs must have a single operand\n"; errs() << "live outs must have a single operand\n";
return false; return false;