Skip to content
Snippets Groups Projects
Commit d7190d0b authored by Cupertino Miranda's avatar Cupertino Miranda
Browse files

bpf: support more instructions to match CO-RE relocations

BPF supports multiple instructions to be CO-RE relocatable regardless of
the position of the immediate field in the encoding.
In particular, not only the MOV instruction allows a CO-RE
relocation of its immediate operand, but the LD and ST instructions can
have a CO-RE relocation happening to their offset immediate operand,
even though those operands are encoded in different encoding bits.
This patch moves matching from a more traditional matching of the
UNSPEC_CORE_RELOC pattern within a define_insn to a match within the
constraints of both immediates and address operands from more generic
mov define_insn rule.

gcc/Changelog:
	* config/bpf/bpf-protos.h (bpf_add_core_reloc): Renamed function
	to bpf_output_move.
	* config/bpf/bpf.cc (bpf_legitimate_address_p): Allow
	UNSPEC_CORE_RELOC to match an address.
	(bpf_insn_cost): Make UNSPEC_CORE_RELOC immediate moves
	expensive to prioritize loads and stores.
	(TARGET_INSN_COST): Add hook.
	(bpf_output_move): Wrapper to call bpf_output_core_reloc.
	(bpf_print_operand): Add support to print immediate operands
	specified with the UNSPEC_CORE_RELOC.
	(bpf_print_operand_address): Likewise, but to support
	UNSPEC_CORE_RELOC in addresses.
	(bpf_init_builtins): Flag BPF_BUILTIN_CORE_RELOC as NOTHROW.
	* config/bpf/bpf.md: Wrap patterns for MOV, LD and ST
	instruction with bpf_output_move call.
	(mov_reloc_core<MM:mode>): Remove now spurious define_insn.
	* config/bpf/constraints.md: Added "c" and "C" constraints to
	match immediates represented with UNSPEC_CORE_RELOC.
	* config/bpf/core-builtins.cc (bpf_add_core_reloc): Remove
	(bpf_output_core_reloc): Add function to create the CO-RE
	relocations based on new matching rules.
	* config/bpf/core-builtins.h (bpf_output_core_reloc): Add
	prototype.
	* config/bpf/predicates.md (core_imm_operand) Add predicate.
	(mov_src_operand): Add match for core_imm_operand.

gcc/testsuite/ChangeLog:
	* gcc.target/bpf/btfext-funcinfo.c: Updated to changes.
	* gcc.target/bpf/core-builtin-fieldinfo-const-elimination.c:
	Likewise.
	* gcc.target/bpf/core-builtin-fieldinfo-existence-1.c: Likewise.
	* gcc.target/bpf/core-builtin-fieldinfo-lshift-1-be.c: Likewise.
	* gcc.target/bpf/core-builtin-fieldinfo-lshift-1-le.c: Likewise.
	* gcc.target/bpf/core-builtin-fieldinfo-lshift-2.c: Likewise.
	* gcc.target/bpf/core-builtin-fieldinfo-offset-1.c: Likewise.
	* gcc.target/bpf/core-builtin-fieldinfo-rshift-1.c: Likewise.
	* gcc.target/bpf/core-builtin-fieldinfo-rshift-2.c: Likewise.
	* gcc.target/bpf/core-builtin-fieldinfo-sign-1.c: Likewise.
	* gcc.target/bpf/core-builtin-fieldinfo-sign-2.c: Likewise.
	* gcc.target/bpf/core-builtin-fieldinfo-size-1.c: Likewise.
parent 4d4929fe
Loading
Showing
with 189 additions and 91 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment