integrate.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. /* Procedure integration for GNU CC.
  2. Copyright (C) 1988 Free Software Foundation, Inc.
  3. Contributed by Michael Tiemann (tiemann@mcc.com)
  4. This file is part of GNU CC.
  5. GNU CC is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY. No author or distributor
  7. accepts responsibility to anyone for the consequences of using it
  8. or for whether it serves any particular purpose or works at all,
  9. unless he says so in writing. Refer to the GNU CC General Public
  10. License for full details.
  11. Everyone is granted permission to copy, modify and redistribute
  12. GNU CC, but only under the conditions described in the
  13. GNU CC General Public License. A copy of this license is
  14. supposed to have been given to you along with GNU CC so you
  15. can know your rights and responsibilities. It should be in a
  16. file named COPYING. Among other things, the copyright notice
  17. and this notice must be preserved on all copies. */
  18. #include <ctype.h>
  19. #include <stdio.h>
  20. #include <strings.h>
  21. #include "config.h"
  22. #include "rtl.h"
  23. #include "tree.h"
  24. #include "flags.h"
  25. #include "insn-flags.h"
  26. #include "expr.h"
  27. #include "obstack.h"
  28. #define obstack_chunk_alloc xmalloc
  29. #define obstack_chunk_free free
  30. extern int xmalloc ();
  31. extern void free ();
  32. extern struct obstack permanent_obstack, maybepermanent_obstack;
  33. extern struct obstack *rtl_obstack, *saveable_obstack, *current_obstack;
  34. #define MIN(x,y) ((x < y) ? x : y)
  35. extern tree pushdecl ();
  36. /* This is the target of the inline function being expanded,
  37. or NULL if there is none. */
  38. static rtx inline_target;
  39. /* We must take special care not to disrupt life too severely
  40. when performing procedure integration. One thing that that
  41. involves is not creating illegitimate address which reload
  42. cannot fix. Since we don't know what the frame pointer is
  43. not capable of (in a machine independent way), we create
  44. a pseudo-frame pointer which will have to do for now. */
  45. static rtx inline_fp_rtx;
  46. /* Convert old frame-pointer offsets to new. Parameters which only
  47. produce values (no addresses, and are never assigned), map directly
  48. to the pseudo-reg of the incoming value. Parameters that are
  49. assigned to but do not have their address taken are given a fresh
  50. pseudo-register. Parameters that have their address take are
  51. given a fresh stack-slot. */
  52. static rtx *parm_map;
  53. /* ?? Should this be done here?? It is not right now.
  54. Keep track of whether a given pseudo-register is the sum
  55. of the frame pointer and a const_int (or zero). */
  56. static char *fp_addr_p;
  57. /* For the local variables of the procdure being integrated that live
  58. on the frame, FRAME_POINTER_DELTA says how much to change their
  59. offsets by, so that they now live in the correct place on the
  60. frame of the function being compiled. */
  61. static int fp_delta;
  62. /* Return a copy of an rtx (as needed), substituting pseudo-register,
  63. labels, and frame-pointer offsets as necessary. */
  64. static rtx copy_rtx_and_substitute ();
  65. static void copy_parm_decls ();
  66. static void copy_decl_tree ();
  67. static rtx try_fold_cc0 ();
  68. /* We do some simple constant folding optimization. This optimization
  69. really exists primarily to save time inlining a function. It
  70. also help users who ask for inline functions without -O. */
  71. static rtx fold_out_const_cc0 ();
  72. /* Zero if the current function (whose FUNCTION_DECL is FNDECL)
  73. is safe and reasonable to integrate into other functions.
  74. Nonzero means value is a warning message with a single %s
  75. for the function's name. */
  76. char *
  77. function_cannot_inline_p (fndecl)
  78. register tree fndecl;
  79. {
  80. register rtx insn;
  81. tree last = tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
  82. int nargs = list_length (DECL_ARGUMENTS (fndecl));
  83. int max_insns = 4 * (4 + nargs + 16*TREE_INLINE (fndecl));
  84. register int ninsns = 0;
  85. register tree parms;
  86. /* No inlines with varargs. `grokdeclarator' gives a warning
  87. message about that if `inline' is specified. This code
  88. it put in to catch the volunteers. */
  89. if (last && TREE_VALUE (last) != void_type_node)
  90. return "varargs function `%s' cannot be inline";
  91. /* If its not even close, don't even look. */
  92. if (get_max_uid () > 2 * max_insns)
  93. return "function `%s' too large to be inline";
  94. /* Don't inline functions which have BLKmode arguments.
  95. Don't inline functions that take the address of
  96. a parameter and do not specify a function prototype. */
  97. for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
  98. {
  99. if (TYPE_MODE (TREE_TYPE (parms)) == BLKmode)
  100. return "function `%s' with large aggregate parameter cannot be inline";
  101. if (last == NULL_TREE && TREE_ADDRESSABLE (parms))
  102. return "function `%s' without prototype uses address of parameter;\n cannot be inline";
  103. }
  104. if (get_max_uid () > max_insns)
  105. {
  106. for (ninsns = 0, insn = get_first_nonparm_insn (); insn && ninsns < max_insns;
  107. insn = NEXT_INSN (insn))
  108. {
  109. if (GET_CODE (insn) == INSN
  110. || GET_CODE (insn) == JUMP_INSN
  111. || GET_CODE (insn) == CALL_INSN)
  112. ninsns++;
  113. }
  114. if (ninsns >= max_insns)
  115. return "function `%s' too large to be inline";
  116. }
  117. return 0;
  118. }
  119. /* Variables used within save_for_inline. */
  120. /* Mapping from old pesudo-register to new pseudo-registers.
  121. The first element of this map is reg_map[FIRST_PSEUDO_REGISTER].
  122. It allocated in `save_current_insns' and `expand_function_inline',
  123. and deallocated on exit from each of those routines. */
  124. static rtx *reg_map;
  125. /* Mapping from old code-labels to new code-labels.
  126. The first element of this map is label_map[min_labelno].
  127. It allocated in `save_current_insns' and `expand_function_inline',
  128. and deallocated on exit from each of those routines. */
  129. static rtx *label_map;
  130. /* Map pseudo reg number into the PARM_DECL for the parm living in the reg.
  131. Zero for a reg that isn't a parm's home.
  132. Only reg numbers less than max_parm_reg are mapped here. */
  133. static tree *parmdecl_map;
  134. /* Keep track of first pseudo-register beyond those that are parms. */
  135. static int max_parm_reg;
  136. /* On machines that perform a function return with a single
  137. instruction, such as the VAX, these return insns must be
  138. mapped into branch statements. */
  139. extern rtx return_label;
  140. /* Copy an rtx for save_for_inline. */
  141. static rtx copy_for_inline ();
  142. /* Make the insns and PARM_DECLs of the current function permanent
  143. and record other information in DECL_SAVED_INSNS to allow inlining
  144. of this function in subsequent calls. */
  145. void
  146. save_for_inline (fndecl)
  147. tree fndecl;
  148. {
  149. extern rtx *regno_reg_rtx; /* in emit-rtl.c. */
  150. extern current_function_args_size;
  151. rtx first_insn, last_insn, insn;
  152. rtx head, copy;
  153. tree parms;
  154. int max_labelno, min_labelno, i, len;
  155. int max_reg;
  156. /* Make and emit a return-label if we have not already done so. */
  157. if (return_label == 0)
  158. {
  159. return_label = gen_label_rtx ();
  160. emit_label (return_label);
  161. }
  162. /* Get some bounds on the labels and registers used. */
  163. max_labelno = max_label_num ();
  164. min_labelno = get_first_label_num ();
  165. max_parm_reg = max_parm_reg_num ();
  166. max_reg = max_reg_num ();
  167. /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
  168. Set TREE_VOLATILE to 0 if the parm is in a register, otherwise 1.
  169. Later we set TREE_READONLY to 0 if the parm is modified inside the fn. */
  170. parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
  171. for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
  172. {
  173. rtx p = DECL_RTL (parms);
  174. if (GET_CODE (p) == REG)
  175. {
  176. parmdecl_map[REGNO (p)] = parms;
  177. TREE_VOLATILE (parms) = 0;
  178. }
  179. else
  180. TREE_VOLATILE (parms) = 1;
  181. TREE_READONLY (parms) = 1;
  182. }
  183. /* The list of DECL_SAVES_INSNS, starts off with a header which
  184. contains the following information:
  185. the first insn of the function (not including the insns that copy
  186. parameters into registers).
  187. the first label used by that function,
  188. the last label used by that function,
  189. and the total number of registers used. */
  190. head = gen_inline_header_rtx (NULL, NULL, min_labelno, max_labelno,
  191. max_parm_reg, max_reg,
  192. current_function_args_size);
  193. /* We have now allocated all that needs to be allocated permanently
  194. on the rtx obstack. Set our high-water mark, so that we
  195. can free the rest of this when the time comes. */
  196. preserve_data ();
  197. /* Copy the chain insns of this function.
  198. Install the copied chain as the insns of this function,
  199. for continued compilation;
  200. the original chain is recorded as the DECL_SAVED_INSNS
  201. for inlining future calls. */
  202. /* If there are insns that copy parms from the stack into pseudo registers,
  203. those insns are not copied. `expand_inline_function' must
  204. emit the correct code to handle such things. */
  205. insn = get_insns ();
  206. if (GET_CODE (insn) != NOTE)
  207. abort ();
  208. first_insn = rtx_alloc (NOTE);
  209. NOTE_SOURCE_FILE (first_insn) = NOTE_SOURCE_FILE (insn);
  210. NOTE_LINE_NUMBER (first_insn) = NOTE_LINE_NUMBER (insn);
  211. INSN_UID (first_insn) = INSN_UID (insn);
  212. PREV_INSN (first_insn) = NULL;
  213. NEXT_INSN (first_insn) = NULL;
  214. last_insn = first_insn;
  215. /* Each pseudo-reg in the old insn chain must have a unique rtx in the copy.
  216. Make these new rtx's now, and install them in regno_reg_rtx, so they
  217. will be the official pseudo-reg rtx's for the rest of compilation. */
  218. reg_map = (rtx *) alloca ((max_reg + 1) * sizeof (rtx));
  219. len = sizeof (struct rtx_def) + (GET_RTX_LENGTH (REG) - 1) * sizeof (rtunion);
  220. for (i = max_reg - 1; i >= FIRST_PSEUDO_REGISTER; i--)
  221. reg_map[i] = (rtx)obstack_copy (&maybepermanent_obstack, regno_reg_rtx[i], len);
  222. bcopy (reg_map + FIRST_PSEUDO_REGISTER,
  223. regno_reg_rtx + FIRST_PSEUDO_REGISTER,
  224. (max_reg_num () - FIRST_PSEUDO_REGISTER) * sizeof (rtx));
  225. /* Likewise each label rtx must have a unique rtx as its copy. */
  226. label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
  227. label_map -= min_labelno;
  228. for (i = min_labelno; i < max_labelno; i++)
  229. label_map[i] = gen_label_rtx ();
  230. /* Now copy the chain of insns. */
  231. for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
  232. {
  233. switch (GET_CODE (insn))
  234. {
  235. case NOTE:
  236. copy = rtx_alloc (NOTE);
  237. NOTE_SOURCE_FILE (copy) = NOTE_SOURCE_FILE (insn);
  238. NOTE_LINE_NUMBER (copy) = NOTE_LINE_NUMBER (insn);
  239. break;
  240. case INSN:
  241. case CALL_INSN:
  242. case JUMP_INSN:
  243. copy = rtx_alloc (GET_CODE (insn));
  244. PATTERN (copy) = copy_for_inline (PATTERN (insn));
  245. INSN_CODE (copy) = -1;
  246. LOG_LINKS (copy) = NULL;
  247. REG_NOTES (copy) = copy_for_inline (REG_NOTES (insn));
  248. break;
  249. case CODE_LABEL:
  250. copy = label_map[CODE_LABEL_NUMBER (insn)];
  251. break;
  252. case BARRIER:
  253. copy = rtx_alloc (BARRIER);
  254. break;
  255. default:
  256. abort ();
  257. }
  258. INSN_UID (copy) = INSN_UID (insn);
  259. NEXT_INSN (last_insn) = copy;
  260. PREV_INSN (copy) = last_insn;
  261. last_insn = copy;
  262. }
  263. NEXT_INSN (last_insn) = NULL;
  264. NEXT_INSN (head) = get_first_nonparm_insn ();
  265. FIRST_PARM_INSN (head) = get_insns ();
  266. DECL_SAVED_INSNS (fndecl) = head;
  267. DECL_FRAME_SIZE (fndecl) = get_frame_size ();
  268. TREE_INLINE (fndecl) = 1;
  269. parmdecl_map = 0;
  270. label_map = 0;
  271. reg_map = 0;
  272. return_label = 0;
  273. set_new_first_and_last_insn (first_insn, last_insn);
  274. }
  275. /* Copy the rtx ORIG recursively, replacing pseudo-regs and labels
  276. according to `reg_map' and `label_map'.
  277. All other kinds of rtx are copied except those that can never be
  278. changed during compilation. */
  279. static rtx
  280. copy_for_inline (orig)
  281. rtx orig;
  282. {
  283. register rtx x = orig;
  284. register int i;
  285. register enum rtx_code code;
  286. register char *format_ptr;
  287. if (x == 0)
  288. return x;
  289. code = GET_CODE (x);
  290. /* These types may be freely shared. */
  291. switch (code)
  292. {
  293. case QUEUED:
  294. case CONST_INT:
  295. case CONST_DOUBLE:
  296. case SYMBOL_REF:
  297. case CODE_LABEL:
  298. case PC:
  299. case CC0:
  300. return x;
  301. case MEM:
  302. /* A MEM is allowed to be shared if its address is constant
  303. or is a constant plus one of the special registers. */
  304. if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
  305. return x;
  306. if (GET_CODE (XEXP (x, 0)) == PLUS
  307. && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
  308. && (REGNO (XEXP (XEXP (x, 0), 0)) == FRAME_POINTER_REGNUM
  309. || REGNO (XEXP (XEXP (x, 0), 0)) == ARG_POINTER_REGNUM)
  310. && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
  311. if (GET_CODE (XEXP (x, 0)) == REG
  312. && (REGNO (XEXP (x, 0)) == FRAME_POINTER_REGNUM
  313. || REGNO (XEXP (x, 0)) == ARG_POINTER_REGNUM)
  314. && CONSTANT_ADDRESS_P (XEXP (x, 1)))
  315. return x;
  316. break;
  317. case LABEL_REF:
  318. {
  319. /* Must point to the new insn. */
  320. return gen_rtx (LABEL_REF, GET_MODE (orig),
  321. label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))]);
  322. }
  323. case REG:
  324. if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
  325. return reg_map [REGNO (x)];
  326. else
  327. return x;
  328. /* If a parm that gets modified lives in a pseudo-reg,
  329. set its TREE_VOLATILE to prevent certain optimizations. */
  330. case SET:
  331. {
  332. rtx dest = SET_DEST (x);
  333. if (GET_CODE (dest) == REG
  334. && REGNO (dest) < max_parm_reg
  335. && REGNO (dest) >= FIRST_PSEUDO_REGISTER)
  336. TREE_READONLY (parmdecl_map[REGNO (dest)]) = 0;
  337. }
  338. break;
  339. }
  340. /* Replace this rtx with a copy of itself. */
  341. x = rtx_alloc (code);
  342. bcopy (orig, x, sizeof (int) * (GET_RTX_LENGTH (code) + 1));
  343. /* Now scan the subexpressions recursively.
  344. We can store any replaced subexpressions directly into X
  345. since we know X is not shared! Any vectors in X
  346. must be copied if X was copied. */
  347. format_ptr = GET_RTX_FORMAT (code);
  348. for (i = 0; i < GET_RTX_LENGTH (code); i++)
  349. {
  350. switch (*format_ptr++)
  351. {
  352. case 'e':
  353. XEXP (x, i) = copy_for_inline (XEXP (x, i));
  354. break;
  355. case 'E':
  356. if (XVEC (x, i) != NULL)
  357. {
  358. register int j;
  359. XVEC (x, i) = gen_rtvec_v (XVECLEN (x, i), &XVECEXP (x, i, 0));
  360. for (j = 0; j < XVECLEN (x, i); j++)
  361. XVECEXP (x, i, j)
  362. = copy_for_inline (XVECEXP (x, i, j));
  363. }
  364. break;
  365. }
  366. }
  367. return x;
  368. }
  369. /* Integrate the procedure defined by FNDECL. Note that this function
  370. may wind up calling itself. Since the static variables are not
  371. reentrant, we do not assign them until after the possibility
  372. or recursion is eliminated.
  373. If IGNORE is nonzero, do not produce a value.
  374. Otherwise store the value in TARGET if it is nonzero and that is convenient.
  375. Value is:
  376. (rtx)-1 if we could not substitute the function
  377. 0 if we substituted it and it does not produce a value
  378. else an rtx for where the value is stored. */
  379. rtx
  380. expand_inline_function (fndecl, parms, target, ignore, type, structure_value_addr)
  381. tree fndecl, parms;
  382. rtx target;
  383. int ignore;
  384. tree type;
  385. rtx structure_value_addr;
  386. {
  387. tree formal, actual;
  388. rtx header = DECL_SAVED_INSNS (fndecl);
  389. rtx insns = FIRST_FUNCTION_INSN (header);
  390. rtx insn, protect;
  391. rtx last_insn = get_last_insn ();
  392. int max_regno = MAX_REGNUM (header) + 1;
  393. register int i;
  394. int keep;
  395. int min_labelno = FIRST_LABELNO (header);
  396. int max_labelno = LAST_LABELNO (header);
  397. int nargs;
  398. rtx *arg_vec;
  399. rtx return_label = 0;
  400. rtx follows_call = 0;
  401. if (max_regno < FIRST_PSEUDO_REGISTER)
  402. return (rtx)-1;
  403. nargs = list_length (DECL_ARGUMENTS (fndecl));
  404. /* We expect PARMS to have the right length; don't crash if not. */
  405. if (list_length (parms) != nargs)
  406. return (rtx)-1;
  407. /* Make a fresh binding contour that we can easily remove. */
  408. pushlevel (0);
  409. expand_start_bindings (0);
  410. /* Get all the actual args as RTL, and store them in ARG_VEC. */
  411. arg_vec = (rtx *)alloca (nargs * sizeof (rtx));
  412. for (formal = DECL_ARGUMENTS (fndecl),
  413. actual = parms,
  414. i = 0;
  415. formal;
  416. formal = TREE_CHAIN (formal),
  417. actual = TREE_CHAIN (actual),
  418. i++)
  419. {
  420. tree arg = TREE_VALUE (actual); /* this has already been converted */
  421. enum machine_mode tmode = TYPE_MODE (TREE_TYPE (formal));
  422. tree decl = formal;
  423. rtx copy;
  424. emit_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  425. if (TREE_ADDRESSABLE (formal))
  426. {
  427. int size = int_size_in_bytes (TREE_TYPE (formal));
  428. copy = assign_stack_local (tmode, size);
  429. store_expr (arg, copy, 0);
  430. }
  431. else if (! TREE_READONLY (formal)
  432. || TREE_VOLATILE (formal))
  433. {
  434. /* If parm is modified or if it hasn't a pseudo reg,
  435. we may not simply substitute the actual value;
  436. copy it through a register. */
  437. copy = gen_reg_rtx (tmode);
  438. store_expr (arg, copy, 0);
  439. }
  440. else
  441. {
  442. copy = expand_expr (arg, 0, tmode, 0);
  443. /* We do not use CONSTANT_ADDRESS_P here because
  444. the set of cases where that might make a difference
  445. are a subset of the cases that arise even when
  446. it is a CONSTANT_ADDRESS_P (i.e., fp_delta
  447. gets into the act. */
  448. if (GET_CODE (copy) != REG && ! CONSTANT_P (copy))
  449. copy = copy_to_reg (copy);
  450. }
  451. arg_vec[i] = copy;
  452. }
  453. copy_parm_decls (DECL_ARGUMENTS (fndecl), arg_vec);
  454. /* Perform postincrements before actually calling the function. */
  455. emit_queue ();
  456. /* clean up stack so that variables might have smaller offsets. */
  457. do_pending_stack_adjust ();
  458. /* Pass the function the address in which to return a structure value. */
  459. if (structure_value_addr)
  460. emit_move_insn (struct_value_rtx, structure_value_addr);
  461. /* Now prepare for copying the insns.
  462. Set up reg_map, parm_map and label_map saying how to translate
  463. the pseudo-registers, stack-parm references and labels when copying. */
  464. reg_map = (rtx *) alloca (max_regno * sizeof (rtx));
  465. bzero (reg_map, max_regno * sizeof (rtx));
  466. if (DECL_ARGUMENTS (fndecl))
  467. {
  468. tree decl = DECL_ARGUMENTS (fndecl);
  469. tree last = tree_last (decl);
  470. int offset = FUNCTION_ARGS_SIZE (header);
  471. parm_map =
  472. (rtx *)alloca ((offset / UNITS_PER_WORD) * sizeof (rtx));
  473. bzero (parm_map, (offset / UNITS_PER_WORD) * sizeof (rtx));
  474. parm_map -= FIRST_PARM_OFFSET / UNITS_PER_WORD;
  475. for (formal = decl, i = 0; formal; formal = TREE_CHAIN (formal), i++)
  476. {
  477. /* Create an entry in PARM_MAP that says what pseudo register
  478. is associated with an address we might compute. */
  479. parm_map[DECL_OFFSET (formal) / BITS_PER_WORD] = arg_vec[i];
  480. /* Create an entry in REG_MAP that says what rtx is associated
  481. with a pseudo register from the function being inlined. */
  482. if (GET_CODE (DECL_RTL (formal)) == REG)
  483. reg_map[REGNO (DECL_RTL (formal))] = arg_vec[i];
  484. }
  485. }
  486. else
  487. {
  488. parm_map = NULL;
  489. }
  490. label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
  491. label_map -= min_labelno;
  492. for (i = min_labelno; i < max_labelno; i++)
  493. label_map[i] = gen_label_rtx ();
  494. /* Set up a target to translate the inline function's value-register. */
  495. if (structure_value_addr != 0 || TYPE_MODE (type) == VOIDmode)
  496. inline_target = 0;
  497. else if (target && GET_MODE (target) == TYPE_MODE (type))
  498. inline_target = target;
  499. else
  500. inline_target = gen_reg_rtx (TYPE_MODE (type));
  501. /* We are about to make space in this function's stack frame
  502. for a copy of the stack frame of the inline function.
  503. First, create an RTX that points to that stack frame
  504. with the same offset usually used for the frame pointer.
  505. This will be substituted for all frame-pointer references. */
  506. fp_delta = get_frame_size ();
  507. #ifdef FRAME_GROWS_DOWNWARD
  508. fp_delta = - fp_delta;
  509. #endif
  510. fp_delta -= STARTING_FRAME_OFFSET;
  511. inline_fp_rtx
  512. = copy_to_mode_reg (Pmode,
  513. plus_constant (frame_pointer_rtx, fp_delta));
  514. /* Now allocate the space for that to point at. */
  515. assign_stack_local (VOIDmode, DECL_FRAME_SIZE (fndecl));
  516. /* Now copy the insns one by one. */
  517. for (insn = insns; insn; insn = NEXT_INSN (insn))
  518. {
  519. rtx copy, pattern, next = 0;
  520. switch (GET_CODE (insn))
  521. {
  522. case INSN:
  523. pattern = PATTERN (insn);
  524. /* Special handling for the insn immediately after a CALL_INSN
  525. that returned a value:
  526. If it does copy the value, we must avoid the usual translation
  527. of the return-register into INLINE_TARGET.
  528. If it just USEs the value, the inline function expects it to
  529. stay in the return-register and be returned,
  530. so copy it into INLINE_TARGET. */
  531. if (follows_call
  532. /* Allow a stack-adjust, handled normally, to come in between
  533. the call and the value-copying insn. */
  534. && ! (GET_CODE (pattern) == SET
  535. && SET_DEST (pattern) == stack_pointer_rtx))
  536. {
  537. if (GET_CODE (pattern) == SET
  538. && rtx_equal_p (SET_SRC (pattern), follows_call))
  539. /* This insn copies the value: take special care to copy
  540. that value to this insn's destination. */
  541. {
  542. copy = emit_insn (gen_rtx (SET, VOIDmode,
  543. copy_rtx_and_substitute (SET_DEST (pattern)),
  544. follows_call));
  545. copy->integrated = 1;
  546. follows_call = 0;
  547. break;
  548. }
  549. else if (GET_CODE (pattern) == USE
  550. && rtx_equal_p (XEXP (pattern, 0), follows_call))
  551. /* This insn does nothing but says the value is expected
  552. to flow through to the inline function's return-value.
  553. Make that happen, then ignore this insn. */
  554. {
  555. copy = emit_insn (gen_rtx (SET, VOIDmode, inline_target,
  556. follows_call));
  557. copy->integrated = 1;
  558. follows_call = 0;
  559. break;
  560. }
  561. /* If it does neither, this value must be ignored. */
  562. follows_call = 0;
  563. }
  564. /* The (USE (REG n)) at return from the function should be ignored
  565. since we are changing (REG n) into inline_target. */
  566. if (GET_CODE (pattern) == USE
  567. && GET_CODE (XEXP (pattern, 0)) == REG
  568. && FUNCTION_VALUE_REGNO_P (REGNO (XEXP (pattern, 0))))
  569. break;
  570. /* Try to do some quick constant folding here.
  571. This will save save execution time of the compiler,
  572. as well time and space of the program if done here. */
  573. if (GET_CODE (pattern) == SET
  574. && SET_DEST (pattern) == cc0_rtx)
  575. next = try_fold_cc0 (insn);
  576. if (next != 0)
  577. {
  578. insn = next;
  579. }
  580. else
  581. {
  582. copy = emit_insn (copy_rtx_and_substitute (pattern));
  583. copy->integrated = 1;
  584. }
  585. break;
  586. case JUMP_INSN:
  587. follows_call = 0;
  588. if (GET_CODE (PATTERN (insn)) == RETURN)
  589. {
  590. if (return_label == 0)
  591. return_label = gen_label_rtx ();
  592. emit_jump (return_label);
  593. break;
  594. }
  595. copy = emit_jump_insn (copy_rtx_and_substitute (PATTERN (insn)));
  596. copy->integrated = 1;
  597. break;
  598. case CALL_INSN:
  599. {
  600. rtx newbod;
  601. /* If the call's body is (set (reg...) (call...)),
  602. the register is a function return register, but DON'T
  603. translate it into INLINE_TARGET because it describes the
  604. called function, not the caller's return value. */
  605. if (GET_CODE (PATTERN (insn)) == SET)
  606. newbod = gen_rtx (SET, VOIDmode, SET_DEST (PATTERN (insn)),
  607. copy_rtx_and_substitute (SET_SRC (PATTERN (insn))));
  608. else
  609. newbod = copy_rtx_and_substitute (PATTERN (insn));
  610. copy = emit_call_insn (newbod);
  611. }
  612. copy->integrated = 1;
  613. /* Special handling needed for the following INSN depending on
  614. whether it copies the value from the fcn return reg. */
  615. if (GET_CODE (PATTERN (insn)) == SET)
  616. follows_call = SET_DEST (PATTERN (insn));
  617. break;
  618. case CODE_LABEL:
  619. emit_label (label_map[CODE_LABEL_NUMBER (insn)]);
  620. follows_call = 0;
  621. break;
  622. case BARRIER:
  623. emit_barrier ();
  624. break;
  625. case NOTE:
  626. emit_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
  627. break;
  628. default:
  629. abort ();
  630. break;
  631. }
  632. }
  633. if (return_label)
  634. emit_label (return_label);
  635. /* Make copies of the decls of the symbols in the inline function, so that
  636. the copies of the variables get declared in the current function. */
  637. copy_decl_tree (DECL_INITIAL (fndecl), 0);
  638. /* End the scope containing the copied formal parameter variables. */
  639. expand_end_bindings (getdecls (), 1);
  640. poplevel (1, 1, 0);
  641. reg_map = NULL;
  642. label_map = NULL;
  643. if (ignore || TYPE_MODE (type) == VOIDmode)
  644. return 0;
  645. if (structure_value_addr)
  646. {
  647. if (target)
  648. return target;
  649. return gen_rtx (MEM, BLKmode,
  650. memory_address (BLKmode, structure_value_addr));
  651. }
  652. return inline_target;
  653. }
  654. /* Given a chain of PARM_DECLs, ARGS, and a vector of RTL homes VEC,
  655. copy each decl into a VAR_DECL, push all of those decls
  656. and give each one the corresponding home. */
  657. static void
  658. copy_parm_decls (args, vec)
  659. tree args;
  660. rtx *vec;
  661. {
  662. register tree tail;
  663. register int i;
  664. for (tail = args, i = 0; tail; tail = TREE_CHAIN (tail), i++)
  665. {
  666. register tree decl = pushdecl (build_decl (VAR_DECL, DECL_NAME (tail),
  667. TREE_TYPE (tail)));
  668. DECL_RTL (decl) = vec[i];
  669. }
  670. }
  671. /* Given a LET_STMT node, push decls and levels
  672. so as to construct in the current function a tree of contexts
  673. isomorphic to the one that is given. */
  674. static void
  675. copy_decl_tree (let, level)
  676. tree let;
  677. int level;
  678. {
  679. tree t;
  680. pushlevel (0);
  681. for (t = STMT_VARS (let); t; t = TREE_CHAIN (t))
  682. {
  683. tree d = build_decl (TREE_CODE (t), DECL_NAME (t), TREE_TYPE (t));
  684. DECL_SOURCE_LINE (d) = DECL_SOURCE_LINE (t);
  685. DECL_SOURCE_FILE (d) = DECL_SOURCE_FILE (t);
  686. if (DECL_RTL (t) != 0)
  687. DECL_RTL (d) = copy_rtx_and_substitute (DECL_RTL (t));
  688. TREE_EXTERNAL (d) = TREE_EXTERNAL (t);
  689. TREE_STATIC (d) = TREE_STATIC (t);
  690. TREE_PUBLIC (d) = TREE_PUBLIC (t);
  691. TREE_LITERAL (d) = TREE_LITERAL (t);
  692. TREE_ADDRESSABLE (d) = TREE_ADDRESSABLE (t);
  693. TREE_READONLY (d) = TREE_READONLY (t);
  694. TREE_VOLATILE (d) = TREE_VOLATILE (t);
  695. pushdecl (d);
  696. }
  697. for (t = STMT_BODY (let); t; t = TREE_CHAIN (t))
  698. copy_decl_tree (t, level + 1);
  699. poplevel (level > 0, 0, 0);
  700. }
  701. /* Create a new copy of an rtx.
  702. Recursively copies the operands of the rtx,
  703. except for those few rtx codes that are sharable. */
  704. static rtx
  705. copy_rtx_and_substitute (orig)
  706. register rtx orig;
  707. {
  708. register rtx copy, temp;
  709. register int i, j;
  710. register RTX_CODE code;
  711. register enum machine_mode mode;
  712. register char *format_ptr;
  713. int regno;
  714. if (orig == 0)
  715. return 0;
  716. code = GET_CODE (orig);
  717. mode = GET_MODE (orig);
  718. switch (code)
  719. {
  720. case REG:
  721. /* If a frame-pointer register shows up, then we
  722. must `fix' the reference. If the stack pointer
  723. register shows up, it must be part of stack-adjustments
  724. (*not* because we eliminated the frame pointer!).
  725. Small hard registers are returned as-is. Pseudo-registers
  726. go through their `reg_map'. */
  727. regno = REGNO (orig);
  728. if (regno < FIRST_PSEUDO_REGISTER)
  729. {
  730. if (FUNCTION_VALUE_REGNO_P (regno))
  731. return inline_target;
  732. if (regno == FRAME_POINTER_REGNUM)
  733. return plus_constant (orig, fp_delta);
  734. return orig;
  735. }
  736. if (reg_map[regno] == NULL)
  737. reg_map[regno] = gen_reg_rtx (mode);
  738. return reg_map[regno];
  739. case CODE_LABEL:
  740. return label_map[CODE_LABEL_NUMBER (orig)];
  741. case LABEL_REF:
  742. copy = rtx_alloc (LABEL_REF);
  743. PUT_MODE (copy, mode);
  744. XEXP (copy, 0) = label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))];
  745. return copy;
  746. case PC:
  747. case CC0:
  748. case CONST_INT:
  749. case CONST_DOUBLE:
  750. case SYMBOL_REF:
  751. return orig;
  752. case PLUS:
  753. /* Note: the PLUS case is not nearly as careful as the MEM
  754. case in terms of preserving addresses. The reason for this
  755. is that it is expected that if a PLUS_EXPR turns out not
  756. to be a legitimate address, reload can fix that up, without
  757. doing major damage. However, a MEM rtx must preside
  758. over a legitimate address. The MEM case has lots of hair
  759. to deal with what happens when it sits on a PLUS... */
  760. /* Take care of the easy case quickly. */
  761. if (XEXP (orig, 0) == frame_pointer_rtx
  762. || XEXP (orig, 1) == frame_pointer_rtx
  763. || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  764. && (XEXP (orig, 0) == arg_pointer_rtx
  765. || XEXP (orig, 1) == arg_pointer_rtx)))
  766. {
  767. if (XEXP (orig, 0) == frame_pointer_rtx
  768. || XEXP (orig, 0) == arg_pointer_rtx)
  769. copy = XEXP (orig, 1);
  770. else
  771. copy = XEXP (orig, 0);
  772. if (GET_CODE (copy) == CONST_INT)
  773. {
  774. int c = INTVAL (copy);
  775. if (c > 0)
  776. {
  777. copy = parm_map[c / UNITS_PER_WORD];
  778. return XEXP (copy, 0);
  779. }
  780. return gen_rtx (PLUS, mode,
  781. frame_pointer_rtx,
  782. gen_rtx (CONST_INT, SImode,
  783. c + fp_delta));
  784. }
  785. copy = copy_rtx_and_substitute (copy);
  786. temp = gen_rtx (PLUS, mode, frame_pointer_rtx, copy);
  787. return plus_constant (temp, fp_delta);
  788. }
  789. else if (reg_mentioned_p (frame_pointer_rtx, orig)
  790. || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  791. && reg_mentioned_p (arg_pointer_rtx, orig)))
  792. {
  793. /* If we have a complex sum which has a frame pointer
  794. in it, and it was a legitimate address, then
  795. keep it that way. */
  796. if (memory_address_p (mode, orig))
  797. {
  798. if (GET_CODE (XEXP (orig, 0)) == CONST_INT)
  799. {
  800. copy = copy_rtx_and_substitute (XEXP (orig, 1));
  801. temp = plus_constant (copy, INTVAL (XEXP (orig, 0)));
  802. }
  803. else if (GET_CODE (XEXP (orig, 1)) == CONST_INT)
  804. {
  805. copy = copy_rtx_and_substitute (XEXP (orig, 0));
  806. temp = plus_constant (copy, INTVAL (XEXP (orig, 1)));
  807. }
  808. else
  809. {
  810. temp = gen_rtx (PLUS, GET_MODE (orig),
  811. copy_rtx_and_substitute (XEXP (orig, 0)),
  812. copy_rtx_and_substitute (XEXP (orig, 1)));
  813. }
  814. temp = memory_address (mode, temp);
  815. }
  816. else
  817. temp = gen_rtx (PLUS, GET_MODE (orig),
  818. copy_rtx_and_substitute (XEXP (orig, 0)),
  819. copy_rtx_and_substitute (XEXP (orig, 1)));
  820. }
  821. else
  822. temp = gen_rtx (PLUS, GET_MODE (orig),
  823. copy_rtx_and_substitute (XEXP (orig, 0)),
  824. copy_rtx_and_substitute (XEXP (orig, 1)));
  825. return temp;
  826. case MEM:
  827. /* Take care of easiest case here. */
  828. copy = XEXP (orig, 0);
  829. if (copy == frame_pointer_rtx || copy == arg_pointer_rtx)
  830. return gen_rtx (MEM, mode,
  831. plus_constant (frame_pointer_rtx, fp_delta));
  832. if (GET_CODE (copy) == PLUS)
  833. {
  834. if (XEXP (copy, 0) == frame_pointer_rtx
  835. || XEXP (copy, 1) == frame_pointer_rtx
  836. || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  837. && (XEXP (copy, 0) == arg_pointer_rtx
  838. || XEXP (copy, 1) == arg_pointer_rtx)))
  839. {
  840. rtx reg;
  841. if (XEXP (copy, 0) == frame_pointer_rtx
  842. || XEXP (copy, 0) == arg_pointer_rtx)
  843. reg = XEXP (copy, 0), copy = XEXP (copy, 1);
  844. else
  845. reg = XEXP (copy, 1), copy = XEXP (copy, 0);
  846. if (GET_CODE (copy) == CONST_INT)
  847. {
  848. int c = INTVAL (copy);
  849. if (reg == arg_pointer_rtx
  850. && c >= FIRST_PARM_OFFSET)
  851. {
  852. copy = parm_map[c / UNITS_PER_WORD];
  853. /* If the MEM is only some of the bytes in the parm,
  854. truncate the parm value to the desired mode. */
  855. if (GET_MODE (copy) != mode
  856. && GET_MODE (copy) != VOIDmode)
  857. return convert_to_mode (mode, copy, 0);
  858. return copy;
  859. }
  860. temp = gen_rtx (PLUS, Pmode,
  861. frame_pointer_rtx,
  862. gen_rtx (CONST_INT, SImode,
  863. c + fp_delta));
  864. if (! memory_address_p (Pmode, temp))
  865. return gen_rtx (MEM, mode, plus_constant (inline_fp_rtx, c));
  866. }
  867. copy = copy_rtx_and_substitute (copy);
  868. temp = gen_rtx (PLUS, Pmode, frame_pointer_rtx, copy);
  869. temp = plus_constant (temp, fp_delta);
  870. temp = memory_address (Pmode, temp);
  871. }
  872. else if (reg_mentioned_p (frame_pointer_rtx, copy)
  873. || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  874. && reg_mentioned_p (arg_pointer_rtx, copy)))
  875. {
  876. if (GET_CODE (XEXP (copy, 0)) == CONST_INT)
  877. {
  878. temp = copy_rtx_and_substitute (XEXP (copy, 1));
  879. temp = plus_constant (temp, INTVAL (XEXP (copy, 0)));
  880. }
  881. else if (GET_CODE (XEXP (copy, 1)) == CONST_INT)
  882. {
  883. temp = copy_rtx_and_substitute (XEXP (copy, 0));
  884. temp = plus_constant (temp, INTVAL (XEXP (copy, 1)));
  885. }
  886. else
  887. {
  888. temp = gen_rtx (PLUS, GET_MODE (copy),
  889. copy_rtx_and_substitute (XEXP (copy, 0)),
  890. copy_rtx_and_substitute (XEXP (copy, 1)));
  891. }
  892. }
  893. else
  894. {
  895. if (GET_CODE (XEXP (copy, 1)) == CONST_INT)
  896. temp = plus_constant (copy_rtx_and_substitute (XEXP (copy, 0)),
  897. INTVAL (XEXP (copy, 1)));
  898. else if (GET_CODE (XEXP (copy, 0)) == CONST_INT)
  899. temp = plus_constant (copy_rtx_and_substitute (XEXP (copy, 1)),
  900. INTVAL (XEXP (copy, 0)));
  901. else
  902. {
  903. rtx left = copy_rtx_and_substitute (XEXP (copy, 0));
  904. rtx right = copy_rtx_and_substitute (XEXP (copy, 1));
  905. temp = gen_rtx (PLUS, GET_MODE (copy), left, right);
  906. }
  907. }
  908. }
  909. else
  910. temp = copy_rtx_and_substitute (copy);
  911. return change_address (orig, mode, temp);
  912. case RETURN:
  913. abort ();
  914. }
  915. copy = rtx_alloc (code);
  916. PUT_MODE (copy, mode);
  917. copy->in_struct = orig->in_struct;
  918. copy->volatil = orig->volatil;
  919. copy->unchanging = orig->unchanging;
  920. format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
  921. for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
  922. {
  923. rtx new;
  924. switch (*format_ptr++)
  925. {
  926. case 'u':
  927. case '0':
  928. break;
  929. case 'e':
  930. XEXP (copy, i) = copy_rtx_and_substitute (XEXP (orig, i));
  931. break;
  932. case 'E':
  933. XVEC (copy, i) = XVEC (orig, i);
  934. if (XVEC (orig, i) != NULL)
  935. {
  936. XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
  937. for (j = 0; j < XVECLEN (copy, i); j++)
  938. XVECEXP (copy, i, j) = copy_rtx_and_substitute (XVECEXP (orig, i, j));
  939. }
  940. break;
  941. case 'i':
  942. XINT (copy, i) = XINT (orig, i);
  943. break;
  944. case 's':
  945. XSTR (copy, i) = XSTR (orig, i);
  946. break;
  947. default:
  948. fprintf (stderr,
  949. "switch format wrong in rtl2.copy_rtx_and_substitute(). format was: %c.\n",
  950. format_ptr[-1]);
  951. abort ();
  952. }
  953. }
  954. return copy;
  955. }
  956. /* Attempt to simplify INSN while copying it from an inline fn,
  957. assuming it is a SET that sets CC0.
  958. If we simplify it, we emit the appropriate insns and return
  959. the last insn that we have handled (since we may handle the insn
  960. that follows INSN as well as INSN itself).
  961. Otherwise we do nothing and return zero. */
  962. static rtx
  963. try_fold_cc0 (insn)
  964. rtx insn;
  965. {
  966. rtx cnst = copy_rtx_and_substitute (SET_SRC (PATTERN (insn)));
  967. rtx pat, copy;
  968. if (CONSTANT_P (cnst)
  969. /* @@ Cautious: Don't know how many of these tests we need. */
  970. && NEXT_INSN (insn)
  971. && GET_CODE (pat = PATTERN (NEXT_INSN (insn))) == SET
  972. && SET_DEST (pat) == pc_rtx
  973. && GET_CODE (pat = SET_SRC (pat)) == IF_THEN_ELSE
  974. && GET_RTX_LENGTH (GET_CODE (XEXP (pat, 0))) == 2)
  975. {
  976. rtx cnst2;
  977. rtx cond = XEXP (pat, 0);
  978. if ((XEXP (cond, 0) == cc0_rtx
  979. && CONSTANT_P (XEXP (cond, 1))
  980. && (cnst2 = XEXP (cond, 1)))
  981. || (XEXP (cond, 1) == cc0_rtx
  982. && CONSTANT_P (XEXP (cond, 0))
  983. && (cnst2 = XEXP (cond, 0))))
  984. {
  985. copy = fold_out_const_cc0 (cond, XEXP (pat, 1), XEXP (pat, 2),
  986. cnst, cnst2);
  987. if (copy)
  988. {
  989. if (GET_CODE (copy) == LABEL_REF)
  990. {
  991. /* We will branch unconditionally to
  992. the label specified by COPY.
  993. Eliminate dead code by running down the
  994. list of insn until we see a CODE_LABEL.
  995. If the CODE_LABEL is the one specified
  996. by COPY, we win, and can delete all code
  997. up to (but not necessarily including)
  998. that label. Otherwise only win a little:
  999. emit the branch insn, and continue expanding. */
  1000. rtx tmp = NEXT_INSN (insn);
  1001. while (tmp && GET_CODE (tmp) != CODE_LABEL)
  1002. tmp = NEXT_INSN (tmp);
  1003. if (! tmp)
  1004. abort ();
  1005. if (label_map[CODE_LABEL_NUMBER (tmp)] == XEXP (copy, 0))
  1006. {
  1007. /* Big win. */
  1008. return PREV_INSN (tmp);
  1009. }
  1010. else
  1011. {
  1012. /* Small win. Emit the unconditional branch,
  1013. followed by a BARRIER, so that jump optimization
  1014. will know what to do. */
  1015. emit_jump (copy);
  1016. return NEXT_INSN (insn);
  1017. }
  1018. }
  1019. else if (copy == pc_rtx)
  1020. {
  1021. /* Do not take the branch, just fall through.
  1022. Jump optimize should handle the elimination of
  1023. dead code if appropriate. */
  1024. return NEXT_INSN (insn);
  1025. }
  1026. else
  1027. abort ();
  1028. }
  1029. }
  1030. }
  1031. return 0;
  1032. }
  1033. /* If (COND_RTX CNST1 CNST2) yield a result we can treat
  1034. as being constant, return THEN_RTX if the result is always
  1035. non-zero, and return ELSE_RTX otherwise. */
  1036. static rtx
  1037. fold_out_const_cc0 (cond_rtx, then_rtx, else_rtx, cnst1, cnst2)
  1038. rtx cond_rtx, then_rtx, else_rtx;
  1039. rtx cnst1, cnst2;
  1040. {
  1041. int value1, value2;
  1042. int int1 = GET_CODE (cnst1) == CONST_INT;
  1043. int int2 = GET_CODE (cnst2) == CONST_INT;
  1044. if (int1)
  1045. value1 = INTVAL (cnst1);
  1046. else
  1047. value1 = 1;
  1048. if (int2)
  1049. value2 = INTVAL (cnst2);
  1050. else
  1051. value2 = 1;
  1052. switch (GET_CODE (cond_rtx))
  1053. {
  1054. case NE:
  1055. if (int1 && int2)
  1056. if (value1 != value2)
  1057. return copy_rtx_and_substitute (then_rtx);
  1058. else
  1059. return copy_rtx_and_substitute (else_rtx);
  1060. if (value1 == 0 || value2 == 0)
  1061. return copy_rtx_and_substitute (then_rtx);
  1062. if (int1 == 0 && int2 == 0)
  1063. if (rtx_equal_p (cnst1, cnst2))
  1064. return copy_rtx_and_substitute (else_rtx);
  1065. break;
  1066. case EQ:
  1067. if (int1 && int2)
  1068. if (value1 == value2)
  1069. return copy_rtx_and_substitute (then_rtx);
  1070. else
  1071. return copy_rtx_and_substitute (else_rtx);
  1072. if (value1 == 0 || value2 == 0)
  1073. return copy_rtx_and_substitute (else_rtx);
  1074. if (int1 == 0 && int2 == 0)
  1075. if (rtx_equal_p (cnst1, cnst2))
  1076. return copy_rtx_and_substitute (then_rtx);
  1077. break;
  1078. case GE:
  1079. if (int1 && int2)
  1080. if (value1 >= value2)
  1081. return copy_rtx_and_substitute (then_rtx);
  1082. else
  1083. return copy_rtx_and_substitute (else_rtx);
  1084. if (value1 == 0)
  1085. return copy_rtx_and_substitute (else_rtx);
  1086. if (value2 == 0)
  1087. return copy_rtx_and_substitute (then_rtx);
  1088. break;
  1089. case GT:
  1090. if (int1 && int2)
  1091. if (value1 > value2)
  1092. return copy_rtx_and_substitute (then_rtx);
  1093. else
  1094. return copy_rtx_and_substitute (else_rtx);
  1095. if (value1 == 0)
  1096. return copy_rtx_and_substitute (else_rtx);
  1097. if (value2 == 0)
  1098. return copy_rtx_and_substitute (then_rtx);
  1099. break;
  1100. case LE:
  1101. if (int1 && int2)
  1102. if (value1 <= value2)
  1103. return copy_rtx_and_substitute (then_rtx);
  1104. else
  1105. return copy_rtx_and_substitute (else_rtx);
  1106. if (value1 == 0)
  1107. return copy_rtx_and_substitute (then_rtx);
  1108. if (value2 == 0)
  1109. return copy_rtx_and_substitute (else_rtx);
  1110. break;
  1111. case LT:
  1112. if (int1 && int2)
  1113. if (value1 < value2)
  1114. return copy_rtx_and_substitute (then_rtx);
  1115. else
  1116. return copy_rtx_and_substitute (else_rtx);
  1117. if (value1 == 0)
  1118. return copy_rtx_and_substitute (then_rtx);
  1119. if (value2 == 0)
  1120. return copy_rtx_and_substitute (else_rtx);
  1121. break;
  1122. case GEU:
  1123. if (int1 && int2)
  1124. if ((unsigned)value1 >= (unsigned)value2)
  1125. return copy_rtx_and_substitute (then_rtx);
  1126. else
  1127. return copy_rtx_and_substitute (else_rtx);
  1128. if (value1 == 0)
  1129. return copy_rtx_and_substitute (else_rtx);
  1130. if (value2 == 0)
  1131. return copy_rtx_and_substitute (then_rtx);
  1132. break;
  1133. case GTU:
  1134. if (int1 && int2)
  1135. if ((unsigned)value1 > (unsigned)value2)
  1136. return copy_rtx_and_substitute (then_rtx);
  1137. else
  1138. return copy_rtx_and_substitute (else_rtx);
  1139. if (value1 == 0)
  1140. return copy_rtx_and_substitute (else_rtx);
  1141. if (value2 == 0)
  1142. return copy_rtx_and_substitute (then_rtx);
  1143. break;
  1144. case LEU:
  1145. if (int1 && int2)
  1146. if ((unsigned)value1 <= (unsigned)value2)
  1147. return copy_rtx_and_substitute (then_rtx);
  1148. else
  1149. return copy_rtx_and_substitute (else_rtx);
  1150. if (value1 == 0)
  1151. return copy_rtx_and_substitute (then_rtx);
  1152. if (value2 == 0)
  1153. return copy_rtx_and_substitute (else_rtx);
  1154. break;
  1155. case LTU:
  1156. if (int1 && int2)
  1157. if ((unsigned)value1 < (unsigned)value2)
  1158. return copy_rtx_and_substitute (then_rtx);
  1159. else
  1160. return copy_rtx_and_substitute (else_rtx);
  1161. if (value1 == 0)
  1162. return copy_rtx_and_substitute (then_rtx);
  1163. if (value2 == 0)
  1164. return copy_rtx_and_substitute (else_rtx);
  1165. break;
  1166. }
  1167. /* Could not hack it. */
  1168. return 0;
  1169. }
  1170. /* Output the assembly language code for the function FNDECL
  1171. from its DECL_SAVED_INSNS. Used for inline functions that are output
  1172. at end of compilation instead of where they came in the source. */
  1173. void
  1174. output_inline_function (fndecl)
  1175. tree fndecl;
  1176. {
  1177. rtx head = DECL_SAVED_INSNS (fndecl);
  1178. rtx last;
  1179. temporary_allocation ();
  1180. /* This call is only used to initialize global variables.
  1181. The rtl code it emits will be discarded below. */
  1182. expand_function_start (fndecl);
  1183. /* Set stack frame size. */
  1184. assign_stack_local (BLKmode, DECL_FRAME_SIZE (fndecl));
  1185. restore_reg_data (FIRST_PARM_INSN (head));
  1186. expand_function_end (fndecl);
  1187. for (last = head; NEXT_INSN (last); last = NEXT_INSN (last))
  1188. ;
  1189. set_new_first_and_last_insn (FIRST_PARM_INSN (head), last);
  1190. /* Compile this function all the way down to assembly code. */
  1191. rest_of_compilation (fndecl);
  1192. permanent_allocation ();
  1193. }