* [PATCH RFA (cgraph)] c++: pragma target and static init [PR109753]
@ 2024-05-02 13:54 Jason Merrill
2024-05-14 21:21 ` PING " Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2024-05-02 13:54 UTC (permalink / raw)
To: gcc-patches, Jan Hubicka
Tested x86_64-pc-linux-gnu, OK for trunk? 14.2?
This two-year-old thread seems relevant:
https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593410.html
-- 8< --
#pragma target and optimize should also apply to implicitly-generated
functions like static initialization functions and defaulted special member
functions.
At least one of the create_same_body_alias/handle_optimize_attribute changes
is necessary to avoid regressing g++.dg/opt/pr105306.C; maybe_clone_body
creates a cgraph_node for the ~B alias before handle_optimize_attribute, and
the alias never goes through finalize_function, so we need to adjust
semantic_interposition somewhere else.
PR c++/109753
gcc/ChangeLog:
* cgraph.cc (cgraph_node::create_same_body_alias): Set
semantic_interposition.
gcc/c-family/ChangeLog:
* c-attribs.cc (handle_optimize_attribute): Set
cgraph_node::semantic_interposition.
gcc/cp/ChangeLog:
* decl.cc (start_preparsed_function): Call decl_attributes.
gcc/testsuite/ChangeLog:
* g++.dg/opt/always_inline1.C: New test.
---
gcc/c-family/c-attribs.cc | 4 ++++
gcc/cgraph.cc | 2 ++
gcc/cp/decl.cc | 3 +++
gcc/testsuite/g++.dg/opt/always_inline1.C | 8 ++++++++
4 files changed, 17 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/opt/always_inline1.C
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 04e39b41bdf..605469dd7dd 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -5971,6 +5971,10 @@ handle_optimize_attribute (tree *node, tree name, tree args,
if (prev_target_node != target_node)
DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node;
+ /* Also update the cgraph_node, if it's already built. */
+ if (cgraph_node *cn = cgraph_node::get (*node))
+ cn->semantic_interposition = flag_semantic_interposition;
+
/* Restore current options. */
cl_optimization_restore (&global_options, &global_options_set,
&cur_opts);
diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 473d8410bc9..f3bd2fa8ece 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -604,6 +604,8 @@ cgraph_node::create_same_body_alias (tree alias, tree decl)
n = cgraph_node::create_alias (alias, decl);
n->cpp_implicit_alias = true;
+ /* Aliases don't go through finalize_function. */
+ n->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition);
if (symtab->cpp_implicit_aliases_done)
n->resolve_alias (cgraph_node::get (decl));
return n;
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 378311c0f04..4531d830462 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -17796,6 +17796,9 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
doing_friend = true;
}
+ /* Adjust for #pragma target/optimize. */
+ decl_attributes (&decl1, NULL_TREE, 0);
+
if (DECL_DECLARED_INLINE_P (decl1)
&& lookup_attribute ("noinline", attrs))
warning_at (DECL_SOURCE_LOCATION (decl1), 0,
diff --git a/gcc/testsuite/g++.dg/opt/always_inline1.C b/gcc/testsuite/g++.dg/opt/always_inline1.C
new file mode 100644
index 00000000000..a042a1cf0c6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/always_inline1.C
@@ -0,0 +1,8 @@
+// PR c++/109753
+// { dg-do compile { target x86_64-*-* } }
+
+#pragma GCC target("avx2")
+struct aa {
+ __attribute__((__always_inline__)) aa() {}
+};
+aa _M_impl;
base-commit: 2f15787f2e1a3afe2c2ad93d4eb0d3c1f73c8fbd
--
2.44.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* PING Re: [PATCH RFA (cgraph)] c++: pragma target and static init [PR109753]
2024-05-02 13:54 [PATCH RFA (cgraph)] c++: pragma target and static init [PR109753] Jason Merrill
@ 2024-05-14 21:21 ` Jason Merrill
2024-05-23 22:43 ` PING " Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2024-05-14 21:21 UTC (permalink / raw)
To: gcc-patches, Jan Hubicka
Ping
On 5/2/24 09:54, Jason Merrill wrote:
> Tested x86_64-pc-linux-gnu, OK for trunk? 14.2?
>
> This two-year-old thread seems relevant:
> https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593410.html
>
> -- 8< --
>
> #pragma target and optimize should also apply to implicitly-generated
> functions like static initialization functions and defaulted special member
> functions.
>
> At least one of the create_same_body_alias/handle_optimize_attribute changes
> is necessary to avoid regressing g++.dg/opt/pr105306.C; maybe_clone_body
> creates a cgraph_node for the ~B alias before handle_optimize_attribute, and
> the alias never goes through finalize_function, so we need to adjust
> semantic_interposition somewhere else.
>
> PR c++/109753
>
> gcc/ChangeLog:
>
> * cgraph.cc (cgraph_node::create_same_body_alias): Set
> semantic_interposition.
>
> gcc/c-family/ChangeLog:
>
> * c-attribs.cc (handle_optimize_attribute): Set
> cgraph_node::semantic_interposition.
>
> gcc/cp/ChangeLog:
>
> * decl.cc (start_preparsed_function): Call decl_attributes.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/opt/always_inline1.C: New test.
> ---
> gcc/c-family/c-attribs.cc | 4 ++++
> gcc/cgraph.cc | 2 ++
> gcc/cp/decl.cc | 3 +++
> gcc/testsuite/g++.dg/opt/always_inline1.C | 8 ++++++++
> 4 files changed, 17 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/opt/always_inline1.C
>
> diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
> index 04e39b41bdf..605469dd7dd 100644
> --- a/gcc/c-family/c-attribs.cc
> +++ b/gcc/c-family/c-attribs.cc
> @@ -5971,6 +5971,10 @@ handle_optimize_attribute (tree *node, tree name, tree args,
> if (prev_target_node != target_node)
> DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node;
>
> + /* Also update the cgraph_node, if it's already built. */
> + if (cgraph_node *cn = cgraph_node::get (*node))
> + cn->semantic_interposition = flag_semantic_interposition;
> +
> /* Restore current options. */
> cl_optimization_restore (&global_options, &global_options_set,
> &cur_opts);
> diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
> index 473d8410bc9..f3bd2fa8ece 100644
> --- a/gcc/cgraph.cc
> +++ b/gcc/cgraph.cc
> @@ -604,6 +604,8 @@ cgraph_node::create_same_body_alias (tree alias, tree decl)
>
> n = cgraph_node::create_alias (alias, decl);
> n->cpp_implicit_alias = true;
> + /* Aliases don't go through finalize_function. */
> + n->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition);
> if (symtab->cpp_implicit_aliases_done)
> n->resolve_alias (cgraph_node::get (decl));
> return n;
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 378311c0f04..4531d830462 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -17796,6 +17796,9 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
> doing_friend = true;
> }
>
> + /* Adjust for #pragma target/optimize. */
> + decl_attributes (&decl1, NULL_TREE, 0);
> +
> if (DECL_DECLARED_INLINE_P (decl1)
> && lookup_attribute ("noinline", attrs))
> warning_at (DECL_SOURCE_LOCATION (decl1), 0,
> diff --git a/gcc/testsuite/g++.dg/opt/always_inline1.C b/gcc/testsuite/g++.dg/opt/always_inline1.C
> new file mode 100644
> index 00000000000..a042a1cf0c6
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/opt/always_inline1.C
> @@ -0,0 +1,8 @@
> +// PR c++/109753
> +// { dg-do compile { target x86_64-*-* } }
> +
> +#pragma GCC target("avx2")
> +struct aa {
> + __attribute__((__always_inline__)) aa() {}
> +};
> +aa _M_impl;
>
> base-commit: 2f15787f2e1a3afe2c2ad93d4eb0d3c1f73c8fbd
^ permalink raw reply [flat|nested] 4+ messages in thread
* PING Re: PING Re: [PATCH RFA (cgraph)] c++: pragma target and static init [PR109753]
2024-05-14 21:21 ` PING " Jason Merrill
@ 2024-05-23 22:43 ` Jason Merrill
2024-05-29 13:49 ` [pushed] " Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2024-05-23 22:43 UTC (permalink / raw)
To: gcc-patches, Jan Hubicka
Ping
On 5/14/24 17:21, Jason Merrill wrote:
> Ping
>
> On 5/2/24 09:54, Jason Merrill wrote:
>> Tested x86_64-pc-linux-gnu, OK for trunk? 14.2?
>>
>> This two-year-old thread seems relevant:
>> https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593410.html
>>
>> -- 8< --
>>
>> #pragma target and optimize should also apply to implicitly-generated
>> functions like static initialization functions and defaulted special
>> member
>> functions.
>>
>> At least one of the create_same_body_alias/handle_optimize_attribute
>> changes
>> is necessary to avoid regressing g++.dg/opt/pr105306.C; maybe_clone_body
>> creates a cgraph_node for the ~B alias before
>> handle_optimize_attribute, and
>> the alias never goes through finalize_function, so we need to adjust
>> semantic_interposition somewhere else.
>>
>> PR c++/109753
>>
>> gcc/ChangeLog:
>>
>> * cgraph.cc (cgraph_node::create_same_body_alias): Set
>> semantic_interposition.
>>
>> gcc/c-family/ChangeLog:
>>
>> * c-attribs.cc (handle_optimize_attribute): Set
>> cgraph_node::semantic_interposition.
>>
>> gcc/cp/ChangeLog:
>>
>> * decl.cc (start_preparsed_function): Call decl_attributes.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * g++.dg/opt/always_inline1.C: New test.
>> ---
>> gcc/c-family/c-attribs.cc | 4 ++++
>> gcc/cgraph.cc | 2 ++
>> gcc/cp/decl.cc | 3 +++
>> gcc/testsuite/g++.dg/opt/always_inline1.C | 8 ++++++++
>> 4 files changed, 17 insertions(+)
>> create mode 100644 gcc/testsuite/g++.dg/opt/always_inline1.C
>>
>> diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
>> index 04e39b41bdf..605469dd7dd 100644
>> --- a/gcc/c-family/c-attribs.cc
>> +++ b/gcc/c-family/c-attribs.cc
>> @@ -5971,6 +5971,10 @@ handle_optimize_attribute (tree *node, tree
>> name, tree args,
>> if (prev_target_node != target_node)
>> DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node;
>> + /* Also update the cgraph_node, if it's already built. */
>> + if (cgraph_node *cn = cgraph_node::get (*node))
>> + cn->semantic_interposition = flag_semantic_interposition;
>> +
>> /* Restore current options. */
>> cl_optimization_restore (&global_options, &global_options_set,
>> &cur_opts);
>> diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
>> index 473d8410bc9..f3bd2fa8ece 100644
>> --- a/gcc/cgraph.cc
>> +++ b/gcc/cgraph.cc
>> @@ -604,6 +604,8 @@ cgraph_node::create_same_body_alias (tree alias,
>> tree decl)
>> n = cgraph_node::create_alias (alias, decl);
>> n->cpp_implicit_alias = true;
>> + /* Aliases don't go through finalize_function. */
>> + n->semantic_interposition = opt_for_fn (decl,
>> flag_semantic_interposition);
>> if (symtab->cpp_implicit_aliases_done)
>> n->resolve_alias (cgraph_node::get (decl));
>> return n;
>> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
>> index 378311c0f04..4531d830462 100644
>> --- a/gcc/cp/decl.cc
>> +++ b/gcc/cp/decl.cc
>> @@ -17796,6 +17796,9 @@ start_preparsed_function (tree decl1, tree
>> attrs, int flags)
>> doing_friend = true;
>> }
>> + /* Adjust for #pragma target/optimize. */
>> + decl_attributes (&decl1, NULL_TREE, 0);
>> +
>> if (DECL_DECLARED_INLINE_P (decl1)
>> && lookup_attribute ("noinline", attrs))
>> warning_at (DECL_SOURCE_LOCATION (decl1), 0,
>> diff --git a/gcc/testsuite/g++.dg/opt/always_inline1.C
>> b/gcc/testsuite/g++.dg/opt/always_inline1.C
>> new file mode 100644
>> index 00000000000..a042a1cf0c6
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/opt/always_inline1.C
>> @@ -0,0 +1,8 @@
>> +// PR c++/109753
>> +// { dg-do compile { target x86_64-*-* } }
>> +
>> +#pragma GCC target("avx2")
>> +struct aa {
>> + __attribute__((__always_inline__)) aa() {}
>> +};
>> +aa _M_impl;
>>
>> base-commit: 2f15787f2e1a3afe2c2ad93d4eb0d3c1f73c8fbd
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pushed] c++: pragma target and static init [PR109753]
2024-05-23 22:43 ` PING " Jason Merrill
@ 2024-05-29 13:49 ` Jason Merrill
0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2024-05-29 13:49 UTC (permalink / raw)
To: gcc-patches
Revised to drop the cgraph change so I can self-approve the remaining patch.
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
#pragma target and optimize should also apply to implicitly-generated
functions like static initialization functions and defaulted special member
functions.
The handle_optimize_attribute change is necessary to avoid regressing
g++.dg/opt/pr105306.C; maybe_clone_body creates a cgraph_node for the ~B
alias before handle_optimize_attribute, and the alias never goes through
finalize_function, so we need to adjust semantic_interposition somewhere
else.
PR c++/109753
gcc/c-family/ChangeLog:
* c-attribs.cc (handle_optimize_attribute): Set
cgraph_node::semantic_interposition.
gcc/cp/ChangeLog:
* decl.cc (start_preparsed_function): Call decl_attributes.
gcc/testsuite/ChangeLog:
* g++.dg/opt/always_inline1.C: New test.
---
gcc/c-family/c-attribs.cc | 4 ++++
gcc/cp/decl.cc | 3 +++
gcc/testsuite/g++.dg/opt/always_inline1.C | 8 ++++++++
3 files changed, 15 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/opt/always_inline1.C
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 04e39b41bdf..605469dd7dd 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -5971,6 +5971,10 @@ handle_optimize_attribute (tree *node, tree name, tree args,
if (prev_target_node != target_node)
DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node;
+ /* Also update the cgraph_node, if it's already built. */
+ if (cgraph_node *cn = cgraph_node::get (*node))
+ cn->semantic_interposition = flag_semantic_interposition;
+
/* Restore current options. */
cl_optimization_restore (&global_options, &global_options_set,
&cur_opts);
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index a992d54dc8f..d481e1ec074 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -17832,6 +17832,9 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
doing_friend = true;
}
+ /* Adjust for #pragma target/optimize. */
+ decl_attributes (&decl1, NULL_TREE, 0);
+
if (DECL_DECLARED_INLINE_P (decl1)
&& lookup_attribute ("noinline", attrs))
warning_at (DECL_SOURCE_LOCATION (decl1), 0,
diff --git a/gcc/testsuite/g++.dg/opt/always_inline1.C b/gcc/testsuite/g++.dg/opt/always_inline1.C
new file mode 100644
index 00000000000..a042a1cf0c6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/always_inline1.C
@@ -0,0 +1,8 @@
+// PR c++/109753
+// { dg-do compile { target x86_64-*-* } }
+
+#pragma GCC target("avx2")
+struct aa {
+ __attribute__((__always_inline__)) aa() {}
+};
+aa _M_impl;
base-commit: ff41abdca0ab9993b6170b9b1f46b3a40921f1b0
--
2.44.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-29 13:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-02 13:54 [PATCH RFA (cgraph)] c++: pragma target and static init [PR109753] Jason Merrill
2024-05-14 21:21 ` PING " Jason Merrill
2024-05-23 22:43 ` PING " Jason Merrill
2024-05-29 13:49 ` [pushed] " Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).