]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[NDS32] Add strict_aligned_p to machine_function and implement TARGET_EXPAND_TO_RTL_HOOK.
authorChung-Ju Wu <jasonwucj@gmail.com>
Sun, 8 Apr 2018 11:14:09 +0000 (11:14 +0000)
committerChung-Ju Wu <jasonwucj@gcc.gnu.org>
Sun, 8 Apr 2018 11:14:09 +0000 (11:14 +0000)
gcc/
* 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.

From-SVN: r259222

gcc/ChangeLog
gcc/config/nds32/nds32.c
gcc/config/nds32/nds32.h

index 0238883b143027910367df2d1b6816cc4bf873a0..f1d773b2ab1f3d9fa7fc29a15b18adfb46b03e71 100644 (file)
@@ -1,3 +1,12 @@
+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>
 
index 76980d3ab1c0ad3ba762db68a2c24b76bfb1ba9b..36417cbc543d6bda3086ebe45e9bcaf009fb874f 100644 (file)
@@ -342,6 +342,9 @@ nds32_init_machine_status (void)
   /* 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;
 }
 
@@ -1414,8 +1417,12 @@ nds32_legitimate_index_p (machine_mode outer_mode,
          /* 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;
@@ -1430,8 +1437,12 @@ nds32_legitimate_index_p (machine_mode outer_mode,
                    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;
@@ -1446,11 +1457,15 @@ nds32_legitimate_index_p (machine_mode outer_mode,
                    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;
@@ -1589,6 +1604,20 @@ nds32_adjust_insn_length (rtx_insn *insn, int length)
     }
 }
 
+/* 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
@@ -2469,11 +2498,15 @@ nds32_legitimate_address_p (machine_mode mode, rtx x, bool strict)
                {
                  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;
                    }
                }
@@ -4827,6 +4860,9 @@ nds32_use_blocks_for_constant_p (machine_mode mode,
 #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.  */
 
index 03deda962b17c56c37ef78c6e4d2c3f3287d5fb4..d68820c422bcbfbdc780a4c2c26e79ccacc8588b 100644 (file)
@@ -296,6 +296,15 @@ struct GTY(()) machine_function
   /* 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.  */