public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* how to write a define_peephole2 that uses custom registers in nios2
@ 2005-07-26 10:03 Liu Haibin
  2005-07-27 19:14 ` James E Wilson
  0 siblings, 1 reply; 4+ messages in thread
From: Liu Haibin @ 2005-07-26 10:03 UTC (permalink / raw)
  To: gcc

Hi,

nios2 has a set of custom registers for custom instructions. They all
start with "c", like

custom 1 c4, c2, c0

I want to define a peephole to replace a sequence of codes with this
above custom instruction.

custom instruction is defined as following in nios2.md

(define_insn "custom_inii"
  [(set (match_operand:SI 0 "register_operand"   "=r")
        (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
                          (match_operand:SI 2 "register_operand"   "r")
                          (match_operand:SI 3 "register_operand"  
"r")] CUSTOM_INII))]
  ""
  "custom\\t%1, %0, %2, %3"
  [(set_attr "type" "custom")])

But the problem is it uses normal register, like r8, r9. How can I
write the define_peephole2 so that it uses custom registers?


Thanks
Haibin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to write a define_peephole2 that uses custom registers in nios2
  2005-07-26 10:03 how to write a define_peephole2 that uses custom registers in nios2 Liu Haibin
@ 2005-07-27 19:14 ` James E Wilson
  2005-07-28 12:28   ` Liu Haibin
  0 siblings, 1 reply; 4+ messages in thread
From: James E Wilson @ 2005-07-27 19:14 UTC (permalink / raw)
  To: Liu Haibin; +Cc: gcc

Liu Haibin wrote:
>                           (match_operand:SI 2 "register_operand"   "r")
> But the problem is it uses normal register, like r8, r9. How can I
> write the define_peephole2 so that it uses custom registers?

See the "Constraints" section of the documentation.  "r" means a general 
register.  If you want a custom register, then you need to use a 
contraint letter that maps to a custom register.

If the port does not already support custom registers, then you need to 
modify many of the register allocation related macros to add support for 
the custom registers.  See the "Registers" and "Register Classes" 
sections of the documentation.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to write a define_peephole2 that uses custom registers in nios2
  2005-07-27 19:14 ` James E Wilson
@ 2005-07-28 12:28   ` Liu Haibin
  2005-07-28 19:08     ` James E Wilson
  0 siblings, 1 reply; 4+ messages in thread
From: Liu Haibin @ 2005-07-28 12:28 UTC (permalink / raw)
  To: James E Wilson; +Cc: gcc

Thanks. I modified the related macros, like reg_class,
REG_CLASS_FROM_LETTER(CHAR) and so on. But I have a problem on
define_peephole2.

After I modified the related macros, I replaced the "r" in
"custom_inii" with "c".

(define_insn "custom_inii"
  [(set (match_operand:SI 0 "register_operand"   "=c")
        (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
                          (match_operand:SI 2 "register_operand"   "c")
                          (match_operand:SI 3 "register_operand"  
"c")] CUSTOM_INII))]
  ""
  "custom\\t%1, %0, %2, %3"
  [(set_attr "type" "custom")])

And I defined the peephole as 

(define_peephole2
  [(set (match_operand:SI 0 "register_operand"          "")
        (plus:SI (match_operand:SI 1 "register_operand" "")
                 (match_operand:SI 2 "arith_operand"     "")))]
  "REG_P(operands[2])"
  [(set (match_operand:SI 0 "register_operand" "=c")
  	(unspec_volatile:SI [(match_operand:SI 3 "custom_insn_opcode" "N")
			(match_operand:SI 1 "register_operand" "c")
			(match_operand:SI 2 "register_operand" "c")] CUSTOM_INII))]
  "
{
	operands[3] = GEN_INT(100);
}")

I encounter the following error

isqrt.c: In function `usqrt':
isqrt.c:65: error: insn does not satisfy its constraints:
(insn 118 41 36 1 0x1002f390 (set (reg/v:SI 4 r4 [82])
        (unspec_volatile:SI [
                (const_int 100 [0x64])
                (reg:SI 4 r4 [86])
                (reg:SI 3 r3 [88])
            ] 117)) 75 {custom_inii} (nil)
    (expr_list:REG_DEAD (reg:SI 3 r3 [88])
        (nil)))
isqrt.c:65: internal compiler error: in build_def_use, at regrename.c:782
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://www.altera.com/mysupport> for instructions.

I think the reason it failed is there's no more define_insn
"custom_inii" with general registers because I already changed the "r"
to "c". However, it seems very difficult here. The old insn patterns
are all general registers, but the new insn patterns are defined as
custom registers.

Can I use something like

operands[0] = gen_rtx_REG (DImode, REGNO(operands[0]));

here to force all the operands to be a different kind? Or how can I
define the peephole?










On 7/28/05, James E Wilson <wilson@specifix.com> wrote:
> Liu Haibin wrote:
> >                           (match_operand:SI 2 "register_operand"   "r")
> > But the problem is it uses normal register, like r8, r9. How can I
> > write the define_peephole2 so that it uses custom registers?
> 
> See the "Constraints" section of the documentation.  "r" means a general
> register.  If you want a custom register, then you need to use a
> contraint letter that maps to a custom register.
> 
> If the port does not already support custom registers, then you need to
> modify many of the register allocation related macros to add support for
> the custom registers.  See the "Registers" and "Register Classes"
> sections of the documentation.
> --
> Jim Wilson, GNU Tools Support, http://www.specifix.com
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to write a define_peephole2 that uses custom registers in nios2
  2005-07-28 12:28   ` Liu Haibin
@ 2005-07-28 19:08     ` James E Wilson
  0 siblings, 0 replies; 4+ messages in thread
From: James E Wilson @ 2005-07-28 19:08 UTC (permalink / raw)
  To: Liu Haibin; +Cc: gcc

Liu Haibin wrote:
> to "c". However, it seems very difficult here. The old insn patterns
> are all general registers, but the new insn patterns are defined as
> custom registers.

The peephole pass does not do register allocation.  So you can't use it 
to magically change "r" registers to "c" registers.  What you are trying 
to do here won't work.

> Can I use something like
> operands[0] = gen_rtx_REG (DImode, REGNO(operands[0]));
> here to force all the operands to be a different kind? Or how can I
> define the peephole?

If you are willing and able to do your own register allocation, then you 
might be able to get this to work, but this is very unlikely to be a 
good solution.

You probably shouldn't be using peepholes here.  You probably should be 
generating the insns you want during initial RTL generation.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-07-28 19:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-26 10:03 how to write a define_peephole2 that uses custom registers in nios2 Liu Haibin
2005-07-27 19:14 ` James E Wilson
2005-07-28 12:28   ` Liu Haibin
2005-07-28 19:08     ` James E Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).