870-xtensa-add-mauto-litpools-option.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. From 6d852ffb43b111a39162135c95249e749c4e285b Mon Sep 17 00:00:00 2001
  2. From: Max Filippov <jcmvbkbc@gmail.com>
  3. Date: Thu, 6 Aug 2015 01:16:02 +0300
  4. Subject: [PATCH] xtensa: add -mauto-litpools option
  5. With support from assembler this option allows compiling huge functions,
  6. where single literal pool at the beginning of a function may not be
  7. reachable by L32R instructions at its end.
  8. Currently assembler --auto-litpools option cannot deal with literals
  9. used from multiple locations separated by more than 256 KBytes of code.
  10. Don't turn constants into literals, instead use MOVI instruction to load
  11. them into registers and let the assembler turn them into literals as
  12. necessary.
  13. 2015-08-12 Max Filippov <jcmvbkbc@gmail.com>
  14. gcc/
  15. * config/xtensa/constraints.md (define_constraint "Y"): New
  16. constraint.
  17. * config/xtensa/elf.h (ASM_SPEC): Add m(no-)auto-litpools.
  18. * config/xtensa/linux.h (ASM_SPEC): Likewise.
  19. * config/xtensa/predicates.md (move_operand): Match constants
  20. and symbols in the presence of TARGET_AUTO_LITPOOLS.
  21. * config/xtensa/xtensa.c (xtensa_valid_move): Don't allow
  22. immediate references to TLS data.
  23. (xtensa_emit_move_sequence): Don't force constants to memory in
  24. the presence of TARGET_AUTO_LITPOOLS.
  25. (print_operand): Add 'y' format, same as default, but capable of
  26. printing SF mode constants as well.
  27. * config/xtensa/xtensa.md (movsi_internal, movhi_internal)
  28. (movsf_internal): Add movi pattern that loads literal.
  29. (movsf, movdf): Don't force constants to memory in the presence
  30. of TARGET_AUTO_LITPOOLS.
  31. (movdf_internal): Add 'Y' constraint.
  32. * config/xtensa/xtensa.opt (mauto-litpools): New option.
  33. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
  34. ---
  35. Backported from: r226828
  36. Changes to ChangeLogs and documentation are dropped.
  37. gcc/config/xtensa/constraints.md | 5 +++++
  38. gcc/config/xtensa/elf.h | 4 +++-
  39. gcc/config/xtensa/linux.h | 4 +++-
  40. gcc/config/xtensa/predicates.md | 3 ++-
  41. gcc/config/xtensa/xtensa.c | 19 ++++++++++++++++++-
  42. gcc/config/xtensa/xtensa.md | 35 +++++++++++++++++++----------------
  43. gcc/config/xtensa/xtensa.opt | 4 ++++
  44. 7 files changed, 54 insertions(+), 20 deletions(-)
  45. diff --git a/gcc/config/xtensa/constraints.md b/gcc/config/xtensa/constraints.md
  46. index 30f4c1f..773d4f9 100644
  47. --- a/gcc/config/xtensa/constraints.md
  48. +++ b/gcc/config/xtensa/constraints.md
  49. @@ -111,6 +111,11 @@
  50. (and (match_code "const_int")
  51. (match_test "xtensa_mask_immediate (ival)")))
  52. +(define_constraint "Y"
  53. + "A constant that can be used in relaxed MOVI instructions."
  54. + (and (match_code "const_int,const_double,const,symbol_ref,label_ref")
  55. + (match_test "TARGET_AUTO_LITPOOLS")))
  56. +
  57. ;; Memory constraints. Do not use define_memory_constraint here. Doing so
  58. ;; causes reload to force some constants into the constant pool, but since
  59. ;; the Xtensa constant pool can only be accessed with L32R instructions, it
  60. diff --git a/gcc/config/xtensa/elf.h b/gcc/config/xtensa/elf.h
  61. index e59bede..12056f7 100644
  62. --- a/gcc/config/xtensa/elf.h
  63. +++ b/gcc/config/xtensa/elf.h
  64. @@ -48,7 +48,9 @@ along with GCC; see the file COPYING3. If not see
  65. %{mtarget-align:--target-align} \
  66. %{mno-target-align:--no-target-align} \
  67. %{mlongcalls:--longcalls} \
  68. - %{mno-longcalls:--no-longcalls}"
  69. + %{mno-longcalls:--no-longcalls} \
  70. + %{mauto-litpools:--auto-litpools} \
  71. + %{mno-auto-litpools:--no-auto-litpools}"
  72. #undef LIB_SPEC
  73. #define LIB_SPEC "-lc -lsim -lc -lhandlers-sim -lhal"
  74. diff --git a/gcc/config/xtensa/linux.h b/gcc/config/xtensa/linux.h
  75. index 675aacf..5b0243a 100644
  76. --- a/gcc/config/xtensa/linux.h
  77. +++ b/gcc/config/xtensa/linux.h
  78. @@ -42,7 +42,9 @@ along with GCC; see the file COPYING3. If not see
  79. %{mtarget-align:--target-align} \
  80. %{mno-target-align:--no-target-align} \
  81. %{mlongcalls:--longcalls} \
  82. - %{mno-longcalls:--no-longcalls}"
  83. + %{mno-longcalls:--no-longcalls} \
  84. + %{mauto-litpools:--auto-litpools} \
  85. + %{mno-auto-litpools:--no-auto-litpools}"
  86. #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
  87. diff --git a/gcc/config/xtensa/predicates.md b/gcc/config/xtensa/predicates.md
  88. index e02209e..d7dfa11 100644
  89. --- a/gcc/config/xtensa/predicates.md
  90. +++ b/gcc/config/xtensa/predicates.md
  91. @@ -142,7 +142,8 @@
  92. (match_test "GET_MODE_CLASS (mode) == MODE_INT
  93. && xtensa_simm12b (INTVAL (op))"))
  94. (and (match_code "const_int,const_double,const,symbol_ref,label_ref")
  95. - (match_test "TARGET_CONST16 && CONSTANT_P (op)
  96. + (match_test "(TARGET_CONST16 || TARGET_AUTO_LITPOOLS)
  97. + && CONSTANT_P (op)
  98. && GET_MODE_SIZE (mode) % UNITS_PER_WORD == 0")))))
  99. ;; Accept the floating point constant 1 in the appropriate mode.
  100. diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
  101. index eb039ba..206ff80 100644
  102. --- a/gcc/config/xtensa/xtensa.c
  103. +++ b/gcc/config/xtensa/xtensa.c
  104. @@ -501,6 +501,9 @@ xtensa_valid_move (machine_mode mode, rtx *operands)
  105. {
  106. int dst_regnum = xt_true_regnum (operands[0]);
  107. + if (xtensa_tls_referenced_p (operands[1]))
  108. + return FALSE;
  109. +
  110. /* The stack pointer can only be assigned with a MOVSP opcode. */
  111. if (dst_regnum == STACK_POINTER_REGNUM)
  112. return !TARGET_WINDOWED_ABI
  113. @@ -1069,7 +1072,7 @@ xtensa_emit_move_sequence (rtx *operands, machine_mode mode)
  114. return 1;
  115. }
  116. - if (! TARGET_CONST16)
  117. + if (! TARGET_AUTO_LITPOOLS && ! TARGET_CONST16)
  118. {
  119. src = force_const_mem (SImode, src);
  120. operands[1] = src;
  121. @@ -2449,6 +2452,20 @@ print_operand (FILE *file, rtx x, int letter)
  122. }
  123. break;
  124. + case 'y':
  125. + if (GET_CODE (x) == CONST_DOUBLE &&
  126. + GET_MODE (x) == SFmode)
  127. + {
  128. + REAL_VALUE_TYPE r;
  129. + long l;
  130. + REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  131. + REAL_VALUE_TO_TARGET_SINGLE (r, l);
  132. + fprintf (file, "0x%08lx", l);
  133. + break;
  134. + }
  135. +
  136. + /* fall through */
  137. +
  138. default:
  139. if (GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
  140. fprintf (file, "%s", reg_names[xt_true_regnum (x)]);
  141. diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
  142. index 6d84384..0e673a3 100644
  143. --- a/gcc/config/xtensa/xtensa.md
  144. +++ b/gcc/config/xtensa/xtensa.md
  145. @@ -761,8 +761,8 @@
  146. })
  147. (define_insn "movsi_internal"
  148. - [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,W,a,a,U,*a,*A")
  149. - (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,i,T,U,r,*A,*r"))]
  150. + [(set (match_operand:SI 0 "nonimmed_operand" "=D,D,D,D,R,R,a,q,a,a,W,a,a,U,*a,*A")
  151. + (match_operand:SI 1 "move_operand" "M,D,d,R,D,d,r,r,I,Y,i,T,U,r,*A,*r"))]
  152. "xtensa_valid_move (SImode, operands)"
  153. "@
  154. movi.n\t%0, %x1
  155. @@ -774,15 +774,16 @@
  156. mov\t%0, %1
  157. movsp\t%0, %1
  158. movi\t%0, %x1
  159. + movi\t%0, %1
  160. const16\t%0, %t1\;const16\t%0, %b1
  161. %v1l32r\t%0, %1
  162. %v1l32i\t%0, %1
  163. %v0s32i\t%1, %0
  164. rsr\t%0, ACCLO
  165. wsr\t%1, ACCLO"
  166. - [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,load,load,store,rsr,wsr")
  167. + [(set_attr "type" "move,move,move,load,store,store,move,move,move,move,move,load,load,store,rsr,wsr")
  168. (set_attr "mode" "SI")
  169. - (set_attr "length" "2,2,2,2,2,2,3,3,3,6,3,3,3,3,3")])
  170. + (set_attr "length" "2,2,2,2,2,2,3,3,3,3,6,3,3,3,3,3")])
  171. ;; 16-bit Integer moves
  172. @@ -796,21 +797,22 @@
  173. })
  174. (define_insn "movhi_internal"
  175. - [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A")
  176. - (match_operand:HI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))]
  177. + [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,a,U,*a,*A")
  178. + (match_operand:HI 1 "move_operand" "M,d,r,I,Y,U,r,*A,*r"))]
  179. "xtensa_valid_move (HImode, operands)"
  180. "@
  181. movi.n\t%0, %x1
  182. mov.n\t%0, %1
  183. mov\t%0, %1
  184. movi\t%0, %x1
  185. + movi\t%0, %1
  186. %v1l16ui\t%0, %1
  187. %v0s16i\t%1, %0
  188. rsr\t%0, ACCLO
  189. wsr\t%1, ACCLO"
  190. - [(set_attr "type" "move,move,move,move,load,store,rsr,wsr")
  191. + [(set_attr "type" "move,move,move,move,move,load,store,rsr,wsr")
  192. (set_attr "mode" "HI")
  193. - (set_attr "length" "2,2,3,3,3,3,3,3")])
  194. + (set_attr "length" "2,2,3,3,3,3,3,3,3")])
  195. ;; 8-bit Integer moves
  196. @@ -881,7 +883,7 @@
  197. (match_operand:SF 1 "general_operand" ""))]
  198. ""
  199. {
  200. - if (!TARGET_CONST16 && CONSTANT_P (operands[1]))
  201. + if (!TARGET_CONST16 && !TARGET_AUTO_LITPOOLS && CONSTANT_P (operands[1]))
  202. operands[1] = force_const_mem (SFmode, operands[1]);
  203. if ((!register_operand (operands[0], SFmode)
  204. @@ -896,8 +898,8 @@
  205. })
  206. (define_insn "movsf_internal"
  207. - [(set (match_operand:SF 0 "nonimmed_operand" "=f,f,U,D,D,R,a,f,a,W,a,a,U")
  208. - (match_operand:SF 1 "move_operand" "f,U,f,d,R,d,r,r,f,iF,T,U,r"))]
  209. + [(set (match_operand:SF 0 "nonimmed_operand" "=f,f,U,D,D,R,a,f,a,a,W,a,a,U")
  210. + (match_operand:SF 1 "move_operand" "f,U,f,d,R,d,r,r,f,Y,iF,T,U,r"))]
  211. "((register_operand (operands[0], SFmode)
  212. || register_operand (operands[1], SFmode))
  213. && !(FP_REG_P (xt_true_regnum (operands[0]))
  214. @@ -912,13 +914,14 @@
  215. mov\t%0, %1
  216. wfr\t%0, %1
  217. rfr\t%0, %1
  218. + movi\t%0, %y1
  219. const16\t%0, %t1\;const16\t%0, %b1
  220. %v1l32r\t%0, %1
  221. %v1l32i\t%0, %1
  222. %v0s32i\t%1, %0"
  223. - [(set_attr "type" "farith,fload,fstore,move,load,store,move,farith,farith,move,load,load,store")
  224. + [(set_attr "type" "farith,fload,fstore,move,load,store,move,farith,farith,move,move,load,load,store")
  225. (set_attr "mode" "SF")
  226. - (set_attr "length" "3,3,3,2,2,2,3,3,3,6,3,3,3")])
  227. + (set_attr "length" "3,3,3,2,2,2,3,3,3,3,6,3,3,3")])
  228. (define_insn "*lsiu"
  229. [(set (match_operand:SF 0 "register_operand" "=f")
  230. @@ -991,7 +994,7 @@
  231. (match_operand:DF 1 "general_operand" ""))]
  232. ""
  233. {
  234. - if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
  235. + if (CONSTANT_P (operands[1]) && !TARGET_CONST16 && !TARGET_AUTO_LITPOOLS)
  236. operands[1] = force_const_mem (DFmode, operands[1]);
  237. if (!register_operand (operands[0], DFmode)
  238. @@ -1002,8 +1005,8 @@
  239. })
  240. (define_insn_and_split "movdf_internal"
  241. - [(set (match_operand:DF 0 "nonimmed_operand" "=a,W,a,a,U")
  242. - (match_operand:DF 1 "move_operand" "r,iF,T,U,r"))]
  243. + [(set (match_operand:DF 0 "nonimmed_operand" "=a,a,W,a,a,U")
  244. + (match_operand:DF 1 "move_operand" "r,Y,iF,T,U,r"))]
  245. "register_operand (operands[0], DFmode)
  246. || register_operand (operands[1], DFmode)"
  247. "#"
  248. diff --git a/gcc/config/xtensa/xtensa.opt b/gcc/config/xtensa/xtensa.opt
  249. index 2fd6cee..21c6e96 100644
  250. --- a/gcc/config/xtensa/xtensa.opt
  251. +++ b/gcc/config/xtensa/xtensa.opt
  252. @@ -38,6 +38,10 @@ mtext-section-literals
  253. Target
  254. Intersperse literal pools with code in the text section
  255. +mauto-litpools
  256. +Target Report Mask(AUTO_LITPOOLS)
  257. +Relax literals in assembler and place them automatically in the text section
  258. +
  259. mserialize-volatile
  260. Target Report Mask(SERIALIZE_VOLATILE)
  261. -mno-serialize-volatile Do not serialize volatile memory references with MEMW instructions
  262. --
  263. 1.8.1.4