|
|
1.1 root 1: /* Expands front end tree to back end RTL for GNU C-Compiler 1.1.1.15! root 2: Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc. 1.1 root 3: 4: This file is part of GNU CC. 5: 1.1.1.15! root 6: GNU CC is free software; you can redistribute it and/or modify ! 7: it under the terms of the GNU General Public License as published by ! 8: the Free Software Foundation; either version 1, or (at your option) ! 9: any later version. ! 10: 1.1 root 11: GNU CC is distributed in the hope that it will be useful, 1.1.1.15! root 12: but WITHOUT ANY WARRANTY; without even the implied warranty of ! 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! 14: GNU General Public License for more details. ! 15: ! 16: You should have received a copy of the GNU General Public License ! 17: along with GNU CC; see the file COPYING. If not, write to ! 18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 1.1 root 19: 20: 21: /* This file handles the generation of rtl code from tree structure 1.1.1.2 root 22: above the level of expressions, using subroutines in exp*.c and emit-rtl.c. 1.1 root 23: It also creates the rtl expressions for parameters and auto variables 24: and has full responsibility for allocating stack slots. 25: 1.1.1.2 root 26: The functions whose names start with `expand_' are called by the 27: parser to generate RTL instructions for various kinds of constructs. 28: 29: Some control and binding constructs require calling several such 30: functions at different times. For example, a simple if-then 31: is expanded by calling `expand_start_cond' (with the condition-expression 32: as argument) before parsing the then-clause and calling `expand_end_cond' 33: after parsing the then-clause. 34: 1.1.1.10 root 35: `expand_function_start' is called at the beginning of a function, 36: before the function body is parsed, and `expand_function_end' is 1.1.1.2 root 37: called after parsing the body. 38: 39: Call `assign_stack_local' to allocate a stack slot for a local variable. 40: This is usually done during the RTL generation for the function body, 41: but it can also be done in the reload pass when a pseudo-register does 42: not get a hard register. 43: 44: Call `put_var_into_stack' when you learn, belatedly, that a variable 45: previously given a pseudo-register must in fact go in the stack. 46: This function changes the DECL_RTL to be a stack slot instead of a reg 47: then scans all the RTL instructions so far generated to correct them. */ 1.1 root 48: 49: #include "config.h" 50: 51: #include <stdio.h> 52: 53: #include "rtl.h" 54: #include "tree.h" 1.1.1.2 root 55: #include "flags.h" 1.1 root 56: #include "insn-flags.h" 1.1.1.2 root 57: #include "insn-config.h" 1.1 root 58: #include "expr.h" 1.1.1.2 root 59: #include "regs.h" 1.1 root 60: 61: #define MAX(x,y) (((x) > (y)) ? (x) : (y)) 62: #define MIN(x,y) (((x) < (y)) ? (x) : (y)) 63: 1.1.1.2 root 64: /* Nonzero if function being compiled pops its args on return. 65: May affect compilation of return insn or of function epilogue. */ 66: 67: int current_function_pops_args; 68: 1.1.1.10 root 69: /* Nonzero if function being compiled needs to be given an address 70: where the value should be stored. */ 71: 72: int current_function_returns_struct; 73: 1.1.1.15! root 74: /* Nonzero if function being compiled needs to ! 75: return the address of where it has put a structure value. */ ! 76: ! 77: int current_function_returns_pcc_struct; ! 78: 1.1.1.10 root 79: /* Nonzero if function being compiled needs to be passed a static chain. */ 80: 81: int current_function_needs_context; 82: 1.1.1.11 root 83: /* Nonzero if function being compiled can call setjmp. */ 84: 85: int current_function_calls_setjmp; 86: 1.1.1.2 root 87: /* If function's args have a fixed size, this is that size, in bytes. 88: Otherwise, it is -1. 89: May affect compilation of return insn or of function epilogue. */ 90: 91: int current_function_args_size; 92: 93: /* # bytes the prologue should push and pretend that the caller pushed them. 94: The prologue must do this, but only if parms can be passed in registers. */ 95: 96: int current_function_pretend_args_size; 97: 98: /* Name of function now being compiled. */ 99: 100: char *current_function_name; 101: 1.1 root 102: /* Label that will go on function epilogue. 103: Jumping to this label serves as a "return" instruction 104: on machines which require execution of the epilogue on all returns. */ 105: 1.1.1.2 root 106: rtx return_label; 1.1 root 107: 1.1.1.5 root 108: /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs. 109: So we can mark them all live at the end of the function, if nonopt. */ 110: rtx save_expr_regs; 111: 1.1.1.13 root 112: /* List (chain of EXPR_LISTs) of all stack slots in this function. 113: Made for the sake of unshare_all_rtl. */ 114: rtx stack_slot_list; 115: 1.1.1.15! root 116: /* Filename and line number of last line-number note, ! 117: whether we actually emitted it or not. */ ! 118: char *emit_filename; ! 119: int emit_lineno; ! 120: 1.1.1.5 root 121: /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */ 122: static rtx parm_birth_insn; 123: 1.1 root 124: /* The FUNCTION_DECL node for the function being compiled. */ 125: 126: static tree this_function; 127: 128: /* Offset to end of allocated area of stack frame. 129: If stack grows down, this is the address of the last stack slot allocated. 130: If stack grows up, this is the address for the next slot. */ 131: static int frame_offset; 132: 1.1.1.2 root 133: /* Nonzero if a stack slot has been generated whose address is not 134: actually valid. It means that the generated rtl must all be scanned 135: to detect and correct the invalid addresses where they occur. */ 136: static int invalid_stack_slot; 1.1 root 137: 138: /* Label to jump back to for tail recursion, or 0 if we have 139: not yet needed one for this function. */ 140: static rtx tail_recursion_label; 141: 142: /* Place after which to insert the tail_recursion_label if we need one. */ 143: static rtx tail_recursion_reentry; 144: 1.1.1.2 root 145: /* Each time we expand an expression-statement, 146: record the expr's type and its RTL value here. */ 147: 148: static tree last_expr_type; 149: static rtx last_expr_value; 150: 1.1.1.10 root 151: /* Chain of all RTL_EXPRs that have insns in them. */ 152: static tree rtl_expr_chain; 153: 1.1.1.8 root 154: /* Last insn of those whose job was to put parms into their nominal homes. */ 155: static rtx last_parm_insn; 156: 1.1.1.6 root 157: static void expand_goto_internal (); 158: static int expand_fixup (); 1.1.1.2 root 159: static void fixup_gotos (); 1.1.1.7 root 160: static void expand_cleanups (); 161: static void fixup_cleanups (); 1.1.1.8 root 162: static void expand_null_return_1 (); 1.1 root 163: static int tail_recursion_args (); 1.1.1.8 root 164: static void fixup_stack_slots (); 1.1.1.2 root 165: static rtx fixup_stack_1 (); 166: static rtx fixup_memory_subreg (); 1.1.1.13 root 167: static rtx walk_fixup_memory_subreg (); 1.1.1.2 root 168: static void fixup_var_refs (); 1.1.1.10 root 169: static void fixup_var_refs_insns (); 1.1.1.2 root 170: static rtx fixup_var_refs_1 (); 171: static rtx parm_stack_loc (); 172: static void optimize_bit_field (); 1.1.1.14 root 173: static void do_jump_if_equal (); 1.1 root 174: 1.1.1.13 root 175: /* Functions and data structures for expanding case statements. */ 176: 177: static void balance_case_nodes (); 178: static void emit_case_nodes (); 179: static void group_case_nodes (); 180: static void emit_jump_if_reachable (); 181: 182: /* Case label structure, used to hold info on labels within case 183: statements. We handle "range" labels; for a single-value label 184: as in C, the high and low limits are the same. */ 185: 186: struct case_node 187: { 188: struct case_node *left; 189: struct case_node *right; 190: struct case_node *parent; 191: tree low; 192: tree high; 193: tree test_label; 194: tree code_label; 195: }; 196: 197: typedef struct case_node case_node; 198: typedef struct case_node *case_node_ptr; 199: 1.1.1.2 root 200: /* Stack of control and binding constructs we are currently inside. 1.1 root 201: 1.1.1.2 root 202: These constructs begin when you call `expand_start_WHATEVER' 203: and end when you call `expand_end_WHATEVER'. This stack records 204: info about how the construct began that tells the end-function 205: what to do. It also may provide information about the construct 206: to alter the behavior of other constructs within the body. 207: For example, they may affect the behavior of C `break' and `continue'. 208: 209: Each construct gets one `struct nesting' object. 210: All of these objects are chained through the `all' field. 211: `nesting_stack' points to the first object (innermost construct). 212: The position of an entry on `nesting_stack' is in its `depth' field. 213: 214: Each type of construct has its own individual stack. 215: For example, loops have `loop_stack'. Each object points to the 216: next object of the same type through the `next' field. 217: 218: Some constructs are visible to `break' exit-statements and others 219: are not. Which constructs are visible depends on the language. 220: Therefore, the data structure allows each construct to be visible 221: or not, according to the args given when the construct is started. 222: The construct is visible if the `exit_label' field is non-null. 223: In that case, the value should be a CODE_LABEL rtx. */ 224: 225: struct nesting 1.1 root 226: { 1.1.1.2 root 227: struct nesting *all; 228: struct nesting *next; 229: int depth; 230: rtx exit_label; 231: union 232: { 233: /* For conds (if-then and if-then-else statements). */ 234: struct 235: { 236: /* Label on the else-part, if any, else 0. */ 237: rtx else_label; 238: /* Label at the end of the whole construct. */ 239: rtx after_label; 240: } cond; 241: /* For loops. */ 242: struct 243: { 244: /* Label at the top of the loop; place to loop back to. */ 245: rtx start_label; 246: /* Label at the end of the whole construct. */ 247: rtx end_label; 248: /* Label for `continue' statement to jump to; 249: this is in front of the stepper of the loop. */ 250: rtx continue_label; 251: } loop; 252: /* For variable binding contours. */ 253: struct 254: { 255: /* Nonzero => value to restore stack to on exit. */ 256: rtx stack_level; 257: /* The NOTE that starts this contour. 258: Used by expand_goto to check whether the destination 259: is within each contour or not. */ 260: rtx first_insn; 261: /* Innermost containing binding contour that has a stack level. */ 262: struct nesting *innermost_stack_block; 1.1.1.7 root 263: /* List of cleanups to be run on exit from this contour. 264: This is a list of expressions to be evaluated. 265: The TREE_PURPOSE of each link is the ..._DECL node 266: which the cleanup pertains to. */ 267: tree cleanups; 1.1.1.13 root 268: /* List of cleanup-lists of blocks containing this block, 269: as they were at the locus where this block appears. 270: There is an element for each containing block, 271: ordered innermost containing block first. 272: The element's TREE_VALUE is the cleanup-list of that block, 273: which may be null. */ 274: tree outer_cleanups; 1.1.1.2 root 275: /* Chain of labels defined inside this binding contour. 1.1.1.8 root 276: For contours that have stack levels or cleanups. */ 1.1.1.2 root 277: struct label_chain *label_chain; 278: } block; 279: /* For switch (C) or case (Pascal) statements, 280: and also for dummies (see `expand_start_case_dummy'). */ 281: struct 282: { 283: /* The insn after which the case dispatch should finally 284: be emitted. Zero for a dummy. */ 285: rtx start; 1.1.1.13 root 286: /* A list of case labels, kept in ascending order by value 287: as the list is built. 288: During expand_end_case, this list may be rearranged into a 289: nearly balanced binary tree. */ 290: struct case_node *case_list; 291: /* Label to jump to if no case matches. */ 292: tree default_label; 1.1.1.2 root 293: /* The expression to be dispatched on. */ 294: tree index_expr; 295: /* Type that INDEX_EXPR should be converted to. */ 296: tree nominal_type; 1.1.1.13 root 297: /* Number of range exprs in case statement. */ 298: short num_ranges; 1.1.1.2 root 299: } case_stmt; 300: } data; 301: }; 1.1 root 302: 1.1.1.2 root 303: /* Chain of all pending binding contours. */ 304: struct nesting *block_stack; 1.1 root 305: 1.1.1.7 root 306: /* Chain of all pending binding contours that restore stack levels 307: or have cleanups. */ 1.1.1.2 root 308: struct nesting *stack_block_stack; 1.1 root 309: 1.1.1.2 root 310: /* Chain of all pending conditional statements. */ 311: struct nesting *cond_stack; 1.1 root 312: 1.1.1.2 root 313: /* Chain of all pending loops. */ 314: struct nesting *loop_stack; 315: 316: /* Chain of all pending case or switch statements. */ 317: struct nesting *case_stack; 318: 319: /* Separate chain including all of the above, 320: chained through the `all' field. */ 321: struct nesting *nesting_stack; 322: 323: /* Number of entries on nesting_stack now. */ 324: int nesting_depth; 325: 326: /* Pop one of the sub-stacks, such as `loop_stack' or `cond_stack'; 327: and pop off `nesting_stack' down to the same level. */ 328: 329: #define POPSTACK(STACK) \ 330: do { int initial_depth = nesting_stack->depth; \ 331: do { struct nesting *this = STACK; \ 332: STACK = this->next; \ 333: nesting_stack = this->all; \ 334: nesting_depth = this->depth; \ 335: free (this); } \ 336: while (nesting_depth > initial_depth); } while (0) 337: 1.1 root 338: /* Return the rtx-label that corresponds to a LABEL_DECL, 339: creating it if necessary. */ 340: 341: static rtx 342: label_rtx (label) 343: tree label; 344: { 1.1.1.2 root 345: if (TREE_CODE (label) != LABEL_DECL) 346: abort (); 347: 1.1 root 348: if (DECL_RTL (label)) 349: return DECL_RTL (label); 350: 351: return DECL_RTL (label) = gen_label_rtx (); 352: } 353: 354: /* Add an unconditional jump to LABEL as the next sequential instruction. */ 355: 356: void 357: emit_jump (label) 358: rtx label; 359: { 360: do_pending_stack_adjust (); 361: emit_jump_insn (gen_jump (label)); 362: emit_barrier (); 363: } 1.1.1.2 root 364: 365: /* Handle goto statements and the labels that they can go to. */ 1.1 root 366: 1.1.1.2 root 367: /* In some cases it is impossible to generate code for a forward goto 368: until the label definition is seen. This happens when it may be necessary 369: for the goto to reset the stack pointer: we don't yet know how to do that. 370: So expand_goto puts an entry on this fixup list. 371: Each time a binding contour that resets the stack is exited, 372: we check each fixup. 373: If the target label has now been defined, we can insert the proper code. */ 1.1 root 374: 1.1.1.2 root 375: struct goto_fixup 1.1 root 376: { 1.1.1.2 root 377: /* Points to following fixup. */ 378: struct goto_fixup *next; 379: /* Points to the insn before the jump insn. 380: If more code must be inserted, it goes after this insn. */ 381: rtx before_jump; 1.1.1.6 root 382: /* The LABEL_DECL that this jump is jumping to, or 0 383: for break, continue or return. */ 1.1.1.2 root 384: tree target; 1.1.1.6 root 385: /* The CODE_LABEL rtx that this is jumping to. */ 386: rtx target_rtl; 1.1.1.2 root 387: /* The outermost stack level that should be restored for this jump. 388: Each time a binding contour that resets the stack is exited, 389: if the target label is *not* yet defined, this slot is updated. */ 390: rtx stack_level; 1.1.1.13 root 391: /* List of lists of cleanup expressions to be run by this goto. 392: There is one element for each block that this goto is within. 393: The TREE_VALUE contains the cleanup list of that block as of the 394: time this goto was seen. 395: The TREE_ADDRESSABLE flag is 1 for a block that has been exited. */ 1.1.1.7 root 396: tree cleanup_list_list; 1.1.1.2 root 397: }; 398: 399: static struct goto_fixup *goto_fixup_chain; 400: 401: /* Within any binding contour that must restore a stack level, 402: all labels are recorded with a chain of these structures. */ 403: 404: struct label_chain 405: { 406: /* Points to following fixup. */ 407: struct label_chain *next; 408: tree label; 409: }; 410: 411: /* Specify the location in the RTL code of a label BODY, 412: which is a LABEL_DECL tree node. 413: 414: This is used for the kind of label that the user can jump to with a 415: goto statement, and for alternatives of a switch or case statement. 416: RTL labels generated for loops and conditionals don't go through here; 417: they are generated directly at the RTL level, by other functions below. 418: 419: Note that this has nothing to do with defining label *names*. 420: Languages vary in how they do that and what that even means. */ 421: 422: void 423: expand_label (body) 424: tree body; 425: { 426: struct label_chain *p; 427: 428: do_pending_stack_adjust (); 429: emit_label (label_rtx (body)); 430: 1.1.1.7 root 431: if (stack_block_stack != 0) 1.1.1.2 root 432: { 433: p = (struct label_chain *) oballoc (sizeof (struct label_chain)); 434: p->next = stack_block_stack->data.block.label_chain; 435: stack_block_stack->data.block.label_chain = p; 436: p->label = body; 437: } 1.1 root 438: } 439: 1.1.1.2 root 440: /* Generate RTL code for a `goto' statement with target label BODY. 441: BODY should be a LABEL_DECL tree node that was or will later be 442: defined with `expand_label'. */ 443: 444: void 445: expand_goto (body) 446: tree body; 1.1 root 447: { 1.1.1.8 root 448: expand_goto_internal (body, label_rtx (body), 0); 1.1.1.6 root 449: } 450: 1.1.1.8 root 451: /* Generate RTL code for a `goto' statement with target label BODY. 452: LABEL should be a LABEL_REF. 453: LAST_INSN, if non-0, is the rtx we should consider as the last 1.1.1.9 root 454: insn emitted (for the purposes of cleaning up a return). */ 1.1.1.8 root 455: 1.1.1.6 root 456: static void 1.1.1.8 root 457: expand_goto_internal (body, label, last_insn) 1.1.1.6 root 458: tree body; 459: rtx label; 1.1.1.8 root 460: rtx last_insn; 1.1.1.6 root 461: { 1.1.1.2 root 462: struct nesting *block; 463: rtx stack_level = 0; 464: 465: if (GET_CODE (label) != CODE_LABEL) 466: abort (); 467: 468: /* If label has already been defined, we can tell now 469: whether and how we must alter the stack level. */ 470: 1.1.1.6 root 471: if (PREV_INSN (label) != 0) 1.1.1.2 root 472: { 1.1.1.13 root 473: /* Find the innermost pending block that contains the label. 1.1.1.2 root 474: (Check containment by comparing insn-uids.) 1.1.1.13 root 475: Then restore the outermost stack level within that block, 476: and do cleanups of all blocks contained in it. */ 1.1.1.2 root 477: for (block = block_stack; block; block = block->next) 478: { 479: if (INSN_UID (block->data.block.first_insn) < INSN_UID (label)) 480: break; 481: if (block->data.block.stack_level != 0) 482: stack_level = block->data.block.stack_level; 1.1.1.7 root 483: /* Execute the cleanups for blocks we are exiting. */ 484: if (block->data.block.cleanups != 0) 485: expand_cleanups (block->data.block.cleanups, 0); 1.1.1.2 root 486: } 487: 488: if (stack_level) 489: emit_move_insn (stack_pointer_rtx, stack_level); 490: 1.1.1.6 root 491: if (body != 0 && TREE_PACKED (body)) 1.1.1.13 root 492: error ("jump to `%s' invalidly jumps into binding contour", 1.1.1.2 root 493: IDENTIFIER_POINTER (DECL_NAME (body))); 494: } 495: /* Label not yet defined: may need to put this goto 496: on the fixup list. */ 1.1.1.8 root 497: else if (! expand_fixup (body, label, last_insn)) 1.1.1.13 root 498: { 499: /* No fixup needed. Record that the label is the target 500: of at least one goto that has no fixup. */ 501: if (body != 0) 502: TREE_ADDRESSABLE (body) = 1; 503: } 1.1.1.2 root 504: 1.1.1.6 root 505: emit_jump (label); 506: } 507: 508: /* Generate if necessary a fixup for a goto 509: whose target label in tree structure (if any) is TREE_LABEL 510: and whose target in rtl is RTL_LABEL. 511: 1.1.1.8 root 512: If LAST_INSN is nonzero, we pretend that the jump appears 513: after insn LAST_INSN instead of at the current point in the insn stream. 514: 1.1.1.6 root 515: The fixup will be used later to insert insns at this point 516: to restore the stack level as appropriate for the target label. 517: 518: Value is nonzero if a fixup is made. */ 519: 520: static int 1.1.1.8 root 521: expand_fixup (tree_label, rtl_label, last_insn) 1.1.1.6 root 522: tree tree_label; 523: rtx rtl_label; 1.1.1.8 root 524: rtx last_insn; 1.1.1.6 root 525: { 1.1.1.13 root 526: struct nesting *block, *end_block; 527: 528: /* See if we can recognize which block the label will be output in. 529: This is possible in some very common cases. 530: If we succeed, set END_BLOCK to that block. 531: Otherwise, set it to 0. */ 532: 533: if (cond_stack 534: && (rtl_label == cond_stack->data.cond.else_label 535: || rtl_label == cond_stack->data.cond.after_label)) 536: end_block = cond_stack; 537: /* If we are in a loop, recognize certain labels which 538: are likely targets. This reduces the number of fixups 539: we need to create. */ 540: else if (loop_stack 541: && (rtl_label == loop_stack->data.loop.start_label 542: || rtl_label == loop_stack->data.loop.end_label 543: || rtl_label == loop_stack->data.loop.continue_label)) 544: end_block = loop_stack; 545: else 546: end_block = 0; 547: 548: /* Now set END_BLOCK to the binding level to which we will return. */ 549: 550: if (end_block) 551: { 552: struct nesting *next_block = end_block->all; 553: block = block_stack; 554: 555: /* First see if the END_BLOCK is inside the innermost binding level. 556: If so, then no cleanups or stack levels are relevant. */ 557: while (next_block && next_block != block) 558: next_block = next_block->all; 559: 560: if (next_block) 561: return 0; 562: 563: /* Otherwise, set END_BLOCK to the innermost binding level 564: which is outside the relevant control-structure nesting. */ 565: next_block = block_stack->next; 566: for (block = block_stack; block != end_block; block = block->all) 567: if (block == next_block) 568: next_block = next_block->next; 569: end_block = next_block; 570: } 571: 1.1.1.7 root 572: /* Does any containing block have a stack level or cleanups? 1.1.1.6 root 573: If not, no fixup is needed, and that is the normal case 574: (the only case, for standard C). */ 1.1.1.13 root 575: for (block = block_stack; block != end_block; block = block->next) 1.1.1.7 root 576: if (block->data.block.stack_level != 0 577: || block->data.block.cleanups != 0) 1.1.1.6 root 578: break; 579: 1.1.1.13 root 580: if (block != end_block) 1.1.1.6 root 581: { 582: /* Ok, a fixup is needed. Add a fixup to the list of such. */ 583: struct goto_fixup *fixup 584: = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup)); 585: /* In case an old stack level is restored, make sure that comes 586: after any pending stack adjust. */ 587: do_pending_stack_adjust (); 1.1.1.8 root 588: fixup->before_jump = last_insn ? last_insn : get_last_insn (); 1.1.1.6 root 589: fixup->target = tree_label; 590: fixup->target_rtl = rtl_label; 591: fixup->stack_level = 0; 1.1.1.13 root 592: fixup->cleanup_list_list 593: = (block->data.block.outer_cleanups || block->data.block.cleanups 594: ? tree_cons (0, block->data.block.cleanups, 595: block->data.block.outer_cleanups) 596: : 0); 1.1.1.6 root 597: fixup->next = goto_fixup_chain; 598: goto_fixup_chain = fixup; 1.1.1.2 root 599: } 600: 1.1.1.6 root 601: return block != 0; 1.1 root 602: } 603: 1.1.1.2 root 604: /* When exiting a binding contour, process all pending gotos requiring fixups. 1.1.1.13 root 605: THISBLOCK is the structure that describes the block being exited. 1.1.1.7 root 606: STACK_LEVEL is the rtx for the stack level to restore exiting this contour. 1.1.1.13 root 607: CLEANUP_LIST is a list of expressions to evaluate on exiting this contour. 608: FIRST_INSN is the insn that began this contour. 1.1.1.7 root 609: 1.1.1.2 root 610: Gotos that jump out of this contour must restore the 1.1.1.7 root 611: stack level and do the cleanups before actually jumping. 1.1 root 612: 1.1.1.7 root 613: DONT_JUMP_IN nonzero means report error there is a jump into this 614: contour from before the beginning of the contour. 615: This is also done if STACK_LEVEL is nonzero. */ 1.1 root 616: 1.1.1.2 root 617: static void 1.1.1.13 root 618: fixup_gotos (thisblock, stack_level, cleanup_list, first_insn, dont_jump_in) 619: struct nesting *thisblock; 1.1.1.2 root 620: rtx stack_level; 1.1.1.7 root 621: tree cleanup_list; 1.1.1.2 root 622: rtx first_insn; 1.1.1.7 root 623: int dont_jump_in; 1.1 root 624: { 1.1.1.13 root 625: register struct goto_fixup *f, *prev; 1.1 root 626: 1.1.1.13 root 627: /* F is the fixup we are considering; PREV is the previous one. */ 628: 629: for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next) 1.1.1.2 root 630: { 631: /* Test for a fixup that is inactive because it is already handled. */ 632: if (f->before_jump == 0) 1.1.1.13 root 633: { 634: /* Delete inactive fixup from the chain, if that is easy to do. */ 635: if (prev != 0) 636: prev->next = f->next; 637: } 1.1.1.2 root 638: /* Has this fixup's target label been defined? 639: If so, we can finalize it. */ 1.1.1.6 root 640: else if (PREV_INSN (f->target_rtl) != 0) 1.1.1.2 root 641: { 642: /* If this fixup jumped into this contour from before the beginning 643: of this contour, report an error. */ 1.1.1.13 root 644: /* ??? Bug: this does not detect jumping in through intermediate 645: blocks that have stack levels or cleanups. 646: It detects only a problem with the innermost block 647: around the label. */ 1.1.1.6 root 648: if (f->target != 0 1.1.1.13 root 649: && (dont_jump_in || stack_level || cleanup_list) 1.1.1.6 root 650: && INSN_UID (first_insn) > INSN_UID (f->before_jump) 1.1.1.2 root 651: && ! TREE_ADDRESSABLE (f->target)) 652: { 1.1.1.13 root 653: error_with_decl (f->target, 654: "label `%s' used before containing binding contour"); 1.1.1.2 root 655: /* Prevent multiple errors for one label. */ 656: TREE_ADDRESSABLE (f->target) = 1; 657: } 1.1 root 658: 1.1.1.7 root 659: /* Execute cleanups for blocks this jump exits. */ 660: if (f->cleanup_list_list) 1.1.1.13 root 661: { 662: tree lists; 663: for (lists = f->cleanup_list_list; lists; lists = TREE_CHAIN (lists)) 664: /* Marked elements correspond to blocks that have been closed. 665: Do their cleanups. */ 666: if (TREE_ADDRESSABLE (lists) 667: && TREE_VALUE (lists) != 0) 668: fixup_cleanups (TREE_VALUE (lists), &f->before_jump); 669: } 1.1.1.7 root 670: 1.1.1.2 root 671: /* Restore stack level for the biggest contour that this 672: jump jumps out of. */ 673: if (f->stack_level) 674: emit_insn_after (gen_move_insn (stack_pointer_rtx, f->stack_level), 675: f->before_jump); 676: f->before_jump = 0; 677: } 678: /* Label has still not appeared. If we are exiting a block with 679: a stack level to restore, mark this stack level as needing 1.1.1.13 root 680: restoration when the fixup is later finalized. 681: Also mark the cleanup_list_list element for F 682: that corresponds to this block, so that ultimately 683: this block's cleanups will be executed by the code above. */ 1.1.1.15! root 684: /* Note: if THISBLOCK == 0 and we have a label that hasn't appeared, ! 685: it means the label is undefined. That's erroneous, but possible. */ ! 686: else if (thisblock != 0) 1.1.1.7 root 687: { 1.1.1.13 root 688: tree lists = f->cleanup_list_list; 689: for (; lists; lists = TREE_CHAIN (lists)) 690: /* If the following elt. corresponds to our containing block 691: then the elt. must be for this block. */ 692: if (TREE_CHAIN (lists) == thisblock->data.block.outer_cleanups) 693: TREE_ADDRESSABLE (lists) = 1; 694: 1.1.1.7 root 695: if (stack_level) 696: f->stack_level = stack_level; 697: } 1.1.1.2 root 698: } 699: } 700: 701: /* Generate RTL for an asm statement (explicit assembler code). 702: BODY is a STRING_CST node containing the assembler code text. */ 703: 704: void 705: expand_asm (body) 706: tree body; 1.1 root 707: { 1.1.1.2 root 708: emit_insn (gen_rtx (ASM_INPUT, VOIDmode, 709: TREE_STRING_POINTER (body))); 710: last_expr_type = 0; 711: } 712: 713: /* Generate RTL for an asm statement with arguments. 714: STRING is the instruction template. 715: OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs. 716: Each output or input has an expression in the TREE_VALUE and 717: a constraint-string in the TREE_PURPOSE. 1.1.1.8 root 718: CLOBBERS is a list of STRING_CST nodes each naming a hard register 719: that is clobbered by this insn. 1.1.1.2 root 720: 721: Not all kinds of lvalue that may appear in OUTPUTS can be stored directly. 722: Some elements of OUTPUTS may be replaced with trees representing temporary 723: values. The caller should copy those temporary values to the originally 724: specified lvalues. 1.1 root 725: 1.1.1.2 root 726: VOL nonzero means the insn is volatile; don't optimize it. */ 1.1 root 727: 1.1.1.2 root 728: void 1.1.1.13 root 729: expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line) 1.1.1.8 root 730: tree string, outputs, inputs, clobbers; 1.1.1.2 root 731: int vol; 1.1.1.13 root 732: char *filename; 733: int line; 1.1.1.2 root 734: { 735: rtvec argvec, constraints; 736: rtx body; 737: int ninputs = list_length (inputs); 738: int noutputs = list_length (outputs); 1.1.1.8 root 739: int nclobbers = list_length (clobbers); 1.1.1.2 root 740: tree tail; 1.1.1.13 root 741: register int i; 742: /* Vector of RTX's of evaluated output operands. */ 743: rtx *output_rtx = (rtx *) alloca (noutputs * sizeof (rtx)); 744: /* The insn we have emitted. */ 745: rtx insn; 1.1.1.2 root 746: 1.1.1.4 root 747: last_expr_type = 0; 748: 1.1.1.2 root 749: for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++) 750: { 751: tree val = TREE_VALUE (tail); 1.1.1.14 root 752: int j; 753: int found_equal; 1.1 root 754: 1.1.1.4 root 755: /* If there's an erroneous arg, emit no insn. */ 756: if (TREE_TYPE (val) == error_mark_node) 757: return; 758: 1.1.1.14 root 759: /* Make sure constraint has `=' and does not have `+'. */ 760: 761: found_equal = 0; 762: for (j = 0; j < TREE_STRING_LENGTH (TREE_PURPOSE (tail)); j++) 763: { 764: if (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '+') 765: { 766: error ("input operand constraint contains `+'"); 767: return; 768: } 769: if (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '=') 770: found_equal = 1; 771: } 772: if (! found_equal) 773: { 774: error ("output operand constraint lacks `='"); 775: return; 776: } 777: 1.1.1.2 root 778: /* If an output operand is not a variable or indirect ref, 779: create a SAVE_EXPR which is a pseudo-reg 780: to act as an intermediate temporary. 781: Make the asm insn write into that, then copy it to 782: the real output operand. */ 783: 784: if (TREE_CODE (val) != VAR_DECL 785: && TREE_CODE (val) != PARM_DECL 786: && TREE_CODE (val) != INDIRECT_REF) 1.1.1.10 root 787: { 788: rtx reg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (val))); 789: /* `build' isn't safe; it really expects args to be trees. */ 790: tree t = build_nt (SAVE_EXPR, val, reg); 791: 792: save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, reg, save_expr_regs); 793: TREE_VALUE (tail) = t; 794: TREE_TYPE (t) = TREE_TYPE (val); 795: } 1.1.1.13 root 796: output_rtx[i] = expand_expr (TREE_VALUE (tail), 0, VOIDmode, 0); 1.1.1.2 root 797: } 1.1 root 798: 1.1.1.8 root 799: if (ninputs + noutputs > MAX_RECOG_OPERANDS) 800: { 801: error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS); 802: return; 803: } 804: 1.1.1.2 root 805: /* Make vectors for the expression-rtx and constraint strings. */ 1.1 root 806: 1.1.1.4 root 807: argvec = rtvec_alloc (ninputs); 808: constraints = rtvec_alloc (ninputs); 1.1 root 809: 1.1.1.2 root 810: body = gen_rtx (ASM_OPERANDS, VOIDmode, 811: TREE_STRING_POINTER (string), "", 0, argvec, constraints); 1.1.1.10 root 812: MEM_VOLATILE_P (body) = vol; 1.1 root 813: 1.1.1.2 root 814: /* Eval the inputs and put them into ARGVEC. 815: Put their constraints into ASM_INPUTs and store in CONSTRAINTS. */ 1.1 root 816: 1.1.1.2 root 817: i = 0; 818: for (tail = inputs; tail; tail = TREE_CHAIN (tail)) 819: { 1.1.1.14 root 820: int j; 821: 1.1.1.4 root 822: /* If there's an erroneous arg, emit no insn, 823: because the ASM_INPUT would get VOIDmode 824: and that could cause a crash in reload. */ 825: if (TREE_TYPE (TREE_VALUE (tail)) == error_mark_node) 826: return; 1.1.1.8 root 827: if (TREE_PURPOSE (tail) == NULL_TREE) 828: { 1.1.1.13 root 829: error ("hard register `%s' listed as input operand to `asm'", 1.1.1.8 root 830: TREE_STRING_POINTER (TREE_VALUE (tail)) ); 831: return; 832: } 1.1.1.4 root 833: 1.1.1.14 root 834: /* Make sure constraint has neither `=' nor `+'. */ 835: 836: for (j = 0; j < TREE_STRING_LENGTH (TREE_PURPOSE (tail)); j++) 837: if (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '=' 838: || TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '+') 839: { 840: error ("input operand constraint contains `%c'", 841: TREE_STRING_POINTER (TREE_PURPOSE (tail))[j]); 842: return; 843: } 844: 1.1.1.2 root 845: XVECEXP (body, 3, i) /* argvec */ 846: = expand_expr (TREE_VALUE (tail), 0, VOIDmode, 0); 847: XVECEXP (body, 4, i) /* constraints */ 848: = gen_rtx (ASM_INPUT, TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))), 849: TREE_STRING_POINTER (TREE_PURPOSE (tail))); 850: i++; 851: } 1.1 root 852: 1.1.1.13 root 853: /* Protect all the operands from the queue, 854: now that they have all been evaluated. */ 855: 856: for (i = 0; i < ninputs; i++) 857: XVECEXP (body, 3, i) = protect_from_queue (XVECEXP (body, 3, i), 0); 858: 859: for (i = 0; i < noutputs; i++) 860: output_rtx[i] = protect_from_queue (output_rtx[i], 1); 861: 1.1.1.2 root 862: /* Now, for each output, construct an rtx 863: (set OUTPUT (asm_operands INSN OUTPUTNUMBER OUTPUTCONSTRAINT 864: ARGVEC CONSTRAINTS)) 865: If there is more than one, put them inside a PARALLEL. */ 1.1 root 866: 1.1.1.8 root 867: if (noutputs == 1 && nclobbers == 0) 1.1.1.2 root 868: { 869: XSTR (body, 1) = TREE_STRING_POINTER (TREE_PURPOSE (outputs)); 1.1.1.13 root 870: insn = emit_insn (gen_rtx (SET, VOIDmode, output_rtx[0], body)); 1.1.1.2 root 871: } 1.1.1.8 root 872: else if (noutputs == 0 && nclobbers == 0) 1.1.1.5 root 873: { 874: /* No output operands: put in a raw ASM_OPERANDS rtx. */ 1.1.1.13 root 875: insn = emit_insn (body); 1.1.1.5 root 876: } 1.1.1.2 root 877: else 878: { 1.1.1.12 root 879: rtx obody = body; 880: int num = noutputs; 881: if (num == 0) num = 1; 882: body = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (num + nclobbers)); 1.1.1.8 root 883: 884: /* For each output operand, store a SET. */ 1.1.1.2 root 885: 886: for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++) 1.1 root 887: { 1.1.1.2 root 888: XVECEXP (body, 0, i) 889: = gen_rtx (SET, VOIDmode, 1.1.1.13 root 890: output_rtx[i], 1.1.1.2 root 891: gen_rtx (ASM_OPERANDS, VOIDmode, 892: TREE_STRING_POINTER (string), 893: TREE_STRING_POINTER (TREE_PURPOSE (tail)), 894: i, argvec, constraints)); 1.1.1.10 root 895: MEM_VOLATILE_P (SET_SRC (XVECEXP (body, 0, i))) = vol; 1.1 root 896: } 897: 1.1.1.12 root 898: /* If there are no outputs (but there are some clobbers) 899: store the bare ASM_OPERANDS into the PARALLEL. */ 900: 901: if (i == 0) 902: XVECEXP (body, 0, i++) = obody; 903: 1.1.1.8 root 904: /* Store (clobber REG) for each clobbered register specified. */ 905: 906: for (tail = clobbers; tail; tail = TREE_CHAIN (tail), i++) 907: { 908: int j; 909: char *regname = TREE_STRING_POINTER (TREE_VALUE (tail)); 910: extern char *reg_names[]; 911: 912: for (j = 0; j < FIRST_PSEUDO_REGISTER; j++) 913: if (!strcmp (regname, reg_names[j])) 914: break; 915: 916: if (j == FIRST_PSEUDO_REGISTER) 917: { 1.1.1.13 root 918: error ("unknown register name `%s' in `asm'", regname); 1.1.1.8 root 919: return; 920: } 921: 1.1.1.12 root 922: /* Use QImode since that's guaranteed to clobber just one reg. */ 1.1.1.8 root 923: XVECEXP (body, 0, i) 1.1.1.12 root 924: = gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, QImode, j)); 1.1.1.8 root 925: } 926: 1.1.1.13 root 927: insn = emit_insn (body); 1.1.1.2 root 928: } 1.1.1.13 root 929: 930: /* Record the source file and line number in the insn, 931: for the sake of errors generated at reload or final time. */ 932: 933: REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_ASM_FILE, 934: gen_rtx (SYMBOL_REF, VOIDmode, filename), 935: REG_NOTES (insn)); 936: REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_ASM_LINE, 937: gen_rtx (CONST_INT, VOIDmode, line), 938: REG_NOTES (insn)); 939: 1.1.1.2 root 940: last_expr_type = 0; 941: } 1.1 root 942: 1.1.1.2 root 943: /* Nonzero if within a ({...}) grouping, in which case we must 944: always compute a value for each expr-stmt in case it is the last one. */ 1.1 root 945: 1.1.1.2 root 946: int expr_stmts_for_value; 1.1 root 947: 1.1.1.2 root 948: /* Generate RTL to evaluate the expression EXP 949: and remember it in case this is the VALUE in a ({... VALUE; }) constr. */ 1.1 root 950: 1.1.1.2 root 951: void 952: expand_expr_stmt (exp) 953: tree exp; 954: { 1.1.1.13 root 955: /* If -W, warn about statements with no side effects, 956: except inside a ({...}) where they may be useful. */ 1.1.1.14 root 957: if (extra_warnings && expr_stmts_for_value == 0 && !TREE_VOLATILE (exp) 958: && exp != error_mark_node) 1.1.1.15! root 959: warning_with_file_and_line (emit_filename, emit_lineno, ! 960: "statement with no effect"); 1.1.1.2 root 961: last_expr_type = TREE_TYPE (exp); 1.1.1.13 root 962: if (! flag_syntax_only) 963: last_expr_value = expand_expr (exp, expr_stmts_for_value ? 0 : const0_rtx, 964: VOIDmode, 0); 1.1.1.2 root 965: emit_queue (); 966: } 1.1 root 967: 1.1.1.2 root 968: /* Clear out the memory of the last expression evaluated. */ 1.1 root 969: 1.1.1.2 root 970: void 971: clear_last_expr () 972: { 973: last_expr_type = 0; 974: } 1.1 root 975: 1.1.1.7 root 976: /* Begin a statement which will return a value. 1.1.1.10 root 977: Return the RTL_EXPR for this statement expr. 978: The caller must save that value and pass it to expand_end_stmt_expr. */ 1.1.1.7 root 979: 980: tree 981: expand_start_stmt_expr () 982: { 983: rtx save = start_sequence (); 1.1.1.10 root 984: /* Make the RTL_EXPR node temporary, not momentary, 985: so that rtl_expr_chain doesn't become garbage. */ 986: int momentary = suspend_momentary (); 1.1.1.7 root 987: tree t = make_node (RTL_EXPR); 1.1.1.10 root 988: resume_momentary (momentary); 1.1.1.7 root 989: RTL_EXPR_RTL (t) = save; 1.1.1.10 root 990: expr_stmts_for_value++; 1.1.1.7 root 991: return t; 992: } 993: 994: /* Restore the previous state at the end of a statement that returns a value. 995: Returns a tree node representing the statement's value and the 996: insns to compute the value. 997: 1.1.1.2 root 998: The nodes of that expression have been freed by now, so we cannot use them. 999: But we don't want to do that anyway; the expression has already been 1.1.1.10 root 1000: evaluated and now we just want to use the value. So generate a RTL_EXPR 1.1.1.2 root 1001: with the proper type and RTL value. 1.1 root 1002: 1.1.1.7 root 1003: If the last substatement was not an expression, 1.1.1.2 root 1004: return something with type `void'. */ 1.1 root 1005: 1.1.1.2 root 1006: tree 1.1.1.7 root 1007: expand_end_stmt_expr (t) 1008: tree t; 1.1.1.2 root 1009: { 1.1.1.7 root 1010: rtx saved = RTL_EXPR_RTL (t); 1.1 root 1011: 1.1.1.2 root 1012: if (last_expr_type == 0) 1013: { 1014: last_expr_type = void_type_node; 1015: last_expr_value = const0_rtx; 1016: } 1.1.1.7 root 1017: TREE_TYPE (t) = last_expr_type; 1.1.1.2 root 1018: RTL_EXPR_RTL (t) = last_expr_value; 1.1.1.10 root 1019: RTL_EXPR_SEQUENCE (t) = get_insns (); 1020: 1021: rtl_expr_chain = tree_cons (NULL_TREE, t, rtl_expr_chain); 1.1 root 1022: 1.1.1.7 root 1023: end_sequence (saved); 1.1.1.10 root 1024: 1025: /* Don't consider deleting this expr or containing exprs at tree level. */ 1026: TREE_VOLATILE (t) = 1; 1027: /* Propagate volatility of the actual RTL expr. */ 1028: TREE_THIS_VOLATILE (t) = volatile_refs_p (last_expr_value); 1029: 1030: last_expr_type = 0; 1.1.1.2 root 1031: expr_stmts_for_value--; 1.1.1.7 root 1032: 1033: return t; 1.1.1.2 root 1034: } 1035: 1036: /* Generate RTL for the start of an if-then. COND is the expression 1037: whose truth should be tested. 1.1 root 1038: 1.1.1.2 root 1039: If EXITFLAG is nonzero, this conditional is visible to 1040: `exit_something'. */ 1.1 root 1041: 1.1.1.2 root 1042: void 1043: expand_start_cond (cond, exitflag) 1044: tree cond; 1045: int exitflag; 1046: { 1047: struct nesting *thiscond 1048: = (struct nesting *) xmalloc (sizeof (struct nesting)); 1.1 root 1049: 1.1.1.2 root 1050: /* Make an entry on cond_stack for the cond we are entering. */ 1.1 root 1051: 1.1.1.2 root 1052: thiscond->next = cond_stack; 1053: thiscond->all = nesting_stack; 1054: thiscond->depth = ++nesting_depth; 1055: thiscond->data.cond.after_label = 0; 1056: thiscond->data.cond.else_label = gen_label_rtx (); 1057: thiscond->exit_label = exitflag ? thiscond->data.cond.else_label : 0; 1058: cond_stack = thiscond; 1059: nesting_stack = thiscond; 1.1 root 1060: 1.1.1.2 root 1061: do_jump (cond, thiscond->data.cond.else_label, NULL); 1062: } 1.1 root 1063: 1.1.1.2 root 1064: /* Generate RTL for the end of an if-then with no else-clause. 1065: Pop the record for it off of cond_stack. */ 1.1 root 1066: 1.1.1.2 root 1067: void 1068: expand_end_cond () 1069: { 1070: struct nesting *thiscond = cond_stack; 1.1 root 1071: 1.1.1.2 root 1072: do_pending_stack_adjust (); 1073: emit_label (thiscond->data.cond.else_label); 1.1 root 1074: 1.1.1.2 root 1075: POPSTACK (cond_stack); 1076: last_expr_type = 0; 1077: } 1.1 root 1078: 1.1.1.2 root 1079: /* Generate RTL between the then-clause and the else-clause 1080: of an if-then-else. */ 1.1 root 1081: 1.1.1.2 root 1082: void 1083: expand_start_else () 1084: { 1085: cond_stack->data.cond.after_label = gen_label_rtx (); 1086: if (cond_stack->exit_label != 0) 1087: cond_stack->exit_label = cond_stack->data.cond.after_label; 1088: emit_jump (cond_stack->data.cond.after_label); 1089: if (cond_stack->data.cond.else_label) 1090: emit_label (cond_stack->data.cond.else_label); 1091: } 1.1 root 1092: 1.1.1.2 root 1093: /* Generate RTL for the end of an if-then-else. 1094: Pop the record for it off of cond_stack. */ 1095: 1096: void 1097: expand_end_else () 1098: { 1099: struct nesting *thiscond = cond_stack; 1100: 1101: do_pending_stack_adjust (); 1102: /* Note: a syntax error can cause this to be called 1103: without first calling `expand_start_else'. */ 1104: if (thiscond->data.cond.after_label) 1105: emit_label (thiscond->data.cond.after_label); 1106: 1107: POPSTACK (cond_stack); 1108: last_expr_type = 0; 1109: } 1110: 1111: /* Generate RTL for the start of a loop. EXIT_FLAG is nonzero if this 1112: loop should be exited by `exit_something'. This is a loop for which 1113: `expand_continue' will jump to the top of the loop. 1114: 1115: Make an entry on loop_stack to record the labels associated with 1116: this loop. */ 1117: 1118: void 1119: expand_start_loop (exit_flag) 1120: int exit_flag; 1121: { 1122: register struct nesting *thisloop 1123: = (struct nesting *) xmalloc (sizeof (struct nesting)); 1124: 1125: /* Make an entry on loop_stack for the loop we are entering. */ 1126: 1127: thisloop->next = loop_stack; 1128: thisloop->all = nesting_stack; 1129: thisloop->depth = ++nesting_depth; 1130: thisloop->data.loop.start_label = gen_label_rtx (); 1131: thisloop->data.loop.end_label = gen_label_rtx (); 1132: thisloop->data.loop.continue_label = thisloop->data.loop.start_label; 1133: thisloop->exit_label = exit_flag ? thisloop->data.loop.end_label : 0; 1134: loop_stack = thisloop; 1135: nesting_stack = thisloop; 1136: 1137: do_pending_stack_adjust (); 1138: emit_queue (); 1139: emit_note (0, NOTE_INSN_LOOP_BEG); 1140: emit_label (thisloop->data.loop.start_label); 1141: } 1142: 1143: /* Like expand_start_loop but for a loop where the continuation point 1144: (for expand_continue_loop) will be specified explicitly. */ 1.1 root 1145: 1.1.1.2 root 1146: void 1147: expand_start_loop_continue_elsewhere (exit_flag) 1148: int exit_flag; 1149: { 1150: expand_start_loop (exit_flag); 1151: loop_stack->data.loop.continue_label = gen_label_rtx (); 1152: } 1153: 1154: /* Specify the continuation point for a loop started with 1155: expand_start_loop_continue_elsewhere. 1156: Use this at the point in the code to which a continue statement 1157: should jump. */ 1158: 1159: void 1160: expand_loop_continue_here () 1161: { 1162: do_pending_stack_adjust (); 1163: emit_label (loop_stack->data.loop.continue_label); 1164: } 1165: 1166: /* Finish a loop. Generate a jump back to the top and the loop-exit label. 1167: Pop the block off of loop_stack. */ 1168: 1169: void 1170: expand_end_loop () 1171: { 1172: register rtx insn = get_last_insn (); 1173: register rtx start_label = loop_stack->data.loop.start_label; 1174: 1175: do_pending_stack_adjust (); 1176: 1177: /* If optimizing, perhaps reorder the loop. If the loop 1178: starts with a conditional exit, roll that to the end 1179: where it will optimize together with the jump back. */ 1180: if (optimize 1181: && 1182: ! (GET_CODE (insn) == JUMP_INSN 1183: && GET_CODE (PATTERN (insn)) == SET 1184: && SET_DEST (PATTERN (insn)) == pc_rtx 1185: && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE)) 1186: { 1187: /* Scan insns from the top of the loop looking for a qualified 1188: conditional exit. */ 1189: for (insn = loop_stack->data.loop.start_label; insn; insn= NEXT_INSN (insn)) 1190: if (GET_CODE (insn) == JUMP_INSN && GET_CODE (PATTERN (insn)) == SET 1191: && SET_DEST (PATTERN (insn)) == pc_rtx 1192: && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE 1193: && 1194: ((GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == LABEL_REF 1195: && (XEXP (XEXP (SET_SRC (PATTERN (insn)), 1), 0) 1196: == loop_stack->data.loop.end_label)) 1197: || 1198: (GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 2)) == LABEL_REF 1199: && (XEXP (XEXP (SET_SRC (PATTERN (insn)), 2), 0) 1200: == loop_stack->data.loop.end_label)))) 1201: break; 1202: if (insn != 0) 1203: { 1204: /* We found one. Move everything from there up 1205: to the end of the loop, and add a jump into the loop 1206: to jump to there. */ 1207: register rtx newstart_label = gen_label_rtx (); 1208: 1209: emit_label_after (newstart_label, PREV_INSN (start_label)); 1210: reorder_insns (start_label, insn, get_last_insn ()); 1211: emit_jump_insn_after (gen_jump (start_label), PREV_INSN (newstart_label)); 1212: emit_barrier_after (PREV_INSN (newstart_label)); 1213: start_label = newstart_label; 1214: } 1215: } 1216: 1217: emit_jump (start_label); 1218: emit_note (0, NOTE_INSN_LOOP_END); 1219: emit_label (loop_stack->data.loop.end_label); 1220: 1221: POPSTACK (loop_stack); 1222: 1223: last_expr_type = 0; 1224: } 1225: 1226: /* Generate a jump to the current loop's continue-point. 1227: This is usually the top of the loop, but may be specified 1228: explicitly elsewhere. If not currently inside a loop, 1229: return 0 and do nothing; caller will print an error message. */ 1230: 1231: int 1232: expand_continue_loop () 1233: { 1234: last_expr_type = 0; 1235: if (loop_stack == 0) 1236: return 0; 1.1.1.8 root 1237: expand_goto_internal (0, loop_stack->data.loop.continue_label, 0); 1.1.1.2 root 1238: return 1; 1239: } 1240: 1241: /* Generate a jump to exit the current loop. If not currently inside a loop, 1242: return 0 and do nothing; caller will print an error message. */ 1243: 1244: int 1245: expand_exit_loop () 1246: { 1247: last_expr_type = 0; 1248: if (loop_stack == 0) 1249: return 0; 1.1.1.8 root 1250: expand_goto_internal (0, loop_stack->data.loop.end_label, 0); 1.1.1.2 root 1251: return 1; 1252: } 1253: 1254: /* Generate a conditional jump to exit the current loop if COND 1255: evaluates to zero. If not currently inside a loop, 1256: return 0 and do nothing; caller will print an error message. */ 1257: 1258: int 1259: expand_exit_loop_if_false (cond) 1260: tree cond; 1261: { 1262: last_expr_type = 0; 1263: if (loop_stack == 0) 1264: return 0; 1265: do_jump (cond, loop_stack->data.loop.end_label, NULL); 1266: return 1; 1267: } 1268: 1269: /* Generate a jump to exit the current loop, conditional, binding contour 1270: or case statement. Not all such constructs are visible to this function, 1271: only those started with EXIT_FLAG nonzero. Individual languages use 1272: the EXIT_FLAG parameter to control which kinds of constructs you can 1273: exit this way. 1274: 1275: If not currently inside anything that can be exited, 1276: return 0 and do nothing; caller will print an error message. */ 1277: 1278: int 1279: expand_exit_something () 1280: { 1281: struct nesting *n; 1282: last_expr_type = 0; 1283: for (n = nesting_stack; n; n = n->all) 1.1.1.7 root 1284: if (n->exit_label != 0) 1285: { 1.1.1.8 root 1286: expand_goto_internal (0, n->exit_label, 0); 1.1.1.7 root 1287: return 1; 1288: } 1289: 1.1.1.2 root 1290: return 0; 1291: } 1292: 1293: /* Generate RTL to return from the current function, with no value. 1294: (That is, we do not do anything about returning any value.) */ 1295: 1296: void 1297: expand_null_return () 1298: { 1.1.1.8 root 1299: expand_null_return_1 (0); 1300: } 1301: 1302: /* Output a return with no value. If LAST_INSN is nonzero, 1303: pretend that the return takes place after LAST_INSN. */ 1304: 1305: static void 1306: expand_null_return_1 (last_insn) 1307: rtx last_insn; 1308: { 1.1.1.2 root 1309: clear_pending_stack_adjust (); 1.1.1.10 root 1310: do_pending_stack_adjust (); 1.1.1.2 root 1311: #ifdef FUNCTION_EPILOGUE 1.1.1.8 root 1312: #ifdef HAVE_return 1.1.1.15! root 1313: if (! HAVE_return || current_function_returns_pcc_struct) 1.1.1.8 root 1314: expand_goto_internal (0, return_label, last_insn); 1315: else 1316: { 1317: emit_jump_insn (gen_return ()); 1318: emit_barrier (); 1319: } 1.1.1.2 root 1320: #else 1.1.1.8 root 1321: expand_goto_internal (0, return_label, last_insn); 1322: #endif 1323: #else /* no FUNCTION_EPILOGUE */ 1.1.1.2 root 1324: emit_jump_insn (gen_return ()); 1325: emit_barrier (); 1326: #endif 1327: last_expr_type = 0; 1328: } 1.1 root 1329: 1.1.1.2 root 1330: /* Generate RTL to evaluate the expression RETVAL and return it 1331: from the current function. */ 1.1 root 1332: 1.1.1.2 root 1333: void 1334: expand_return (retval) 1335: tree retval; 1336: { 1337: register rtx val = 0; 1338: register rtx op0; 1.1.1.7 root 1339: tree retval_rhs; 1.1.1.15! root 1340: int cleanups; ! 1341: struct nesting *block; ! 1342: ! 1343: /* Are any cleanups needed? E.g. C++ destructors to be run? */ ! 1344: cleanups = 0; ! 1345: for (block = block_stack; block; block = block->next) ! 1346: if (block->data.block.cleanups != 0) ! 1347: { ! 1348: cleanups = 1; ! 1349: break; ! 1350: } 1.1.1.7 root 1351: 1352: if (TREE_CODE (retval) == RESULT_DECL) 1353: retval_rhs = retval; 1354: else if ((TREE_CODE (retval) == MODIFY_EXPR || TREE_CODE (retval) == INIT_EXPR) 1355: && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL) 1356: retval_rhs = TREE_OPERAND (retval, 1); 1.1.1.14 root 1357: else if (TREE_TYPE (retval) == void_type_node) 1358: /* Recognize tail-recursive call to void function. */ 1359: retval_rhs = retval; 1.1.1.7 root 1360: else 1361: retval_rhs = NULL_TREE; 1.1.1.2 root 1362: 1363: /* For tail-recursive call to current function, 1364: just jump back to the beginning. 1365: It's unsafe if any auto variable in this function 1366: has its address taken; for simplicity, 1367: require stack frame to be empty. */ 1.1.1.7 root 1368: if (optimize && retval_rhs != 0 1.1.1.3 root 1369: && frame_offset == STARTING_FRAME_OFFSET 1.1.1.7 root 1370: && TREE_CODE (retval_rhs) == CALL_EXPR 1371: && TREE_CODE (TREE_OPERAND (retval_rhs, 0)) == ADDR_EXPR 1372: && TREE_OPERAND (TREE_OPERAND (retval_rhs, 0), 0) == this_function 1.1.1.2 root 1373: /* Finish checking validity, and if valid emit code 1374: to set the argument variables for the new call. */ 1.1.1.8 root 1375: && tail_recursion_args (TREE_OPERAND (retval_rhs, 1), 1.1.1.2 root 1376: DECL_ARGUMENTS (this_function))) 1377: { 1378: if (tail_recursion_label == 0) 1379: { 1380: tail_recursion_label = gen_label_rtx (); 1381: emit_label_after (tail_recursion_label, 1382: tail_recursion_reentry); 1383: } 1.1.1.15! root 1384: expand_goto_internal (0, tail_recursion_label, get_last_insn ()); 1.1.1.2 root 1385: emit_barrier (); 1386: return; 1387: } 1.1.1.8 root 1388: #ifdef HAVE_return 1.1.1.15! root 1389: if (HAVE_return && ! cleanups ! 1390: && ! current_function_returns_pcc_struct) 1.1.1.8 root 1391: { 1392: /* If this is return x == y; then generate 1393: if (x == y) return 1; else return 0; 1394: if we can do it with explicit return insns. */ 1395: if (retval_rhs) 1396: switch (TREE_CODE (retval_rhs)) 1397: { 1398: case EQ_EXPR: 1399: case NE_EXPR: 1400: case GT_EXPR: 1401: case GE_EXPR: 1402: case LT_EXPR: 1403: case LE_EXPR: 1404: case TRUTH_ANDIF_EXPR: 1405: case TRUTH_ORIF_EXPR: 1.1.1.10 root 1406: case TRUTH_AND_EXPR: 1407: case TRUTH_OR_EXPR: 1.1.1.8 root 1408: case TRUTH_NOT_EXPR: 1409: op0 = gen_label_rtx (); 1410: val = DECL_RTL (DECL_RESULT (this_function)); 1411: jumpifnot (retval_rhs, op0); 1412: emit_move_insn (val, const1_rtx); 1413: emit_insn (gen_rtx (USE, VOIDmode, val)); 1414: expand_null_return (); 1415: emit_label (op0); 1416: emit_move_insn (val, const0_rtx); 1417: emit_insn (gen_rtx (USE, VOIDmode, val)); 1418: expand_null_return (); 1419: return; 1420: } 1421: } 1422: #endif /* HAVE_return */ 1.1.1.2 root 1423: 1.1.1.15! root 1424: if (cleanups && GET_CODE (DECL_RTL (DECL_RESULT (this_function))) == REG) ! 1425: { ! 1426: rtx last_insn; ! 1427: /* Calculate the return value into a pseudo reg. */ ! 1428: val = expand_expr (retval_rhs, 0, VOIDmode, 0); ! 1429: emit_queue (); ! 1430: /* Put the cleanups here. */ ! 1431: last_insn = get_last_insn (); ! 1432: /* Copy the value into hard return reg. */ ! 1433: emit_move_insn (DECL_RTL (DECL_RESULT (this_function)), val); ! 1434: val = DECL_RTL (DECL_RESULT (this_function)); ! 1435: ! 1436: if (GET_CODE (val) == REG) ! 1437: emit_insn (gen_rtx (USE, VOIDmode, val)); ! 1438: expand_null_return_1 (last_insn); ! 1439: } ! 1440: else ! 1441: { ! 1442: /* No cleanups or no hard reg used; ! 1443: calculate value into hard return reg ! 1444: and let cleanups come after. */ ! 1445: val = expand_expr (retval, 0, VOIDmode, 0); ! 1446: emit_queue (); 1.1.1.2 root 1447: 1.1.1.15! root 1448: val = DECL_RTL (DECL_RESULT (this_function)); ! 1449: if (GET_CODE (val) == REG) ! 1450: emit_insn (gen_rtx (USE, VOIDmode, val)); ! 1451: expand_null_return (); ! 1452: } 1.1.1.2 root 1453: } 1454: 1455: /* Return 1 if the end of the generated RTX is not a barrier. 1456: This means code already compiled can drop through. */ 1457: 1458: int 1459: drop_through_at_end_p () 1460: { 1461: rtx insn = get_last_insn (); 1462: while (insn && GET_CODE (insn) == NOTE) 1463: insn = PREV_INSN (insn); 1464: return insn && GET_CODE (insn) != BARRIER; 1.1 root 1465: } 1466: 1467: /* Emit code to alter this function's formal parms for a tail-recursive call. 1468: ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs). 1469: FORMALS is the chain of decls of formals. 1470: Return 1 if this can be done; 1471: otherwise return 0 and do not emit any code. */ 1472: 1473: static int 1474: tail_recursion_args (actuals, formals) 1475: tree actuals, formals; 1476: { 1477: register tree a = actuals, f = formals; 1478: register int i; 1479: register rtx *argvec; 1480: 1481: /* Check that number and types of actuals are compatible 1482: with the formals. This is not always true in valid C code. 1483: Also check that no formal needs to be addressable 1484: and that all formals are scalars. */ 1485: 1486: /* Also count the args. */ 1487: 1488: for (a = actuals, f = formals, i = 0; a && f; a = TREE_CHAIN (a), f = TREE_CHAIN (f), i++) 1489: { 1490: if (TREE_TYPE (TREE_VALUE (a)) != TREE_TYPE (f)) 1491: return 0; 1492: if (GET_CODE (DECL_RTL (f)) != REG || DECL_MODE (f) == BLKmode) 1493: return 0; 1494: } 1495: if (a != 0 || f != 0) 1496: return 0; 1497: 1498: /* Compute all the actuals. */ 1499: 1500: argvec = (rtx *) alloca (i * sizeof (rtx)); 1501: 1502: for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++) 1503: argvec[i] = expand_expr (TREE_VALUE (a), 0, VOIDmode, 0); 1504: 1505: /* Find which actual values refer to current values of previous formals. 1506: Copy each of them now, before any formal is changed. */ 1507: 1508: for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++) 1509: { 1510: int copy = 0; 1511: register int j; 1512: for (f = formals, j = 0; j < i; f = TREE_CHAIN (f), j++) 1513: if (reg_mentioned_p (DECL_RTL (f), argvec[i])) 1514: { copy = 1; break; } 1515: if (copy) 1516: argvec[i] = copy_to_reg (argvec[i]); 1517: } 1518: 1519: /* Store the values of the actuals into the formals. */ 1520: 1.1.1.2 root 1521: for (f = formals, a = actuals, i = 0; f; 1522: f = TREE_CHAIN (f), a = TREE_CHAIN (a), i++) 1.1 root 1523: { 1524: if (DECL_MODE (f) == GET_MODE (argvec[i])) 1525: emit_move_insn (DECL_RTL (f), argvec[i]); 1526: else 1.1.1.2 root 1527: convert_move (DECL_RTL (f), argvec[i], 1528: TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a)))); 1.1 root 1529: } 1530: 1531: return 1; 1532: } 1533: 1.1.1.2 root 1534: /* Generate the RTL code for entering a binding contour. 1535: The variables are declared one by one, by calls to `expand_decl'. 1.1 root 1536: 1.1.1.2 root 1537: EXIT_FLAG is nonzero if this construct should be visible to 1538: `exit_something'. */ 1539: 1540: void 1541: expand_start_bindings (exit_flag) 1542: int exit_flag; 1.1 root 1543: { 1.1.1.2 root 1544: struct nesting *thisblock 1545: = (struct nesting *) xmalloc (sizeof (struct nesting)); 1546: 1547: rtx note = emit_note (0, NOTE_INSN_BLOCK_BEG); 1548: 1549: /* Make an entry on block_stack for the block we are entering. */ 1550: 1551: thisblock->next = block_stack; 1552: thisblock->all = nesting_stack; 1553: thisblock->depth = ++nesting_depth; 1554: thisblock->data.block.stack_level = 0; 1.1.1.7 root 1555: thisblock->data.block.cleanups = 0; 1.1.1.13 root 1556: /* We build this even if the cleanups lists are empty 1557: because we rely on having an element in the chain 1558: for each block that is pending. */ 1559: thisblock->data.block.outer_cleanups 1560: = (block_stack 1561: ? tree_cons (NULL_TREE, block_stack->data.block.cleanups, 1562: block_stack->data.block.outer_cleanups) 1563: : 0); 1.1.1.2 root 1564: thisblock->data.block.label_chain = 0; 1565: thisblock->data.block.innermost_stack_block = stack_block_stack; 1566: thisblock->data.block.first_insn = note; 1567: thisblock->exit_label = exit_flag ? gen_label_rtx () : 0; 1568: block_stack = thisblock; 1569: nesting_stack = thisblock; 1570: } 1571: 1.1.1.3 root 1572: /* Output a USE for any register use in RTL. 1573: This is used with -noreg to mark the extent of lifespan 1574: of any registers used in a user-visible variable's DECL_RTL. */ 1575: 1.1.1.13 root 1576: void 1.1.1.3 root 1577: use_variable (rtl) 1578: rtx rtl; 1579: { 1580: if (GET_CODE (rtl) == REG) 1581: /* This is a register variable. */ 1582: emit_insn (gen_rtx (USE, VOIDmode, rtl)); 1583: else if (GET_CODE (rtl) == MEM 1584: && GET_CODE (XEXP (rtl, 0)) == REG 1585: && XEXP (rtl, 0) != frame_pointer_rtx 1586: && XEXP (rtl, 0) != arg_pointer_rtx) 1587: /* This is a variable-sized structure. */ 1588: emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0))); 1589: } 1590: 1.1.1.13 root 1591: /* Like use_variable except that it outputs the USEs after INSN 1592: instead of at the end of the insn-chain. */ 1593: 1594: static void 1595: use_variable_after (rtl, insn) 1596: rtx rtl, insn; 1597: { 1598: if (GET_CODE (rtl) == REG) 1599: /* This is a register variable. */ 1600: emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn); 1601: else if (GET_CODE (rtl) == MEM 1602: && GET_CODE (XEXP (rtl, 0)) == REG 1603: && XEXP (rtl, 0) != frame_pointer_rtx 1604: && XEXP (rtl, 0) != arg_pointer_rtx) 1605: /* This is a variable-sized structure. */ 1606: emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn); 1607: } 1608: 1.1.1.2 root 1609: /* Generate RTL code to terminate a binding contour. 1610: VARS is the chain of VAR_DECL nodes 1611: for the variables bound in this contour. 1.1.1.7 root 1612: MARK_ENDS is nonzero if we should put a note at the beginning 1613: and end of this binding contour. 1614: 1615: DONT_JUMP_IN is nonzero if it is not valid to jump into this contour. 1616: (That is true automatically if the contour has a saved stack level.) */ 1.1.1.2 root 1617: 1618: void 1.1.1.7 root 1619: expand_end_bindings (vars, mark_ends, dont_jump_in) 1.1.1.2 root 1620: tree vars; 1621: int mark_ends; 1.1.1.7 root 1622: int dont_jump_in; 1.1.1.2 root 1623: { 1624: register struct nesting *thisblock = block_stack; 1625: register tree decl; 1626: 1.1.1.10 root 1627: if (warn_unused) 1628: for (decl = vars; decl; decl = TREE_CHAIN (decl)) 1629: if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL) 1630: warning_with_decl (decl, "unused variable `%s'"); 1631: 1.1.1.2 root 1632: /* Mark the beginning and end of the scope if requested. */ 1633: 1634: if (mark_ends) 1635: emit_note (0, NOTE_INSN_BLOCK_END); 1636: else 1637: /* Get rid of the beginning-mark if we don't make an end-mark. */ 1638: NOTE_LINE_NUMBER (thisblock->data.block.first_insn) = NOTE_INSN_DELETED; 1639: 1640: if (thisblock->exit_label) 1641: { 1642: do_pending_stack_adjust (); 1643: emit_label (thisblock->exit_label); 1644: } 1645: 1.1.1.13 root 1646: if (dont_jump_in 1647: || thisblock->data.block.stack_level != 0 1648: || thisblock->data.block.cleanups != 0) 1.1.1.2 root 1649: { 1650: struct label_chain *chain; 1651: 1652: /* Any labels in this block are no longer valid to go to. 1653: Mark them to cause an error message. */ 1654: for (chain = thisblock->data.block.label_chain; chain; chain = chain->next) 1655: { 1656: TREE_PACKED (chain->label) = 1; 1657: /* If any goto without a fixup came to this label, 1658: that must be an error, because gotos without fixups 1.1.1.13 root 1659: come from outside all saved stack-levels and all cleanups. */ 1.1.1.2 root 1660: if (TREE_ADDRESSABLE (chain->label)) 1.1.1.13 root 1661: error_with_decl (chain->label, 1662: "label `%s' used before containing binding contour"); 1.1.1.2 root 1663: } 1.1.1.7 root 1664: } 1665: 1666: /* Restore stack level in effect before the block 1667: (only if variable-size objects allocated). */ 1668: 1669: if (thisblock->data.block.stack_level != 0 1670: || thisblock->data.block.cleanups != 0) 1671: { 1672: /* Perform any cleanups associated with the block. */ 1673: 1674: expand_cleanups (thisblock->data.block.cleanups, 0); 1675: 1676: /* Restore the stack level. */ 1677: 1678: if (thisblock->data.block.stack_level != 0) 1679: { 1680: do_pending_stack_adjust (); 1681: emit_move_insn (stack_pointer_rtx, 1682: thisblock->data.block.stack_level); 1683: } 1.1.1.2 root 1684: 1.1.1.7 root 1685: /* Any gotos out of this block must also do these things. 1.1.1.2 root 1686: Also report any gotos with fixups that came to labels in this level. */ 1.1.1.13 root 1687: fixup_gotos (thisblock, 1688: thisblock->data.block.stack_level, 1.1.1.7 root 1689: thisblock->data.block.cleanups, 1690: thisblock->data.block.first_insn, 1691: dont_jump_in); 1.1.1.2 root 1692: } 1693: 1694: /* If doing stupid register allocation, make sure lives of all 1695: register variables declared here extend thru end of scope. */ 1696: 1697: if (obey_regdecls) 1698: for (decl = vars; decl; decl = TREE_CHAIN (decl)) 1699: { 1.1.1.3 root 1700: rtx rtl = DECL_RTL (decl); 1701: if (TREE_CODE (decl) == VAR_DECL && rtl != 0) 1702: use_variable (rtl); 1.1.1.2 root 1703: } 1704: 1705: /* Restore block_stack level for containing block. */ 1706: 1707: stack_block_stack = thisblock->data.block.innermost_stack_block; 1708: POPSTACK (block_stack); 1709: } 1710: 1711: /* Generate RTL for the automatic variable declaration DECL. 1.1.1.7 root 1712: (Other kinds of declarations are simply ignored if seen here.) 1713: CLEANUP is an expression to be executed at exit from this binding contour; 1714: for example, in C++, it might call the destructor for this variable. 1715: 1716: If CLEANUP contains any SAVE_EXPRs, then you must preevaluate them 1717: either before or after calling `expand_decl' but before compiling 1718: any subsequent expressions. This is because CLEANUP may be expanded 1719: more than once, on different branches of execution. 1720: For the same reason, CLEANUP may not contain a CALL_EXPR 1721: except as its topmost node--else `preexpand_calls' would get confused. 1722: 1.1.1.13 root 1723: If CLEANUP is nonzero and DECL is zero, we record a cleanup 1724: that is not associated with any particular variable. 1725: 1.1.1.7 root 1726: There is no special support here for C++ constructors. 1727: They should be handled by the proper code in DECL_INITIAL. */ 1.1.1.2 root 1728: 1729: void 1.1.1.7 root 1730: expand_decl (decl, cleanup) 1.1.1.2 root 1731: register tree decl; 1.1.1.7 root 1732: tree cleanup; 1.1.1.2 root 1733: { 1734: struct nesting *thisblock = block_stack; 1.1.1.13 root 1735: tree type; 1736: 1737: /* Record the cleanup if there is one. */ 1738: 1739: if (cleanup != 0) 1740: { 1741: thisblock->data.block.cleanups 1742: = temp_tree_cons (decl, cleanup, thisblock->data.block.cleanups); 1743: /* If this block has a cleanup, it belongs in stack_block_stack. */ 1744: stack_block_stack = thisblock; 1745: } 1746: 1747: if (decl == NULL_TREE) 1748: { 1749: /* This was a cleanup with no variable. */ 1750: if (cleanup == 0) 1751: abort (); 1752: return; 1753: } 1754: 1755: type = TREE_TYPE (decl); 1.1.1.2 root 1756: 1757: /* Aside from that, only automatic variables need any expansion done. 1.1.1.14 root 1758: Static and external variables, and external functions, 1759: will be handled by `assemble_variable' (called from finish_decl). 1760: TYPE_DECL and CONST_DECL require nothing. 1.1.1.2 root 1761: PARM_DECLs are handled in `assign_parms'. */ 1762: 1763: if (TREE_CODE (decl) != VAR_DECL) 1764: return; 1765: if (TREE_STATIC (decl) || TREE_EXTERNAL (decl)) 1766: return; 1767: 1768: /* Create the RTL representation for the variable. */ 1769: 1770: if (type == error_mark_node) 1771: DECL_RTL (decl) = gen_rtx (MEM, BLKmode, const0_rtx); 1.1.1.14 root 1772: else if (DECL_SIZE (decl) == 0) 1773: /* Variable with incomplete type. */ 1774: { 1775: if (DECL_INITIAL (decl) == 0) 1776: /* Error message was already done; now avoid a crash. */ 1777: DECL_RTL (decl) = assign_stack_local (DECL_MODE (decl), 0); 1778: else 1779: /* An initializer is going to decide the size of this array. 1780: Until we know the size, represent its address with a reg. */ 1781: DECL_RTL (decl) = gen_rtx (MEM, BLKmode, gen_reg_rtx (Pmode)); 1782: } 1.1.1.2 root 1783: else if (DECL_MODE (decl) != BLKmode 1784: /* If -ffloat-store, don't put explicit float vars 1785: into regs. */ 1786: && !(flag_float_store 1787: && TREE_CODE (type) == REAL_TYPE) 1788: && ! TREE_VOLATILE (decl) 1789: && ! TREE_ADDRESSABLE (decl) 1790: && (TREE_REGDECL (decl) || ! obey_regdecls)) 1791: { 1792: /* Automatic variable that can go in a register. */ 1793: DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); 1794: if (TREE_CODE (type) == POINTER_TYPE) 1795: mark_reg_pointer (DECL_RTL (decl)); 1.1.1.10 root 1796: REG_USERVAR_P (DECL_RTL (decl)) = 1; 1.1.1.2 root 1797: } 1798: else if (TREE_LITERAL (DECL_SIZE (decl))) 1799: { 1.1.1.14 root 1800: rtx oldaddr = 0; 1801: rtx addr; 1802: 1803: /* If we previously made RTL for this decl, it must be an array 1804: whose size was determined by the initializer. 1805: The old address was a register; set that register now 1806: to the proper address. */ 1807: if (DECL_RTL (decl) != 0) 1808: { 1809: if (GET_CODE (DECL_RTL (decl)) != MEM 1810: || GET_CODE (XEXP (DECL_RTL (decl), 0)) != REG) 1811: abort (); 1812: oldaddr = XEXP (DECL_RTL (decl), 0); 1813: } 1814: 1.1.1.2 root 1815: /* Variable of fixed size that goes on the stack. */ 1816: DECL_RTL (decl) 1817: = assign_stack_local (DECL_MODE (decl), 1818: (TREE_INT_CST_LOW (DECL_SIZE (decl)) 1819: * DECL_SIZE_UNIT (decl) 1820: + BITS_PER_UNIT - 1) 1821: / BITS_PER_UNIT); 1.1.1.14 root 1822: if (oldaddr) 1823: { 1824: addr = force_operand (XEXP (DECL_RTL (decl), 0), oldaddr); 1825: emit_move_insn (oldaddr, addr); 1826: } 1827: 1.1.1.2 root 1828: /* If this is a memory ref that contains aggregate components, 1829: mark it as such for cse and loop optimize. */ 1.1.1.10 root 1830: MEM_IN_STRUCT_P (DECL_RTL (decl)) 1.1.1.2 root 1831: = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE 1832: || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE 1833: || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE); 1.1.1.8 root 1834: #if 0 1835: /* If this is in memory because of -ffloat-store, 1836: set the volatile bit, to prevent optimizations from 1837: undoing the effects. */ 1838: if (flag_float_store && TREE_CODE (type) == REAL_TYPE) 1.1.1.10 root 1839: MEM_VOLATILE_P (DECL_RTL (decl)) = 1; 1.1.1.8 root 1840: #endif 1.1.1.2 root 1841: } 1842: else 1843: /* Dynamic-size object: must push space on the stack. */ 1844: { 1845: rtx address, size; 1846: 1847: frame_pointer_needed = 1; 1848: 1849: /* Record the stack pointer on entry to block, if have 1850: not already done so. */ 1851: if (thisblock->data.block.stack_level == 0) 1852: { 1853: do_pending_stack_adjust (); 1854: thisblock->data.block.stack_level 1855: = copy_to_reg (stack_pointer_rtx); 1856: stack_block_stack = thisblock; 1857: } 1858: 1859: /* Compute the variable's size, in bytes. */ 1860: size = expand_expr (convert_units (DECL_SIZE (decl), 1861: DECL_SIZE_UNIT (decl), 1862: BITS_PER_UNIT), 1863: 0, VOIDmode, 0); 1864: 1865: /* Round it up to this machine's required stack boundary. */ 1866: #ifdef STACK_BOUNDARY 1867: /* Avoid extra code if we can prove it's a multiple already. */ 1868: if (DECL_SIZE_UNIT (decl) % STACK_BOUNDARY) 1869: size = round_push (size); 1870: #endif 1871: 1872: /* Make space on the stack, and get an rtx for the address of it. */ 1873: #ifdef STACK_GROWS_DOWNWARD 1874: anti_adjust_stack (size); 1875: #endif 1876: address = copy_to_reg (stack_pointer_rtx); 1.1.1.4 root 1877: #ifdef STACK_POINTER_OFFSET 1878: /* If the contents of the stack pointer reg are offset from the 1879: actual top-of-stack address, add the offset here. */ 1880: emit_insn (gen_add2_insn (address, gen_rtx (CONST_INT, VOIDmode, 1881: STACK_POINTER_OFFSET))); 1882: #endif 1.1.1.2 root 1883: #ifndef STACK_GROWS_DOWNWARD 1884: anti_adjust_stack (size); 1885: #endif 1886: 1887: /* Reference the variable indirect through that rtx. */ 1888: DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl), address); 1889: } 1890: 1891: if (TREE_VOLATILE (decl)) 1.1.1.10 root 1892: MEM_VOLATILE_P (DECL_RTL (decl)) = 1; 1.1.1.2 root 1893: if (TREE_READONLY (decl)) 1.1.1.10 root 1894: RTX_UNCHANGING_P (DECL_RTL (decl)) = 1; 1.1.1.2 root 1895: 1896: /* If doing stupid register allocation, make sure life of any 1897: register variable starts here, at the start of its scope. */ 1898: 1.1.1.14 root 1899: if (obey_regdecls) 1.1.1.3 root 1900: use_variable (DECL_RTL (decl)); 1.1.1.14 root 1901: } 1902: 1903: /* Emit code to perform the initialization of a declaration DECL. */ 1904: 1905: void 1906: expand_decl_init (decl) 1907: tree decl; 1908: { 1909: if (TREE_STATIC (decl)) 1910: return; 1.1.1.2 root 1911: 1912: /* Compute and store the initial value now. */ 1913: 1.1.1.3 root 1914: if (DECL_INITIAL (decl) == error_mark_node) 1915: { 1916: enum tree_code code = TREE_CODE (TREE_TYPE (decl)); 1917: if (code == INTEGER_TYPE || code == REAL_TYPE || code == ENUMERAL_TYPE 1918: || code == POINTER_TYPE) 1919: expand_assignment (decl, convert (TREE_TYPE (decl), integer_zero_node), 1920: 0, 0); 1921: emit_queue (); 1922: } 1.1.1.7 root 1923: else if (DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) != TREE_LIST) 1.1.1.2 root 1924: { 1.1.1.12 root 1925: emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl)); 1.1.1.2 root 1926: expand_assignment (decl, DECL_INITIAL (decl), 0, 0); 1927: emit_queue (); 1928: } 1929: } 1.1.1.13 root 1930: 1931: /* DECL is an anonymous union. CLEANUP is a cleanup for DECL. 1932: DECL_ELTS is the list of elements that belong to DECL's type. 1933: In each, the TREE_VALUE is a VAR_DECL, and the TREE_PURPOSE a cleanup. */ 1934: 1935: void 1936: expand_anon_union_decl (decl, cleanup, decl_elts) 1937: tree decl, cleanup, decl_elts; 1938: { 1939: struct nesting *thisblock = block_stack; 1940: rtx x; 1941: 1942: expand_decl (decl, cleanup); 1943: x = DECL_RTL (decl); 1944: 1945: while (decl_elts) 1946: { 1947: tree decl_elt = TREE_VALUE (decl_elts); 1948: tree cleanup_elt = TREE_PURPOSE (decl_elts); 1949: 1950: DECL_RTL (decl_elt) 1951: = (GET_MODE (x) != BLKmode 1952: /* 1953: #error broken 1954: /* ??? This is incorrect if X is a MEM. 1955: (SUBREG (MEM)) is not allowed at rtl generation time. */ 1956: ? gen_rtx (SUBREG, TYPE_MODE (TREE_TYPE (decl_elt)), x, 0) 1957: : x); 1958: 1959: /* Record the cleanup if there is one. */ 1960: 1961: if (cleanup != 0) 1962: thisblock->data.block.cleanups 1963: = temp_tree_cons (decl_elt, cleanup_elt, 1964: thisblock->data.block.cleanups); 1965: 1966: decl_elts = TREE_CHAIN (decl_elts); 1967: } 1968: } 1.1.1.2 root 1969: 1.1.1.7 root 1970: /* Expand a list of cleanups LIST. 1971: Elements may be expressions or may be nested lists. 1972: 1973: If DONT_DO is nonnull, then any list-element 1974: whose TREE_PURPOSE matches DONT_DO is omitted. 1975: This is sometimes used to avoid a cleanup associated with 1976: a value that is being returned out of the scope. */ 1977: 1978: static void 1979: expand_cleanups (list, dont_do) 1980: tree list; 1981: tree dont_do; 1982: { 1983: tree tail; 1984: for (tail = list; tail; tail = TREE_CHAIN (tail)) 1985: if (dont_do == 0 || TREE_PURPOSE (tail) != dont_do) 1986: { 1987: if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST) 1.1.1.8 root 1988: expand_cleanups (TREE_VALUE (tail), dont_do); 1.1.1.7 root 1989: else 1990: expand_expr (TREE_VALUE (tail), const0_rtx, VOIDmode, 0); 1991: } 1992: } 1993: 1994: /* Expand a list of cleanups for a goto fixup. 1995: The expansion is put into the insn chain after the insn *BEFORE_JUMP 1996: and *BEFORE_JUMP is set to the insn that now comes before the jump. */ 1997: 1998: static void 1999: fixup_cleanups (list, before_jump) 2000: tree list; 2001: rtx *before_jump; 2002: { 2003: rtx beyond_jump = get_last_insn (); 2004: rtx new_before_jump; 2005: 2006: expand_cleanups (list, 0); 2007: new_before_jump = get_last_insn (); 2008: 2009: reorder_insns (NEXT_INSN (beyond_jump), new_before_jump, *before_jump); 2010: *before_jump = new_before_jump; 2011: } 1.1.1.8 root 2012: 2013: /* Move all cleanups from the current block_stack 2014: to the containing block_stack, where they are assumed to 2015: have been created. If anything can cause a temporary to 2016: be created, but not expanded for more than one level of 2017: block_stacks, then this code will have to change. */ 2018: 2019: void 2020: move_cleanups_up () 2021: { 2022: struct nesting *block = block_stack; 2023: struct nesting *outer = block->next; 2024: 2025: outer->data.block.cleanups 1.1.1.13 root 2026: = chainon (block->data.block.cleanups, 2027: outer->data.block.cleanups); 1.1.1.8 root 2028: block->data.block.cleanups = 0; 2029: } 1.1.1.7 root 2030: 1.1.1.2 root 2031: /* Enter a case (Pascal) or switch (C) statement. 2032: Push a block onto case_stack and nesting_stack 2033: to accumulate the case-labels that are seen 2034: and to record the labels generated for the statement. 2035: 2036: EXIT_FLAG is nonzero if `exit_something' should exit this case stmt. 2037: Otherwise, this construct is transparent for `exit_something'. 2038: 2039: EXPR is the index-expression to be dispatched on. 2040: TYPE is its nominal type. We could simply convert EXPR to this type, 2041: but instead we take short cuts. */ 2042: 2043: void 2044: expand_start_case (exit_flag, expr, type) 2045: int exit_flag; 2046: tree expr; 2047: tree type; 2048: { 2049: register struct nesting *thiscase 2050: = (struct nesting *) xmalloc (sizeof (struct nesting)); 2051: 2052: /* Make an entry on case_stack for the case we are entering. */ 2053: 2054: thiscase->next = case_stack; 2055: thiscase->all = nesting_stack; 2056: thiscase->depth = ++nesting_depth; 2057: thiscase->exit_label = exit_flag ? gen_label_rtx () : 0; 2058: thiscase->data.case_stmt.case_list = 0; 2059: thiscase->data.case_stmt.index_expr = expr; 2060: thiscase->data.case_stmt.nominal_type = type; 1.1.1.13 root 2061: thiscase->data.case_stmt.default_label = 0; 2062: thiscase->data.case_stmt.num_ranges = 0; 1.1.1.2 root 2063: case_stack = thiscase; 2064: nesting_stack = thiscase; 2065: 2066: do_pending_stack_adjust (); 2067: 1.1.1.6 root 2068: /* Make sure case_stmt.start points to something that won't 2069: need any transformation before expand_end_case. */ 2070: if (GET_CODE (get_last_insn ()) != NOTE) 2071: emit_note (0, NOTE_INSN_DELETED); 2072: 1.1.1.2 root 2073: thiscase->data.case_stmt.start = get_last_insn (); 2074: } 2075: 2076: /* Start a "dummy case statement" within which case labels are invalid 2077: and are not connected to any larger real case statement. 2078: This can be used if you don't want to let a case statement jump 2079: into the middle of certain kinds of constructs. */ 2080: 2081: void 2082: expand_start_case_dummy () 2083: { 2084: register struct nesting *thiscase 2085: = (struct nesting *) xmalloc (sizeof (struct nesting)); 2086: 2087: /* Make an entry on case_stack for the dummy. */ 2088: 2089: thiscase->next = case_stack; 2090: thiscase->all = nesting_stack; 2091: thiscase->depth = ++nesting_depth; 2092: thiscase->exit_label = 0; 2093: thiscase->data.case_stmt.case_list = 0; 2094: thiscase->data.case_stmt.start = 0; 2095: thiscase->data.case_stmt.nominal_type = 0; 1.1.1.13 root 2096: thiscase->data.case_stmt.default_label = 0; 2097: thiscase->data.case_stmt.num_ranges = 0; 1.1.1.2 root 2098: case_stack = thiscase; 2099: nesting_stack = thiscase; 2100: } 2101: 2102: /* End a dummy case statement. */ 2103: 2104: void 2105: expand_end_case_dummy () 2106: { 2107: POPSTACK (case_stack); 2108: } 1.1.1.7 root 2109: 1.1.1.2 root 2110: /* Accumulate one case or default label inside a case or switch statement. 2111: VALUE is the value of the case (a null pointer, for a default label). 2112: 2113: If not currently inside a case or switch statement, return 1 and do 2114: nothing. The caller will print a language-specific error message. 1.1.1.7 root 2115: If VALUE is a duplicate or overlaps, return 2 and do nothing. 1.1.1.2 root 2116: If VALUE is out of range, return 3 and do nothing. 1.1.1.13 root 2117: Return 0 on success. 2118: 2119: Extended to handle range statements, should they ever 2120: be adopted. */ 1.1.1.2 root 2121: 2122: int 2123: pushcase (value, label) 2124: register tree value; 2125: register tree label; 2126: { 1.1.1.13 root 2127: register struct case_node **l; 2128: register struct case_node *n; 1.1.1.2 root 2129: tree index_type; 2130: tree nominal_type; 2131: 2132: /* Fail if not inside a real case statement. */ 2133: if (! (case_stack && case_stack->data.case_stmt.start)) 2134: return 1; 2135: 2136: index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr); 2137: nominal_type = case_stack->data.case_stmt.nominal_type; 2138: 2139: /* If the index is erroneous, avoid more problems: pretend to succeed. */ 2140: if (index_type == error_mark_node) 2141: return 0; 2142: 2143: /* Convert VALUE to the type in which the comparisons are nominally done. */ 2144: if (value != 0) 2145: value = convert (nominal_type, value); 2146: 1.1.1.7 root 2147: /* Fail if this value is out of range for the actual type of the index 2148: (which may be narrower than NOMINAL_TYPE). */ 2149: if (value != 0 && ! int_fits_type_p (value, index_type)) 2150: return 3; 2151: 2152: /* Fail if this is a duplicate or overlaps another entry. */ 2153: if (value == 0) 1.1.1.2 root 2154: { 1.1.1.13 root 2155: if (case_stack->data.case_stmt.default_label != 0) 1.1.1.2 root 2156: return 2; 1.1.1.13 root 2157: case_stack->data.case_stmt.default_label = label; 1.1.1.2 root 2158: } 1.1.1.7 root 2159: else 2160: { 1.1.1.13 root 2161: /* Find the elt in the chain before which to insert the new value, 2162: to keep the chain sorted in increasing order. 2163: But report an error if this element is a duplicate. */ 2164: for (l = &case_stack->data.case_stmt.case_list; 2165: /* Keep going past elements distinctly less than VALUE. */ 1.1.1.14 root 2166: *l != 0 && tree_int_cst_lt ((*l)->high, value); 1.1.1.13 root 2167: l = &(*l)->right) 2168: ; 2169: if (*l) 1.1.1.7 root 2170: { 1.1.1.13 root 2171: /* Element we will insert before must be distinctly greater; 2172: overlap means error. */ 2173: if (! tree_int_cst_lt (value, (*l)->low)) 2174: return 2; 1.1.1.7 root 2175: } 1.1.1.13 root 2176: 2177: /* Add this label to the chain, and succeed. 2178: Copy VALUE so it is on temporary rather than momentary 2179: obstack and will thus survive till the end of the case statement. */ 2180: n = (struct case_node *) oballoc (sizeof (struct case_node)); 2181: n->left = 0; 2182: n->right = *l; 2183: n->high = n->low = copy_node (value); 2184: n->code_label = label; 2185: n->test_label = 0; 2186: *l = n; 1.1.1.7 root 2187: } 2188: 2189: expand_label (label); 2190: return 0; 2191: } 2192: 2193: /* Like pushcase but this case applies to all values 2194: between VALUE1 and VALUE2 (inclusive). 2195: The return value is the same as that of pushcase 2196: but there is one additional error code: 2197: 4 means the specified range was empty. 2198: 2199: Note that this does not currently work, since expand_end_case 2200: has yet to be extended to handle RANGE_EXPRs. */ 2201: 2202: int 2203: pushcase_range (value1, value2, label) 2204: register tree value1, value2; 2205: register tree label; 2206: { 1.1.1.13 root 2207: register struct case_node **l; 2208: register struct case_node *n; 1.1.1.7 root 2209: tree index_type; 2210: tree nominal_type; 2211: 2212: /* Fail if not inside a real case statement. */ 2213: if (! (case_stack && case_stack->data.case_stmt.start)) 2214: return 1; 2215: 2216: index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr); 2217: nominal_type = case_stack->data.case_stmt.nominal_type; 2218: 2219: /* If the index is erroneous, avoid more problems: pretend to succeed. */ 2220: if (index_type == error_mark_node) 2221: return 0; 2222: 2223: /* Convert VALUEs to type in which the comparisons are nominally done. */ 2224: if (value1 != 0) 2225: value1 = convert (nominal_type, value1); 2226: if (value2 != 0) 2227: value2 = convert (nominal_type, value2); 2228: 2229: /* Fail if these values are out of range. */ 2230: if (value1 != 0 && ! int_fits_type_p (value1, index_type)) 2231: return 3; 2232: 2233: if (value2 != 0 && ! int_fits_type_p (value2, index_type)) 1.1.1.2 root 2234: return 3; 2235: 1.1.1.7 root 2236: /* Fail if the range is empty. */ 2237: if (tree_int_cst_lt (value2, value1)) 2238: return 4; 2239: 1.1.1.8 root 2240: /* If the bounds are equal, turn this into the one-value case. */ 2241: if (tree_int_cst_equal (value1, value2)) 2242: return pushcase (value1, label); 2243: 1.1.1.13 root 2244: /* Find the elt in the chain before which to insert the new value, 2245: to keep the chain sorted in increasing order. 2246: But report an error if this element is a duplicate. */ 2247: for (l = &case_stack->data.case_stmt.case_list; 2248: /* Keep going past elements distinctly less than this range. */ 1.1.1.14 root 2249: *l != 0 && tree_int_cst_lt ((*l)->high, value1); 1.1.1.13 root 2250: l = &(*l)->right) 2251: ; 2252: if (*l) 2253: { 2254: /* Element we will insert before must be distinctly greater; 2255: overlap means error. */ 2256: if (! tree_int_cst_lt (value2, (*l)->low)) 2257: return 2; 1.1.1.7 root 2258: } 2259: 1.1.1.13 root 2260: /* Add this label to the chain, and succeed. 2261: Copy VALUE1, VALUE2 so they are on temporary rather than momentary 2262: obstack and will thus survive till the end of the case statement. */ 2263: 2264: n = (struct case_node *) oballoc (sizeof (struct case_node)); 2265: n->left = 0; 2266: n->right = *l; 2267: n->low = copy_node (value1); 2268: n->high = copy_node (value2); 2269: n->code_label = label; 2270: n->test_label = 0; 2271: *l = n; 2272: 1.1.1.2 root 2273: expand_label (label); 1.1.1.7 root 2274: 1.1.1.13 root 2275: case_stack->data.case_stmt.num_ranges++; 2276: 1.1.1.2 root 2277: return 0; 2278: } 2279: 2280: /* Terminate a case (Pascal) or switch (C) statement 2281: in which CASE_INDEX is the expression to be tested. 2282: Generate the code to test it and jump to the right place. */ 2283: 2284: void 2285: expand_end_case () 2286: { 2287: tree minval, maxval, range; 2288: rtx default_label = 0; 1.1.1.13 root 2289: register struct case_node *n; 1.1.1.2 root 2290: int count; 2291: rtx index; 2292: rtx table_label = gen_label_rtx (); 2293: int ncases; 2294: rtx *labelvec; 2295: register int i; 2296: rtx before_case; 2297: register struct nesting *thiscase = case_stack; 2298: tree index_expr = thiscase->data.case_stmt.index_expr; 2299: 2300: do_pending_stack_adjust (); 2301: 1.1.1.6 root 2302: /* An ERROR_MARK occurs for various reasons including invalid data type. */ 2303: if (TREE_TYPE (index_expr) != error_mark_node) 1.1.1.2 root 2304: { 2305: /* If we don't have a default-label, create one here, 2306: after the body of the switch. */ 1.1.1.13 root 2307: if (thiscase->data.case_stmt.default_label == 0) 2308: { 2309: thiscase->data.case_stmt.default_label 2310: = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 2311: expand_label (thiscase->data.case_stmt.default_label); 2312: } 2313: default_label = label_rtx (thiscase->data.case_stmt.default_label); 1.1.1.2 root 2314: 2315: before_case = get_last_insn (); 2316: 1.1.1.13 root 2317: /* Simplify the case-list before we count it. */ 2318: group_case_nodes (thiscase->data.case_stmt.case_list); 2319: 1.1.1.2 root 2320: /* Get upper and lower bounds of case values. 2321: Also convert all the case values to the index expr's data type. */ 2322: 1.1.1.13 root 2323: count = 0; 2324: for (n = thiscase->data.case_stmt.case_list; n; n = n->right) 2325: { 2326: /* Check low and high label values are integers. */ 2327: if (TREE_CODE (n->low) != INTEGER_CST) 2328: abort (); 2329: if (TREE_CODE (n->high) != INTEGER_CST) 2330: abort (); 2331: 2332: n->low = convert (TREE_TYPE (index_expr), n->low); 2333: n->high = convert (TREE_TYPE (index_expr), n->high); 2334: 2335: /* Count the elements and track the largest and smallest 2336: of them (treating them as signed even if they are not). */ 2337: if (count++ == 0) 2338: { 2339: minval = n->low; 2340: maxval = n->high; 2341: } 2342: else 2343: { 2344: if (INT_CST_LT (n->low, minval)) 2345: minval = n->low; 2346: if (INT_CST_LT (maxval, n->high)) 2347: maxval = n->high; 2348: } 2349: /* A range counts double, since it requires two compares. */ 2350: if (! tree_int_cst_equal (n->low, n->high)) 2351: count++; 2352: } 1.1.1.2 root 2353: 2354: /* Compute span of values. */ 2355: if (count != 0) 2356: range = combine (MINUS_EXPR, maxval, minval); 2357: 2358: if (count == 0 || TREE_CODE (TREE_TYPE (index_expr)) == ERROR_MARK) 2359: { 2360: expand_expr (index_expr, const0_rtx, VOIDmode, 0); 2361: emit_queue (); 2362: emit_jump (default_label); 2363: } 2364: /* If range of values is much bigger than number of values, 2365: make a sequence of conditional branches instead of a dispatch. 2366: If the switch-index is a constant, do it this way 2367: because we can optimize it. */ 2368: else if (TREE_INT_CST_HIGH (range) != 0 1.1 root 2369: #ifdef HAVE_casesi 1.1.1.2 root 2370: || count < 4 1.1 root 2371: #else 1.1.1.2 root 2372: /* If machine does not have a case insn that compares the 2373: bounds, this means extra overhead for dispatch tables 2374: which raises the threshold for using them. */ 2375: || count < 5 1.1 root 2376: #endif 1.1.1.2 root 2377: || (unsigned) (TREE_INT_CST_LOW (range)) > 10 * count 2378: || TREE_CODE (index_expr) == INTEGER_CST) 2379: { 2380: index = expand_expr (index_expr, 0, VOIDmode, 0); 2381: emit_queue (); 1.1.1.14 root 2382: do_pending_stack_adjust (); 1.1 root 2383: 1.1.1.2 root 2384: index = protect_from_queue (index, 0); 2385: if (GET_CODE (index) == MEM) 2386: index = copy_to_reg (index); 1.1.1.14 root 2387: if (GET_CODE (index) == CONST_INT 2388: || TREE_CODE (index_expr) == INTEGER_CST) 1.1.1.2 root 2389: { 1.1.1.14 root 2390: /* Make a tree node with the proper constant value 2391: if we don't already have one. */ 2392: if (TREE_CODE (index_expr) != INTEGER_CST) 2393: { 2394: index_expr = build_int_2 (INTVAL (index), 0); 2395: index_expr = convert (TREE_TYPE (index_expr), index_expr); 2396: } 2397: 1.1.1.13 root 2398: /* For constant index expressions we need only 2399: issue a unconditional branch to the appropriate 2400: target code. The job of removing any unreachable 2401: code is left to the optimisation phase if the 2402: "-O" option is specified. */ 2403: for (n = thiscase->data.case_stmt.case_list; 2404: n; 2405: n = n->right) 2406: { 2407: if (! tree_int_cst_lt (index_expr, n->low) 2408: && ! tree_int_cst_lt (n->high, index_expr)) 2409: break; 2410: } 2411: if (n) 2412: emit_jump (label_rtx (n->code_label)); 1.1.1.14 root 2413: else 2414: emit_jump (default_label); 1.1.1.13 root 2415: } 2416: else 2417: { 2418: /* If the index expression is not constant we generate 2419: a binary decision tree to select the appropriate 2420: target code. This is done as follows: 2421: 2422: The list of cases is rearranged into a binary tree, 2423: nearly optimal assuming equal probability for each case. 2424: 2425: The tree is transformed into RTL, eliminating 2426: redundant test conditions at the same time. 2427: 2428: If program flow could reach the end of the 2429: decision tree an unconditional jump to the 2430: default code is emitted. */ 2431: balance_case_nodes (&thiscase->data.case_stmt.case_list, 0); 2432: emit_case_nodes (index, thiscase->data.case_stmt.case_list, 1.1.1.14 root 2433: default_label, 2434: TREE_UNSIGNED (TREE_TYPE (index_expr))); 1.1.1.13 root 2435: emit_jump_if_reachable (default_label); 1.1.1.2 root 2436: } 2437: } 2438: else 2439: { 1.1 root 2440: #ifdef HAVE_casesi 1.1.1.3 root 2441: /* Convert the index to SImode. */ 1.1.1.2 root 2442: if (TYPE_MODE (TREE_TYPE (index_expr)) == DImode) 2443: { 1.1.1.3 root 2444: index_expr = build (MINUS_EXPR, TREE_TYPE (index_expr), 2445: index_expr, minval); 1.1.1.2 root 2446: minval = integer_zero_node; 2447: } 1.1.1.3 root 2448: if (TYPE_MODE (TREE_TYPE (index_expr)) != SImode) 2449: index_expr = convert (type_for_size (GET_MODE_BITSIZE (SImode), 0), 2450: index_expr); 1.1.1.2 root 2451: index = expand_expr (index_expr, 0, VOIDmode, 0); 2452: emit_queue (); 2453: index = protect_from_queue (index, 0); 2454: do_pending_stack_adjust (); 2455: 2456: emit_jump_insn (gen_casesi (index, expand_expr (minval, 0, VOIDmode, 0), 2457: expand_expr (range, 0, VOIDmode, 0), 2458: table_label, default_label)); 1.1 root 2459: #else 2460: #ifdef HAVE_tablejump 1.1.1.3 root 2461: index_expr = convert (type_for_size (GET_MODE_BITSIZE (SImode), 0), 1.1.1.2 root 2462: build (MINUS_EXPR, TREE_TYPE (index_expr), 2463: index_expr, minval)); 2464: index = expand_expr (index_expr, 0, VOIDmode, 0); 2465: emit_queue (); 2466: index = protect_from_queue (index, 0); 2467: do_pending_stack_adjust (); 2468: 2469: do_tablejump (index, 2470: gen_rtx (CONST_INT, VOIDmode, TREE_INT_CST_LOW (range)), 2471: table_label, default_label); 1.1 root 2472: #else 1.1.1.2 root 2473: lossage; 2474: #endif /* not HAVE_tablejump */ 2475: #endif /* not HAVE_casesi */ 2476: 2477: /* Get table of labels to jump to, in order of case index. */ 2478: 2479: ncases = TREE_INT_CST_LOW (range) + 1; 2480: labelvec = (rtx *) alloca (ncases * sizeof (rtx)); 2481: bzero (labelvec, ncases * sizeof (rtx)); 1.1 root 2482: 1.1.1.13 root 2483: for (n = thiscase->data.case_stmt.case_list; n; n = n->right) 2484: { 2485: register int i 2486: = TREE_INT_CST_LOW (n->low) - TREE_INT_CST_LOW (minval); 2487: 2488: while (i + TREE_INT_CST_LOW (minval) 2489: <= TREE_INT_CST_LOW (n->high)) 2490: labelvec[i++] 2491: = gen_rtx (LABEL_REF, Pmode, label_rtx (n->code_label)); 2492: } 1.1.1.2 root 2493: 2494: /* Fill in the gaps with the default. */ 2495: for (i = 0; i < ncases; i++) 2496: if (labelvec[i] == 0) 2497: labelvec[i] = gen_rtx (LABEL_REF, Pmode, default_label); 2498: 2499: /* Output the table */ 2500: emit_label (table_label); 1.1 root 2501: 2502: #ifdef CASE_VECTOR_PC_RELATIVE 1.1.1.2 root 2503: emit_jump_insn (gen_rtx (ADDR_DIFF_VEC, CASE_VECTOR_MODE, 2504: gen_rtx (LABEL_REF, Pmode, table_label), 2505: gen_rtvec_v (ncases, labelvec))); 1.1 root 2506: #else 1.1.1.2 root 2507: emit_jump_insn (gen_rtx (ADDR_VEC, CASE_VECTOR_MODE, 2508: gen_rtvec_v (ncases, labelvec))); 1.1 root 2509: #endif 1.1.1.2 root 2510: /* If the case insn drops through the table, 2511: after the table we must jump to the default-label. 2512: Otherwise record no drop-through after the table. */ 2513: #ifdef CASE_DROPS_THROUGH 2514: emit_jump (default_label); 2515: #else 2516: emit_barrier (); 2517: #endif 2518: } 2519: 2520: reorder_insns (NEXT_INSN (before_case), get_last_insn (), 2521: thiscase->data.case_stmt.start); 2522: } 2523: if (thiscase->exit_label) 2524: emit_label (thiscase->exit_label); 2525: 2526: POPSTACK (case_stack); 2527: } 2528: 2529: /* Generate code to jump to LABEL if OP1 and OP2 are equal. */ 2530: 1.1.1.14 root 2531: static void 2532: do_jump_if_equal (op1, op2, label, unsignedp) 1.1.1.2 root 2533: rtx op1, op2, label; 1.1.1.14 root 2534: int unsignedp; 1.1.1.2 root 2535: { 2536: if (GET_CODE (op1) == CONST_INT 2537: && GET_CODE (op2) == CONST_INT) 2538: { 2539: if (INTVAL (op1) == INTVAL (op2)) 2540: emit_jump (label); 2541: } 2542: else 2543: { 1.1.1.14 root 2544: emit_cmp_insn (op1, op2, 0, unsignedp, 0); 1.1.1.2 root 2545: emit_jump_insn (gen_beq (label)); 2546: } 1.1 root 2547: } 2548: 1.1.1.13 root 2549: /* Scan an ordered list of case nodes 2550: combining those with consecutive values or ranges. 2551: 2552: Eg. three separate entries 1: 2: 3: become one entry 1..3: */ 2553: 2554: static void 2555: group_case_nodes (head) 2556: case_node_ptr head; 2557: { 2558: case_node_ptr node = head; 2559: 2560: while (node) 2561: { 2562: rtx lb = next_real_insn (label_rtx (node->code_label)); 2563: case_node_ptr np = node; 2564: 2565: /* Try to group the successors of NODE with NODE. */ 2566: while (((np = np->right) != 0) 2567: /* Do they jump to the same place? */ 2568: && next_real_insn (label_rtx (np->code_label)) == lb 2569: /* Are their ranges consecutive? */ 2570: && tree_int_cst_equal (np->low, 2571: combine (PLUS_EXPR, node->high, 2572: build_int_2 (1, 0)))) 2573: { 2574: node->high = np->high; 2575: } 2576: /* NP is the first node after NODE which can't be grouped with it. 2577: Delete the nodes in between, and move on to that node. */ 2578: node->right = np; 2579: node = np; 2580: } 2581: } 2582: 2583: /* Take an ordered list of case nodes 2584: and transform them into a near optimal binary tree, 2585: on the assumtion that any target code selection value is as 2586: likely as any other. 2587: 2588: The transformation is performed by splitting the ordered 2589: list into two equal sections plus a pivot. The parts are 2590: then attached to the pivot as left and right branches. Each 2591: branch is is then transformed recursively. */ 2592: 2593: static void 2594: balance_case_nodes (head, parent) 2595: case_node_ptr *head; 2596: case_node_ptr parent; 2597: { 2598: register case_node_ptr np; 2599: 2600: np = *head; 2601: if (np) 2602: { 2603: int i = 0; 2604: int ranges = 0; 2605: register case_node_ptr *npp; 2606: case_node_ptr left; 2607: 2608: /* Count the number of entries on branch. 2609: Also count the ranges. */ 2610: while (np) 2611: { 2612: if (!tree_int_cst_equal (np->low, np->high)) 2613: ranges++; 2614: i++; 2615: np = np->right; 2616: } 2617: if (i > 2) 2618: { 2619: /* Split this list if it is long enough for that to help. */ 2620: npp = head; 2621: left = *npp; 2622: /* If there are just three nodes, split at the middle one. */ 2623: if (i == 3) 2624: npp = &(*npp)->right; 2625: else 2626: { 2627: /* Find the place in the list that bisects the list's total cost, 2628: where ranges count as 2. 2629: Here I gets half the total cost. */ 2630: i = (i + ranges + 1) / 2; 2631: while (1) 2632: { 2633: /* Skip nodes while their cost does not reach that amount. */ 2634: if (!tree_int_cst_equal ((*npp)->low, (*npp)->high)) 2635: i--; 2636: i--; 2637: if (i <= 0) 2638: break; 2639: npp = &(*npp)->right; 2640: } 2641: } 2642: *head = np = *npp; 2643: *npp = 0; 2644: np->parent = parent; 2645: np->left = left; 2646: 2647: /* Optimize each of the two split parts. */ 2648: balance_case_nodes (&np->left, np); 2649: balance_case_nodes (&np->right, np); 2650: } 2651: else 2652: { 2653: /* Else leave this branch as one level, 2654: but fill in `parent' fields. */ 2655: np = *head; 2656: np->parent = parent; 2657: for (; np->right; np = np->right) 2658: np->right->parent = np; 2659: } 2660: } 2661: } 2662: 2663: /* Search the parent sections of the case node tree 2664: to see if a test for the lower bound of NODE would be redundant. 2665: 2666: The instructions to synthesis the case decision tree are 2667: output in the same order as nodes are processed so it is 2668: known that if a parent node checks the range of the current 2669: node minus one that the current node is bounded at its lower 2670: span. Thus the test would be redundant. */ 2671: 2672: static int 2673: node_has_low_bound (node) 2674: case_node_ptr node; 2675: { 2676: tree low_minus_one; 2677: case_node_ptr pnode; 2678: 2679: if (node->left) 2680: { 2681: low_minus_one = combine (MINUS_EXPR, node->low, build_int_2 (1, 0)); 1.1.1.14 root 2682: /* Avoid the screw case of overflow where low_minus_one is > low. */ 2683: if (tree_int_cst_lt (low_minus_one, node->low)) 2684: for (pnode = node->parent; pnode; pnode = pnode->parent) 2685: { 2686: if (tree_int_cst_equal (low_minus_one, pnode->high)) 2687: return 1; 2688: /* If a parent node has a left branch we know that none 2689: of its parents can have a high bound of our target 2690: minus one so we abort the search. */ 2691: if (node->left) 2692: break; 2693: } 1.1.1.13 root 2694: } 2695: return 0; 2696: } 2697: 2698: /* Search the parent sections of the case node tree 2699: to see if a test for the upper bound of NODE would be redundant. 2700: 2701: The instructions to synthesis the case decision tree are 2702: output in the same order as nodes are processed so it is 2703: known that if a parent node checks the range of the current 2704: node plus one that the current node is bounded at its upper 2705: span. Thus the test would be redundant. */ 2706: 2707: static int 2708: node_has_high_bound (node) 2709: case_node_ptr node; 2710: { 2711: tree high_plus_one; 2712: case_node_ptr pnode; 2713: 2714: if (node->right == 0) 2715: { 2716: high_plus_one = combine (PLUS_EXPR, node->high, build_int_2 (1, 0)); 1.1.1.14 root 2717: /* Avoid the screw case of overflow where high_plus_one is > high. */ 2718: if (tree_int_cst_lt (node->high, high_plus_one)) 2719: for (pnode = node->parent; pnode; pnode = pnode->parent) 2720: { 2721: if (tree_int_cst_equal (high_plus_one, pnode->low)) 2722: return 1; 2723: /* If a parent node has a right branch we know that none 2724: of its parents can have a low bound of our target 2725: plus one so we abort the search. */ 2726: if (node->right) 2727: break; 2728: } 1.1.1.13 root 2729: } 2730: return 0; 2731: } 2732: 2733: /* Search the parent sections of the 2734: case node tree to see if both tests for the upper and lower 2735: bounds of NODE would be redundant. */ 2736: 2737: static int 2738: node_is_bounded (node) 2739: case_node_ptr node; 2740: { 2741: if (node->left || node->right) 2742: return 0; 2743: return node_has_low_bound (node) && node_has_high_bound (node); 2744: } 2745: 2746: /* Emit an unconditional jump to LABEL unless it would be dead code. */ 2747: 2748: static void 2749: emit_jump_if_reachable (label) 2750: rtx label; 2751: { 2752: rtx last_insn; 2753: 2754: if (GET_CODE (get_last_insn ()) != BARRIER) 2755: emit_jump (label); 2756: } 2757: 2758: /* Emit step-by-step code to select a case for the value of INDEX. 2759: The thus generated decision tree follows the form of the 2760: case-node binary tree NODE, whose nodes represent test conditions. 1.1.1.14 root 2761: UNSIGNEDP is nonzero if we should do unsigned comparisons. 1.1.1.13 root 2762: 2763: Care is taken to prune redundant tests from the decision tree 2764: by detecting any boundary conditions already checked by 2765: emitted rtx. (See node_has_high_bound, node_has_low_bound 2766: and node_is_bounded, above.) 2767: 2768: Where the test conditions can be shown to be redundant we emit 2769: an unconditional jump to the target code. As a further 2770: optimization, the subordinates of a tree node are examined to 2771: check for bounded nodes. In this case conditional and/or 2772: unconditional jumps as a result of the boundary check for the 2773: current node are arranged to target the subordinates associated 2774: code for out of bound conditions on the current node node. */ 2775: 2776: static void 1.1.1.14 root 2777: emit_case_nodes (index, node, default_label, unsignedp) 2778: rtx index; 1.1.1.13 root 2779: case_node_ptr node; 2780: tree default_label; 1.1.1.14 root 2781: int unsignedp; 1.1.1.13 root 2782: { 1.1.1.14 root 2783: /* If INDEX has an unsigned type, we must make unsigned branches. */ 2784: typedef rtx rtx_function (); 2785: rtx_function *gen_bgt_pat = unsignedp ? gen_bgtu : gen_bgt; 2786: rtx_function *gen_bge_pat = unsignedp ? gen_bgeu : gen_bge; 2787: rtx_function *gen_blt_pat = unsignedp ? gen_bltu : gen_blt; 2788: rtx_function *gen_ble_pat = unsignedp ? gen_bleu : gen_ble; 2789: 1.1.1.13 root 2790: if (node->test_label) 2791: { 2792: /* If this test node requires a label it follows that 2793: it must be preceeded by an unconditional branch. 2794: If control can pass to this point we can assume that 2795: a "br default" is in order. */ 2796: emit_jump_if_reachable (default_label); 2797: expand_label (node->test_label); 2798: } 2799: if (tree_int_cst_equal (node->low, node->high)) 2800: { 2801: /* Node is single valued. */ 2802: do_jump_if_equal (index, expand_expr (node->low, 0, VOIDmode, 0), 1.1.1.14 root 2803: label_rtx (node->code_label), unsignedp); 1.1.1.13 root 2804: if (node->right) 2805: { 2806: if (node->left) 2807: { 2808: /* This node has children on either side. */ 1.1.1.14 root 2809: emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0); 1.1.1.13 root 2810: 2811: if (node_is_bounded (node->right)) 2812: { 1.1.1.14 root 2813: emit_jump_insn (gen_bgt_pat (label_rtx (node->right->code_label))); 1.1.1.13 root 2814: if (node_is_bounded (node->left)) 2815: emit_jump (label_rtx (node->left->code_label)); 2816: else 1.1.1.14 root 2817: emit_case_nodes (index, node->left, 2818: default_label, unsignedp); 1.1.1.13 root 2819: } 2820: else 2821: { 2822: if (node_is_bounded (node->left)) 1.1.1.14 root 2823: emit_jump_insn (gen_blt_pat (label_rtx (node->left->code_label))); 1.1.1.13 root 2824: else 2825: { 2826: node->right->test_label = 2827: build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 1.1.1.14 root 2828: emit_jump_insn (gen_bgt_pat (label_rtx (node->right->test_label))); 2829: emit_case_nodes (index, node->left, 2830: default_label, unsignedp); 1.1.1.13 root 2831: } 1.1.1.14 root 2832: emit_case_nodes (index, node->right, 2833: default_label, unsignedp); 1.1.1.13 root 2834: } 2835: } 2836: else 2837: { 2838: /* Here we have a right child but no left 2839: so we issue conditional branch to default 2840: and process the right child. */ 2841: 2842: /* Omit the conditional branch to default 2843: if we it avoid only one right child; 2844: it costs too much space to save so little time. */ 2845: if (node->right->right && !node_has_low_bound (node)) 1.1.1.14 root 2846: { 2847: emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0); 2848: emit_jump_insn (gen_blt_pat (default_label)); 2849: } 1.1.1.13 root 2850: if (node_is_bounded (node->right)) 2851: emit_jump (label_rtx (node->right->code_label)); 2852: else 1.1.1.14 root 2853: emit_case_nodes (index, node->right, default_label, unsignedp); 1.1.1.13 root 2854: } 2855: } 2856: else if (node->left) 2857: { 2858: if (node_is_bounded (node->left)) 2859: emit_jump (label_rtx (node->left->code_label)); 2860: else 1.1.1.14 root 2861: emit_case_nodes (index, node->left, default_label, unsignedp); 1.1.1.13 root 2862: } 2863: } 2864: else 2865: { 2866: /* Node is a range. */ 2867: if (node->right) 2868: { 2869: if (node->left) 2870: { 1.1.1.14 root 2871: emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0); 1.1.1.13 root 2872: if (node_is_bounded (node->right)) 2873: { 2874: /* Right hand node is fully bounded so we can 2875: eliminate any testing and branch directly 2876: to the target code. */ 1.1.1.14 root 2877: emit_jump_insn (gen_bgt_pat (label_rtx (node->right->code_label))); 1.1.1.13 root 2878: } 2879: else 2880: { 2881: /* Right hand node requires testing so create 2882: a label to put on the cmp code. */ 2883: node->right->test_label = 2884: build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 1.1.1.14 root 2885: emit_jump_insn (gen_bgt_pat (label_rtx (node->right->test_label))); 1.1.1.13 root 2886: } 1.1.1.14 root 2887: emit_cmp_insn (index, expand_expr (node->low, 0, VOIDmode, 0), 0, 0, 0); 2888: emit_jump_insn (gen_bge_pat (label_rtx (node->code_label))); 1.1.1.13 root 2889: if (node_is_bounded (node->left)) 2890: { 2891: /* Left hand node is fully bounded so we can 2892: eliminate any testing and branch directly 2893: to the target code. */ 2894: emit_jump (label_rtx (node->left->code_label)); 2895: } 2896: else 1.1.1.14 root 2897: emit_case_nodes (index, node->left, default_label, unsignedp); 1.1.1.13 root 2898: /* If right node has been given a test label above 2899: we must process it now. */ 2900: if (node->right->test_label) 1.1.1.14 root 2901: emit_case_nodes (index, node->right, default_label, unsignedp); 1.1.1.13 root 2902: } 2903: else 2904: { 2905: if (!node_has_low_bound (node)) 2906: { 1.1.1.14 root 2907: emit_cmp_insn (index, expand_expr (node->low, 0, VOIDmode, 0), 0, 0, 0); 2908: emit_jump_insn (gen_blt_pat (default_label)); 1.1.1.13 root 2909: } 1.1.1.14 root 2910: emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0); 2911: emit_jump_insn (gen_ble_pat (label_rtx (node->code_label))); 1.1.1.13 root 2912: if (node_is_bounded (node->right)) 2913: { 2914: /* Right hand node is fully bounded so we can 2915: eliminate any testing and branch directly 2916: to the target code. */ 2917: emit_jump (label_rtx (node->right->code_label)); 2918: } 2919: else 1.1.1.14 root 2920: emit_case_nodes (index, node->right, default_label, unsignedp); 1.1.1.13 root 2921: } 2922: } 2923: else if (node->left) 2924: { 2925: if (!node_has_high_bound (node)) 2926: { 1.1.1.14 root 2927: emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0); 2928: emit_jump_insn (gen_bgt_pat (default_label)); 1.1.1.13 root 2929: } 1.1.1.14 root 2930: emit_cmp_insn (index, expand_expr (node->low, 0, VOIDmode, 0), 0, 0, 0); 2931: emit_jump_insn (gen_bge_pat (label_rtx (node->code_label))); 1.1.1.13 root 2932: if (node_is_bounded (node->left)) 2933: { 2934: /* Left hand node is fully bounded so we can 2935: eliminate any testing and branch directly 2936: to the target code. */ 2937: emit_jump (label_rtx (node->left->code_label)); 2938: } 2939: else 1.1.1.14 root 2940: emit_case_nodes (index, node->left, default_label, unsignedp); 1.1.1.13 root 2941: } 2942: else 2943: { 2944: /* Node has no children so we check low and 2945: high bounds to remove redundant tests. In practice 2946: only one of the limits may be bounded or the parent 2947: node will have emmited a jump to our target code. */ 2948: if (!node_has_high_bound (node)) 2949: { 1.1.1.14 root 2950: emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0); 2951: emit_jump_insn (gen_bgt_pat (default_label)); 1.1.1.13 root 2952: } 2953: if (!node_has_low_bound (node)) 2954: { 1.1.1.14 root 2955: emit_cmp_insn (index, expand_expr (node->low, 0, VOIDmode, 0), 0, 0, 0); 2956: emit_jump_insn (gen_bge_pat (label_rtx (node->code_label))); 1.1.1.13 root 2957: } 2958: /* We allow the default case to drop through since 2959: it will picked up by calls to `jump_if_reachable' 2960: either on the next test label or at the end of 2961: the decision tree emission. */ 2962: } 2963: } 2964: } 2965: 1.1.1.2 root 2966: /* Allocate fixed slots in the stack frame of the current function. */ 1.1 root 2967: 2968: /* Return size needed for stack frame based on slots so far allocated. */ 2969: 2970: int 2971: get_frame_size () 2972: { 1.1.1.2 root 2973: #ifdef FRAME_GROWS_DOWNWARD 2974: return -frame_offset; 2975: #else 1.1 root 2976: return frame_offset; 1.1.1.2 root 2977: #endif 1.1 root 2978: } 2979: 2980: /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it 2981: with machine mode MODE. */ 2982: 2983: rtx 2984: assign_stack_local (mode, size) 2985: enum machine_mode mode; 2986: int size; 2987: { 1.1.1.2 root 2988: register rtx x, addr; 1.1.1.4 root 2989: int bigend_correction = 0; 1.1 root 2990: 1.1.1.2 root 2991: frame_pointer_needed = 1; 1.1 root 2992: 2993: /* Make each stack slot a multiple of the main allocation unit. */ 2994: size = (((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1) 2995: / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)) 2996: * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); 2997: 1.1.1.4 root 2998: /* On a big-endian machine, if we are allocating more space than we will use, 2999: use the least significant bytes of those that are allocated. */ 3000: #ifdef BYTES_BIG_ENDIAN 3001: if (mode != BLKmode) 3002: bigend_correction = size - GET_MODE_SIZE (mode); 3003: #endif 3004: 1.1 root 3005: #ifdef FRAME_GROWS_DOWNWARD 3006: frame_offset -= size; 3007: #endif 1.1.1.2 root 3008: addr = gen_rtx (PLUS, Pmode, frame_pointer_rtx, 1.1.1.4 root 3009: gen_rtx (CONST_INT, VOIDmode, 3010: (frame_offset + bigend_correction))); 1.1 root 3011: #ifndef FRAME_GROWS_DOWNWARD 3012: frame_offset += size; 3013: #endif 3014: 1.1.1.2 root 3015: if (! memory_address_p (mode, addr)) 3016: invalid_stack_slot = 1; 3017: 3018: x = gen_rtx (MEM, mode, addr); 3019: 1.1.1.13 root 3020: stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list); 3021: 1.1.1.2 root 3022: return x; 1.1 root 3023: } 3024: 1.1.1.2 root 3025: /* Retroactively move an auto variable from a register to a stack slot. 3026: This is done when an address-reference to the variable is seen. */ 1.1 root 3027: 1.1.1.2 root 3028: void 3029: put_var_into_stack (decl) 3030: tree decl; 3031: { 3032: register rtx reg = DECL_RTL (decl); 3033: register rtx new; 1.1 root 3034: 1.1.1.2 root 3035: /* No need to do anything if decl has no rtx yet 3036: since in that case caller is setting TREE_ADDRESSABLE 3037: and a stack slot will be assigned when the rtl is made. */ 3038: if (reg == 0) 3039: return; 3040: if (GET_CODE (reg) != REG) 3041: return; 3042: 3043: new = parm_stack_loc (reg); 3044: if (new == 0) 3045: new = assign_stack_local (GET_MODE (reg), GET_MODE_SIZE (GET_MODE (reg))); 3046: 1.1.1.10 root 3047: XEXP (reg, 0) = XEXP (new, 0); 3048: /* `volatil' bit means one thing for MEMs, another entirely for REGs. */ 3049: REG_USERVAR_P (reg) = 0; 3050: PUT_CODE (reg, MEM); 3051: 1.1.1.2 root 3052: /* If this is a memory ref that contains aggregate components, 3053: mark it as such for cse and loop optimize. */ 1.1.1.10 root 3054: MEM_IN_STRUCT_P (reg) 1.1.1.2 root 3055: = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE 3056: || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE 3057: || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE); 3058: 3059: fixup_var_refs (reg); 3060: } 3061: 1.1 root 3062: static void 1.1.1.2 root 3063: fixup_var_refs (var) 3064: rtx var; 1.1 root 3065: { 1.1.1.10 root 3066: extern rtx sequence_stack; 3067: rtx stack = sequence_stack; 3068: tree pending; 3069: 3070: stack = sequence_stack; 3071: 3072: /* Must scan all insns for stack-refs that exceed the limit. */ 3073: fixup_var_refs_insns (var, get_insns (), stack == 0); 3074: 3075: /* Scan all pending sequences too. */ 3076: for (; stack; stack = XEXP (XEXP (stack, 1), 1)) 3077: { 3078: push_to_sequence (XEXP (stack, 0)); 3079: fixup_var_refs_insns (var, XEXP (stack, 0), 3080: XEXP (XEXP (stack, 1), 1) == 0); 3081: end_sequence (); 3082: } 3083: 3084: /* Scan all waiting RTL_EXPRs too. */ 3085: for (pending = rtl_expr_chain; pending; pending = TREE_CHAIN (pending)) 3086: { 3087: rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending)); 3088: if (seq != const0_rtx && seq != 0) 3089: { 3090: push_to_sequence (seq); 3091: fixup_var_refs_insns (var, seq, 0); 3092: end_sequence (); 3093: } 3094: } 3095: } 1.1.1.2 root 3096: 1.1.1.10 root 3097: /* Scan the insn-chain starting with INSN for refs to VAR 3098: and fix them up. TOPLEVEL is nonzero if this chain is the 3099: main chain of insns for the current function. */ 3100: 3101: static void 3102: fixup_var_refs_insns (var, insn, toplevel) 3103: rtx var; 3104: rtx insn; 3105: int toplevel; 3106: { 3107: while (insn) 1.1.1.2 root 3108: { 3109: rtx next = NEXT_INSN (insn); 1.1.1.13 root 3110: rtx note; 1.1.1.2 root 3111: if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN 3112: || GET_CODE (insn) == JUMP_INSN) 3113: { 3114: /* The insn to load VAR from a home in the arglist 3115: is now a no-op. When we see it, just delete it. */ 1.1.1.10 root 3116: if (toplevel 3117: && GET_CODE (PATTERN (insn)) == SET 1.1.1.2 root 3118: && SET_DEST (PATTERN (insn)) == var 3119: && rtx_equal_p (SET_SRC (PATTERN (insn)), var)) 1.1.1.8 root 3120: { 3121: next = delete_insn (insn); 3122: if (insn == last_parm_insn) 3123: last_parm_insn = PREV_INSN (next); 3124: } 1.1.1.2 root 3125: else 3126: fixup_var_refs_1 (var, PATTERN (insn), insn); 1.1.1.13 root 3127: /* Also fix up any invalid exprs in the REG_NOTES of this insn. 3128: But don't touch other insns referred to by reg-notes; 3129: we will get them elsewhere. */ 3130: for (note = REG_NOTES (insn); note; note = XEXP (note, 1)) 3131: if (GET_CODE (note) != INSN_LIST) 3132: XEXP (note, 0) = walk_fixup_memory_subreg (XEXP (note, 0), insn); 1.1.1.2 root 3133: } 3134: insn = next; 3135: } 3136: } 1.1.1.13 root 3137: 1.1.1.2 root 3138: static rtx 3139: fixup_var_refs_1 (var, x, insn) 3140: register rtx var; 3141: register rtx x; 3142: rtx insn; 3143: { 3144: register int i; 3145: RTX_CODE code = GET_CODE (x); 3146: register char *fmt; 3147: register rtx tem; 3148: 3149: switch (code) 3150: { 3151: case MEM: 3152: if (var == x) 3153: { 3154: x = fixup_stack_1 (x, insn); 3155: tem = gen_reg_rtx (GET_MODE (x)); 3156: emit_insn_before (gen_move_insn (tem, x), insn); 3157: return tem; 3158: } 3159: break; 3160: 3161: case REG: 3162: case CC0: 3163: case PC: 3164: case CONST_INT: 3165: case CONST: 3166: case SYMBOL_REF: 3167: case LABEL_REF: 3168: case CONST_DOUBLE: 3169: return x; 3170: 3171: case SIGN_EXTRACT: 3172: case ZERO_EXTRACT: 3173: /* Note that in some cases those types of expressions are altered 3174: by optimize_bit_field, and do not survive to get here. */ 3175: case SUBREG: 3176: tem = x; 3177: while (GET_CODE (tem) == SUBREG || GET_CODE (tem) == SIGN_EXTRACT 3178: || GET_CODE (tem) == ZERO_EXTRACT) 3179: tem = XEXP (tem, 0); 3180: if (tem == var) 3181: { 3182: x = fixup_stack_1 (x, insn); 3183: tem = gen_reg_rtx (GET_MODE (x)); 1.1.1.7 root 3184: if (GET_CODE (x) == SUBREG) 1.1.1.13 root 3185: x = fixup_memory_subreg (x, insn); 1.1.1.2 root 3186: emit_insn_before (gen_move_insn (tem, x), insn); 3187: return tem; 3188: } 3189: break; 3190: 3191: case SET: 3192: /* First do special simplification of bit-field references. */ 3193: if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT 3194: || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT) 3195: optimize_bit_field (x, insn, 0); 3196: if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT 3197: || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT) 3198: optimize_bit_field (x, insn, 0); 3199: 3200: { 3201: rtx dest = SET_DEST (x); 3202: rtx src = SET_SRC (x); 3203: rtx outerdest = dest; 3204: rtx outersrc = src; 3205: 3206: while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART 3207: || GET_CODE (dest) == SIGN_EXTRACT 3208: || GET_CODE (dest) == ZERO_EXTRACT) 3209: dest = XEXP (dest, 0); 3210: while (GET_CODE (src) == SUBREG 3211: || GET_CODE (src) == SIGN_EXTRACT 3212: || GET_CODE (src) == ZERO_EXTRACT) 3213: src = XEXP (src, 0); 3214: 3215: /* If VAR does not appear at the top level of the SET 3216: just scan the lower levels of the tree. */ 3217: 3218: if (src != var && dest != var) 3219: break; 3220: 3221: /* Clean up (SUBREG:SI (MEM:mode ...) 0) 3222: that may appear inside a SIGN_EXTRACT or ZERO_EXTRACT. 3223: This was legitimate when the MEM was a REG. */ 3224: 3225: if ((GET_CODE (outerdest) == SIGN_EXTRACT 3226: || GET_CODE (outerdest) == ZERO_EXTRACT) 3227: && GET_CODE (XEXP (outerdest, 0)) == SUBREG 3228: && SUBREG_REG (XEXP (outerdest, 0)) == var) 1.1.1.13 root 3229: XEXP (outerdest, 0) = fixup_memory_subreg (XEXP (outerdest, 0), insn); 1.1.1.2 root 3230: 3231: if ((GET_CODE (outersrc) == SIGN_EXTRACT 3232: || GET_CODE (outersrc) == ZERO_EXTRACT) 3233: && GET_CODE (XEXP (outersrc, 0)) == SUBREG 3234: && SUBREG_REG (XEXP (outersrc, 0)) == var) 1.1.1.13 root 3235: XEXP (outersrc, 0) = fixup_memory_subreg (XEXP (outersrc, 0), insn); 1.1.1.2 root 3236: 3237: /* Make sure a MEM inside a SIGN_EXTRACT has QImode 3238: since that's what bit-field insns want. */ 3239: 3240: if ((GET_CODE (outerdest) == SIGN_EXTRACT 3241: || GET_CODE (outerdest) == ZERO_EXTRACT) 3242: && GET_CODE (XEXP (outerdest, 0)) == MEM 3243: && GET_MODE (XEXP (outerdest, 0)) != QImode) 3244: { 3245: XEXP (outerdest, 0) = copy_rtx (XEXP (outerdest, 0)); 3246: PUT_MODE (XEXP (outerdest, 0), QImode); 3247: } 3248: 3249: if ((GET_CODE (outersrc) == SIGN_EXTRACT 3250: || GET_CODE (outersrc) == ZERO_EXTRACT) 3251: && GET_CODE (XEXP (outersrc, 0)) == MEM 3252: && GET_MODE (XEXP (outersrc, 0)) != QImode) 3253: { 3254: XEXP (outersrc, 0) = copy_rtx (XEXP (outersrc, 0)); 3255: PUT_MODE (XEXP (outersrc, 0), QImode); 3256: } 3257: 3258: /* STRICT_LOW_PART is a no-op on memory references 3259: and it can cause combinations to be unrecognizable, 3260: so eliminate it. */ 3261: 3262: if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART) 3263: SET_DEST (x) = XEXP (SET_DEST (x), 0); 3264: 3265: /* An insn to copy VAR into or out of a register 3266: must be left alone, to avoid an infinite loop here. 1.1.1.9 root 3267: But do fix up the address of VAR's stack slot if nec, 3268: and fix up SUBREGs containing VAR 3269: (since they are now memory subregs). */ 3270: 3271: if (GET_CODE (SET_SRC (x)) == REG || GET_CODE (SET_DEST (x)) == REG 3272: || (GET_CODE (SET_SRC (x)) == SUBREG 3273: && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG) 1.1.1.2 root 3274: || (GET_CODE (SET_DEST (x)) == SUBREG 3275: && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG)) 1.1.1.9 root 3276: { 3277: if (src == var && GET_CODE (SET_SRC (x)) == SUBREG) 1.1.1.13 root 3278: SET_SRC (x) = fixup_memory_subreg (SET_SRC (x), insn); 1.1.1.9 root 3279: if (dest == var && GET_CODE (SET_DEST (x)) == SUBREG) 1.1.1.13 root 3280: SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn); 1.1.1.9 root 3281: return fixup_stack_1 (x, insn); 3282: } 1.1.1.2 root 3283: 3284: /* Otherwise, storing into VAR must be handled specially 3285: by storing into a temporary and copying that into VAR 3286: with a new insn after this one. */ 3287: 3288: if (dest == var) 3289: { 3290: rtx temp; 3291: rtx fixeddest; 3292: tem = SET_DEST (x); 1.1.1.12 root 3293: /* STRICT_LOW_PART can be discarded, around a MEM. */ 1.1.1.2 root 3294: if (GET_CODE (tem) == STRICT_LOW_PART) 3295: tem = XEXP (tem, 0); 1.1.1.12 root 3296: /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */ 3297: if (GET_CODE (tem) == SUBREG) 1.1.1.13 root 3298: tem = fixup_memory_subreg (tem, insn); 1.1.1.12 root 3299: fixeddest = fixup_stack_1 (tem, insn); 1.1.1.2 root 3300: temp = gen_reg_rtx (GET_MODE (tem)); 3301: emit_insn_after (gen_move_insn (fixeddest, temp), insn); 3302: SET_DEST (x) = temp; 3303: } 3304: } 3305: } 3306: 3307: /* Nothing special about this RTX; fix its operands. */ 3308: 3309: fmt = GET_RTX_FORMAT (code); 3310: for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 3311: { 3312: if (fmt[i] == 'e') 3313: XEXP (x, i) = fixup_var_refs_1 (var, XEXP (x, i), insn); 3314: if (fmt[i] == 'E') 3315: { 3316: register int j; 3317: for (j = 0; j < XVECLEN (x, i); j++) 3318: XVECEXP (x, i, j) 3319: = fixup_var_refs_1 (var, XVECEXP (x, i, j), insn); 3320: } 3321: } 3322: return x; 3323: } 1.1.1.13 root 3324: 1.1.1.2 root 3325: /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)), 1.1.1.13 root 3326: return an rtx (MEM:m1 newaddr) which is equivalent. 3327: If any insns must be emitted to compute NEWADDR, put them before INSN. */ 1.1.1.2 root 3328: 3329: static rtx 1.1.1.13 root 3330: fixup_memory_subreg (x, insn) 1.1.1.2 root 3331: rtx x; 1.1.1.13 root 3332: rtx insn; 1.1.1.2 root 3333: { 3334: int offset = SUBREG_WORD (x) * UNITS_PER_WORD; 3335: rtx addr = XEXP (SUBREG_REG (x), 0); 1.1.1.7 root 3336: enum machine_mode mode = GET_MODE (x); 1.1.1.13 root 3337: rtx saved, result; 1.1.1.2 root 3338: 3339: #ifdef BYTES_BIG_ENDIAN 1.1.1.8 root 3340: offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))) 1.1.1.15! root 3341: - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))); 1.1.1.2 root 3342: #endif 1.1.1.13 root 3343: addr = plus_constant (addr, offset); 3344: if (memory_address_p (mode, addr)) 3345: return change_address (SUBREG_REG (x), mode, addr); 3346: saved = start_sequence (); 3347: result = change_address (SUBREG_REG (x), mode, addr); 3348: emit_insn_before (gen_sequence (), insn); 3349: end_sequence (saved); 3350: return result; 3351: } 3352: 3353: /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X. 3354: Replace subexpressions of X in place. 3355: If X itself is a (SUBREG (MEM ...) ...), return the replacement expression. 3356: Otherwise return X, with its contents possibly altered. 3357: 3358: If any insns must be emitted to compute NEWADDR, put them before INSN. */ 3359: 3360: static rtx 3361: walk_fixup_memory_subreg (x, insn) 3362: register rtx x; 3363: rtx insn; 3364: { 3365: register enum rtx_code code; 3366: register char *fmt; 3367: register int i; 3368: 3369: code = GET_CODE (x); 3370: 3371: if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM) 3372: return fixup_memory_subreg (x, insn); 3373: 3374: /* Nothing special about this RTX; fix its operands. */ 3375: 3376: fmt = GET_RTX_FORMAT (code); 3377: for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 3378: { 3379: if (fmt[i] == 'e') 3380: XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn); 3381: if (fmt[i] == 'E') 3382: { 3383: register int j; 3384: for (j = 0; j < XVECLEN (x, i); j++) 3385: XVECEXP (x, i, j) 3386: = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn); 3387: } 3388: } 3389: return x; 1.1.1.2 root 3390: } 3391: 3392: #if 0 3393: /* Fix up any references to stack slots that are invalid memory addresses 3394: because they exceed the maximum range of a displacement. */ 3395: 3396: void 3397: fixup_stack_slots () 3398: { 3399: register rtx insn; 3400: 3401: /* Did we generate a stack slot that is out of range 3402: or otherwise has an invalid address? */ 3403: if (invalid_stack_slot) 3404: { 3405: /* Yes. Must scan all insns for stack-refs that exceed the limit. */ 3406: for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 3407: if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN 3408: || GET_CODE (insn) == JUMP_INSN) 3409: fixup_stack_1 (PATTERN (insn), insn); 3410: } 3411: } 3412: #endif 3413: 3414: /* For each memory ref within X, if it refers to a stack slot 3415: with an out of range displacement, put the address in a temp register 3416: (emitting new insns before INSN to load these registers) 3417: and alter the memory ref to use that register. 3418: Replace each such MEM rtx with a copy, to avoid clobberage. */ 3419: 3420: static rtx 3421: fixup_stack_1 (x, insn) 3422: rtx x; 3423: rtx insn; 3424: { 3425: register int i; 3426: register RTX_CODE code = GET_CODE (x); 3427: register char *fmt; 3428: 3429: if (code == MEM) 3430: { 3431: register rtx ad = XEXP (x, 0); 3432: /* If we have address of a stack slot but it's not valid 3433: (displacement is too large), compute the sum in a register. */ 3434: if (GET_CODE (ad) == PLUS 3435: && XEXP (ad, 0) == frame_pointer_rtx 3436: && GET_CODE (XEXP (ad, 1)) == CONST_INT) 3437: { 3438: rtx temp; 3439: if (memory_address_p (GET_MODE (x), ad)) 3440: return x; 3441: temp = gen_reg_rtx (GET_MODE (ad)); 3442: emit_insn_before (gen_move_insn (temp, ad), insn); 3443: return change_address (x, VOIDmode, temp); 3444: } 3445: return x; 3446: } 3447: 3448: fmt = GET_RTX_FORMAT (code); 3449: for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 3450: { 3451: if (fmt[i] == 'e') 3452: XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn); 3453: if (fmt[i] == 'E') 3454: { 3455: register int j; 3456: for (j = 0; j < XVECLEN (x, i); j++) 3457: XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn); 3458: } 3459: } 3460: return x; 1.1 root 3461: } 1.1.1.2 root 3462: 3463: /* Optimization: a bit-field instruction whose field 3464: happens to be a byte or halfword in memory 3465: can be changed to a move instruction. 1.1 root 3466: 1.1.1.2 root 3467: We call here when INSN is an insn to examine or store into a bit-field. 3468: BODY is the SET-rtx to be altered. 3469: 3470: EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0. 3471: (Currently this is called only from stmt.c, and EQUIV_MEM is always 0.) */ 1.1 root 3472: 3473: static void 1.1.1.2 root 3474: optimize_bit_field (body, insn, equiv_mem) 3475: rtx body; 3476: rtx insn; 3477: rtx *equiv_mem; 1.1 root 3478: { 1.1.1.2 root 3479: register rtx bitfield; 3480: int destflag; 1.1 root 3481: 1.1.1.2 root 3482: if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT 3483: || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT) 3484: bitfield = SET_DEST (body), destflag = 1; 3485: else 3486: bitfield = SET_SRC (body), destflag = 0; 3487: 3488: /* First check that the field being stored has constant size and position 3489: and is in fact a byte or halfword suitably aligned. */ 3490: 3491: if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT 3492: && GET_CODE (XEXP (bitfield, 2)) == CONST_INT 3493: && (INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (QImode) 3494: || INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (HImode)) 3495: && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0) 1.1 root 3496: { 1.1.1.2 root 3497: register rtx memref = 0; 3498: 1.1.1.10 root 3499: /* Now check that the containing word is memory, not a register, 1.1.1.2 root 3500: and that it is safe to change the machine mode and to 3501: add something to the address. */ 3502: 3503: if (GET_CODE (XEXP (bitfield, 0)) == MEM) 3504: memref = XEXP (bitfield, 0); 3505: else if (GET_CODE (XEXP (bitfield, 0)) == REG 1.1.1.8 root 3506: && equiv_mem != 0) 3507: memref = equiv_mem[REGNO (XEXP (bitfield, 0))]; 1.1.1.2 root 3508: else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG 3509: && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM) 3510: memref = SUBREG_REG (XEXP (bitfield, 0)); 3511: else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG 3512: && equiv_mem != 0 1.1.1.8 root 3513: && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG) 3514: memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))]; 1.1.1.2 root 3515: 3516: if (memref 3517: && ! mode_dependent_address_p (XEXP (memref, 0)) 3518: && offsetable_address_p (GET_MODE (bitfield), XEXP (memref, 0))) 1.1 root 3519: { 1.1.1.2 root 3520: /* Now adjust the address, first for any subreg'ing 3521: that we are now getting rid of, 3522: and then for which byte of the word is wanted. */ 3523: 3524: register int offset 3525: = INTVAL (XEXP (bitfield, 2)) / GET_MODE_BITSIZE (QImode); 3526: if (GET_CODE (XEXP (bitfield, 0)) == SUBREG) 3527: { 3528: offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD; 3529: #ifdef BYTES_BIG_ENDIAN 3530: offset -= (MIN (UNITS_PER_WORD, 3531: GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0)))) 3532: - MIN (UNITS_PER_WORD, 3533: GET_MODE_SIZE (GET_MODE (memref)))); 3534: #endif 3535: } 1.1.1.8 root 3536: 1.1.1.2 root 3537: memref = gen_rtx (MEM, 3538: (INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (QImode) 3539: ? QImode : HImode), 3540: XEXP (memref, 0)); 1.1 root 3541: 1.1.1.2 root 3542: /* Store this memory reference where 3543: we found the bit field reference. */ 1.1 root 3544: 1.1.1.2 root 3545: if (destflag) 1.1 root 3546: { 1.1.1.2 root 3547: SET_DEST (body) 3548: = adj_offsetable_operand (memref, offset); 3549: if (! CONSTANT_ADDRESS_P (SET_SRC (body))) 1.1 root 3550: { 1.1.1.2 root 3551: rtx src = SET_SRC (body); 3552: while (GET_CODE (src) == SUBREG 3553: && SUBREG_WORD (src) == 0) 3554: src = SUBREG_REG (src); 3555: if (GET_MODE (src) != GET_MODE (memref)) 1.1.1.10 root 3556: src = gen_lowpart (GET_MODE (memref), SET_SRC (body)); 1.1.1.2 root 3557: SET_SRC (body) = src; 1.1 root 3558: } 1.1.1.2 root 3559: else if (GET_MODE (SET_SRC (body)) != VOIDmode 3560: && GET_MODE (SET_SRC (body)) != GET_MODE (memref)) 3561: /* This shouldn't happen because anything that didn't have 3562: one of these modes should have got converted explicitly 3563: and then referenced through a subreg. 3564: This is so because the original bit-field was 3565: handled by agg_mode and so its tree structure had 3566: the same mode that memref now has. */ 3567: abort (); 3568: } 3569: else 3570: { 1.1.1.8 root 3571: rtx dest = SET_DEST (body); 3572: 3573: while (GET_CODE (dest) == SUBREG 3574: && SUBREG_WORD (dest) == 0) 3575: dest = SUBREG_REG (dest); 3576: SET_DEST (body) = dest; 3577: 3578: memref = adj_offsetable_operand (memref, offset); 3579: if (GET_MODE (dest) == GET_MODE (memref)) 3580: SET_SRC (body) = memref; 3581: else 3582: { 1.1.1.10 root 3583: /* Convert the mem ref to the destination mode. */ 3584: rtx last = get_last_insn (); 1.1.1.8 root 3585: rtx newreg = gen_reg_rtx (GET_MODE (dest)); 1.1.1.10 root 3586: convert_move (newreg, memref, 3587: GET_CODE (SET_SRC (body)) == ZERO_EXTRACT); 3588: /* Put the conversion before the insn being fixed. */ 3589: reorder_insns (NEXT_INSN (last), get_last_insn (), 3590: PREV_INSN (insn)); 1.1.1.8 root 3591: SET_SRC (body) = newreg; 3592: } 1.1 root 3593: } 1.1.1.2 root 3594: 3595: /* Cause the insn to be re-recognized. */ 3596: 3597: INSN_CODE (insn) = -1; 1.1 root 3598: } 3599: } 3600: } 3601: 3602: /* 1 + last pseudo register number used for loading a copy 3603: of a parameter of this function. */ 3604: 3605: static int max_parm_reg; 3606: 1.1.1.2 root 3607: /* Vector indexed by REGNO, containing location on stack in which 3608: to put the parm which is nominally in pseudo register REGNO, 3609: if we discover that that parm must go in the stack. */ 3610: static rtx *parm_reg_stack_loc; 3611: 3612: int 3613: max_parm_reg_num () 3614: { 3615: return max_parm_reg; 3616: } 3617: 3618: /* Return the first insn following those generated by `assign_parms'. */ 3619: 3620: rtx 3621: get_first_nonparm_insn () 3622: { 3623: if (last_parm_insn) 3624: return NEXT_INSN (last_parm_insn); 3625: return get_insns (); 3626: } 3627: 3628: /* Get the stack home of a REG rtx that is one of this function's parameters. 3629: This is called rather than assign a new stack slot as a local. 3630: Return 0 if there is no existing stack home suitable for such use. */ 3631: 3632: static rtx 3633: parm_stack_loc (reg) 3634: rtx reg; 3635: { 3636: if (REGNO (reg) < max_parm_reg) 3637: return parm_reg_stack_loc[REGNO (reg)]; 3638: return 0; 3639: } 3640: 1.1 root 3641: /* Assign RTL expressions to the function's parameters. 3642: This may involve copying them into registers and using 3643: those registers as the RTL for them. */ 3644: 3645: static void 3646: assign_parms (fndecl) 3647: tree fndecl; 3648: { 3649: register tree parm; 1.1.1.2 root 3650: register rtx entry_parm; 3651: register rtx stack_parm; 3652: register CUMULATIVE_ARGS args_so_far; 3653: enum machine_mode passed_mode, nominal_mode; 3654: /* Total space needed so far for args on the stack, 3655: given as a constant and a tree-expression. */ 3656: struct args_size stack_args_size; 1.1.1.8 root 3657: int first_parm_offset = FIRST_PARM_OFFSET (fndecl); 1.1.1.13 root 3658: tree fntype = TREE_TYPE (fndecl); 1.1.1.2 root 3659: 3660: int nparmregs 3661: = list_length (DECL_ARGUMENTS (fndecl)) + FIRST_PSEUDO_REGISTER; 3662: 3663: /* Nonzero if function takes extra anonymous args. 3664: This means the last named arg must be on the stack 1.1.1.4 root 3665: right before the anonymous ones. 3666: Also nonzero if the first arg is named `__builtin_va_alist', 3667: which is used on some machines for old-fashioned non-ANSI varargs.h; 3668: this too should be stuck onto the stack as if it had arrived there. */ 1.1.1.2 root 3669: int vararg 1.1.1.4 root 3670: = ((DECL_ARGUMENTS (fndecl) != 0 1.1.1.13 root 3671: && DECL_NAME (DECL_ARGUMENTS (fndecl)) 1.1.1.4 root 3672: && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (DECL_ARGUMENTS (fndecl))), 3673: "__builtin_va_alist"))) 3674: || 1.1.1.13 root 3675: (TYPE_ARG_TYPES (fntype) != 0 3676: && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) 1.1.1.4 root 3677: != void_type_node))); 1.1.1.2 root 3678: 3679: stack_args_size.constant = 0; 3680: stack_args_size.var = 0; 3681: 1.1.1.6 root 3682: /* If struct value address comes on the stack, count it in size of args. */ 3683: if (DECL_MODE (DECL_RESULT (fndecl)) == BLKmode 3684: && GET_CODE (struct_value_incoming_rtx) == MEM) 3685: stack_args_size.constant += GET_MODE_SIZE (Pmode); 3686: 1.1.1.2 root 3687: parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx)); 3688: bzero (parm_reg_stack_loc, nparmregs * sizeof (rtx)); 3689: 1.1.1.13 root 3690: INIT_CUMULATIVE_ARGS (args_so_far, fntype); 1.1 root 3691: 1.1.1.2 root 3692: for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm)) 1.1 root 3693: { 1.1.1.2 root 3694: int aggregate 3695: = (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE 3696: || TREE_CODE (TREE_TYPE (parm)) == RECORD_TYPE 3697: || TREE_CODE (TREE_TYPE (parm)) == UNION_TYPE); 3698: struct args_size stack_offset; 3699: rtx stack_offset_rtx; 1.1.1.6 root 3700: enum direction where_pad; 1.1.1.2 root 3701: 3702: DECL_OFFSET (parm) = -1; 3703: 1.1.1.8 root 3704: if (TREE_TYPE (parm) == error_mark_node 1.1.1.10 root 3705: /* This can happen after weird syntax errors 3706: or if an enum type is defined among the parms. */ 1.1.1.8 root 3707: || TREE_CODE (parm) != PARM_DECL 3708: || DECL_ARG_TYPE (parm) == NULL) 1.1.1.2 root 3709: { 3710: DECL_RTL (parm) = gen_rtx (MEM, BLKmode, const0_rtx); 1.1.1.13 root 3711: TREE_USED (parm) = 1; 1.1.1.2 root 3712: continue; 3713: } 3714: 3715: /* Find mode of arg as it is passed, and mode of arg 3716: as it should be during execution of this function. */ 3717: passed_mode = TYPE_MODE (DECL_ARG_TYPE (parm)); 3718: nominal_mode = TYPE_MODE (TREE_TYPE (parm)); 3719: 1.1.1.6 root 3720: /* Get this parm's offset as an rtx. */ 3721: stack_offset = stack_args_size; 1.1.1.8 root 3722: stack_offset.constant += first_parm_offset; 1.1.1.6 root 3723: 3724: /* Find out if the parm needs padding, and whether above or below. */ 3725: where_pad 3726: = FUNCTION_ARG_PADDING (passed_mode, 3727: expand_expr (size_in_bytes (DECL_ARG_TYPE (parm)), 3728: 0, VOIDmode, 0)); 3729: 3730: /* If it is padded below, adjust the stack address 3731: upward over the padding. */ 3732: if (where_pad == downward) 3733: { 3734: if (passed_mode != BLKmode) 3735: { 3736: if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY) 3737: stack_offset.constant 3738: += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1) 3739: / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT) 3740: - GET_MODE_SIZE (passed_mode)); 3741: } 3742: else 3743: { 3744: tree sizetree = size_in_bytes (DECL_ARG_TYPE (parm)); 3745: /* Round the size up to multiple of PARM_BOUNDARY bits. */ 3746: tree s1 = convert_units (sizetree, BITS_PER_UNIT, PARM_BOUNDARY); 3747: tree s2 = convert_units (s1, PARM_BOUNDARY, BITS_PER_UNIT); 3748: /* Add it in. */ 3749: ADD_PARM_SIZE (stack_offset, s2); 3750: SUB_PARM_SIZE (stack_offset, sizetree); 3751: } 3752: } 3753: 3754: stack_offset_rtx = ARGS_SIZE_RTX (stack_offset); 3755: 1.1.1.2 root 3756: /* Determine parm's home in the stack, 3757: in case it arrives in the stack or we should pretend it did. */ 3758: stack_parm 3759: = gen_rtx (MEM, passed_mode, 3760: memory_address (passed_mode, 3761: gen_rtx (PLUS, Pmode, 3762: arg_pointer_rtx, stack_offset_rtx))); 3763: 3764: /* If this is a memory ref that contains aggregate components, 3765: mark it as such for cse and loop optimize. */ 1.1.1.10 root 3766: MEM_IN_STRUCT_P (stack_parm) = aggregate; 1.1.1.2 root 3767: 3768: /* Let machine desc say which reg (if any) the parm arrives in. 3769: 0 means it arrives on the stack. */ 3770: entry_parm = 0; 3771: /* Variable-size args, and args following such, are never in regs. */ 3772: if (TREE_CODE (TYPE_SIZE (TREE_TYPE (parm))) == INTEGER_CST 3773: || stack_offset.var != 0) 3774: { 3775: #ifdef FUNCTION_INCOMING_ARG 3776: entry_parm 3777: = FUNCTION_INCOMING_ARG (args_so_far, passed_mode, 3778: DECL_ARG_TYPE (parm), 1); 3779: #else 3780: entry_parm 3781: = FUNCTION_ARG (args_so_far, passed_mode, DECL_ARG_TYPE (parm), 1); 3782: #endif 3783: } 3784: /* If this parm was passed part in regs and part in memory, 3785: pretend it arrived entirely in memory 3786: by pushing the register-part onto the stack. 3787: 3788: In the special case of a DImode or DFmode that is split, 3789: we could put it together in a pseudoreg directly, 3790: but for now that's not worth bothering with. */ 3791: 3792: /* If this is the last named arg and anonymous args follow, 3793: likewise pretend this arg arrived on the stack 3794: so varargs can find the anonymous args following it. */ 3795: { 3796: int nregs = 0; 3797: int i; 3798: #ifdef FUNCTION_ARG_PARTIAL_NREGS 3799: nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode, 3800: DECL_ARG_TYPE (parm), 1); 3801: #endif 3802: if (TREE_CHAIN (parm) == 0 && vararg && entry_parm != 0) 1.1.1.4 root 3803: { 3804: if (GET_MODE (entry_parm) == BLKmode) 3805: nregs = GET_MODE_SIZE (GET_MODE (entry_parm)) / UNITS_PER_WORD; 3806: else 3807: nregs = (int_size_in_bytes (DECL_ARG_TYPE (parm)) 3808: / UNITS_PER_WORD); 3809: } 1.1.1.2 root 3810: 3811: if (nregs > 0) 1.1.1.4 root 3812: { 3813: current_function_pretend_args_size 3814: = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1) 3815: / (PARM_BOUNDARY / BITS_PER_UNIT) 3816: * (PARM_BOUNDARY / BITS_PER_UNIT)); 3817: 3818: i = nregs; 3819: while (--i >= 0) 3820: emit_move_insn (gen_rtx (MEM, SImode, 3821: plus_constant (XEXP (stack_parm, 0), 3822: i * GET_MODE_SIZE (SImode))), 3823: gen_rtx (REG, SImode, REGNO (entry_parm) + i)); 3824: entry_parm = stack_parm; 3825: } 1.1.1.2 root 3826: } 3827: 1.1.1.4 root 3828: /* If we didn't decide this parm came in a register, 3829: by default it came on the stack. */ 1.1.1.2 root 3830: if (entry_parm == 0) 3831: entry_parm = stack_parm; 3832: 1.1.1.4 root 3833: /* For a stack parm, record in DECL_OFFSET the arglist offset 3834: of the parm at the time it is passed (before conversion). */ 1.1.1.2 root 3835: if (entry_parm == stack_parm) 1.1.1.4 root 3836: DECL_OFFSET (parm) = stack_offset.constant * BITS_PER_UNIT; 3837: 3838: /* If there is actually space on the stack for this parm, 3839: count it in stack_args_size; otherwise set stack_parm to 0 3840: to indicate there is no preallocated stack slot for the parm. */ 3841: 3842: if (entry_parm == stack_parm 3843: #ifdef REG_PARM_STACK_SPACE 3844: /* On some machines, even if a parm value arrives in a register 3845: there is still an (uninitialized) stack slot allocated for it. */ 3846: || 1 3847: #endif 3848: ) 1.1.1.2 root 3849: { 3850: tree sizetree = size_in_bytes (DECL_ARG_TYPE (parm)); 1.1.1.6 root 3851: if (where_pad != none) 3852: { 3853: /* Round the size up to multiple of PARM_BOUNDARY bits. */ 3854: tree s1 = convert_units (sizetree, BITS_PER_UNIT, PARM_BOUNDARY); 3855: sizetree = convert_units (s1, PARM_BOUNDARY, BITS_PER_UNIT); 3856: } 1.1.1.2 root 3857: /* Add it in. */ 1.1.1.6 root 3858: ADD_PARM_SIZE (stack_args_size, sizetree); 1.1.1.2 root 3859: } 1.1.1.4 root 3860: else 3861: /* No stack slot was pushed for this parm. */ 3862: stack_parm = 0; 1.1.1.2 root 3863: 1.1.1.4 root 3864: /* Now adjust STACK_PARM to the mode and precise location 1.1.1.2 root 3865: where this parameter should live during execution, 3866: if we discover that it must live in the stack during execution. 3867: To make debuggers happier on big-endian machines, we store 3868: the value in the last bytes of the space available. */ 3869: 1.1.1.4 root 3870: if (nominal_mode != BLKmode && nominal_mode != passed_mode 3871: && stack_parm != 0) 1.1.1.2 root 3872: { 3873: #ifdef BYTES_BIG_ENDIAN 1.1.1.6 root 3874: if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD) 3875: { 3876: stack_offset.constant 3877: += GET_MODE_SIZE (passed_mode) 3878: - GET_MODE_SIZE (nominal_mode); 3879: stack_offset_rtx = ARGS_SIZE_RTX (stack_offset); 3880: } 1.1.1.2 root 3881: #endif 3882: 3883: stack_parm 3884: = gen_rtx (MEM, nominal_mode, 3885: memory_address (nominal_mode, 3886: gen_rtx (PLUS, Pmode, 3887: arg_pointer_rtx, 3888: stack_offset_rtx))); 3889: 3890: /* If this is a memory ref that contains aggregate components, 3891: mark it as such for cse and loop optimize. */ 1.1.1.10 root 3892: MEM_IN_STRUCT_P (stack_parm) = aggregate; 1.1.1.2 root 3893: } 3894: 3895: /* ENTRY_PARM is an RTX for the parameter as it arrives, 3896: in the mode in which it arrives. 1.1.1.4 root 3897: STACK_PARM is an RTX for a stack slot where the parameter can live 3898: during the function (in case we want to put it there). 3899: STACK_PARM is 0 if no stack slot was pushed for it. 1.1 root 3900: 1.1.1.4 root 3901: Now output code if necessary to convert ENTRY_PARM to 1.1 root 3902: the type in which this function declares it, 1.1.1.4 root 3903: and store that result in an appropriate place, 3904: which may be a pseudo reg, may be STACK_PARM, 3905: or may be a local stack slot if STACK_PARM is 0. 3906: 3907: Set DECL_RTL to that place. */ 1.1.1.2 root 3908: 3909: if (nominal_mode == BLKmode) 3910: { 3911: /* If a BLKmode arrives in registers, copy it to a stack slot. */ 1.1.1.4 root 3912: if (GET_CODE (entry_parm) == REG) 1.1.1.2 root 3913: { 1.1.1.4 root 3914: if (stack_parm == 0) 3915: stack_parm 3916: = assign_stack_local (GET_MODE (entry_parm), 3917: int_size_in_bytes (TREE_TYPE (parm))); 1.1.1.2 root 3918: 3919: move_block_from_reg (REGNO (entry_parm), stack_parm, 3920: int_size_in_bytes (TREE_TYPE (parm)) 3921: / UNITS_PER_WORD); 3922: } 3923: DECL_RTL (parm) = stack_parm; 3924: } 1.1.1.10 root 3925: else if (! ((obey_regdecls && ! TREE_REGDECL (parm) 3926: && ! TREE_INLINE (fndecl)) 1.1.1.14 root 3927: /* layout_decl may set this. */ 3928: || TREE_ADDRESSABLE (parm) 1.1.1.15! root 3929: || TREE_VOLATILE (parm) 1.1.1.2 root 3930: /* If -ffloat-store specified, don't put explicit 3931: float variables into registers. */ 3932: || (flag_float_store 3933: && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))) 1.1 root 3934: { 1.1.1.2 root 3935: /* Store the parm in a pseudoregister during the function. */ 3936: register rtx parmreg = gen_reg_rtx (nominal_mode); 1.1 root 3937: 1.1.1.10 root 3938: REG_USERVAR_P (parmreg) = 1; 1.1 root 3939: DECL_RTL (parm) = parmreg; 3940: 3941: /* Copy the value into the register. */ 1.1.1.2 root 3942: if (GET_MODE (parmreg) != GET_MODE (entry_parm)) 3943: convert_move (parmreg, entry_parm, 0); 1.1 root 3944: else 1.1.1.2 root 3945: emit_move_insn (parmreg, entry_parm); 3946: 3947: /* In any case, record the parm's desired stack location 3948: in case we later discover it must live in the stack. */ 3949: if (REGNO (parmreg) >= nparmregs) 3950: { 3951: rtx *new; 3952: nparmregs = REGNO (parmreg) + 5; 3953: new = (rtx *) oballoc (nparmregs * sizeof (rtx)); 3954: bcopy (parm_reg_stack_loc, new, nparmregs * sizeof (rtx)); 3955: parm_reg_stack_loc = new; 3956: } 3957: parm_reg_stack_loc[REGNO (parmreg)] = stack_parm; 1.1 root 3958: 1.1.1.2 root 3959: /* Mark the register as eliminable if we did no conversion 3960: and it was copied from memory at a fixed offset. */ 3961: if (nominal_mode == passed_mode 3962: && GET_CODE (entry_parm) == MEM 3963: && stack_offset.var == 0) 1.1.1.10 root 3964: REG_NOTES (get_last_insn ()) 3965: = gen_rtx (EXPR_LIST, REG_EQUIV, 3966: entry_parm, REG_NOTES (get_last_insn ())); 1.1 root 3967: 3968: /* For pointer data type, suggest pointer register. */ 3969: if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE) 3970: mark_reg_pointer (parmreg); 3971: } 1.1.1.2 root 3972: else 1.1 root 3973: { 1.1.1.2 root 3974: /* Value must be stored in the stack slot STACK_PARM 3975: during function execution. */ 3976: 3977: if (passed_mode != nominal_mode) 3978: /* Conversion is required. */ 3979: entry_parm = convert_to_mode (nominal_mode, entry_parm, 0); 3980: 3981: if (entry_parm != stack_parm) 3982: { 3983: if (stack_parm == 0) 3984: stack_parm = assign_stack_local (GET_MODE (entry_parm), 3985: GET_MODE_SIZE (GET_MODE (entry_parm))); 3986: emit_move_insn (stack_parm, entry_parm); 3987: } 3988: 3989: DECL_RTL (parm) = stack_parm; 3990: frame_pointer_needed = 1; 1.1 root 3991: } 1.1.1.2 root 3992: 3993: if (TREE_VOLATILE (parm)) 1.1.1.10 root 3994: MEM_VOLATILE_P (DECL_RTL (parm)) = 1; 1.1.1.2 root 3995: if (TREE_READONLY (parm)) 1.1.1.10 root 3996: RTX_UNCHANGING_P (DECL_RTL (parm)) = 1; 1.1.1.2 root 3997: 3998: /* Update info on where next arg arrives in registers. */ 3999: 4000: FUNCTION_ARG_ADVANCE (args_so_far, passed_mode, DECL_ARG_TYPE (parm), 1); 1.1 root 4001: } 1.1.1.4 root 4002: 1.1 root 4003: max_parm_reg = max_reg_num (); 1.1.1.2 root 4004: last_parm_insn = get_last_insn (); 4005: 4006: current_function_args_size = stack_args_size.constant; 1.1 root 4007: } 4008: 4009: /* Allocation of space for returned structure values. 4010: During the rtl generation pass, `get_structure_value_addr' 4011: is called from time to time to request the address of a block in our 4012: stack frame in which called functions will store the structures 4013: they are returning. The same space is used for all of these blocks. 4014: 1.1.1.2 root 4015: We allocate these blocks like stack locals. We keep reusing 4016: the same block until a bigger one is needed. */ 4017: 4018: /* Length in bytes of largest structure value returned by 4019: any function called so far in this function. */ 4020: static int max_structure_value_size; 1.1 root 4021: 1.1.1.2 root 4022: /* An rtx for the addr we are currently using for structure values. 4023: This is typically (PLUS (REG:SI stackptr) (CONST_INT...)). */ 4024: static rtx structure_value; 1.1 root 4025: 4026: rtx 4027: get_structure_value_addr (sizex) 4028: rtx sizex; 4029: { 4030: register int size; 4031: if (GET_CODE (sizex) != CONST_INT) 4032: abort (); 4033: size = INTVAL (sizex); 4034: 4035: /* Round up to a multiple of the main allocation unit. */ 4036: size = (((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1) 4037: / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)) 4038: * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); 4039: 1.1.1.2 root 4040: /* If this size is bigger than space we know to use, 4041: get a bigger piece of space. */ 1.1 root 4042: if (size > max_structure_value_size) 4043: { 4044: max_structure_value_size = size; 1.1.1.2 root 4045: structure_value = assign_stack_local (BLKmode, size); 4046: if (GET_CODE (structure_value) == MEM) 4047: structure_value = XEXP (structure_value, 0); 1.1 root 4048: } 1.1.1.2 root 4049: 4050: return structure_value; 1.1 root 4051: } 1.1.1.2 root 4052: 4053: /* Walk the tree of LET_STMTs describing the binding levels within a function 4054: and warn about uninitialized variables. 4055: This is done after calling flow_analysis and before global_alloc 4056: clobbers the pseudo-regs to hard regs. */ 1.1 root 4057: 1.1.1.2 root 4058: void 4059: uninitialized_vars_warning (block) 4060: tree block; 1.1 root 4061: { 1.1.1.2 root 4062: register tree decl, sub; 4063: for (decl = STMT_VARS (block); decl; decl = TREE_CHAIN (decl)) 4064: { 4065: if (TREE_CODE (decl) == VAR_DECL 4066: /* These warnings are unreliable for and aggregates 4067: because assigning the fields one by one can fail to convince 4068: flow.c that the entire aggregate was initialized. 4069: Unions are troublesome because members may be shorter. */ 4070: && TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE 4071: && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE 4072: && TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE 4073: && GET_CODE (DECL_RTL (decl)) == REG 4074: && regno_uninitialized (REGNO (DECL_RTL (decl)))) 4075: warning_with_decl (decl, 1.1.1.15! root 4076: "`%s' may be used uninitialized in this function"); 1.1.1.2 root 4077: if (TREE_CODE (decl) == VAR_DECL 4078: && GET_CODE (DECL_RTL (decl)) == REG 4079: && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) 4080: warning_with_decl (decl, 4081: "variable `%s' may be clobbered by `longjmp'"); 4082: } 4083: for (sub = STMT_BODY (block); sub; sub = TREE_CHAIN (sub)) 4084: uninitialized_vars_warning (sub); 1.1 root 4085: } 1.1.1.11 root 4086: 4087: /* If this function call setjmp, put all vars into the stack 4088: unless they were declared `register'. */ 4089: 4090: void 4091: setjmp_protect (block) 4092: tree block; 4093: { 4094: register tree decl, sub; 4095: for (decl = STMT_VARS (block); decl; decl = TREE_CHAIN (decl)) 4096: if ((TREE_CODE (decl) == VAR_DECL 4097: || TREE_CODE (decl) == PARM_DECL) 4098: && DECL_RTL (decl) != 0 4099: && GET_CODE (DECL_RTL (decl)) == REG 4100: && ! TREE_REGDECL (decl)) 4101: put_var_into_stack (decl); 4102: for (sub = STMT_BODY (block); sub; sub = TREE_CHAIN (sub)) 4103: setjmp_protect (sub); 4104: } 1.1 root 4105: 1.1.1.2 root 4106: /* Generate RTL for the start of the function FUNC (a FUNCTION_DECL tree node) 4107: and initialize static variables for generating RTL for the statements 4108: of the function. */ 1.1 root 4109: 1.1.1.2 root 4110: void 4111: expand_function_start (subr) 1.1 root 4112: tree subr; 4113: { 4114: register int i; 1.1.1.2 root 4115: tree tem; 1.1 root 4116: 4117: this_function = subr; 1.1.1.2 root 4118: cse_not_expected = ! optimize; 4119: 4120: /* We have not yet found a reason why a frame pointer cannot 4121: be omitted for this function in particular, but maybe we know 4122: a priori that it is required. 4123: `flag_omit_frame_pointer' has its main effect here. */ 4124: frame_pointer_needed = FRAME_POINTER_REQUIRED || ! flag_omit_frame_pointer; 1.1 root 4125: 1.1.1.2 root 4126: /* No gotos have been expanded yet. */ 4127: goto_fixup_chain = 0; 1.1 root 4128: 1.1.1.13 root 4129: /* No stack slots have been made yet. */ 4130: stack_slot_list = 0; 4131: 1.1.1.2 root 4132: /* No invalid stack slots have been made yet. */ 4133: invalid_stack_slot = 0; 4134: 4135: /* Initialize the RTL mechanism. */ 4136: init_emit (write_symbols); 4137: 4138: /* Initialize the queue of pending postincrement and postdecrements, 4139: and some other info in expr.c. */ 4140: init_expr (); 4141: 4142: init_const_rtx_hash_table (); 4143: 4144: /* Decide whether function should try to pop its args on return. */ 4145: 4146: current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (subr)); 4147: 4148: current_function_name = IDENTIFIER_POINTER (DECL_NAME (subr)); 4149: 1.1.1.10 root 4150: /* Nonzero if this is a nested function that uses a static chain. */ 4151: 1.1.1.13 root 4152: current_function_needs_context 4153: = (DECL_CONTEXT (current_function_decl) != 0 4154: && TREE_CODE (DECL_CONTEXT (current_function_decl)) == LET_STMT); 1.1.1.10 root 4155: 1.1.1.11 root 4156: /* Set if a call to setjmp is seen. */ 4157: 4158: current_function_calls_setjmp = 0; 4159: 1.1.1.15! root 4160: current_function_returns_pcc_struct = 0; ! 4161: current_function_returns_struct = 0; 1.1.1.10 root 4162: 1.1.1.2 root 4163: /* Make the label for return statements to jump to, if this machine 4164: does not have a one-instruction return. */ 1.1.1.8 root 4165: #ifdef HAVE_return 1.1.1.15! root 4166: if (HAVE_return && ! current_function_returns_pcc_struct) 1.1.1.8 root 4167: return_label = 0; 4168: else 4169: return_label = gen_label_rtx (); 1.1.1.2 root 4170: #else 1.1.1.8 root 4171: return_label = gen_label_rtx (); 1.1 root 4172: #endif 4173: 1.1.1.2 root 4174: /* No space assigned yet for structure values. */ 1.1 root 4175: max_structure_value_size = 0; 1.1.1.2 root 4176: structure_value = 0; 1.1 root 4177: 1.1.1.2 root 4178: /* We are not currently within any block, conditional, loop or case. */ 1.1 root 4179: block_stack = 0; 1.1.1.2 root 4180: loop_stack = 0; 4181: case_stack = 0; 4182: cond_stack = 0; 4183: nesting_stack = 0; 4184: nesting_depth = 0; 4185: 4186: /* We have not yet needed to make a label to jump to for tail-recursion. */ 1.1 root 4187: tail_recursion_label = 0; 4188: 1.1.1.2 root 4189: /* No stack slots allocated yet. */ 4190: frame_offset = STARTING_FRAME_OFFSET; 4191: 1.1.1.5 root 4192: /* No SAVE_EXPRs in this function yet. */ 4193: save_expr_regs = 0; 4194: 1.1.1.10 root 4195: /* No RTL_EXPRs in this function yet. */ 4196: rtl_expr_chain = 0; 4197: 1.1.1.4 root 4198: /* Within function body, compute a type's size as soon it is laid out. */ 4199: immediate_size_expand++; 4200: 1.1.1.2 root 4201: init_pending_stack_adjust (); 1.1 root 4202: clear_current_args_size (); 1.1.1.7 root 4203: current_function_pretend_args_size = 0; 1.1 root 4204: 4205: /* Prevent ever trying to delete the first instruction of a function. 4206: Also tell final how to output a linenum before the function prologue. */ 1.1.1.12 root 4207: emit_line_note (DECL_SOURCE_FILE (subr), DECL_SOURCE_LINE (subr)); 1.1 root 4208: /* Make sure first insn is a note even if we don't want linenums. 4209: This makes sure the first insn will never be deleted. 4210: Also, final expects a note to appear there. */ 4211: emit_note (0, NOTE_INSN_DELETED); 4212: 4213: /* Initialize rtx for parameters and local variables. 4214: In some cases this requires emitting insns. */ 4215: 4216: assign_parms (subr); 1.1.1.2 root 4217: 1.1 root 4218: /* Initialize rtx used to return the value. */ 4219: 1.1.1.15! root 4220: /* Decide whether to return the value in memory or in a register. */ ! 4221: if (DECL_MODE (DECL_RESULT (current_function_decl)) == BLKmode ! 4222: || (flag_pcc_struct_return ! 4223: && ((TREE_CODE (TREE_TYPE (DECL_RESULT (current_function_decl))) ! 4224: == RECORD_TYPE) ! 4225: || (TREE_CODE (TREE_TYPE (DECL_RESULT (current_function_decl))) ! 4226: == UNION_TYPE)))) 1.1 root 4227: { 4228: /* Returning something that won't go in a register. */ 4229: register rtx value_address; 4230: 1.1.1.15! root 4231: #ifdef PCC_STATIC_STRUCT_RETURN ! 4232: if (flag_pcc_struct_return) ! 4233: { ! 4234: int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr))); ! 4235: value_address = assemble_static_space (size); ! 4236: current_function_returns_pcc_struct = 1; ! 4237: } ! 4238: else ! 4239: #endif ! 4240: { ! 4241: /* Expect to be passed the address of a place to store the value. */ ! 4242: value_address = gen_reg_rtx (Pmode); ! 4243: emit_move_insn (value_address, struct_value_incoming_rtx); ! 4244: current_function_returns_struct = 1; ! 4245: } 1.1 root 4246: DECL_RTL (DECL_RESULT (subr)) 4247: = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), 4248: value_address); 4249: } 4250: else 1.1.1.15! root 4251: /* Scalar, returned in a register. */ 1.1.1.2 root 4252: #ifdef FUNCTION_OUTGOING_VALUE 1.1 root 4253: DECL_RTL (DECL_RESULT (subr)) 1.1.1.2 root 4254: = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr); 4255: #else 4256: DECL_RTL (DECL_RESULT (subr)) 4257: = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr); 4258: #endif 1.1.1.6 root 4259: 4260: /* Mark this reg as the function's return value. */ 4261: if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG) 4262: REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1; 1.1.1.8 root 4263: 1.1.1.10 root 4264: /* If doing stupid allocation, mark parms as born here. */ 4265: 4266: if (obey_regdecls) 4267: { 4268: parm_birth_insn = get_last_insn (); 4269: for (i = FIRST_PSEUDO_REGISTER; i < max_parm_reg; i++) 4270: use_variable (regno_reg_rtx[i]); 4271: } 4272: 1.1.1.8 root 4273: /* After the parm initializations is where the tail-recursion label 4274: should go, if we end up needing one. */ 4275: tail_recursion_reentry = get_last_insn (); 4276: 4277: /* Evaluate now the sizes of any types declared among the arguments. */ 4278: for (tem = get_pending_sizes (); tem; tem = TREE_CHAIN (tem)) 4279: expand_expr (TREE_VALUE (tem), 0, VOIDmode, 0); 1.1.1.2 root 4280: } 1.1 root 4281: 1.1.1.6 root 4282: /* Generate RTL for the end of the current function. 1.1.1.13 root 4283: FILENAME and LINE are the current position in the source file. */ 1.1 root 4284: 1.1.1.2 root 4285: void 1.1.1.6 root 4286: expand_function_end (filename, line) 4287: char *filename; 4288: int line; 1.1.1.2 root 4289: { 4290: register int i; 1.1.1.13 root 4291: extern rtx sequence_stack; 4292: 4293: /* End any sequences that failed to be closed due to syntax errors. */ 4294: while (sequence_stack) 4295: end_sequence (0); 1.1 root 4296: 1.1.1.4 root 4297: /* Outside function body, can't compute type's actual size 4298: until next function's body starts. */ 4299: immediate_size_expand--; 4300: 1.1.1.13 root 4301: /* If returning a structure, arrange to return the address of the value 4302: in a place where debuggers expect to find it. */ 1.1.1.15! root 4303: if (current_function_returns_struct) 1.1.1.13 root 4304: { 4305: rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0); 4306: tree type = TREE_TYPE (DECL_RESULT (current_function_decl)); 4307: rtx outgoing 4308: = hard_function_value (build_pointer_type (type), 4309: current_function_decl); 4310: 4311: emit_move_insn (outgoing, value_address); 4312: } 4313: 1.1 root 4314: /* If doing stupid register allocation, 1.1.1.2 root 4315: mark register parms as dying here. */ 4316: 1.1 root 4317: if (obey_regdecls) 1.1.1.5 root 4318: { 4319: rtx tem; 4320: for (i = FIRST_PSEUDO_REGISTER; i < max_parm_reg; i++) 4321: use_variable (regno_reg_rtx[i]); 4322: 4323: /* Likewise for the regs of all the SAVE_EXPRs in the function. */ 4324: 4325: for (tem = save_expr_regs; tem; tem = XEXP (tem, 1)) 1.1.1.13 root 4326: { 4327: /* ??? Tiemann thinks this does not work. */ 4328: use_variable (XEXP (tem, 0)); 4329: use_variable_after (XEXP (tem, 0), parm_birth_insn); 4330: } 1.1.1.5 root 4331: } 1.1 root 4332: 4333: clear_pending_stack_adjust (); 1.1.1.2 root 4334: do_pending_stack_adjust (); 1.1 root 4335: 1.1.1.2 root 4336: /* Mark the end of the function body. 4337: If control reaches this insn, the function can drop through 4338: without returning a value. */ 4339: emit_note (0, NOTE_INSN_FUNCTION_END); 4340: 1.1.1.6 root 4341: /* Output a linenumber for the end of the function. 4342: SDB depends on this. */ 1.1.1.13 root 4343: emit_line_note_force (filename, line); 1.1.1.6 root 4344: 1.1.1.2 root 4345: /* If we require a true epilogue, 4346: put here the label that return statements jump to. 4347: If there will be no epilogue, write a return instruction. */ 1.1.1.8 root 4348: #ifdef HAVE_return 1.1.1.15! root 4349: if (HAVE_return && ! current_function_returns_pcc_struct) 1.1.1.8 root 4350: emit_jump_insn (gen_return ()); 4351: else 1.1 root 4352: #endif 1.1.1.8 root 4353: emit_label (return_label); 1.1.1.6 root 4354: 1.1.1.15! root 4355: /* If returning a structure PCC style, ! 4356: really return the address of where we put the structure. ! 4357: Do this after the return label, since all returns must ! 4358: do it. */ ! 4359: if (current_function_returns_pcc_struct) ! 4360: { ! 4361: rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0); ! 4362: tree type = TREE_TYPE (DECL_RESULT (current_function_decl)); ! 4363: rtx outgoing ! 4364: = hard_function_value (build_pointer_type (type), ! 4365: current_function_decl); ! 4366: ! 4367: emit_move_insn (outgoing, value_address); ! 4368: use_variable (outgoing); ! 4369: } ! 4370: 1.1.1.6 root 4371: /* Fix up any gotos that jumped out to the outermost 4372: binding level of the function. 4373: Must follow emitting RETURN_LABEL. */ 1.1.1.8 root 4374: 4375: /* If you have any cleanups to do at this point, 4376: and they need to create temporary variables, 4377: then you will lose. */ 1.1.1.14 root 4378: fixup_gotos (0, 0, 0, get_insns (), 0); 1.1 root 4379: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.