!157 [sync] PR-155: [Sync] Sync patch from openeuler/gcc

From: @openeuler-sync-bot 
Reviewed-by: @eastb233 
Signed-off-by: @eastb233
This commit is contained in:
openeuler-ci-bot 2022-03-23 03:40:54 +00:00 committed by Gitee
commit 03165599dd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 139 additions and 1 deletions

View File

@ -0,0 +1,130 @@
From adfcca263996bf174f7108b477e81e7ec58f19c4 Mon Sep 17 00:00:00 2001
From: dingguangya <dingguangya1@huawei.com>
Date: Mon, 14 Mar 2022 10:42:07 +0800
Subject: [PATCH] [AutoFdo] Fix memory leaks in autofdo and autoprefetch
Fix memory leaks in autofdo and autoprefetch.
---
gcc/final.c | 23 +++++++++++++++--------
gcc/tree-ssa-loop-prefetch.c | 4 ++++
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/gcc/final.c b/gcc/final.c
index b9affd3a7..da8d20958 100644
--- a/gcc/final.c
+++ b/gcc/final.c
@@ -4770,12 +4770,16 @@ get_fdo_count_quality (profile_count count)
return profile_quality[count.quality ()];
}
-static const char *
+/* If the function is not public, return the function_name/file_name for
+ disambiguation of local symbols since there could be identical function
+ names coming from identical file names. The caller needs to free memory. */
+
+static char *
alias_local_functions (const char *fnname)
{
if (TREE_PUBLIC (cfun->decl))
{
- return fnname;
+ return concat (fnname, NULL);
}
return concat (fnname, "/", lbasename (dump_base_name), NULL);
@@ -4826,12 +4830,14 @@ dump_direct_callee_info_to_asm (basic_block bb, gcov_type call_count)
if (callee)
{
+ char *func_name =
+ alias_local_functions (get_fnname_from_decl (callee));
fprintf (asm_out_file, "\t.string \"%x\"\n",
INSN_ADDRESSES (INSN_UID (insn)));
fprintf (asm_out_file, "\t.string \"%s%s\"\n",
ASM_FDO_CALLEE_FLAG,
- alias_local_functions (get_fnname_from_decl (callee)));
+ func_name);
fprintf (asm_out_file,
"\t.string \"" HOST_WIDE_INT_PRINT_DEC "\"\n",
@@ -4841,9 +4847,9 @@ dump_direct_callee_info_to_asm (basic_block bb, gcov_type call_count)
{
fprintf (dump_file, "call: %x --> %s\n",
INSN_ADDRESSES (INSN_UID (insn)),
- alias_local_functions
- (get_fnname_from_decl (callee)));
+ func_name);
}
+ free (func_name);
}
}
}
@@ -4917,8 +4923,9 @@ dump_bb_info_to_asm (basic_block bb, gcov_type bb_count)
static void
dump_function_info_to_asm (const char *fnname)
{
+ char *func_name = alias_local_functions (fnname);
fprintf (asm_out_file, "\t.string \"%s%s\"\n",
- ASM_FDO_CALLER_FLAG, alias_local_functions (fnname));
+ ASM_FDO_CALLER_FLAG, func_name);
fprintf (asm_out_file, "\t.string \"%s%d\"\n",
ASM_FDO_CALLER_SIZE_FLAG, get_function_end_addr ());
fprintf (asm_out_file, "\t.string \"%s%s\"\n",
@@ -4926,8 +4933,7 @@ dump_function_info_to_asm (const char *fnname)
if (dump_file)
{
- fprintf (dump_file, "\n FUNC_NAME: %s\n",
- alias_local_functions (fnname));
+ fprintf (dump_file, "\n FUNC_NAME: %s\n", func_name);
fprintf (dump_file, " file: %s\n",
dump_base_name);
fprintf (dump_file, " profile_status: %s\n",
@@ -4937,6 +4943,7 @@ dump_function_info_to_asm (const char *fnname)
fprintf (dump_file, " function_bind: %s\n",
simple_get_function_bind ());
}
+ free (func_name);
}
/* Dump function profile info form AutoFDO or PGO to asm. */
diff --git a/gcc/tree-ssa-loop-prefetch.c b/gcc/tree-ssa-loop-prefetch.c
index 0d992d8f6..781831c39 100644
--- a/gcc/tree-ssa-loop-prefetch.c
+++ b/gcc/tree-ssa-loop-prefetch.c
@@ -2248,6 +2248,7 @@ get_bb_branch_prob (hash_map <basic_block, bb_bp> &bb_branch_prob,
branch_prob.true_edge_prob = get_edge_prob (e);
}
}
+ free (body);
}
/* Traverse each bb in the loop and prune fake loops. */
@@ -2416,6 +2417,7 @@ estimate_num_loop_insns (struct loop *loop, eni_weights *weights)
if (get_bb_prob (bb_branch_prob, loop) == false)
{
dump_loop_bb (loop);
+ free (body);
return 0;
}
if (dump_file && (dump_flags & TDF_DETAILS))
@@ -2596,6 +2598,7 @@ is_high_exec_rate_loop (struct loop *loop)
if (loop_exec_rate < (float) LOOP_EXECUTION_RATE / 100.0)
{
+ exit_edges.release ();
return false;
}
}
@@ -2606,6 +2609,7 @@ is_high_exec_rate_loop (struct loop *loop)
loop_exec_rate, (float) LOOP_EXECUTION_RATE / 100.0);
dump_loop_bb (loop);
}
+ exit_edges.release ();
return true;
}
--
2.27.0.windows.1

View File

@ -61,7 +61,7 @@
Summary: Various compilers (C, C++, Objective-C, ...)
Name: gcc
Version: %{gcc_version}
Release: 9
Release: 10
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
URL: https://gcc.gnu.org
@ -148,6 +148,7 @@ Patch29: 0029-AutoBOLT-Support-saving-feedback-count-info-to-ELF-s.patch
Patch30: 0030-AutoBOLT-Add-bolt-linker-plugin-2-3.patch
Patch31: 0031-AutoBOLT-Enable-BOLT-linker-plugin-on-aarch64-3-3.patch
Patch32: 0032-Autoprefetch-Prune-invaild-loops-containing-edges-wh.patch
Patch33: 0033-AutoFdo-Fix-memory-leaks-in-autofdo-and-autoprefetch.patch
%global gcc_target_platform %{_arch}-linux-gnu
@ -621,6 +622,7 @@ not stable, so plugins must be rebuilt any time GCC is updated.
%patch30 -p1
%patch31 -p1
%patch32 -p1
%patch33 -p1
%build
@ -2587,6 +2589,12 @@ end
%doc rpm.doc/changelogs/libcc1/ChangeLog*
%changelog
* Tue Mar 22 2022 benniaobufeijiushiji <linda7@huawei.com> - 10.3.1-10
- Type:Sync
- ID:NA
- SUG:NA
- DESC:Sync patch from openeuler/gcc
* Wed Mar 2 2022 benniaobufeijiushiji <linda7@huawei.com> - 10.3.1-9
- Type:Sync
- ID:NA