This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fwd: [RFC][gomp4] Offloading patches (2/3): Add tables generation


Okay, so given the resistance to a unique-string scheme I went back and adapted the mechanism from your patches for ptx. I guess we can use that for now; if and when it breaks I have something ready to replace it.

There were still a number of things in these patches that did not make sense to me and which I've changed. Let me know if there was a good reason for the way some of these things were originally done.
 * Functions and variables now go into different tables, otherwise
   intermixing between them could be a problem that causes tables to
   go out of sync between host and target (imagine one big table being
   generated by ptx lto1/mkoffload, and multiple small table fragments
   being linked together on the host side).
 * I've put the begin/end fragments for the host tables into crtstuff,
   which seems like the standard way of doing things.
 * Changed the generation of tables to lower the alignment so that
   there are no gaps when linking together multiple files.
 * All the target-specific image-generating code is moved out of
   lto-wrapper into a mkoffload tool.
 * Is there a reason to call a register function for the host tables?
   The way I've set it up, we register a target function/variable table
   while also passing a pointer to the __OPENMP_TARGET__ symbol which
   holds information about the host side tables.
 * There aren't any named sections in ptx, so I've added another target
   hook to write out the map.
 * An offload compiler is built with --enable-as-accelerator-for=, which
   eliminates the need for -fopenmp-target, and changes install paths so
   that the host compiler knows where to find it. No need for
   OFFLOAD_TARGET_COMPILERS anymore.

I'll still need to add gcc driver support to automatically set the OFFLOAD_TARGET_NAMES variable from the accelerator targets that were configured in. Currently that still needs to be set manually for testing.

I'm appending those parts of my current patch kit that seem relevant. This includes the ptx mkoffload tool and a patch to make a dummy GOMP_offload_register function. Most of the others are updated versions of patches I've posted before, and two adapted from Michael Zolotukhin's set (automatically generated files not included in the diffs for size reasons). How does this look?


Bernd

2013-09-05  Nathan Sidwell  <nathan@codesourcery.com>

	* configure.ac: Add --enable-accelerator.
	* configure: Rebuilt.

Index: gomp-4_0-branch/configure.ac
===================================================================
--- gomp-4_0-branch.orig/configure.ac
+++ gomp-4_0-branch/configure.ac
@@ -286,6 +286,26 @@ case ${with_newlib} in
   yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
 esac
 
+# Handle --enable-accelerator.  This is in top-level because both libgoacc and
+# GCC proper need this information.
+# --disable-accelerator
+#   Default.  Do not build accelerator pieces, only support host execution.
+# --enable-accelerator=device-triplet
+#   Build accelerator pieces for 'device-triplet'
+AC_ARG_ENABLE(accelerator,
+[AS_HELP_STRING([[--enable-accelerator[=ARG]]],
+		[build accelerator @<:@ARG={no,device-triplet}@:>@])],
+ENABLE_ACCELERATOR=$enableval,
+ENABLE_ACCELERATOR=no)
+case "${ENABLE_ACCELERATOR}" in
+  yes) AC_MSG_ERROR([--enable-accelerators must name accelerator]) ;;
+  no) ;;
+  nvptx)
+   # validate target ok here?
+   ;;
+  *) AC_MSG_ERROR([unrecognized accelerator]) ;;
+esac
+
 # Handle --enable-gold, --enable-ld.
 # --disable-gold [--enable-ld]
 #     Build only ld.  Default option.
Index: gcc/config.in
===================================================================
--- gcc/config.in.orig
+++ gcc/config.in
@@ -1,5 +1,18 @@
 /* config.in.  Generated from configure.ac by autoheader.  */
 
+/* Define if this compiler should be built and used as the target device
+   compiler for OpenACC. */
+#ifndef USED_FOR_TARGET
+#undef ACCEL_COMPILER
+#endif
+
+
+/* Define to the name of the OpenACC accelerator target. */
+#ifndef USED_FOR_TARGET
+#undef ACCEL_TARGET
+#endif
+
+
 /* Define if building universal (internal helper macro) */
 #ifndef USED_FOR_TARGET
 #undef AC_APPLE_UNIVERSAL_BUILD
Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac.orig
+++ gcc/configure.ac
@@ -38,6 +38,11 @@ AC_CANONICAL_TARGET
 # Determine the noncanonical target name, for directory use.
 ACX_NONCANONICAL_TARGET
 
+# Used for constructing correct paths for offload compilers.
+real_target_noncanonical=${target_noncanonical}
+tool_prefix=$target_noncanonical
+accel_dir_suffix=
+
 # Determine the target- and build-specific subdirectories
 GCC_TOPLEV_SUBDIRS
 
@@ -834,6 +839,36 @@ AC_ARG_ENABLE(languages,
 esac],
 [enable_languages=c])
 
+AC_ARG_ENABLE(accelerator,
+[AS_HELP_STRING([--enable-accelerator], [build accelerator @<:@ARG={no,device-triplet}@:>@])],
+[
+  case $enable_accelerator in
+  no) ;;
+  *)
+    AC_DEFINE_UNQUOTED(ACCEL_TARGET,"${enable_accelerator}",
+     [Define to the name of the OpenACC accelerator target.])
+    ;;
+  esac
+], [enable_accelerator=no])
+AC_SUBST(enable_accelerator)
+
+AC_ARG_ENABLE(as-accelerator-for,
+[AS_HELP_STRING([--enable-as-accelerator-for], [build compiler as accelerator target for given host])],
+[
+  if test $enable_accelerator = no; then
+    echo "--enable-as-accelerator-for requires --enable-accelerator"
+    exit 1;
+  fi
+  AC_DEFINE(ACCEL_COMPILER, 1,
+   [Define if this compiler should be built and used as the target
+    device compiler for OpenACC.])
+  enable_as_accelerator=yes
+  tool_prefix=${enable_as_accelerator_for}-accel-${enable_accelerator}
+  accel_dir_suffix=/accel/${target_noncanonical}
+  real_target_noncanonical=${enable_as_accelerator_for}
+], [enable_as_accelerator=no])
+AC_SUBST(enable_as_accelerator)
+
 AC_ARG_WITH(multilib-list,
 [AS_HELP_STRING([--with-multilib-list], [select multilibs (AArch64, SH and x86-64 only)])],
 :,
@@ -5375,6 +5410,10 @@ AC_SUBST(c_target_objs)
 AC_SUBST(cxx_target_objs)
 AC_SUBST(fortran_target_objs)
 AC_SUBST(target_cpu_default)
+AC_SUBST(tool_prefix)
+AC_SUBST(real_target_noncanonical)
+AC_SUBST(accel_dir_suffix)
+AC_SUBST(accel_host)
 
 AC_SUBST_FILE(language_hooks)
 
@@ -5578,5 +5617,6 @@ do
 done
 ], 
 [subdirs='$subdirs'])
+
 AC_OUTPUT
 
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in.orig
+++ gcc/Makefile.in
@@ -58,6 +58,7 @@ build=@build@
 host=@host@
 target=@target@
 target_noncanonical:=@target_noncanonical@
+real_target_noncanonical:=@real_target_noncanonical@
 
 # Sed command to transform gcc to installed name.
 program_transform_name := @program_transform_name@
@@ -66,6 +67,11 @@ program_transform_name := @program_trans
 # Directories used during build
 # -----------------------------
 
+# Normally identical to target_noncanonical, except for compilers built
+# as accelerator targets.
+tool_prefix = @tool_prefix@
+accel_dir_suffix = @accel_dir_suffix@
+
 # Directory where sources are, from where we are.
 srcdir = @srcdir@
 gcc_docdir = @srcdir@/doc
@@ -351,6 +357,8 @@ enable_plugin = @enable_plugin@
 
 enable_host_shared = @enable_host_shared@
 
+enable_as_accelerator = @enable_as_accelerator@
+
 CPPLIB = ../libcpp/libcpp.a
 CPPINC = -I$(srcdir)/../libcpp/include
 
@@ -586,9 +594,9 @@ libexecdir = @libexecdir@
 # --------
 
 # Directory in which the compiler finds libraries etc.
-libsubdir = $(libdir)/gcc/$(target_noncanonical)/$(version)
+libsubdir = $(libdir)/gcc/$(real_target_noncanonical)/$(version)$(accel_dir_suffix)
 # Directory in which the compiler finds executables
-libexecsubdir = $(libexecdir)/gcc/$(target_noncanonical)/$(version)
+libexecsubdir = $(libexecdir)/gcc/$(real_target_noncanonical)/$(version)$(accel_dir_suffix)
 # Directory in which all plugin resources are installed
 plugin_resourcesdir = $(libsubdir)/plugin
  # Directory in which plugin headers are installed
@@ -766,7 +774,7 @@ BUILD_CPPFLAGS= -I. -I$(@D) -I$(srcdir)
 
 # Actual name to use when installing a native compiler.
 GCC_INSTALL_NAME := $(shell echo gcc|sed '$(program_transform_name)')
-GCC_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gcc|sed '$(program_transform_name)')
+GCC_TARGET_INSTALL_NAME := $(tool_prefix)-$(shell echo gcc|sed '$(program_transform_name)')
 CPP_INSTALL_NAME := $(shell echo cpp|sed '$(program_transform_name)')
 GCOV_INSTALL_NAME := $(shell echo gcov|sed '$(program_transform_name)')
 
@@ -1935,9 +1943,11 @@ DRIVER_DEFINES = \
   -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc/\" \
   -DSTANDARD_LIBEXEC_PREFIX=\"$(libexecdir)/gcc/\" \
   -DDEFAULT_TARGET_VERSION=\"$(version)\" \
+  -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
   -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
   -DSTANDARD_BINDIR_PREFIX=\"$(bindir)/\" \
   -DTOOLDIR_BASE_PREFIX=\"$(libsubdir_to_prefix)$(prefix_to_exec_prefix)\" \
+  -DACCEL_DIR_SUFFIX=\"$(accel_dir_suffix)\" \
   @TARGET_SYSTEM_ROOT_DEFINE@ \
   $(VALGRIND_DRIVER_DEFINES) \
   $(if $(SHLIB),$(if $(filter yes,@enable_shared@),-DENABLE_SHARED_LIBGCC)) \
@@ -3203,16 +3213,22 @@ install-common: native lang.install-comm
 # Install the driver program as $(target_noncanonical)-gcc,
 # $(target_noncanonical)-gcc-$(version), and also as gcc if native.
 install-driver: installdirs xgcc$(exeext)
-	-rm -f $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
-	-$(INSTALL_PROGRAM) xgcc$(exeext) $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
-	-rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-$(version)$(exeext)
-	-( cd $(DESTDIR)$(bindir) && \
-	   $(LN) $(GCC_INSTALL_NAME)$(exeext) $(target_noncanonical)-gcc-$(version)$(exeext) )
-	-if [ ! -f gcc-cross$(exeext) ] ; then \
-	  rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-tmp$(exeext); \
+	-install_name=$(GCC_INSTALL_NAME); \
+	if test "@enable_as_accelerator@" = "yes" ; then \
+	  install_name=$(GCC_TARGET_INSTALL_NAME); \
+	fi; \
+	rm -f $(DESTDIR)$(bindir)/$${install_name}$(exeext); \
+	$(INSTALL_PROGRAM) xgcc$(exeext) $(DESTDIR)$(bindir)/$${install_name}$(exeext)
+	-if test "@enable_as_accelerator@" != "yes" ; then \
+	  rm -f $(DESTDIR)$(bindir)/$(tool_prefix)-gcc-$(version)$(exeext); \
 	  ( cd $(DESTDIR)$(bindir) && \
-	    $(LN) $(GCC_INSTALL_NAME)$(exeext) $(target_noncanonical)-gcc-tmp$(exeext) && \
-	    mv -f $(target_noncanonical)-gcc-tmp$(exeext) $(GCC_TARGET_INSTALL_NAME)$(exeext) ); \
+	    $(LN) $(GCC_INSTALL_NAME)$(exeext) $(tool_prefix)-gcc-$(version)$(exeext) ); \
+	  if [ ! -f gcc-cross$(exeext) ] ; then \
+	    rm -f $(DESTDIR)$(bindir)/$(tool_prefix)-gcc-tmp$(exeext); \
+	      ( cd $(DESTDIR)$(bindir) && \
+	      $(LN) $(GCC_INSTALL_NAME)$(exeext) $(tool_prefix)-gcc-tmp$(exeext) && \
+	      mv -f $(tool_prefix)-gcc-tmp$(exeext) $(GCC_TARGET_INSTALL_NAME)$(exeext) ); \
+	  fi; \
 	fi
 
 # Install the info files.
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c.orig
+++ gcc/gcc.c
@@ -157,6 +157,7 @@ static const char *const spec_version =
 /* The target machine.  */
 
 static const char *spec_machine = DEFAULT_TARGET_MACHINE;
+static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE;
 
 /* Nonzero if cross-compiling.
    When -b is used, the value comes from the `specs' file.  */
@@ -1230,6 +1231,9 @@ static const char *const standard_startf
    relative to the driver.  */
 static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
 
+/* A prefix to be used when this is an accelerator compiler.  */
+static const char *const accel_dir_suffix = ACCEL_DIR_SUFFIX;
+
 /* Subdirectory to use for locating libraries.  Set by
    set_multilib_dir based on the compilation options.  */
 
@@ -2184,7 +2188,7 @@ for_each_path (const struct path_prefix
 
   multi_suffix = machine_suffix;
   just_multi_suffix = just_machine_suffix;
-  if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0)
+  if (just_multi_suffix && do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0)
     {
       multi_dir = concat (multilib_dir, dir_separator_str, NULL);
       multi_suffix = concat (multi_suffix, multi_dir, NULL);
@@ -2211,7 +2215,7 @@ for_each_path (const struct path_prefix
       if (multiarch_suffix)
 	multiarch_len = strlen (multiarch_suffix);
       suffix_len = strlen (multi_suffix);
-      just_suffix_len = strlen (just_multi_suffix);
+      just_suffix_len = just_multi_suffix ?  strlen (just_multi_suffix) : 0;
 
       if (path == NULL)
 	{
@@ -2237,6 +2241,7 @@ for_each_path (const struct path_prefix
 	  /* Some paths are tried with just the machine (ie. target)
 	     subdir.  This is used for finding as, ld, etc.  */
 	  if (!skip_multi_dir
+	      && just_multi_suffix
 	      && pl->require_machine_suffix == 2)
 	    {
 	      memcpy (path + len, just_multi_suffix, just_suffix_len + 1);
@@ -4044,15 +4049,15 @@ process_command (unsigned int decoded_op
     }
 
   gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix));
-  tooldir_prefix2 = concat (tooldir_base_prefix, spec_machine,
+  tooldir_prefix2 = concat (tooldir_base_prefix, spec_host_machine,
 			    dir_separator_str, NULL);
 
   /* Look for tools relative to the location from which the driver is
      running, or, if that is not available, the configured prefix.  */
   tooldir_prefix
     = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
-	      spec_machine, dir_separator_str,
-	      spec_version, dir_separator_str, tooldir_prefix2, NULL);
+	      spec_host_machine, dir_separator_str, spec_version,
+	      accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL);
   free (tooldir_prefix2);
 
   add_prefix (&exec_prefixes,
@@ -6458,9 +6463,12 @@ main (int argc, char **argv)
 
   /* Read specs from a file if there is one.  */
 
-  machine_suffix = concat (spec_machine, dir_separator_str,
-			   spec_version, dir_separator_str, NULL);
-  just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
+  machine_suffix = concat (spec_host_machine, dir_separator_str, spec_version,
+			   accel_dir_suffix, dir_separator_str, NULL);
+#ifndef ACCEL_COMPILER
+  just_machine_suffix = concat (spec_host_machine,
+				dir_separator_str, NULL);
+#endif
 
   specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
   /* Read the specs file unless it is a default one.  */
@@ -6469,16 +6477,17 @@ main (int argc, char **argv)
   else
     init_spec ();
 
+#ifndef ACCEL_COMPILER
   /* We need to check standard_exec_prefix/just_machine_suffix/specs
      for any override of as, ld and libraries.  */
   specs_file = (char *) alloca (strlen (standard_exec_prefix)
 		       + strlen (just_machine_suffix) + sizeof ("specs"));
-
   strcpy (specs_file, standard_exec_prefix);
   strcat (specs_file, just_machine_suffix);
   strcat (specs_file, "specs");
   if (access (specs_file, R_OK) == 0)
     read_specs (specs_file, true, false);
+#endif
 
   /* Process any configure-time defaults specified for the command line
      options, via OPTION_DEFAULT_SPECS.  */
@@ -6657,8 +6666,9 @@ main (int argc, char **argv)
 
   /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake.  */
   if (gcc_exec_prefix)
-    gcc_exec_prefix = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
-			      spec_version, dir_separator_str, NULL);
+    gcc_exec_prefix = concat (gcc_exec_prefix, spec_host_machine,
+			      dir_separator_str, spec_version,
+			      accel_dir_suffix, dir_separator_str, NULL);
 
   /* Now we have the specs.
      Set the `valid' bits for switches that match anything in any spec.  */
	* Makefile.def (host_modules, dependencies): Add accel-gcc entries.
	(flags_to_pass): Add accel_target_alias).
	* Makefile.tpl (accel_target_alias, accel_target_vendor,
	accel_target_os, accel_target): New variables.
	(configure-[+prefix+][+module+]): Special case accel-gcc module.
	* configure.ac (host_tools): Add accel-gcc.
	(ENABLE_ACCELERATOR handling): Set skipdirs and
	accel_target_noncanonical, then use ACX_CANONICAL_ACCEL_TARGET.
	* configure: Regenerate.
	* Makefile.in: Regenerate.

	config/
	* acx.m4 (ACX_CANONICAL_ACCEL_TARGET): New macro.

------------------------------------------------------------------------
Index: configure.ac
===================================================================
--- configure.ac.orig
+++ configure.ac
@@ -141,7 +141,7 @@ host_libs="intl libiberty opcodes bfd re
 # binutils, gas and ld appear in that order because it makes sense to run
 # "make check" in that particular order.
 # If --enable-gold is used, "gold" may replace "ld".
-host_tools="texinfo flex bison binutils gas ld fixincludes gcc cgen sid sim gdb gprof etc expect dejagnu m4 utils guile fastjar gnattools"
+host_tools="texinfo flex bison binutils gas ld fixincludes accel-gcc gcc cgen sid sim gdb gprof etc expect dejagnu m4 utils guile fastjar gnattools"
 
 # libgcj represents the runtime libraries only used by gcj.
 libgcj="target-libffi \
@@ -297,15 +297,26 @@ AC_ARG_ENABLE(accelerator,
 		[build accelerator @<:@ARG={no,device-triplet}@:>@])],
 ENABLE_ACCELERATOR=$enableval,
 ENABLE_ACCELERATOR=no)
+accel_target_noncanonical=NONE
 case "${ENABLE_ACCELERATOR}" in
-  yes) AC_MSG_ERROR([--enable-accelerators must name accelerator]) ;;
-  no) ;;
-  nvptx)
-   # validate target ok here?
-   ;;
-  *) AC_MSG_ERROR([unrecognized accelerator]) ;;
+  yes)
+    AC_MSG_ERROR([--enable-accelerators must name accelerator])
+    skipdirs="${skipdirs} accel-gcc"
+    ;;
+  no)
+    skipdirs="${skipdirs} accel-gcc"
+    ;;
+  nvptx*)
+    accel_target_noncanonical="${ENABLE_ACCELERATOR}"
+    ;;
+  *)
+    AC_MSG_ERROR([unrecognized accelerator])
+    skipdirs="${skipdirs} accel-gcc"
+    ;;
 esac
 
+ACX_CANONICAL_ACCEL_TARGET
+
 # Handle --enable-gold, --enable-ld.
 # --disable-gold [--enable-ld]
 #     Build only ld.  Default option.
@@ -2139,7 +2150,15 @@ done
 configdirs_all="$configdirs"
 configdirs=
 for i in ${configdirs_all} ; do
-  if test -f ${srcdir}/$i/configure ; then
+  case $i in
+    accel-gcc)
+      confsrcdir=gcc
+      ;;
+    *)
+      confsrcdir=$i
+      ;;
+  esac
+  if test -f ${srcdir}/${confsrcdir}/configure ; then
     configdirs="${configdirs} $i"
   fi
 done
@@ -3148,7 +3167,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 NCN_STRICT_CHECK_TOOLS(AR, ar)
 NCN_STRICT_CHECK_TOOLS(AS, as)
Index: config/acx.m4
===================================================================
--- config/acx.m4.orig
+++ config/acx.m4
@@ -61,6 +61,36 @@ AC_DEFUN([ACX_NONCANONICAL_TARGET],
 AC_SUBST(target_noncanonical)
 ]) []dnl # ACX_NONCANONICAL_TARGET
 
+AC_DEFUN(ACX_CANONICAL_ACCEL_TARGET,
+[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
+AC_MSG_CHECKING(accelerator target system type)
+
+dnl Set accel_target_alias.
+accel_target_alias=$accel_target_noncanonical
+case "$accel_target_alias" in
+NONE)
+  accel_target=NONE
+  ;;
+*)
+  accel_target=`$ac_config_sub $accel_target_alias`
+  ;;
+esac
+
+dnl Set the other accel_target vars.
+changequote(<<, >>)dnl
+accel_target_cpu=`echo $accel_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+accel_target_vendor=`echo $accel_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+accel_target_os=`echo $accel_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+changequote([, ])dnl
+AC_MSG_RESULT($accel_target)
+AC_SUBST(accel_target_noncanonical)dnl
+AC_SUBST(accel_target)dnl
+AC_SUBST(accel_target_alias)dnl
+AC_SUBST(accel_target_cpu)dnl
+AC_SUBST(accel_target_vendor)dnl
+AC_SUBST(accel_target_os)dnl
+])
+
 dnl ####
 dnl # GCC_TOPLEV_SUBDIRS
 dnl # GCC & friends build 'build', 'host', and 'target' tools.  These must
Index: Makefile.def
===================================================================
--- Makefile.def.orig
+++ Makefile.def
@@ -45,6 +45,9 @@ host_modules= { module= flex; no_check_c
 host_modules= { module= gas; bootstrap=true; };
 host_modules= { module= gcc; bootstrap=true; 
 		extra_make_flags="$(EXTRA_GCC_FLAGS)"; };
+host_modules= { module= accel-gcc;
+	        actual_module=gcc;
+		extra_configure_flags='--enable-as-accelerator-for=$(target_alias)'; };
 host_modules= { module= gmp; lib_path=.libs; bootstrap=true;
 		extra_configure_flags='--disable-shared';
 		no_install= true;
@@ -211,6 +212,7 @@ flags_to_pass = { flag= sysconfdir ; };
 flags_to_pass = { flag= tooldir ; };
 flags_to_pass = { flag= build_tooldir ; };
 flags_to_pass = { flag= target_alias ; };
+flags_to_pass = { flag= accel_target_alias ; };
 
 // Build tools
 flags_to_pass = { flag= AWK ; };
@@ -307,6 +309,7 @@ dependencies = { module=all-gcc; on=all-
 dependencies = { module=all-gcc; on=all-mpfr; };
 dependencies = { module=all-gcc; on=all-mpc; };
 dependencies = { module=all-gcc; on=all-cloog; };
+dependencies = { module=all-gcc; on=all-accel-gcc; };
 dependencies = { module=all-gcc; on=all-build-texinfo; };
 dependencies = { module=all-gcc; on=all-build-bison; };
 dependencies = { module=all-gcc; on=all-build-flex; };
@@ -319,6 +322,24 @@ dependencies = { module=all-gcc; on=all-
 dependencies = { module=all-gcc; on=all-libiberty; };
 dependencies = { module=all-gcc; on=all-fixincludes; };
 dependencies = { module=all-gcc; on=all-lto-plugin; };
+dependencies = { module=all-accel-gcc; on=all-libiberty; hard=true; };
+dependencies = { module=all-accel-gcc; on=all-intl; };
+dependencies = { module=all-accel-gcc; on=all-mpfr; };
+dependencies = { module=all-accel-gcc; on=all-mpc; };
+dependencies = { module=all-accel-gcc; on=all-cloog; };
+dependencies = { module=all-accel-gcc; on=all-accel-gcc; };
+dependencies = { module=all-accel-gcc; on=all-build-texinfo; };
+dependencies = { module=all-accel-gcc; on=all-build-bison; };
+dependencies = { module=all-accel-gcc; on=all-build-flex; };
+dependencies = { module=all-accel-gcc; on=all-build-libiberty; };
+dependencies = { module=all-accel-gcc; on=all-build-fixincludes; };
+dependencies = { module=all-accel-gcc; on=all-zlib; };
+dependencies = { module=all-accel-gcc; on=all-libbacktrace; hard=true; };
+dependencies = { module=all-accel-gcc; on=all-libcpp; hard=true; };
+dependencies = { module=all-accel-gcc; on=all-libdecnumber; hard=true; };
+dependencies = { module=all-accel-gcc; on=all-libiberty; };
+dependencies = { module=all-accel-gcc; on=all-fixincludes; };
+dependencies = { module=all-accel-gcc; on=all-lto-plugin; };
 dependencies = { module=info-gcc; on=all-build-libiberty; };
 dependencies = { module=dvi-gcc; on=all-build-libiberty; };
 dependencies = { module=pdf-gcc; on=all-build-libiberty; };
Index: Makefile.tpl
===================================================================
--- Makefile.tpl.orig
+++ Makefile.tpl
@@ -49,6 +49,10 @@ target_alias=@target_noncanonical@
 target_vendor=@target_vendor@
 target_os=@target_os@
 target=@target@
+accel_target_alias=@accel_target_noncanonical@
+accel_target_vendor=@accel_target_vendor@
+accel_target_os=@accel_target_os@
+accel_target=@accel_target@
 
 program_transform_name = @program_transform_name@
 
@@ -996,18 +1000,23 @@ configure-[+prefix+][+module+]: [+ IF bo
 	$(SHELL) $(srcdir)/mkinstalldirs [+subdir+]/[+module+] ; \
 	[+exports+] [+extra_exports+] \
 	echo Configuring in [+subdir+]/[+module+]; \
+	[+ IF (= (get "module") "accel-gcc") +] \
+	this_target="$(accel_target_alias)"; \
+	[+ ELSE +] \
+	this_target="[+target_alias+]"; \
+	[+ ENDIF +] \
 	cd "[+subdir+]/[+module+]" || exit 1; \
 	case $(srcdir) in \
 	  /* | [A-Za-z]:[\\/]*) topdir=$(srcdir) ;; \
-	  *) topdir=`echo [+subdir+]/[+module+]/ | \
+	  *) topdir=`echo [+subdir+]/[+? actual_module (get "actual_module") (get "module")+]/ | \
 		sed -e 's,\./,,g' -e 's,[^/]*/,../,g' `$(srcdir) ;; \
 	esac; \
-	srcdiroption="--srcdir=$${topdir}/[+module+]"; \
-	libsrcdir="$$s/[+module+]"; \
+	srcdiroption="--srcdir=$${topdir}/[+? actual_module (get "actual_module") (get "module")+]"; \
+	libsrcdir="$$s/[+? actual_module (get "actual_module") (get "module")+]"; \
 	[+ IF no-config-site +]rm -f no-such-file || : ; \
 	CONFIG_SITE=no-such-file [+ ENDIF +]$(SHELL) $${libsrcdir}/configure \
 	  [+args+] --build=${build_alias} --host=[+host_alias+] \
-	  --target=[+target_alias+] $${srcdiroption} [+extra_configure_flags+] \
+	  --target=$${this_target} $${srcdiroption} [+extra_configure_flags+] \
 	  || exit 1
 @endif [+prefix+][+module+]
 
@@ -1085,7 +1094,7 @@ all-[+prefix+][+module+]: configure-[+pr
 	[+exports+] [+extra_exports+] \
 	(cd [+subdir+]/[+module+] && \
 	  $(MAKE) $(BASE_FLAGS_TO_PASS) [+args+] [+stage1_args+] [+extra_make_flags+] \
-		$(TARGET-[+prefix+][+module+]))
+		$(TARGET-[+prefix+][+? actual_module (get "actual_module") (get "module")+]))
 @endif [+prefix+][+module+]
 
 [+ IF bootstrap +]
Index: gcc/config/darwin.c
===================================================================
--- gcc/config/darwin.c.orig
+++ gcc/config/darwin.c
@@ -61,6 +61,7 @@ along with GCC; see the file COPYING3.
 #include "gimple.h"
 #include "gimplify.h"
 #include "lto-streamer.h"
+#include "lto-section-names.h"
 
 /* Darwin supports a feature called fix-and-continue, which is used
    for rapid turn around debugging.  When code is compiled with the
@@ -1900,9 +1901,6 @@ typedef struct GTY (()) darwin_lto_secti
 
 static GTY (()) vec<darwin_lto_section_e, va_gc> *lto_section_names;
 
-/* Segment for LTO data.  */
-#define LTO_SEGMENT_NAME "__GNU_LTO"
-
 /* Section wrapper scheme (used here to wrap the unlimited number of LTO
    sections into three Mach-O ones).
    NOTE: These names MUST be kept in sync with those in
Index: gcc/config/i386/winnt.c
===================================================================
--- gcc/config/i386/winnt.c.orig
+++ gcc/config/i386/winnt.c
@@ -49,6 +49,7 @@ along with GCC; see the file COPYING3.
 #include "is-a.h"
 #include "gimple.h"
 #include "lto-streamer.h"
+#include "lto-section-names.h"
 
 /* i386/PE specific attribute support.
 
Index: gcc/lto/lto-object.c
===================================================================
--- gcc/lto/lto-object.c.orig
+++ gcc/lto/lto-object.c
@@ -32,13 +32,9 @@ along with GCC; see the file COPYING3.
 #include "lto.h"
 #include "tm.h"
 #include "lto-streamer.h"
+#include "lto-section-names.h"
 #include "simple-object.h"
 
-/* Segment name for LTO sections.  This is only used for Mach-O.
-   FIXME: This needs to be kept in sync with darwin.c.  */
-
-#define LTO_SEGMENT_NAME "__GNU_LTO"
-
 /* An LTO file wrapped around an simple_object.  */
 
 struct lto_simple_object
Index: gcc/lto/lto.c
===================================================================
--- gcc/lto/lto.c.orig
+++ gcc/lto/lto.c
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.
 #include "lto.h"
 #include "lto-tree.h"
 #include "lto-streamer.h"
+#include "lto-section-names.h"
 #include "tree-streamer.h"
 #include "splay-tree.h"
 #include "lto-partition.h"
Index: gcc/lto-streamer.c
===================================================================
--- gcc/lto-streamer.c.orig
+++ gcc/lto-streamer.c
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3.
 #include "diagnostic-core.h"
 #include "tree-streamer.h"
 #include "lto-streamer.h"
+#include "lto-section-names.h"
 #include "streamer-hooks.h"
 
 /* Statistics gathered during LTO, WPA and LTRANS.  */
Index: gcc/lto-streamer.h
===================================================================
--- gcc/lto-streamer.h.orig
+++ gcc/lto-streamer.h
@@ -134,17 +134,6 @@ along with GCC; see the file COPYING3.
      String are represented in the table as pairs, a length in ULEB128
      form followed by the data for the string.  */
 
-/* The string that is the prefix on the section names we make for lto.
-   For decls the DECL_ASSEMBLER_NAME is appended to make the section
-   name for the functions and static_initializers.  For other types of
-   sections a '.' and the section type are appended.  */
-#define LTO_SECTION_NAME_PREFIX         ".gnu.lto_"
-#define OMP_SECTION_NAME_PREFIX         ".gnu.target_lto_"
-
-/* Can be either OMP_SECTION_NAME_PREFIX when we stream pragma omp target
-   stuff, or LTO_SECTION_NAME_PREFIX for lto case.  */
-extern const char  *section_name_prefix;
-
 #define LTO_major_version 3
 #define LTO_minor_version 0
 
Index: gcc/lto-wrapper.c
===================================================================
--- gcc/lto-wrapper.c.orig
+++ gcc/lto-wrapper.c
@@ -46,11 +46,7 @@ along with GCC; see the file COPYING3.
 #include "opts.h"
 #include "options.h"
 #include "simple-object.h"
-
-/* From lto-streamer.h which we cannot include with -fkeep-inline-functions.
-   ???  Split out a lto-streamer-core.h.  */
-
-#define LTO_SECTION_NAME_PREFIX         ".gnu.lto_"
+#include "lto-section-names.h"
 
 /* End of lto-streamer.h copy.  */
 
Index: gcc/lto-section-names.h
===================================================================
--- /dev/null
+++ gcc/lto-section-names.h
@@ -0,0 +1,34 @@
+/* Definitions for LTO section names.
+   Copyright (C) 2013 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/>.  */
+
+/* The string that is the prefix on the section names we make for lto.
+   For decls the DECL_ASSEMBLER_NAME is appended to make the section
+   name for the functions and static_initializers.  For other types of
+   sections a '.' and the section type are appended.  */
+#define LTO_SECTION_NAME_PREFIX ".gnu.lto_"
+#define LTO_TARGET_SECTION_NAME_PREFIX ".gnu.tlto_"
+
+/* Segment name for LTO sections.  This is only used for Mach-O.  */
+
+#define LTO_SEGMENT_NAME "__GNU_LTO"
+#define OMP_SECTION_NAME_PREFIX         ".gnu.target_lto_"
+
+/* Can be either OMP_SECTION_NAME_PREFIX when we stream pragma omp target
+   stuff, or LTO_SECTION_NAME_PREFIX for lto case.  */
+extern const char  *section_name_prefix;
Index: gcc/cgraphunit.c
===================================================================
--- gcc/cgraphunit.c.orig
+++ gcc/cgraphunit.c
@@ -210,6 +210,7 @@ along with GCC; see the file COPYING3.
 #include "pass_manager.h"
 #include "tree-nested.h"
 #include "gimplify.h"
+#include "lto-section-names.h"
 
 /* Queue of cgraph nodes scheduled to be added into cgraph.  This is a
    secondary queue used during optimization to accommodate passes that
Index: gomp-4_0-branch/gcc/lto/lto-object.c
===================================================================
--- gomp-4_0-branch.orig/gcc/lto/lto-object.c
+++ gomp-4_0-branch/gcc/lto/lto-object.c
@@ -225,8 +225,7 @@ lto_obj_add_section (void *data, const c
   void **slot;
   struct lto_section_list *list = loasd->list;
 
-  if (strncmp (name, LTO_SECTION_NAME_PREFIX,
-	       strlen (LTO_SECTION_NAME_PREFIX)) != 0)
+  if (strncmp (name, section_name_prefix, strlen (section_name_prefix)))
     return 1;
 
   new_name = xstrdup (name);
Index: gomp-4_0-branch/gcc/lto/lto.c
===================================================================
--- gomp-4_0-branch.orig/gcc/lto/lto.c
+++ gomp-4_0-branch/gcc/lto/lto.c
@@ -2082,7 +2082,7 @@ lto_section_with_id (const char *name, u
 {
   const char *s;
 
-  if (strncmp (name, LTO_SECTION_NAME_PREFIX, strlen (LTO_SECTION_NAME_PREFIX)))
+  if (strncmp (name, section_name_prefix, strlen (section_name_prefix)))
     return 0;
   s = strrchr (name, '.');
   return s && sscanf (s, "." HOST_WIDE_INT_PRINT_HEX_PURE, id) == 1;
@@ -2758,6 +2758,10 @@ read_cgraph_and_symbols (unsigned nfiles
 
   timevar_push (TV_IPA_LTO_DECL_IN);
 
+#ifdef ACCEL_COMPILER
+    section_name_prefix = OMP_SECTION_NAME_PREFIX;
+#endif
+
   real_file_decl_data
     = decl_data = ggc_alloc_cleared_vec_lto_file_decl_data_ptr (nfiles + 1);
   real_file_count = nfiles;
Index: gomp-4_0-branch/gcc/omp-low.c
===================================================================
--- gomp-4_0-branch.orig/gcc/omp-low.c
+++ gomp-4_0-branch/gcc/omp-low.c
@@ -64,6 +64,7 @@ along with GCC; see the file COPYING3.
 #include "optabs.h"
 #include "cfgloop.h"
 #include "target.h"
+#include "common/common-target.h"
 #include "omp-low.h"
 #include "gimple-low.h"
 #include "tree-cfgcleanup.h"
@@ -8494,19 +8495,22 @@ expand_omp_target (struct omp_region *re
     }
 
   gimple g;
-  /* FIXME: This will be address of
-     extern char __OPENMP_TARGET__[] __attribute__((visibility ("hidden")))
-     symbol, as soon as the linker plugin is able to create it for us.  */
-  tree openmp_target = build_zero_cst (ptr_type_node);
+  tree openmp_target
+    = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+		  get_identifier ("__OPENMP_TARGET__"), ptr_type_node);
+  TREE_PUBLIC (openmp_target) = 1;
+  DECL_EXTERNAL (openmp_target) = 1;
   if (kind == GF_OMP_TARGET_KIND_REGION)
     {
       tree fnaddr = build_fold_addr_expr (child_fn);
-      g = gimple_build_call (builtin_decl_explicit (start_ix), 7,
-			     device, fnaddr, openmp_target, t1, t2, t3, t4);
+      g = gimple_build_call (builtin_decl_explicit (start_ix), 7, device,
+			     fnaddr, build_fold_addr_expr (openmp_target),
+			     t1, t2, t3, t4);
     }
   else
-    g = gimple_build_call (builtin_decl_explicit (start_ix), 6,
-			   device, openmp_target, t1, t2, t3, t4);
+    g = gimple_build_call (builtin_decl_explicit (start_ix), 6, device,
+			   build_fold_addr_expr (openmp_target),
+			   t1, t2, t3, t4);
   gimple_set_location (g, gimple_location (entry_stmt));
   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
   if (kind != GF_OMP_TARGET_KIND_REGION)
@@ -12566,4 +12570,139 @@ make_pass_omp_simd_clone (gcc::context *
   return new pass_omp_simd_clone (ctxt);
 }
 
+/* Helper function for omp_finish_file routine.
+   Takes decls from V_DECLS and adds their addresses and sizes to
+   constructor-vector V_CTOR.  It will be later used as DECL_INIT for decl
+   representing a global symbol for OpenMP descriptor.  */
+static void
+add_decls_addresses_to_decl_constructor (vec<tree, va_gc> *v_decls,
+					 vec<constructor_elt, va_gc> *v_ctor)
+{
+  unsigned len = vec_safe_length (v_decls);
+  for (unsigned i = 0; i < len; i++)
+    {
+      tree it = (*v_decls)[i];
+      bool is_function = TREE_CODE (it) != VAR_DECL;
+
+      CONSTRUCTOR_APPEND_ELT (v_ctor, NULL_TREE, build_fold_addr_expr (it));
+      if (!is_function)
+	CONSTRUCTOR_APPEND_ELT (v_ctor, NULL_TREE,
+				fold_convert (const_ptr_type_node,
+					      DECL_SIZE (it)));
+    }
+}
+
+/* Create new symbol containing (address, size) pairs for omp-marked
+   functions and global variables.  */
+void
+omp_finish_file (void)
+{
+  struct cgraph_node *node;
+  struct varpool_node *vnode;
+  const char *funcs_section_name = ".offload_func_table_section";
+  const char *vars_section_name = ".offload_var_table_section";
+  vec<tree, va_gc> *v_funcs, *v_vars;
+
+  vec_alloc (v_vars, 0);
+  vec_alloc (v_funcs, 0);
+
+  /* Collect all omp-target functions.  */
+  FOR_EACH_DEFINED_FUNCTION (node)
+    {
+      /* TODO: This check could fail on functions, created by omp
+	 parallel/task pragmas.  It's better to name outlined for offloading
+	 functions in some different way and to check here the function name.
+	 It could be something like "*_omp_tgtfn" in contrast with "*_omp_fn"
+	 for functions from omp parallel/task pragmas.  */
+      if (!lookup_attribute ("omp declare target",
+			     DECL_ATTRIBUTES (node->decl))
+	  || !DECL_ARTIFICIAL (node->decl))
+	continue;
+      vec_safe_push (v_funcs, node->decl);
+    }
+  /* Collect all omp-target global variables.  */
+  FOR_EACH_DEFINED_VARIABLE (vnode)
+    {
+      if (!lookup_attribute ("omp declare target",
+			     DECL_ATTRIBUTES (vnode->decl))
+	  || TREE_CODE (vnode->decl) != VAR_DECL
+	  || DECL_SIZE (vnode->decl) == 0)
+	continue;
+
+      vec_safe_push (v_vars, vnode->decl);
+    }
+  unsigned num_vars = vec_safe_length (v_vars);
+  unsigned num_funcs = vec_safe_length (v_funcs);
+
+  if (num_vars == 0 && num_funcs == 0)
+    return;
+
+#ifdef ACCEL_COMPILER
+  /* Decls are placed in reversed order in fat-objects, so we need to
+     revert them back if we compile target.  */
+  for (unsigned i = 0; i < num_funcs / 2; i++)
+    {
+      tree it = (*v_funcs)[i];
+      (*v_funcs)[i] = (*v_funcs)[num_funcs - i - 1];
+      (*v_funcs)[num_funcs - i - 1] = it;
+    }
+  for (unsigned i = 0; i < num_vars / 2; i++)
+    {
+      tree it = (*v_vars)[i];
+      (*v_vars)[i] = (*v_vars)[num_vars - i - 1];
+      (*v_vars)[num_vars - i - 1] = it;
+    }
+#endif
+
+  if (targetm_common.have_named_sections)
+    {
+      vec<constructor_elt, va_gc> *v_f, *v_v;
+      vec_alloc (v_f, num_funcs);
+      vec_alloc (v_v, num_vars * 2);
+
+      add_decls_addresses_to_decl_constructor (v_funcs, v_f);
+      add_decls_addresses_to_decl_constructor (v_vars, v_v);
+
+      tree vars_decl_type = build_array_type_nelts (pointer_sized_int_node,
+						    num_vars * 2);
+      tree funcs_decl_type = build_array_type_nelts (pointer_sized_int_node,
+						     num_funcs);
+      TYPE_ALIGN (vars_decl_type) = TYPE_ALIGN (pointer_sized_int_node);
+      TYPE_ALIGN (funcs_decl_type) = TYPE_ALIGN (pointer_sized_int_node);
+      tree ctor_v = build_constructor (vars_decl_type, v_v);
+      tree ctor_f = build_constructor (funcs_decl_type, v_f);
+      TREE_CONSTANT (ctor_v) = TREE_CONSTANT (ctor_f) = 1;
+      TREE_STATIC (ctor_v) = TREE_STATIC (ctor_f) = 1;
+      tree funcs_decl = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+				    get_identifier (".omp_func_table"),
+				    funcs_decl_type);
+      tree vars_decl = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+				   get_identifier (".omp_var_table"),
+				   vars_decl_type);
+      TREE_STATIC (funcs_decl) = TREE_STATIC (vars_decl) = 1;
+      DECL_INITIAL (funcs_decl) = ctor_f;
+      DECL_INITIAL (vars_decl) = ctor_v;
+      DECL_SECTION_NAME (funcs_decl)
+	= build_string (strlen (funcs_section_name), funcs_section_name);
+      DECL_SECTION_NAME (vars_decl)
+	= build_string (strlen (vars_section_name), vars_section_name);
+ 
+      varpool_assemble_decl (varpool_node_for_decl (vars_decl));
+      varpool_assemble_decl (varpool_node_for_decl (funcs_decl));
+   }
+  else
+    {
+      for (unsigned i = 0; i < num_funcs; i++)
+	{
+	  tree it = (*v_funcs)[i];
+	  targetm.record_offload_symbol (it);
+	}  
+      for (unsigned i = 0; i < num_funcs; i++)
+	{
+	  tree it = (*v_vars)[i];
+	  targetm.record_offload_symbol (it);
+	}  
+    }
+}
+
 #include "gt-omp-low.h"
Index: gomp-4_0-branch/gcc/omp-low.h
===================================================================
--- gomp-4_0-branch.orig/gcc/omp-low.h
+++ gomp-4_0-branch/gcc/omp-low.h
@@ -27,5 +27,6 @@ extern void omp_expand_local (basic_bloc
 extern void free_omp_regions (void);
 extern tree omp_reduction_init (tree, tree);
 extern bool make_gimple_omp_edges (basic_block, struct omp_region **, int *);
+extern void omp_finish_file (void);
 
 #endif /* GCC_OMP_LOW_H */
Index: gomp-4_0-branch/gcc/toplev.c
===================================================================
--- gomp-4_0-branch.orig/gcc/toplev.c
+++ gomp-4_0-branch/gcc/toplev.c
@@ -79,6 +79,7 @@ along with GCC; see the file COPYING3.
 #include "context.h"
 #include "pass_manager.h"
 #include "optabs.h"
+#include "omp-low.h"
 
 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
 #include "dbxout.h"
@@ -577,6 +578,8 @@ compile_file (void)
       if (flag_sanitize & SANITIZE_THREAD)
 	tsan_finish_file ();
 
+      omp_finish_file ();
+
       output_shared_constant_pool ();
       output_object_blocks ();
       finish_tm_clone_pairs ();
Index: gomp-4_0-branch/gcc/config.in
===================================================================
--- gomp-4_0-branch.orig/gcc/config.in
+++ gomp-4_0-branch/gcc/config.in
@@ -145,6 +145,12 @@
 #endif
 
 
+/* Define this to enable support for offloading. */
+#ifndef USED_FOR_TARGET
+#undef ENABLE_OFFLOADING
+#endif
+
+
 /* Define to enable plugin support. */
 #ifndef USED_FOR_TARGET
 #undef ENABLE_PLUGIN
Index: gomp-4_0-branch/gcc/configure.ac
===================================================================
--- gomp-4_0-branch.orig/gcc/configure.ac
+++ gomp-4_0-branch/gcc/configure.ac
@@ -845,6 +845,8 @@ AC_ARG_ENABLE(accelerator,
   case $enable_accelerator in
   no) ;;
   *)
+    AC_DEFINE(ENABLE_OFFLOADING, 1,
+     [Define this to enable support for offloading.])
     AC_DEFINE_UNQUOTED(ACCEL_TARGET,"${enable_accelerator}",
      [Define to the name of the OpenACC accelerator target.])
     ;;
Index: gomp-4_0-branch/libgcc/crtstuff.c
===================================================================
--- gomp-4_0-branch.orig/libgcc/crtstuff.c
+++ gomp-4_0-branch/libgcc/crtstuff.c
@@ -311,6 +311,15 @@ register_tm_clones (void)
 }
 #endif /* USE_TM_CLONE_REGISTRY */
 
+#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
+void *_omp_func_table[0]
+  __attribute__ ((__used__, visibility ("protected"),
+		  section (".offload_func_table_section"))) = { };
+void *_omp_var_table[0]
+  __attribute__ ((__used__, visibility ("protected"),
+		  section (".offload_var_table_section"))) = { };
+#endif
+
 #if defined(INIT_SECTION_ASM_OP) || defined(INIT_ARRAY_SECTION_ASM_OP)
 
 #ifdef OBJECT_FORMAT_ELF
@@ -752,6 +761,23 @@ __do_global_ctors (void)
 #error "What are you doing with crtstuff.c, then?"
 #endif
 
+#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
+void *_omp_funcs_end[0]
+  __attribute__ ((__used__, visibility ("protected"),
+		  section (".offload_func_table_section"))) = { };
+void *_omp_vars_end[0]
+  __attribute__ ((__used__, visibility ("protected"),
+		  section (".offload_var_table_section"))) = { };
+extern void *_omp_func_table[];
+extern void *_omp_var_table[];
+void *__OPENMP_TARGET__[] __attribute__ ((__visibility__ ("protected"))) =
+{
+  &_omp_func_table, &_omp_funcs_end,
+  &_omp_var_table, &_omp_vars_end
+};
+#endif
+
+
 #else /* ! CRT_BEGIN && ! CRT_END */
 #error "One of CRT_BEGIN or CRT_END must be defined."
 #endif
Index: gomp-4_0-branch/gcc/target.def
===================================================================
--- gomp-4_0-branch.orig/gcc/target.def
+++ gomp-4_0-branch/gcc/target.def
@@ -1772,6 +1772,14 @@ HOOK_VECTOR_END (vectorize)
 #undef HOOK_PREFIX
 #define HOOK_PREFIX "TARGET_"
 
+DEFHOOK
+(record_offload_symbol,
+ "Used when offloaded functions are seen in the compilation unit and no named\n\
+sections are available.  It is called once for each symbol that must be\n\
+recorded in the offload function and variable table.",
+ void, (tree),
+ hook_void_tree)
+
 /* Allow target specific overriding of option settings after options have
   been changed by an attribute or pragma or when it is reset at the
   end of the code affected by an attribute or pragma.  */
Index: gomp-4_0-branch/gcc/doc/tm.texi
===================================================================
--- gomp-4_0-branch.orig/gcc/doc/tm.texi
+++ gomp-4_0-branch/gcc/doc/tm.texi
@@ -11413,3 +11413,9 @@ If defined, this function returns an app
 @deftypefn {Target Hook} void TARGET_ATOMIC_ASSIGN_EXPAND_FENV (tree *@var{hold}, tree *@var{clear}, tree *@var{update})
 ISO C11 requires atomic compound assignments that may raise floating-point exceptions to raise exceptions corresponding to the arithmetic operation whose result was successfully stored in a compare-and-exchange sequence.  This requires code equivalent to calls to @code{feholdexcept}, @code{feclearexcept} and @code{feupdateenv} to be generated at appropriate points in the compare-and-exchange sequence.  This hook should set @code{*@var{hold}} to an expression equivalent to the call to @code{feholdexcept}, @code{*@var{clear}} to an expression equivalent to the call to @code{feclearexcept} and @code{*@var{update}} to an expression equivalent to the call to @code{feupdateenv}.  The three expressions are @code{NULL_TREE} on entry to the hook and may be left as @code{NULL_TREE} if no code is required in a particular place.  The default implementation leaves all three expressions as @code{NULL_TREE}.  The @code{__atomic_feraiseexcept} function from @code{libatomic} may be of use as part of the code generated in @code{*@var{update}}.
 @end deftypefn
+
+@deftypefn {Target Hook} void TARGET_RECORD_OFFLOAD_SYMBOL (tree)
+Used when offloaded functions are seen in the compilation unit and no named
+sections are available.  It is called once for each symbol that must be
+recorded in the offload function and variable table.
+@end deftypefn
Index: gomp-4_0-branch/gcc/doc/tm.texi.in
===================================================================
--- gomp-4_0-branch.orig/gcc/doc/tm.texi.in
+++ gomp-4_0-branch/gcc/doc/tm.texi.in
@@ -8409,3 +8409,5 @@ and the associated definitions of those
 @hook TARGET_ATOMIC_ALIGN_FOR_MODE
 
 @hook TARGET_ATOMIC_ASSIGN_EXPAND_FENV
+
+@hook TARGET_RECORD_OFFLOAD_SYMBOL
Index: libgomp/libgomp.map
===================================================================
--- libgomp/libgomp.map	(revision 207857)
+++ libgomp/libgomp.map	(working copy)
@@ -226,6 +226,7 @@ GOMP_4.0 {
 	GOMP_target_end_data;
 	GOMP_target_update;
 	GOMP_teams;
+	GOMP_offload_register;
 } GOMP_3.0;
 
 OACC_2.0 {
Index: libgomp/libgomp_g.h
===================================================================
--- libgomp/libgomp_g.h	(revision 207857)
+++ libgomp/libgomp_g.h	(working copy)
@@ -213,7 +213,8 @@ extern void GOMP_target_end_data (void);
 extern void GOMP_target_update (int, const void *,
 				size_t, void **, size_t *, unsigned char *);
 extern void GOMP_teams (unsigned int, unsigned int);
-
+extern void GOMP_offload_register (const void *, const char *,
+				   const void *, const void *, void *);
 /* oacc-parallel.c */
 
 extern void GOACC_parallel (int, void (*) (void *), const void *,
Index: libgomp/target.c
===================================================================
--- libgomp/target.c	(revision 207857)
+++ libgomp/target.c	(working copy)
@@ -714,6 +714,13 @@ gomp_target_init (void)
   gomp_find_available_plugins ();
 }
 
+void
+GOMP_offload_register (const void *target_id, const char *target_name,
+		       const void *func_mappings, const void *var_mappings,
+		       void *target_data)
+{
+}
+
 #else /* PLUGIN_SUPPORT */
 /* If dlfcn.h is unavailable we always fallback to host execution.
    GOMP_target* routines are just stubs for this case.  */

Attachment: mkoffload.c
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]