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)));
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);
/*! 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;
/*! 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 */
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;
+ }
};
///////////////////////////////////////////////////////////////////////////
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();
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);
}
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();
}