public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/autopar_devel] Fix alignment for local variable [PR90811]
@ 2020-08-22 21:25 Giuliano Belinassi
  0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-22 21:25 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4b224c7bf7faf7cd5443600d3afd7ed254a84f43

commit 4b224c7bf7faf7cd5443600d3afd7ed254a84f43
Author: Kito Cheng <kito.cheng@sifive.com>
Date:   Tue Apr 14 14:53:19 2020 +0800

    Fix alignment for local variable [PR90811]
    
     - The alignment for local variable was adjust during estimate_stack_frame_size,
       however it seems wrong spot to adjust that, expand phase will adjust that
       but it little too late to some gimple optimization, which rely on certain
       target hooks need to check alignment, forwprop is an example for
       that, result of simplify_builtin_call rely on the alignment on some
       target like ARM or RISC-V.
    
     - Exclude static local var and hard register var in the process of
       alignment adjustment.
    
     - This patch fix gfortran.dg/pr45636.f90 for arm and riscv.
    
     - Regression test on riscv32/riscv64 and x86_64-linux-gnu, no new fail
       introduced.
    
    gcc/ChangeLog
    
            PR target/90811
            * Makefile.in (OBJS): Add adjust-alignment.o.
            * adjust-alignment.c (pass_data_adjust_alignment): New.
            (pass_adjust_alignment): New.
            (pass_adjust_alignment::execute): New.
            (make_pass_adjust_alignment): New.
            * tree-pass.h (make_pass_adjust_alignment): New.
            * passes.def: Add pass_adjust_alignment.

Diff:
---
 gcc/ChangeLog          | 11 +++++++
 gcc/Makefile.in        |  1 +
 gcc/adjust-alignment.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++
 gcc/passes.def         |  1 +
 gcc/tree-pass.h        |  1 +
 5 files changed, 98 insertions(+)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9eee988e12c..fdaa94ae8b9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2020-05-20  Kito Cheng  <kito.cheng@sifive.com>
+
+	PR target/90811
+	* Makefile.in (OBJS): Add adjust-alignment.o.
+	* adjust-alignment.c (pass_data_adjust_alignment): New.
+	(pass_adjust_alignment): New.
+	(pass_adjust_alignment::execute): New.
+	(make_pass_adjust_alignment): New.
+	* tree-pass.h (make_pass_adjust_alignment): New.
+	* passes.def: Add pass_adjust_alignment.
+
 2020-05-19  Alex Coplan  <alex.coplan@arm.com>
 
 	PR target/94591
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 9ba21f735f6..0fe2ba241e3 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1267,6 +1267,7 @@ OBJS = \
 	insn-recog.o \
 	insn-enums.o \
 	ggc-page.o \
+	adjust-alignment.o \
 	alias.o \
 	alloc-pool.o \
 	auto-inc-dec.o \
diff --git a/gcc/adjust-alignment.c b/gcc/adjust-alignment.c
new file mode 100644
index 00000000000..40cfd188928
--- /dev/null
+++ b/gcc/adjust-alignment.c
@@ -0,0 +1,84 @@
+/* Adjust alignment for local variable.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Kito Cheng <kito.cheng@sifive.com>
+
+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 Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "backend.h"
+#include "target.h"
+#include "tree.h"
+#include "tree-pass.h"
+#include "tm_p.h"
+
+namespace {
+
+const pass_data pass_data_adjust_alignment =
+{
+  GIMPLE_PASS, /* type */
+  "adjust_alignment", /* name */
+  OPTGROUP_NONE, /* optinfo_flags */
+  TV_NONE, /* tv_id */
+  0, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  0, /* todo_flags_finish */
+};
+
+class pass_adjust_alignment : public gimple_opt_pass
+{
+public:
+  pass_adjust_alignment (gcc::context *ctxt)
+    : gimple_opt_pass (pass_data_adjust_alignment, ctxt)
+  {}
+
+  virtual unsigned int execute (function *);
+}; // class pass_adjust_alignment
+
+} // anon namespace
+
+/* Entry point to adjust_alignment pass.  */
+unsigned int
+pass_adjust_alignment::execute (function *fun)
+{
+  size_t i;
+  tree var;
+
+  FOR_EACH_LOCAL_DECL (fun, i, var)
+    {
+      /* Don't adjust aligment for static local var and hard register var.  */
+      if (is_global_var (var) || DECL_HARD_REGISTER (var))
+	continue;
+
+      unsigned align = LOCAL_DECL_ALIGNMENT (var);
+
+      /* Make sure alignment only increase.  */
+      gcc_assert (align >= DECL_ALIGN (var));
+
+      SET_DECL_ALIGN (var, align);
+    }
+  return 0;
+}
+
+gimple_opt_pass *
+make_pass_adjust_alignment (gcc::context *ctxt)
+{
+  return new pass_adjust_alignment (ctxt);
+}
diff --git a/gcc/passes.def b/gcc/passes.def
index 2bf2cb78fc5..92cbe587a8a 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -183,6 +183,7 @@ along with GCC; see the file COPYING3.  If not see
   NEXT_PASS (pass_oacc_device_lower);
   NEXT_PASS (pass_omp_device_lower);
   NEXT_PASS (pass_omp_target_link);
+  NEXT_PASS (pass_adjust_alignment);
   NEXT_PASS (pass_all_optimizations);
   PUSH_INSERT_PASSES_WITHIN (pass_all_optimizations)
       NEXT_PASS (pass_remove_cgraph_callee_edges);
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index a1207a20a3c..576b3f67434 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -480,6 +480,7 @@ extern gimple_opt_pass *make_pass_sprintf_length (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_walloca (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_coroutine_lower_builtins (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_coroutine_early_expand_ifns (gcc::context *ctxt);
+extern gimple_opt_pass *make_pass_adjust_alignment (gcc::context *ctxt);
 
 /* IPA Passes */
 extern simple_ipa_opt_pass *make_pass_ipa_lower_emutls (gcc::context *ctxt);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-22 21:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 21:25 [gcc/devel/autopar_devel] Fix alignment for local variable [PR90811] Giuliano Belinassi

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).