[Beignet] [PATCH] cppcheck: (performance) Prefer prefix ++/-- operators for non-primitive types

Song, Ruiling ruiling.song at intel.com
Sun May 17 19:34:49 PDT 2015


The patch looks good to me. Thanks!

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Daniel Winzen
> Sent: Saturday, May 02, 2015 2:30 PM
> To: beignet at lists.freedesktop.org
> Cc: Daniel Winzen
> Subject: [Beignet] [PATCH] cppcheck: (performance) Prefer prefix ++/--
> operators for non-primitive types
> 
> Signed-off-by: Daniel Winzen <d at winzen4.de>
> ---
>  backend/src/ir/structural_analysis.cpp  | 82
> ++++++++++++++++-----------------  backend/src/llvm/llvm_bitcode_link.cpp
> |  2 +-  backend/src/llvm/llvm_printf_parser.cpp |  4 +-
>  backend/src/llvm/llvm_to_gen.cpp        |  2 +-
>  4 files changed, 45 insertions(+), 45 deletions(-)
> 
> diff --git a/backend/src/ir/structural_analysis.cpp
> b/backend/src/ir/structural_analysis.cpp
> index 101570a..91100c8 100644
> --- a/backend/src/ir/structural_analysis.cpp
> +++ b/backend/src/ir/structural_analysis.cpp
> @@ -54,7 +54,7 @@ namespace analysis
>      while(iter != iter_end)
>      {
>        delete *iter;
> -      iter++;
> +      ++iter;
>      }
>    }
>    void ControlTree::handleSelfLoopNode(Node *loopnode, ir::LabelIndex&
> whileLabel) @@ -63,9 +63,9 @@ namespace analysis
>      ir::BasicBlock *pbb = loopnode->getExit();
>      GBE_ASSERT(pbb->isLoopExit);
>      ir::BasicBlock::iterator it = pbb->end();
> -    it--;
> +    --it;
>      if (pbb->hasExtraBra)
> -      it--;
> +      --it;
>      ir::BranchInstruction* pinsn = static_cast<ir::BranchInstruction
> *>(&*it);
> 
>      if(!pinsn->isPredicated()){
> @@ -97,7 +97,7 @@ namespace analysis
>      while(it != node->children.end())
>      {
>        markNeedIf(*it,status);
> -      it++;
> +      ++it;
>      }
>    }
> 
> @@ -115,7 +115,7 @@ namespace analysis
>      while(it != node->children.end())
>      {
>        markNeedEndif(*it, status);
> -      it++;
> +      ++it;
>      }
>    }
> 
> @@ -132,7 +132,7 @@ namespace analysis
>      while(it != node->children.end())
>      {
>        markStructuredNodes(*it, status);
> -      it++;
> +      ++it;
>      }
>    }
> 
> @@ -142,7 +142,7 @@ namespace analysis
>      ir::BranchInstruction* pinsn = static_cast<ir::BranchInstruction
> *>(pbb->getLastInstruction());
>      ir::Register reg = pinsn->getPredicateIndex();
>      ir::BasicBlock::iterator it = pbb->end();
> -    it--;
> +    --it;
>      /* since this node is an if node, so we remove the BRA instruction at
> the bottom of the exit BB of 'node',
>       * and insert IF instead
>       */
> @@ -158,7 +158,7 @@ namespace analysis
>    {
>      ir::BasicBlock *pbb = node->getExit();
>      ir::BasicBlock::iterator it = pbb->end();
> -    it--;
> +    --it;
>      ir::Instruction *p_last_insn = pbb->getLastInstruction();
> 
>      endiflabel = fn->newLabel();
> @@ -183,7 +183,7 @@ namespace analysis
>    {
>      ir::BasicBlock *pbb = node->getExit();
>      ir::BasicBlock::iterator it = pbb->end();
> -    it--;
> +    --it;
>      if((*it).getOpcode() == ir::OP_BRA)
>        pbb->erase(it);
> 
> @@ -204,7 +204,7 @@ namespace analysis
> 
>      ir::BasicBlock *pbb = node->getEntry();
>      ir::BasicBlock::iterator it = pbb->begin();
> -    it++;
> +    ++it;
> 
>      elselabel = fn->newLabel();
>      pbb->thisElseLabel = elselabel;
> @@ -223,7 +223,7 @@ namespace analysis
>      NodeVector::iterator end = nodes.end();
>      NodeVector::iterator begin = nodes.begin();
>      it = end;
> -    it--;
> +    --it;
>      NodeVector::reverse_iterator rit = nodes.rbegin();
>      /* structured bbs only need if and endif insn to handle the execution
>       * in structure entry and exit BasicBlock, so we process the nodes
> backward, since @@ -253,7 +253,7 @@ namespace analysis
>            eexit->matchingStructureEntry = entry;
>          }
>        }
> -      rit++;
> +      ++rit;
>      }
> 
>      rit = nodes.rbegin();
> @@ -320,7 +320,7 @@ namespace analysis
>            else
>            {
>              index++;
> -            iter++;
> +            ++iter;
>            }
>          }
> 
> @@ -335,7 +335,7 @@ namespace analysis
>          for(size_t i = 0; i < unstruSeqTail.size(); ++i)
>            bbs[firstindex++] = unstruSeqTail[i];
>        }
> -      rit++;
> +      ++rit;
>      }
> 
>     /* now, erase the BRAs inserted before whose targets are their
> fallthrough blocks */ @@ -347,7 +347,7 @@ namespace analysis
>          if(((ir::BranchInstruction
> *)bbs[i]->getLastInstruction())->getLabelIndex() ==
> bbs[i+1]->getLabelIndex())
>          {
>            ir::BasicBlock::iterator it= bbs[i]->end();
> -          it--;
> +          --it;
> 
>            bbs[i]->erase(it);
> 
> @@ -373,9 +373,9 @@ namespace analysis
>              {
>                NodeList::iterator child_iter = (*it)->children.end();
>                ir::LabelIndex endiflabel;
> -              child_iter--;
> +              --child_iter;
>                handleThenNode(*child_iter, endiflabel); // this call would
> pass out the proper endiflabel for handleIfNode's use.
> -              child_iter--;
> +              --child_iter;
>                handleIfNode(*child_iter, endiflabel, endiflabel);
>              }
>              break;
> @@ -386,13 +386,13 @@ namespace analysis
>                ir::LabelIndex endiflabel;
>                ir::LabelIndex elselabel;
>                NodeList::iterator else_node;
> -              child_iter--;
> +              --child_iter;
>                else_node = child_iter;
>                handleElseNode(*child_iter, elselabel, endiflabel);
>                ir::LabelIndex elseBBLabel =
> (*child_iter)->getEntry()->getLabelIndex();
> -              child_iter--;
> +              --child_iter;
>                handleThenNode2(*child_iter, *else_node, elseBBLabel);
> -              child_iter--;
> +              --child_iter;
>                handleIfNode(*child_iter, endiflabel, elselabel);
>              }
>              break;
> @@ -409,7 +409,7 @@ namespace analysis
>          }
>        }
> 
> -      it++;
> +      ++it;
>      }
> 
>    }
> @@ -431,7 +431,7 @@ namespace analysis
>      while(iter != node->children.end())
>      {
>        getStructureSequence(*iter, seq);
> -      iter++;
> +      ++iter;
>      }
> 
>    }
> @@ -458,7 +458,7 @@ namespace analysis
>      {
>        std::set<int> ret = getStructureBasicBlocksIndex(*iter, bbs);
>        result.insert(ret.begin(), ret.end());
> -      iter++;
> +      ++iter;
>      }
>      return result;
>    }
> @@ -478,7 +478,7 @@ namespace analysis
>      {
>        std::set<ir::BasicBlock *> ret = getStructureBasicBlocks(*iter);
>        result.insert(ret.begin(), ret.end());
> -      iter++;
> +      ++iter;
>      }
>      return result;
>    }
> @@ -499,7 +499,7 @@ namespace analysis
>      {
>        if((*iter).getOpcode() == ir::OP_SYNC)
>          return true;
> -      iter++;
> +      ++iter;
>      }
> 
>      return false;
> @@ -527,7 +527,7 @@ namespace analysis
>          varKill.insert(reg);
>        }
> 
> -      iter++;
> +      ++iter;
>      }
>    }
> 
> @@ -543,7 +543,7 @@ namespace analysis
>          {
>            std::set<ir::BasicBlock *> bbs;
>            NodeList::iterator thenIter = (*iter)->children.begin();
> -          thenIter++;
> +          ++thenIter;
>            bbs = getStructureBasicBlocks(*thenIter);
> 
>            Node *elseNode = *((*iter)->children.rbegin()); @@ -554,14
> +554,14 @@ namespace analysis
>            while(bbiter != bbs.end())
>            {
>              (*bbiter)->liveout.insert(livein.begin(), livein.end());
> -            bbiter++;
> +            ++bbiter;
>            }
>          }
> 
>          default:
>            break;
>        }
> -      iter++;
> +      ++iter;
>      }
>    }
> 
> @@ -615,7 +615,7 @@ namespace analysis
>        while(iter_begin != iter_end)
>        {
>          bbmap[p_tmp_bb]->preds().insert(bbmap[*iter_begin]);
> -        iter_begin++;
> +        ++iter_begin;
>        }
> 
>        iter_begin = p_tmp_bb->getSuccessorSet().begin();
> @@ -623,7 +623,7 @@ namespace analysis
>        while(iter_begin != iter_end)
>        {
>          bbmap[p_tmp_bb]->succs().insert(bbmap[*iter_begin]);
> -        iter_begin++;
> +        ++iter_begin;
>        }
> 
>        p_tmp_bb = p_tmp_bb->getNextBlock(); @@ -734,7 +734,7 @@
> namespace analysis
>            p->canBeHandled = false;
>            break;
>          }
> -        iter++;
> +        ++iter;
>        }
> 
>        return insertNode(p);
> @@ -842,7 +842,7 @@ namespace analysis
> 
>      visited.insert(from);
> 
> -    for(NodeSet::const_iterator s = from->succs().begin(); s !=
> from->succs().end(); s++)
> +    for(NodeSet::const_iterator s = from->succs().begin(); s !=
> + from->succs().end(); ++s)
>      {
>        if(path(*s, to, notthrough))
>          return true;
> @@ -906,10 +906,10 @@ namespace analysis
>    void ControlTree::reduce(Node* node,  NodeSet nodeSet)
>    {
>      NodeSet::iterator n;
> -    for(n = nodeSet.begin(); n != nodeSet.end(); n++)
> +    for(n = nodeSet.begin(); n != nodeSet.end(); ++n)
>      {
>        NodeSet::iterator p;
> -      for(p = (*n)->preds().begin(); p != (*n)->preds().end(); p++)
> +      for(p = (*n)->preds().begin(); p != (*n)->preds().end(); ++p)
>        {
>          if(nodeSet.find(*p) != nodeSet.end())
>            continue;
> @@ -925,7 +925,7 @@ namespace analysis
> 
> 
>       NodeSet::iterator s;
> -     for(s = (*n)->succs().begin(); s != (*n)->succs().end(); s++)
> +     for(s = (*n)->succs().begin(); s != (*n)->succs().end(); ++s)
>       {
>          if(nodeSet.find(*s) != nodeSet.end())
>            continue;
> @@ -942,11 +942,11 @@ namespace analysis
> 
>      if(!isCyclic(node))
>      {
> -      for(n = nodeSet.begin(); n != nodeSet.end(); n++)
> +      for(n = nodeSet.begin(); n != nodeSet.end(); ++n)
>        {
>          bool shouldbreak = false;
>          NodeSet::iterator p;
> -        for(p = (*n)->preds().begin(); p != (*n)->preds().end(); p++)
> +        for(p = (*n)->preds().begin(); p != (*n)->preds().end(); ++p)
>          {
>            if(nodeSet.find(*p) == nodeSet.end())
>              continue;
> @@ -978,7 +978,7 @@ namespace analysis
>      {
>        if(!nodeSet.erase(*n))
>        {
> -        n++;
> +        ++n;
>          continue;
>        }
> 
> @@ -1028,7 +1028,7 @@ namespace analysis
>            //reuse the loop info from llvm gaterLoopInfo.
>            const gbe::vector<ir::Loop *> &loops = fn->getLoops();
>            if(loops.size() == 0){
> -            post_ctr++;
> +            ++post_ctr;
>              continue;
>            }
> 
> @@ -1070,7 +1070,7 @@ namespace analysis
>            }
>            else
>            {
> -            post_ctr++;
> +            ++post_ctr;
>            }
>          }
>        }
> diff --git a/backend/src/llvm/llvm_bitcode_link.cpp
> b/backend/src/llvm/llvm_bitcode_link.cpp
> index ebf4386..45081d6 100644
> --- a/backend/src/llvm/llvm_bitcode_link.cpp
> +++ b/backend/src/llvm/llvm_bitcode_link.cpp
> @@ -84,7 +84,7 @@ namespace gbe
>    static bool materializedFuncCall(Module& src, Module& lib,
> llvm::Function &KF, std::set<std::string>& MFS)
>    {
>      bool fromSrc = false;
> -    for (llvm::Function::iterator B = KF.begin(), BE = KF.end(); B != BE; B++) {
> +    for (llvm::Function::iterator B = KF.begin(), BE = KF.end(); B !=
> + BE; ++B) {
>        for (BasicBlock::iterator instI = B->begin(),
>             instE = B->end(); instI != instE; ++instI) {
>          llvm::CallInst* call = dyn_cast<llvm::CallInst>(instI); diff --git
> a/backend/src/llvm/llvm_printf_parser.cpp
> b/backend/src/llvm/llvm_printf_parser.cpp
> index 2f85443..f055785 100644
> --- a/backend/src/llvm/llvm_printf_parser.cpp
> +++ b/backend/src/llvm/llvm_printf_parser.cpp
> @@ -592,7 +592,7 @@ error:
>      }
> 
>      /* First find printfs and caculate all slots size of one loop. */
> -    for (llvm::Function::iterator B = F.begin(), BE = F.end(); B != BE; B++) {
> +    for (llvm::Function::iterator B = F.begin(), BE = F.end(); B != BE;
> + ++B) {
>        for (BasicBlock::iterator instI = B->begin(),
>             instE = B->end(); instI != instE; ++instI) {
> 
> @@ -727,7 +727,7 @@ error:
>      assert(out_buf_sizeof_offset == totalSizeofSize);
> 
>      /* Replace the instruction's operand if using printf's return value. */
> -    for (llvm::Function::iterator B = F.begin(), BE = F.end(); B != BE; B++) {
> +    for (llvm::Function::iterator B = F.begin(), BE = F.end(); B != BE;
> + ++B) {
>        for (BasicBlock::iterator instI = B->begin(),
>             instE = B->end(); instI != instE; ++instI) {
> 
> diff --git a/backend/src/llvm/llvm_to_gen.cpp
> b/backend/src/llvm/llvm_to_gen.cpp
> index 4ea722a..292b665 100644
> --- a/backend/src/llvm/llvm_to_gen.cpp
> +++ b/backend/src/llvm/llvm_to_gen.cpp
> @@ -318,7 +318,7 @@ namespace gbe
>        delete ct;
>        if (OCL_OUTPUT_CFG_GEN_IR)
>          iter->second->outputCFG();
> -      iter++;
> +      ++iter;
>      }
> 
>      delete libraryInfo;
> --
> 2.1.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list