Question on implementation detail of `temp_sync`
Quoted 1 line · lrwei
Sorry for the unintentional sending of an uncompleted message.
Questions about the internals of the TCG are very much in the remit of qemu-devel so are likely to get missed on qemu-discuss which is more aimed at user questions.
Quoted 1 line
<re-pasted to fix html noise>
Quoted 2 lines
I understands that the current code works, but gets confused on why
tsneeds to be loaded in to a register whenfree_or_deadis not set.
It isn't, the break leaves the switch statement once it stores the constant to memory.
Quoted 10 lines
For example in the following scenario:
movi_i32r0,0x1add_i32r1, r1, r0
...
(where r0 is not used any more, and both r0 and r1 are globals)If I am not mistaken, the code gen procedure of the first IR will call
temp_syncwithfree_or_deadnot set, which load the constant in to a register and store it back to memory. At this time,r0will beTEMP_VAL_REGinstead ofTEMP_VAL_CONST, so the following IR can't embed this constant operand in the assembly instruction it produces. Also, this results in a seemingly useless register allocation (, why don't the further use of r0 use the constant directly?)
Is this what you are actually seeing generated? If you run with -d in_asm,op,op_opt,out_asm it should be clear what actually happened.
Quoted 2 lines
So I wonder whether there is any reason for this loading a constant into register, I'll be very appreciated if someone can point out the reason for me.
<snip>
Quoted 11 lines
Thanks in advance.
lrwei
------------------ Original ------------------
From: "lrwei"<[email protected]>;
Date: Tue, Aug 4, 2020 12:06 PM
To: "qemu-discuss"<[email protected]>;
Subject: Question on implementation detail oftemp_sync
<re-pasted fixing html noise>
Quoted 28 lines
Hello to the list,
Recently I have been studying the code of TCG, and get confused by the following detail in functiontemp_syncintcg/tcg.c:case TEMP_VAL_CONST: /* If we're going to free the temp immediately, then we won't require it later in a register, so attempt to store the constant to memory directly. */ if (free_or_dead && tcg_out_sti(s, ts->type, ts->val, ts->mem_base->reg, ts->mem_offset)) { break; } temp_load(s, ts, tcg_target_available_regs[ts->type], allocated_regs, preferred_regs); /* fallthrough */
movi_i32Would it be better to remove the
free_or_deadin the if statement, i.e. turn the function to be:case TEMP_VAL_CONST: if (tcg_out_sti(s, ts->type, ts->val, ts->mem_base->reg, ts->mem_offset)) { break; } temp_load(s, ts, tcg_target_available_regs[ts->type], allocated_regs, preferred_regs); /* fallthrough */
Signature · 1 line
Alex Bennée