MIPS: Implement TARGET_INSN_COSTS

Message ID 20231228135631.3581609-1-syq@gcc.gnu.org
State New
Headers
Series MIPS: Implement TARGET_INSN_COSTS |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed

Commit Message

YunQiang Su Dec. 28, 2023, 1:56 p.m. UTC
  MIPS backend had some information about INSN, including length,
count etc.

And since some instructions are more costly, let's add a new
attr `perf_ratio`.  It's default value is (const_int 1).

The return value of mips_insn_cost is
  insn_count * perf_ratio * 4.

The magic `4` here, is due to that `rtx_cost` returns 4
for simple instructions.

gcc
	* config/mips/mips.cc (mips_insn_cost): New function.
	TARGET_INSN_COST: defined to mips_insn_cost.
	* config/mips/mips.md (perf_ratio): New attr.
---
 gcc/config/mips/mips.cc | 14 ++++++++++++++
 gcc/config/mips/mips.md |  4 ++++
 2 files changed, 18 insertions(+)
  

Patch

diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index 9180dbbf843..fddb1519d76 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -4170,6 +4170,18 @@  mips_set_reg_reg_cost (machine_mode mode)
     }
 }
 
+/* Implement TARGET_INSN_COSTS.  */
+
+static int
+mips_insn_cost (rtx_insn *x, bool speed ATTRIBUTE_UNUSED)
+{
+  if (GET_CODE (PATTERN (x)) != SET)
+    return pattern_cost (PATTERN (x), speed);
+  return get_attr_insn_count (x)
+	  * get_attr_perf_ratio (x)
+	  * 4;
+}
+
 /* Implement TARGET_RTX_COSTS.  */
 
 static bool
@@ -23069,6 +23081,8 @@  mips_bit_clear_p (enum machine_mode mode, unsigned HOST_WIDE_INT m)
 #define TARGET_RTX_COSTS mips_rtx_costs
 #undef TARGET_ADDRESS_COST
 #define TARGET_ADDRESS_COST mips_address_cost
+#undef  TARGET_INSN_COST
+#define TARGET_INSN_COST mips_insn_cost
 
 #undef TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P
 #define TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P mips_no_speculation_in_delay_slots_p
diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md
index 0666310734e..d6c4ba13f47 100644
--- a/gcc/config/mips/mips.md
+++ b/gcc/config/mips/mips.md
@@ -312,6 +312,10 @@  (define_attr "sync_insn2" "nop,and,xor,not"
 ;; "11" specifies MEMMODEL_ACQUIRE.
 (define_attr "sync_memmodel" "" (const_int 10))
 
+;; Performance ratio. Used by mips_insn_cost: it returns insn_count*perf_ratio*4.
+;; Add this attr to the slow INSNs.
+(define_attr "perf_ratio" "" (const_int 1))
+
 ;; Accumulator operand for madd patterns.
 (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))