[Beignet] [PATCH] GBE/IR: add collectInsnNum to collect block instruction number.

Yang, Rong R rong.r.yang at intel.com
Wed Aug 12 20:08:10 PDT 2015


LGTM, thanks.

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> xionghu.luo at intel.com
> Sent: Wednesday, August 5, 2015 13:13
> To: beignet at lists.freedesktop.org
> Cc: Luo, Xionghu
> Subject: [Beignet] [PATCH] GBE/IR: add collectInsnNum to collect block
> instruction number.
> 
> From: Luo Xionghu <xionghu.luo at intel.com>
> 
> if we are in if/endif fix mode, the long if/endif block need be split to short
> ones, but we cannot do this in structuralized blocks, so don't generated long
> if/endif structuralized blocks here.
> the threshold is 1000 by estimate.
> 
> Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
> ---
>  backend/src/ir/structurizer.cpp | 24 +++++++++++++++++++++---
> backend/src/ir/structurizer.hpp |  4 +++-
>  2 files changed, 24 insertions(+), 4 deletions(-)
> 
> diff --git a/backend/src/ir/structurizer.cpp b/backend/src/ir/structurizer.cpp
> index 6c4e455..38d3dd1 100644
> --- a/backend/src/ir/structurizer.cpp
> +++ b/backend/src/ir/structurizer.cpp
> @@ -458,6 +458,17 @@ namespace ir {
>      return p_block;
>    }
> 
> +  void CFGStructurizer::collectInsnNum(Block* block, const BasicBlock*
> + bb)  {
> +    BasicBlock::const_iterator iter = bb->begin();
> +    BasicBlock::const_iterator iter_end = bb->end();
> +    while(iter != iter_end)
> +    {
> +      block->insnNum++;
> +      iter++;
> +    }
> +  }
> +
>    bool CFGStructurizer::checkForBarrier(const BasicBlock* bb)
>    {
>      BasicBlock::const_iterator iter = bb->begin(); @@ -600,6 +611,7 @@
> namespace ir {
>      loops = fn->getLoops();
>      fn->foreachBlock([&](ir::BasicBlock &bb){
>          orderedBlks.push_back(bbmap[&bb]);
> +        collectInsnNum(bbmap[&bb], &bb);
>          });
>    }
> 
> @@ -721,6 +733,7 @@ namespace ir {
>            p->canBeHandled = false;
>            break;
>          }
> +        p->insnNum += (*iter)->insnNum;
>          iter++;
>        }
>        return insertBlock(p);
> @@ -770,6 +783,7 @@ namespace ir {
>      if(loopSets.size() == 1)
>      {
>        Block* p = new SelfLoopBlock(*loopSets.begin());
> +      p->insnNum = (*loopSets.begin())->insnNum;
>        p->canBeHandled = true;
>        (*loopSets.begin())->getExit()->isLoopExit = true;
>        return insertBlock(p);
> @@ -881,7 +895,8 @@ namespace ir {
>      if (TrueBB->succ_size() == 1 && FalseBB->succ_size() == 1
>          && TrueBB->pred_size() == 1 && FalseBB->pred_size() == 1
>          && *TrueBB->succ_begin() == *FalseBB->succ_begin()
> -        && !TrueBB->hasBarrier() && !FalseBB->hasBarrier() ) {
> +        && !TrueBB->hasBarrier() && !FalseBB->hasBarrier()
> +        && TrueBB->insnNum < 1000 && FalseBB->insnNum < 1000) {
>        // if-else pattern
>        ifSets.insert(block);
>        if(block->fallthrough() == TrueBB) { @@ -895,17 +910,19 @@ namespace
> ir {
>        }else{
>          GBE_ASSERT(0);
>        }
> +      mergedBB->insnNum = block->insnNum + TrueBB->insnNum +
> + FalseBB->insnNum;
> 
>        if(block->canBeHandled == false || TrueBB->canBeHandled == false ||
> FalseBB->canBeHandled == false)
>          block->canBeHandled = false;
> 
>        insertBlock(mergedBB);
>      } else if (TrueBB->succ_size() == 1 && TrueBB->pred_size() == 1 &&
> -        *TrueBB->succ_begin() == FalseBB && !TrueBB->hasBarrier() ) {
> +        *TrueBB->succ_begin() == FalseBB && !TrueBB->hasBarrier() &&
> + TrueBB->insnNum < 1000 ) {
>        // if-then pattern, false is empty
>        ifSets.insert(block);
>        ifSets.insert(TrueBB);
>        mergedBB = new IfThenBlock(block, TrueBB);
> +      mergedBB->insnNum = block->insnNum + TrueBB->insnNum;
>        if(block->fallthrough() == FalseBB)
>          block->inversePredicate = false;
> 
> @@ -914,11 +931,12 @@ namespace ir {
> 
>        insertBlock(mergedBB);
>      } else if (FalseBB->succ_size() == 1 && FalseBB->pred_size() == 1 &&
> -        *FalseBB->succ_begin() == TrueBB && !FalseBB->hasBarrier() ) {
> +        *FalseBB->succ_begin() == TrueBB && !FalseBB->hasBarrier() &&
> + FalseBB->insnNum < 1000 ) {
>        // if-then pattern, true is empty
>        ifSets.insert(block);
>        ifSets.insert(FalseBB);
>        mergedBB = new IfThenBlock(block, FalseBB);
> +      mergedBB->insnNum = block->insnNum + FalseBB->insnNum;
>        if(block->fallthrough() == TrueBB)
>          block->inversePredicate = false;
> 
> diff --git a/backend/src/ir/structurizer.hpp b/backend/src/ir/structurizer.hpp
> index 8207644..09b2a7f 100644
> --- a/backend/src/ir/structurizer.hpp
> +++ b/backend/src/ir/structurizer.hpp
> @@ -53,7 +53,7 @@ namespace ir {
>    class Block
>    {
>    public:
> -    Block(BlockType type, const BlockList& children): has_barrier(false),
> mark(false), canBeHandled(true), inversePredicate(true)
> +    Block(BlockType type, const BlockList& children):
> + has_barrier(false), mark(false), canBeHandled(true),
> + inversePredicate(true), insnNum(0)
>      {
>        this->btype = type;
>        this->children = children;
> @@ -105,6 +105,7 @@ namespace ir {
>       * m-->n
>       * */
>      bool inversePredicate;
> +    int insnNum;
>    };
> 
>    /* represents basic block */
> @@ -211,6 +212,7 @@ namespace ir {
>        Block* mergeLoopBlock(BlockList& loopSets);
>        int  ifPatternMatch(Block *block);
>        int  patternMatch(Block *block);
> +      void collectInsnNum(Block* block, const BasicBlock* bb);
> 
>      private:
>        void handleSelfLoopBlock(Block *loopblock, LabelIndex& whileLabel);
> --
> 1.9.1
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list