fr30.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. /* FR30 specific functions.
  2. Copyright (C) 1998-2015 Free Software Foundation, Inc.
  3. Contributed by Cygnus Solutions.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. /*{{{ Includes */
  17. #include "config.h"
  18. #include "system.h"
  19. #include "coretypes.h"
  20. #include "tm.h"
  21. #include "rtl.h"
  22. #include "regs.h"
  23. #include "hard-reg-set.h"
  24. #include "insn-config.h"
  25. #include "conditions.h"
  26. #include "insn-attr.h"
  27. #include "flags.h"
  28. #include "recog.h"
  29. #include "hash-set.h"
  30. #include "machmode.h"
  31. #include "vec.h"
  32. #include "double-int.h"
  33. #include "input.h"
  34. #include "alias.h"
  35. #include "symtab.h"
  36. #include "wide-int.h"
  37. #include "inchash.h"
  38. #include "tree.h"
  39. #include "fold-const.h"
  40. #include "stor-layout.h"
  41. #include "varasm.h"
  42. #include "output.h"
  43. #include "hashtab.h"
  44. #include "function.h"
  45. #include "statistics.h"
  46. #include "real.h"
  47. #include "fixed-value.h"
  48. #include "expmed.h"
  49. #include "dojump.h"
  50. #include "explow.h"
  51. #include "calls.h"
  52. #include "emit-rtl.h"
  53. #include "stmt.h"
  54. #include "expr.h"
  55. #include "obstack.h"
  56. #include "except.h"
  57. #include "dominance.h"
  58. #include "cfg.h"
  59. #include "cfgrtl.h"
  60. #include "cfganal.h"
  61. #include "lcm.h"
  62. #include "cfgbuild.h"
  63. #include "cfgcleanup.h"
  64. #include "predict.h"
  65. #include "basic-block.h"
  66. #include "df.h"
  67. #include "diagnostic-core.h"
  68. #include "tm_p.h"
  69. #include "target.h"
  70. #include "target-def.h"
  71. #include "builtins.h"
  72. /*}}}*/
  73. /*{{{ Function Prologues & Epilogues */
  74. /* The FR30 stack looks like this:
  75. Before call After call
  76. FP ->| | | |
  77. +-----------------------+ +-----------------------+ high
  78. | | | | memory
  79. | local variables, | | local variables, |
  80. | reg save area, etc. | | reg save area, etc. |
  81. | | | |
  82. +-----------------------+ +-----------------------+
  83. | | | |
  84. | args to the func that | | args to this func. |
  85. | is being called that | | |
  86. SP ->| do not fit in regs | | |
  87. +-----------------------+ +-----------------------+
  88. | args that used to be | \
  89. | in regs; only created | | pretend_size
  90. AP-> | for vararg funcs | /
  91. +-----------------------+
  92. | | \
  93. | register save area | |
  94. | | |
  95. +-----------------------+ | reg_size
  96. | return address | |
  97. +-----------------------+ |
  98. FP ->| previous frame ptr | /
  99. +-----------------------+
  100. | | \
  101. | local variables | | var_size
  102. | | /
  103. +-----------------------+
  104. | | \
  105. low | room for args to | |
  106. memory | other funcs called | | args_size
  107. | from this one | |
  108. SP ->| | /
  109. +-----------------------+
  110. Note, AP is a fake hard register. It will be eliminated in favor of
  111. SP or FP as appropriate.
  112. Note, Some or all of the stack sections above may be omitted if they
  113. are not needed. */
  114. /* Structure to be filled in by fr30_compute_frame_size() with register
  115. save masks, and offsets for the current function. */
  116. struct fr30_frame_info
  117. {
  118. unsigned int total_size; /* # Bytes that the entire frame takes up. */
  119. unsigned int pretend_size; /* # Bytes we push and pretend caller did. */
  120. unsigned int args_size; /* # Bytes that outgoing arguments take up. */
  121. unsigned int reg_size; /* # Bytes needed to store regs. */
  122. unsigned int var_size; /* # Bytes that variables take up. */
  123. unsigned int frame_size; /* # Bytes in current frame. */
  124. unsigned int gmask; /* Mask of saved registers. */
  125. unsigned int save_fp; /* Nonzero if frame pointer must be saved. */
  126. unsigned int save_rp; /* Nonzero if return pointer must be saved. */
  127. int initialised; /* Nonzero if frame size already calculated. */
  128. };
  129. /* Current frame information calculated by fr30_compute_frame_size(). */
  130. static struct fr30_frame_info current_frame_info;
  131. /* Zero structure to initialize current_frame_info. */
  132. static struct fr30_frame_info zero_frame_info;
  133. static void fr30_setup_incoming_varargs (cumulative_args_t, machine_mode,
  134. tree, int *, int);
  135. static bool fr30_must_pass_in_stack (machine_mode, const_tree);
  136. static int fr30_arg_partial_bytes (cumulative_args_t, machine_mode,
  137. tree, bool);
  138. static rtx fr30_function_arg (cumulative_args_t, machine_mode,
  139. const_tree, bool);
  140. static void fr30_function_arg_advance (cumulative_args_t, machine_mode,
  141. const_tree, bool);
  142. static bool fr30_frame_pointer_required (void);
  143. static rtx fr30_function_value (const_tree, const_tree, bool);
  144. static rtx fr30_libcall_value (machine_mode, const_rtx);
  145. static bool fr30_function_value_regno_p (const unsigned int);
  146. static bool fr30_can_eliminate (const int, const int);
  147. static void fr30_asm_trampoline_template (FILE *);
  148. static void fr30_trampoline_init (rtx, tree, rtx);
  149. static int fr30_num_arg_regs (machine_mode, const_tree);
  150. #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
  151. #define RETURN_POINTER_MASK (1 << (RETURN_POINTER_REGNUM))
  152. /* Tell prologue and epilogue if register REGNO should be saved / restored.
  153. The return address and frame pointer are treated separately.
  154. Don't consider them here. */
  155. #define MUST_SAVE_REGISTER(regno) \
  156. ( (regno) != RETURN_POINTER_REGNUM \
  157. && (regno) != FRAME_POINTER_REGNUM \
  158. && df_regs_ever_live_p (regno) \
  159. && ! call_used_regs [regno] )
  160. #define MUST_SAVE_FRAME_POINTER (df_regs_ever_live_p (FRAME_POINTER_REGNUM) || frame_pointer_needed)
  161. #define MUST_SAVE_RETURN_POINTER (df_regs_ever_live_p (RETURN_POINTER_REGNUM) || crtl->profile)
  162. #if UNITS_PER_WORD == 4
  163. #define WORD_ALIGN(SIZE) (((SIZE) + 3) & ~3)
  164. #endif
  165. /* Initialize the GCC target structure. */
  166. #undef TARGET_ASM_ALIGNED_HI_OP
  167. #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
  168. #undef TARGET_ASM_ALIGNED_SI_OP
  169. #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
  170. #undef TARGET_PROMOTE_PROTOTYPES
  171. #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
  172. #undef TARGET_PASS_BY_REFERENCE
  173. #define TARGET_PASS_BY_REFERENCE hook_pass_by_reference_must_pass_in_stack
  174. #undef TARGET_ARG_PARTIAL_BYTES
  175. #define TARGET_ARG_PARTIAL_BYTES fr30_arg_partial_bytes
  176. #undef TARGET_FUNCTION_ARG
  177. #define TARGET_FUNCTION_ARG fr30_function_arg
  178. #undef TARGET_FUNCTION_ARG_ADVANCE
  179. #define TARGET_FUNCTION_ARG_ADVANCE fr30_function_arg_advance
  180. #undef TARGET_FUNCTION_VALUE
  181. #define TARGET_FUNCTION_VALUE fr30_function_value
  182. #undef TARGET_LIBCALL_VALUE
  183. #define TARGET_LIBCALL_VALUE fr30_libcall_value
  184. #undef TARGET_FUNCTION_VALUE_REGNO_P
  185. #define TARGET_FUNCTION_VALUE_REGNO_P fr30_function_value_regno_p
  186. #undef TARGET_SETUP_INCOMING_VARARGS
  187. #define TARGET_SETUP_INCOMING_VARARGS fr30_setup_incoming_varargs
  188. #undef TARGET_MUST_PASS_IN_STACK
  189. #define TARGET_MUST_PASS_IN_STACK fr30_must_pass_in_stack
  190. #undef TARGET_FRAME_POINTER_REQUIRED
  191. #define TARGET_FRAME_POINTER_REQUIRED fr30_frame_pointer_required
  192. #undef TARGET_CAN_ELIMINATE
  193. #define TARGET_CAN_ELIMINATE fr30_can_eliminate
  194. #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
  195. #define TARGET_ASM_TRAMPOLINE_TEMPLATE fr30_asm_trampoline_template
  196. #undef TARGET_TRAMPOLINE_INIT
  197. #define TARGET_TRAMPOLINE_INIT fr30_trampoline_init
  198. struct gcc_target targetm = TARGET_INITIALIZER;
  199. /* Worker function for TARGET_CAN_ELIMINATE. */
  200. bool
  201. fr30_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
  202. {
  203. return (to == FRAME_POINTER_REGNUM || ! frame_pointer_needed);
  204. }
  205. /* Returns the number of bytes offset between FROM_REG and TO_REG
  206. for the current function. As a side effect it fills in the
  207. current_frame_info structure, if the data is available. */
  208. unsigned int
  209. fr30_compute_frame_size (int from_reg, int to_reg)
  210. {
  211. int regno;
  212. unsigned int return_value;
  213. unsigned int var_size;
  214. unsigned int args_size;
  215. unsigned int pretend_size;
  216. unsigned int reg_size;
  217. unsigned int gmask;
  218. var_size = WORD_ALIGN (get_frame_size ());
  219. args_size = WORD_ALIGN (crtl->outgoing_args_size);
  220. pretend_size = crtl->args.pretend_args_size;
  221. reg_size = 0;
  222. gmask = 0;
  223. /* Calculate space needed for registers. */
  224. for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno ++)
  225. {
  226. if (MUST_SAVE_REGISTER (regno))
  227. {
  228. reg_size += UNITS_PER_WORD;
  229. gmask |= 1 << regno;
  230. }
  231. }
  232. current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
  233. current_frame_info.save_rp = MUST_SAVE_RETURN_POINTER;
  234. reg_size += (current_frame_info.save_fp + current_frame_info.save_rp)
  235. * UNITS_PER_WORD;
  236. /* Save computed information. */
  237. current_frame_info.pretend_size = pretend_size;
  238. current_frame_info.var_size = var_size;
  239. current_frame_info.args_size = args_size;
  240. current_frame_info.reg_size = reg_size;
  241. current_frame_info.frame_size = args_size + var_size;
  242. current_frame_info.total_size = args_size + var_size + reg_size + pretend_size;
  243. current_frame_info.gmask = gmask;
  244. current_frame_info.initialised = reload_completed;
  245. /* Calculate the required distance. */
  246. return_value = 0;
  247. if (to_reg == STACK_POINTER_REGNUM)
  248. return_value += args_size + var_size;
  249. if (from_reg == ARG_POINTER_REGNUM)
  250. return_value += reg_size;
  251. return return_value;
  252. }
  253. /* Called after register allocation to add any instructions needed for the
  254. prologue. Using a prologue insn is favored compared to putting all of the
  255. instructions in output_function_prologue(), since it allows the scheduler
  256. to intermix instructions with the saves of the caller saved registers. In
  257. some cases, it might be necessary to emit a barrier instruction as the last
  258. insn to prevent such scheduling. */
  259. void
  260. fr30_expand_prologue (void)
  261. {
  262. int regno;
  263. rtx insn;
  264. if (! current_frame_info.initialised)
  265. fr30_compute_frame_size (0, 0);
  266. /* This cases shouldn't happen. Catch it now. */
  267. gcc_assert (current_frame_info.total_size || !current_frame_info.gmask);
  268. /* Allocate space for register arguments if this is a variadic function. */
  269. if (current_frame_info.pretend_size)
  270. {
  271. int regs_to_save = current_frame_info.pretend_size / UNITS_PER_WORD;
  272. /* Push argument registers into the pretend arg area. */
  273. for (regno = FIRST_ARG_REGNUM + FR30_NUM_ARG_REGS; regno --, regs_to_save --;)
  274. {
  275. insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
  276. RTX_FRAME_RELATED_P (insn) = 1;
  277. }
  278. }
  279. if (current_frame_info.gmask)
  280. {
  281. /* Save any needed call-saved regs. */
  282. for (regno = STACK_POINTER_REGNUM; regno--;)
  283. {
  284. if ((current_frame_info.gmask & (1 << regno)) != 0)
  285. {
  286. insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
  287. RTX_FRAME_RELATED_P (insn) = 1;
  288. }
  289. }
  290. }
  291. /* Save return address if necessary. */
  292. if (current_frame_info.save_rp)
  293. {
  294. insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode,
  295. RETURN_POINTER_REGNUM)));
  296. RTX_FRAME_RELATED_P (insn) = 1;
  297. }
  298. /* Save old frame pointer and create new one, if necessary. */
  299. if (current_frame_info.save_fp)
  300. {
  301. if (current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
  302. {
  303. int enter_size = current_frame_info.frame_size + UNITS_PER_WORD;
  304. rtx pattern;
  305. insn = emit_insn (gen_enter_func (GEN_INT (enter_size)));
  306. RTX_FRAME_RELATED_P (insn) = 1;
  307. pattern = PATTERN (insn);
  308. /* Also mark all 3 subexpressions as RTX_FRAME_RELATED_P. */
  309. if (GET_CODE (pattern) == PARALLEL)
  310. {
  311. int x;
  312. for (x = XVECLEN (pattern, 0); x--;)
  313. {
  314. rtx part = XVECEXP (pattern, 0, x);
  315. /* One of the insns in the ENTER pattern updates the
  316. frame pointer. If we do not actually need the frame
  317. pointer in this function then this is a side effect
  318. rather than a desired effect, so we do not mark that
  319. insn as being related to the frame set up. Doing this
  320. allows us to compile the crash66.C test file in the
  321. G++ testsuite. */
  322. if (! frame_pointer_needed
  323. && GET_CODE (part) == SET
  324. && SET_DEST (part) == hard_frame_pointer_rtx)
  325. RTX_FRAME_RELATED_P (part) = 0;
  326. else
  327. RTX_FRAME_RELATED_P (part) = 1;
  328. }
  329. }
  330. }
  331. else
  332. {
  333. insn = emit_insn (gen_movsi_push (frame_pointer_rtx));
  334. RTX_FRAME_RELATED_P (insn) = 1;
  335. if (frame_pointer_needed)
  336. {
  337. insn = emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
  338. RTX_FRAME_RELATED_P (insn) = 1;
  339. }
  340. }
  341. }
  342. /* Allocate the stack frame. */
  343. if (current_frame_info.frame_size == 0)
  344. ; /* Nothing to do. */
  345. else if (current_frame_info.save_fp
  346. && current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
  347. ; /* Nothing to do. */
  348. else if (current_frame_info.frame_size <= 512)
  349. {
  350. insn = emit_insn (gen_add_to_stack
  351. (GEN_INT (- (signed) current_frame_info.frame_size)));
  352. RTX_FRAME_RELATED_P (insn) = 1;
  353. }
  354. else
  355. {
  356. rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
  357. insn = emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
  358. RTX_FRAME_RELATED_P (insn) = 1;
  359. insn = emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
  360. RTX_FRAME_RELATED_P (insn) = 1;
  361. }
  362. if (crtl->profile)
  363. emit_insn (gen_blockage ());
  364. }
  365. /* Called after register allocation to add any instructions needed for the
  366. epilogue. Using an epilogue insn is favored compared to putting all of the
  367. instructions in output_function_epilogue(), since it allows the scheduler
  368. to intermix instructions with the restores of the caller saved registers.
  369. In some cases, it might be necessary to emit a barrier instruction as the
  370. first insn to prevent such scheduling. */
  371. void
  372. fr30_expand_epilogue (void)
  373. {
  374. int regno;
  375. /* Perform the inversion operations of the prologue. */
  376. gcc_assert (current_frame_info.initialised);
  377. /* Pop local variables and arguments off the stack.
  378. If frame_pointer_needed is TRUE then the frame pointer register
  379. has actually been used as a frame pointer, and we can recover
  380. the stack pointer from it, otherwise we must unwind the stack
  381. manually. */
  382. if (current_frame_info.frame_size > 0)
  383. {
  384. if (current_frame_info.save_fp && frame_pointer_needed)
  385. {
  386. emit_insn (gen_leave_func ());
  387. current_frame_info.save_fp = 0;
  388. }
  389. else if (current_frame_info.frame_size <= 508)
  390. emit_insn (gen_add_to_stack
  391. (GEN_INT (current_frame_info.frame_size)));
  392. else
  393. {
  394. rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
  395. emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
  396. emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
  397. }
  398. }
  399. if (current_frame_info.save_fp)
  400. emit_insn (gen_movsi_pop (frame_pointer_rtx));
  401. /* Pop all the registers that were pushed. */
  402. if (current_frame_info.save_rp)
  403. emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, RETURN_POINTER_REGNUM)));
  404. for (regno = 0; regno < STACK_POINTER_REGNUM; regno ++)
  405. if (current_frame_info.gmask & (1 << regno))
  406. emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, regno)));
  407. if (current_frame_info.pretend_size)
  408. emit_insn (gen_add_to_stack (GEN_INT (current_frame_info.pretend_size)));
  409. /* Reset state info for each function. */
  410. current_frame_info = zero_frame_info;
  411. emit_jump_insn (gen_return_from_func ());
  412. }
  413. /* Do any needed setup for a variadic function. We must create a register
  414. parameter block, and then copy any anonymous arguments, plus the last
  415. named argument, from registers into memory. * copying actually done in
  416. fr30_expand_prologue().
  417. ARG_REGS_USED_SO_FAR has *not* been updated for the last named argument
  418. which has type TYPE and mode MODE, and we rely on this fact. */
  419. void
  420. fr30_setup_incoming_varargs (cumulative_args_t arg_regs_used_so_far_v,
  421. machine_mode mode,
  422. tree type ATTRIBUTE_UNUSED,
  423. int *pretend_size,
  424. int second_time ATTRIBUTE_UNUSED)
  425. {
  426. CUMULATIVE_ARGS *arg_regs_used_so_far
  427. = get_cumulative_args (arg_regs_used_so_far_v);
  428. int size;
  429. /* All BLKmode values are passed by reference. */
  430. gcc_assert (mode != BLKmode);
  431. /* ??? This run-time test as well as the code inside the if
  432. statement is probably unnecessary. */
  433. if (targetm.calls.strict_argument_naming (arg_regs_used_so_far_v))
  434. /* If TARGET_STRICT_ARGUMENT_NAMING returns true, then the last named
  435. arg must not be treated as an anonymous arg. */
  436. /* ??? This is a pointer increment, which makes no sense. */
  437. arg_regs_used_so_far += fr30_num_arg_regs (mode, type);
  438. size = FR30_NUM_ARG_REGS - (* arg_regs_used_so_far);
  439. if (size <= 0)
  440. return;
  441. * pretend_size = (size * UNITS_PER_WORD);
  442. }
  443. /*}}}*/
  444. /*{{{ Printing operands */
  445. /* Print a memory address as an operand to reference that memory location. */
  446. void
  447. fr30_print_operand_address (FILE *stream, rtx address)
  448. {
  449. switch (GET_CODE (address))
  450. {
  451. case SYMBOL_REF:
  452. output_addr_const (stream, address);
  453. break;
  454. default:
  455. fprintf (stderr, "code = %x\n", GET_CODE (address));
  456. debug_rtx (address);
  457. output_operand_lossage ("fr30_print_operand_address: unhandled address");
  458. break;
  459. }
  460. }
  461. /* Print an operand. */
  462. void
  463. fr30_print_operand (FILE *file, rtx x, int code)
  464. {
  465. rtx x0;
  466. switch (code)
  467. {
  468. case '#':
  469. /* Output a :D if this instruction is delayed. */
  470. if (dbr_sequence_length () != 0)
  471. fputs (":D", file);
  472. return;
  473. case 'p':
  474. /* Compute the register name of the second register in a hi/lo
  475. register pair. */
  476. if (GET_CODE (x) != REG)
  477. output_operand_lossage ("fr30_print_operand: unrecognized %%p code");
  478. else
  479. fprintf (file, "r%d", REGNO (x) + 1);
  480. return;
  481. case 'b':
  482. /* Convert GCC's comparison operators into FR30 comparison codes. */
  483. switch (GET_CODE (x))
  484. {
  485. case EQ: fprintf (file, "eq"); break;
  486. case NE: fprintf (file, "ne"); break;
  487. case LT: fprintf (file, "lt"); break;
  488. case LE: fprintf (file, "le"); break;
  489. case GT: fprintf (file, "gt"); break;
  490. case GE: fprintf (file, "ge"); break;
  491. case LTU: fprintf (file, "c"); break;
  492. case LEU: fprintf (file, "ls"); break;
  493. case GTU: fprintf (file, "hi"); break;
  494. case GEU: fprintf (file, "nc"); break;
  495. default:
  496. output_operand_lossage ("fr30_print_operand: unrecognized %%b code");
  497. break;
  498. }
  499. return;
  500. case 'B':
  501. /* Convert GCC's comparison operators into the complimentary FR30
  502. comparison codes. */
  503. switch (GET_CODE (x))
  504. {
  505. case EQ: fprintf (file, "ne"); break;
  506. case NE: fprintf (file, "eq"); break;
  507. case LT: fprintf (file, "ge"); break;
  508. case LE: fprintf (file, "gt"); break;
  509. case GT: fprintf (file, "le"); break;
  510. case GE: fprintf (file, "lt"); break;
  511. case LTU: fprintf (file, "nc"); break;
  512. case LEU: fprintf (file, "hi"); break;
  513. case GTU: fprintf (file, "ls"); break;
  514. case GEU: fprintf (file, "c"); break;
  515. default:
  516. output_operand_lossage ("fr30_print_operand: unrecognized %%B code");
  517. break;
  518. }
  519. return;
  520. case 'A':
  521. /* Print a signed byte value as an unsigned value. */
  522. if (GET_CODE (x) != CONST_INT)
  523. output_operand_lossage ("fr30_print_operand: invalid operand to %%A code");
  524. else
  525. {
  526. HOST_WIDE_INT val;
  527. val = INTVAL (x);
  528. val &= 0xff;
  529. fprintf (file, HOST_WIDE_INT_PRINT_DEC, val);
  530. }
  531. return;
  532. case 'x':
  533. if (GET_CODE (x) != CONST_INT
  534. || INTVAL (x) < 16
  535. || INTVAL (x) > 32)
  536. output_operand_lossage ("fr30_print_operand: invalid %%x code");
  537. else
  538. fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) - 16);
  539. return;
  540. case 'F':
  541. if (GET_CODE (x) != CONST_DOUBLE)
  542. output_operand_lossage ("fr30_print_operand: invalid %%F code");
  543. else
  544. {
  545. char str[30];
  546. real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x),
  547. sizeof (str), 0, 1);
  548. fputs (str, file);
  549. }
  550. return;
  551. case 0:
  552. /* Handled below. */
  553. break;
  554. default:
  555. fprintf (stderr, "unknown code = %x\n", code);
  556. output_operand_lossage ("fr30_print_operand: unknown code");
  557. return;
  558. }
  559. switch (GET_CODE (x))
  560. {
  561. case REG:
  562. fputs (reg_names [REGNO (x)], file);
  563. break;
  564. case MEM:
  565. x0 = XEXP (x,0);
  566. switch (GET_CODE (x0))
  567. {
  568. case REG:
  569. gcc_assert ((unsigned) REGNO (x0) < ARRAY_SIZE (reg_names));
  570. fprintf (file, "@%s", reg_names [REGNO (x0)]);
  571. break;
  572. case PLUS:
  573. if (GET_CODE (XEXP (x0, 0)) != REG
  574. || REGNO (XEXP (x0, 0)) < FRAME_POINTER_REGNUM
  575. || REGNO (XEXP (x0, 0)) > STACK_POINTER_REGNUM
  576. || GET_CODE (XEXP (x0, 1)) != CONST_INT)
  577. {
  578. fprintf (stderr, "bad INDEXed address:");
  579. debug_rtx (x);
  580. output_operand_lossage ("fr30_print_operand: unhandled MEM");
  581. }
  582. else if (REGNO (XEXP (x0, 0)) == FRAME_POINTER_REGNUM)
  583. {
  584. HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
  585. if (val < -(1 << 9) || val > ((1 << 9) - 4))
  586. {
  587. fprintf (stderr, "frame INDEX out of range:");
  588. debug_rtx (x);
  589. output_operand_lossage ("fr30_print_operand: unhandled MEM");
  590. }
  591. fprintf (file, "@(r14, #" HOST_WIDE_INT_PRINT_DEC ")", val);
  592. }
  593. else
  594. {
  595. HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
  596. if (val < 0 || val > ((1 << 6) - 4))
  597. {
  598. fprintf (stderr, "stack INDEX out of range:");
  599. debug_rtx (x);
  600. output_operand_lossage ("fr30_print_operand: unhandled MEM");
  601. }
  602. fprintf (file, "@(r15, #" HOST_WIDE_INT_PRINT_DEC ")", val);
  603. }
  604. break;
  605. case SYMBOL_REF:
  606. output_address (x0);
  607. break;
  608. default:
  609. fprintf (stderr, "bad MEM code = %x\n", GET_CODE (x0));
  610. debug_rtx (x);
  611. output_operand_lossage ("fr30_print_operand: unhandled MEM");
  612. break;
  613. }
  614. break;
  615. case CONST_DOUBLE :
  616. /* We handle SFmode constants here as output_addr_const doesn't. */
  617. if (GET_MODE (x) == SFmode)
  618. {
  619. REAL_VALUE_TYPE d;
  620. long l;
  621. REAL_VALUE_FROM_CONST_DOUBLE (d, x);
  622. REAL_VALUE_TO_TARGET_SINGLE (d, l);
  623. fprintf (file, "0x%08lx", l);
  624. break;
  625. }
  626. /* Fall through. Let output_addr_const deal with it. */
  627. default:
  628. output_addr_const (file, x);
  629. break;
  630. }
  631. return;
  632. }
  633. /*}}}*/
  634. /* Implements TARGET_FUNCTION_VALUE. */
  635. static rtx
  636. fr30_function_value (const_tree valtype,
  637. const_tree fntype_or_decli ATTRIBUTE_UNUSED,
  638. bool outgoing ATTRIBUTE_UNUSED)
  639. {
  640. return gen_rtx_REG (TYPE_MODE (valtype), RETURN_VALUE_REGNUM);
  641. }
  642. /* Implements TARGET_LIBCALL_VALUE. */
  643. static rtx
  644. fr30_libcall_value (machine_mode mode,
  645. const_rtx fun ATTRIBUTE_UNUSED)
  646. {
  647. return gen_rtx_REG (mode, RETURN_VALUE_REGNUM);
  648. }
  649. /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
  650. static bool
  651. fr30_function_value_regno_p (const unsigned int regno)
  652. {
  653. return (regno == RETURN_VALUE_REGNUM);
  654. }
  655. /*{{{ Function arguments */
  656. /* Return true if we should pass an argument on the stack rather than
  657. in registers. */
  658. static bool
  659. fr30_must_pass_in_stack (machine_mode mode, const_tree type)
  660. {
  661. if (mode == BLKmode)
  662. return true;
  663. if (type == NULL)
  664. return false;
  665. return AGGREGATE_TYPE_P (type);
  666. }
  667. /* Compute the number of word sized registers needed to hold a
  668. function argument of mode INT_MODE and tree type TYPE. */
  669. static int
  670. fr30_num_arg_regs (machine_mode mode, const_tree type)
  671. {
  672. int size;
  673. if (targetm.calls.must_pass_in_stack (mode, type))
  674. return 0;
  675. if (type && mode == BLKmode)
  676. size = int_size_in_bytes (type);
  677. else
  678. size = GET_MODE_SIZE (mode);
  679. return (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  680. }
  681. /* Returns the number of bytes in which *part* of a parameter of machine
  682. mode MODE and tree type TYPE (which may be NULL if the type is not known).
  683. If the argument fits entirely in the argument registers, or entirely on
  684. the stack, then 0 is returned.
  685. CUM is the number of argument registers already used by earlier
  686. parameters to the function. */
  687. static int
  688. fr30_arg_partial_bytes (cumulative_args_t cum_v, machine_mode mode,
  689. tree type, bool named)
  690. {
  691. CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
  692. /* Unnamed arguments, i.e. those that are prototyped as ...
  693. are always passed on the stack.
  694. Also check here to see if all the argument registers are full. */
  695. if (named == 0 || *cum >= FR30_NUM_ARG_REGS)
  696. return 0;
  697. /* Work out how many argument registers would be needed if this
  698. parameter were to be passed entirely in registers. If there
  699. are sufficient argument registers available (or if no registers
  700. are needed because the parameter must be passed on the stack)
  701. then return zero, as this parameter does not require partial
  702. register, partial stack stack space. */
  703. if (*cum + fr30_num_arg_regs (mode, type) <= FR30_NUM_ARG_REGS)
  704. return 0;
  705. return (FR30_NUM_ARG_REGS - *cum) * UNITS_PER_WORD;
  706. }
  707. static rtx
  708. fr30_function_arg (cumulative_args_t cum_v, machine_mode mode,
  709. const_tree type, bool named)
  710. {
  711. CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
  712. if (!named
  713. || fr30_must_pass_in_stack (mode, type)
  714. || *cum >= FR30_NUM_ARG_REGS)
  715. return NULL_RTX;
  716. else
  717. return gen_rtx_REG (mode, *cum + FIRST_ARG_REGNUM);
  718. }
  719. /* A C statement (sans semicolon) to update the summarizer variable CUM to
  720. advance past an argument in the argument list. The values MODE, TYPE and
  721. NAMED describe that argument. Once this is done, the variable CUM is
  722. suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
  723. This macro need not do anything if the argument in question was passed on
  724. the stack. The compiler knows how to track the amount of stack space used
  725. for arguments without any special help. */
  726. static void
  727. fr30_function_arg_advance (cumulative_args_t cum, machine_mode mode,
  728. const_tree type, bool named)
  729. {
  730. *get_cumulative_args (cum) += named * fr30_num_arg_regs (mode, type);
  731. }
  732. /*}}}*/
  733. /*{{{ Operand predicates */
  734. #ifndef Mmode
  735. #define Mmode machine_mode
  736. #endif
  737. /* Returns true iff all the registers in the operands array
  738. are in descending or ascending order. */
  739. int
  740. fr30_check_multiple_regs (rtx *operands, int num_operands, int descending)
  741. {
  742. if (descending)
  743. {
  744. unsigned int prev_regno = 0;
  745. while (num_operands --)
  746. {
  747. if (GET_CODE (operands [num_operands]) != REG)
  748. return 0;
  749. if (REGNO (operands [num_operands]) < prev_regno)
  750. return 0;
  751. prev_regno = REGNO (operands [num_operands]);
  752. }
  753. }
  754. else
  755. {
  756. unsigned int prev_regno = CONDITION_CODE_REGNUM;
  757. while (num_operands --)
  758. {
  759. if (GET_CODE (operands [num_operands]) != REG)
  760. return 0;
  761. if (REGNO (operands [num_operands]) > prev_regno)
  762. return 0;
  763. prev_regno = REGNO (operands [num_operands]);
  764. }
  765. }
  766. return 1;
  767. }
  768. int
  769. fr30_const_double_is_zero (rtx operand)
  770. {
  771. REAL_VALUE_TYPE d;
  772. if (operand == NULL || GET_CODE (operand) != CONST_DOUBLE)
  773. return 0;
  774. REAL_VALUE_FROM_CONST_DOUBLE (d, operand);
  775. return REAL_VALUES_EQUAL (d, dconst0);
  776. }
  777. /*}}}*/
  778. /*{{{ Instruction Output Routines */
  779. /* Output a double word move.
  780. It must be REG<-REG, REG<-MEM, MEM<-REG or REG<-CONST.
  781. On the FR30 we are constrained by the fact that it does not
  782. support offsetable addresses, and so we have to load the
  783. address of the secnd word into the second destination register
  784. before we can use it. */
  785. rtx
  786. fr30_move_double (rtx * operands)
  787. {
  788. rtx src = operands[1];
  789. rtx dest = operands[0];
  790. enum rtx_code src_code = GET_CODE (src);
  791. enum rtx_code dest_code = GET_CODE (dest);
  792. machine_mode mode = GET_MODE (dest);
  793. rtx val;
  794. start_sequence ();
  795. if (dest_code == REG)
  796. {
  797. if (src_code == REG)
  798. {
  799. int reverse = (REGNO (dest) == REGNO (src) + 1);
  800. /* We normally copy the low-numbered register first. However, if
  801. the first register of operand 0 is the same as the second register
  802. of operand 1, we must copy in the opposite order. */
  803. emit_insn (gen_rtx_SET (VOIDmode,
  804. operand_subword (dest, reverse, TRUE, mode),
  805. operand_subword (src, reverse, TRUE, mode)));
  806. emit_insn (gen_rtx_SET (VOIDmode,
  807. operand_subword (dest, !reverse, TRUE, mode),
  808. operand_subword (src, !reverse, TRUE, mode)));
  809. }
  810. else if (src_code == MEM)
  811. {
  812. rtx addr = XEXP (src, 0);
  813. rtx dest0 = operand_subword (dest, 0, TRUE, mode);
  814. rtx dest1 = operand_subword (dest, 1, TRUE, mode);
  815. rtx new_mem;
  816. gcc_assert (GET_CODE (addr) == REG);
  817. /* Copy the address before clobbering it. See PR 34174. */
  818. emit_insn (gen_rtx_SET (SImode, dest1, addr));
  819. emit_insn (gen_rtx_SET (VOIDmode, dest0,
  820. adjust_address (src, SImode, 0)));
  821. emit_insn (gen_rtx_SET (SImode, dest1,
  822. plus_constant (SImode, dest1,
  823. UNITS_PER_WORD)));
  824. new_mem = gen_rtx_MEM (SImode, dest1);
  825. MEM_COPY_ATTRIBUTES (new_mem, src);
  826. emit_insn (gen_rtx_SET (VOIDmode, dest1, new_mem));
  827. }
  828. else if (src_code == CONST_INT || src_code == CONST_DOUBLE)
  829. {
  830. rtx words[2];
  831. split_double (src, &words[0], &words[1]);
  832. emit_insn (gen_rtx_SET (VOIDmode,
  833. operand_subword (dest, 0, TRUE, mode),
  834. words[0]));
  835. emit_insn (gen_rtx_SET (VOIDmode,
  836. operand_subword (dest, 1, TRUE, mode),
  837. words[1]));
  838. }
  839. }
  840. else if (src_code == REG && dest_code == MEM)
  841. {
  842. rtx addr = XEXP (dest, 0);
  843. rtx src0;
  844. rtx src1;
  845. gcc_assert (GET_CODE (addr) == REG);
  846. src0 = operand_subword (src, 0, TRUE, mode);
  847. src1 = operand_subword (src, 1, TRUE, mode);
  848. emit_move_insn (adjust_address (dest, SImode, 0), src0);
  849. if (REGNO (addr) == STACK_POINTER_REGNUM
  850. || REGNO (addr) == FRAME_POINTER_REGNUM)
  851. emit_insn (gen_rtx_SET (VOIDmode,
  852. adjust_address (dest, SImode, UNITS_PER_WORD),
  853. src1));
  854. else
  855. {
  856. rtx new_mem;
  857. rtx scratch_reg_r0 = gen_rtx_REG (SImode, 0);
  858. /* We need a scratch register to hold the value of 'address + 4'.
  859. We use r0 for this purpose. It is used for example for long
  860. jumps and is already marked to not be used by normal register
  861. allocation. */
  862. emit_insn (gen_movsi_internal (scratch_reg_r0, addr));
  863. emit_insn (gen_addsi_small_int (scratch_reg_r0, scratch_reg_r0,
  864. GEN_INT (UNITS_PER_WORD)));
  865. new_mem = gen_rtx_MEM (SImode, scratch_reg_r0);
  866. MEM_COPY_ATTRIBUTES (new_mem, dest);
  867. emit_move_insn (new_mem, src1);
  868. emit_insn (gen_blockage ());
  869. }
  870. }
  871. else
  872. /* This should have been prevented by the constraints on movdi_insn. */
  873. gcc_unreachable ();
  874. val = get_insns ();
  875. end_sequence ();
  876. return val;
  877. }
  878. /* Implement TARGET_FRAME_POINTER_REQUIRED. */
  879. bool
  880. fr30_frame_pointer_required (void)
  881. {
  882. return (flag_omit_frame_pointer == 0 || crtl->args.pretend_args_size > 0);
  883. }
  884. /*}}}*/
  885. /*{{{ Trampoline Output Routines */
  886. /* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.
  887. On the FR30, the trampoline is:
  888. nop
  889. ldi:32 STATIC, r12
  890. nop
  891. ldi:32 FUNCTION, r0
  892. jmp @r0
  893. The no-ops are to guarantee that the static chain and final
  894. target are 32 bit aligned within the trampoline. That allows us to
  895. initialize those locations with simple SImode stores. The alternative
  896. would be to use HImode stores. */
  897. static void
  898. fr30_asm_trampoline_template (FILE *f)
  899. {
  900. fprintf (f, "\tnop\n");
  901. fprintf (f, "\tldi:32\t#0, %s\n", reg_names [STATIC_CHAIN_REGNUM]);
  902. fprintf (f, "\tnop\n");
  903. fprintf (f, "\tldi:32\t#0, %s\n", reg_names [COMPILER_SCRATCH_REGISTER]);
  904. fprintf (f, "\tjmp\t@%s\n", reg_names [COMPILER_SCRATCH_REGISTER]);
  905. }
  906. /* Implement TARGET_TRAMPOLINE_INIT. */
  907. static void
  908. fr30_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
  909. {
  910. rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
  911. rtx mem;
  912. emit_block_move (m_tramp, assemble_trampoline_template (),
  913. GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
  914. mem = adjust_address (m_tramp, SImode, 4);
  915. emit_move_insn (mem, chain_value);
  916. mem = adjust_address (m_tramp, SImode, 12);
  917. emit_move_insn (mem, fnaddr);
  918. }
  919. /*}}}*/
  920. /* Local Variables: */
  921. /* folded-file: t */
  922. /* End: */