Re: [PATCH v5] bpf: Improvements in CO-RE builtins implementation.

2023-10-31 Thread Cupertino Miranda



> On 10/31/23 09:58, David Faust wrote:
>> Hi Cupertino,
>>
>> On 10/30/23 12:39, Cupertino Miranda wrote:
>>>
>>> Hi everyone,
>>>
>>> Please find a new version for the review as inline attachment.
>>>
>>> Best regards,
>>> Cupertino
>>>
>>
>> This version LGTM.
>> Thanks!
>
> OK for trunk.
Pushed !

> Thanks.
Thanks,
Cupertino

>
>>
>>>
>>> Changes from v4:
>>>  - Implemented TARGET_DELEGITIMIZE_ADDRESS target hook as the proper
>>>  solution to the the warning for UNSPEC_CORE_RELOC being
>>>  non-delegitimize.
>>>
>>
>>


Re: [PATCH v5] bpf: Improvements in CO-RE builtins implementation.

2023-10-31 Thread David Faust



On 10/31/23 09:58, David Faust wrote:
> Hi Cupertino,
> 
> On 10/30/23 12:39, Cupertino Miranda wrote:
>>
>> Hi everyone,
>>
>> Please find a new version for the review as inline attachment.
>>
>> Best regards,
>> Cupertino
>>
> 
> This version LGTM.
> Thanks!

OK for trunk.
Thanks.

> 
>>
>> Changes from v4:
>>  - Implemented TARGET_DELEGITIMIZE_ADDRESS target hook as the proper
>>  solution to the the warning for UNSPEC_CORE_RELOC being
>>  non-delegitimize.
>>
> 
> 


Re: [PATCH v5] bpf: Improvements in CO-RE builtins implementation.

2023-10-31 Thread David Faust
Hi Cupertino,

On 10/30/23 12:39, Cupertino Miranda wrote:
> 
> Hi everyone,
> 
> Please find a new version for the review as inline attachment.
> 
> Best regards,
> Cupertino
> 

This version LGTM.
Thanks!

> 
> Changes from v4:
>  - Implemented TARGET_DELEGITIMIZE_ADDRESS target hook as the proper
>  solution to the the warning for UNSPEC_CORE_RELOC being
>  non-delegitimize.
> 




[PATCH v5] bpf: Improvements in CO-RE builtins implementation.

2023-10-30 Thread Cupertino Miranda

Hi everyone,

Please find a new version for the review as inline attachment.

Best regards,
Cupertino


Changes from v4:
 - Implemented TARGET_DELEGITIMIZE_ADDRESS target hook as the proper
 solution to the the warning for UNSPEC_CORE_RELOC being
 non-delegitimize.

commit 5b45d225c473827b5ef7001e5b24df74d27953ff
Author: Cupertino Miranda 
Date:   Tue Aug 8 09:22:41 2023 +0100

bpf: Improvements in CO-RE builtins implementation.

This patch moved the processing of attribute preserve_access_index to
its own independent pass in a gimple lowering pass.
This approach is more consistent with the implementation of the CO-RE
builtins when used explicitly in the code.  The attributed type accesses
are now early converted to __builtin_core_reloc builtin instead of being
kept as an expression in code through out all of the middle-end.
This disables the compiler to optimize out or manipulate the expression
using the local defined type, instead of assuming nothing is known about
this expression, as it should be the case in all of the CO-RE
relocations.

In the process, also the __builtin_preserve_access_index has been
improved to generate code for more complex expressions that would
require more then one CO-RE relocation.
This turned out to be a requirement, since bpf-next selftests would rely on
loop unrolling in order to convert an undefined index array access into a
defined one. This seemed extreme to expect for the unroll to happen, and for
that reason GCC still generates correct code in such scenarios, even when index
access is never predictable or unrolling does not occur.

gcc/ChangeLog:
* config/bpf/bpf-passes.def (pass_lower_bpf_core): Added pass.
* config/bpf/bpf-protos.h: Added prototype for new pass.
* config/bpf/bpf.cc (bpf_delegitimize_address): New function.
* config/bpf/bpf.md (mov_reloc_core): Prefixed
name with '*'.
* config/bpf/core-builtins.cc (cr_builtins) Added access_node to
struct.
(is_attr_preserve_access): Improved check.
(core_field_info): Make use of root_for_core_field_info
function.
(process_field_expr): Adapted to new functions.
(pack_type): Small improvement.
(bpf_handle_plugin_finish_type): Adapted to GTY(()).
(bpf_init_core_builtins): Changed to new function names.
(construct_builtin_core_reloc): Improved implementation.
(bpf_resolve_overloaded_core_builtin): Changed how
__builtin_preserve_access_index is converted.
(compute_field_expr): Corrected implementation. Added
access_node argument.
(bpf_core_get_index): Added valid argument.
(root_for_core_field_info, pack_field_expr)
(core_expr_with_field_expr_plus_base, make_core_safe_access_index)
(replace_core_access_index_comp_expr, maybe_get_base_for_field_expr)
(core_access_clean, core_is_access_index, core_mark_as_access_index)
(make_gimple_core_safe_access_index, execute_lower_bpf_core)
(make_pass_lower_bpf_core): Added functions.
(pass_data_lower_bpf_core): New pass struct.
(pass_lower_bpf_core): New gimple_opt_pass class.
(pack_field_expr_for_preserve_field)
(bpf_replace_core_move_operands): Removed function.
(bpf_enum_value_kind): Added GTY(()).
* config/bpf/core-builtins.h (bpf_field_info_kind, bpf_type_id_kind)
(bpf_type_info_kind, bpf_enum_value_kind): New enum.
* config/bpf/t-bpf: Added pass bpf-passes.def to PASSES_EXTRA.

gcc/testsuite/ChangeLog:
* gcc.target/bpf/core-attr-5.c: New test.
* gcc.target/bpf/core-attr-6.c: New test.
* gcc.target/bpf/core-builtin-1.c: Corrected
* gcc.target/bpf/core-builtin-enumvalue-opt.c: Corrected regular
expression.
* gcc.target/bpf/core-builtin-enumvalue.c: Corrected regular
expression.
* gcc.target/bpf/core-builtin-exprlist-1.c: New test.
* gcc.target/bpf/core-builtin-exprlist-2.c: New test.
* gcc.target/bpf/core-builtin-exprlist-3.c: New test.
* gcc.target/bpf/core-builtin-exprlist-4.c: New test.
* gcc.target/bpf/core-builtin-fieldinfo-offset-1.c: Extra tests

diff --git a/gcc/config/bpf/bpf-passes.def b/gcc/config/bpf/bpf-passes.def
new file mode 100644
index ..0ec20eac965d
--- /dev/null
+++ b/gcc/config/bpf/bpf-passes.def
@@ -0,0 +1,20 @@
+/* Declaration of target-specific passes for eBPF.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software