[Beignet] [PATCH 2/5] GBE: refine longjmp checking.
Zhigang Gong
zhigang.gong at linux.intel.com
Thu Sep 24 17:05:58 PDT 2015
On Thu, Sep 24, 2015 at 07:05:38AM +0000, Yang, Rong R wrote:
> One comment.
>
> > -----Original Message-----
> > From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> > Zhigang Gong
> > Sent: Monday, September 14, 2015 14:20
> > To: beignet at lists.freedesktop.org
> > Cc: Gong, Zhigang
> > Subject: [Beignet] [PATCH 2/5] GBE: refine longjmp checking.
> >
> > Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
> > ---
> > backend/src/backend/gen_insn_selection.cpp | 2 +-
> > backend/src/ir/function.hpp | 17 +++++++++++++++++
> > 2 files changed, 18 insertions(+), 1 deletion(-)
> >
> > diff --git a/backend/src/backend/gen_insn_selection.cpp
> > b/backend/src/backend/gen_insn_selection.cpp
> > index ab00269..57dbec9 100644
> > --- a/backend/src/backend/gen_insn_selection.cpp
> > +++ b/backend/src/backend/gen_insn_selection.cpp
> > @@ -1154,7 +1154,7 @@ namespace gbe
> > SelectionInstruction *insn = this->appendInsn(SEL_OP_JMPI, 0, 1);
> > insn->src(0) = src;
> > insn->index = index.value();
> > - insn->extra.longjmp = abs(index - origin) > 800;
> > + insn->extra.longjmp = ctx.getFunction().getDistance(origin, index)
> > + > 8000;
> > return insn->extra.longjmp ? 2 : 1;
> > }
> >
> > diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp index
> > b5f4ba2..b924332 100644
> > --- a/backend/src/ir/function.hpp
> > +++ b/backend/src/ir/function.hpp
> > @@ -487,6 +487,23 @@ namespace ir {
> > Register getSurfaceBaseReg(uint8_t bti) const;
> > void appendSurface(uint8_t bti, Register reg);
> > /*! Output the control flow graph to .dot file */
> > + /*! Get instruction distance between two BBs */
> > + INLINE uint32_t getDistance(LabelIndex b0, LabelIndex b1) const {
> > + int start, end;
> > + if (b0.value() < b1.value()) {
> > + start = b0.value();
> > + end = b1.value() - 1;
> > + } else {
> > + start = b1.value();
> > + end = b0.value() - 1;
> > + }
> > + uint32_t insnNum = 0;
> > + for(int i = start; i <= end; i++) {
> > + BasicBlock &bb = getBlock(LabelIndex(i));
> > + insnNum += bb.size();
> > + }
> If front jump, need not include the start and end block's size.
Nice catch, there are more cases than I thought:
Two forward jump cases:
JMPI created by label instruction:
b0:
( 85) cmp.le(16) null:UW g1<8,8,1>:UW 0x1UW { align1 WE_all 1H switch };
( 87) (-f0.any16h) jmpi(1) offset_to_b1 { align1 WE_all };
( 89) (+f0) if(16) 45 { align1 WE_normal 1H };
...
b1:
...
JMPI created by forward JMPI.
b0:
...
jmpi(1) offset_to_b1 { align1 WE_all };
b1:
...
One backward JMPI only has one case:
b1:
b0:
...
( 11172) endif(16) 2 null { align1 WE_normal 1H };
( 11174) (+f0.any16h) jmpi(1) offset_to_b0 { align1 WE_all };
It jumps from b0's end to b1's beginning. So we need to accumulate b1 to b0's instructions.
I did make another mistake in the backward jump case, should not exclude b0.
I will send a new version latter.
BTW, using this solution to determine a long jump is still a hacky work around.
I hope some one could refine the backend to support insert one instruction easily
in code emission stage.
Thanks,
Zhigang Gong.
>
> > + return insnNum;
> > + }
> > void outputCFG();
> > private:
> > friend class Context; //!< Can freely modify a function
> > --
> > 1.9.1
> >
> > _______________________________________________
> > Beignet mailing list
> > Beignet at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/beignet
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list