Am 17.06.24 um 21:13 schrieb Stefan Schulze Frielinghaus via Gcc:
Hi all,

I'm trying to add an alternative to an existing insn foobar:

(define_insn "foobar"
   [(set (match_operand ...)
         (match_operand ...))]
   ""
   "@
    foo
    bar
    #")

Since the asm output depends on the operands in a non-trivial way which isn't
easily solved via iterators, I went for a general C function and came up with:

(define_insn "foobar"
   [(set (match_operand ...)
         (match_operand ...))]
   ""
   "@
    foo
    * return foobar_helper (operands[0], operands[1]);
    bar
    #"
   [(set_attr_alternative "mnemonic" [(const_string "foo")
                                      (const_string "specialcase")
                                      (const_string "bar")
                                      (const_string "unknown")])])

If there exist a lot of alternatives, then setting the mnemonic attribute like
this feels repetitive and is error prone.  Furthermore, if there exists no
other insn with an output template containing foo/bar, then I would have to
declare foo/bar via

(define_attr "mnemonic" "...,foo,bar,..." (const_string "unknown"))

which again is repetitive.  Thus, I'm wondering if there exists a more elegant
way to achieve this?  Ultimately, I would like to set the mnemonic
attribute only manually for the alternative which is implemented via C
code and let the mnemonic attribute for the remaining alternatives be
set automagically.  Not sure whether this is supported?

If all fails, I have another idea how to solve this by utilizing PRINT_OPERAND.
However, now I'm curious whether my current attempt is feasible or not.

Cheers,
Stefan

It's a bit unclear to me what you are trying to do, as you are not only
adding an insn alternative, but also are adding insn attribute
"mnemonic", which the original insn did not have.

Also, it's unclear how PRINT_OPERAND would help with setting the attribute.

Johann

Reply via email to