[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Pnet-developers] jit coder problem
From: |
Rhys Weatherley |
Subject: |
Re: [Pnet-developers] jit coder problem |
Date: |
Fri, 17 Feb 2006 07:10:47 +1000 |
User-agent: |
KMail/1.4.3 |
On Friday 17 February 2006 05:06 am, address@hidden wrote:
> Should we fix this by examining the instruction at the branch target and
> see if it's a ret instruction and do the ret instead of the branch then ?
>
> That's just my first idea how we could handle this issue.
Putting a value on the stack and then jumping is pretty common (conditional
expressions like A ? B : C also use this pattern). The way to handle it is
to copy the value to a common jit_value_t on each branch and then reload at
the destination from that common jit_value_t.
Whenever you reach a branch and there are values on the stack, then look at
the destination label to see if there are common value names for the stack
positions. If not, then create new temporaries for each stack position, copy
the current contents into them, and store them with the label. If there are
common values names on the label already, then copy into those existing
names. When you reach the label, the first thing you do is repopulate the
stack with the saved common values.
It sounds verbose, but the optimiser will remove most of the redundant copies,
assign global registers for the common jit_value_t's, and it will all come
out in the wash.
In the case of "ret", you could optimise this case by looking ahead and then
doing the return at the source. But this is an optimisation. You still need
to handle the general case.
Cheers,
Rhys.