[Beignet] [PATCH 1/3] GBE: fix the hard coded endif offset calculation.

Zhigang Gong zhigang.gong at intel.com
Sun Apr 27 18:00:42 PDT 2014


Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
 backend/src/backend/gen_context.cpp        |  6 +++---
 backend/src/backend/gen_context.hpp        |  7 ++-----
 backend/src/backend/gen_insn_selection.cpp | 22 ++++++++++++++--------
 backend/src/backend/gen_insn_selection.hpp |  5 +----
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/backend/src/backend/gen_context.cpp b/backend/src/backend/gen_context.cpp
index b107552..349349d 100644
--- a/backend/src/backend/gen_context.cpp
+++ b/backend/src/backend/gen_context.cpp
@@ -110,8 +110,8 @@ namespace gbe
       const int32_t insnID = pair.second;
       // FIXME the 'labelPair' implementation must be fixed, as it is hard to
       // convert InstructionSelection offset to ASM offset since asm maybe compacted
-      const int32_t jip = labelPos.find(labelPair.l0)->second + labelPair.offset0*2;
-      const int32_t uip = labelPos.find(labelPair.l1)->second + labelPair.offset1*2;
+      const int32_t jip = labelPos.find(labelPair.l0)->second;
+      const int32_t uip = labelPos.find(labelPair.l1)->second;
       assert((jip - insnID) < 32767 && (jip - insnID) > -32768);
       assert((uip - insnID) < 32767 && (uip - insnID) > -32768);
       p->patchJMPI(insnID, (((uip - insnID)) << 16) | ((jip - insnID)));
@@ -253,7 +253,7 @@ namespace gbe
       case SEL_OP_IF:
         {
           const ir::LabelIndex label0(insn.index), label1(insn.index1);
-          const LabelPair labelPair(label0, label1, insn.offset0, insn.offset1);
+          const LabelPair labelPair(label0, label1);
           const GenRegister src = ra->genReg(insn.src(0));
           this->branchPos3.push_back(std::make_pair(labelPair, p->store.size()));
           p->IF(src);
diff --git a/backend/src/backend/gen_context.hpp b/backend/src/backend/gen_context.hpp
index 14ea719..dfddd28 100644
--- a/backend/src/backend/gen_context.hpp
+++ b/backend/src/backend/gen_context.hpp
@@ -155,13 +155,10 @@ namespace gbe
     /*! Store the position of each label instruction in the Gen ISA stream */
     map<ir::LabelIndex, uint32_t> labelPos;
     typedef struct LabelPair {
-      LabelPair(ir::LabelIndex l0, ir::LabelIndex l1,
-                int16_t offset0 = 0, int16_t offset1 = 0) :
-                l0(l0), l1(l1), offset0(offset0), offset1(offset1) {};
+      LabelPair(ir::LabelIndex l0, ir::LabelIndex l1) :
+                l0(l0), l1(l1){};
       ir::LabelIndex l0;
       ir::LabelIndex l1;
-      int16_t offset0;
-      int16_t offset1;
     } LabelPair;
     /*! Store the Gen instructions to patch */
     vector<std::pair<LabelPair, uint32_t>> branchPos3;
diff --git a/backend/src/backend/gen_insn_selection.cpp b/backend/src/backend/gen_insn_selection.cpp
index 32086d3..420737c 100644
--- a/backend/src/backend/gen_insn_selection.cpp
+++ b/backend/src/backend/gen_insn_selection.cpp
@@ -505,7 +505,7 @@ namespace gbe
     /*! Jump indexed instruction, return the encoded instruction count according to jump distance. */
     int JMPI(Reg src, ir::LabelIndex target, ir::LabelIndex origin);
     /*! IF indexed instruction */
-    void IF(Reg src, ir::LabelIndex jip, ir::LabelIndex uip, int16_t offset0, int16_t offset1);
+    void IF(Reg src, ir::LabelIndex jip, ir::LabelIndex uip);
     /*! ENDIF indexed instruction */
     void ENDIF(Reg src, ir::LabelIndex jip);
     /*! BRD indexed instruction */
@@ -574,6 +574,14 @@ namespace gbe
     GBE_CLASS(Opaque);
     friend class SelectionBlock;
     friend class SelectionInstruction;
+  private:
+    /*! Auxiliary label for if/endif. */ 
+    uint16_t currAuxLabel;
+    INLINE ir::LabelIndex newAuxLabel()
+    {
+      currAuxLabel++;
+      return (ir::LabelIndex)currAuxLabel;
+    }
   };
 
   ///////////////////////////////////////////////////////////////////////////
@@ -607,7 +615,7 @@ namespace gbe
     ctx(ctx), block(NULL),
     curr(ctx.getSimdWidth()), file(ctx.getFunction().getRegisterFile()),
     maxInsnNum(ctx.getFunction().getLargestBlockSize()), dagPool(maxInsnNum),
-    stateNum(0), vectorNum(0), bwdCodeGeneration(false)
+    stateNum(0), vectorNum(0), bwdCodeGeneration(false), currAuxLabel(ctx.getFunction().labelNum())
   {
     const ir::Function &fn = ctx.getFunction();
     this->regNum = fn.regNum();
@@ -955,17 +963,16 @@ namespace gbe
     insn->index1 = uint16_t(uip);
   }
 
-  void Selection::Opaque::IF(Reg src, ir::LabelIndex jip, ir::LabelIndex uip,
-                             int16_t offset0, int16_t offset1) {
+  void Selection::Opaque::IF(Reg src, ir::LabelIndex jip, ir::LabelIndex uip) {
     SelectionInstruction *insn = this->appendInsn(SEL_OP_IF, 0, 1);
     insn->src(0) = src;
     insn->index = uint16_t(jip);
     insn->index1 = uint16_t(uip);
-    insn->offset0 = offset0;
-    insn->offset1 = offset1;
   }
 
   void Selection::Opaque::ENDIF(Reg src, ir::LabelIndex jip) {
+    this->block->endifLabel = this->newAuxLabel();
+    this->LABEL(this->block->endifLabel);
     SelectionInstruction *insn = this->appendInsn(SEL_OP_ENDIF, 0, 1);
     insn->src(0) = src;
     insn->index = uint16_t(jip);
@@ -3215,8 +3222,7 @@ namespace gbe
         }
         sel.push();
           sel.curr.predicate = GEN_PREDICATE_NORMAL;
-          // It's easier to set the jip to a relative position over next block.
-          sel.IF(GenRegister::immd(0), nextLabel, nextLabel, sel.block->endifOffset, sel.block->endifOffset);
+          sel.IF(GenRegister::immd(0), sel.block->endifLabel, sel.block->endifLabel);
         sel.pop();
       }
 
diff --git a/backend/src/backend/gen_insn_selection.hpp b/backend/src/backend/gen_insn_selection.hpp
index ad8c4ec..018114d 100644
--- a/backend/src/backend/gen_insn_selection.hpp
+++ b/backend/src/backend/gen_insn_selection.hpp
@@ -138,10 +138,6 @@ namespace gbe
     uint16_t index;
     /*! For BRC/IF to store the UIP */
     uint16_t index1;
-    /*! For IF instruction to adjust the corresponding ENDIF's position. */
-    /*! as endif is not at the begining of any BBs.*/
-    uint16_t offset0;
-    uint16_t offset1;
     /*! instruction ID used for vector allocation. */
     uint32_t ID;
     /*! Variable sized. Destinations and sources go here */
@@ -194,6 +190,7 @@ namespace gbe
     void append(SelectionInstruction *insn);
     /*! Append a new selection instruction at the beginning of the block */
     void prepend(SelectionInstruction *insn);
+    ir::LabelIndex endifLabel;
     int endifOffset;
     bool hasBarrier;
     bool hasBranch;
-- 
1.8.3.2



More information about the Beignet mailing list