emit_cmp_insn in alpha
Jim Wilson
wilson@tuliptree.org
Wed May 7 07:16:00 GMT 2003
Hilmi Ozdoganoglu wrote:
> I modified the alpha_expand_epilogue() function in
> config/alpha/alpha.c and added the following:
> 1. How am I supposed to emit a compare instuction in alpha?
emit_cmp_and_jump_insns is a middle-end routine. It is used during
initial RTL generation. You can't use it during optimization passes.
Particularly not in expand_epilogue, which is run near the end of the
optimizer. If you want to emit instructions here, you will have to do
everything by hand.
This runs after register allocation, so you can't use pseudo-regs here.
You must allocate hard registers. Since this is the epilogue, we know
that any call clobbered register is OK to use if it currently doesn't
have a useful value in it. Also, call saved registers are OK to use if
we haven't restored them from the stack yet, and if they have no useful
value in them. Note that the existing code is using regs 22 and 23
directly, because it knows that they are safe.
Any instructions you emit here must be valid for the target. The RTL
emitted here won't be optimized, so if you need something non-trivial,
you should put some effort into emitting optimized RTL.
You are emitting a label into the epilogue. I am not sure if that is
safe. It might confuse the CFG machinery. You might have to update the
CFG after generating your modified epilogues.
In order to get a compare, you will need to directly call the md
patterns that emit compare instructions, e.g. setcc_internal. You will
need to modify the md file to delete the * so that you can actually call
these patterns. Then you do something like
emit_insn (gen_setcc_internal (operands...));
emit_insn (gen_bcc_normal (operands...));
It isn't normal to do this sort of thing. Normally, the epilogue only
emits move instructions. Thus there is no easy way to do it.
It might be easiest to do this code insertion someplace else, e.g. in
the middle end instead of in the optimizer. expand_function_end in
function.c for instance. This makes most of the above issues moot.
emit_cmp_and_jump will work here.
> 2. Once I do that how do I specify which register the result is in so I
> can pass that (an also, how do I do this?) result register to the
> following conditional jump instruction?
If you are using the high level emit_cmp_insn, then it happens
automatically for you. You don't need to worry about it.
If you are using the low level functions like gen_setcc_internal, then
the result register is one of the operands.
> 3. Why doesn't output_asm_insn() ouput the instructions in the right
> place? I tried doing the above using this function but it placed the
> instuctions in the beginning too late in the code.
Not clear what the problem here is. Where are you calling
output_asm_insn from? You shouldn't be calling it at all, final does that.
output_asm_insn emits assembly directly to the output file, which means
it won't likely won't end up in the current function which is in RTL
which hasn't been emitted to the assembly output file yet.
Jim
More information about the Gcc
mailing list