public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/n] OpenMP 4.0 offloading infrastructure
@ 2014-09-15 16:52 Ilya Verbin
  2014-09-17 13:46 ` Jakub Jelinek
  0 siblings, 1 reply; 21+ messages in thread
From: Ilya Verbin @ 2014-09-15 16:52 UTC (permalink / raw)
  To: Jakub Jelinek, Richard Biener, Richard Henderson, gcc-patches
  Cc: Bernd Schmidt, Thomas Schwinge, Andrey Turetskiy, Kirill Yukhin

Hello,

This patch contains necessary changes for the build system to support offloading.
It adds 2 new options for configure:
* --enable-as-accelerator-for=ARG is intended for the offload target compiler.
* --enable-offload-targets=LIST is intended for the offload host compiler.
Some more info: https://gcc.gnu.org/wiki/Offloading#Building_host_and_accel_compilers

Bootstrapped and regtested on i686-linux and x86_64-linux.  Is it OK for trunk?


2014-09-15  Bernd Schmidt  <bernds@codesourcery.com>
	    Thomas Schwinge  <thomas@codesourcery.com>
	    Ilya Verbin  <ilya.verbin@intel.com>
	    Andrey Turetskiy  <andrey.turetskiy@intel.com>

	* configure: Regenerate.
	* configure.ac (--enable-as-accelerator-for)
	(--enable-offload-targets): New configure options.
gcc/
	* Makefile.in (real_target_noncanonical, accel_dir_suffix)
	(enable_as_accelerator): New variables substituted by configure.
	(libsubdir, libexecsubdir, unlibsubdir, install_driver): Tweak for the
	possibility of being configured as an offload compiler.
	(DRIVER_DEFINES): Pass new defines DEFAULT_REAL_TARGET_MACHINE and
	ACCEL_DIR_SUFFIX.
	* config.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (real_target_noncanonical, accel_dir_suffix)
	(enable_as_accelerator, enable_offload_targets): Compute new variables.
	(--enable-as-accelerator-for, --enable-offload-targets): New options.
	(ACCEL_COMPILER): Define if the compiler is built as the accel compiler.
	(OFFLOAD_TARGETS): List of target names suitable for offloading.
	(ENABLE_OFFLOADING): Define if list of offload targets is not empty.
libgcc/
	* Makefile.in (crtompbegin$(objext), crtompend$(objext)): New rule.
	* configure: Regenerate.
	* configure.ac (--enable-offload-targets): New configure option.
	(extra_parts): Add crtompbegin.o and crtompend.o if
	enable_offload_targets is not empty.
	* ompstuff.c: New file.
libgomp/
	* Makefile.in: Regenerate.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Check for libdl, required for plugin support.
	(PLUGIN_SUPPORT): Define if plugins are supported.
	(--enable-as-accelerator-for, --enable-offload-targets): New options.
	(OFFLOAD_LIBRARY): Define if libgomp is built as offload target library.
	(enable_offload_targets): Support Intel MIC targets.
	(OFFLOAD_TARGETS): List of target names suitable for offloading.
	* testsuite/Makefile.in: Regenerate.

Thanks,
  -- Ilya

---

diff --git a/configure b/configure
index 55fca62..fb40a2f 100755
--- a/configure
+++ b/configure
@@ -747,6 +747,8 @@ ospace_frag'
 ac_user_opts='
 enable_option_checking
 with_build_libsubdir
+enable_as_accelerator_for
+enable_offload_targets
 enable_gold
 enable_ld
 enable_libquadmath
@@ -1466,6 +1468,11 @@ Optional Features:
   --disable-option-checking  ignore unrecognized --enable/--with options
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-as-accelerator-for=ARG
+                          build as offload target compiler. Specify offload
+                          host triple by ARG.
+  --enable-offload-targets=LIST
+                          enable offloading to devices from LIST
   --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
   --enable-ld[=ARG]       build ld [ARG={default,yes,no}]
   --disable-libquadmath   do not build libquadmath directory
@@ -2893,6 +2900,26 @@ case ${with_newlib} in
   yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
 esac
 
+# Check whether --enable-as-accelerator-for was given.
+if test "${enable_as_accelerator_for+set}" = set; then :
+  enableval=$enable_as_accelerator_for; ENABLE_AS_ACCELERATOR_FOR=$enableval
+else
+  ENABLE_AS_ACCELERATOR_FOR=no
+fi
+
+
+# Check whether --enable-offload-targets was given.
+if test "${enable_offload_targets+set}" = set; then :
+  enableval=$enable_offload_targets;
+  if test x"$enable_offload_targets" = x; then
+    as_fn_error "no offload targets specified" "$LINENO" 5
+  fi
+
+else
+  enable_offload_targets=
+fi
+
+
 # Handle --enable-gold, --enable-ld.
 # --disable-gold [--enable-ld]
 #     Build only ld.  Default option.
diff --git a/configure.ac b/configure.ac
index 2dc657f..69e2d14 100644
--- a/configure.ac
+++ b/configure.ac
@@ -286,6 +286,22 @@ case ${with_newlib} in
   yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
 esac
 
+AC_ARG_ENABLE(as-accelerator-for,
+[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
+		[build as offload target compiler.
+		Specify offload host triple by ARG.])],
+ENABLE_AS_ACCELERATOR_FOR=$enableval,
+ENABLE_AS_ACCELERATOR_FOR=no)
+
+AC_ARG_ENABLE(offload-targets,
+[AS_HELP_STRING([--enable-offload-targets=LIST],
+		[enable offloading to devices from LIST])],
+[
+  if test x"$enable_offload_targets" = x; then
+    AC_MSG_ERROR([no offload targets specified])
+  fi
+], [enable_offload_targets=])
+
 # Handle --enable-gold, --enable-ld.
 # --disable-gold [--enable-ld]
 #     Build only ld.  Default option.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index e86382f..65c29b2 100644
--- a/gcc/Makefile.in
+++ b/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,10 @@ program_transform_name := @program_transform_name@
 # Directories used during build
 # -----------------------------
 
+# Normally identical to target_noncanonical, except for compilers built
+# as accelerator targets.
+accel_dir_suffix = @accel_dir_suffix@
+
 # Directory where sources are, from where we are.
 srcdir = @srcdir@
 gcc_docdir = @srcdir@/doc
@@ -356,6 +361,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
 
@@ -591,9 +598,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
@@ -601,7 +608,11 @@ plugin_includedir = $(plugin_resourcesdir)/include
 # Directory in which plugin specific executables are installed
 plugin_bindir = $(libexecsubdir)/plugin
 # Used to produce a relative $(gcc_tooldir) in gcc.o
+ifeq ($(enable_as_accelerator),yes)
+unlibsubdir = ../../../../..
+else
 unlibsubdir = ../../..
+endif
 # $(prefix), expressed as a path relative to $(libsubdir).
 #
 # An explanation of the sed strings:
@@ -1953,9 +1964,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)) \
@@ -3258,17 +3271,19 @@ install-common: native lang.install-common installdirs
 install-driver: installdirs xgcc$(exeext)
 	-rm -f $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
 	-$(INSTALL_PROGRAM) xgcc$(exeext) $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
-	-if [ "$(GCC_INSTALL_NAME)" != "$(target_noncanonical)-gcc-$(version)" ]; then \
-	  rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-$(version)$(exeext); \
-	  ( cd $(DESTDIR)$(bindir) && \
-	    $(LN) $(GCC_INSTALL_NAME)$(exeext) $(target_noncanonical)-gcc-$(version)$(exeext) ); \
-	fi
-	-if [ ! -f gcc-cross$(exeext) ] \
-	    && [ "$(GCC_INSTALL_NAME)" != "$(GCC_TARGET_INSTALL_NAME)" ]; then \
-	  rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-tmp$(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) ); \
+	-if test "@enable_as_accelerator@" != "yes" ; then \
+	  if [ "$(GCC_INSTALL_NAME)" != "$(target_noncanonical)-gcc-$(version)" ]; then \
+	    rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-$(version)$(exeext); \
+	    ( cd $(DESTDIR)$(bindir) && \
+	      $(LN) $(GCC_INSTALL_NAME)$(exeext) $(target_noncanonical)-gcc-$(version)$(exeext) ); \
+	  fi; \
+	  if [ ! -f gcc-cross$(exeext) ] \
+	      && [ "$(GCC_INSTALL_NAME)" != "$(GCC_TARGET_INSTALL_NAME)" ]; then \
+	    rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-tmp$(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) ); \
+	  fi; \
 	fi
 
 # Install the info files.
diff --git a/gcc/config.in b/gcc/config.in
index 90809e3..bf07125 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1,5 +1,11 @@
 /* config.in.  Generated from configure.ac by autoheader.  */
 
+/* Define if this compiler should be built as the offload target compiler. */
+#ifndef USED_FOR_TARGET
+#undef ACCEL_COMPILER
+#endif
+
+
 /* Define if building universal (internal helper macro) */
 #ifndef USED_FOR_TARGET
 #undef AC_APPLE_UNIVERSAL_BUILD
@@ -144,6 +150,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
@@ -1699,16 +1711,19 @@
 #undef HAVE_WORKING_VFORK
 #endif
 
-/* Define if isl is in use. */
-#ifndef USED_FOR_TARGET
-#undef HAVE_isl
-#endif
 
 /* Define if cloog is in use. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_cloog
 #endif
 
+
+/* Define if isl is in use. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_isl
+#endif
+
+
 /* Define if F_SETLKW supported by fcntl. */
 #ifndef USED_FOR_TARGET
 #undef HOST_HAS_F_SETLKW
@@ -1783,6 +1798,12 @@
 #endif
 
 
+/* Define to hold the list of target names suitable for offloading. */
+#ifndef USED_FOR_TARGET
+#undef OFFLOAD_TARGETS
+#endif
+
+
 /* Define to the address where bug reports for this package should be sent. */
 #ifndef USED_FOR_TARGET
 #undef PACKAGE_BUGREPORT
diff --git a/gcc/configure b/gcc/configure
index fc78f42..50426d6 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -610,6 +610,8 @@ ISLINC
 ISLLIBS
 GMPINC
 GMPLIBS
+accel_dir_suffix
+real_target_noncanonical
 target_cpu_default
 fortran_target_objs
 cxx_target_objs
@@ -761,6 +763,7 @@ LN
 LN_S
 AWK
 SET_MAKE
+enable_as_accelerator
 REPORT_BUGS_TEXI
 REPORT_BUGS_TO
 PKGVERSION
@@ -901,6 +904,8 @@ with_specs
 with_pkgversion
 with_bugurl
 enable_languages
+enable_as_accelerator_for
+enable_offload_targets
 with_multilib_list
 enable_rpath
 with_libiconv_prefix
@@ -1610,6 +1615,11 @@ Optional Features:
                           GNU Objective-C runtime
   --disable-shared        don't provide a shared libgcc
   --enable-languages=LIST specify which front-ends to build
+  --enable-as-accelerator-for=ARG
+                          build as offload target compiler. Specify offload
+                          host triple by ARG.
+  --enable-offload-targets=LIST
+                          enable offloading to devices from LIST
   --disable-rpath         do not hardcode runtime library paths
   --enable-sjlj-exceptions
                           arrange to use setjmp/longjmp exception handling
@@ -3194,6 +3204,10 @@ esac
 
 
 
+# Used for constructing correct paths for offload compilers.
+real_target_noncanonical=${target_noncanonical}
+accel_dir_suffix=
+
 # Determine the target- and build-specific subdirectories
 
 # post-stage1 host modules use a different CC_FOR_BUILD so, in order to
@@ -7391,6 +7405,47 @@ else
 fi
 
 
+# Check whether --enable-as-accelerator-for was given.
+if test "${enable_as_accelerator_for+set}" = set; then :
+  enableval=$enable_as_accelerator_for;
+
+$as_echo "#define ACCEL_COMPILER 1" >>confdefs.h
+
+  enable_as_accelerator=yes
+  sedscript="s#${target_noncanonical}#${enable_as_accelerator_for}-accel-${target_noncanonical}#"
+  program_transform_name=`echo $program_transform_name | sed $sedscript`
+  accel_dir_suffix=/accel/${target_noncanonical}
+  real_target_noncanonical=${enable_as_accelerator_for}
+
+else
+  enable_as_accelerator=no
+fi
+
+
+
+# Check whether --enable-offload-targets was given.
+if test "${enable_offload_targets+set}" = set; then :
+  enableval=$enable_offload_targets;
+  if test x"$enable_offload_targets" = x; then
+    as_fn_error "no offload targets specified" "$LINENO" 5
+  fi
+
+else
+  enable_offload_targets=
+fi
+
+enable_offload_targets=`echo "$enable_offload_targets" | sed -e 's#,#:#g'`
+
+cat >>confdefs.h <<_ACEOF
+#define OFFLOAD_TARGETS "$enable_offload_targets"
+_ACEOF
+
+if test x"$enable_offload_targets" != x; then
+
+$as_echo "#define ENABLE_OFFLOADING 1" >>confdefs.h
+
+fi
+
 
 # Check whether --with-multilib-list was given.
 if test "${with_multilib_list+set}" = set; then :
@@ -18033,7 +18088,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18036 "configure"
+#line 18091 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18139,7 +18194,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18142 "configure"
+#line 18197 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -27864,6 +27919,8 @@ fi
 
 
 
+
+
 # Echo link setup.
 if test x${build} = x${host} ; then
   if test x${host} = x${target} ; then
diff --git a/gcc/configure.ac b/gcc/configure.ac
index c7f0e6a..028b00e 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -38,6 +38,10 @@ 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}
+accel_dir_suffix=
+
 # Determine the target- and build-specific subdirectories
 GCC_TOPLEV_SUBDIRS
 
@@ -883,6 +887,37 @@ AC_ARG_ENABLE(languages,
 esac],
 [enable_languages=c])
 
+AC_ARG_ENABLE(as-accelerator-for,
+[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
+		[build as offload target compiler.
+		Specify offload host triple by ARG.])],
+[
+  AC_DEFINE(ACCEL_COMPILER, 1,
+    [Define if this compiler should be built as the offload target compiler.])
+  enable_as_accelerator=yes
+  sedscript="s#${target_noncanonical}#${enable_as_accelerator_for}-accel-${target_noncanonical}#"
+  program_transform_name=`echo $program_transform_name | sed $sedscript`
+  accel_dir_suffix=/accel/${target_noncanonical}
+  real_target_noncanonical=${enable_as_accelerator_for}
+], [enable_as_accelerator=no])
+AC_SUBST(enable_as_accelerator)
+
+AC_ARG_ENABLE(offload-targets,
+[AS_HELP_STRING([--enable-offload-targets=LIST],
+		[enable offloading to devices from LIST])],
+[
+  if test x"$enable_offload_targets" = x; then
+    AC_MSG_ERROR([no offload targets specified])
+  fi
+], [enable_offload_targets=])
+enable_offload_targets=`echo "$enable_offload_targets" | sed -e 's#,#:#g'`
+AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$enable_offload_targets",
+  [Define to hold the list of target names suitable for offloading.])
+if test x"$enable_offload_targets" != x; then
+  AC_DEFINE(ENABLE_OFFLOADING, 1,
+    [Define this to enable support for offloading.])
+fi
+
 AC_ARG_WITH(multilib-list,
 [AS_HELP_STRING([--with-multilib-list], [select multilibs (AArch64, SH and x86-64 only)])],
 :,
@@ -5488,6 +5523,8 @@ AC_SUBST(c_target_objs)
 AC_SUBST(cxx_target_objs)
 AC_SUBST(fortran_target_objs)
 AC_SUBST(target_cpu_default)
+AC_SUBST(real_target_noncanonical)
+AC_SUBST(accel_dir_suffix)
 
 AC_SUBST_FILE(language_hooks)
 
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index 6a6cf66..48f9173 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -987,6 +987,14 @@ crtendS$(objext): $(srcdir)/crtstuff.c
 crtbeginT$(objext): $(srcdir)/crtstuff.c
 	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN -DCRTSTUFFT_O
 
+# crtompbegin and crtompend contain symbols, that mark the begin and the end of
+# tables with addresses, required for OpenMP offloading.
+crtompbegin$(objext): $(srcdir)/ompstuff.c
+	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN
+
+crtompend$(objext): $(srcdir)/ompstuff.c
+	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END
+
 ifeq ($(enable_vtable_verify),yes)
 # These are used in vtable verification; see comments in source files for
 # more details.
diff --git a/libgcc/configure b/libgcc/configure
index 35896de..832f82c 100644
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -664,6 +664,7 @@ with_build_libsubdir
 enable_decimal_float
 with_system_libunwind
 enable_sjlj_exceptions
+enable_offload_targets
 enable_tls
 '
       ac_precious_vars='build_alias
@@ -1301,6 +1302,8 @@ Optional Features:
 			to use
   --enable-sjlj-exceptions
                           force use of builtin_setjmp for exceptions
+  --enable-offload-targets=LIST
+                          enable offloading to devices from LIST
   --enable-tls            Use thread-local storage [default=yes]
 
 Optional Packages:
@@ -4357,6 +4360,21 @@ esac
 # Collect host-machine-specific information.
 . ${srcdir}/config.host
 
+# Check whether --enable-offload-targets was given.
+if test "${enable_offload_targets+set}" = set; then :
+  enableval=$enable_offload_targets;
+  if test x"$enable_offload_targets" = x; then
+    as_fn_error "no offload targets specified" "$LINENO" 5
+  fi
+
+else
+  enable_offload_targets=
+fi
+
+if test x"$enable_offload_targets" != x; then
+  extra_parts="${extra_parts} crtompbegin.o crtompend.o"
+fi
+
 # Check if Solaris/x86 linker supports ZERO terminator unwind entries.
 # This is after config.host so we can augment tmake_file.
 # Link with -nostartfiles -nodefaultlibs since neither are present while
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index d877d21..3abba2d 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -307,6 +307,18 @@ esac
 # Collect host-machine-specific information.
 . ${srcdir}/config.host
 
+AC_ARG_ENABLE(offload-targets,
+[AS_HELP_STRING([--enable-offload-targets=LIST],
+		[enable offloading to devices from LIST])],
+[
+  if test x"$enable_offload_targets" = x; then
+    AC_MSG_ERROR([no offload targets specified])
+  fi
+], [enable_offload_targets=])
+if test x"$enable_offload_targets" != x; then
+  extra_parts="${extra_parts} crtompbegin.o crtompend.o"
+fi
+
 # Check if Solaris/x86 linker supports ZERO terminator unwind entries.
 # This is after config.host so we can augment tmake_file.
 # Link with -nostartfiles -nodefaultlibs since neither are present while
diff --git a/libgcc/ompstuff.c b/libgcc/ompstuff.c
new file mode 100644
index 0000000..7625e7c
--- /dev/null
+++ b/libgcc/ompstuff.c
@@ -0,0 +1,79 @@
+/* Specialized bits of code needed for the OpenMP offloading tables.
+   Copyright (C) 2014 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.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Target machine header files require this define. */
+#define IN_LIBGCC2
+
+/* FIXME: Including auto-host is incorrect, but until we have
+   identified the set of defines that need to go into auto-target.h,
+   this will have to do.  */
+#include "auto-host.h"
+#undef pid_t
+#undef rlim_t
+#undef ssize_t
+#undef vfork
+#include "tconfig.h"
+#include "tsystem.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "libgcc_tm.h"
+
+#define OFFLOAD_FUNC_TABLE_SECTION_NAME "__gnu_offload_funcs"
+#define OFFLOAD_VAR_TABLE_SECTION_NAME "__gnu_offload_vars"
+
+#ifdef CRT_BEGIN
+
+#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
+void *_omp_func_table[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
+void *_omp_var_table[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };
+#endif
+
+#elif defined CRT_END
+
+#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
+void *_omp_funcs_end[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
+void *_omp_vars_end[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };
+
+extern void *_omp_func_table[];
+extern void *_omp_var_table[];
+
+void *__OPENMP_TARGET__[]
+  __attribute__ ((__visibility__ ("hidden"))) =
+{
+  &_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
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 5cd666f..d2e1ffc 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -246,6 +246,7 @@ datadir = @datadir@
 datarootdir = @datarootdir@
 docdir = @docdir@
 dvidir = @dvidir@
+enable_as_accelerator = @enable_as_accelerator@
 enable_shared = @enable_shared@
 enable_static = @enable_static@
 exec_prefix = @exec_prefix@
diff --git a/libgomp/config.h.in b/libgomp/config.h.in
index 14c7e2a..e8466bf 100644
--- a/libgomp/config.h.in
+++ b/libgomp/config.h.in
@@ -30,6 +30,9 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
+/* Define to 1 if you have the `dl' library (-ldl). */
+#undef HAVE_LIBDL
+
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
@@ -86,6 +89,12 @@
    */
 #undef LT_OBJDIR
 
+/* Define if this library should be used on target device. */
+#undef OFFLOAD_LIBRARY
+
+/* Define to hold the list of target names suitable for offloading. */
+#undef OFFLOAD_TARGETS
+
 /* Name of package */
 #undef PACKAGE
 
@@ -107,6 +116,9 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
+/* Define if all infrastructure, needed for plugins, is supported. */
+#undef PLUGIN_SUPPORT
+
 /* The size of `char', as computed by sizeof. */
 #undef SIZEOF_CHAR
 
diff --git a/libgomp/configure b/libgomp/configure
index 766eb09..adb843d 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -616,6 +616,7 @@ OMP_LOCK_SIZE
 USE_FORTRAN_FALSE
 USE_FORTRAN_TRUE
 link_gomp
+enable_as_accelerator
 XLDFLAGS
 XCFLAGS
 config_path
@@ -770,6 +771,8 @@ enable_maintainer_mode
 enable_linux_futex
 enable_tls
 enable_symvers
+enable_as_accelerator_for
+enable_offload_targets
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1421,6 +1424,10 @@ Optional Features:
   --enable-tls            Use thread-local storage [default=yes]
   --enable-symvers=STYLE  enables symbol versioning of the shared library
                           [default=yes]
+  --enable-as-accelerator-for=ARG
+                          enable target implementation of libgomp routines
+  --enable-offload-targets=LIST
+                          enable offloading to devices from LIST
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -11094,7 +11101,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11097 "configure"
+#line 11104 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11200,7 +11207,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11203 "configure"
+#line 11210 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15052,6 +15059,60 @@ fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
 
+plugin_support=yes
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlsym in -ldl" >&5
+$as_echo_n "checking for dlsym in -ldl... " >&6; }
+if test "${ac_cv_lib_dl_dlsym+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlsym ();
+int
+main ()
+{
+return dlsym ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlsym=yes
+else
+  ac_cv_lib_dl_dlsym=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlsym" >&5
+$as_echo "$ac_cv_lib_dl_dlsym" >&6; }
+if test "x$ac_cv_lib_dl_dlsym" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBDL 1
+_ACEOF
+
+  LIBS="-ldl $LIBS"
+
+else
+  plugin_support=no
+fi
+
+if test x"$plugin_support" = xyes; then
+
+$as_echo "#define PLUGIN_SUPPORT 1" >>confdefs.h
+
+fi
+
 # Check for functions needed.
 for ac_func in getloadavg clock_gettime strtoull
 do :
@@ -16153,6 +16214,52 @@ else
   multilib_arg=
 fi
 
+# Check whether --enable-as-accelerator-for was given.
+if test "${enable_as_accelerator_for+set}" = set; then :
+  enableval=$enable_as_accelerator_for;
+
+$as_echo "#define OFFLOAD_LIBRARY 1" >>confdefs.h
+
+  enable_as_accelerator=yes
+
+else
+  enable_as_accelerator=no
+fi
+
+
+
+offload_targets=
+# Check whether --enable-offload-targets was given.
+if test "${enable_offload_targets+set}" = set; then :
+  enableval=$enable_offload_targets;
+  if test x"$enable_offload_targets" = x; then
+    as_fn_error "no offload targets specified" "$LINENO" 5
+  else
+    for tgt in $enable_offload_targets; do
+      case $tgt in
+	*-intelmic-*)
+	  offload_target_name="mic"
+	  ;;
+	*)
+	  as_fn_error "unknown offload target specified" "$LINENO" 5
+	  ;;
+      esac
+      if test x"$offload_targets" = x; then
+	offload_targets=$offload_target_name
+      else
+	offload_targets=$offload_targets,$offload_target_name
+      fi
+    done
+  fi
+
+fi
+
+
+cat >>confdefs.h <<_ACEOF
+#define OFFLOAD_TARGETS "$offload_targets"
+_ACEOF
+
+
 # Set up the set of libraries that we need to link against for libgomp.
 # Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
 # which will force linkage against -lpthread (or equivalent for the system).
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index 84d250f..9367b91 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -193,6 +193,13 @@ AC_LINK_IFELSE(
    [],
    [AC_MSG_ERROR([Pthreads are required to build libgomp])])])
 
+plugin_support=yes
+AC_CHECK_LIB(dl, dlsym, , [plugin_support=no])
+if test x"$plugin_support" = xyes; then
+  AC_DEFINE(PLUGIN_SUPPORT, 1,
+    [Define if all infrastructure, needed for plugins, is supported.])
+fi
+
 # Check for functions needed.
 AC_CHECK_FUNCS(getloadavg clock_gettime strtoull)
 
@@ -273,6 +280,44 @@ else
   multilib_arg=
 fi
 
+AC_ARG_ENABLE(as-accelerator-for,
+[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
+		[enable target implementation of libgomp routines])],
+[
+  AC_DEFINE(OFFLOAD_LIBRARY, 1,
+    [Define if this library should be used on target device.])
+  enable_as_accelerator=yes
+], [enable_as_accelerator=no])
+AC_SUBST(enable_as_accelerator)
+
+offload_targets=
+AC_ARG_ENABLE(offload-targets,
+[AS_HELP_STRING([--enable-offload-targets=LIST],
+		[enable offloading to devices from LIST])],
+[
+  if test x"$enable_offload_targets" = x; then
+    AC_MSG_ERROR([no offload targets specified])
+  else
+    for tgt in $enable_offload_targets; do
+      case $tgt in
+	*-intelmic-*)
+	  offload_target_name="mic"
+	  ;;
+	*)
+	  AC_MSG_ERROR([unknown offload target specified])
+	  ;;
+      esac
+      if test x"$offload_targets" = x; then
+	offload_targets=$offload_target_name
+      else
+	offload_targets=$offload_targets,$offload_target_name
+      fi
+    done
+  fi
+])
+AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$offload_targets",
+  [Define to hold the list of target names suitable for offloading.])
+
 # Set up the set of libraries that we need to link against for libgomp.
 # Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
 # which will force linkage against -lpthread (or equivalent for the system).
diff --git a/libgomp/testsuite/Makefile.in b/libgomp/testsuite/Makefile.in
index 5273eaa..efb64f3 100644
--- a/libgomp/testsuite/Makefile.in
+++ b/libgomp/testsuite/Makefile.in
@@ -162,6 +162,7 @@ datadir = @datadir@
 datarootdir = @datarootdir@
 docdir = @docdir@
 dvidir = @dvidir@
+enable_as_accelerator = @enable_as_accelerator@
 enable_shared = @enable_shared@
 enable_static = @enable_static@
 exec_prefix = @exec_prefix@
-- 
1.7.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-09-15 16:52 [PATCH 1/n] OpenMP 4.0 offloading infrastructure Ilya Verbin
@ 2014-09-17 13:46 ` Jakub Jelinek
  2014-09-26 12:36   ` Ilya Verbin
  0 siblings, 1 reply; 21+ messages in thread
From: Jakub Jelinek @ 2014-09-17 13:46 UTC (permalink / raw)
  To: Ilya Verbin
  Cc: Richard Biener, Richard Henderson, gcc-patches, Bernd Schmidt,
	Thomas Schwinge, Andrey Turetskiy, Kirill Yukhin

On Mon, Sep 15, 2014 at 08:52:27PM +0400, Ilya Verbin wrote:
> This patch contains necessary changes for the build system to support offloading.
> It adds 2 new options for configure:
> * --enable-as-accelerator-for=ARG is intended for the offload target compiler.
> * --enable-offload-targets=LIST is intended for the offload host compiler.
> Some more info: https://gcc.gnu.org/wiki/Offloading#Building_host_and_accel_compilers
> 
> Bootstrapped and regtested on i686-linux and x86_64-linux.  Is it OK for trunk?

Looks mostly ok, just some nits.  But see the patch I've just posted,
perhaps we want to tweak the --enable-offload-targets arguments.  And
I'd strongly prefer if the offloading patches are committed after everything
has been reviewed, so what will be acked please stash away for later batch
commits.
> --- /dev/null
> +++ b/libgcc/ompstuff.c
> @@ -0,0 +1,79 @@
> +/* FIXME: Including auto-host is incorrect, but until we have
> +   identified the set of defines that need to go into auto-target.h,
> +   this will have to do.  */
> +#include "auto-host.h"
> +#undef pid_t
> +#undef rlim_t
> +#undef ssize_t
> +#undef vfork

crtstuff.c undefs here also caddr_t, any reason not to do that too?

> +#include "tconfig.h"
> +#include "tsystem.h"
> +#include "coretypes.h"
> +#include "tm.h"
> +#include "libgcc_tm.h"
> +
> +#define OFFLOAD_FUNC_TABLE_SECTION_NAME "__gnu_offload_funcs"
> +#define OFFLOAD_VAR_TABLE_SECTION_NAME "__gnu_offload_vars"
> +
> +#ifdef CRT_BEGIN
> +
> +#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
> +void *_omp_func_table[0]
> +  __attribute__ ((__used__, visibility ("hidden"),
> +		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
> +void *_omp_var_table[0]
> +  __attribute__ ((__used__, visibility ("hidden"),
> +		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };
> +#endif

Does this mean that if HAVE_GAS_HIDDEN is not defined, you don't
define _omp_*_table at all and offloading will fail?
I wonder if it just should avoid visibility ("hidden") if it isn't
supported.

	Jakub

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-09-17 13:46 ` Jakub Jelinek
@ 2014-09-26 12:36   ` Ilya Verbin
  2014-09-26 22:03     ` Joseph S. Myers
                       ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Ilya Verbin @ 2014-09-26 12:36 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Richard Biener, Richard Henderson, gcc-patches, Bernd Schmidt,
	Thomas Schwinge, Andrey Turetskiy, Kirill Yukhin

Hi,

The patch has been updated:

On 17 Sep 15:45, Jakub Jelinek wrote:
> Looks mostly ok, just some nits.  But see the patch I've just posted,
> perhaps we want to tweak the --enable-offload-targets arguments.  And

Now the targets in --enable-offload-targets can have optional path to the build
or install tree of the corresponding offload compiler.

> > --- /dev/null
> > +++ b/libgcc/ompstuff.c
> > @@ -0,0 +1,79 @@
> > +/* FIXME: Including auto-host is incorrect, but until we have
> > +   identified the set of defines that need to go into auto-target.h,
> > +   this will have to do.  */
> > +#include "auto-host.h"
> > +#undef pid_t
> > +#undef rlim_t
> > +#undef ssize_t
> > +#undef vfork
> 
> crtstuff.c undefs here also caddr_t, any reason not to do that too?

caddr_t was added to the crtstuff.c after ompstuff.c was created.  Fixed.

> > +#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
> > +void *_omp_func_table[0]
> > +  __attribute__ ((__used__, visibility ("hidden"),
> > +		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
> > +void *_omp_var_table[0]
> > +  __attribute__ ((__used__, visibility ("hidden"),
> > +		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };
> > +#endif
> 
> Does this mean that if HAVE_GAS_HIDDEN is not defined, you don't
> define _omp_*_table at all and offloading will fail?
> I wonder if it just should avoid visibility ("hidden") if it isn't
> supported.

Without visibility ("hidden") offloading works in case if there is only an
executable.  If some dso will register their _omp_func_table in libgomp,
offloading will not work, since _omp_func_table from the executable override
the respective symbols in dso.  So, if there are exec and dso with offloading,
but without visibility ("hidden"), I'd prefer to perform host fallback, as is
now, rather than crashing at run-time.

Also, previous patch contains a bug: if a compiler is configured as accelerator,
it installs *-accel-*-g++, and other drivers.  But only *-accel-*-gcc is needed.
Therefore I suppressed their installation in corresponding Makefiles.

The define OFFLOAD_LIBRARY is now removed from libgomp, since it is no longer
needed.

And libexecsubdir in lto-plugin/Makefile.in is tweaked for the possibility of
being configured as accelerator (like it was done in gcc/Makefile.in).
Otherwise offload compiler is unable to find its plugin.

Bootstrapped and regtested on i686-linux and x86_64-linux.
OK for trunk (after everything has been reviewed)?


2014-09-26  Bernd Schmidt  <bernds@codesourcery.com>
	    Thomas Schwinge  <thomas@codesourcery.com>
	    Ilya Verbin  <ilya.verbin@intel.com>
	    Andrey Turetskiy  <andrey.turetskiy@intel.com>

	* configure: Regenerate.
	* configure.ac (--enable-as-accelerator-for)
	(--enable-offload-targets): New configure options.
gcc/
	* Makefile.in (real_target_noncanonical, accel_dir_suffix)
	(enable_as_accelerator): New variables substituted by configure.
	(libsubdir, libexecsubdir, unlibsubdir): Tweak for the possibility of
	being configured as an offload compiler.
	(DRIVER_DEFINES): Pass new defines DEFAULT_REAL_TARGET_MACHINE and
	ACCEL_DIR_SUFFIX.
	(install-cpp, install-common, install_driver, install-gcc-ar): Do not
	install for the offload compiler.
	* config.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (real_target_noncanonical, accel_dir_suffix)
	(enable_as_accelerator, enable_offload_targets): Compute new variables.
	(--enable-as-accelerator-for, --enable-offload-targets): New options.
	(ACCEL_COMPILER): Define if the compiler is built as the accel compiler.
	(OFFLOAD_TARGETS): List of target names suitable for offloading.
	(ENABLE_OFFLOADING): Define if list of offload targets is not empty.
gcc/cp/
	* Make-lang.in (c++.install-common): Do not install for the offload
	compiler.
gcc/fortran/
	* Make-lang.in (fortran.install-common): Do not install for the offload
	compiler.
libgcc/
	* Makefile.in (crtompbegin$(objext), crtompend$(objext)): New rule.
	* configure: Regenerate.
	* configure.ac (--enable-as-accelerator-for)
	(--enable-offload-targets): New configure options.
	(extra_parts): Add crtompbegin.o and crtompend.o if
	enable_offload_targets is not empty.
	* ompstuff.c: New file.
libgomp/
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Check for libdl, required for plugin support.
	(PLUGIN_SUPPORT): Define if plugins are supported.
	(--enable-offload-targets): New configure option.
	(enable_offload_targets): Support Intel MIC targets.
	(OFFLOAD_TARGETS): List of target names suitable for offloading.
lto-plugin/
	* Makefile.am (libexecsubdir): Tweak for the possibility of being
	configured for offload compiler.
	(accel_dir_suffix): New variable substituted by configure.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (--enable-as-accelerator-for): New option.

Thanks,
  -- Ilya


---

diff --git a/configure b/configure
index 55fca62..956062a 100755
--- a/configure
+++ b/configure
@@ -747,6 +747,8 @@ ospace_frag'
 ac_user_opts='
 enable_option_checking
 with_build_libsubdir
+enable_as_accelerator_for
+enable_offload_targets
 enable_gold
 enable_ld
 enable_libquadmath
@@ -1466,6 +1468,13 @@ Optional Features:
   --disable-option-checking  ignore unrecognized --enable/--with options
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-as-accelerator-for=ARG
+                          build as offload target compiler. Specify offload
+                          host triple by ARG
+  --enable-offload-targets=LIST
+                          enable offloading to devices from comma-separated
+                          LIST of TARGET[=DIR]. Use optional path to find
+                          offload target compiler during the build
   --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
   --enable-ld[=ARG]       build ld [ARG={default,yes,no}]
   --disable-libquadmath   do not build libquadmath directory
@@ -2893,6 +2902,26 @@ case ${with_newlib} in
   yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
 esac
 
+# Check whether --enable-as-accelerator-for was given.
+if test "${enable_as_accelerator_for+set}" = set; then :
+  enableval=$enable_as_accelerator_for; ENABLE_AS_ACCELERATOR_FOR=$enableval
+else
+  ENABLE_AS_ACCELERATOR_FOR=no
+fi
+
+
+# Check whether --enable-offload-targets was given.
+if test "${enable_offload_targets+set}" = set; then :
+  enableval=$enable_offload_targets;
+  if test x"$enable_offload_targets" = x; then
+    as_fn_error "no offload targets specified" "$LINENO" 5
+  fi
+
+else
+  enable_offload_targets=
+fi
+
+
 # Handle --enable-gold, --enable-ld.
 # --disable-gold [--enable-ld]
 #     Build only ld.  Default option.
diff --git a/configure.ac b/configure.ac
index 2dc657f..d031452 100644
--- a/configure.ac
+++ b/configure.ac
@@ -286,6 +286,24 @@ case ${with_newlib} in
   yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
 esac
 
+AC_ARG_ENABLE(as-accelerator-for,
+[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
+		[build as offload target compiler.
+		Specify offload host triple by ARG])],
+ENABLE_AS_ACCELERATOR_FOR=$enableval,
+ENABLE_AS_ACCELERATOR_FOR=no)
+
+AC_ARG_ENABLE(offload-targets,
+[AS_HELP_STRING([--enable-offload-targets=LIST],
+		[enable offloading to devices from comma-separated LIST of
+		TARGET[=DIR]. Use optional path to find offload target compiler
+		during the build])],
+[
+  if test x"$enable_offload_targets" = x; then
+    AC_MSG_ERROR([no offload targets specified])
+  fi
+], [enable_offload_targets=])
+
 # Handle --enable-gold, --enable-ld.
 # --disable-gold [--enable-ld]
 #     Build only ld.  Default option.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 97b439a..36f2d0f 100644
--- a/gcc/Makefile.in
+++ b/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,10 @@ program_transform_name := @program_transform_name@
 # Directories used during build
 # -----------------------------
 
+# Normally identical to target_noncanonical, except for compilers built
+# as accelerator targets.
+accel_dir_suffix = @accel_dir_suffix@
+
 # Directory where sources are, from where we are.
 srcdir = @srcdir@
 gcc_docdir = @srcdir@/doc
@@ -356,6 +361,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
 
@@ -567,9 +574,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
@@ -577,7 +584,11 @@ plugin_includedir = $(plugin_resourcesdir)/include
 # Directory in which plugin specific executables are installed
 plugin_bindir = $(libexecsubdir)/plugin
 # Used to produce a relative $(gcc_tooldir) in gcc.o
+ifeq ($(enable_as_accelerator),yes)
+unlibsubdir = ../../../../..
+else
 unlibsubdir = ../../..
+endif
 # $(prefix), expressed as a path relative to $(libsubdir).
 #
 # An explanation of the sed strings:
@@ -1929,9 +1940,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)) \
@@ -3103,12 +3116,14 @@ install-strip: install
 
 # Handle cpp installation.
 install-cpp: installdirs cpp$(exeext)
-	-rm -f $(DESTDIR)$(bindir)/$(CPP_INSTALL_NAME)$(exeext)
-	-$(INSTALL_PROGRAM) -m 755 cpp$(exeext) $(DESTDIR)$(bindir)/$(CPP_INSTALL_NAME)$(exeext)
-	-if [ x$(cpp_install_dir) != x ]; then \
-	  rm -f $(DESTDIR)$(prefix)/$(cpp_install_dir)/$(CPP_INSTALL_NAME)$(exeext); \
-	  $(INSTALL_PROGRAM) -m 755 cpp$(exeext) $(DESTDIR)$(prefix)/$(cpp_install_dir)/$(CPP_INSTALL_NAME)$(exeext); \
-	else true; fi
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  rm -f $(DESTDIR)$(bindir)/$(CPP_INSTALL_NAME)$(exeext); \
+	  $(INSTALL_PROGRAM) -m 755 cpp$(exeext) $(DESTDIR)$(bindir)/$(CPP_INSTALL_NAME)$(exeext); \
+	  if [ x$(cpp_install_dir) != x ]; then \
+	    rm -f $(DESTDIR)$(prefix)/$(cpp_install_dir)/$(CPP_INSTALL_NAME)$(exeext); \
+	    $(INSTALL_PROGRAM) -m 755 cpp$(exeext) $(DESTDIR)$(prefix)/$(cpp_install_dir)/$(CPP_INSTALL_NAME)$(exeext); \
+	  else true; fi; \
+	fi
 
 # Create the installation directories.
 # $(libdir)/gcc/include isn't currently searched by cpp.
@@ -3216,17 +3231,21 @@ install-common: native lang.install-common installdirs
 # otherwise override the specs built into the driver.
 	rm -f $(DESTDIR)$(libsubdir)/specs
 # Install gcov if it was compiled.
-	-if [ -f gcov$(exeext) ]; \
-	then \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  if [ -f gcov$(exeext) ]; \
+	  then \
 	    rm -f $(DESTDIR)$(bindir)/$(GCOV_INSTALL_NAME)$(exeext); \
 	    $(INSTALL_PROGRAM) gcov$(exeext) $(DESTDIR)$(bindir)/$(GCOV_INSTALL_NAME)$(exeext); \
+	  fi; \
 	fi
 # Install gcov-tool if it was compiled.
-	-if [ -f gcov-tool$(exeext) ]; \
-	then \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  if [ -f gcov-tool$(exeext) ]; \
+	  then \
 	    rm -f $(DESTDIR)$(bindir)/$(GCOV_TOOL_INSTALL_NAME)$(exeext); \
 	    $(INSTALL_PROGRAM) \
 	    gcov-tool$(exeext) $(DESTDIR)$(bindir)/$(GCOV_TOOL_INSTALL_NAME)$(exeext); \
+	  fi; \
 	fi
 
 # Install the driver program as $(target_noncanonical)-gcc,
@@ -3234,17 +3253,19 @@ install-common: native lang.install-common installdirs
 install-driver: installdirs xgcc$(exeext)
 	-rm -f $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
 	-$(INSTALL_PROGRAM) xgcc$(exeext) $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
-	-if [ "$(GCC_INSTALL_NAME)" != "$(target_noncanonical)-gcc-$(version)" ]; then \
-	  rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-$(version)$(exeext); \
-	  ( cd $(DESTDIR)$(bindir) && \
-	    $(LN) $(GCC_INSTALL_NAME)$(exeext) $(target_noncanonical)-gcc-$(version)$(exeext) ); \
-	fi
-	-if [ ! -f gcc-cross$(exeext) ] \
-	    && [ "$(GCC_INSTALL_NAME)" != "$(GCC_TARGET_INSTALL_NAME)" ]; then \
-	  rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-tmp$(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) ); \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  if [ "$(GCC_INSTALL_NAME)" != "$(target_noncanonical)-gcc-$(version)" ]; then \
+	    rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-$(version)$(exeext); \
+	    ( cd $(DESTDIR)$(bindir) && \
+	      $(LN) $(GCC_INSTALL_NAME)$(exeext) $(target_noncanonical)-gcc-$(version)$(exeext) ); \
+	  fi; \
+	  if [ ! -f gcc-cross$(exeext) ] \
+	      && [ "$(GCC_INSTALL_NAME)" != "$(GCC_TARGET_INSTALL_NAME)" ]; then \
+	    rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-tmp$(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) ); \
+	  fi; \
 	fi
 
 # Install the info files.
@@ -3441,19 +3462,21 @@ install-lto-wrapper: lto-wrapper$(exeext)
 	$(INSTALL_PROGRAM) lto-wrapper$(exeext) $(DESTDIR)$(libexecsubdir)/lto-wrapper$(exeext)
 
 install-gcc-ar: installdirs gcc-ar$(exeext) gcc-nm$(exeext) gcc-ranlib$(exeext)
-	for i in gcc-ar gcc-nm gcc-ranlib; do \
-	  install_name=`echo $$i|sed '$(program_transform_name)'` ;\
-	  target_install_name=$(target_noncanonical)-`echo $$i|sed '$(program_transform_name)'` ; \
-	  rm -f $(DESTDIR)$(bindir)/$$install_name$(exeext) ; \
-	  $(INSTALL_PROGRAM) $$i$(exeext) $(DESTDIR)$(bindir)/$$install_name$(exeext) ;\
-	  if test -f gcc-cross$(exeext); then \
-	    :; \
-	  else \
-	    rm -f $(DESTDIR)$(bindir)/$$target_install_name$(exeext); \
-	    ( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $$install_name$(exeext) $$target_install_name$(exeext) ) ; \
-	  fi ; \
-	done
+	if test "$(enable_as_accelerator)" != "yes" ; then \
+	  for i in gcc-ar gcc-nm gcc-ranlib; do \
+	    install_name=`echo $$i|sed '$(program_transform_name)'` ;\
+	    target_install_name=$(target_noncanonical)-`echo $$i|sed '$(program_transform_name)'` ; \
+	    rm -f $(DESTDIR)$(bindir)/$$install_name$(exeext) ; \
+	    $(INSTALL_PROGRAM) $$i$(exeext) $(DESTDIR)$(bindir)/$$install_name$(exeext) ;\
+	    if test -f gcc-cross$(exeext); then \
+	      :; \
+	    else \
+	      rm -f $(DESTDIR)$(bindir)/$$target_install_name$(exeext); \
+	      ( cd $(DESTDIR)$(bindir) && \
+		$(LN) $$install_name$(exeext) $$target_install_name$(exeext) ) ; \
+	    fi ; \
+	  done; \
+	fi
 
 # Cancel installation by deleting the installed files.
 uninstall: lang.uninstall
diff --git a/gcc/config.in b/gcc/config.in
index 90809e3..bf07125 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1,5 +1,11 @@
 /* config.in.  Generated from configure.ac by autoheader.  */
 
+/* Define if this compiler should be built as the offload target compiler. */
+#ifndef USED_FOR_TARGET
+#undef ACCEL_COMPILER
+#endif
+
+
 /* Define if building universal (internal helper macro) */
 #ifndef USED_FOR_TARGET
 #undef AC_APPLE_UNIVERSAL_BUILD
@@ -144,6 +150,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
@@ -1699,16 +1711,19 @@
 #undef HAVE_WORKING_VFORK
 #endif
 
-/* Define if isl is in use. */
-#ifndef USED_FOR_TARGET
-#undef HAVE_isl
-#endif
 
 /* Define if cloog is in use. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_cloog
 #endif
 
+
+/* Define if isl is in use. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_isl
+#endif
+
+
 /* Define if F_SETLKW supported by fcntl. */
 #ifndef USED_FOR_TARGET
 #undef HOST_HAS_F_SETLKW
@@ -1783,6 +1798,12 @@
 #endif
 
 
+/* Define to hold the list of target names suitable for offloading. */
+#ifndef USED_FOR_TARGET
+#undef OFFLOAD_TARGETS
+#endif
+
+
 /* Define to the address where bug reports for this package should be sent. */
 #ifndef USED_FOR_TARGET
 #undef PACKAGE_BUGREPORT
diff --git a/gcc/configure b/gcc/configure
index 380a235..b02df3f 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -610,6 +610,8 @@ ISLINC
 ISLLIBS
 GMPINC
 GMPLIBS
+accel_dir_suffix
+real_target_noncanonical
 target_cpu_default
 fortran_target_objs
 cxx_target_objs
@@ -761,6 +763,7 @@ LN
 LN_S
 AWK
 SET_MAKE
+enable_as_accelerator
 REPORT_BUGS_TEXI
 REPORT_BUGS_TO
 PKGVERSION
@@ -901,6 +904,8 @@ with_specs
 with_pkgversion
 with_bugurl
 enable_languages
+enable_as_accelerator_for
+enable_offload_targets
 with_multilib_list
 enable_rpath
 with_libiconv_prefix
@@ -1610,6 +1615,13 @@ Optional Features:
                           GNU Objective-C runtime
   --disable-shared        don't provide a shared libgcc
   --enable-languages=LIST specify which front-ends to build
+  --enable-as-accelerator-for=ARG
+                          build as offload target compiler. Specify offload
+                          host triple by ARG
+  --enable-offload-targets=LIST
+                          enable offloading to devices from comma-separated
+                          LIST of TARGET[=DIR]. Use optional path to find
+                          offload target compiler during the build
   --disable-rpath         do not hardcode runtime library paths
   --enable-sjlj-exceptions
                           arrange to use setjmp/longjmp exception handling
@@ -3194,6 +3206,10 @@ esac
 
 
 
+# Used for constructing correct paths for offload compilers.
+real_target_noncanonical=${target_noncanonical}
+accel_dir_suffix=
+
 # Determine the target- and build-specific subdirectories
 
 # post-stage1 host modules use a different CC_FOR_BUILD so, in order to
@@ -7391,6 +7407,61 @@ else
 fi
 
 
+# Check whether --enable-as-accelerator-for was given.
+if test "${enable_as_accelerator_for+set}" = set; then :
+  enableval=$enable_as_accelerator_for;
+
+$as_echo "#define ACCEL_COMPILER 1" >>confdefs.h
+
+  enable_as_accelerator=yes
+  case "${target}" in
+    *-intelmicemul-*)
+      # In this case we expect offload compiler to be built as native, so we
+      # need to rename the driver to avoid clashes with host's drivers.
+      program_transform_name="s&^&${target}-&" ;;
+  esac
+  sedscript="s#${target_noncanonical}#${enable_as_accelerator_for}-accel-${target_noncanonical}#"
+  program_transform_name=`echo $program_transform_name | sed $sedscript`
+  accel_dir_suffix=/accel/${target_noncanonical}
+  real_target_noncanonical=${enable_as_accelerator_for}
+
+else
+  enable_as_accelerator=no
+fi
+
+
+
+# Check whether --enable-offload-targets was given.
+if test "${enable_offload_targets+set}" = set; then :
+  enableval=$enable_offload_targets;
+  if test x"$enable_offload_targets" = x; then
+    as_fn_error "no offload targets specified" "$LINENO" 5
+  fi
+
+else
+  enable_offload_targets=
+fi
+
+offload_targets=
+for tgt in `echo $enable_offload_targets | sed 's/,/ /g'`; do
+  tgt=`echo $tgt | sed 's/=.*//'`
+  if test x"$offload_targets" = x; then
+    offload_targets=$tgt
+  else
+    offload_targets="$offload_targets:$tgt"
+  fi
+done
+
+cat >>confdefs.h <<_ACEOF
+#define OFFLOAD_TARGETS "$offload_targets"
+_ACEOF
+
+if test x"$offload_targets" != x; then
+
+$as_echo "#define ENABLE_OFFLOADING 1" >>confdefs.h
+
+fi
+
 
 # Check whether --with-multilib-list was given.
 if test "${with_multilib_list+set}" = set; then :
@@ -18049,7 +18120,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18052 "configure"
+#line 18123 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18155,7 +18226,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18158 "configure"
+#line 18229 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -27864,6 +27935,8 @@ fi
 
 
 
+
+
 # Echo link setup.
 if test x${build} = x${host} ; then
   if test x${host} = x${target} ; then
diff --git a/gcc/configure.ac b/gcc/configure.ac
index eb480de..b8eba3b 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -38,6 +38,10 @@ 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}
+accel_dir_suffix=
+
 # Determine the target- and build-specific subdirectories
 GCC_TOPLEV_SUBDIRS
 
@@ -883,6 +887,53 @@ AC_ARG_ENABLE(languages,
 esac],
 [enable_languages=c])
 
+AC_ARG_ENABLE(as-accelerator-for,
+[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
+		[build as offload target compiler.
+		Specify offload host triple by ARG])],
+[
+  AC_DEFINE(ACCEL_COMPILER, 1,
+    [Define if this compiler should be built as the offload target compiler.])
+  enable_as_accelerator=yes
+  case "${target}" in
+    *-intelmicemul-*)
+      # In this case we expect offload compiler to be built as native, so we
+      # need to rename the driver to avoid clashes with host's drivers.
+      program_transform_name="s&^&${target}-&" ;;
+  esac
+  sedscript="s#${target_noncanonical}#${enable_as_accelerator_for}-accel-${target_noncanonical}#"
+  program_transform_name=`echo $program_transform_name | sed $sedscript`
+  accel_dir_suffix=/accel/${target_noncanonical}
+  real_target_noncanonical=${enable_as_accelerator_for}
+], [enable_as_accelerator=no])
+AC_SUBST(enable_as_accelerator)
+
+AC_ARG_ENABLE(offload-targets,
+[AS_HELP_STRING([--enable-offload-targets=LIST],
+		[enable offloading to devices from comma-separated LIST of
+		TARGET[=DIR]. Use optional path to find offload target compiler
+		during the build])],
+[
+  if test x"$enable_offload_targets" = x; then
+    AC_MSG_ERROR([no offload targets specified])
+  fi
+], [enable_offload_targets=])
+offload_targets=
+for tgt in `echo $enable_offload_targets | sed 's/,/ /g'`; do
+  tgt=`echo $tgt | sed 's/=.*//'`
+  if test x"$offload_targets" = x; then
+    offload_targets=$tgt
+  else
+    offload_targets="$offload_targets:$tgt"
+  fi
+done
+AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$offload_targets",
+  [Define to hold the list of target names suitable for offloading.])
+if test x"$offload_targets" != x; then
+  AC_DEFINE(ENABLE_OFFLOADING, 1,
+    [Define this to enable support for offloading.])
+fi
+
 AC_ARG_WITH(multilib-list,
 [AS_HELP_STRING([--with-multilib-list], [select multilibs (AArch64, SH and x86-64 only)])],
 :,
@@ -5488,6 +5539,8 @@ AC_SUBST(c_target_objs)
 AC_SUBST(cxx_target_objs)
 AC_SUBST(fortran_target_objs)
 AC_SUBST(target_cpu_default)
+AC_SUBST(real_target_noncanonical)
+AC_SUBST(accel_dir_suffix)
 
 AC_SUBST_FILE(language_hooks)
 
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 36f9583..d6fbdce 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -164,21 +164,23 @@ check_g++_parallelize = 10000
 # Install the driver program as $(target)-g++ and $(target)-c++, and
 # also as g++ and c++ if native.
 c++.install-common: installdirs
-	-rm -f $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
-	-$(INSTALL_PROGRAM) xg++$(exeext) $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
-	-chmod a+x $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
-	-rm -f $(DESTDIR)$(bindir)/$(CXX_INSTALL_NAME)$(exeext)
-	-( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $(GXX_INSTALL_NAME)$(exeext) $(CXX_INSTALL_NAME)$(exeext) )
-	-if [ -f cc1plus$(exeext) ] ; then \
-	  if [ ! -f g++-cross$(exeext) ] ; then \
-	    rm -f $(DESTDIR)$(bindir)/$(GXX_TARGET_INSTALL_NAME)$(exeext); \
-	    ( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $(GXX_INSTALL_NAME)$(exeext) $(GXX_TARGET_INSTALL_NAME)$(exeext) ); \
-	    rm -f $(DESTDIR)$(bindir)/$(CXX_TARGET_INSTALL_NAME)$(exeext); \
-	    ( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $(CXX_INSTALL_NAME)$(exeext) $(CXX_TARGET_INSTALL_NAME)$(exeext) ); \
-	  fi ; \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  rm -f $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext); \
+	  $(INSTALL_PROGRAM) xg++$(exeext) $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext); \
+	  chmod a+x $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext); \
+	  rm -f $(DESTDIR)$(bindir)/$(CXX_INSTALL_NAME)$(exeext); \
+	  ( cd $(DESTDIR)$(bindir) && \
+	    $(LN) $(GXX_INSTALL_NAME)$(exeext) $(CXX_INSTALL_NAME)$(exeext) ); \
+	  if [ -f cc1plus$(exeext) ] ; then \
+	    if [ ! -f g++-cross$(exeext) ] ; then \
+	      rm -f $(DESTDIR)$(bindir)/$(GXX_TARGET_INSTALL_NAME)$(exeext); \
+	      ( cd $(DESTDIR)$(bindir) && \
+		$(LN) $(GXX_INSTALL_NAME)$(exeext) $(GXX_TARGET_INSTALL_NAME)$(exeext) ); \
+	      rm -f $(DESTDIR)$(bindir)/$(CXX_TARGET_INSTALL_NAME)$(exeext); \
+	      ( cd $(DESTDIR)$(bindir) && \
+		$(LN) $(CXX_INSTALL_NAME)$(exeext) $(CXX_TARGET_INSTALL_NAME)$(exeext) ); \
+	    fi ; \
+	  fi; \
 	fi
 
 # We can't use links because not everyone supports them.  So just copy the
diff --git a/gcc/fortran/Make-lang.in b/gcc/fortran/Make-lang.in
index ca0a4e6..3621b4f 100644
--- a/gcc/fortran/Make-lang.in
+++ b/gcc/fortran/Make-lang.in
@@ -235,14 +235,16 @@ install-finclude-dir: installdirs
 # Install the driver program as $(target)-gfortran, and also as gfortran
 # if native.
 fortran.install-common: install-finclude-dir installdirs
-	-if [ -f f951$(exeext) ] ; then \
-	  rm -f $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
-	  $(INSTALL_PROGRAM) gfortran$(exeext) $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
-	  chmod a+x $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
-	  if [ ! -f gfortran-cross$(exeext) ] ; then \
-	    rm -f $(DESTDIR)$(bindir)/$(GFORTRAN_TARGET_INSTALL_NAME)$(exeext); \
-	    $(LN) $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext) $(DESTDIR)$(bindir)/$(GFORTRAN_TARGET_INSTALL_NAME)$(exeext); \
-	  fi ; \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  if [ -f f951$(exeext) ] ; then \
+	    rm -f $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
+	    $(INSTALL_PROGRAM) gfortran$(exeext) $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
+	    chmod a+x $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
+	    if [ ! -f gfortran-cross$(exeext) ] ; then \
+	      rm -f $(DESTDIR)$(bindir)/$(GFORTRAN_TARGET_INSTALL_NAME)$(exeext); \
+	      $(LN) $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext) $(DESTDIR)$(bindir)/$(GFORTRAN_TARGET_INSTALL_NAME)$(exeext); \
+	    fi ; \
+	  fi; \
 	fi
 
 fortran.install-plugin:
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index 0d2c0b4..be8300d 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -184,7 +184,7 @@ STRIP = @STRIP@
 STRIP_FOR_TARGET = $(STRIP)
 
 # Directory in which the compiler finds libraries etc.
-libsubdir = $(libdir)/gcc/$(host_noncanonical)/$(version)
+libsubdir = $(libdir)/gcc/$(host_noncanonical)/$(version)@accel_dir_suffix@
 # Used to install the shared libgcc.
 slibdir = @slibdir@
 # Maybe used for DLLs on Windows targets.
@@ -990,6 +990,14 @@ crtendS$(objext): $(srcdir)/crtstuff.c
 crtbeginT$(objext): $(srcdir)/crtstuff.c
 	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN -DCRTSTUFFT_O
 
+# crtompbegin and crtompend contain symbols, that mark the begin and the end of
+# tables with addresses, required for OpenMP offloading.
+crtompbegin$(objext): $(srcdir)/ompstuff.c
+	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN
+
+crtompend$(objext): $(srcdir)/ompstuff.c
+	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END
+
 ifeq ($(enable_vtable_verify),yes)
 # These are used in vtable verification; see comments in source files for
 # more details.
diff --git a/libgcc/configure b/libgcc/configure
index 19c4ed6..f09c2a9 100644
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -566,6 +566,7 @@ sfp_machine_header
 set_use_emutls
 set_have_cc_tls
 vis_hide
+accel_dir_suffix
 force_explicit_eh_registry
 fixed_point
 enable_decimal_float
@@ -666,6 +667,8 @@ enable_decimal_float
 with_system_libunwind
 enable_sjlj_exceptions
 enable_explicit_exception_frame_registration
+enable_as_accelerator_for
+enable_offload_targets
 enable_tls
 '
       ac_precious_vars='build_alias
@@ -1307,6 +1310,13 @@ Optional Features:
                           register exception tables explicitly at module
                           start, for use e.g. for compatibility with
                           installations without PT_GNU_EH_FRAME support
+  --enable-as-accelerator-for=ARG
+                          build as offload target compiler. Specify offload
+                          host triple by ARG
+  --enable-offload-targets=LIST
+                          enable offloading to devices from comma-separated
+                          LIST of TARGET[=DIR]. Use optional path to find
+                          offload target compiler during the build
   --enable-tls            Use thread-local storage [default=yes]
 
 Optional Packages:
@@ -4379,6 +4389,38 @@ esac
 # Collect host-machine-specific information.
 . ${srcdir}/config.host
 
+# Used for constructing correct paths for offload compilers.
+accel_dir_suffix=
+# Check whether --enable-as-accelerator-for was given.
+if test "${enable_as_accelerator_for+set}" = set; then :
+  enableval=$enable_as_accelerator_for;
+  accel_dir_suffix=/accel/${target_noncanonical}
+  case "${target_noncanonical}" in
+    *-intelmicemul-*)
+      # In this case we expect offload compiler to be built as native, so we
+      # need to change install directory for driver to be able to find libgcc.
+      host_noncanonical=${enable_as_accelerator_for} ;;
+  esac
+
+fi
+
+
+
+# Check whether --enable-offload-targets was given.
+if test "${enable_offload_targets+set}" = set; then :
+  enableval=$enable_offload_targets;
+  if test x"$enable_offload_targets" = x; then
+    as_fn_error "no offload targets specified" "$LINENO" 5
+  fi
+
+else
+  enable_offload_targets=
+fi
+
+if test x"$enable_offload_targets" != x; then
+  extra_parts="${extra_parts} crtompbegin.o crtompend.o"
+fi
+
 # Check if Solaris/x86 linker supports ZERO terminator unwind entries.
 # This is after config.host so we can augment tmake_file.
 # Link with -nostartfiles -nodefaultlibs since neither are present while
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 72a21a9..6cce5d5 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -323,6 +323,37 @@ esac
 # Collect host-machine-specific information.
 . ${srcdir}/config.host
 
+# Used for constructing correct paths for offload compilers.
+accel_dir_suffix=
+AC_ARG_ENABLE(as-accelerator-for,
+[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
+		[build as offload target compiler.
+		Specify offload host triple by ARG])],
+[
+  accel_dir_suffix=/accel/${target_noncanonical}
+  case "${target_noncanonical}" in
+    *-intelmicemul-*)
+      # In this case we expect offload compiler to be built as native, so we
+      # need to change install directory for driver to be able to find libgcc.
+      host_noncanonical=${enable_as_accelerator_for} ;;
+  esac
+])
+AC_SUBST(accel_dir_suffix)
+
+AC_ARG_ENABLE(offload-targets,
+[AS_HELP_STRING([--enable-offload-targets=LIST],
+		[enable offloading to devices from comma-separated LIST of
+		TARGET[=DIR]. Use optional path to find offload target compiler
+		during the build])],
+[
+  if test x"$enable_offload_targets" = x; then
+    AC_MSG_ERROR([no offload targets specified])
+  fi
+], [enable_offload_targets=])
+if test x"$enable_offload_targets" != x; then
+  extra_parts="${extra_parts} crtompbegin.o crtompend.o"
+fi
+
 # Check if Solaris/x86 linker supports ZERO terminator unwind entries.
 # This is after config.host so we can augment tmake_file.
 # Link with -nostartfiles -nodefaultlibs since neither are present while
diff --git a/libgcc/ompstuff.c b/libgcc/ompstuff.c
new file mode 100644
index 0000000..96bdf5f
--- /dev/null
+++ b/libgcc/ompstuff.c
@@ -0,0 +1,80 @@
+/* Specialized bits of code needed for the OpenMP offloading tables.
+   Copyright (C) 2014 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.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Target machine header files require this define. */
+#define IN_LIBGCC2
+
+/* FIXME: Including auto-host is incorrect, but until we have
+   identified the set of defines that need to go into auto-target.h,
+   this will have to do.  */
+#include "auto-host.h"
+#undef caddr_t
+#undef pid_t
+#undef rlim_t
+#undef ssize_t
+#undef vfork
+#include "tconfig.h"
+#include "tsystem.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "libgcc_tm.h"
+
+#define OFFLOAD_FUNC_TABLE_SECTION_NAME "__gnu_offload_funcs"
+#define OFFLOAD_VAR_TABLE_SECTION_NAME "__gnu_offload_vars"
+
+#ifdef CRT_BEGIN
+
+#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
+void *_omp_func_table[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
+void *_omp_var_table[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };
+#endif
+
+#elif defined CRT_END
+
+#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
+void *_omp_funcs_end[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
+void *_omp_vars_end[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };
+
+extern void *_omp_func_table[];
+extern void *_omp_var_table[];
+
+void *__OPENMP_TARGET__[]
+  __attribute__ ((__visibility__ ("hidden"))) =
+{
+  &_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
diff --git a/libgomp/config.h.in b/libgomp/config.h.in
index 14c7e2a..94a2b3b 100644
--- a/libgomp/config.h.in
+++ b/libgomp/config.h.in
@@ -30,6 +30,9 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
+/* Define to 1 if you have the `dl' library (-ldl). */
+#undef HAVE_LIBDL
+
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
@@ -86,6 +89,9 @@
    */
 #undef LT_OBJDIR
 
+/* Define to hold the list of target names suitable for offloading. */
+#undef OFFLOAD_TARGETS
+
 /* Name of package */
 #undef PACKAGE
 
@@ -107,6 +113,9 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
+/* Define if all infrastructure, needed for plugins, is supported. */
+#undef PLUGIN_SUPPORT
+
 /* The size of `char', as computed by sizeof. */
 #undef SIZEOF_CHAR
 
diff --git a/libgomp/configure b/libgomp/configure
index 766eb09..60d1492 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -770,6 +770,7 @@ enable_maintainer_mode
 enable_linux_futex
 enable_tls
 enable_symvers
+enable_offload_targets
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1421,6 +1422,10 @@ Optional Features:
   --enable-tls            Use thread-local storage [default=yes]
   --enable-symvers=STYLE  enables symbol versioning of the shared library
                           [default=yes]
+  --enable-offload-targets=LIST
+                          enable offloading to devices from comma-separated
+                          LIST of TARGET[=DIR]. Use optional path to find
+                          offload target compiler during the build
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -11094,7 +11099,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11097 "configure"
+#line 11102 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11200,7 +11205,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11203 "configure"
+#line 11208 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15052,6 +15057,60 @@ fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
 
+plugin_support=yes
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlsym in -ldl" >&5
+$as_echo_n "checking for dlsym in -ldl... " >&6; }
+if test "${ac_cv_lib_dl_dlsym+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlsym ();
+int
+main ()
+{
+return dlsym ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlsym=yes
+else
+  ac_cv_lib_dl_dlsym=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlsym" >&5
+$as_echo "$ac_cv_lib_dl_dlsym" >&6; }
+if test "x$ac_cv_lib_dl_dlsym" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBDL 1
+_ACEOF
+
+  LIBS="-ldl $LIBS"
+
+else
+  plugin_support=no
+fi
+
+if test x"$plugin_support" = xyes; then
+
+$as_echo "#define PLUGIN_SUPPORT 1" >>confdefs.h
+
+fi
+
 # Check for functions needed.
 for ac_func in getloadavg clock_gettime strtoull
 do :
@@ -16153,6 +16212,37 @@ else
   multilib_arg=
 fi
 
+offload_targets=
+# Check whether --enable-offload-targets was given.
+if test "${enable_offload_targets+set}" = set; then :
+  enableval=$enable_offload_targets;
+  if test x"$enable_offload_targets" = x; then
+    as_fn_error "no offload targets specified" "$LINENO" 5
+  else
+    for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+      tgt=`echo $tgt | sed 's/=.*//'`
+      case $tgt in
+	*-intelmic-* | *-intelmicemul-*)
+	  tgt_name="intelmic" ;;
+	*)
+	  as_fn_error "unknown offload target specified" "$LINENO" 5 ;;
+      esac
+      if test x"$offload_targets" = x; then
+	offload_targets=$tgt_name
+      else
+	offload_targets=$offload_targets,$tgt_name
+      fi
+    done
+  fi
+
+fi
+
+
+cat >>confdefs.h <<_ACEOF
+#define OFFLOAD_TARGETS "$offload_targets"
+_ACEOF
+
+
 # Set up the set of libraries that we need to link against for libgomp.
 # Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
 # which will force linkage against -lpthread (or equivalent for the system).
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index 84d250f..da2c040 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -193,6 +193,13 @@ AC_LINK_IFELSE(
    [],
    [AC_MSG_ERROR([Pthreads are required to build libgomp])])])
 
+plugin_support=yes
+AC_CHECK_LIB(dl, dlsym, , [plugin_support=no])
+if test x"$plugin_support" = xyes; then
+  AC_DEFINE(PLUGIN_SUPPORT, 1,
+    [Define if all infrastructure, needed for plugins, is supported.])
+fi
+
 # Check for functions needed.
 AC_CHECK_FUNCS(getloadavg clock_gettime strtoull)
 
@@ -273,6 +280,35 @@ else
   multilib_arg=
 fi
 
+offload_targets=
+AC_ARG_ENABLE(offload-targets,
+[AS_HELP_STRING([--enable-offload-targets=LIST],
+		[enable offloading to devices from comma-separated LIST of
+		TARGET[=DIR]. Use optional path to find offload target compiler
+		during the build])],
+[
+  if test x"$enable_offload_targets" = x; then
+    AC_MSG_ERROR([no offload targets specified])
+  else
+    for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+      tgt=`echo $tgt | sed 's/=.*//'`
+      case $tgt in
+	*-intelmic-* | *-intelmicemul-*)
+	  tgt_name="intelmic" ;;
+	*)
+	  AC_MSG_ERROR([unknown offload target specified]) ;;
+      esac
+      if test x"$offload_targets" = x; then
+	offload_targets=$tgt_name
+      else
+	offload_targets=$offload_targets,$tgt_name
+      fi
+    done
+  fi
+])
+AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$offload_targets",
+  [Define to hold the list of target names suitable for offloading.])
+
 # Set up the set of libraries that we need to link against for libgomp.
 # Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
 # which will force linkage against -lpthread (or equivalent for the system).
diff --git a/lto-plugin/Makefile.am b/lto-plugin/Makefile.am
index 93ea649..c637ecb 100644
--- a/lto-plugin/Makefile.am
+++ b/lto-plugin/Makefile.am
@@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS = no-dependencies
 
 gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
 target_noncanonical := @target_noncanonical@
-libexecsubdir := $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
+libexecsubdir := $(libexecdir)/gcc/$(real_target_noncanonical)/$(gcc_version)$(accel_dir_suffix)
 
 AM_CPPFLAGS = -I$(top_srcdir)/../include $(DEFS)
 AM_CFLAGS = @ac_lto_plugin_warn_cflags@
diff --git a/lto-plugin/Makefile.in b/lto-plugin/Makefile.in
index b15d901..4bd943b 100644
--- a/lto-plugin/Makefile.in
+++ b/lto-plugin/Makefile.in
@@ -167,6 +167,7 @@ ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 ac_lto_plugin_ldflags = @ac_lto_plugin_ldflags@
 ac_lto_plugin_warn_cflags = @ac_lto_plugin_warn_cflags@
+accel_dir_suffix = @accel_dir_suffix@
 am__include = @am__include@
 am__leading_dot = @am__leading_dot@
 am__quote = @am__quote@
@@ -209,6 +210,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+real_target_noncanonical = @real_target_noncanonical@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -227,7 +229,7 @@ with_libiberty = @with_libiberty@
 ACLOCAL_AMFLAGS = -I .. -I ../config
 AUTOMAKE_OPTIONS = no-dependencies
 gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
-libexecsubdir := $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
+libexecsubdir := $(libexecdir)/gcc/$(real_target_noncanonical)/$(gcc_version)$(accel_dir_suffix)
 AM_CPPFLAGS = -I$(top_srcdir)/../include $(DEFS)
 AM_CFLAGS = @ac_lto_plugin_warn_cflags@
 AM_LDFLAGS = @ac_lto_plugin_ldflags@
diff --git a/lto-plugin/configure b/lto-plugin/configure
index c34e653..0a81817 100755
--- a/lto-plugin/configure
+++ b/lto-plugin/configure
@@ -622,6 +622,8 @@ EGREP
 GREP
 SED
 LIBTOOL
+real_target_noncanonical
+accel_dir_suffix
 gcc_build_dir
 ac_lto_plugin_ldflags
 ac_lto_plugin_warn_cflags
@@ -730,6 +732,7 @@ enable_maintainer_mode
 with_libiberty
 enable_dependency_tracking
 enable_largefile
+enable_as_accelerator_for
 enable_shared
 enable_static
 with_pic
@@ -1371,6 +1374,9 @@ Optional Features:
   --disable-dependency-tracking  speeds up one-time build
   --enable-dependency-tracking   do not reject slow dependency extractors
   --disable-largefile     omit support for large files
+  --enable-as-accelerator-for=ARG
+                          build as offload target compiler. Specify offload
+                          host triple by ARG.
   --enable-shared[=PKGS]  build shared libraries [default=yes]
   --enable-static[=PKGS]  build static libraries [default=yes]
   --enable-fast-install[=PKGS]
@@ -4135,6 +4141,20 @@ else
 fi
 
 
+# Used for constructing correct paths for offload compilers.
+accel_dir_suffix=
+real_target_noncanonical=${target_noncanonical}
+# Check whether --enable-as-accelerator-for was given.
+if test "${enable_as_accelerator_for+set}" = set; then :
+  enableval=$enable_as_accelerator_for;
+    accel_dir_suffix=/accel/${target_noncanonical}
+    real_target_noncanonical=${enable_as_accelerator_for}
+
+fi
+
+
+
+
 case `pwd` in
   *\ * | *\	*)
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
@@ -10607,7 +10627,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10610 "configure"
+#line 10630 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -10713,7 +10733,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10716 "configure"
+#line 10736 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac
index c3ae93e..807e941 100644
--- a/lto-plugin/configure.ac
+++ b/lto-plugin/configure.ac
@@ -34,6 +34,20 @@ else
 fi
 AC_SUBST(gcc_build_dir)
 
+# Used for constructing correct paths for offload compilers.
+accel_dir_suffix=
+real_target_noncanonical=${target_noncanonical}
+AC_ARG_ENABLE(as-accelerator-for,
+  [AS_HELP_STRING([--enable-as-accelerator-for=ARG],
+		  [build as offload target compiler.
+		  Specify offload host triple by ARG.])],
+  [
+    accel_dir_suffix=/accel/${target_noncanonical}
+    real_target_noncanonical=${enable_as_accelerator_for}
+  ])
+AC_SUBST(accel_dir_suffix)
+AC_SUBST(real_target_noncanonical)
+
 AM_PROG_LIBTOOL
 ACX_LT_HOST_FLAGS
 AC_SUBST(target_noncanonical)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-09-26 12:36   ` Ilya Verbin
@ 2014-09-26 22:03     ` Joseph S. Myers
  2014-09-30 10:11     ` Jakub Jelinek
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 21+ messages in thread
From: Joseph S. Myers @ 2014-09-26 22:03 UTC (permalink / raw)
  To: Ilya Verbin
  Cc: Jakub Jelinek, Richard Biener, Richard Henderson, gcc-patches,
	Bernd Schmidt, Thomas Schwinge, Andrey Turetskiy, Kirill Yukhin

On Fri, 26 Sep 2014, Ilya Verbin wrote:

> 2014-09-26  Bernd Schmidt  <bernds@codesourcery.com>
> 	    Thomas Schwinge  <thomas@codesourcery.com>
> 	    Ilya Verbin  <ilya.verbin@intel.com>
> 	    Andrey Turetskiy  <andrey.turetskiy@intel.com>
> 
> 	* configure: Regenerate.
> 	* configure.ac (--enable-as-accelerator-for)
> 	(--enable-offload-targets): New configure options.
> gcc/
> 	* Makefile.in (real_target_noncanonical, accel_dir_suffix)
> 	(enable_as_accelerator): New variables substituted by configure.
> 	(libsubdir, libexecsubdir, unlibsubdir): Tweak for the possibility of
> 	being configured as an offload compiler.
> 	(DRIVER_DEFINES): Pass new defines DEFAULT_REAL_TARGET_MACHINE and
> 	ACCEL_DIR_SUFFIX.
> 	(install-cpp, install-common, install_driver, install-gcc-ar): Do not
> 	install for the offload compiler.
> 	* config.in: Regenerate.
> 	* configure: Regenerate.
> 	* configure.ac (real_target_noncanonical, accel_dir_suffix)
> 	(enable_as_accelerator, enable_offload_targets): Compute new variables.
> 	(--enable-as-accelerator-for, --enable-offload-targets): New options.
> 	(ACCEL_COMPILER): Define if the compiler is built as the accel compiler.
> 	(OFFLOAD_TARGETS): List of target names suitable for offloading.
> 	(ENABLE_OFFLOADING): Define if list of offload targets is not empty.

Any patch adding new configure options needs to add documentation of the 
semantics of those options in install.texi.  I see no such documentation 
in this patch.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-09-26 12:36   ` Ilya Verbin
  2014-09-26 22:03     ` Joseph S. Myers
@ 2014-09-30 10:11     ` Jakub Jelinek
  2014-09-30 11:16     ` Thomas Schwinge
  2015-02-19 11:43     ` Thomas Schwinge
  3 siblings, 0 replies; 21+ messages in thread
From: Jakub Jelinek @ 2014-09-30 10:11 UTC (permalink / raw)
  To: Ilya Verbin
  Cc: Richard Biener, Richard Henderson, gcc-patches, Bernd Schmidt,
	Thomas Schwinge, Andrey Turetskiy, Kirill Yukhin

On Fri, Sep 26, 2014 at 04:36:21PM +0400, Ilya Verbin wrote:
> 2014-09-26  Bernd Schmidt  <bernds@codesourcery.com>
> 	    Thomas Schwinge  <thomas@codesourcery.com>
> 	    Ilya Verbin  <ilya.verbin@intel.com>
> 	    Andrey Turetskiy  <andrey.turetskiy@intel.com>
> 
> 	* configure: Regenerate.
> 	* configure.ac (--enable-as-accelerator-for)
> 	(--enable-offload-targets): New configure options.
> gcc/
> 	* Makefile.in (real_target_noncanonical, accel_dir_suffix)
> 	(enable_as_accelerator): New variables substituted by configure.
> 	(libsubdir, libexecsubdir, unlibsubdir): Tweak for the possibility of
> 	being configured as an offload compiler.
> 	(DRIVER_DEFINES): Pass new defines DEFAULT_REAL_TARGET_MACHINE and
> 	ACCEL_DIR_SUFFIX.
> 	(install-cpp, install-common, install_driver, install-gcc-ar): Do not
> 	install for the offload compiler.
> 	* config.in: Regenerate.
> 	* configure: Regenerate.
> 	* configure.ac (real_target_noncanonical, accel_dir_suffix)
> 	(enable_as_accelerator, enable_offload_targets): Compute new variables.
> 	(--enable-as-accelerator-for, --enable-offload-targets): New options.
> 	(ACCEL_COMPILER): Define if the compiler is built as the accel compiler.
> 	(OFFLOAD_TARGETS): List of target names suitable for offloading.
> 	(ENABLE_OFFLOADING): Define if list of offload targets is not empty.
> gcc/cp/
> 	* Make-lang.in (c++.install-common): Do not install for the offload
> 	compiler.
> gcc/fortran/
> 	* Make-lang.in (fortran.install-common): Do not install for the offload
> 	compiler.
> libgcc/
> 	* Makefile.in (crtompbegin$(objext), crtompend$(objext)): New rule.
> 	* configure: Regenerate.
> 	* configure.ac (--enable-as-accelerator-for)
> 	(--enable-offload-targets): New configure options.
> 	(extra_parts): Add crtompbegin.o and crtompend.o if
> 	enable_offload_targets is not empty.
> 	* ompstuff.c: New file.
> libgomp/
> 	* config.h.in: Regenerate.
> 	* configure: Regenerate.
> 	* configure.ac: Check for libdl, required for plugin support.
> 	(PLUGIN_SUPPORT): Define if plugins are supported.
> 	(--enable-offload-targets): New configure option.
> 	(enable_offload_targets): Support Intel MIC targets.
> 	(OFFLOAD_TARGETS): List of target names suitable for offloading.
> lto-plugin/
> 	* Makefile.am (libexecsubdir): Tweak for the possibility of being
> 	configured for offload compiler.
> 	(accel_dir_suffix): New variable substituted by configure.
> 	* Makefile.in: Regenerate.
> 	* configure: Regenerate.
> 	* configure.ac (--enable-as-accelerator-for): New option.

If you add the documentation Joseph requested, looks good to me
(once the rest is reviewed too).

	Jakub

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-09-26 12:36   ` Ilya Verbin
  2014-09-26 22:03     ` Joseph S. Myers
  2014-09-30 10:11     ` Jakub Jelinek
@ 2014-09-30 11:16     ` Thomas Schwinge
  2014-10-01 16:06       ` Ilya Verbin
  2014-12-12  8:14       ` Thomas Schwinge
  2015-02-19 11:43     ` Thomas Schwinge
  3 siblings, 2 replies; 21+ messages in thread
From: Thomas Schwinge @ 2014-09-30 11:16 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek
  Cc: Richard Biener, Richard Henderson, gcc-patches, Bernd Schmidt,
	Andrey Turetskiy, Kirill Yukhin

[-- Attachment #1: Type: text/plain, Size: 6555 bytes --]

Hi!

On Fri, 26 Sep 2014 16:36:21 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> --- a/gcc/Makefile.in
> +++ b/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,10 @@ program_transform_name := @program_transform_name@
>  # Directories used during build
>  # -----------------------------
>  
> +# Normally identical to target_noncanonical, except for compilers built
> +# as accelerator targets.
> +accel_dir_suffix = @accel_dir_suffix@

Doesn't that comment belong to real_target_noncanonical just above?  By
default, accel_dir_suffix is empty.  Probably also move accel_dir_suffix
above to where real_target_noncanonical is being set?


> --- a/configure.ac
> +++ b/configure.ac
> @@ -286,6 +286,24 @@ case ${with_newlib} in
>    yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
>  esac
>  
> +AC_ARG_ENABLE(as-accelerator-for,
> +[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
> +		[build as offload target compiler.
> +		Specify offload host triple by ARG])],
> +ENABLE_AS_ACCELERATOR_FOR=$enableval,
> +ENABLE_AS_ACCELERATOR_FOR=no)

I don't see $ENABLE_AS_ACCELERATOR_FOR being used anywhere, so this can
probably be removed?

Also, given that we're addding --enable-as-accelerator-for and
--enable-offload-targets to the top-level configure, do we need really to
repeat (and thus, in the future maintain) those also in the subdirectory
configure files where the respective enable_* flags are evaulated?  If my
understanding of Autoconf is correct, then the enable_* variables will be
available in the subdirectory configure files, even without repeating the
AC_ARG_ENABLE instantiations.

How is this handled for other --enable-[...] flags that are needed in
several configure files?

> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac
> @@ -883,6 +887,53 @@ AC_ARG_ENABLE(languages,
>  esac],
>  [enable_languages=c])
>  
> +AC_ARG_ENABLE(as-accelerator-for,
> +[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
> +		[build as offload target compiler.
> +		Specify offload host triple by ARG])],
> +[
> +  AC_DEFINE(ACCEL_COMPILER, 1,
> +    [Define if this compiler should be built as the offload target compiler.])
> +  enable_as_accelerator=yes
> +  case "${target}" in
> +    *-intelmicemul-*)
> +      # In this case we expect offload compiler to be built as native, so we
> +      # need to rename the driver to avoid clashes with host's drivers.
> +      program_transform_name="s&^&${target}-&" ;;
> +  esac
> +  sedscript="s#${target_noncanonical}#${enable_as_accelerator_for}-accel-${target_noncanonical}#"
> +  program_transform_name=`echo $program_transform_name | sed $sedscript`
> +  accel_dir_suffix=/accel/${target_noncanonical}
> +  real_target_noncanonical=${enable_as_accelerator_for}
> +], [enable_as_accelerator=no])
> +AC_SUBST(enable_as_accelerator)

Thus, here you should be able to remove the AC_ARG_ENABLE for
--enable-as-accelerator-for, and just do something like (untested):

    if test x"$enable_as_accelerator" != x; then
      AC_DEFINE([...])
      [...]
    fi

I'm not sure whether the AC_SUBST for enable_as_accelerator needs to be
repeated.  (I think it needs to be repeated.)

> +AC_ARG_ENABLE(offload-targets,

Likewise, and also in the other */configure.ac files.


> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac

> +AC_SUBST(real_target_noncanonical)
> +AC_SUBST(accel_dir_suffix)

Can't we move these two AC_SUBST invocation up to where the variables are
being defined?


> --- /dev/null
> +++ b/libgcc/ompstuff.c
> @@ -0,0 +1,80 @@
> +/* Specialized bits of code needed for the OpenMP offloading tables.

> +#define OFFLOAD_FUNC_TABLE_SECTION_NAME "__gnu_offload_funcs"
> +#define OFFLOAD_VAR_TABLE_SECTION_NAME "__gnu_offload_vars"

Here we use __gnu_offload_* names here, and...

> +void *_omp_func_table[0]
> +  __attribute__ ((__used__, visibility ("hidden"),
> +		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
> +void *_omp_var_table[0]
> +  __attribute__ ((__used__, visibility ("hidden"),
> +		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };

..., also use OFFLOAD_*_TABLE_*, but on the other hand use _omp_*_table.
For consistency, shouldn't these also be named _offload_*_table?  Then
the »OpenMP« could be removed from the description in line 1 (just
»needed for the offloading tables«, and the file also be renamed to
offloadstuff.c or similar.  I certainly do acknowledge the role that
OpenMP has played in the development of this, but yet, this
infrastructure is not tied to OpenMP.

> +void *__OPENMP_TARGET__[]
> +  __attribute__ ((__visibility__ ("hidden"))) =
> +{
> +  &_omp_func_table, &_omp_funcs_end,
> +  &_omp_var_table, &_omp_vars_end
> +};

Also, the name __OPENMP_TARGET__ here is more opaque than it needs to be:
what about using __OFFLOADING_TABLE__ or similar.  As I have argued
before in a similar context (and Jakub has generally agreed): »the
"target" tag is confusing in that "target" typically has a different
meaning in the compiler context -- while this one here is used for
implementing OpenMP's target construct, what it technically does should
be described by .gnu.offload_[...] or somthing similar.  [...] Again, all
this doesn't matter to anyone who's already versed with the code, but it
does matter to people who are new, and still have to learn all these fine
details.  (Of which there are many, many more.  Yes, I know, life's
tough, and I'm used to that, but still.)  ;-)«.

> --- a/libgcc/Makefile.in
> +++ b/libgcc/Makefile.in

> @@ -990,6 +990,14 @@ crtendS$(objext): $(srcdir)/crtstuff.c
>  crtbeginT$(objext): $(srcdir)/crtstuff.c
>  	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN -DCRTSTUFFT_O
>  
> +# crtompbegin and crtompend contain symbols, that mark the begin and the end of
> +# tables with addresses, required for OpenMP offloading.
> +crtompbegin$(objext): $(srcdir)/ompstuff.c
> +	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN
> +
> +crtompend$(objext): $(srcdir)/ompstuff.c
> +	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END
> +

If you agree, then these files would be renamed to
crtoffload[ing]{begin,end}$(objext).


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-09-30 11:16     ` Thomas Schwinge
@ 2014-10-01 16:06       ` Ilya Verbin
  2014-12-12  8:14       ` Thomas Schwinge
  1 sibling, 0 replies; 21+ messages in thread
From: Ilya Verbin @ 2014-10-01 16:06 UTC (permalink / raw)
  To: Joseph S. Myers, Thomas Schwinge, Jakub Jelinek
  Cc: Richard Biener, Richard Henderson, gcc-patches, Bernd Schmidt,
	Andrey Turetskiy, Kirill Yukhin

On 26 Sep 22:02, Joseph S. Myers wrote:
> Any patch adding new configure options needs to add documentation of the 
> semantics of those options in install.texi.  I see no such documentation 
> in this patch.

Done.

On 30 Sep 13:16, Thomas Schwinge wrote:
> Doesn't that comment belong to real_target_noncanonical just above?  By
> default, accel_dir_suffix is empty.  Probably also move accel_dir_suffix
> above to where real_target_noncanonical is being set?

Right, done.

> I don't see $ENABLE_AS_ACCELERATOR_FOR being used anywhere, so this can
> probably be removed?

It will be used in one of the upcoming patches.

> Also, given that we're addding --enable-as-accelerator-for and
> --enable-offload-targets to the top-level configure, do we need really to
> repeat (and thus, in the future maintain) those also in the subdirectory
> configure files where the respective enable_* flags are evaulated?  If my
> understanding of Autoconf is correct, then the enable_* variables will be
> available in the subdirectory configure files, even without repeating the
> AC_ARG_ENABLE instantiations.
> 
> How is this handled for other --enable-[...] flags that are needed in
> several configure files?
> 
> Thus, here you should be able to remove the AC_ARG_ENABLE for
> --enable-as-accelerator-for, and just do something like (untested):
> 
>     if test x"$enable_as_accelerator" != x; then
>       AC_DEFINE([...])
>       [...]
>     fi
> 
> I'm not sure whether the AC_SUBST for enable_as_accelerator needs to be
> repeated.  (I think it needs to be repeated.)
> 
> Likewise, and also in the other */configure.ac files.

I didn't know that this is possible.  Thanks, done.
AC_SUBST needs to be repeated.

> Can't we move these two AC_SUBST invocation up to where the variables are
> being defined?

Done.

> ..., also use OFFLOAD_*_TABLE_*, but on the other hand use _omp_*_table.
> For consistency, shouldn't these also be named _offload_*_table?  Then
> the »OpenMP« could be removed from the description in line 1 (just
> »needed for the offloading tables«, and the file also be renamed to
> offloadstuff.c or similar.  I certainly do acknowledge the role that
> OpenMP has played in the development of this, but yet, this
> infrastructure is not tied to OpenMP.
> 
> Also, the name __OPENMP_TARGET__ here is more opaque than it needs to be:
> what about using __OFFLOADING_TABLE__ or similar.  As I have argued
> before in a similar context (and Jakub has generally agreed): »the
> "target" tag is confusing in that "target" typically has a different
> meaning in the compiler context -- while this one here is used for
> implementing OpenMP's target construct, what it technically does should
> be described by .gnu.offload_[...] or somthing similar.  [...] Again, all
> this doesn't matter to anyone who's already versed with the code, but it
> does matter to people who are new, and still have to learn all these fine
> details.  (Of which there are many, many more.  Yes, I know, life's
> tough, and I'm used to that, but still.)  ;-)«.
> 
> If you agree, then these files would be renamed to
> crtoffload[ing]{begin,end}$(objext).

Sounds reasonable, renamed.

On 30 Sep 12:10, Jakub Jelinek wrote:
> If you add the documentation Joseph requested, looks good to me
> (once the rest is reviewed too).

If no other objections, I will consider this patch as a pre-approved.

Thanks,
  -- Ilya


	* configure: Regenerate.
	* configure.ac (--enable-as-accelerator-for)
	(--enable-offload-targets): New configure options.
gcc/
	* Makefile.in (real_target_noncanonical, accel_dir_suffix)
	(enable_as_accelerator): New variables substituted by configure.
	(libsubdir, libexecsubdir, unlibsubdir): Tweak for the possibility of
	being configured as an offload compiler.
	(DRIVER_DEFINES): Pass new defines DEFAULT_REAL_TARGET_MACHINE and
	ACCEL_DIR_SUFFIX.
	(install-cpp, install-common, install_driver, install-gcc-ar): Do not
	install for the offload compiler.
	* config.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (real_target_noncanonical, accel_dir_suffix)
	(enable_as_accelerator): Compute new variables.
	(ACCEL_COMPILER): Define if the compiler is built as the accel compiler.
	(OFFLOAD_TARGETS): List of target names suitable for offloading.
	(ENABLE_OFFLOADING): Define if list of offload targets is not empty.
gcc/cp/
	* Make-lang.in (c++.install-common): Do not install for the offload
	compiler.
gcc/doc/
	* install.texi (Options specification): Document
	--enable-as-accelerator-for and --enable-offload-targets.
gcc/fortran/
	* Make-lang.in (fortran.install-common): Do not install for the offload
	compiler.
libgcc/
	* Makefile.in (crtoffloadbegin$(objext)): New rule.
	(crtoffloadend$(objext)): Likewise.
	* configure: Regenerate.
	* configure.ac (accel_dir_suffix): Compute new variable.
	(extra_parts): Add crtoffloadbegin.o and crtoffloadend.o
	if enable_offload_targets is not empty.
	* offloadstuff.c: New file.
libgomp/
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Check for libdl, required for plugin support.
	(PLUGIN_SUPPORT): Define if plugins are supported.
	(enable_offload_targets): Support Intel MIC targets.
	(OFFLOAD_TARGETS): List of target names suitable for offloading.
lto-plugin/
	* Makefile.am (libexecsubdir): Tweak for the possibility of being
	configured for offload compiler.
	(accel_dir_suffix, real_target_noncanonical): New variables substituted
	by configure.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (accel_dir_suffix, real_target_noncanonical): Compute new
	variables.

---

diff --git a/configure b/configure
index 55fca62..956062a 100755
--- a/configure
+++ b/configure
@@ -747,6 +747,8 @@ ospace_frag'
 ac_user_opts='
 enable_option_checking
 with_build_libsubdir
+enable_as_accelerator_for
+enable_offload_targets
 enable_gold
 enable_ld
 enable_libquadmath
@@ -1466,6 +1468,13 @@ Optional Features:
   --disable-option-checking  ignore unrecognized --enable/--with options
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-as-accelerator-for=ARG
+                          build as offload target compiler. Specify offload
+                          host triple by ARG
+  --enable-offload-targets=LIST
+                          enable offloading to devices from comma-separated
+                          LIST of TARGET[=DIR]. Use optional path to find
+                          offload target compiler during the build
   --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
   --enable-ld[=ARG]       build ld [ARG={default,yes,no}]
   --disable-libquadmath   do not build libquadmath directory
@@ -2893,6 +2902,26 @@ case ${with_newlib} in
   yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
 esac
 
+# Check whether --enable-as-accelerator-for was given.
+if test "${enable_as_accelerator_for+set}" = set; then :
+  enableval=$enable_as_accelerator_for; ENABLE_AS_ACCELERATOR_FOR=$enableval
+else
+  ENABLE_AS_ACCELERATOR_FOR=no
+fi
+
+
+# Check whether --enable-offload-targets was given.
+if test "${enable_offload_targets+set}" = set; then :
+  enableval=$enable_offload_targets;
+  if test x"$enable_offload_targets" = x; then
+    as_fn_error "no offload targets specified" "$LINENO" 5
+  fi
+
+else
+  enable_offload_targets=
+fi
+
+
 # Handle --enable-gold, --enable-ld.
 # --disable-gold [--enable-ld]
 #     Build only ld.  Default option.
diff --git a/configure.ac b/configure.ac
index 2dc657f..d031452 100644
--- a/configure.ac
+++ b/configure.ac
@@ -286,6 +286,24 @@ case ${with_newlib} in
   yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
 esac
 
+AC_ARG_ENABLE(as-accelerator-for,
+[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
+		[build as offload target compiler.
+		Specify offload host triple by ARG])],
+ENABLE_AS_ACCELERATOR_FOR=$enableval,
+ENABLE_AS_ACCELERATOR_FOR=no)
+
+AC_ARG_ENABLE(offload-targets,
+[AS_HELP_STRING([--enable-offload-targets=LIST],
+		[enable offloading to devices from comma-separated LIST of
+		TARGET[=DIR]. Use optional path to find offload target compiler
+		during the build])],
+[
+  if test x"$enable_offload_targets" = x; then
+    AC_MSG_ERROR([no offload targets specified])
+  fi
+], [enable_offload_targets=])
+
 # Handle --enable-gold, --enable-ld.
 # --disable-gold [--enable-ld]
 #     Build only ld.  Default option.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index b38f8ef..09ef297 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -59,6 +59,11 @@ host=@host@
 target=@target@
 target_noncanonical:=@target_noncanonical@
 
+# Normally identical to target_noncanonical, except for compilers built
+# as accelerator targets.
+real_target_noncanonical:=@real_target_noncanonical@
+accel_dir_suffix = @accel_dir_suffix@
+
 # Sed command to transform gcc to installed name.
 program_transform_name := @program_transform_name@
 
@@ -356,6 +361,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
 
@@ -567,9 +574,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
@@ -577,7 +584,11 @@ plugin_includedir = $(plugin_resourcesdir)/include
 # Directory in which plugin specific executables are installed
 plugin_bindir = $(libexecsubdir)/plugin
 # Used to produce a relative $(gcc_tooldir) in gcc.o
+ifeq ($(enable_as_accelerator),yes)
+unlibsubdir = ../../../../..
+else
 unlibsubdir = ../../..
+endif
 # $(prefix), expressed as a path relative to $(libsubdir).
 #
 # An explanation of the sed strings:
@@ -1930,9 +1941,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)) \
@@ -3104,12 +3117,14 @@ install-strip: install
 
 # Handle cpp installation.
 install-cpp: installdirs cpp$(exeext)
-	-rm -f $(DESTDIR)$(bindir)/$(CPP_INSTALL_NAME)$(exeext)
-	-$(INSTALL_PROGRAM) -m 755 cpp$(exeext) $(DESTDIR)$(bindir)/$(CPP_INSTALL_NAME)$(exeext)
-	-if [ x$(cpp_install_dir) != x ]; then \
-	  rm -f $(DESTDIR)$(prefix)/$(cpp_install_dir)/$(CPP_INSTALL_NAME)$(exeext); \
-	  $(INSTALL_PROGRAM) -m 755 cpp$(exeext) $(DESTDIR)$(prefix)/$(cpp_install_dir)/$(CPP_INSTALL_NAME)$(exeext); \
-	else true; fi
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  rm -f $(DESTDIR)$(bindir)/$(CPP_INSTALL_NAME)$(exeext); \
+	  $(INSTALL_PROGRAM) -m 755 cpp$(exeext) $(DESTDIR)$(bindir)/$(CPP_INSTALL_NAME)$(exeext); \
+	  if [ x$(cpp_install_dir) != x ]; then \
+	    rm -f $(DESTDIR)$(prefix)/$(cpp_install_dir)/$(CPP_INSTALL_NAME)$(exeext); \
+	    $(INSTALL_PROGRAM) -m 755 cpp$(exeext) $(DESTDIR)$(prefix)/$(cpp_install_dir)/$(CPP_INSTALL_NAME)$(exeext); \
+	  else true; fi; \
+	fi
 
 # Create the installation directories.
 # $(libdir)/gcc/include isn't currently searched by cpp.
@@ -3217,17 +3232,21 @@ install-common: native lang.install-common installdirs
 # otherwise override the specs built into the driver.
 	rm -f $(DESTDIR)$(libsubdir)/specs
 # Install gcov if it was compiled.
-	-if [ -f gcov$(exeext) ]; \
-	then \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  if [ -f gcov$(exeext) ]; \
+	  then \
 	    rm -f $(DESTDIR)$(bindir)/$(GCOV_INSTALL_NAME)$(exeext); \
 	    $(INSTALL_PROGRAM) gcov$(exeext) $(DESTDIR)$(bindir)/$(GCOV_INSTALL_NAME)$(exeext); \
+	  fi; \
 	fi
 # Install gcov-tool if it was compiled.
-	-if [ -f gcov-tool$(exeext) ]; \
-	then \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  if [ -f gcov-tool$(exeext) ]; \
+	  then \
 	    rm -f $(DESTDIR)$(bindir)/$(GCOV_TOOL_INSTALL_NAME)$(exeext); \
 	    $(INSTALL_PROGRAM) \
 	    gcov-tool$(exeext) $(DESTDIR)$(bindir)/$(GCOV_TOOL_INSTALL_NAME)$(exeext); \
+	  fi; \
 	fi
 
 # Install the driver program as $(target_noncanonical)-gcc,
@@ -3235,17 +3254,19 @@ install-common: native lang.install-common installdirs
 install-driver: installdirs xgcc$(exeext)
 	-rm -f $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
 	-$(INSTALL_PROGRAM) xgcc$(exeext) $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
-	-if [ "$(GCC_INSTALL_NAME)" != "$(target_noncanonical)-gcc-$(version)" ]; then \
-	  rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-$(version)$(exeext); \
-	  ( cd $(DESTDIR)$(bindir) && \
-	    $(LN) $(GCC_INSTALL_NAME)$(exeext) $(target_noncanonical)-gcc-$(version)$(exeext) ); \
-	fi
-	-if [ ! -f gcc-cross$(exeext) ] \
-	    && [ "$(GCC_INSTALL_NAME)" != "$(GCC_TARGET_INSTALL_NAME)" ]; then \
-	  rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-tmp$(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) ); \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  if [ "$(GCC_INSTALL_NAME)" != "$(target_noncanonical)-gcc-$(version)" ]; then \
+	    rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-$(version)$(exeext); \
+	    ( cd $(DESTDIR)$(bindir) && \
+	      $(LN) $(GCC_INSTALL_NAME)$(exeext) $(target_noncanonical)-gcc-$(version)$(exeext) ); \
+	  fi; \
+	  if [ ! -f gcc-cross$(exeext) ] \
+	      && [ "$(GCC_INSTALL_NAME)" != "$(GCC_TARGET_INSTALL_NAME)" ]; then \
+	    rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-tmp$(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) ); \
+	  fi; \
 	fi
 
 # Install the info files.
@@ -3442,19 +3463,21 @@ install-lto-wrapper: lto-wrapper$(exeext)
 	$(INSTALL_PROGRAM) lto-wrapper$(exeext) $(DESTDIR)$(libexecsubdir)/lto-wrapper$(exeext)
 
 install-gcc-ar: installdirs gcc-ar$(exeext) gcc-nm$(exeext) gcc-ranlib$(exeext)
-	for i in gcc-ar gcc-nm gcc-ranlib; do \
-	  install_name=`echo $$i|sed '$(program_transform_name)'` ;\
-	  target_install_name=$(target_noncanonical)-`echo $$i|sed '$(program_transform_name)'` ; \
-	  rm -f $(DESTDIR)$(bindir)/$$install_name$(exeext) ; \
-	  $(INSTALL_PROGRAM) $$i$(exeext) $(DESTDIR)$(bindir)/$$install_name$(exeext) ;\
-	  if test -f gcc-cross$(exeext); then \
-	    :; \
-	  else \
-	    rm -f $(DESTDIR)$(bindir)/$$target_install_name$(exeext); \
-	    ( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $$install_name$(exeext) $$target_install_name$(exeext) ) ; \
-	  fi ; \
-	done
+	if test "$(enable_as_accelerator)" != "yes" ; then \
+	  for i in gcc-ar gcc-nm gcc-ranlib; do \
+	    install_name=`echo $$i|sed '$(program_transform_name)'` ;\
+	    target_install_name=$(target_noncanonical)-`echo $$i|sed '$(program_transform_name)'` ; \
+	    rm -f $(DESTDIR)$(bindir)/$$install_name$(exeext) ; \
+	    $(INSTALL_PROGRAM) $$i$(exeext) $(DESTDIR)$(bindir)/$$install_name$(exeext) ;\
+	    if test -f gcc-cross$(exeext); then \
+	      :; \
+	    else \
+	      rm -f $(DESTDIR)$(bindir)/$$target_install_name$(exeext); \
+	      ( cd $(DESTDIR)$(bindir) && \
+		$(LN) $$install_name$(exeext) $$target_install_name$(exeext) ) ; \
+	    fi ; \
+	  done; \
+	fi
 
 # Cancel installation by deleting the installed files.
 uninstall: lang.uninstall
diff --git a/gcc/config.in b/gcc/config.in
index 90809e3..bf07125 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1,5 +1,11 @@
 /* config.in.  Generated from configure.ac by autoheader.  */
 
+/* Define if this compiler should be built as the offload target compiler. */
+#ifndef USED_FOR_TARGET
+#undef ACCEL_COMPILER
+#endif
+
+
 /* Define if building universal (internal helper macro) */
 #ifndef USED_FOR_TARGET
 #undef AC_APPLE_UNIVERSAL_BUILD
@@ -144,6 +150,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
@@ -1699,16 +1711,19 @@
 #undef HAVE_WORKING_VFORK
 #endif
 
-/* Define if isl is in use. */
-#ifndef USED_FOR_TARGET
-#undef HAVE_isl
-#endif
 
 /* Define if cloog is in use. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_cloog
 #endif
 
+
+/* Define if isl is in use. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_isl
+#endif
+
+
 /* Define if F_SETLKW supported by fcntl. */
 #ifndef USED_FOR_TARGET
 #undef HOST_HAS_F_SETLKW
@@ -1783,6 +1798,12 @@
 #endif
 
 
+/* Define to hold the list of target names suitable for offloading. */
+#ifndef USED_FOR_TARGET
+#undef OFFLOAD_TARGETS
+#endif
+
+
 /* Define to the address where bug reports for this package should be sent. */
 #ifndef USED_FOR_TARGET
 #undef PACKAGE_BUGREPORT
diff --git a/gcc/configure b/gcc/configure
index 380a235..cc802fa 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -761,6 +761,9 @@ LN
 LN_S
 AWK
 SET_MAKE
+accel_dir_suffix
+real_target_noncanonical
+enable_as_accelerator
 REPORT_BUGS_TEXI
 REPORT_BUGS_TO
 PKGVERSION
@@ -3194,6 +3197,10 @@ esac
 
 
 
+# Used for constructing correct paths for offload compilers.
+real_target_noncanonical=${target_noncanonical}
+accel_dir_suffix=
+
 # Determine the target- and build-specific subdirectories
 
 # post-stage1 host modules use a different CC_FOR_BUILD so, in order to
@@ -7391,6 +7398,45 @@ else
 fi
 
 
+if test x"$enable_as_accelerator_for" != x; then
+
+$as_echo "#define ACCEL_COMPILER 1" >>confdefs.h
+
+  enable_as_accelerator=yes
+  case "${target}" in
+    *-intelmicemul-*)
+      # In this case we expect offload compiler to be built as native, so we
+      # need to rename the driver to avoid clashes with host's drivers.
+      program_transform_name="s&^&${target}-&" ;;
+  esac
+  sedscript="s#${target_noncanonical}#${enable_as_accelerator_for}-accel-${target_noncanonical}#"
+  program_transform_name=`echo $program_transform_name | sed $sedscript`
+  accel_dir_suffix=/accel/${target_noncanonical}
+  real_target_noncanonical=${enable_as_accelerator_for}
+fi
+
+
+
+
+for tgt in `echo $enable_offload_targets | sed 's/,/ /g'`; do
+  tgt=`echo $tgt | sed 's/=.*//'`
+  if test x"$offload_targets" = x; then
+    offload_targets=$tgt
+  else
+    offload_targets="$offload_targets:$tgt"
+  fi
+done
+
+cat >>confdefs.h <<_ACEOF
+#define OFFLOAD_TARGETS "$offload_targets"
+_ACEOF
+
+if test x"$offload_targets" != x; then
+
+$as_echo "#define ENABLE_OFFLOADING 1" >>confdefs.h
+
+fi
+
 
 # Check whether --with-multilib-list was given.
 if test "${with_multilib_list+set}" = set; then :
@@ -18049,7 +18095,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18052 "configure"
+#line 18098 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18155,7 +18201,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18158 "configure"
+#line 18204 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index eb480de..e3c41a3 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -38,6 +38,10 @@ 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}
+accel_dir_suffix=
+
 # Determine the target- and build-specific subdirectories
 GCC_TOPLEV_SUBDIRS
 
@@ -883,6 +887,40 @@ AC_ARG_ENABLE(languages,
 esac],
 [enable_languages=c])
 
+if test x"$enable_as_accelerator_for" != x; then
+  AC_DEFINE(ACCEL_COMPILER, 1,
+    [Define if this compiler should be built as the offload target compiler.])
+  enable_as_accelerator=yes
+  case "${target}" in
+    *-intelmicemul-*)
+      # In this case we expect offload compiler to be built as native, so we
+      # need to rename the driver to avoid clashes with host's drivers.
+      program_transform_name="s&^&${target}-&" ;;
+  esac
+  sedscript="s#${target_noncanonical}#${enable_as_accelerator_for}-accel-${target_noncanonical}#"
+  program_transform_name=`echo $program_transform_name | sed $sedscript`
+  accel_dir_suffix=/accel/${target_noncanonical}
+  real_target_noncanonical=${enable_as_accelerator_for}
+fi
+AC_SUBST(enable_as_accelerator)
+AC_SUBST(real_target_noncanonical)
+AC_SUBST(accel_dir_suffix)
+
+for tgt in `echo $enable_offload_targets | sed 's/,/ /g'`; do
+  tgt=`echo $tgt | sed 's/=.*//'`
+  if test x"$offload_targets" = x; then
+    offload_targets=$tgt
+  else
+    offload_targets="$offload_targets:$tgt"
+  fi
+done
+AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$offload_targets",
+  [Define to hold the list of target names suitable for offloading.])
+if test x"$offload_targets" != x; then
+  AC_DEFINE(ENABLE_OFFLOADING, 1,
+    [Define this to enable support for offloading.])
+fi
+
 AC_ARG_WITH(multilib-list,
 [AS_HELP_STRING([--with-multilib-list], [select multilibs (AArch64, SH and x86-64 only)])],
 :,
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 36f9583..d6fbdce 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -164,21 +164,23 @@ check_g++_parallelize = 10000
 # Install the driver program as $(target)-g++ and $(target)-c++, and
 # also as g++ and c++ if native.
 c++.install-common: installdirs
-	-rm -f $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
-	-$(INSTALL_PROGRAM) xg++$(exeext) $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
-	-chmod a+x $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
-	-rm -f $(DESTDIR)$(bindir)/$(CXX_INSTALL_NAME)$(exeext)
-	-( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $(GXX_INSTALL_NAME)$(exeext) $(CXX_INSTALL_NAME)$(exeext) )
-	-if [ -f cc1plus$(exeext) ] ; then \
-	  if [ ! -f g++-cross$(exeext) ] ; then \
-	    rm -f $(DESTDIR)$(bindir)/$(GXX_TARGET_INSTALL_NAME)$(exeext); \
-	    ( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $(GXX_INSTALL_NAME)$(exeext) $(GXX_TARGET_INSTALL_NAME)$(exeext) ); \
-	    rm -f $(DESTDIR)$(bindir)/$(CXX_TARGET_INSTALL_NAME)$(exeext); \
-	    ( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $(CXX_INSTALL_NAME)$(exeext) $(CXX_TARGET_INSTALL_NAME)$(exeext) ); \
-	  fi ; \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  rm -f $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext); \
+	  $(INSTALL_PROGRAM) xg++$(exeext) $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext); \
+	  chmod a+x $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext); \
+	  rm -f $(DESTDIR)$(bindir)/$(CXX_INSTALL_NAME)$(exeext); \
+	  ( cd $(DESTDIR)$(bindir) && \
+	    $(LN) $(GXX_INSTALL_NAME)$(exeext) $(CXX_INSTALL_NAME)$(exeext) ); \
+	  if [ -f cc1plus$(exeext) ] ; then \
+	    if [ ! -f g++-cross$(exeext) ] ; then \
+	      rm -f $(DESTDIR)$(bindir)/$(GXX_TARGET_INSTALL_NAME)$(exeext); \
+	      ( cd $(DESTDIR)$(bindir) && \
+		$(LN) $(GXX_INSTALL_NAME)$(exeext) $(GXX_TARGET_INSTALL_NAME)$(exeext) ); \
+	      rm -f $(DESTDIR)$(bindir)/$(CXX_TARGET_INSTALL_NAME)$(exeext); \
+	      ( cd $(DESTDIR)$(bindir) && \
+		$(LN) $(CXX_INSTALL_NAME)$(exeext) $(CXX_TARGET_INSTALL_NAME)$(exeext) ); \
+	    fi ; \
+	  fi; \
 	fi
 
 # We can't use links because not everyone supports them.  So just copy the
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 75ac9a6..abbbb10 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1829,6 +1829,20 @@ If GCC is configured with some multilibs that use glibc and some that
 do not, this option applies only to the multilibs that use glibc.
 However, such configurations may not work well as not all the relevant
 configuration in GCC is on a per-multilib basis.
+
+@item --enable-as-accelerator-for=@var{target}
+Build as offload target compiler. Specify offload host triple by @var{target}.
+
+@item --enable-offload-targets=@var{target1}[=@var{path1}],@dots{},@var{targetN}[=@var{pathN}]
+Enable offloading to targets @var{target1}, @dots{}, @var{targetN}.
+Offload compilers are expected to be already installed.  Default search
+path for them is @file{@var{exec-prefix}}, but it can be changed by
+specifying paths @var{path1}, @dots{}, @var{pathN}.
+
+@smallexample
+% @var{srcdir}/configure \
+    --enable-offload-target=i686-unknown-linux-gnu=/path/to/i686/compiler,x86_64-pc-linux-gnu
+@end smallexample
 @end table
 
 @subheading Cross-Compiler-Specific Options
diff --git a/gcc/fortran/Make-lang.in b/gcc/fortran/Make-lang.in
index ca0a4e6..3621b4f 100644
--- a/gcc/fortran/Make-lang.in
+++ b/gcc/fortran/Make-lang.in
@@ -235,14 +235,16 @@ install-finclude-dir: installdirs
 # Install the driver program as $(target)-gfortran, and also as gfortran
 # if native.
 fortran.install-common: install-finclude-dir installdirs
-	-if [ -f f951$(exeext) ] ; then \
-	  rm -f $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
-	  $(INSTALL_PROGRAM) gfortran$(exeext) $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
-	  chmod a+x $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
-	  if [ ! -f gfortran-cross$(exeext) ] ; then \
-	    rm -f $(DESTDIR)$(bindir)/$(GFORTRAN_TARGET_INSTALL_NAME)$(exeext); \
-	    $(LN) $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext) $(DESTDIR)$(bindir)/$(GFORTRAN_TARGET_INSTALL_NAME)$(exeext); \
-	  fi ; \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  if [ -f f951$(exeext) ] ; then \
+	    rm -f $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
+	    $(INSTALL_PROGRAM) gfortran$(exeext) $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
+	    chmod a+x $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext); \
+	    if [ ! -f gfortran-cross$(exeext) ] ; then \
+	      rm -f $(DESTDIR)$(bindir)/$(GFORTRAN_TARGET_INSTALL_NAME)$(exeext); \
+	      $(LN) $(DESTDIR)$(bindir)/$(GFORTRAN_INSTALL_NAME)$(exeext) $(DESTDIR)$(bindir)/$(GFORTRAN_TARGET_INSTALL_NAME)$(exeext); \
+	    fi ; \
+	  fi; \
 	fi
 
 fortran.install-plugin:
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index 0d2c0b4..72eee9b 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -184,7 +184,7 @@ STRIP = @STRIP@
 STRIP_FOR_TARGET = $(STRIP)
 
 # Directory in which the compiler finds libraries etc.
-libsubdir = $(libdir)/gcc/$(host_noncanonical)/$(version)
+libsubdir = $(libdir)/gcc/$(host_noncanonical)/$(version)@accel_dir_suffix@
 # Used to install the shared libgcc.
 slibdir = @slibdir@
 # Maybe used for DLLs on Windows targets.
@@ -990,6 +990,14 @@ crtendS$(objext): $(srcdir)/crtstuff.c
 crtbeginT$(objext): $(srcdir)/crtstuff.c
 	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN -DCRTSTUFFT_O
 
+# crtoffloadbegin and crtoffloadend contain symbols, that mark the begin and
+# the end of tables with addresses, required for offloading.
+crtoffloadbegin$(objext): $(srcdir)/offloadstuff.c
+	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN
+
+crtoffloadend$(objext): $(srcdir)/offloadstuff.c
+	$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END
+
 ifeq ($(enable_vtable_verify),yes)
 # These are used in vtable verification; see comments in source files for
 # more details.
diff --git a/libgcc/configure b/libgcc/configure
index 19c4ed6..534d000 100644
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -566,6 +566,7 @@ sfp_machine_header
 set_use_emutls
 set_have_cc_tls
 vis_hide
+accel_dir_suffix
 force_explicit_eh_registry
 fixed_point
 enable_decimal_float
@@ -4379,6 +4380,23 @@ esac
 # Collect host-machine-specific information.
 . ${srcdir}/config.host
 
+# Used for constructing correct paths for offload compilers.
+accel_dir_suffix=
+if test x"$enable_as_accelerator_for" != x; then
+  accel_dir_suffix=/accel/${target_noncanonical}
+  case "${target_noncanonical}" in
+    *-intelmicemul-*)
+      # In this case we expect offload compiler to be built as native, so we
+      # need to change install directory for driver to be able to find libgcc.
+      host_noncanonical=${enable_as_accelerator_for} ;;
+  esac
+fi
+
+
+if test x"$enable_offload_targets" != x; then
+  extra_parts="${extra_parts} crtoffloadbegin.o crtoffloadend.o"
+fi
+
 # Check if Solaris/x86 linker supports ZERO terminator unwind entries.
 # This is after config.host so we can augment tmake_file.
 # Link with -nostartfiles -nodefaultlibs since neither are present while
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 72a21a9..f319bc7 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -323,6 +323,23 @@ esac
 # Collect host-machine-specific information.
 . ${srcdir}/config.host
 
+# Used for constructing correct paths for offload compilers.
+accel_dir_suffix=
+if test x"$enable_as_accelerator_for" != x; then
+  accel_dir_suffix=/accel/${target_noncanonical}
+  case "${target_noncanonical}" in
+    *-intelmicemul-*)
+      # In this case we expect offload compiler to be built as native, so we
+      # need to change install directory for driver to be able to find libgcc.
+      host_noncanonical=${enable_as_accelerator_for} ;;
+  esac
+fi
+AC_SUBST(accel_dir_suffix)
+
+if test x"$enable_offload_targets" != x; then
+  extra_parts="${extra_parts} crtoffloadbegin.o crtoffloadend.o"
+fi
+
 # Check if Solaris/x86 linker supports ZERO terminator unwind entries.
 # This is after config.host so we can augment tmake_file.
 # Link with -nostartfiles -nodefaultlibs since neither are present while
diff --git a/libgcc/offloadstuff.c b/libgcc/offloadstuff.c
new file mode 100644
index 0000000..78071ef
--- /dev/null
+++ b/libgcc/offloadstuff.c
@@ -0,0 +1,80 @@
+/* Specialized bits of code needed for the offloading tables.
+   Copyright (C) 2014 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.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Target machine header files require this define. */
+#define IN_LIBGCC2
+
+/* FIXME: Including auto-host is incorrect, but until we have
+   identified the set of defines that need to go into auto-target.h,
+   this will have to do.  */
+#include "auto-host.h"
+#undef caddr_t
+#undef pid_t
+#undef rlim_t
+#undef ssize_t
+#undef vfork
+#include "tconfig.h"
+#include "tsystem.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "libgcc_tm.h"
+
+#define OFFLOAD_FUNC_TABLE_SECTION_NAME "__gnu_offload_funcs"
+#define OFFLOAD_VAR_TABLE_SECTION_NAME "__gnu_offload_vars"
+
+#ifdef CRT_BEGIN
+
+#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
+void *_offload_func_table[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
+void *_offload_var_table[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };
+#endif
+
+#elif defined CRT_END
+
+#if defined(HAVE_GAS_HIDDEN) && defined(ENABLE_OFFLOADING)
+void *_offload_funcs_end[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_FUNC_TABLE_SECTION_NAME))) = { };
+void *_offload_vars_end[0]
+  __attribute__ ((__used__, visibility ("hidden"),
+		  section (OFFLOAD_VAR_TABLE_SECTION_NAME))) = { };
+
+extern void *_offload_func_table[];
+extern void *_offload_var_table[];
+
+void *__OFFLOAD_TABLE__[]
+  __attribute__ ((__visibility__ ("hidden"))) =
+{
+  &_offload_func_table, &_offload_funcs_end,
+  &_offload_var_table, &_offload_vars_end
+};
+#endif
+
+#else /* ! CRT_BEGIN && ! CRT_END */
+#error "One of CRT_BEGIN or CRT_END must be defined."
+#endif
diff --git a/libgomp/config.h.in b/libgomp/config.h.in
index 14c7e2a..94a2b3b 100644
--- a/libgomp/config.h.in
+++ b/libgomp/config.h.in
@@ -30,6 +30,9 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
+/* Define to 1 if you have the `dl' library (-ldl). */
+#undef HAVE_LIBDL
+
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
@@ -86,6 +89,9 @@
    */
 #undef LT_OBJDIR
 
+/* Define to hold the list of target names suitable for offloading. */
+#undef OFFLOAD_TARGETS
+
 /* Name of package */
 #undef PACKAGE
 
@@ -107,6 +113,9 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
+/* Define if all infrastructure, needed for plugins, is supported. */
+#undef PLUGIN_SUPPORT
+
 /* The size of `char', as computed by sizeof. */
 #undef SIZEOF_CHAR
 
diff --git a/libgomp/configure b/libgomp/configure
index 766eb09..97c9be6 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -15052,6 +15052,60 @@ fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
 
+plugin_support=yes
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlsym in -ldl" >&5
+$as_echo_n "checking for dlsym in -ldl... " >&6; }
+if test "${ac_cv_lib_dl_dlsym+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlsym ();
+int
+main ()
+{
+return dlsym ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlsym=yes
+else
+  ac_cv_lib_dl_dlsym=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlsym" >&5
+$as_echo "$ac_cv_lib_dl_dlsym" >&6; }
+if test "x$ac_cv_lib_dl_dlsym" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBDL 1
+_ACEOF
+
+  LIBS="-ldl $LIBS"
+
+else
+  plugin_support=no
+fi
+
+if test x"$plugin_support" = xyes; then
+
+$as_echo "#define PLUGIN_SUPPORT 1" >>confdefs.h
+
+fi
+
 # Check for functions needed.
 for ac_func in getloadavg clock_gettime strtoull
 do :
@@ -16153,6 +16207,29 @@ else
   multilib_arg=
 fi
 
+offload_targets=
+if test x"$enable_offload_targets" != x; then
+  for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+    tgt=`echo $tgt | sed 's/=.*//'`
+    case $tgt in
+      *-intelmic-* | *-intelmicemul-*)
+	tgt_name="intelmic" ;;
+      *)
+	as_fn_error "unknown offload target specified" "$LINENO" 5 ;;
+    esac
+    if test x"$offload_targets" = x; then
+      offload_targets=$tgt_name
+    else
+      offload_targets=$offload_targets,$tgt_name
+    fi
+  done
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define OFFLOAD_TARGETS "$offload_targets"
+_ACEOF
+
+
 # Set up the set of libraries that we need to link against for libgomp.
 # Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
 # which will force linkage against -lpthread (or equivalent for the system).
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index 84d250f..3f34ff8 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -193,6 +193,13 @@ AC_LINK_IFELSE(
    [],
    [AC_MSG_ERROR([Pthreads are required to build libgomp])])])
 
+plugin_support=yes
+AC_CHECK_LIB(dl, dlsym, , [plugin_support=no])
+if test x"$plugin_support" = xyes; then
+  AC_DEFINE(PLUGIN_SUPPORT, 1,
+    [Define if all infrastructure, needed for plugins, is supported.])
+fi
+
 # Check for functions needed.
 AC_CHECK_FUNCS(getloadavg clock_gettime strtoull)
 
@@ -273,6 +280,26 @@ else
   multilib_arg=
 fi
 
+offload_targets=
+if test x"$enable_offload_targets" != x; then
+  for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
+    tgt=`echo $tgt | sed 's/=.*//'`
+    case $tgt in
+      *-intelmic-* | *-intelmicemul-*)
+	tgt_name="intelmic" ;;
+      *)
+	AC_MSG_ERROR([unknown offload target specified]) ;;
+    esac
+    if test x"$offload_targets" = x; then
+      offload_targets=$tgt_name
+    else
+      offload_targets=$offload_targets,$tgt_name
+    fi
+  done
+fi
+AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$offload_targets",
+  [Define to hold the list of target names suitable for offloading.])
+
 # Set up the set of libraries that we need to link against for libgomp.
 # Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
 # which will force linkage against -lpthread (or equivalent for the system).
diff --git a/lto-plugin/Makefile.am b/lto-plugin/Makefile.am
index 93ea649..c637ecb 100644
--- a/lto-plugin/Makefile.am
+++ b/lto-plugin/Makefile.am
@@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS = no-dependencies
 
 gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
 target_noncanonical := @target_noncanonical@
-libexecsubdir := $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
+libexecsubdir := $(libexecdir)/gcc/$(real_target_noncanonical)/$(gcc_version)$(accel_dir_suffix)
 
 AM_CPPFLAGS = -I$(top_srcdir)/../include $(DEFS)
 AM_CFLAGS = @ac_lto_plugin_warn_cflags@
diff --git a/lto-plugin/Makefile.in b/lto-plugin/Makefile.in
index b15d901..4bd943b 100644
--- a/lto-plugin/Makefile.in
+++ b/lto-plugin/Makefile.in
@@ -167,6 +167,7 @@ ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 ac_lto_plugin_ldflags = @ac_lto_plugin_ldflags@
 ac_lto_plugin_warn_cflags = @ac_lto_plugin_warn_cflags@
+accel_dir_suffix = @accel_dir_suffix@
 am__include = @am__include@
 am__leading_dot = @am__leading_dot@
 am__quote = @am__quote@
@@ -209,6 +210,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+real_target_noncanonical = @real_target_noncanonical@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -227,7 +229,7 @@ with_libiberty = @with_libiberty@
 ACLOCAL_AMFLAGS = -I .. -I ../config
 AUTOMAKE_OPTIONS = no-dependencies
 gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
-libexecsubdir := $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
+libexecsubdir := $(libexecdir)/gcc/$(real_target_noncanonical)/$(gcc_version)$(accel_dir_suffix)
 AM_CPPFLAGS = -I$(top_srcdir)/../include $(DEFS)
 AM_CFLAGS = @ac_lto_plugin_warn_cflags@
 AM_LDFLAGS = @ac_lto_plugin_ldflags@
diff --git a/lto-plugin/configure b/lto-plugin/configure
index c34e653..e15e6d6 100755
--- a/lto-plugin/configure
+++ b/lto-plugin/configure
@@ -622,6 +622,8 @@ EGREP
 GREP
 SED
 LIBTOOL
+real_target_noncanonical
+accel_dir_suffix
 gcc_build_dir
 ac_lto_plugin_ldflags
 ac_lto_plugin_warn_cflags
@@ -4135,6 +4137,16 @@ else
 fi
 
 
+# Used for constructing correct paths for offload compilers.
+accel_dir_suffix=
+real_target_noncanonical=${target_noncanonical}
+if test x"$enable_as_accelerator_for" != x; then
+  accel_dir_suffix=/accel/${target_noncanonical}
+  real_target_noncanonical=${enable_as_accelerator_for}
+fi
+
+
+
 case `pwd` in
   *\ * | *\	*)
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
@@ -10607,7 +10619,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10610 "configure"
+#line 10622 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -10713,7 +10725,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10716 "configure"
+#line 10728 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac
index c3ae93e..db5b6cd 100644
--- a/lto-plugin/configure.ac
+++ b/lto-plugin/configure.ac
@@ -34,6 +34,16 @@ else
 fi
 AC_SUBST(gcc_build_dir)
 
+# Used for constructing correct paths for offload compilers.
+accel_dir_suffix=
+real_target_noncanonical=${target_noncanonical}
+if test x"$enable_as_accelerator_for" != x; then
+  accel_dir_suffix=/accel/${target_noncanonical}
+  real_target_noncanonical=${enable_as_accelerator_for}
+fi
+AC_SUBST(accel_dir_suffix)
+AC_SUBST(real_target_noncanonical)
+
 AM_PROG_LIBTOOL
 ACX_LT_HOST_FLAGS
 AC_SUBST(target_noncanonical)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-09-30 11:16     ` Thomas Schwinge
  2014-10-01 16:06       ` Ilya Verbin
@ 2014-12-12  8:14       ` Thomas Schwinge
  2014-12-12  8:17         ` Jakub Jelinek
  1 sibling, 1 reply; 21+ messages in thread
From: Thomas Schwinge @ 2014-12-12  8:14 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek, gcc-patches; +Cc: Andrey Turetskiy, Kirill Yukhin

[-- Attachment #1: Type: text/plain, Size: 2864 bytes --]

Hi!

On Tue, 30 Sep 2014 13:16:37 +0200, I wrote:
> On Fri, 26 Sep 2014 16:36:21 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -286,6 +286,24 @@ case ${with_newlib} in
> >    yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
> >  esac
> >  
> > +AC_ARG_ENABLE(as-accelerator-for,
> > +[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
> > +		[build as offload target compiler.
> > +		Specify offload host triple by ARG])],
> > +ENABLE_AS_ACCELERATOR_FOR=$enableval,
> > +ENABLE_AS_ACCELERATOR_FOR=no)
> 
> I don't see $ENABLE_AS_ACCELERATOR_FOR being used anywhere, so this can
> probably be removed?

On Wed, 1 Oct 2014 20:05:45 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> It will be used in one of the upcoming patches.

OK, but why do you need the all-uppercase variant?  The lowercase
enable_as_accelerator_for already is (automatically) populated by
Autoconf, and used in other places?  Here is a untested cleanup patch;
could you please test this?

	* configure.ac (--enable-as-accelerator-for): Don't set
	ENABLE_AS_ACCELERATOR_FOR.  Update all users.
	* configure: Regenerate.

diff --git configure configure
index 297f38e..1804198 100755
--- configure
+++ configure
@@ -2893,9 +2893,7 @@ esac
 
 # Check whether --enable-as-accelerator-for was given.
 if test "${enable_as_accelerator_for+set}" = set; then :
-  enableval=$enable_as_accelerator_for; ENABLE_AS_ACCELERATOR_FOR=$enableval
-else
-  ENABLE_AS_ACCELERATOR_FOR=no
+  enableval=$enable_as_accelerator_for;
 fi
 
 
@@ -3094,7 +3092,7 @@ if test "${enable_liboffloadmic+set}" = set; then :
     as_fn_error "--enable-liboffloadmic=no/host/target" "$LINENO" 5 ;;
 esac
 else
-  if test "${ENABLE_AS_ACCELERATOR_FOR}" != "no"; then
+  if test x"$enable_as_accelerator_for" != x; then
   case "${target}" in
     *-intelmic-* | *-intelmicemul-*)
       enable_liboffloadmic=target
diff --git configure.ac configure.ac
index fd1bdf0..91c9a72 100644
--- configure.ac
+++ configure.ac
@@ -289,9 +289,7 @@ esac
 AC_ARG_ENABLE(as-accelerator-for,
 [AS_HELP_STRING([--enable-as-accelerator-for=ARG],
 		[build as offload target compiler.
-		Specify offload host triple by ARG])],
-ENABLE_AS_ACCELERATOR_FOR=$enableval,
-ENABLE_AS_ACCELERATOR_FOR=no)
+		Specify offload host triple by ARG])])
 
 AC_ARG_ENABLE(offload-targets,
 [AS_HELP_STRING([--enable-offload-targets=LIST],
@@ -470,7 +468,7 @@ AC_HELP_STRING([[--enable-liboffloadmic[=ARG]]],
   *)
     AC_MSG_ERROR([--enable-liboffloadmic=no/host/target]) ;;
 esac],
-[if test "${ENABLE_AS_ACCELERATOR_FOR}" != "no"; then
+[if test x"$enable_as_accelerator_for" != x; then
   case "${target}" in
     *-intelmic-* | *-intelmicemul-*)
       enable_liboffloadmic=target


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-12-12  8:14       ` Thomas Schwinge
@ 2014-12-12  8:17         ` Jakub Jelinek
  2014-12-15  9:07           ` Kirill Yukhin
  0 siblings, 1 reply; 21+ messages in thread
From: Jakub Jelinek @ 2014-12-12  8:17 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Ilya Verbin, gcc-patches, Andrey Turetskiy, Kirill Yukhin

On Fri, Dec 12, 2014 at 09:14:28AM +0100, Thomas Schwinge wrote:
> On Tue, 30 Sep 2014 13:16:37 +0200, I wrote:
> > On Fri, 26 Sep 2014 16:36:21 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > > --- a/configure.ac
> > > +++ b/configure.ac
> > > @@ -286,6 +286,24 @@ case ${with_newlib} in
> > >    yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
> > >  esac
> > >  
> > > +AC_ARG_ENABLE(as-accelerator-for,
> > > +[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
> > > +		[build as offload target compiler.
> > > +		Specify offload host triple by ARG])],
> > > +ENABLE_AS_ACCELERATOR_FOR=$enableval,
> > > +ENABLE_AS_ACCELERATOR_FOR=no)
> > 
> > I don't see $ENABLE_AS_ACCELERATOR_FOR being used anywhere, so this can
> > probably be removed?
> 
> On Wed, 1 Oct 2014 20:05:45 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > It will be used in one of the upcoming patches.
> 
> OK, but why do you need the all-uppercase variant?  The lowercase
> enable_as_accelerator_for already is (automatically) populated by
> Autoconf, and used in other places?  Here is a untested cleanup patch;
> could you please test this?
> 
> 	* configure.ac (--enable-as-accelerator-for): Don't set
> 	ENABLE_AS_ACCELERATOR_FOR.  Update all users.
> 	* configure: Regenerate.

Ok if it works.

	Jakub

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-12-12  8:17         ` Jakub Jelinek
@ 2014-12-15  9:07           ` Kirill Yukhin
  0 siblings, 0 replies; 21+ messages in thread
From: Kirill Yukhin @ 2014-12-15  9:07 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Thomas Schwinge, Ilya Verbin, gcc-patches, Andrey Turetskiy

Hi,
On 12 Dec 09:17, Jakub Jelinek wrote:
> On Fri, Dec 12, 2014 at 09:14:28AM +0100, Thomas Schwinge wrote:
> > On Tue, 30 Sep 2014 13:16:37 +0200, I wrote:
> > > On Fri, 26 Sep 2014 16:36:21 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > > > --- a/configure.ac
> > > > +++ b/configure.ac
> > > > @@ -286,6 +286,24 @@ case ${with_newlib} in
> > > >    yes) skipdirs=`echo " ${skipdirs} " | sed -e 's/ target-newlib / /'` ;;
> > > >  esac
> > > >  
> > > > +AC_ARG_ENABLE(as-accelerator-for,
> > > > +[AS_HELP_STRING([--enable-as-accelerator-for=ARG],
> > > > +		[build as offload target compiler.
> > > > +		Specify offload host triple by ARG])],
> > > > +ENABLE_AS_ACCELERATOR_FOR=$enableval,
> > > > +ENABLE_AS_ACCELERATOR_FOR=no)
> > > 
> > > I don't see $ENABLE_AS_ACCELERATOR_FOR being used anywhere, so this can
> > > probably be removed?
> > 
> > On Wed, 1 Oct 2014 20:05:45 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > > It will be used in one of the upcoming patches.
> > 
> > OK, but why do you need the all-uppercase variant?  The lowercase
> > enable_as_accelerator_for already is (automatically) populated by
> > Autoconf, and used in other places?  Here is a untested cleanup patch;
> > could you please test this?
> > 
> > 	* configure.ac (--enable-as-accelerator-for): Don't set
> > 	ENABLE_AS_ACCELERATOR_FOR.  Update all users.
> > 	* configure: Regenerate.
> 
> Ok if it works.
The patch doesn't regress MIC offloading.

--
Thanks, K

> 
> 	Jakub

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-09-26 12:36   ` Ilya Verbin
                       ` (2 preceding siblings ...)
  2014-09-30 11:16     ` Thomas Schwinge
@ 2015-02-19 11:43     ` Thomas Schwinge
  2015-02-20 14:40       ` Ilya Verbin
  3 siblings, 1 reply; 21+ messages in thread
From: Thomas Schwinge @ 2015-02-19 11:43 UTC (permalink / raw)
  To: Ilya Verbin, Jakub Jelinek
  Cc: Richard Biener, Richard Henderson, gcc-patches, Bernd Schmidt,
	Andrey Turetskiy, Kirill Yukhin

[-- Attachment #1: Type: text/plain, Size: 1040 bytes --]

Hi!

On Fri, 26 Sep 2014 16:36:21 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> The patch has been updated:

> if a compiler is configured as accelerator,
> it installs *-accel-*-g++, and other drivers.  But only *-accel-*-gcc is needed.
> Therefore I suppressed their installation in corresponding Makefiles.

> gcc/
> 	* Makefile.in

> 	(install-cpp, install-common, install_driver, install-gcc-ar): Do not
> 	install for the offload compiler.

> gcc/cp/
> 	* Make-lang.in (c++.install-common): Do not install for the offload
> 	compiler.
> gcc/fortran/
> 	* Make-lang.in (fortran.install-common): Do not install for the offload
> 	compiler.

Hmm, shouldn't that be done for all gcc/*/Make-lang.in?  If I understand
correctly, if the language is enabled,
gcc/java/Make-lang.in:java.install-common would currently still install
*-gcj, and similar for gcc/go/Make-lang.in:go.install-common,
gcc/ada/gcc-interface/Make-lang.in:ada.install-common,
gcc/jit/Make-lang.in:jit.install-common.


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2015-02-19 11:43     ` Thomas Schwinge
@ 2015-02-20 14:40       ` Ilya Verbin
  2015-02-20 14:43         ` Thomas Schwinge
  2015-02-20 19:47         ` Mike Stump
  0 siblings, 2 replies; 21+ messages in thread
From: Ilya Verbin @ 2015-02-20 14:40 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Jakub Jelinek, gcc-patches, Bernd Schmidt, Kirill Yukhin

On Thu, Feb 19, 2015 at 12:37:10 +0100, Thomas Schwinge wrote:
> On Fri, 26 Sep 2014 16:36:21 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > gcc/
> > 	* Makefile.in
> 
> > 	(install-cpp, install-common, install_driver, install-gcc-ar): Do not
> > 	install for the offload compiler.
> 
> > gcc/cp/
> > 	* Make-lang.in (c++.install-common): Do not install for the offload
> > 	compiler.
> > gcc/fortran/
> > 	* Make-lang.in (fortran.install-common): Do not install for the offload
> > 	compiler.
> 
> Hmm, shouldn't that be done for all gcc/*/Make-lang.in?  If I understand
> correctly, if the language is enabled,
> gcc/java/Make-lang.in:java.install-common would currently still install
> *-gcj, and similar for gcc/go/Make-lang.in:go.install-common,
> gcc/ada/gcc-interface/Make-lang.in:ada.install-common,
> gcc/jit/Make-lang.in:jit.install-common.

I assumed that nobody would build an offloading compiler with --enable-languages
other than c,c++,fortran[,lto].

  -- Ilya

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2015-02-20 14:40       ` Ilya Verbin
@ 2015-02-20 14:43         ` Thomas Schwinge
  2015-02-20 15:05           ` Jakub Jelinek
  2015-02-20 19:47         ` Mike Stump
  1 sibling, 1 reply; 21+ messages in thread
From: Thomas Schwinge @ 2015-02-20 14:43 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: Jakub Jelinek, gcc-patches, Bernd Schmidt, Kirill Yukhin

[-- Attachment #1: Type: text/plain, Size: 3230 bytes --]

Hi!

On Fri, 20 Feb 2015 17:36:12 +0300, Ilya Verbin <iverbin@gmail.com> wrote:
> On Thu, Feb 19, 2015 at 12:37:10 +0100, Thomas Schwinge wrote:
> > On Fri, 26 Sep 2014 16:36:21 +0400, Ilya Verbin <iverbin@gmail.com> wrote:
> > > gcc/
> > > 	* Makefile.in
> > 
> > > 	(install-cpp, install-common, install_driver, install-gcc-ar): Do not
> > > 	install for the offload compiler.
> > 
> > > gcc/cp/
> > > 	* Make-lang.in (c++.install-common): Do not install for the offload
> > > 	compiler.
> > > gcc/fortran/
> > > 	* Make-lang.in (fortran.install-common): Do not install for the offload
> > > 	compiler.
> > 
> > Hmm, shouldn't that be done for all gcc/*/Make-lang.in?  If I understand
> > correctly, if the language is enabled,
> > gcc/java/Make-lang.in:java.install-common would currently still install
> > *-gcj, and similar for gcc/go/Make-lang.in:go.install-common,
> > gcc/ada/gcc-interface/Make-lang.in:ada.install-common,
> > gcc/jit/Make-lang.in:jit.install-common.
> 
> I assumed that nobody would build an offloading compiler with --enable-languages
> other than c,c++,fortran[,lto].

Well, but users (like Jakub, for example) ;-) may decide to build the
offloading compilers without specifying --enable-languages, and that'll
then default to include Java, and you'll end up with:

    $ ls -l install/offload-x86_64-intelmicemul-linux-gnu/bin/
    total 12152
    -rwxr-xr-x 1 tschwing eeg    3107 Feb 19 13:37 aot-compile
    -rwxr-xr-x 1 tschwing eeg    9419 Feb 19 13:37 gappletviewer
    -rwxr-xr-x 1 tschwing eeg    9429 Feb 19 13:37 gc-analyze
    -rwxr-xr-x 1 tschwing eeg  105588 Feb 19 13:37 gcj-dbtool
    -rwxr-xr-x 1 tschwing eeg    9415 Feb 19 13:37 gcjh
    -rwxr-xr-x 1 tschwing eeg    7453 Feb 19 13:37 gij
    -rwxr-xr-x 1 tschwing eeg    9385 Feb 19 13:37 gjar
    -rwxr-xr-x 1 tschwing eeg    9415 Feb 19 13:37 gjarsigner
    -rwxr-xr-x 1 tschwing eeg    9387 Feb 19 13:37 gjavah
    -rwxr-xr-x 1 tschwing eeg    9467 Feb 19 13:37 gjdoc
    -rwxr-xr-x 1 tschwing eeg    9397 Feb 19 13:37 gkeytool
    -rwxr-xr-x 1 tschwing eeg    9436 Feb 19 13:37 gnative2ascii
    -rwxr-xr-x 1 tschwing eeg    9386 Feb 19 13:37 gorbd
    -rwxr-xr-x 1 tschwing eeg    9386 Feb 19 13:37 grmic
    -rwxr-xr-x 1 tschwing eeg    9386 Feb 19 13:37 grmid
    -rwxr-xr-x 1 tschwing eeg    9418 Feb 19 13:37 grmiregistry
    -rwxr-xr-x 1 tschwing eeg    9420 Feb 19 13:37 gserialver
    -rwxr-xr-x 1 tschwing eeg    9415 Feb 19 13:37 gtnameserv
    -rwxr-xr-x 1 tschwing eeg    9340 Feb 19 13:37 jv-convert
    -rwxr-xr-x 1 tschwing eeg     859 Feb 19 13:37 rebuild-gcj-db
    -rwxr-xr-x 2 tschwing eeg 3277373 Feb 19 13:37 x86_64-intelmicemul-linux-gnu-x86_64-unknown-linux-gnu-accel-x86_64-intelmicemul-linux-gnu-gcj
    -rwxr-xr-x 1 tschwing eeg 3231429 Feb 19 13:37 x86_64-unknown-linux-gnu-accel-x86_64-intelmicemul-linux-gnu-gcc
    -rwxr-xr-x 2 tschwing eeg 3277373 Feb 19 13:37 x86_64-unknown-linux-gnu-accel-x86_64-intelmicemul-linux-gnu-gcj
    -rwxr-xr-x 1 tschwing eeg 2327849 Feb 19 13:37 x86_64-unknown-linux-gnu-accel-x86_64-intelmicemul-linux-gnu-jcf-dump

... and more files with clashing file names in other directories.


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2015-02-20 14:43         ` Thomas Schwinge
@ 2015-02-20 15:05           ` Jakub Jelinek
  2015-02-25 20:09             ` Ilya Verbin
  0 siblings, 1 reply; 21+ messages in thread
From: Jakub Jelinek @ 2015-02-20 15:05 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Ilya Verbin, gcc-patches, Bernd Schmidt, Kirill Yukhin

On Fri, Feb 20, 2015 at 03:41:40PM +0100, Thomas Schwinge wrote:
> Well, but users (like Jakub, for example) ;-) may decide to build the
> offloading compilers without specifying --enable-languages, and that'll
> then default to include Java, and you'll end up with:

Yeah.  We can perhaps tweak what languages we include by default for
the --enable-as-accelerator-for= configurations, but if the user decides
to explicitly add some language, we should still support that.

	Jakub

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2015-02-20 14:40       ` Ilya Verbin
  2015-02-20 14:43         ` Thomas Schwinge
@ 2015-02-20 19:47         ` Mike Stump
  2015-02-20 19:49           ` Thomas Schwinge
  1 sibling, 1 reply; 21+ messages in thread
From: Mike Stump @ 2015-02-20 19:47 UTC (permalink / raw)
  To: Ilya Verbin
  Cc: Thomas Schwinge, Jakub Jelinek, gcc-patches, Bernd Schmidt,
	Kirill Yukhin

On Feb 20, 2015, at 6:36 AM, Ilya Verbin <iverbin@gmail.com> wrote:
> I assumed that nobody would build an offloading compiler with --enable-languages
> other than c,c++,fortran[,lto].

:-)  You should try objc and obj-c++…  With some luck, they might just work out of the box.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2015-02-20 19:47         ` Mike Stump
@ 2015-02-20 19:49           ` Thomas Schwinge
  2015-02-21 12:12             ` Iain Sandoe
  0 siblings, 1 reply; 21+ messages in thread
From: Thomas Schwinge @ 2015-02-20 19:49 UTC (permalink / raw)
  To: Mike Stump
  Cc: Jakub Jelinek, gcc-patches, Bernd Schmidt, Kirill Yukhin,
	Ilya Verbin, iain

[-- Attachment #1: Type: text/plain, Size: 644 bytes --]

Hi!

On Fri, 20 Feb 2015 11:35:18 -0800, Mike Stump <mikestump@comcast.net> wrote:
> On Feb 20, 2015, at 6:36 AM, Ilya Verbin <iverbin@gmail.com> wrote:
> > I assumed that nobody would build an offloading compiler with --enable-languages
> > other than c,c++,fortran[,lto].
> 
> :-)  You should try objc and obj-c++…  With some luck, they might just work out of the box.

At least objc does build indeed (gets enabled by default if
--enable-languages is not explicitly specified).  Now we just need
someone to write additional OpenACC/OpenMP test cases...  Are you or Iain
interested (in doing that)?  ;-D


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2015-02-20 19:49           ` Thomas Schwinge
@ 2015-02-21 12:12             ` Iain Sandoe
  0 siblings, 0 replies; 21+ messages in thread
From: Iain Sandoe @ 2015-02-21 12:12 UTC (permalink / raw)
  To: Thomas Schwinge
  Cc: Mike Stump, Jakub Jelinek, gcc-patches, Bernd Schmidt,
	Kirill Yukhin, Ilya Verbin

Hi Thomas,

On 20 Feb 2015, at 19:46, Thomas Schwinge wrote:

> On Fri, 20 Feb 2015 11:35:18 -0800, Mike Stump <mikestump@comcast.net> wrote:
>> On Feb 20, 2015, at 6:36 AM, Ilya Verbin <iverbin@gmail.com> wrote:
>>> I assumed that nobody would build an offloading compiler with --enable-languages
>>> other than c,c++,fortran[,lto].
>> 
>> :-)  You should try objc and obj-c++…  With some luck, they might just work out of the box.
> 
> At least objc does build indeed (gets enabled by default if
> --enable-languages is not explicitly specified).  Now we just need
> someone to write additional OpenACC/OpenMP test cases...  Are you or Iain
> interested (in doing that)?  ;-D

Well, the mantra is "Objective-C,C++ are supersets of the underlying languages".

So, for a first cut, it should be possible to run all the existing C and C++ testcases with -x objective-c,c++ respectively.   If that doesn't work as expected - we should examine why (and identify any restrictions that apply).  Do you want to try that (at least once manually) to see if there are any show-stoppers? (I don't have an accelerated setup here).

That should be adequate, for now at least, since there are currently no Objective-C family-specific OpenAcc or OpenMP clauses (AFAIU).

FWIW, I, for one, have implemented real-time signal processing and data collection systems in Objective-C (a useful thin wrapper to get access to GUI features, without slowing the actual work down).  So, it seems reasonable that acceleration capabilities will be interesting to (at least some) Objective-C users.

As for the future (i.e. should the Objective C family support extra capabilities in this area), IMO, unless we see some killer capability that is a "must have" (for stage #1 of course), then let's leave the lead on language features to the "defining implementation" (i.e. clang).  TBH, we are somewhat behind on Objective-C in any event, catching up to modern capabilities is a higher priority for me.

cheers
Iain

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2015-02-20 15:05           ` Jakub Jelinek
@ 2015-02-25 20:09             ` Ilya Verbin
  0 siblings, 0 replies; 21+ messages in thread
From: Ilya Verbin @ 2015-02-25 20:09 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Thomas Schwinge, gcc-patches, Bernd Schmidt, Kirill Yukhin

On Fri, Feb 20, 2015 at 15:50:53 +0100, Jakub Jelinek wrote:
> On Fri, Feb 20, 2015 at 03:41:40PM +0100, Thomas Schwinge wrote:
> > Well, but users (like Jakub, for example) ;-) may decide to build the
> > offloading compilers without specifying --enable-languages, and that'll
> > then default to include Java, and you'll end up with:
> 
> Yeah.  We can perhaps tweak what languages we include by default for
> the --enable-as-accelerator-for= configurations, but if the user decides
> to explicitly add some language, we should still support that.

Here is the patch.
Build and install seems to be working both for accel and regular modes, with
--enable-languages=c,c++,fortran,go,java,jit,lto,objc,obj-c++
OK for trunk?


gcc/ada/
	* gcc-interface/Make-lang.in (ada.install-common): Do not install for
	the offloading compiler.
gcc/go/
	* Make-lang.in (go.install-common): Do not install for the offloading
	compiler.
gcc/java/
	* Make-lang.in (java.install-common): Do not install for the offloading
	compiler.
gcc/jit/
	* Make-lang.in (jit.install-common): Do not install for the offloading
	compiler.
	

diff --git a/gcc/ada/gcc-interface/Make-lang.in b/gcc/ada/gcc-interface/Make-lang.in
index 4696203..81fd80a 100644
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -754,25 +754,27 @@ doc/gnat-style.pdf: ada/gnat-style.texi $(gcc_docdir)/include/fdl.texi
 # vxaddr2line is only used for cross VxWorks ports (it calls the underlying
 # cross addr2line).
 ada.install-common:
-	$(MKDIR) $(DESTDIR)$(bindir)
-	-if [ -f gnat1$(exeext) ] ; \
-	then \
-	  for tool in $(ADA_TOOLS) ; do \
-	    install_name=`echo $$tool|sed '$(program_transform_name)'`$(exeext); \
-	    $(RM) $(DESTDIR)$(bindir)/$$install_name; \
-	    if [ -f $$tool-cross$(exeext) ] ; \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  $(MKDIR) $(DESTDIR)$(bindir); \
+	  if [ -f gnat1$(exeext) ] ; \
+	  then \
+	    for tool in $(ADA_TOOLS) ; do \
+	      install_name=`echo $$tool|sed '$(program_transform_name)'`$(exeext); \
+	      $(RM) $(DESTDIR)$(bindir)/$$install_name; \
+	      if [ -f $$tool-cross$(exeext) ] ; \
+	      then \
+	        $(INSTALL_PROGRAM) $$tool-cross$(exeext) $(DESTDIR)$(bindir)/$$install_name; \
+	      else \
+	        $(INSTALL_PROGRAM) $$tool$(exeext) $(DESTDIR)$(bindir)/$$install_name; \
+	      fi ; \
+	    done; \
+	    $(RM) $(DESTDIR)$(bindir)/gnatdll$(exeext); \
+	    $(INSTALL_PROGRAM) gnatdll$(exeext) $(DESTDIR)$(bindir)/gnatdll$(exeext); \
+	    if [ -f vxaddr2line$(exeext) ] ; \
 	    then \
-	      $(INSTALL_PROGRAM) $$tool-cross$(exeext) $(DESTDIR)$(bindir)/$$install_name; \
-	    else \
-	      $(INSTALL_PROGRAM) $$tool$(exeext) $(DESTDIR)$(bindir)/$$install_name; \
+	      $(RM) $(DESTDIR)$(bindir)/vxaddr2line$(exeext); \
+	      $(INSTALL_PROGRAM) vxaddr2line$(exeext) $(DESTDIR)$(bindir)/vxaddr2line$(exeext); \
 	    fi ; \
-	  done; \
-	  $(RM) $(DESTDIR)$(bindir)/gnatdll$(exeext); \
-	  $(INSTALL_PROGRAM) gnatdll$(exeext) $(DESTDIR)$(bindir)/gnatdll$(exeext); \
-	  if [ -f vxaddr2line$(exeext) ] ; \
-	  then \
-	    $(RM) $(DESTDIR)$(bindir)/vxaddr2line$(exeext); \
-	    $(INSTALL_PROGRAM) vxaddr2line$(exeext) $(DESTDIR)$(bindir)/vxaddr2line$(exeext); \
 	  fi ; \
 	fi
 
diff --git a/gcc/go/Make-lang.in b/gcc/go/Make-lang.in
index 6c5968a..891b610 100644
--- a/gcc/go/Make-lang.in
+++ b/gcc/go/Make-lang.in
@@ -136,15 +136,17 @@ check_go_parallelize = 10
 # Install hooks.
 
 go.install-common: installdirs
-	-rm -f $(DESTDIR)$(bindir)/$(GCCGO_INSTALL_NAME)$(exeext)
-	$(INSTALL_PROGRAM) gccgo$(exeext) $(DESTDIR)$(bindir)/$(GCCGO_INSTALL_NAME)$(exeext)
-	-if test -f go1$(exeext); then \
-	  if test -f gccgo-cross$(exeext); then \
-	    :; \
-	  else \
-	    rm -f $(DESTDIR)$(bindir)/$(GCCGO_TARGET_INSTALL_NAME)$(exeext); \
-	    ( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $(GCCGO_INSTALL_NAME)$(exeext) $(GCCGO_TARGET_INSTALL_NAME)$(exeext) ); \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  rm -f $(DESTDIR)$(bindir)/$(GCCGO_INSTALL_NAME)$(exeext); \
+	  $(INSTALL_PROGRAM) gccgo$(exeext) $(DESTDIR)$(bindir)/$(GCCGO_INSTALL_NAME)$(exeext); \
+	  if test -f go1$(exeext); then \
+	    if test -f gccgo-cross$(exeext); then \
+	      :; \
+	    else \
+	      rm -f $(DESTDIR)$(bindir)/$(GCCGO_TARGET_INSTALL_NAME)$(exeext); \
+	      ( cd $(DESTDIR)$(bindir) && \
+	        $(LN) $(GCCGO_INSTALL_NAME)$(exeext) $(GCCGO_TARGET_INSTALL_NAME)$(exeext) ); \
+	    fi; \
 	  fi; \
 	fi
 
diff --git a/gcc/java/Make-lang.in b/gcc/java/Make-lang.in
index e8f2340..1746508 100644
--- a/gcc/java/Make-lang.in
+++ b/gcc/java/Make-lang.in
@@ -156,26 +156,28 @@ check-java-subtargets :
 
 # Install gcj as well as the target-independent tools.
 java.install-common: installdirs
-	-if [ -f $(XGCJ)$(exeext) ]; then \
-	  rm -f $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
-	  $(INSTALL_PROGRAM) $(XGCJ)$(exeext) $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
-	  chmod a+x $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
-	  if [ -f $(XGCJ)-cross$(exeext) ]; then \
-	    true; \
-	  else \
-	    rm -f $(DESTDIR)$(bindir)/$(JAVA_TARGET_INSTALL_NAME)$(exeext); \
-	    ( cd $(DESTDIR)$(bindir) && \
-	      $(LN) $(JAVA_INSTALL_NAME)$(exeext) $(JAVA_TARGET_INSTALL_NAME)$(exeext) ); \
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  if [ -f $(XGCJ)$(exeext) ]; then \
+	    rm -f $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
+	    $(INSTALL_PROGRAM) $(XGCJ)$(exeext) $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
+	    chmod a+x $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
+	    if [ -f $(XGCJ)-cross$(exeext) ]; then \
+	      true; \
+	    else \
+	      rm -f $(DESTDIR)$(bindir)/$(JAVA_TARGET_INSTALL_NAME)$(exeext); \
+	      ( cd $(DESTDIR)$(bindir) && \
+	        $(LN) $(JAVA_INSTALL_NAME)$(exeext) $(JAVA_TARGET_INSTALL_NAME)$(exeext) ); \
+	    fi ; \
 	  fi ; \
-	fi ; \
-        for tool in $(JAVA_TARGET_INDEPENDENT_BIN_TOOLS); do \
-	  tool_transformed_name=`echo $$tool|sed '$(program_transform_name)'`; \
-          if [ -f $$tool$(exeext) ]; then \
-	    rm -f $(DESTDIR)$(bindir)/$$tool_transformed_name$(exeext); \
-	    $(INSTALL_PROGRAM) $$tool$(exeext) $(DESTDIR)$(bindir)/$$tool_transformed_name$(exeext); \
-	    chmod a+x $(DESTDIR)$(bindir)/$$tool_transformed_name$(exeext); \
-          fi ; \
-       done
+          for tool in $(JAVA_TARGET_INDEPENDENT_BIN_TOOLS); do \
+	    tool_transformed_name=`echo $$tool|sed '$(program_transform_name)'`; \
+            if [ -f $$tool$(exeext) ]; then \
+	      rm -f $(DESTDIR)$(bindir)/$$tool_transformed_name$(exeext); \
+	      $(INSTALL_PROGRAM) $$tool$(exeext) $(DESTDIR)$(bindir)/$$tool_transformed_name$(exeext); \
+	      chmod a+x $(DESTDIR)$(bindir)/$$tool_transformed_name$(exeext); \
+            fi ; \
+          done ; \
+	fi
 
 java.install-plugin:
 java.install-man:
diff --git a/gcc/jit/Make-lang.in b/gcc/jit/Make-lang.in
index 44d0750..6a2c80e 100644
--- a/gcc/jit/Make-lang.in
+++ b/gcc/jit/Make-lang.in
@@ -260,18 +260,20 @@ check_jit_parallelize = 10
 #\f
 # Install hooks:
 jit.install-common: installdirs
-	$(INSTALL_PROGRAM) $(LIBGCCJIT_FILENAME) \
-	  $(DESTDIR)/$(libdir)/$(LIBGCCJIT_FILENAME)
-	ln -sf \
-	  $(LIBGCCJIT_FILENAME) \
-	  $(DESTDIR)/$(libdir)/$(LIBGCCJIT_SONAME_SYMLINK)
-	ln -sf \
-	  $(LIBGCCJIT_SONAME_SYMLINK)\
-	  $(DESTDIR)/$(libdir)/$(LIBGCCJIT_LINKER_NAME_SYMLINK)
-	$(INSTALL_PROGRAM) $(srcdir)/jit/libgccjit.h \
-	  $(DESTDIR)/$(includedir)/libgccjit.h
-	$(INSTALL_PROGRAM) $(srcdir)/jit/libgccjit++.h \
-	  $(DESTDIR)/$(includedir)/libgccjit++.h
+	-if test "$(enable_as_accelerator)" != "yes" ; then \
+	  $(INSTALL_PROGRAM) $(LIBGCCJIT_FILENAME) \
+	    $(DESTDIR)/$(libdir)/$(LIBGCCJIT_FILENAME); \
+	  ln -sf \
+	    $(LIBGCCJIT_FILENAME) \
+	    $(DESTDIR)/$(libdir)/$(LIBGCCJIT_SONAME_SYMLINK); \
+	  ln -sf \
+	    $(LIBGCCJIT_SONAME_SYMLINK)\
+	    $(DESTDIR)/$(libdir)/$(LIBGCCJIT_LINKER_NAME_SYMLINK); \
+	  $(INSTALL_PROGRAM) $(srcdir)/jit/libgccjit.h \
+	    $(DESTDIR)/$(includedir)/libgccjit.h; \
+	  $(INSTALL_PROGRAM) $(srcdir)/jit/libgccjit++.h \
+	    $(DESTDIR)/$(includedir)/libgccjit++.h; \
+	fi
 
 jit.install-man:
 

  -- Ilya

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-09-11 11:34 ` Jakub Jelinek
@ 2014-09-11 12:27   ` Ilya Verbin
  0 siblings, 0 replies; 21+ messages in thread
From: Ilya Verbin @ 2014-09-11 12:27 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Kirill Yukhin

On 11 Sep 13:34, Jakub Jelinek wrote:
> I think it is not useful to split patches on in which sequence they were
> added to the tree.  I'd prefer patches for functional parts for the
> differences between trunk and corresponding offloading branch.
> So, one patch should be all the libgomp changes except for addition of
> plugins, another one generic middle-end changes, then the libmicoffload
> support library, then libgomp plugin for Intel MIC and finally rest of Intel
> MIC enablements.  E.g. the patch you've posted contains tons of FIXMEs that
> really shouldn't make into the trunk, not even short lived.
> 
> 	Jakub

Ok.  All other libgomp changes depend on the defines from configure.
So I'll start from the patch, which adds new options for the configure.

Thanks,
  -- Ilya

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/n] OpenMP 4.0 offloading infrastructure
  2014-09-11 11:28 Ilya Verbin
@ 2014-09-11 11:34 ` Jakub Jelinek
  2014-09-11 12:27   ` Ilya Verbin
  0 siblings, 1 reply; 21+ messages in thread
From: Jakub Jelinek @ 2014-09-11 11:34 UTC (permalink / raw)
  To: Ilya Verbin; +Cc: gcc-patches, Kirill Yukhin

On Thu, Sep 11, 2014 at 03:28:02PM +0400, Ilya Verbin wrote:
> I would like to start merging offloading-related patches from gomp-4_0-branch to trunk.
> This is the first patch (from r202620), which adds a splay tree and memory mapping to libgomp.
> I removed temporarily device 257 from it.  Bootstrapped and regtested on x86_64-linux.

I think it is not useful to split patches on in which sequence they were
added to the tree.  I'd prefer patches for functional parts for the
differences between trunk and corresponding offloading branch.
So, one patch should be all the libgomp changes except for addition of
plugins, another one generic middle-end changes, then the libmicoffload
support library, then libgomp plugin for Intel MIC and finally rest of Intel
MIC enablements.  E.g. the patch you've posted contains tons of FIXMEs that
really shouldn't make into the trunk, not even short lived.

	Jakub

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 1/n] OpenMP 4.0 offloading infrastructure
@ 2014-09-11 11:28 Ilya Verbin
  2014-09-11 11:34 ` Jakub Jelinek
  0 siblings, 1 reply; 21+ messages in thread
From: Ilya Verbin @ 2014-09-11 11:28 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches, Kirill Yukhin

Hello,

I would like to start merging offloading-related patches from gomp-4_0-branch to trunk.
This is the first patch (from r202620), which adds a splay tree and memory mapping to libgomp.
I removed temporarily device 257 from it.  Bootstrapped and regtested on x86_64-linux.

2014-09-11  Jakub Jelinek  <jakub@redhat.com>

	* splay-tree.h: New file.
	* target.c (splay_tree_node, splay_tree, splay_tree_key): New typedefs.
	(struct target_mem_desc, struct splay_tree_key_s): New structures.
	(splay_compare): New inline function.
	(resolve_device): Use default_device_var ICV.
	(dev_splay_tree, dev_env_lock): New variables.
	(gomp_map_vars_existing, gomp_map_vars, gomp_unmap_tgt,
	gomp_unmap_vars, gomp_update): New functions.
	(GOMP_target): Arrange for host callback to be performed in a
	separate initial thread and contention group, inheriting ICVs from
	gomp_global_icv etc.
	(GOMP_target_data): Use gomp_map_vars.
	(GOMP_target_end_data): Use gomp_unmap_vars.
	(GOMP_target_update): Use gomp_update.

Thanks,
  -- Ilya

---

diff --git a/libgomp/splay-tree.h b/libgomp/splay-tree.h
new file mode 100644
index 0000000..eb8011a
--- /dev/null
+++ b/libgomp/splay-tree.h
@@ -0,0 +1,232 @@
+/* A splay-tree datatype.
+   Copyright 1998-2014
+   Free Software Foundation, Inc.
+   Contributed by Mark Mitchell (mark@markmitchell.com).
+
+   This file is part of the GNU OpenMP Library (libgomp).
+
+   Libgomp 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.
+
+   Libgomp 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.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* The splay tree code copied from include/splay-tree.h and adjusted,
+   so that all the data lives directly in splay_tree_node_s structure
+   and no extra allocations are needed.
+
+   Files including this header should before including it add:
+typedef struct splay_tree_node_s *splay_tree_node;
+typedef struct splay_tree_s *splay_tree;
+typedef struct splay_tree_key_s *splay_tree_key;
+   define splay_tree_key_s structure, and define
+   splay_compare inline function.  */
+
+/* For an easily readable description of splay-trees, see:
+
+     Lewis, Harry R. and Denenberg, Larry.  Data Structures and Their
+     Algorithms.  Harper-Collins, Inc.  1991.
+
+   The major feature of splay trees is that all basic tree operations
+   are amortized O(log n) time for a tree with n nodes.  */
+
+/* The nodes in the splay tree.  */
+struct splay_tree_node_s {
+  struct splay_tree_key_s key;
+  /* The left and right children, respectively.  */
+  splay_tree_node left;
+  splay_tree_node right;
+};
+
+/* The splay tree.  */
+struct splay_tree_s {
+  splay_tree_node root;
+};
+
+/* Rotate the edge joining the left child N with its parent P.  PP is the
+   grandparents' pointer to P.  */
+
+static inline void
+rotate_left (splay_tree_node *pp, splay_tree_node p, splay_tree_node n)
+{
+  splay_tree_node tmp;
+  tmp = n->right;
+  n->right = p;
+  p->left = tmp;
+  *pp = n;
+}
+
+/* Rotate the edge joining the right child N with its parent P.  PP is the
+   grandparents' pointer to P.  */
+
+static inline void
+rotate_right (splay_tree_node *pp, splay_tree_node p, splay_tree_node n)
+{
+  splay_tree_node tmp;
+  tmp = n->left;
+  n->left = p;
+  p->right = tmp;
+  *pp = n;
+}
+
+/* Bottom up splay of KEY.  */
+
+static void
+splay_tree_splay (splay_tree sp, splay_tree_key key)
+{
+  if (sp->root == NULL)
+    return;
+
+  do {
+    int cmp1, cmp2;
+    splay_tree_node n, c;
+
+    n = sp->root;
+    cmp1 = splay_compare (key, &n->key);
+
+    /* Found.  */
+    if (cmp1 == 0)
+      return;
+
+    /* Left or right?  If no child, then we're done.  */
+    if (cmp1 < 0)
+      c = n->left;
+    else
+      c = n->right;
+    if (!c)
+      return;
+
+    /* Next one left or right?  If found or no child, we're done
+       after one rotation.  */
+    cmp2 = splay_compare (key, &c->key);
+    if (cmp2 == 0
+	|| (cmp2 < 0 && !c->left)
+	|| (cmp2 > 0 && !c->right))
+      {
+	if (cmp1 < 0)
+	  rotate_left (&sp->root, n, c);
+	else
+	  rotate_right (&sp->root, n, c);
+	return;
+      }
+
+    /* Now we have the four cases of double-rotation.  */
+    if (cmp1 < 0 && cmp2 < 0)
+      {
+	rotate_left (&n->left, c, c->left);
+	rotate_left (&sp->root, n, n->left);
+      }
+    else if (cmp1 > 0 && cmp2 > 0)
+      {
+	rotate_right (&n->right, c, c->right);
+	rotate_right (&sp->root, n, n->right);
+      }
+    else if (cmp1 < 0 && cmp2 > 0)
+      {
+	rotate_right (&n->left, c, c->right);
+	rotate_left (&sp->root, n, n->left);
+      }
+    else if (cmp1 > 0 && cmp2 < 0)
+      {
+	rotate_left (&n->right, c, c->left);
+	rotate_right (&sp->root, n, n->right);
+      }
+  } while (1);
+}
+
+/* Insert a new NODE into SP.  The NODE shouldn't exist in the tree.  */
+
+static void
+splay_tree_insert (splay_tree sp, splay_tree_node node)
+{
+  int comparison = 0;
+
+  splay_tree_splay (sp, &node->key);
+
+  if (sp->root)
+    comparison = splay_compare (&sp->root->key, &node->key);
+
+  if (sp->root && comparison == 0)
+    abort ();
+  else
+    {
+      /* Insert it at the root.  */
+      if (sp->root == NULL)
+	node->left = node->right = NULL;
+      else if (comparison < 0)
+	{
+	  node->left = sp->root;
+	  node->right = node->left->right;
+	  node->left->right = NULL;
+	}
+      else
+	{
+	  node->right = sp->root;
+	  node->left = node->right->left;
+	  node->right->left = NULL;
+	}
+
+      sp->root = node;
+    }
+}
+
+/* Remove node with KEY from SP.  It is not an error if it did not exist.  */
+
+static void
+splay_tree_remove (splay_tree sp, splay_tree_key key)
+{
+  splay_tree_splay (sp, key);
+
+  if (sp->root && splay_compare (&sp->root->key, key) == 0)
+    {
+      splay_tree_node left, right;
+
+      left = sp->root->left;
+      right = sp->root->right;
+
+      /* One of the children is now the root.  Doesn't matter much
+	 which, so long as we preserve the properties of the tree.  */
+      if (left)
+	{
+	  sp->root = left;
+
+	  /* If there was a right child as well, hang it off the
+	     right-most leaf of the left child.  */
+	  if (right)
+	    {
+	      while (left->right)
+		left = left->right;
+	      left->right = right;
+	    }
+	}
+      else
+	sp->root = right;
+    }
+}
+
+/* Lookup KEY in SP, returning NODE if present, and NULL
+   otherwise.  */
+
+static splay_tree_key
+splay_tree_lookup (splay_tree sp, splay_tree_key key)
+{
+  splay_tree_splay (sp, key);
+
+  if (sp->root && splay_compare (&sp->root->key, key) == 0)
+    return &sp->root->key;
+  else
+    return NULL;
+}
diff --git a/libgomp/target.c b/libgomp/target.c
index 46acc58..0ead8f4 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -31,12 +31,381 @@
 #include <stdlib.h>
 #include <string.h>
 
+/* Forward declaration for a node in the tree.  */
+typedef struct splay_tree_node_s *splay_tree_node;
+typedef struct splay_tree_s *splay_tree;
+typedef struct splay_tree_key_s *splay_tree_key;
+
+struct target_mem_desc {
+  /* Reference count.  */
+  uintptr_t refcount;
+  /* All the splay nodes allocated together.  */
+  splay_tree_node array;
+  /* Start of the target region.  */
+  uintptr_t tgt_start;
+  /* End of the targer region.  */
+  uintptr_t tgt_end;
+  /* Handle to free.  */
+  void *to_free;
+  /* Previous target_mem_desc.  */
+  struct target_mem_desc *prev;
+  /* Number of items in following list.  */
+  size_t list_count;
+  /* List of splay keys to remove (or decrease refcount)
+     at the end of region.  */
+  splay_tree_key list[];
+};
+
+struct splay_tree_key_s {
+  /* Address of the host object.  */
+  uintptr_t host_start;
+  /* Address immediately after the host object.  */
+  uintptr_t host_end;
+  /* Descriptor of the target memory.  */
+  struct target_mem_desc *tgt;
+  /* Offset from tgt->tgt_start to the start of the target object.  */
+  uintptr_t tgt_offset;
+  /* Reference count.  */
+  uintptr_t refcount;
+  /* True if data should be copied from device to host at the end.  */
+  bool copy_from;
+};
+
+/* The comparison function.  */
+
+static int
+splay_compare (splay_tree_key x, splay_tree_key y)
+{
+  if (x->host_start == x->host_end
+      && y->host_start == y->host_end)
+    return 0;
+  if (x->host_end <= y->host_start)
+    return -1;
+  if (x->host_start >= y->host_end)
+    return 1;
+  return 0;
+}
+
+#include "splay-tree.h"
+
 attribute_hidden int
 gomp_get_num_devices (void)
 {
+  /* FIXME: Scan supported accelerators when called the first time.  */
   return 0;
 }
 
+static int
+resolve_device (int device)
+{
+  if (device == -1)
+    {
+      struct gomp_task_icv *icv = gomp_icv (false);
+      device = icv->default_device_var;
+    }
+  if (device < 0 || device >= gomp_get_num_devices ())
+    return -1;
+
+  /* FIXME: Return device descriptor.  */
+  return -1;
+}
+
+/* These variables would be per-accelerator (which doesn't have shared address
+   space.  */
+static struct splay_tree_s dev_splay_tree;
+static gomp_mutex_t dev_env_lock;
+
+/* Handle the case where splay_tree_lookup found oldn for newn.
+   Helper function of gomp_map_vars.  */
+
+static inline void
+gomp_map_vars_existing (splay_tree_key oldn, splay_tree_key newn,
+			unsigned char kind)
+{
+  if (oldn->host_start > newn->host_start
+      || oldn->host_end < newn->host_end)
+    gomp_fatal ("Trying to map into device [%p..%p) object when"
+		"[%p..%p) is already mapped",
+		(void *) newn->host_start, (void *) newn->host_end,
+		(void *) oldn->host_start, (void *) oldn->host_end);
+  oldn->refcount++;
+}
+
+static struct target_mem_desc *
+gomp_map_vars (size_t mapnum, void **hostaddrs, size_t *sizes,
+	       unsigned char *kinds, bool is_target)
+{
+  size_t i, tgt_align, tgt_size, not_found_cnt = 0;
+  struct splay_tree_key_s cur_node;
+  struct target_mem_desc *tgt
+    = gomp_malloc (sizeof (*tgt) + sizeof (tgt->list[0]) * mapnum);
+  tgt->list_count = mapnum;
+  tgt->refcount = 1;
+
+  if (mapnum == 0)
+    return tgt;
+
+  tgt_align = sizeof (void *);
+  tgt_size = 0;
+  if (is_target)
+    {
+      size_t align = 4 * sizeof (void *);
+      tgt_align = align;
+      tgt_size = mapnum * sizeof (void *);
+    }
+
+  gomp_mutex_lock (&dev_env_lock);
+  for (i = 0; i < mapnum; i++)
+    {
+      cur_node.host_start = (uintptr_t) hostaddrs[i];
+      if ((kinds[i] & 7) != 4)
+	cur_node.host_end = cur_node.host_start + sizes[i];
+      else
+	cur_node.host_end = cur_node.host_start + sizeof (void *);
+      splay_tree_key n = splay_tree_lookup (&dev_splay_tree, &cur_node);
+      if (n)
+	{
+	  tgt->list[i] = n;
+	  gomp_map_vars_existing (n, &cur_node, kinds[i]);
+	}
+      else
+	{
+	  size_t align = (size_t) 1 << (kinds[i] >> 3);
+	  tgt->list[i] = NULL;
+	  not_found_cnt++;
+	  if (tgt_align < align)
+	    tgt_align = align;
+	  tgt_size = (tgt_size + align - 1) & ~(align - 1);
+	  tgt_size += cur_node.host_end - cur_node.host_start;
+	}
+    }
+
+  if (not_found_cnt || is_target)
+    {
+      /* FIXME: This would be accelerator memory allocation, not
+	 host, and should allocate tgt_align aligned tgt_size block
+	 of memory.  */
+      tgt->to_free = gomp_malloc (tgt_size + tgt_align - 1);
+      tgt->tgt_start = (uintptr_t) tgt->to_free;
+      tgt->tgt_start = (tgt->tgt_start + tgt_align - 1) & ~(tgt_align - 1);
+      tgt->tgt_end = tgt->tgt_start + tgt_size;
+    }
+  else
+    {
+      tgt->to_free = NULL;
+      tgt->tgt_start = 0;
+      tgt->tgt_end = 0;
+    }
+
+  tgt_size = 0;
+  if (is_target)
+    tgt_size = mapnum * sizeof (void *);
+
+  tgt->array = NULL;
+  if (not_found_cnt)
+    {
+      tgt->array = gomp_malloc (not_found_cnt * sizeof (*tgt->array));
+      splay_tree_node array = tgt->array;
+
+      for (i = 0; i < mapnum; i++)
+	if (tgt->list[i] == NULL)
+	  {
+	    splay_tree_key k = &array->key;
+	    k->host_start = (uintptr_t) hostaddrs[i];
+	    if ((kinds[i] & 7) != 4)
+	      k->host_end = k->host_start + sizes[i];
+	    else
+	      k->host_end = k->host_start + sizeof (void *);
+	    splay_tree_key n
+	      = splay_tree_lookup (&dev_splay_tree, k);
+	    if (n)
+	      {
+		tgt->list[i] = n;
+		gomp_map_vars_existing (n, k, kinds[i]);
+	      }
+	    else
+	      {
+		size_t align = (size_t) 1 << (kinds[i] >> 3);
+		tgt->list[i] = k;
+		tgt_size = (tgt_size + align - 1) & ~(align - 1);
+		k->tgt = tgt;
+		k->tgt_offset = tgt_size;
+		tgt_size += k->host_end - k->host_start;
+		k->copy_from = false;
+		if ((kinds[i] & 7) == 2 || (kinds[i] & 7) == 3)
+		  k->copy_from = true;
+		k->refcount = 1;
+		tgt->refcount++;
+		array->left = NULL;
+		array->right = NULL;
+		splay_tree_insert (&dev_splay_tree, array);
+		switch (kinds[i] & 7)
+		  {
+		  case 0: /* ALLOC */
+		  case 2: /* FROM */
+		    break;
+		  case 1: /* TO */
+		  case 3: /* TOFROM */
+		    /* FIXME: This is supposed to be copy from host to device
+		       memory.  Perhaps add some smarts, like if copying
+		       several adjacent fields from host to target, use some
+		       host buffer to avoid sending each var individually.  */
+		    memcpy ((void *) (tgt->tgt_start + k->tgt_offset),
+			    (void *) k->host_start,
+			    k->host_end - k->host_start);
+		    break;
+		  case 4: /* POINTER */
+		    cur_node.host_start
+		      = (uintptr_t) *(void **) k->host_start;
+		    /* Add bias to the pointer value.  */
+		    cur_node.host_start += sizes[i];
+		    cur_node.host_end = cur_node.host_start + 1;
+		    n = splay_tree_lookup (&dev_splay_tree, &cur_node);
+		    if (n == NULL)
+		      {
+			/* Could be possibly zero size array section.  */
+			cur_node.host_end--;
+			n = splay_tree_lookup (&dev_splay_tree, &cur_node);
+			if (n == NULL)
+			  {
+			    cur_node.host_start--;
+			    n = splay_tree_lookup (&dev_splay_tree, &cur_node);
+			    cur_node.host_start++;
+			  }
+		      }
+		    if (n == NULL)
+		      gomp_fatal ("Pointer target of array section "
+				  "wasn't mapped");
+		    cur_node.host_start -= n->host_start;
+		    cur_node.tgt_offset = n->tgt->tgt_start + n->tgt_offset
+					  + cur_node.host_start;
+		    /* At this point tgt_offset is target address of the
+		       array section.  Now subtract bias to get what we want
+		       to initialize the pointer with.  */
+		    cur_node.tgt_offset -= sizes[i];
+		    /* FIXME: host to device copy, see above FIXME comment.  */
+		    memcpy ((void *) (tgt->tgt_start + k->tgt_offset),
+			    (void *) &cur_node.tgt_offset,
+			    sizeof (void *));
+		    break;
+		  }
+		array++;
+	      }
+	  }
+    }
+  if (is_target)
+    {
+      for (i = 0; i < mapnum; i++)
+	{
+	  cur_node.tgt_offset = tgt->list[i]->tgt->tgt_start
+				+ tgt->list[i]->tgt_offset;
+	  /* FIXME: host to device copy, see above FIXME comment.  */
+	  memcpy ((void *) (tgt->tgt_start + i * sizeof (void *)),
+		  (void *) &cur_node.tgt_offset,
+		  sizeof (void *));
+	}
+    }
+
+  gomp_mutex_unlock (&dev_env_lock);
+  return tgt;
+}
+
+static void
+gomp_unmap_tgt (struct target_mem_desc *tgt)
+{
+  /* FIXME: Deallocate on target the tgt->tgt_start .. tgt->tgt_end
+     region.  */
+  if (tgt->tgt_end)
+    free (tgt->to_free);
+
+  free (tgt->array);
+  free (tgt);
+}
+
+static void
+gomp_unmap_vars (struct target_mem_desc *tgt)
+{
+  if (tgt->list_count == 0)
+    {
+      free (tgt);
+      return;
+    }
+
+  size_t i;
+  gomp_mutex_lock (&dev_env_lock);
+  for (i = 0; i < tgt->list_count; i++)
+    if (tgt->list[i]->refcount > 1)
+      tgt->list[i]->refcount--;
+    else
+      {
+	splay_tree_key k = tgt->list[i];
+	if (k->copy_from)
+	  /* FIXME: device to host copy.  */
+	  memcpy ((void *) k->host_start,
+		  (void *) (k->tgt->tgt_start + k->tgt_offset),
+		  k->host_end - k->host_start);
+	splay_tree_remove (&dev_splay_tree, k);
+	if (k->tgt->refcount > 1)
+	  k->tgt->refcount--;
+	else
+	  gomp_unmap_tgt (k->tgt);
+      }
+
+  if (tgt->refcount > 1)
+    tgt->refcount--;
+  else
+    gomp_unmap_tgt (tgt);
+  gomp_mutex_unlock (&dev_env_lock);
+}
+
+static void
+gomp_update (size_t mapnum, void **hostaddrs, size_t *sizes,
+	     unsigned char *kinds)
+{
+  size_t i;
+  struct splay_tree_key_s cur_node;
+
+  if (mapnum == 0)
+    return;
+
+  gomp_mutex_lock (&dev_env_lock);
+  for (i = 0; i < mapnum; i++)
+    if (sizes[i])
+      {
+	cur_node.host_start = (uintptr_t) hostaddrs[i];
+	cur_node.host_end = cur_node.host_start + sizes[i];
+	splay_tree_key n = splay_tree_lookup (&dev_splay_tree, &cur_node);
+	if (n)
+	  {
+	    if (n->host_start > cur_node.host_start
+		|| n->host_end < cur_node.host_end)
+	      gomp_fatal ("Trying to update [%p..%p) object when"
+			  "only [%p..%p) is mapped",
+			  (void *) cur_node.host_start,
+			  (void *) cur_node.host_end,
+			  (void *) n->host_start,
+			  (void *) n->host_end);
+	    if ((kinds[i] & 7) == 1)
+	      /* FIXME: host to device copy.  */
+	      memcpy ((void *) (n->tgt->tgt_start + n->tgt_offset
+				+ cur_node.host_start - n->host_start),
+		      (void *) cur_node.host_start,
+		      cur_node.host_end - cur_node.host_start);
+	    else if ((kinds[i] & 7) == 2)
+	      /* FIXME: device to host copy.  */
+	      memcpy ((void *) cur_node.host_start,
+		      (void *) (n->tgt->tgt_start + n->tgt_offset
+				+ cur_node.host_start - n->host_start),
+		      cur_node.host_end - cur_node.host_start);
+	  }
+	else
+	  gomp_fatal ("Trying to update [%p..%p) object that is not mapped",
+		      (void *) cur_node.host_start,
+		      (void *) cur_node.host_end);
+      }
+  gomp_mutex_unlock (&dev_env_lock);
+}
+
 /* Called when encountering a target directive.  If DEVICE
    is -1, it means use device-var ICV.  If it is -2 (or any other value
    larger than last available hw device, use host fallback.
@@ -52,7 +421,26 @@ GOMP_target (int device, void (*fn) (void *), const void *openmp_target,
 	     size_t mapnum, void **hostaddrs, size_t *sizes,
 	     unsigned char *kinds)
 {
-  /* Host fallback.  */
+  device = resolve_device (device);
+  if (device == -1)
+    {
+      /* Host fallback.  */
+      struct gomp_thread old_thr, *thr = gomp_thread ();
+      old_thr = *thr;
+      memset (thr, '\0', sizeof (*thr));
+      if (gomp_places_list)
+	{
+	  thr->place = old_thr.place;
+	  thr->ts.place_partition_len = gomp_places_list_len;
+	}
+      fn (hostaddrs);
+      gomp_free_thread (thr);
+      *thr = old_thr;
+      return;
+    }
+
+  struct target_mem_desc *tgt
+    = gomp_map_vars (mapnum, hostaddrs, sizes, kinds, true);
   struct gomp_thread old_thr, *thr = gomp_thread ();
   old_thr = *thr;
   memset (thr, '\0', sizeof (*thr));
@@ -61,26 +449,63 @@ GOMP_target (int device, void (*fn) (void *), const void *openmp_target,
       thr->place = old_thr.place;
       thr->ts.place_partition_len = gomp_places_list_len;
     }
-  fn (hostaddrs);
+  fn ((void *) tgt->tgt_start);
   gomp_free_thread (thr);
   *thr = old_thr;
+  gomp_unmap_vars (tgt);
 }
 
 void
 GOMP_target_data (int device, const void *openmp_target, size_t mapnum,
 		  void **hostaddrs, size_t *sizes, unsigned char *kinds)
 {
+  device = resolve_device (device);
+  if (device == -1)
+    {
+      /* Host fallback.  */
+      struct gomp_task_icv *icv = gomp_icv (false);
+      if (icv->target_data)
+	{
+	  /* Even when doing a host fallback, if there are any active
+	     #pragma omp target data constructs, need to remember the
+	     new #pragma omp target data, otherwise GOMP_target_end_data
+	     would get out of sync.  */
+	  struct target_mem_desc *tgt
+	    = gomp_map_vars (0, NULL, NULL, NULL, false);
+	  tgt->prev = icv->target_data;
+	  icv->target_data = tgt;
+	}
+      return;
+    }
+
+  struct target_mem_desc *tgt
+    = gomp_map_vars (mapnum, hostaddrs, sizes, kinds, false);
+  struct gomp_task_icv *icv = gomp_icv (true);
+  tgt->prev = icv->target_data;
+  icv->target_data = tgt;
 }
 
 void
 GOMP_target_end_data (void)
 {
+  struct gomp_task_icv *icv = gomp_icv (false);
+  if (icv->target_data)
+    {
+      struct target_mem_desc *tgt = icv->target_data;
+      icv->target_data = tgt->prev;
+      gomp_unmap_vars (tgt);
+    }
 }
 
 void
 GOMP_target_update (int device, const void *openmp_target, size_t mapnum,
 		    void **hostaddrs, size_t *sizes, unsigned char *kinds)
 {
+  device = resolve_device (device);
+  if (device == -1)
+    return;
+
+  gomp_update (mapnum, hostaddrs, sizes, kinds);
 }
 
 void
-- 

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2015-02-25 19:35 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-15 16:52 [PATCH 1/n] OpenMP 4.0 offloading infrastructure Ilya Verbin
2014-09-17 13:46 ` Jakub Jelinek
2014-09-26 12:36   ` Ilya Verbin
2014-09-26 22:03     ` Joseph S. Myers
2014-09-30 10:11     ` Jakub Jelinek
2014-09-30 11:16     ` Thomas Schwinge
2014-10-01 16:06       ` Ilya Verbin
2014-12-12  8:14       ` Thomas Schwinge
2014-12-12  8:17         ` Jakub Jelinek
2014-12-15  9:07           ` Kirill Yukhin
2015-02-19 11:43     ` Thomas Schwinge
2015-02-20 14:40       ` Ilya Verbin
2015-02-20 14:43         ` Thomas Schwinge
2015-02-20 15:05           ` Jakub Jelinek
2015-02-25 20:09             ` Ilya Verbin
2015-02-20 19:47         ` Mike Stump
2015-02-20 19:49           ` Thomas Schwinge
2015-02-21 12:12             ` Iain Sandoe
  -- strict thread matches above, loose matches on Subject: below --
2014-09-11 11:28 Ilya Verbin
2014-09-11 11:34 ` Jakub Jelinek
2014-09-11 12:27   ` Ilya Verbin

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