Apply clang-tidy's modernize-loop-convert to most of lib/Transforms.

Only minor manual fixes. No functionality change intended.

llvm-svn: 273808
This commit is contained in:
Benjamin Kramer
2016-06-26 12:28:59 +00:00
parent ff976c99c7
commit 135f735af1
53 changed files with 398 additions and 519 deletions

View File

@@ -159,23 +159,18 @@ static bool definedInCaller(const SetVector<BasicBlock *> &Blocks, Value *V) {
void CodeExtractor::findInputsOutputs(ValueSet &Inputs,
ValueSet &Outputs) const {
for (SetVector<BasicBlock *>::const_iterator I = Blocks.begin(),
E = Blocks.end();
I != E; ++I) {
BasicBlock *BB = *I;
for (BasicBlock *BB : Blocks) {
// If a used value is defined outside the region, it's an input. If an
// instruction is used outside the region, it's an output.
for (BasicBlock::iterator II = BB->begin(), IE = BB->end();
II != IE; ++II) {
for (User::op_iterator OI = II->op_begin(), OE = II->op_end();
OI != OE; ++OI)
for (Instruction &II : *BB) {
for (User::op_iterator OI = II.op_begin(), OE = II.op_end(); OI != OE;
++OI)
if (definedInCaller(Blocks, *OI))
Inputs.insert(*OI);
for (User *U : II->users())
for (User *U : II.users())
if (!definedInRegion(Blocks, U)) {
Outputs.insert(&*II);
Outputs.insert(&II);
break;
}
}
@@ -263,25 +258,21 @@ void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) {
}
void CodeExtractor::splitReturnBlocks() {
for (SetVector<BasicBlock *>::iterator I = Blocks.begin(), E = Blocks.end();
I != E; ++I)
if (ReturnInst *RI = dyn_cast<ReturnInst>((*I)->getTerminator())) {
for (BasicBlock *Block : Blocks)
if (ReturnInst *RI = dyn_cast<ReturnInst>(Block->getTerminator())) {
BasicBlock *New =
(*I)->splitBasicBlock(RI->getIterator(), (*I)->getName() + ".ret");
Block->splitBasicBlock(RI->getIterator(), Block->getName() + ".ret");
if (DT) {
// Old dominates New. New node dominates all other nodes dominated
// by Old.
DomTreeNode *OldNode = DT->getNode(*I);
SmallVector<DomTreeNode*, 8> Children;
for (DomTreeNode::iterator DI = OldNode->begin(), DE = OldNode->end();
DI != DE; ++DI)
Children.push_back(*DI);
DomTreeNode *OldNode = DT->getNode(Block);
SmallVector<DomTreeNode *, 8> Children(OldNode->begin(),
OldNode->end());
DomTreeNode *NewNode = DT->addNewBlock(New, *I);
DomTreeNode *NewNode = DT->addNewBlock(New, Block);
for (SmallVectorImpl<DomTreeNode *>::iterator I = Children.begin(),
E = Children.end(); I != E; ++I)
DT->changeImmediateDominator(*I, NewNode);
for (DomTreeNode *I : Children)
DT->changeImmediateDominator(I, NewNode);
}
}
}
@@ -310,27 +301,23 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
std::vector<Type*> paramTy;
// Add the types of the input values to the function's argument list
for (ValueSet::const_iterator i = inputs.begin(), e = inputs.end();
i != e; ++i) {
const Value *value = *i;
for (Value *value : inputs) {
DEBUG(dbgs() << "value used in func: " << *value << "\n");
paramTy.push_back(value->getType());
}
// Add the types of the output values to the function's argument list.
for (ValueSet::const_iterator I = outputs.begin(), E = outputs.end();
I != E; ++I) {
DEBUG(dbgs() << "instr used in func: " << **I << "\n");
for (Value *output : outputs) {
DEBUG(dbgs() << "instr used in func: " << *output << "\n");
if (AggregateArgs)
paramTy.push_back((*I)->getType());
paramTy.push_back(output->getType());
else
paramTy.push_back(PointerType::getUnqual((*I)->getType()));
paramTy.push_back(PointerType::getUnqual(output->getType()));
}
DEBUG(dbgs() << "Function type: " << *RetTy << " f(");
for (std::vector<Type*>::iterator i = paramTy.begin(),
e = paramTy.end(); i != e; ++i)
DEBUG(dbgs() << **i << ", ");
for (Type *i : paramTy)
DEBUG(dbgs() << *i << ", ");
DEBUG(dbgs() << ")\n");
StructType *StructTy;
@@ -372,9 +359,8 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
RewriteVal = &*AI++;
std::vector<User*> Users(inputs[i]->user_begin(), inputs[i]->user_end());
for (std::vector<User*>::iterator use = Users.begin(), useE = Users.end();
use != useE; ++use)
if (Instruction* inst = dyn_cast<Instruction>(*use))
for (User *use : Users)
if (Instruction *inst = dyn_cast<Instruction>(use))
if (Blocks.count(inst->getParent()))
inst->replaceUsesOfWith(inputs[i], RewriteVal);
}
@@ -429,19 +415,19 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
LLVMContext &Context = newFunction->getContext();
// Add inputs as params, or to be filled into the struct
for (ValueSet::iterator i = inputs.begin(), e = inputs.end(); i != e; ++i)
for (Value *input : inputs)
if (AggregateArgs)
StructValues.push_back(*i);
StructValues.push_back(input);
else
params.push_back(*i);
params.push_back(input);
// Create allocas for the outputs
for (ValueSet::iterator i = outputs.begin(), e = outputs.end(); i != e; ++i) {
for (Value *output : outputs) {
if (AggregateArgs) {
StructValues.push_back(*i);
StructValues.push_back(output);
} else {
AllocaInst *alloca =
new AllocaInst((*i)->getType(), nullptr, (*i)->getName() + ".loc",
new AllocaInst(output->getType(), nullptr, output->getName() + ".loc",
&codeReplacer->getParent()->front().front());
ReloadOutputs.push_back(alloca);
params.push_back(alloca);
@@ -522,9 +508,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
std::map<BasicBlock*, BasicBlock*> ExitBlockMap;
unsigned switchVal = 0;
for (SetVector<BasicBlock*>::const_iterator i = Blocks.begin(),
e = Blocks.end(); i != e; ++i) {
TerminatorInst *TI = (*i)->getTerminator();
for (BasicBlock *Block : Blocks) {
TerminatorInst *TI = Block->getTerminator();
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
if (!Blocks.count(TI->getSuccessor(i))) {
BasicBlock *OldTarget = TI->getSuccessor(i);
@@ -576,10 +561,9 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Make sure we are looking at the original successor block, not
// at a newly inserted exit block, which won't be in the dominator
// info.
for (std::map<BasicBlock*, BasicBlock*>::iterator I =
ExitBlockMap.begin(), E = ExitBlockMap.end(); I != E; ++I)
if (DefBlock == I->second) {
DefBlock = I->first;
for (const auto &I : ExitBlockMap)
if (DefBlock == I.second) {
DefBlock = I.first;
break;
}
@@ -677,13 +661,12 @@ void CodeExtractor::moveCodeToFunction(Function *newFunction) {
Function::BasicBlockListType &oldBlocks = oldFunc->getBasicBlockList();
Function::BasicBlockListType &newBlocks = newFunction->getBasicBlockList();
for (SetVector<BasicBlock*>::const_iterator i = Blocks.begin(),
e = Blocks.end(); i != e; ++i) {
for (BasicBlock *Block : Blocks) {
// Delete the basic block from the old function, and the list of blocks
oldBlocks.remove(*i);
oldBlocks.remove(Block);
// Insert this basic block into the new function
newBlocks.push_back(*i);
newBlocks.push_back(Block);
}
}
@@ -721,9 +704,9 @@ Function *CodeExtractor::extractCodeRegion() {
findInputsOutputs(inputs, outputs);
SmallPtrSet<BasicBlock *, 1> ExitBlocks;
for (SetVector<BasicBlock *>::iterator I = Blocks.begin(), E = Blocks.end();
I != E; ++I)
for (succ_iterator SI = succ_begin(*I), SE = succ_end(*I); SI != SE; ++SI)
for (BasicBlock *Block : Blocks)
for (succ_iterator SI = succ_begin(Block), SE = succ_end(Block); SI != SE;
++SI)
if (!Blocks.count(*SI))
ExitBlocks.insert(*SI);
NumExitBlocks = ExitBlocks.size();