public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH 9f] Add a way for the C frontend to compile __RTL-tagged functions
Date: Tue, 10 Jan 2017 02:04:00 -0000	[thread overview]
Message-ID: <1484015904-32671-7-git-send-email-dmalcolm@redhat.com> (raw)
In-Reply-To: <1484015904-32671-1-git-send-email-dmalcolm@redhat.com>

The backend is full of singleton state, so we have to compile
__RTL-functions as soon as we parse them.  This means that the
C frontend needs to invoke the backed.

This patch adds the support needed.

Normally this would be a no-no, and including rtl headers is
blocked by this within system.h:

 /* Front ends should never have to include middle-end headers.  Enforce
    this by poisoning the header double-include protection defines.  */
 #ifdef IN_GCC_FRONTEND
 #pragma GCC poison GCC_RTL_H GCC_EXCEPT_H GCC_EXPR_H
 #endif

Hence the patch puts the decl into a new header (run-rtl-passes.h)
that's accessible to the C frontend without exposing any RTL
internals.  (If adding a header for just this decl is overkill, is
there a better place to put the decl?)

gcc/ChangeLog:
	* Makefile.in (OBJS): Add run-rtl-passes.o.
	* pass_manager.h (gcc::pass_manager::get_rest_of_compilation): New
	accessor.
	(gcc::pass_manager::get_clean_slate): New accessor.
	* run-rtl-passes.c: New file.
	* run-rtl-passes.h: New file.
---
 gcc/Makefile.in      |  1 +
 gcc/pass_manager.h   |  6 +++++
 gcc/run-rtl-passes.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gcc/run-rtl-passes.h | 25 ++++++++++++++++++++
 4 files changed, 98 insertions(+)
 create mode 100644 gcc/run-rtl-passes.c
 create mode 100644 gcc/run-rtl-passes.h

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 3d9532b..3ad53ad 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1442,6 +1442,7 @@ OBJS = \
 	rtlhash.o \
 	rtlanal.o \
 	rtlhooks.o \
+	run-rtl-passes.o \
 	sbitmap.o \
 	sched-deps.o \
 	sched-ebb.o \
diff --git a/gcc/pass_manager.h b/gcc/pass_manager.h
index 4d15407..ae97cd4 100644
--- a/gcc/pass_manager.h
+++ b/gcc/pass_manager.h
@@ -82,6 +82,12 @@ public:
 
   opt_pass *get_pass_by_name (const char *name);
 
+  opt_pass *get_rest_of_compilation () const
+  {
+    return pass_rest_of_compilation_1;
+  }
+  opt_pass *get_clean_slate () const { return pass_clean_state_1; }
+
 public:
   /* The root of the compilation pass tree, once constructed.  */
   opt_pass *all_passes;
diff --git a/gcc/run-rtl-passes.c b/gcc/run-rtl-passes.c
new file mode 100644
index 0000000..e1ac4bd
--- /dev/null
+++ b/gcc/run-rtl-passes.c
@@ -0,0 +1,66 @@
+/* run-rtl-passes.c - Run RTL passes directly from frontend
+   Copyright (C) 2016-2017 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 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 "target.h"
+#include "rtl.h"
+#include "function.h"
+#include "basic-block.h"
+#include "tree-pass.h"
+#include "context.h"
+#include "pass_manager.h"
+#include "bitmap.h"
+#include "df.h"
+#include "regs.h"
+#include "insn-attr-common.h" /* for INSN_SCHEDULING.  */
+#include "insn-attr.h" /* for init_sched_attrs.  */
+#include "run-rtl-passes.h"
+
+/* Run the backend passes, starting at the given pass.
+   Take ownership of INITIAL_PASS_NAME.  */
+
+void
+run_rtl_passes (char *initial_pass_name)
+{
+  cfun->pass_startwith = initial_pass_name;
+  max_regno = max_reg_num ();
+
+  /* Pass "expand" normally sets this up.  */
+#ifdef INSN_SCHEDULING
+  init_sched_attrs ();
+#endif
+
+  bitmap_obstack_initialize (NULL);
+  bitmap_obstack_initialize (&reg_obstack);
+
+  opt_pass *rest_of_compilation
+    = g->get_passes ()->get_rest_of_compilation ();
+  gcc_assert (rest_of_compilation);
+  execute_pass_list (cfun, rest_of_compilation);
+
+  opt_pass *clean_slate = g->get_passes ()->get_clean_slate ();
+  gcc_assert (clean_slate);
+  execute_pass_list (cfun, clean_slate);
+
+  bitmap_obstack_release (&reg_obstack);
+
+  cfun->curr_properties |= PROP_rtl;
+}
diff --git a/gcc/run-rtl-passes.h b/gcc/run-rtl-passes.h
new file mode 100644
index 0000000..1390303
--- /dev/null
+++ b/gcc/run-rtl-passes.h
@@ -0,0 +1,25 @@
+/* run-rtl-passes.h - Run a subset of the RTL passes
+   Copyright (C) 2016-2017 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 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/>.  */
+
+#ifndef GCC_RUN_RTL_PASSES_H
+#define GCC_RUN_RTL_PASSES_H
+
+extern void run_rtl_passes (char *initial_pass_name);
+
+#endif /* GCC_RUN_RTL_PASSES_H */
-- 
1.8.5.3

  parent reply	other threads:[~2017-01-10  2:04 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10  2:04 [PATCH 9/9] Add "__RTL" to cc1 (v8) David Malcolm
2017-01-10  2:04 ` [PATCH 9j] testsuite: add x86_64-specific files David Malcolm
2017-01-16 21:59   ` Jeff Law
2017-01-10  2:04 ` David Malcolm [this message]
2017-01-16 21:55   ` [PATCH 9f] Add a way for the C frontend to compile __RTL-tagged functions Jeff Law
2017-01-16 23:23     ` David Malcolm
2017-01-22  9:05       ` Jeff Law
2017-01-10  2:04 ` [PATCH 9a] Add "__RTL" to C frontend David Malcolm
2017-01-10 22:57   ` Joseph Myers
2017-01-10  2:04 ` [PATCH 9e] Update "startwith" logic for pass-skipping to handle __RTL functions David Malcolm
2017-01-16 21:42   ` Jeff Law
2017-01-17  9:28     ` Richard Biener
2017-01-17 21:10       ` [PATCH] Introduce opt_pass::skip virtual function David Malcolm
2017-01-18 16:39       ` [PATCH 9e] Update "startwith" logic for pass-skipping to handle __RTL functions Jeff Law
2017-01-18 17:19         ` David Malcolm
2017-01-19  9:31         ` Richard Biener
2017-01-19 16:52           ` [PATCH, v2] (9e) " David Malcolm
2017-01-20  8:07             ` Richard Biener
2017-01-20 14:57               ` David Malcolm
2017-01-20 15:20                 ` Richard Biener
2017-01-24 17:55                   ` [committed][PATCH 9/9] Add "__RTL" to cc1 (v9) David Malcolm
2017-01-24 18:06                     ` Joseph Myers
2017-01-23 23:59             ` [PATCH, v2] (9e) Update "startwith" logic for pass-skipping to handle __RTL functions Jeff Law
2017-01-20 20:37           ` [PATCH 9e] " Jeff Law
2017-01-10  2:04 ` [PATCH 9i] testsuite: add aarch64-specific files David Malcolm
2017-01-16 22:00   ` Jeff Law
2017-01-10  2:04 ` [PATCH 9g] Extend .md and RTL parsing to support being wired up to cc1 David Malcolm
2017-01-16 22:04   ` Jeff Law
2017-01-16 23:09     ` David Malcolm
2017-01-10  2:04 ` [PATCH 9b] Don't assume that copy tables were initialized David Malcolm
2017-01-10 13:37   ` Richard Biener
2017-01-10  2:04 ` [PATCH 9c] callgraph: handle __RTL functions David Malcolm
2017-01-16 21:25   ` Jeff Law
2017-01-17  9:21     ` Richard Biener
2017-01-17 12:36       ` Jan Hubicka
2017-01-17 17:25         ` David Malcolm
2017-01-18 12:51           ` Jan Hubicka
2017-01-18  0:35       ` Jeff Law
2017-01-10  2:04 ` [PATCH 9d] Don't call delete_tree_ssa for " David Malcolm
2017-01-10 13:42   ` Richard Biener
2017-01-16 21:15     ` Jeff Law
2017-01-16 21:14   ` Jeff Law
2017-01-10  2:04 ` [PATCH 9h] testsuite: add platform-independent files David Malcolm
2017-01-16 21:56   ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484015904-32671-7-git-send-email-dmalcolm@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).