Avoid streaming-out target-specific integer modes with offloading enabled.

The patch falls back to using BLKmode for ARRAY_TYPE if offloading is enabled,
and avoids streaming-out OImode in lto_write_mode_table. I used
default_scalar_mode_supported_p check to test if the mode is "generic",
but not sure if that's entirely correct.

Signed-off-by: Prathamesh Kulkarni <prathameshk@nvidia.com>

diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc
index 8b4bf9659cb..f06c5a1945e 100644
--- a/gcc/lto-streamer-out.cc
+++ b/gcc/lto-streamer-out.cc
@@ -48,6 +48,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "output.h"
 #include "ipa-utils.h"
 #include "toplev.h"
+#include "targhooks.h"
 
 
 static void lto_write_tree (struct output_block*, tree, bool);
@@ -3215,6 +3216,13 @@ lto_write_mode_table (void)
 	  machine_mode m = (machine_mode) i;
 	  if ((GET_MODE_INNER (m) == m) ^ (pass == 0))
 	    continue;
+
+	  /* Avoid streaming target-specific integer modes like OImode.  */
+	  if (GET_MODE_CLASS (m) == MODE_INT
+	      && lto_stream_offload_p
+	      && !default_scalar_mode_supported_p (as_a <scalar_mode> (m)))
+	    continue;
+
 	  bp_pack_value (&bp, m, mode_bits);
 	  bp_pack_enum (&bp, mode_class, MAX_MODE_CLASS, GET_MODE_CLASS (m));
 	  bp_pack_poly_value (&bp, GET_MODE_SIZE (m), 16);
diff --git a/gcc/tree-streamer-out.cc b/gcc/tree-streamer-out.cc
index b7205287ffb..2d3730f5b69 100644
--- a/gcc/tree-streamer-out.cc
+++ b/gcc/tree-streamer-out.cc
@@ -320,7 +320,11 @@ pack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
   /* for VECTOR_TYPE, TYPE_MODE reevaluates the mode using target_flags
      not necessary valid in a global context.
      Use the raw value previously set by layout_type.  */
-  bp_pack_machine_mode (bp, TYPE_MODE_RAW (expr));
+  if (TREE_CODE (expr) == ARRAY_TYPE
+      && lto_stream_offload_p)
+    bp_pack_machine_mode (bp, BLKmode);
+  else
+    bp_pack_machine_mode (bp, TYPE_MODE_RAW (expr));
   /* TYPE_NO_FORCE_BLK is private to stor-layout and need
      no streaming.  */
   bp_pack_value (bp, TYPE_PACKED (expr), 1);
