-/* Convert register usage from "flat" register file usage to a "stack
- register file. FIRST is the first insn in the function, FILE is the
- dump file, if used.
-
- Construct a CFG and run life analysis. Then convert each insn one
- by one. Run a last cleanup_cfg pass, if optimizing, to eliminate
- code duplication created when the converter inserts pop insns on
- the edges. */
-
-bool
-reg_to_stack (rtx first, FILE *file)
-{
- basic_block bb;
- int i;
- int max_uid;
-
- /* Clean up previous run. */
- stack_regs_mentioned_data = 0;
-
- /* See if there is something to do. Flow analysis is quite
- expensive so we might save some compilation time. */
- for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
- if (regs_ever_live[i])
- break;
- if (i > LAST_STACK_REG)
- return false;
-
- /* Ok, floating point instructions exist. If not optimizing,
- build the CFG and run life analysis.
- Also need to rebuild life when superblock scheduling is done
- as it don't update liveness yet. */
- if (!optimize
- || (flag_sched2_use_superblocks
- && flag_schedule_insns_after_reload))
- {
- count_or_remove_death_notes (NULL, 1);
- life_analysis (first, file, PROP_DEATH_NOTES);
- }
- mark_dfs_back_edges ();
-
- /* Set up block info for each basic block. */
- alloc_aux_for_blocks (sizeof (struct block_info_def));
- FOR_EACH_BB_REVERSE (bb)
- {
- edge e;
- for (e = bb->pred; e; e = e->pred_next)
- if (!(e->flags & EDGE_DFS_BACK)
- && e->src != ENTRY_BLOCK_PTR)
- BLOCK_INFO (bb)->predecessors++;
- }
-
- /* Create the replacement registers up front. */
- for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
- {
- enum machine_mode mode;
- for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
- mode != VOIDmode;
- mode = GET_MODE_WIDER_MODE (mode))
- FP_MODE_REG (i, mode) = gen_rtx_REG (mode, i);
- for (mode = GET_CLASS_NARROWEST_MODE (MODE_COMPLEX_FLOAT);
- mode != VOIDmode;
- mode = GET_MODE_WIDER_MODE (mode))
- FP_MODE_REG (i, mode) = gen_rtx_REG (mode, i);
- }
-
- ix86_flags_rtx = gen_rtx_REG (CCmode, FLAGS_REG);
-
- /* A QNaN for initializing uninitialized variables.
-
- ??? We can't load from constant memory in PIC mode, because
- we're inserting these instructions before the prologue and
- the PIC register hasn't been set up. In that case, fall back
- on zero, which we can get from `ldz'. */
-
- if (flag_pic)
- nan = CONST0_RTX (SFmode);
- else
- {
- nan = gen_lowpart (SFmode, GEN_INT (0x7fc00000));
- nan = force_const_mem (SFmode, nan);
- }
-
- /* Allocate a cache for stack_regs_mentioned. */
- max_uid = get_max_uid ();
- VARRAY_CHAR_INIT (stack_regs_mentioned_data, max_uid + 1,
- "stack_regs_mentioned cache");
-
- convert_regs (file);
-
- free_aux_for_blocks ();
- return true;
-}
-\f
-/* Check PAT, which is in INSN, for LABEL_REFs. Add INSN to the
- label's chain of references, and note which insn contains each
- reference. */
-
-static void
-record_label_references (rtx insn, rtx pat)
-{
- enum rtx_code code = GET_CODE (pat);
- int i;
- const char *fmt;
-
- if (code == LABEL_REF)
- {
- rtx label = XEXP (pat, 0);
- rtx ref;
-
- if (GET_CODE (label) != CODE_LABEL)
- abort ();
-
- /* If this is an undefined label, LABEL_REFS (label) contains
- garbage. */
- if (INSN_UID (label) == 0)
- return;
-
- /* Don't make a duplicate in the code_label's chain. */
-
- for (ref = LABEL_REFS (label);
- ref && ref != label;
- ref = LABEL_NEXTREF (ref))
- if (CONTAINING_INSN (ref) == insn)
- return;
-
- CONTAINING_INSN (pat) = insn;
- LABEL_NEXTREF (pat) = LABEL_REFS (label);
- LABEL_REFS (label) = pat;
-
- return;
- }
-
- fmt = GET_RTX_FORMAT (code);
- for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
- {
- if (fmt[i] == 'e')
- record_label_references (insn, XEXP (pat, i));
- if (fmt[i] == 'E')
- {
- int j;
- for (j = 0; j < XVECLEN (pat, i); j++)
- record_label_references (insn, XVECEXP (pat, i, j));
- }
- }
-}
-\f