Go Gcc_backend class: mark prefetch as novops
authorIan Lance Taylor <iant@golang.org>
Wed, 15 Apr 2020 19:59:52 +0000 (12:59 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 15 Apr 2020 20:01:25 +0000 (13:01 -0700)
PR go/94607
* go-gcc.cc (class Gcc_backend): Define builtin_const,
builtin_noreturn, builtin_novops.
(Gcc_backend::define_builtin): Change const_p and noreturn_p
parameters to a single flags parameter.  Change all callers.
(Gcc_backend::Gcc_backend): Pass novops for prefetch.

gcc/go/ChangeLog
gcc/go/go-gcc.cc

index fc73347f9baff228e1048335e4708ec8b299f101..5be05e908e68a78048c94f9ad28354137c62736e 100644 (file)
@@ -1,3 +1,12 @@
+2020-04-15  Ian Lance Taylor  <iant@golang.org>
+
+       PR go/94607
+       * go-gcc.cc (class Gcc_backend): Define builtin_const,
+       builtin_noreturn, builtin_novops.
+       (Gcc_backend::define_builtin): Change const_p and noreturn_p
+       parameters to a single flags parameter.  Change all callers.
+       (Gcc_backend::Gcc_backend): Pass novops for prefetch.
+
 2020-01-01  Jakub Jelinek  <jakub@redhat.com>
 
        Update copyright years.
index 0960894671f0b6457f2b285afd6694673d82f304..fd96481b12df62d1b1959ecdf736101861d679a8 100644 (file)
@@ -541,9 +541,13 @@ class Gcc_backend : public Backend
   convert_tree(tree, tree, Location);
 
 private:
+  static const int builtin_const = 1 << 0;
+  static const int builtin_noreturn = 1 << 1;
+  static const int builtin_novops = 1 << 2;
+
   void
   define_builtin(built_in_function bcode, const char* name, const char* libname,
-                tree fntype, bool const_p, bool noreturn_p);
+                tree fntype, int flags);
 
   // A mapping of the GCC built-ins exposed to GCCGo.
   std::map<std::string, Bfunction*> builtin_functions_;
@@ -566,26 +570,22 @@ Gcc_backend::Gcc_backend()
   tree t = this->integer_type(true, BITS_PER_UNIT)->get_tree();
   tree p = build_pointer_type(build_qualified_type(t, TYPE_QUAL_VOLATILE));
   this->define_builtin(BUILT_IN_SYNC_ADD_AND_FETCH_1, "__sync_fetch_and_add_1",
-                      NULL, build_function_type_list(t, p, t, NULL_TREE),
-                      false, false);
+                      NULL, build_function_type_list(t, p, t, NULL_TREE), 0);
 
   t = this->integer_type(true, BITS_PER_UNIT * 2)->get_tree();
   p = build_pointer_type(build_qualified_type(t, TYPE_QUAL_VOLATILE));
   this->define_builtin(BUILT_IN_SYNC_ADD_AND_FETCH_2, "__sync_fetch_and_add_2",
-                      NULL, build_function_type_list(t, p, t, NULL_TREE),
-                      false, false);
+                      NULL, build_function_type_list(t, p, t, NULL_TREE), 0);
 
   t = this->integer_type(true, BITS_PER_UNIT * 4)->get_tree();
   p = build_pointer_type(build_qualified_type(t, TYPE_QUAL_VOLATILE));
   this->define_builtin(BUILT_IN_SYNC_ADD_AND_FETCH_4, "__sync_fetch_and_add_4",
-                      NULL, build_function_type_list(t, p, t, NULL_TREE),
-                      false, false);
+                      NULL, build_function_type_list(t, p, t, NULL_TREE), 0);
 
   t = this->integer_type(true, BITS_PER_UNIT * 8)->get_tree();
   p = build_pointer_type(build_qualified_type(t, TYPE_QUAL_VOLATILE));
   this->define_builtin(BUILT_IN_SYNC_ADD_AND_FETCH_8, "__sync_fetch_and_add_8",
-                      NULL, build_function_type_list(t, p, t, NULL_TREE),
-                      false, false);
+                      NULL, build_function_type_list(t, p, t, NULL_TREE), 0);
 
   // We use __builtin_expect for magic import functions.
   this->define_builtin(BUILT_IN_EXPECT, "__builtin_expect", NULL,
@@ -593,7 +593,7 @@ Gcc_backend::Gcc_backend()
                                                long_integer_type_node,
                                                long_integer_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
 
   // We use __builtin_memcmp for struct comparisons.
   this->define_builtin(BUILT_IN_MEMCMP, "__builtin_memcmp", "memcmp",
@@ -602,7 +602,7 @@ Gcc_backend::Gcc_backend()
                                                const_ptr_type_node,
                                                size_type_node,
                                                NULL_TREE),
-                      false, false);
+                      0);
 
   // We use __builtin_memmove for copying data.
   this->define_builtin(BUILT_IN_MEMMOVE, "__builtin_memmove", "memmove",
@@ -611,7 +611,7 @@ Gcc_backend::Gcc_backend()
                                                const_ptr_type_node,
                                                size_type_node,
                                                NULL_TREE),
-                      false, false);
+                      0);
 
   // We use __builtin_memset for zeroing data.
   this->define_builtin(BUILT_IN_MEMSET, "__builtin_memset", "memset",
@@ -620,54 +620,54 @@ Gcc_backend::Gcc_backend()
                                                integer_type_node,
                                                size_type_node,
                                                NULL_TREE),
-                      false, false);
+                      0);
 
   // Used by runtime/internal/sys and math/bits.
   this->define_builtin(BUILT_IN_CTZ, "__builtin_ctz", "ctz",
                       build_function_type_list(integer_type_node,
                                                unsigned_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
   this->define_builtin(BUILT_IN_CTZLL, "__builtin_ctzll", "ctzll",
                       build_function_type_list(integer_type_node,
                                                long_long_unsigned_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
   this->define_builtin(BUILT_IN_CLZ, "__builtin_clz", "clz",
                       build_function_type_list(integer_type_node,
                                                unsigned_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
   this->define_builtin(BUILT_IN_CLZLL, "__builtin_clzll", "clzll",
                       build_function_type_list(integer_type_node,
                                                long_long_unsigned_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
   this->define_builtin(BUILT_IN_POPCOUNT, "__builtin_popcount", "popcount",
                       build_function_type_list(integer_type_node,
                                                unsigned_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
   this->define_builtin(BUILT_IN_POPCOUNTLL, "__builtin_popcountll", "popcountll",
                       build_function_type_list(integer_type_node,
                                                long_long_unsigned_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
   this->define_builtin(BUILT_IN_BSWAP16, "__builtin_bswap16", "bswap16",
                       build_function_type_list(uint16_type_node,
                                                uint16_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
   this->define_builtin(BUILT_IN_BSWAP32, "__builtin_bswap32", "bswap32",
                       build_function_type_list(uint32_type_node,
                                                uint32_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
   this->define_builtin(BUILT_IN_BSWAP64, "__builtin_bswap64", "bswap64",
                       build_function_type_list(uint64_type_node,
                                                uint64_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
 
   // We provide some functions for the math library.
   tree math_function_type = build_function_type_list(double_type_node,
@@ -684,104 +684,104 @@ Gcc_backend::Gcc_backend()
     build_function_type_list(long_double_type_node, long_double_type_node,
                             long_double_type_node, NULL_TREE);
   this->define_builtin(BUILT_IN_ACOS, "__builtin_acos", "acos",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_ACOSL, "__builtin_acosl", "acosl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_ASIN, "__builtin_asin", "asin",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_ASINL, "__builtin_asinl", "asinl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_ATAN, "__builtin_atan", "atan",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_ATANL, "__builtin_atanl", "atanl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_ATAN2, "__builtin_atan2", "atan2",
-                      math_function_type_two, true, false);
+                      math_function_type_two, builtin_const);
   this->define_builtin(BUILT_IN_ATAN2L, "__builtin_atan2l", "atan2l",
-                      math_function_type_long_two, true, false);
+                      math_function_type_long_two, builtin_const);
   this->define_builtin(BUILT_IN_CEIL, "__builtin_ceil", "ceil",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_CEILL, "__builtin_ceill", "ceill",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_COS, "__builtin_cos", "cos",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_COSL, "__builtin_cosl", "cosl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_EXP, "__builtin_exp", "exp",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_EXPL, "__builtin_expl", "expl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_EXPM1, "__builtin_expm1", "expm1",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_EXPM1L, "__builtin_expm1l", "expm1l",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_FABS, "__builtin_fabs", "fabs",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_FABSL, "__builtin_fabsl", "fabsl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_FLOOR, "__builtin_floor", "floor",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_FLOORL, "__builtin_floorl", "floorl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_FMOD, "__builtin_fmod", "fmod",
-                      math_function_type_two, true, false);
+                      math_function_type_two, builtin_const);
   this->define_builtin(BUILT_IN_FMODL, "__builtin_fmodl", "fmodl",
-                      math_function_type_long_two, true, false);
+                      math_function_type_long_two, builtin_const);
   this->define_builtin(BUILT_IN_LDEXP, "__builtin_ldexp", "ldexp",
                       build_function_type_list(double_type_node,
                                                double_type_node,
                                                integer_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
   this->define_builtin(BUILT_IN_LDEXPL, "__builtin_ldexpl", "ldexpl",
                       build_function_type_list(long_double_type_node,
                                                long_double_type_node,
                                                integer_type_node,
                                                NULL_TREE),
-                      true, false);
+                      builtin_const);
   this->define_builtin(BUILT_IN_LOG, "__builtin_log", "log",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_LOGL, "__builtin_logl", "logl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_LOG1P, "__builtin_log1p", "log1p",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_LOG1PL, "__builtin_log1pl", "log1pl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_LOG10, "__builtin_log10", "log10",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_LOG10L, "__builtin_log10l", "log10l",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_LOG2, "__builtin_log2", "log2",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_LOG2L, "__builtin_log2l", "log2l",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_SIN, "__builtin_sin", "sin",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_SINL, "__builtin_sinl", "sinl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_SQRT, "__builtin_sqrt", "sqrt",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_SQRTL, "__builtin_sqrtl", "sqrtl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_TAN, "__builtin_tan", "tan",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_TANL, "__builtin_tanl", "tanl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
   this->define_builtin(BUILT_IN_TRUNC, "__builtin_trunc", "trunc",
-                      math_function_type, true, false);
+                      math_function_type, builtin_const);
   this->define_builtin(BUILT_IN_TRUNCL, "__builtin_truncl", "truncl",
-                      math_function_type_long, true, false);
+                      math_function_type_long, builtin_const);
 
   // We use __builtin_return_address in the thunk we build for
   // functions which call recover, and for runtime.getcallerpc.
   t = build_function_type_list(ptr_type_node, unsigned_type_node, NULL_TREE);
   this->define_builtin(BUILT_IN_RETURN_ADDRESS, "__builtin_return_address",
-                      NULL, t, false, false);
+                      NULL, t, 0);
 
   // The runtime calls __builtin_dwarf_cfa for runtime.getcallersp.
   t = build_function_type_list(ptr_type_node, NULL_TREE);
   this->define_builtin(BUILT_IN_DWARF_CFA, "__builtin_dwarf_cfa",
-                      NULL, t, false, false);
+                      NULL, t, 0);
 
   // The runtime calls __builtin_extract_return_addr when recording
   // the address to which a function returns.
@@ -790,26 +790,26 @@ Gcc_backend::Gcc_backend()
                       build_function_type_list(ptr_type_node,
                                                ptr_type_node,
                                                NULL_TREE),
-                      false, false);
+                      0);
 
   // The compiler uses __builtin_trap for some exception handling
   // cases.
   this->define_builtin(BUILT_IN_TRAP, "__builtin_trap", NULL,
                       build_function_type(void_type_node, void_list_node),
-                      false, true);
+                      builtin_noreturn);
 
   // The runtime uses __builtin_prefetch.
   this->define_builtin(BUILT_IN_PREFETCH, "__builtin_prefetch", NULL,
                       build_varargs_function_type_list(void_type_node,
                                                        const_ptr_type_node,
                                                        NULL_TREE),
-                      false, false);
+                      builtin_novops);
 
   // The compiler uses __builtin_unreachable for cases that cannot
   // occur.
   this->define_builtin(BUILT_IN_UNREACHABLE, "__builtin_unreachable", NULL,
                       build_function_type(void_type_node, void_list_node),
-                      true, true);
+                      builtin_const | builtin_noreturn);
 
   // We provide some atomic functions.
   t = build_function_type_list(uint32_type_node,
@@ -817,14 +817,14 @@ Gcc_backend::Gcc_backend()
                                integer_type_node,
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_LOAD_4, "__atomic_load_4", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(uint64_type_node,
                                ptr_type_node,
                                integer_type_node,
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_LOAD_8, "__atomic_load_8", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(void_type_node,
                                ptr_type_node,
@@ -832,7 +832,7 @@ Gcc_backend::Gcc_backend()
                                integer_type_node,
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_STORE_4, "__atomic_store_4", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(void_type_node,
                                ptr_type_node,
@@ -840,7 +840,7 @@ Gcc_backend::Gcc_backend()
                                integer_type_node,
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_STORE_8, "__atomic_store_8", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(uint32_type_node,
                                ptr_type_node,
@@ -848,7 +848,7 @@ Gcc_backend::Gcc_backend()
                                integer_type_node,
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_EXCHANGE_4, "__atomic_exchange_4", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(uint64_type_node,
                                ptr_type_node,
@@ -856,7 +856,7 @@ Gcc_backend::Gcc_backend()
                                integer_type_node,
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_EXCHANGE_8, "__atomic_exchange_8", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(boolean_type_node,
                                ptr_type_node,
@@ -868,7 +868,7 @@ Gcc_backend::Gcc_backend()
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_COMPARE_EXCHANGE_4,
                        "__atomic_compare_exchange_4", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(boolean_type_node,
                                ptr_type_node,
@@ -880,7 +880,7 @@ Gcc_backend::Gcc_backend()
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_COMPARE_EXCHANGE_8,
                        "__atomic_compare_exchange_8", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(uint32_type_node,
                                ptr_type_node,
@@ -888,7 +888,7 @@ Gcc_backend::Gcc_backend()
                                integer_type_node,
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_ADD_FETCH_4, "__atomic_add_fetch_4", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(uint64_type_node,
                                ptr_type_node,
@@ -896,7 +896,7 @@ Gcc_backend::Gcc_backend()
                                integer_type_node,
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_ADD_FETCH_8, "__atomic_add_fetch_8", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(unsigned_char_type_node,
                                ptr_type_node,
@@ -904,9 +904,9 @@ Gcc_backend::Gcc_backend()
                                integer_type_node,
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_AND_FETCH_1, "__atomic_and_fetch_1", NULL,
-                       t, false, false);
+                       t, 0);
   this->define_builtin(BUILT_IN_ATOMIC_FETCH_AND_1, "__atomic_fetch_and_1", NULL,
-                       t, false, false);
+                       t, 0);
 
   t = build_function_type_list(unsigned_char_type_node,
                                ptr_type_node,
@@ -914,9 +914,9 @@ Gcc_backend::Gcc_backend()
                                integer_type_node,
                                NULL_TREE);
   this->define_builtin(BUILT_IN_ATOMIC_OR_FETCH_1, "__atomic_or_fetch_1", NULL,
-                       t, false, false);
+                       t, 0);
   this->define_builtin(BUILT_IN_ATOMIC_FETCH_OR_1, "__atomic_fetch_or_1", NULL,
-                       t, false, false);
+                       t, 0);
 }
 
 // Get an unnamed integer type.
@@ -3482,25 +3482,28 @@ Gcc_backend::write_export_data(const char* bytes, unsigned int size)
 
 void
 Gcc_backend::define_builtin(built_in_function bcode, const char* name,
-                           const char* libname, tree fntype, bool const_p,
-                           bool noreturn_p)
+                           const char* libname, tree fntype, int flags)
 {
   tree decl = add_builtin_function(name, fntype, bcode, BUILT_IN_NORMAL,
                                   libname, NULL_TREE);
-  if (const_p)
+  if ((flags & builtin_const) != 0)
     TREE_READONLY(decl) = 1;
-  if (noreturn_p)
+  if ((flags & builtin_noreturn) != 0)
     TREE_THIS_VOLATILE(decl) = 1;
+  if ((flags & builtin_novops) != 0)
+    DECL_IS_NOVOPS(decl) = 1;
   set_builtin_decl(bcode, decl, true);
   this->builtin_functions_[name] = this->make_function(decl);
   if (libname != NULL)
     {
       decl = add_builtin_function(libname, fntype, bcode, BUILT_IN_NORMAL,
                                  NULL, NULL_TREE);
-      if (const_p)
+      if ((flags & builtin_const) != 0)
        TREE_READONLY(decl) = 1;
-      if (noreturn_p)
+      if ((flags & builtin_noreturn) != 0)
        TREE_THIS_VOLATILE(decl) = 1;
+      if ((flags & builtin_novops) != 0)
+       DECL_IS_NOVOPS(decl) = 1;
       this->builtin_functions_[libname] = this->make_function(decl);
     }
 }