1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[Transforms/IPO] Use range-based for loops (NFC)

This commit is contained in:
Kazu Hirata 2021-02-03 20:41:20 -08:00
parent 7c818b1f11
commit d6e82443c7
5 changed files with 20 additions and 33 deletions

View File

@ -446,9 +446,8 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
"GEPs without uses should be cleaned up already");
IndicesVector Operands;
Operands.reserve(GEP->getNumIndices());
for (User::op_iterator II = GEP->idx_begin(), IE = GEP->idx_end();
II != IE; ++II)
Operands.push_back(cast<ConstantInt>(*II)->getSExtValue());
for (const Use &Idx : GEP->indices())
Operands.push_back(cast<ConstantInt>(Idx)->getSExtValue());
// GEPs with a single 0 index can be merged with direct loads
if (Operands.size() == 1 && Operands.front() == 0)
@ -634,9 +633,8 @@ static bool isSafeToPromoteArgument(Argument *Arg, Type *ByValTy, AAResults &AAR
if (V == Arg) {
// This load actually loads (part of) Arg? Check the indices then.
Indices.reserve(GEP->getNumIndices());
for (User::op_iterator II = GEP->idx_begin(), IE = GEP->idx_end();
II != IE; ++II)
if (ConstantInt *CI = dyn_cast<ConstantInt>(*II))
for (Use &Idx : GEP->indices())
if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx))
Indices.push_back(CI->getSExtValue());
else
// We found a non-constant GEP index for this argument? Bail out
@ -689,9 +687,8 @@ static bool isSafeToPromoteArgument(Argument *Arg, Type *ByValTy, AAResults &AAR
return false;
// Ensure that all of the indices are constants.
for (User::op_iterator i = GEP->idx_begin(), e = GEP->idx_end(); i != e;
++i)
if (ConstantInt *C = dyn_cast<ConstantInt>(*i))
for (Use &Idx : GEP->indices())
if (ConstantInt *C = dyn_cast<ConstantInt>(Idx))
Operands.push_back(C->getSExtValue());
else
return false; // Not a constant operand GEP!

View File

@ -698,9 +698,7 @@ bool HotColdSplitting::outlineColdRegions(Function &F, bool HasProfileSummary) {
bool HotColdSplitting::run(Module &M) {
bool Changed = false;
bool HasProfileSummary = (M.getProfileSummary(/* IsCS */ false) != nullptr);
for (auto It = M.begin(), End = M.end(); It != End; ++It) {
Function &F = *It;
for (Function &F : M) {
// Do not touch declarations.
if (F.isDeclaration())
continue;

View File

@ -529,10 +529,9 @@ void MergeFunctions::eraseInstsUnrelatedToPDI(
// Reduce G to its entry block.
void MergeFunctions::eraseTail(Function *G) {
std::vector<BasicBlock *> WorklistBB;
for (Function::iterator BBI = std::next(G->begin()), BBE = G->end();
BBI != BBE; ++BBI) {
BBI->dropAllReferences();
WorklistBB.push_back(&*BBI);
for (BasicBlock &BB : drop_begin(*G)) {
BB.dropAllReferences();
WorklistBB.push_back(&BB);
}
while (!WorklistBB.empty()) {
BasicBlock *BB = WorklistBB.back();
@ -634,18 +633,15 @@ void MergeFunctions::filterInstsUnrelatedToPDI(
LLVM_DEBUG(
dbgs()
<< " Report parameter debug info related/related instructions: {\n");
for (BasicBlock::iterator BI = GEntryBlock->begin(), BE = GEntryBlock->end();
BI != BE; ++BI) {
Instruction *I = &*BI;
if (PDIRelated.find(I) == PDIRelated.end()) {
for (Instruction &I : *GEntryBlock) {
if (PDIRelated.find(&I) == PDIRelated.end()) {
LLVM_DEBUG(dbgs() << " !PDIRelated: ");
LLVM_DEBUG(I->print(dbgs()));
LLVM_DEBUG(I.print(dbgs()));
LLVM_DEBUG(dbgs() << "\n");
PDIUnrelatedWL.push_back(I);
PDIUnrelatedWL.push_back(&I);
} else {
LLVM_DEBUG(dbgs() << " PDIRelated: ");
LLVM_DEBUG(I->print(dbgs()));
LLVM_DEBUG(I.print(dbgs()));
LLVM_DEBUG(dbgs() << "\n");
}
}

View File

@ -418,12 +418,12 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(
[&ORE](SmallVectorImpl<BasicBlock *> &BlockList) -> BasicBlock * {
BasicBlock *ExitBlock = nullptr;
for (auto *Block : BlockList) {
for (auto SI = succ_begin(Block); SI != succ_end(Block); ++SI) {
if (!is_contained(BlockList, *SI)) {
for (BasicBlock *Succ : successors(Block)) {
if (!is_contained(BlockList, Succ)) {
if (ExitBlock) {
ORE.emit([&]() {
return OptimizationRemarkMissed(DEBUG_TYPE, "MultiExitRegion",
&SI->front())
&Succ->front())
<< "Region dominated by "
<< ore::NV("Block", BlockList.front()->getName())
<< " has more than one region exit edge.";

View File

@ -1907,21 +1907,17 @@ void SampleProfileLoader::buildEdges(Function &F) {
SmallPtrSet<BasicBlock *, 16> Visited;
if (!Predecessors[B1].empty())
llvm_unreachable("Found a stale predecessors list in a basic block.");
for (pred_iterator PI = pred_begin(B1), PE = pred_end(B1); PI != PE; ++PI) {
BasicBlock *B2 = *PI;
for (BasicBlock *B2 : predecessors(B1))
if (Visited.insert(B2).second)
Predecessors[B1].push_back(B2);
}
// Add successors for B1.
Visited.clear();
if (!Successors[B1].empty())
llvm_unreachable("Found a stale successors list in a basic block.");
for (succ_iterator SI = succ_begin(B1), SE = succ_end(B1); SI != SE; ++SI) {
BasicBlock *B2 = *SI;
for (BasicBlock *B2 : successors(B1))
if (Visited.insert(B2).second)
Successors[B1].push_back(B2);
}
}
}