[Beignet] [PATCH] GBE: Handle empty basicblock in Instruction selection

Zhigang Gong zhigang.gong at linux.intel.com
Fri Jun 20 02:51:56 PDT 2014


Good catch, the patch LGTM. Maybe we should remove the whole block
in the future.

On Fri, Jun 20, 2014 at 04:13:13PM +0800, Ruiling Song wrote:
> I meet a corner case which leads to empty bb.
> 
> Lable $12
> add %3, %2, 1
> 
> and what's more %3 is not used anymore later, so we will not select
> instruction for this line of code. Then only Label instruction left
> in the bb, which leads to wrong endifLabel used. The fix simply
> generate endif instruction if needed at first in matchBasicBlock().
> 
> Signed-off-by: Ruiling Song <ruiling.song at intel.com>
> ---
>  backend/src/backend/gen_insn_selection.cpp |   19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/backend/src/backend/gen_insn_selection.cpp b/backend/src/backend/gen_insn_selection.cpp
> index ecb64cd..77d3177 100644
> --- a/backend/src/backend/gen_insn_selection.cpp
> +++ b/backend/src/backend/gen_insn_selection.cpp
> @@ -402,7 +402,7 @@ namespace gbe
>      /*! Build a DAG for the basic block (return number of instructions) */
>      uint32_t buildBasicBlockDAG(const ir::BasicBlock &bb);
>      /*! Perform the selection on the basic block */
> -    void matchBasicBlock(uint32_t insnNum);
> +    void matchBasicBlock(const ir::BasicBlock &bb, uint32_t insnNum);
>      /*! A root instruction needs to be generated */
>      bool isRoot(const ir::Instruction &insn) const;
>  
> @@ -1530,10 +1530,16 @@ namespace gbe
>      return insnNum;
>    }
>  
> -  void Selection::Opaque::matchBasicBlock(uint32_t insnNum)
> +  void Selection::Opaque::matchBasicBlock(const ir::BasicBlock &bb, uint32_t insnNum)
>    {
>      // Bottom up code generation
>      bool needEndif = this->block->hasBranch == false && !this->block->hasBarrier;
> +
> +    if(needEndif) {
> +      const ir::BasicBlock *next = bb.getNextBlock();
> +      this->ENDIF(GenRegister::immd(0), next->getLabelIndex());
> +    }
> +
>      for (int32_t insnID = insnNum-1; insnID >= 0; --insnID) {
>        // Process all possible patterns for this instruction
>        SelectionDAG &dag = *insnDAG[insnID];
> @@ -1570,13 +1576,6 @@ namespace gbe
>            this->block->isLargeBlock = true;
>          }
>  
> -        if (needEndif) {
> -          const ir::BasicBlock *curr = insn.getParent();
> -          const ir::BasicBlock *next = curr->getNextBlock();
> -          this->ENDIF(GenRegister::immd(0), next->getLabelIndex());
> -          needEndif = false;
> -        }
> -
>          // Output the code in the current basic block
>          this->endBackwardGeneration();
>        }
> @@ -1593,7 +1592,7 @@ namespace gbe
>        this->dagPool.rewind();
>        this->appendBlock(bb);
>        const uint32_t insnNum = this->buildBasicBlockDAG(bb);
> -      this->matchBasicBlock(insnNum);
> +      this->matchBasicBlock(bb, insnNum);
>      });
>     }
>  
> -- 
> 1.7.10.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list