From 18629835ba12fdfa693e2f9492a5fc23d95ef165 Mon Sep 17 00:00:00 2001
From: Charles Baylis <charles.baylis@linaro.org>
Date: Wed, 8 Feb 2017 16:52:10 +0000
Subject: [PATCH 1/3] [ARM] Refactor costs calculation for MEM.
This patch moves the calculation of costs for MEM into a
separate function, and reforms the calculation into two
parts. Firstly any additional cost of the addressing mode
is calculated, and then the cost of the memory access itself
is added.
In this patch, the calculation of the cost of the addressing
mode is left as a placeholder, to be added in a subsequent
patch.
gcc/ChangeLog:
<date> Charles Baylis <charles.baylis@linaro.org>
* config/arm/arm.c (arm_mem_costs): New function.
(arm_rtx_costs_internal): Use arm_mem_costs.
Change-Id: I99e93406ea39ee31f71c7bf428ad3e127b7a618e
---
gcc/config/arm/arm.c | 67 ++++++++++++++++++++++++++++++++--------------------
1 file changed, 42 insertions(+), 25 deletions(-)
@@ -9198,8 +9198,48 @@ arm_unspec_cost (rtx x, enum rtx_code /* outer_code */, bool speed_p, int *cost)
} \
while (0);
+/* Helper function for arm_rtx_costs_internal. Calculates the cost of a MEM,
+ considering the costs of the addressing mode and memory access
+ separately. */
+static bool
+arm_mem_costs (rtx x, const struct cpu_cost_table *extra_cost,
+ int *cost, bool speed_p)
+{
+ machine_mode mode = GET_MODE (x);
+ if (flag_pic
+ && GET_CODE (XEXP (x, 0)) == PLUS
+ && will_be_in_index_register (XEXP (XEXP (x, 0), 1)))
+ /* This will be split into two instructions. Add the cost of the
+ additional instruction here. The cost of the memory access is computed
+ below. See arm.md:calculate_pic_address. */
+ *cost = COSTS_N_INSNS (1);
+ else
+ *cost = 0;
+
+ /* Calculate cost of the addressing mode. */
+ if (speed_p)
+ {
+ /* TODO: Add table-driven costs for addressing modes. (See patch 2) */
+ }
+
+ /* Calculate cost of memory access. */
+ if (speed_p)
+ {
+ /* data transfer is transfer size divided by bus width. */
+ int bus_width = arm_arch7 ? 8 : 4;
+ *cost += CEIL (GET_MODE_SIZE (mode), bus_width);
+ *cost += extra_cost->ldst.load;
+ }
+ else
+ {
+ *cost += COSTS_N_INSNS (1);
+ }
+
+ return true;
+}
+
/* RTX costs. Make an estimate of the cost of executing the operation
- X, which is contained with an operation with code OUTER_CODE.
+ X, which is contained within an operation with code OUTER_CODE.
SPEED_P indicates whether the cost desired is the performance cost,
or the size cost. The estimate is stored in COST and the return
value is TRUE if the cost calculation is final, or FALSE if the
@@ -9278,30 +9318,7 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code,
return false;
case MEM:
- /* A memory access costs 1 insn if the mode is small, or the address is
- a single register, otherwise it costs one insn per word. */
- if (REG_P (XEXP (x, 0)))
- *cost = COSTS_N_INSNS (1);
- else if (flag_pic
- && GET_CODE (XEXP (x, 0)) == PLUS
- && will_be_in_index_register (XEXP (XEXP (x, 0), 1)))
- /* This will be split into two instructions.
- See arm.md:calculate_pic_address. */
- *cost = COSTS_N_INSNS (2);
- else
- *cost = COSTS_N_INSNS (ARM_NUM_REGS (mode));
-
- /* For speed optimizations, add the costs of the address and
- accessing memory. */
- if (speed_p)
-#ifdef NOT_YET
- *cost += (extra_cost->ldst.load
- + arm_address_cost (XEXP (x, 0), mode,
- ADDR_SPACE_GENERIC, speed_p));
-#else
- *cost += extra_cost->ldst.load;
-#endif
- return true;
+ return arm_mem_costs (x, extra_cost, cost, speed_p);
case PARALLEL:
{
--
2.7.4