move patterns, emit_move_insn
Georg-Johann Lay
avr@gjlay.de
Mon Mar 2 18:25:00 GMT 2009
Florent DEFAY schrieb:
> Hi,
>
> I am porting GCC on a new arch. I have just been trying to do the
> "prologue" pattern.
>
> I do it this way :
> ______________________________________________
> (define_expand "prologue"
> [(clobber (const_int 0))]
> ""
> {
> function_prologue();
> DONE;
> }
> )
> ______________________________________________
>
> where function_prologue is defined (and not finished) in target.c like this :
> ______________________________________________
> function_prologue()
> {
> emit_move_insn (gen_rtx_REG (HImode, FRAME_POINTER_REGNUM),
> gen_rtx_REG (HImode, STACK_POINTER_REGNUM));
>
> }
> _____________________________________________
>
> And move in HImode is defined by these patterns in the md :
> _____________________________________________
>
> ;; move word expand
> (define_expand "movhi"
> [(set (match_operand:HI 0 "nonimmediate_operand" "=r, m")
> (match_operand:HI 1 "general_operand" "rmi,r")
> )]
> ""
> ""
> )
Note that conatraints are useless here. Remove them because they are
confusing (should give a warning).
>
> ;; move word r -> r
> (define_insn "movhi_r_r"
> [(set (match_operand:HI 0 "register_operand" "=r")
> (match_operand:HI 1 "register_operand" "r")
> )]
> ""
> "movew\t%1,%0"
> )
>
> ;; move word i -> r
> (define_insn "movhi_i_r"
> [(set (match_operand:HI 0 "register_operand" "=r")
> (match_operand:HI 1 "immediate_operand" "i")
> )]
> ""
> "movew\t%1,%0"
> )
>
> ;; move word (r) -> r
> (define_insn "movhi_m1_r"
> [(set (match_operand:HI 0 "general_operand" "=r")
> (mem:HI (match_operand:HI 1 "register_operand" "r"))
> )]
> ""
> "movew\t(%1),%0"
> )
>
> ;; move word r -> (r)
> (define_insn "movhi_r_m1"
> [(set (mem:HI (match_operand:HI 0 "register_operand" "r"))
> (match_operand:HI 1 "general_operand" "r")
> )]
> ""
> "movew\t%1,(%0)"
> )
Try to write it as one insn.
(define_insn "movhi_r_r"
[(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r")
(match_operand:HI 1 "general_operand" "r,m,r,i"))]
""
"@
movew\t%1,%0
..."
)
Note that reload will extract the constraints from the insn(s) it's
going to reload. it's tempting do write insns for each task, but you
will run into problems with that.
Also, (mem (reg)) is a subset of "general_operand". So you actually
allow two kinds of mem-mem moves in r->(r) and (r)->r and reload wont't
be able to reload them.
Also, "general_operand" is too wide for "r" (I hope you did not modify
defaults like "r" or "general_operand")
> _______________________________________
>
> I suppose my patterns for move are not well implemented.
> When I run GCC I have this error :
>
> [guest1]$ target-gcc e.c -S
> e.c: In function ‘nothing’:
> e.c:7: error: insn does not satisfy its constraints:
> (insn 21 3 22 e.c:3 (set (reg/f:HI 5 r5)
> (reg/f:HI 6 r6)) 7 {movhi_r_r} (nil))
>
Check you register class definitions...
> __________________________
> void nothing (void)
> {
> int i = 3;
>
> i = 4 + 2;
> }
> __________________________
>
> The error appeared since I added the "emit_move_insn" in the
> function_prologue. Before that, GCC compiled e.c well.
> I tried to redo patterns and especially constraints and predicates. I
> did not success to avoid the error.
>
> GCC already succeeded in compiling a register to register move with
> source code like
> int i = 3;
> (I mean the pattern movhi_r_r has served successfully).
>
> I would like to know if the error is due to patterns and what is the
> link with emit_move_insn ?
> Looking for any explaination or advice.
... but I would guess that the problems arise from elimination (FP
against SP) which is handled by reload, too. As that involves addition,
your addhi3 must also be implemented correctly.
Georg-Johann
More information about the Gcc-help
mailing list