Re: [PATCH v3] bpf: pseudo-c assembly dialect support
>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi >> index 3063e71c8906..b3be65d3efae 100644 >> --- a/gcc/doc/invoke.texi >> +++ b/gcc/doc/invoke.texi >> @@ -946,8 +946,8 @@ Objective-C and Objective-C++ Dialects}. >> >> @emph{eBPF Options} >> @gccoptlist{-mbig-endian -mlittle-endian -mkernel=@var{version} >> --mframe-limit=@var{bytes} -mxbpf -mco-re -mno-co-re >> --mjmpext -mjmp32 -malu32 -mcpu=@var{version}} >> +-mframe-limit=@var{bytes} -mxbpf -mco-re -mno-co-re -mjmpext >> +-mjmp32 -malu32 -mcpu=@var{version} -masm=@var{dialect>}} > > There is a spurious > character there. > > Other than that, the patch is OK. > Thanks! Fixed the extra character and committed. Thanks !
Re: [PATCH v3] bpf: pseudo-c assembly dialect support
> Thanks for the suggestions/fixes in changelog. > Inlined new patch. > > Cupertino > >>> gcc/ChangeLog: >>> >>> * config/bpf/bpf.opt: Added option -masm=. >>> * config/bpf/bpf-opts.h: Likewize. >>> * config/bpf/bpf.cc: Changed it to conform with new pseudoc >>> dialect support. >>> * config/bpf/bpf.h: Likewise. >>> * config/bpf/bpf.md: Added pseudo-c templates. >>> * doc/invoke.texi: (-masm=DIALECT) New eBPF option item. >> >> I think the ChangeLog could be made more useful, and the syntax of the >> last entry is not entirely right. I suggest something like: >> >> * config/bpf/bpf.opt: Added option -masm=. >> * config/bpf/bpf-opts.h (enum bpf_asm_dialect): New type. >> * config/bpf/bpf.cc (bpf_print_register): New function. >> (bpf_print_register): Support pseudo-c syntax for registers. >> (bpf_print_operand_address): Likewise. >> * config/bpf/bpf.h (ASM_SPEC): handle -msasm. >> (ASSEMBLER_DIALECT): Define. >> * config/bpf/bpf.md: Added pseudo-c templates. >> * doc/invoke.texi (-masm=DIALECT): New eBPF option item. >> >> Please make sure to run the contrib/gcc-changelog/git_check-commit.py >> script. >> > > From 6ebe3229a59b32ffb2ed24b3a2cf8c360a807c31 Mon Sep 17 00:00:00 2001 > From: Cupertino Miranda > Date: Mon, 17 Jul 2023 17:42:42 +0100 > Subject: [PATCH v3] bpf: pseudo-c assembly dialect support > > New pseudo-c BPF assembly dialect already supported by clang and widely > used in the linux kernel. > > gcc/ChangeLog: > > * config/bpf/bpf.opt: Added option -masm=. > * config/bpf/bpf-opts.h (enum bpf_asm_dialect): New type. > * config/bpf/bpf.cc (bpf_print_register): New function. > (bpf_print_register): Support pseudo-c syntax for registers. > (bpf_print_operand_address): Likewise. > * config/bpf/bpf.h (ASM_SPEC): handle -msasm. > (ASSEMBLER_DIALECT): Define. > * config/bpf/bpf.md: Added pseudo-c templates. > * doc/invoke.texi (-masm=): New eBPF option item. > --- > gcc/config/bpf/bpf-opts.h | 6 +++ > gcc/config/bpf/bpf.cc | 46 --- > gcc/config/bpf/bpf.h | 5 +- > gcc/config/bpf/bpf.md | 97 --- > gcc/config/bpf/bpf.opt| 14 ++ > gcc/doc/invoke.texi | 21 - > 6 files changed, 133 insertions(+), 56 deletions(-) > > diff --git a/gcc/config/bpf/bpf-opts.h b/gcc/config/bpf/bpf-opts.h > index 8282351cf045..92db01ec4d54 100644 > --- a/gcc/config/bpf/bpf-opts.h > +++ b/gcc/config/bpf/bpf-opts.h > @@ -60,4 +60,10 @@ enum bpf_isa_version >ISA_V3, > }; > > +enum bpf_asm_dialect > +{ > + ASM_NORMAL, > + ASM_PSEUDOC > +}; > + > #endif /* ! BPF_OPTS_H */ > diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc > index e0324e1e0e08..1d3936871d60 100644 > --- a/gcc/config/bpf/bpf.cc > +++ b/gcc/config/bpf/bpf.cc > @@ -873,16 +873,47 @@ bpf_output_call (rtx target) >return ""; > } > > +/* Print register name according to assembly dialect. > + In normal syntax registers are printed like %rN where N is the > + register number. > + In pseudoc syntax, the register names do not feature a '%' prefix. > + Additionally, the code 'w' denotes that the register should be printed > + as wN instead of rN, where N is the register number, but only when the > + value stored in the operand OP is 32-bit wide. */ > +static void > +bpf_print_register (FILE *file, rtx op, int code) > +{ > + if(asm_dialect == ASM_NORMAL) > +fprintf (file, "%s", reg_names[REGNO (op)]); > + else > +{ > + if (code == 'w' && GET_MODE (op) == SImode) > + { > + if (REGNO (op) == BPF_FP) > + fprintf (file, "w10"); > + else > + fprintf (file, "w%s", reg_names[REGNO (op)]+2); > + } > + else > + { > + if (REGNO (op) == BPF_FP) > + fprintf (file, "r10"); > + else > + fprintf (file, "%s", reg_names[REGNO (op)]+1); > + } > +} > +} > + > /* Print an instruction operand. This function is called in the macro > PRINT_OPERAND defined in bpf.h */ > > void > -bpf_print_operand (FILE *file, rtx op, int code ATTRIBUTE_UNUSED) > +bpf_print_operand (FILE *file, rtx op, int code) > { >switch (GET_CODE (op)) > { > case REG: > - fprintf (file, "%s", reg_names[REGNO (op)]); > + bpf_print_register (file, op, code); >break; > cas
Re: [PATCH v3] bpf: pseudo-c assembly dialect support
Thanks for the suggestions/fixes in changelog. Inlined new patch. Cupertino >> gcc/ChangeLog: >> >> * config/bpf/bpf.opt: Added option -masm=. >> * config/bpf/bpf-opts.h: Likewize. >> * config/bpf/bpf.cc: Changed it to conform with new pseudoc >>dialect support. >> * config/bpf/bpf.h: Likewise. >> * config/bpf/bpf.md: Added pseudo-c templates. >> * doc/invoke.texi: (-masm=DIALECT) New eBPF option item. > > I think the ChangeLog could be made more useful, and the syntax of the > last entry is not entirely right. I suggest something like: > > * config/bpf/bpf.opt: Added option -masm=. > * config/bpf/bpf-opts.h (enum bpf_asm_dialect): New type. > * config/bpf/bpf.cc (bpf_print_register): New function. > (bpf_print_register): Support pseudo-c syntax for registers. > (bpf_print_operand_address): Likewise. > * config/bpf/bpf.h (ASM_SPEC): handle -msasm. > (ASSEMBLER_DIALECT): Define. > * config/bpf/bpf.md: Added pseudo-c templates. > * doc/invoke.texi (-masm=DIALECT): New eBPF option item. > > Please make sure to run the contrib/gcc-changelog/git_check-commit.py > script. > >From 6ebe3229a59b32ffb2ed24b3a2cf8c360a807c31 Mon Sep 17 00:00:00 2001 From: Cupertino Miranda Date: Mon, 17 Jul 2023 17:42:42 +0100 Subject: [PATCH v3] bpf: pseudo-c assembly dialect support New pseudo-c BPF assembly dialect already supported by clang and widely used in the linux kernel. gcc/ChangeLog: * config/bpf/bpf.opt: Added option -masm=. * config/bpf/bpf-opts.h (enum bpf_asm_dialect): New type. * config/bpf/bpf.cc (bpf_print_register): New function. (bpf_print_register): Support pseudo-c syntax for registers. (bpf_print_operand_address): Likewise. * config/bpf/bpf.h (ASM_SPEC): handle -msasm. (ASSEMBLER_DIALECT): Define. * config/bpf/bpf.md: Added pseudo-c templates. * doc/invoke.texi (-masm=): New eBPF option item. --- gcc/config/bpf/bpf-opts.h | 6 +++ gcc/config/bpf/bpf.cc | 46 --- gcc/config/bpf/bpf.h | 5 +- gcc/config/bpf/bpf.md | 97 --- gcc/config/bpf/bpf.opt| 14 ++ gcc/doc/invoke.texi | 21 - 6 files changed, 133 insertions(+), 56 deletions(-) diff --git a/gcc/config/bpf/bpf-opts.h b/gcc/config/bpf/bpf-opts.h index 8282351cf045..92db01ec4d54 100644 --- a/gcc/config/bpf/bpf-opts.h +++ b/gcc/config/bpf/bpf-opts.h @@ -60,4 +60,10 @@ enum bpf_isa_version ISA_V3, }; +enum bpf_asm_dialect +{ + ASM_NORMAL, + ASM_PSEUDOC +}; + #endif /* ! BPF_OPTS_H */ diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index e0324e1e0e08..1d3936871d60 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -873,16 +873,47 @@ bpf_output_call (rtx target) return ""; } +/* Print register name according to assembly dialect. + In normal syntax registers are printed like %rN where N is the + register number. + In pseudoc syntax, the register names do not feature a '%' prefix. + Additionally, the code 'w' denotes that the register should be printed + as wN instead of rN, where N is the register number, but only when the + value stored in the operand OP is 32-bit wide. */ +static void +bpf_print_register (FILE *file, rtx op, int code) +{ + if(asm_dialect == ASM_NORMAL) +fprintf (file, "%s", reg_names[REGNO (op)]); + else +{ + if (code == 'w' && GET_MODE (op) == SImode) + { + if (REGNO (op) == BPF_FP) + fprintf (file, "w10"); + else + fprintf (file, "w%s", reg_names[REGNO (op)]+2); + } + else + { + if (REGNO (op) == BPF_FP) + fprintf (file, "r10"); + else + fprintf (file, "%s", reg_names[REGNO (op)]+1); + } +} +} + /* Print an instruction operand. This function is called in the macro PRINT_OPERAND defined in bpf.h */ void -bpf_print_operand (FILE *file, rtx op, int code ATTRIBUTE_UNUSED) +bpf_print_operand (FILE *file, rtx op, int code) { switch (GET_CODE (op)) { case REG: - fprintf (file, "%s", reg_names[REGNO (op)]); + bpf_print_register (file, op, code); break; case MEM: output_address (GET_MODE (op), XEXP (op, 0)); @@ -936,7 +967,9 @@ bpf_print_operand_address (FILE *file, rtx addr) switch (GET_CODE (addr)) { case REG: - fprintf (file, "[%s+0]", reg_names[REGNO (addr)]); + fprintf (file, asm_dialect == ASM_NORMAL ? "[" : "("); + bpf_print_register (file, addr, 0); + fprintf (file, asm_dialect == ASM_NORMAL ? "+0]" : "+0)"); break; case PLUS: { @@ -945,9 +978,11 @@ bpf_print_operand_address (FILE *file, rtx addr) if (GET_CODE (op0) == REG && GET_CODE (op1) == CONST_INT) { - fprintf (file, "[%s+&q