qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] TCG register allocator


From: Xin Tong
Subject: Re: [Qemu-devel] TCG register allocator
Date: Wed, 25 Jan 2012 10:42:30 -0500

I tried to reserve a register in target-i386 with this code

target-i386/translate.c    tb_env = tcg_global_reg_new_ptr(TCG_AREG1, "env");

i386/tcg-target.h         #define TCG_AREG1 TCG_REG_R13

i386/tcg-target.c         tcg_out_movi(s, TCG_TYPE_PTR, TCG_AREG1, args[0]);

But when i looked into the dynamically generated code, the place which
i use TCG_AREG1 becomes RBP and RBP is not reserved either.

Thanks

Xin



On Wed, Jan 25, 2012 at 10:19 AM, Peter Maydell
<address@hidden> wrote:
> On 25 January 2012 14:24, Xin Tong <address@hidden> wrote:
>> I am wondering how tcg reg alloc works. Specifically, how do i reserve
>> a register only for one specific purpose. R14 on tcg i386 is reserved
>> to point to the cpustate strcuture.  it is assigned in the prologue,
>> but what code makes sure that it is not clobbered in the middle of a
>> TB ?
>
> target-i386/translate.c:optimize_flags_init() calls:
>    cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
>
> which tells TCG that this register always has this value in it.
> TCG will then ensure that it doesn't try to use that register
> when it's doing allocation later. This is done by having
> tcg_global_reg_new_internal() call:
>    tcg_regset_set_reg(s->reserved_regs, reg);
>
> We also add a register to the reserved_regs set in tcg/i386/tcg-target.c:
> tcg_target_init():
>     tcg_regset_set_reg(s->reserved_regs, TCG_REG_CALL_STACK);
>
> because attempting to allocate a value into ESP would be a bad idea :-)
>
> -- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]