summaryrefslogtreecommitdiff
path: root/0315-Bugfix-Add-no-var-recored-check-for-ssa_name-in-stru.patch
diff options
context:
space:
mode:
Diffstat (limited to '0315-Bugfix-Add-no-var-recored-check-for-ssa_name-in-stru.patch')
-rw-r--r--0315-Bugfix-Add-no-var-recored-check-for-ssa_name-in-stru.patch234
1 files changed, 234 insertions, 0 deletions
diff --git a/0315-Bugfix-Add-no-var-recored-check-for-ssa_name-in-stru.patch b/0315-Bugfix-Add-no-var-recored-check-for-ssa_name-in-stru.patch
new file mode 100644
index 0000000..befe1f6
--- /dev/null
+++ b/0315-Bugfix-Add-no-var-recored-check-for-ssa_name-in-stru.patch
@@ -0,0 +1,234 @@
+From 05bece3d79daa886a469b066061f0606ca6ebed8 Mon Sep 17 00:00:00 2001
+From: huang-xioaquan <huangxiaoquan1@huawei.com>
+Date: Mon, 2 Dec 2024 17:39:11 +0800
+Subject: [PATCH 2/5] [Bugfix] Add no var recored check for ssa_name in struct
+ reorg
+
+---
+ gcc/ipa-struct-reorg/escapes.def | 1 +
+ gcc/ipa-struct-reorg/ipa-struct-reorg.cc | 44 ++++++
+ .../gcc.dg/struct/rf_void_ptr_ssa_name.c | 125 ++++++++++++++++++
+ 3 files changed, 170 insertions(+)
+ create mode 100644 gcc/testsuite/gcc.dg/struct/rf_void_ptr_ssa_name.c
+
+diff --git a/gcc/ipa-struct-reorg/escapes.def b/gcc/ipa-struct-reorg/escapes.def
+index 996a09bac..4ba9cc2d0 100644
+--- a/gcc/ipa-struct-reorg/escapes.def
++++ b/gcc/ipa-struct-reorg/escapes.def
+@@ -61,5 +61,6 @@ DEF_ESCAPE (escape_unhandled_rewrite, "Type escapes via a unhandled rewrite stmt
+ DEF_ESCAPE (escape_via_orig_escape, "Type escapes via a original escape type")
+ DEF_ESCAPE (escape_instance_field, "Type escapes via a field of instance")
+ DEF_ESCAPE (escape_via_empty_no_orig, "Type escapes via empty and no original")
++DEF_ESCAPE (escape_no_record_var, "Type escapes via no record var")
+
+ #undef DEF_ESCAPE
+diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc
+index 1a169c635..b93b8a5b5 100644
+--- a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc
++++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc
+@@ -1433,6 +1433,7 @@ public:
+ void propagate_escape_via_original (void);
+ void propagate_escape_via_empty_with_no_original (void);
+ void propagate_escape_via_ext_func_types (void);
++ void propagate_escape_via_no_record_var (void);
+ void analyze_types (void);
+ void clear_visited (void);
+ bool create_new_types (void);
+@@ -4467,6 +4468,13 @@ ipa_struct_reorg::check_type_and_push (tree newdecl, srdecl *decl,
+ }
+ /* At this point there should only be unkown void* ssa names. */
+ gcc_assert (TREE_CODE (newdecl) == SSA_NAME);
++ tree inner = SSA_NAME_VAR (newdecl);
++ if (current_layout_opt_level >= STRUCT_REORDER_FIELDS &&
++ inner && find_decl (inner) == NULL)
++ {
++ type->mark_escape (escape_no_record_var, stmt);
++ return;
++ }
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "\nrecording unkown decl: ");
+@@ -5512,6 +5520,41 @@ ipa_struct_reorg::propagate_escape_via_ext_func_types (void)
+ }
+ }
+
++/* Escape propagation is performed on ssa_name decl that no record var in
++ decls. */
++
++void
++ipa_struct_reorg::propagate_escape_via_no_record_var (void)
++{
++ if (dump_file && (dump_flags & TDF_DETAILS))
++ fprintf (dump_file, "\n propagate_escape_via_no_record_var: \n\n");
++
++ for (unsigned i = 0; i < functions.length (); i++)
++ {
++ if (functions[i]->node)
++ set_cfun (DECL_STRUCT_FUNCTION (functions[i]->node->decl));
++
++ for (unsigned j = 0; j < functions[i]->decls.length (); j++)
++ {
++ srdecl *decl = functions[i]->decls[j];
++ srtype *type = decl->type;
++
++ if (TREE_CODE (decl->decl) == SSA_NAME)
++ {
++ tree inner = SSA_NAME_VAR (decl->decl);
++
++ if (inner && functions[i]->find_decl (inner) == NULL)
++ type->mark_escape (escape_no_record_var, NULL);
++ }
++ }
++
++ set_cfun (NULL);
++ }
++
++ if (dump_file && (dump_flags & TDF_DETAILS))
++ fprintf (dump_file, "\n end propagate_escape_via_no_record_var \n\n");
++}
++
+ /* Prune the escaped types and their decls from what was recorded. */
+
+ void
+@@ -5530,6 +5573,7 @@ ipa_struct_reorg::prune_escaped_types (void)
+ propagate_escape_via_original ();
+ propagate_escape_via_empty_with_no_original ();
+ propagate_escape_via_ext_func_types ();
++ propagate_escape_via_no_record_var ();
+ }
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+diff --git a/gcc/testsuite/gcc.dg/struct/rf_void_ptr_ssa_name.c b/gcc/testsuite/gcc.dg/struct/rf_void_ptr_ssa_name.c
+new file mode 100644
+index 000000000..0f624b6b9
+--- /dev/null
++++ b/gcc/testsuite/gcc.dg/struct/rf_void_ptr_ssa_name.c
+@@ -0,0 +1,125 @@
++// Add a void* ssa_name check and escape.
++/* { dg-do compile } */
++
++// includes
++#include "stdio.h"
++#include "stdlib.h"
++#include "time.h"
++#include "string.h"
++#include "limits.h"
++#include "float.h"
++
++#define JOTAI_NUM_RANDS_ 25
++
++const unsigned rand_primes[JOTAI_NUM_RANDS_] = {179, 103, 479, 647, 229, 37,
++271, 557, 263, 607, 18743, 50359, 21929, 48757, 98179, 12907, 52937, 64579,
++49957, 52567, 507163, 149939, 412157, 680861, 757751};
++
++int next_i ()
++{
++ int counter = 0;
++ return rand_primes[(++counter)%JOTAI_NUM_RANDS_];
++}
++
++float next_f ()
++{
++ int counter = 0;
++ return rand_primes[(++counter)%JOTAI_NUM_RANDS_] / 757751.0F;
++}
++
++// Usage menu
++void usage()
++{
++ printf("%s", "Usage:\n\
++ prog [ARGS]\n\
++\nARGS:\n\
++ 0 big-arr\n\
++ 1 big-arr-10x\n\
++ 2 empty\n\
++\n\
++");
++}
++
++// ------------------------------------------------------------------------- //
++
++typedef unsigned long size_t; // Customize by platform.
++typedef long intptr_t;
++typedef unsigned long uintptr_t;
++typedef long scalar_t__; // Either arithmetic or pointer type.
++/* By default, we understand bool (as a convenience). */
++typedef int bool;
++#define false 0
++#define true 1
++
++/* Forward declarations */
++
++/* Type definitions */
++typedef size_t u32 ;
++struct octeon_device {int octeon_id; } ;
++
++/* Variables and functions */
++ size_t MAX_OCTEON_DEVICES ;
++ struct octeon_device** octeon_device ;
++
++int lio_get_device_id(void *dev)
++{
++ struct octeon_device *octeon_dev = (struct octeon_device *)dev;
++ u32 i;
++
++ for (i = 0; i < MAX_OCTEON_DEVICES; i++)
++ {
++ if (octeon_device[i] == octeon_dev)
++ return octeon_dev->octeon_id;
++ }
++ return -1;
++}
++
++// ------------------------------------------------------------------------- //
++
++int main(int argc, char *argv[])
++{
++ if (argc != 2)
++ {
++ usage();
++ return 1;
++ }
++
++ int opt = atoi(argv[1]);
++ switch(opt)
++ {
++ // big-arr
++ case 0:
++ {
++ void * dev;
++ int benchRet = lio_get_device_id(dev);
++ printf("%d\n", benchRet);
++ break;
++ }
++
++ // big-arr-10x
++ case 1:
++ {
++ void * dev;
++ int benchRet = lio_get_device_id(dev);
++ printf("%d\n", benchRet);
++ break;
++ }
++
++ // empty
++ case 2:
++ {
++ void * dev;
++ int benchRet = lio_get_device_id(dev);
++ printf("%d\n", benchRet);
++ break;
++ }
++
++ default:
++ usage();
++ break;
++ }
++
++ return 0;
++}
++
++/* { dg-final { scan-ipa-dump "No structures to transform" "struct_reorg" } } */
+--
+2.33.0
+