+2018-04-08 Chung-Ju Wu <jasonwucj@gmail.com>
+
+ * config/nds32/nds32.c (nds32_init_machine_status,
+ nds32_legitimate_index_p, nds32_legitimate_address_p): Consider
+ strict_aligned_p field.
+ (nds32_expand_to_rtl_hook): New function.
+ (TARGET_EXPAND_TO_RTL_HOOK): Define.
+ * config/nds32/nds32.h (machine_function): Add strict_aligned_p field.
+
2018-04-08 Kito Cheng <kito.cheng@gmail.com>
Chung-Ju Wu <jasonwucj@gmail.com>
/* Initially assume this function does NOT use fp_as_gp optimization. */
machine->fp_as_gp_p = 0;
+ /* Initially this function is not under strictly aligned situation. */
+ machine->strict_aligned_p = 0;
+
return machine;
}
/* Further check if the value is legal for the 'outer_mode'. */
if (satisfies_constraint_Is16 (index))
{
+ /* If it is not under strictly aligned situation,
+ we can return true without checking alignment. */
+ if (!cfun->machine->strict_aligned_p)
+ return true;
/* Make sure address is half word alignment. */
- if (NDS32_HALF_WORD_ALIGN_P (INTVAL (index)))
+ else if (NDS32_HALF_WORD_ALIGN_P (INTVAL (index)))
return true;
}
break;
return false;
}
+ /* If it is not under strictly aligned situation,
+ we can return true without checking alignment. */
+ if (!cfun->machine->strict_aligned_p)
+ return true;
/* Make sure address is word alignment. */
- if (NDS32_SINGLE_WORD_ALIGN_P (INTVAL (index)))
+ else if (NDS32_SINGLE_WORD_ALIGN_P (INTVAL (index)))
return true;
}
break;
return false;
}
+ /* If it is not under strictly aligned situation,
+ we can return true without checking alignment. */
+ if (!cfun->machine->strict_aligned_p)
+ return true;
/* Make sure address is word alignment.
Currently we do not have 64-bit load/store yet,
so we will use two 32-bit load/store instructions to do
memory access and they are single word alignment. */
- if (NDS32_SINGLE_WORD_ALIGN_P (INTVAL (index)))
+ else if (NDS32_SINGLE_WORD_ALIGN_P (INTVAL (index)))
return true;
}
break;
}
}
+/* Storage Layout. */
+
+/* This function will be called just before expansion into rtl. */
+static void
+nds32_expand_to_rtl_hook (void)
+{
+ /* We need to set strictly aligned situation.
+ After that, the memory address checking in nds32_legitimate_address_p()
+ will take alignment offset into consideration so that it will not create
+ unaligned [base + offset] access during the rtl optimization. */
+ cfun->machine->strict_aligned_p = 1;
+}
+
+\f
/* Register Usage. */
static void
{
if (satisfies_constraint_Is14 (op1))
{
+ /* If it is not under strictly aligned situation,
+ we can return true without checking alignment. */
+ if (!cfun->machine->strict_aligned_p)
+ return true;
/* Make sure address is word alignment.
Currently we do not have 64-bit load/store yet,
so we will use two 32-bit load/store instructions to do
memory access and they are single word alignment. */
- if (NDS32_SINGLE_WORD_ALIGN_P (INTVAL (op1)))
+ else if (NDS32_SINGLE_WORD_ALIGN_P (INTVAL (op1)))
return true;
}
}
#define TARGET_PROMOTE_FUNCTION_MODE \
default_promote_function_mode_always_promote
+#undef TARGET_EXPAND_TO_RTL_HOOK
+#define TARGET_EXPAND_TO_RTL_HOOK nds32_expand_to_rtl_hook
+
\f
/* Layout of Source Language Data Types. */
/* Indicate that whether this function
uses fp_as_gp optimization. */
int fp_as_gp_p;
+ /* Indicate that whether this function is under strictly aligned
+ situation for legitimate address checking. This flag informs
+ nds32_legitimate_address_p() how to treat offset alignment:
+ 1. The IVOPT phase needs to detect available range for memory access,
+ such as checking [base + 32767] ~ [base + (-32768)].
+ For this case we do not want address to be strictly aligned.
+ 2. The rtl lowering and optimization are close to target code.
+ For this case we need address to be strictly aligned. */
+ int strict_aligned_p;
};
/* A C structure that contains the arguments information. */