|Modeling the condition code register in register allocation firstname.lastname@example.org (=?ISO-8859-1?Q?Roland_Lei=DFa?=) (2009-01-09)|
|Re: Modeling the condition code register in register allocation email@example.com (nightmie) (2009-01-11)|
|Re: Modeling the condition code register in register allocation firstname.lastname@example.org (Chris Dodd) (2009-01-11)|
|Re: Modeling the condition code register in register allocation email@example.com (Bartc) (2009-01-13)|
|Re: Modeling the condition code register in register allocation firstname.lastname@example.org (=?ISO-8859-1?Q?Roland_Lei=DFa?=) (2009-01-13)|
|Date:||Tue, 13 Jan 2009 12:28:21 GMT|
|Posted-Date:||13 Jan 2009 07:32:48 EST|
"Roland Lei_a" <email@example.com> wrote in message
> Hello everyone,
> I am currently writing a small compiler as a hobby project. My
> register allocator is basicly working but I have no idea how I could
> model the condition code register (rflags) properly. AMD64 is my
> current backend. My intermediate representation (SSA based) handles
> comparisons and conditional jumps like this at the moment:
> a = b + c
> d = a > 10
> IF d GOTO label1 ELSE GOTO label2
Not quite sure what this represents; perhaps your original source is
if a>10 then ... else ...
And your intermediate representation is as above?
I don't know if my suggestion is going to be that useful, but when I did
this, I made an expression such as this:
/when used in the context of a conditional expression/, yield a new type
that I called 'Cond' rather than an integer or bool. Such a Cond value was
implicity stored in a special machine register, and had a condition code
attached to it (one of the 16 x86 codes). A ">" operator would have the
condition code G or A (depending on signed/unsigned).
In my compiler, when I processed an expression, there was usually some
operation to be applied to the result. In the case of a conditional
expression such as inside If...Then, this was JumpTrue or JumpFalse, which
tested whether the prior condition code was true or not. So the result of
if a > 10 then
Cmp R,10 ;or Cmp (a),10
JumpF G,L1 ;becomes jle L1 in x86
(My method didn't work too well on 'If a Then'; I needed to apply a
conversion from 'a' (an int) to type Cond, which might result in Cmp (a),0).
> Some ideas or related papers?
Oh, you want to do it properly? :-)
Return to the
Search the comp.compilers archives again.