]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Add prefetch instructions.
authorLulu Cheng <chenglulu@loongson.cn>
Wed, 16 Nov 2022 01:25:14 +0000 (09:25 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Wed, 23 Nov 2022 03:05:50 +0000 (11:05 +0800)
Enable sw prefetching at -O3 and higher.

Co-Authored-By: xujiahao <xujiahao@loongson.cn>
gcc/ChangeLog:

* config/loongarch/constraints.md (ZD): New constraint.
* config/loongarch/loongarch-def.c: Initial number of parallel prefetch.
* config/loongarch/loongarch-tune.h (struct loongarch_cache):
Define number of parallel prefetch.
* config/loongarch/loongarch.cc (loongarch_option_override_internal):
Set up parameters to be used in prefetching algorithm.
* config/loongarch/loongarch.md (prefetch): New template.

gcc/config/loongarch/constraints.md
gcc/config/loongarch/loongarch-def.c
gcc/config/loongarch/loongarch-tune.h
gcc/config/loongarch/loongarch.cc
gcc/config/loongarch/loongarch.md

index 43cb7b5f0f58bdf2d614a052dee5471e0d0e8544..46f7f63ae31c8b3ffa4fc754213c95b0ac4b5e42 100644 (file)
 ;;    "ZB"
 ;;      "An address that is held in a general-purpose register.
 ;;      The offset is zero"
+;;    "ZD"
+;;     "An address operand whose address is formed by a base register
+;;      and offset that is suitable for use in instructions with the same
+;;      addressing mode as @code{preld}."
 ;; "<" "Matches a pre-dec or post-dec operand." (Global non-architectural)
 ;; ">" "Matches a pre-inc or post-inc operand." (Global non-architectural)
 
   The offset is zero"
   (and (match_code "mem")
        (match_test "REG_P (XEXP (op, 0))")))
+
+(define_address_constraint "ZD"
+  "An address operand whose address is formed by a base register
+   and offset that is suitable for use in instructions with the same
+   addressing mode as @code{preld}."
+   (match_test "loongarch_12bit_offset_address_p (op, mode)"))
index cbf995d81b5aea8c1a1cf45a68bfe6f0cc724796..80ab10a52a814a42f20b5b41707c22e2bb395872 100644 (file)
@@ -62,11 +62,13 @@ loongarch_cpu_cache[N_TUNE_TYPES] = {
       .l1d_line_size = 64,
       .l1d_size = 64,
       .l2d_size = 256,
+      .simultaneous_prefetches = 4,
   },
   [CPU_LA464] = {
       .l1d_line_size = 64,
       .l1d_size = 64,
       .l2d_size = 256,
+      .simultaneous_prefetches = 4,
   },
 };
 
index 6f3530f5c02d39e012c977f9f971d25bd6b196f9..8e3eb29472bcfc7c69bb786a22f51b6aa174565d 100644 (file)
@@ -45,6 +45,7 @@ struct loongarch_cache {
     int l1d_line_size;  /* bytes */
     int l1d_size;       /* KiB */
     int l2d_size;       /* kiB */
+    int simultaneous_prefetches; /* number of parallel prefetch */
 };
 
 #endif /* LOONGARCH_TUNE_H */
index 8d5d8d965dd723f80d4903dcb3cd3577e8864615..8ee32c905730b74408873bc69735e1fa3aa0ea91 100644 (file)
@@ -63,6 +63,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "context.h"
 #include "builtins.h"
 #include "rtl-iter.h"
+#include "opts.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -6100,6 +6101,33 @@ loongarch_option_override_internal (struct gcc_options *opts)
   if (loongarch_branch_cost == 0)
     loongarch_branch_cost = loongarch_cost->branch_cost;
 
+  /* Set up parameters to be used in prefetching algorithm.  */
+  int simultaneous_prefetches
+    = loongarch_cpu_cache[LARCH_ACTUAL_TUNE].simultaneous_prefetches;
+
+  SET_OPTION_IF_UNSET (opts, &global_options_set,
+                      param_simultaneous_prefetches,
+                      simultaneous_prefetches);
+
+  SET_OPTION_IF_UNSET (opts, &global_options_set,
+                      param_l1_cache_line_size,
+                      loongarch_cpu_cache[LARCH_ACTUAL_TUNE].l1d_line_size);
+
+  SET_OPTION_IF_UNSET (opts, &global_options_set,
+                      param_l1_cache_size,
+                      loongarch_cpu_cache[LARCH_ACTUAL_TUNE].l1d_size);
+
+  SET_OPTION_IF_UNSET (opts, &global_options_set,
+                      param_l2_cache_size,
+                      loongarch_cpu_cache[LARCH_ACTUAL_TUNE].l2d_size);
+
+
+  /* Enable sw prefetching at -O3 and higher.  */
+  if (opts->x_flag_prefetch_loop_arrays < 0
+      && (opts->x_optimize >= 3 || opts->x_flag_profile_use)
+      && !opts->x_optimize_size)
+    opts->x_flag_prefetch_loop_arrays = 1;
+
   if (TARGET_DIRECT_EXTERN_ACCESS && flag_shlib)
     error ("%qs cannot be used for compiling a shared library",
           "-mdirect-extern-access");
index 682ab961741bb14c109ebdedb96017b13cc24e68..2fda53819044a91d7fefc003db8fcc656a642da1 100644 (file)
 ;;  ....................
 ;;
 
+(define_insn "prefetch"
+  [(prefetch (match_operand 0 "address_operand" "ZD")
+            (match_operand 1 "const_int_operand" "n")
+            (match_operand 2 "const_int_operand" "n"))]
+  ""
+{
+  switch (INTVAL (operands[1]))
+  {
+    case 0: return "preld\t0,%a0";
+    case 1: return "preld\t8,%a0";
+    default: gcc_unreachable ();
+  }
+})
+
 (define_insn "nop"
   [(const_int 0)]
   ""