On 11/17/25 12:36, Xi Ruoyao wrote:
On Mon, 2025-11-17 at 12:34 +0800, WANG Xuerui wrote:
From: WANG Xuerui <[email protected]>

The option was introduced a few days ago to provide more control over
the code generation of __builtin_trap(), but the current form does not
provide room for further extension should other means of trapping become
available on future generations of LoongArch cores.  Moreover, using
out-of-range values to ask for something that's not a "break" is
counter-intuitive, at least for an option named "break"-something.

To improve the command-line UX, rename the option to
-mbuiltin-trap-impl= to better reflect the intent from a user's
perspective, and make it accept a string that resembles real LoongArch
assembly if the user were asked to write the trap snippet themselves.

For now, the accepted forms are "break-CODE" where CODE is an integer
literal between 0 and 32767 inclusive, and "amswap.w".  Both deviate
from usual assembly forms somehow for practical reasons:

1. Spaces are notorious in CLI argument handling, so for something
    expected to be passed around often in an unstructured way (read:
    CFLAGS), it is prudent to use something else.
2. The usage of "amswap.w" here (or any other AM* instruction) is
    exotic, as the LoongArch reference manual does not provide any other
    way to trigger an INE (instruction non-existent) exception for sure.
    In this case, the register operands are intentionally illegal, so
    having them fully spelled out only serves to confuse any reader. In
    addition, the exact register usage is irrelevant to the option's
    purpose.

Since this is now freeform string, any future evolution of the option's
usage is made possible.

gcc/ChangeLog:

        * config/loongarch/genopts/loongarch.opt.in: Rework
          -mbreak-code= into -mbuiltin-trap-impl=.
        * config/loongarch/loongarch-opts.cc
        (loongarch_parse_mbuiltin_trap_impl): New function.
        (loongarch_init_misc_options): Parse the new option.
        * config/loongarch/loongarch.opt: Regenerate.
loongarch.opt.urls needs to be regenerated too.

My bad... Rebuilding and v2 will be sent soon.

Reply via email to