This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Seeking suggestion


> From: Jamie Prescott <jpresss@yahoo.com>
> To: gcc@gcc.gnu.org
> Sent: Friday, May 22, 2009 10:36:47 AM
> Subject: Seeking suggestion
> 
> 
> Suppose you're writing the backend for a VM supporting two architectures, in 
> which
> one of them clobbers the CC registers for certain instructions, while the other 
> does not.
> The instructions themselves are exactly the same.
> What is the best/shortest/more-elegant way to write this, possibly w/out 
> duplicating the
> instructions?
> I know I can write a define_expand and redirect, based on the TARGET, to two 
> different
> instructions (one with "clobber", the other w/out), but that's basically three 
> declarations
> for each insns. Is there a shorter way?

I ended up doing something like this (long way, but the only one I know of).
Example, for addsi3:

(define_insn "addsi3_xxx2"
  [(set (match_operand:SI 0 "fullreg_operand" "=r,r")
        (plus:SI (match_operand:SI 1 "fullreg_operand" "0,r")
                 (match_operand:SI 2 "fullreg_or_imm_operand" "rn,rn")))]
  ""
  "@
   add\t%0,%2,%0
   add\t%1,%2,%0"
)

(define_insn "addsi3_xxx"
  [(set (match_operand:SI 0 "fullreg_operand" "=r,r")
        (plus:SI (match_operand:SI 1 "fullreg_operand" "0,r")
                 (match_operand:SI 2 "fullreg_or_imm_operand" "rn,rn")))
   (clobber (reg:CC CC_REG))]
  ""
  "@
   add\t%0,%2,%0
   add\t%1,%2,%0"
)

(define_expand "addsi3"
  [(set (match_operand:SI 0 "fullreg_operand" "=r,r")
        (plus:SI (match_operand:SI 1 "fullreg_operand" "0,r")
                 (match_operand:SI 2 "fullreg_or_imm_operand" "rn,rn")))]
  ""
  {
    if (!TARGET_XXX2)
      emit_insn(gen_addsi3_xxx(operands[0], operands[1], operands[2]));
    else
      emit_insn(gen_addsi3_xxx2(operands[0], operands[1], operands[2]));
    DONE;
  }
)


But now I get and invalid rtx sharing from the push/pop parallels:


xxxx.c: In function 'test_dashr':
xxxx.c:32: error: invalid rtl sharing found in the insn
(insn 26 3 28 2 xxxx.c:26 (parallel [
            (insn/f 25 0 0 (set (reg/f:SI 51 SP)
                    (minus:SI (reg/f:SI 51 SP)
                        (const_int 4 [0x4]))) -1 (nil))
            (set/f (mem:SI (reg/f:SI 51 SP) [0 S4 A8])
                (reg:SI 8 r8))
        ]) -1 (nil))
xxxx.c:32: error: shared rtx
(insn/f 25 0 0 (set (reg/f:SI 51 SP)
        (minus:SI (reg/f:SI 51 SP)
            (const_int 4 [0x4]))) -1 (nil))
xxxx.c:32: internal compiler error: internal consistency failure


Any insights?
Thanks,


- Jamie


      


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]