From: Zhigang Gong Date: Fri, 25 Apr 2014 04:36:59 +0000 (+0800) Subject: GBE: fix the hard coded endif offset calculation. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b3c92e63d0afec143b9ddde04d601a7b88b4ad53;p=contrib%2Fbeignet.git GBE: fix the hard coded endif offset calculation. Signed-off-by: Zhigang Gong Reviewed-by: "Yang, Rong R" --- diff --git a/backend/src/backend/gen_context.cpp b/backend/src/backend/gen_context.cpp index 4da47f8..ef18577 100644 --- a/backend/src/backend/gen_context.cpp +++ b/backend/src/backend/gen_context.cpp @@ -111,8 +111,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))); @@ -254,7 +254,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 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> branchPos3; diff --git a/backend/src/backend/gen_insn_selection.cpp b/backend/src/backend/gen_insn_selection.cpp index c05a97b..09e5423 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(); @@ -961,17 +969,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); @@ -3221,8 +3228,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;