diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:41:05 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:41:05 +0000 | 
| commit | 01095a5d43bbfde13731688ddcf6048ebb8b7721 (patch) | |
| tree | 4def12e759965de927d963ac65840d663ef9d1ea /lib/Transforms/Utils/CodeExtractor.cpp | |
| parent | f0f4822ed4b66e3579e92a89f368f8fb860e218e (diff) | |
Notes
Diffstat (limited to 'lib/Transforms/Utils/CodeExtractor.cpp')
| -rw-r--r-- | lib/Transforms/Utils/CodeExtractor.cpp | 113 | 
1 files changed, 49 insertions, 64 deletions
| diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index 823696d88e65..9f2181f87cee 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -77,15 +77,15 @@ static SetVector<BasicBlock *> buildExtractionBlockSet(IteratorT BBBegin,    // Loop over the blocks, adding them to our set-vector, and aborting with an    // empty set if we encounter invalid blocks. -  for (IteratorT I = BBBegin, E = BBEnd; I != E; ++I) { -    if (!Result.insert(*I)) +  do { +    if (!Result.insert(*BBBegin))        llvm_unreachable("Repeated basic blocks in extraction input"); -    if (!isBlockValidForExtraction(**I)) { +    if (!isBlockValidForExtraction(**BBBegin)) {        Result.clear();        return Result;      } -  } +  } while (++BBBegin != BBEnd);  #ifndef NDEBUG    for (SetVector<BasicBlock *>::iterator I = std::next(Result.begin()), @@ -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,28 +301,26 @@ 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 << ", "); -  DEBUG(dbgs() << ")\n"); +  DEBUG({ +    dbgs() << "Function type: " << *RetTy << " f("; +    for (Type *i : paramTy) +      dbgs() << *i << ", "; +    dbgs() << ")\n"; +  });    StructType *StructTy;    if (AggregateArgs && (inputs.size() + outputs.size() > 0)) { @@ -372,9 +361,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 +417,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 +510,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 +563,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 +663,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 +706,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(); | 
