1 /* Decompose multiword subregs.
2 Copyright (C) 2007 Free Software Foundation, Inc.
3 Contributed by Richard Henderson <rth@redhat.com>
4 Ian Lance Taylor <iant@google.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "coretypes.h"
32 #include "insn-config.h"
34 #include "basic-block.h"
39 #include "tree-pass.h"
41 #ifdef STACK_GROWS_DOWNWARD
42 # undef STACK_GROWS_DOWNWARD
43 # define STACK_GROWS_DOWNWARD 1
45 # define STACK_GROWS_DOWNWARD 0
49 DEF_VEC_ALLOC_P (bitmap
,heap
);
51 /* Decompose multi-word pseudo-registers into individual
52 pseudo-registers when possible. This is possible when all the uses
53 of a multi-word register are via SUBREG, or are copies of the
54 register to another location. Breaking apart the register permits
55 more CSE and permits better register allocation. */
57 /* Bit N in this bitmap is set if regno N is used in a context in
58 which we can decompose it. */
59 static bitmap decomposable_context
;
61 /* Bit N in this bitmap is set if regno N is used in a context in
62 which it can not be decomposed. */
63 static bitmap non_decomposable_context
;
65 /* Bit N in the bitmap in element M of this array is set if there is a
66 copy from reg M to reg N. */
67 static VEC(bitmap
,heap
) *reg_copy_graph
;
69 /* Return whether X is a simple object which we can take a word_mode
73 simple_move_operand (rtx x
)
75 if (GET_CODE (x
) == SUBREG
)
81 if (GET_CODE (x
) == LABEL_REF
82 || GET_CODE (x
) == SYMBOL_REF
83 || GET_CODE (x
) == HIGH
)
87 && (MEM_VOLATILE_P (x
)
88 || mode_dependent_address_p (XEXP (x
, 0))))
94 /* If INSN is a single set between two objects, return the single set.
95 Such an insn can always be decomposed. INSN should have been
96 passed to recog and extract_insn before this is called. */
99 simple_move (rtx insn
)
103 enum machine_mode mode
;
105 if (recog_data
.n_operands
!= 2)
108 set
= single_set (insn
);
113 if (x
!= recog_data
.operand
[0] && x
!= recog_data
.operand
[1])
115 if (!simple_move_operand (x
))
119 if (x
!= recog_data
.operand
[0] && x
!= recog_data
.operand
[1])
121 /* For the src we can handle ASM_OPERANDS, and it is beneficial for
122 things like x86 rdtsc which returns a DImode value. */
123 if (GET_CODE (x
) != ASM_OPERANDS
124 && !simple_move_operand (x
))
127 /* We try to decompose in integer modes, to avoid generating
128 inefficient code copying between integer and floating point
129 registers. That means that we can't decompose if this is a
130 non-integer mode for which there is no integer mode of the same
132 mode
= GET_MODE (SET_SRC (set
));
133 if (!SCALAR_INT_MODE_P (mode
)
134 && (mode_for_size (GET_MODE_SIZE (mode
) * BITS_PER_UNIT
, MODE_INT
, 0)
141 /* If SET is a copy from one multi-word pseudo-register to another,
142 record that in reg_copy_graph. Return whether it is such a
146 find_pseudo_copy (rtx set
)
148 rtx dest
= SET_DEST (set
);
149 rtx src
= SET_SRC (set
);
153 if (!REG_P (dest
) || !REG_P (src
))
158 if (HARD_REGISTER_NUM_P (rd
) || HARD_REGISTER_NUM_P (rs
))
161 if (GET_MODE_SIZE (GET_MODE (dest
)) <= UNITS_PER_WORD
)
164 b
= VEC_index (bitmap
, reg_copy_graph
, rs
);
167 b
= BITMAP_ALLOC (NULL
);
168 VEC_replace (bitmap
, reg_copy_graph
, rs
, b
);
171 bitmap_set_bit (b
, rd
);
176 /* Look through the registers in DECOMPOSABLE_CONTEXT. For each case
177 where they are copied to another register, add the register to
178 which they are copied to DECOMPOSABLE_CONTEXT. Use
179 NON_DECOMPOSABLE_CONTEXT to limit this--we don't bother to track
180 copies of registers which are in NON_DECOMPOSABLE_CONTEXT. */
183 propagate_pseudo_copies (void)
185 bitmap queue
, propagate
;
187 queue
= BITMAP_ALLOC (NULL
);
188 propagate
= BITMAP_ALLOC (NULL
);
190 bitmap_copy (queue
, decomposable_context
);
193 bitmap_iterator iter
;
196 bitmap_clear (propagate
);
198 EXECUTE_IF_SET_IN_BITMAP (queue
, 0, i
, iter
)
200 bitmap b
= VEC_index (bitmap
, reg_copy_graph
, i
);
202 bitmap_ior_and_compl_into (propagate
, b
, non_decomposable_context
);
205 bitmap_and_compl (queue
, propagate
, decomposable_context
);
206 bitmap_ior_into (decomposable_context
, propagate
);
208 while (!bitmap_empty_p (queue
));
211 BITMAP_FREE (propagate
);
214 /* A pointer to one of these values is passed to
215 find_decomposable_subregs via for_each_rtx. */
217 enum classify_move_insn
219 /* Not a simple move from one location to another. */
221 /* A simple move from one pseudo-register to another with no
223 SIMPLE_PSEUDO_REG_MOVE
,
224 /* A simple move involving a non-pseudo-register, or from one
225 pseudo-register to another with a REG_RETVAL note. */
229 /* This is called via for_each_rtx. If we find a SUBREG which we
230 could use to decompose a pseudo-register, set a bit in
231 DECOMPOSABLE_CONTEXT. If we find an unadorned register which is
232 not a simple pseudo-register copy, DATA will point at the type of
233 move, and we set a bit in DECOMPOSABLE_CONTEXT or
234 NON_DECOMPOSABLE_CONTEXT as appropriate. */
237 find_decomposable_subregs (rtx
*px
, void *data
)
239 enum classify_move_insn
*pcmi
= (enum classify_move_insn
*) data
;
245 if (GET_CODE (x
) == SUBREG
)
247 rtx inner
= SUBREG_REG (x
);
248 unsigned int regno
, outer_size
, inner_size
, outer_words
, inner_words
;
253 regno
= REGNO (inner
);
254 if (HARD_REGISTER_NUM_P (regno
))
257 outer_size
= GET_MODE_SIZE (GET_MODE (x
));
258 inner_size
= GET_MODE_SIZE (GET_MODE (inner
));
259 outer_words
= (outer_size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
260 inner_words
= (inner_size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
262 /* We only try to decompose single word subregs of multi-word
263 registers. When we find one, we return -1 to avoid iterating
264 over the inner register.
266 ??? This doesn't allow, e.g., DImode subregs of TImode values
267 on 32-bit targets. We would need to record the way the
268 pseudo-register was used, and only decompose if all the uses
269 were the same number and size of pieces. Hopefully this
270 doesn't happen much. */
272 if (outer_words
== 1 && inner_words
> 1)
274 bitmap_set_bit (decomposable_context
, regno
);
282 /* We will see an outer SUBREG before we see the inner REG, so
283 when we see a plain REG here it means a direct reference to
286 If this is not a simple copy from one location to another,
287 then we can not decompose this register. If this is a simple
288 copy from one pseudo-register to another, with no REG_RETVAL
289 note, and the mode is right, then we mark the register as
290 decomposable. Otherwise we don't say anything about this
291 register--it could be decomposed, but whether that would be
292 profitable depends upon how it is used elsewhere.
294 We only set bits in the bitmap for multi-word
295 pseudo-registers, since those are the only ones we care about
296 and it keeps the size of the bitmaps down. */
299 if (!HARD_REGISTER_NUM_P (regno
)
300 && GET_MODE_SIZE (GET_MODE (x
)) > UNITS_PER_WORD
)
304 case NOT_SIMPLE_MOVE
:
305 bitmap_set_bit (non_decomposable_context
, regno
);
307 case SIMPLE_PSEUDO_REG_MOVE
:
308 if (MODES_TIEABLE_P (GET_MODE (x
), word_mode
))
309 bitmap_set_bit (decomposable_context
, regno
);
320 enum classify_move_insn cmi_mem
= NOT_SIMPLE_MOVE
;
322 /* Any registers used in a MEM do not participate in a
323 SIMPLE_MOVE or SIMPLE_PSEUDO_REG_MOVE. Do our own recursion
324 here, and return -1 to block the parent's recursion. */
325 for_each_rtx (&XEXP (x
, 0), find_decomposable_subregs
, &cmi_mem
);
332 /* Decompose REGNO into word-sized components. We smash the REG node
333 in place. This ensures that (1) something goes wrong quickly if we
334 fail to make some replacement, and (2) the debug information inside
335 the symbol table is automatically kept up to date. */
338 decompose_register (unsigned int regno
)
341 unsigned int words
, i
;
344 reg
= regno_reg_rtx
[regno
];
346 regno_reg_rtx
[regno
] = NULL_RTX
;
347 clear_reg_info_regno (regno
);
349 words
= GET_MODE_SIZE (GET_MODE (reg
));
350 words
= (words
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
352 v
= rtvec_alloc (words
);
353 for (i
= 0; i
< words
; ++i
)
354 RTVEC_ELT (v
, i
) = gen_reg_rtx_offset (reg
, word_mode
, i
* UNITS_PER_WORD
);
356 PUT_CODE (reg
, CONCATN
);
361 fprintf (dump_file
, "; Splitting reg %u ->", regno
);
362 for (i
= 0; i
< words
; ++i
)
363 fprintf (dump_file
, " %u", REGNO (XVECEXP (reg
, 0, i
)));
364 fputc ('\n', dump_file
);
368 /* Get a SUBREG of a CONCATN. */
371 simplify_subreg_concatn (enum machine_mode outermode
, rtx op
,
374 unsigned int inner_size
;
375 enum machine_mode innermode
;
377 unsigned int final_offset
;
379 gcc_assert (GET_CODE (op
) == CONCATN
);
380 gcc_assert (byte
% GET_MODE_SIZE (outermode
) == 0);
382 innermode
= GET_MODE (op
);
383 gcc_assert (byte
< GET_MODE_SIZE (innermode
));
384 gcc_assert (GET_MODE_SIZE (outermode
) <= GET_MODE_SIZE (innermode
));
386 inner_size
= GET_MODE_SIZE (innermode
) / XVECLEN (op
, 0);
387 part
= XVECEXP (op
, 0, byte
/ inner_size
);
388 final_offset
= byte
% inner_size
;
389 if (final_offset
+ GET_MODE_SIZE (outermode
) > inner_size
)
392 return simplify_gen_subreg (outermode
, part
, GET_MODE (part
), final_offset
);
395 /* Wrapper around simplify_gen_subreg which handles CONCATN. */
398 simplify_gen_subreg_concatn (enum machine_mode outermode
, rtx op
,
399 enum machine_mode innermode
, unsigned int byte
)
403 /* We have to handle generating a SUBREG of a SUBREG of a CONCATN.
404 If OP is a SUBREG of a CONCATN, then it must be a simple mode
405 change with the same size and offset 0, or it must extract a
406 part. We shouldn't see anything else here. */
407 if (GET_CODE (op
) == SUBREG
&& GET_CODE (SUBREG_REG (op
)) == CONCATN
)
411 if ((GET_MODE_SIZE (GET_MODE (op
))
412 == GET_MODE_SIZE (GET_MODE (SUBREG_REG (op
))))
413 && SUBREG_BYTE (op
) == 0)
414 return simplify_gen_subreg_concatn (outermode
, SUBREG_REG (op
),
415 GET_MODE (SUBREG_REG (op
)), byte
);
417 op2
= simplify_subreg_concatn (GET_MODE (op
), SUBREG_REG (op
),
421 /* We don't handle paradoxical subregs here. */
422 gcc_assert (GET_MODE_SIZE (outermode
)
423 <= GET_MODE_SIZE (GET_MODE (op
)));
424 gcc_assert (GET_MODE_SIZE (GET_MODE (op
))
425 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (op
))));
426 op2
= simplify_subreg_concatn (outermode
, SUBREG_REG (op
),
427 byte
+ SUBREG_BYTE (op
));
428 gcc_assert (op2
!= NULL_RTX
);
433 gcc_assert (op
!= NULL_RTX
);
434 gcc_assert (innermode
== GET_MODE (op
));
437 if (GET_CODE (op
) == CONCATN
)
438 return simplify_subreg_concatn (outermode
, op
, byte
);
440 ret
= simplify_gen_subreg (outermode
, op
, innermode
, byte
);
442 /* If we see an insn like (set (reg:DI) (subreg:DI (reg:SI) 0)) then
443 resolve_simple_move will ask for the high part of the paradoxical
444 subreg, which does not have a value. Just return a zero. */
446 && GET_CODE (op
) == SUBREG
447 && SUBREG_BYTE (op
) == 0
448 && (GET_MODE_SIZE (innermode
)
449 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op
)))))
450 return CONST0_RTX (outermode
);
452 gcc_assert (ret
!= NULL_RTX
);
456 /* Return whether we should resolve X into the registers into which it
460 resolve_reg_p (rtx x
)
462 return GET_CODE (x
) == CONCATN
;
465 /* Return whether X is a SUBREG of a register which we need to
469 resolve_subreg_p (rtx x
)
471 if (GET_CODE (x
) != SUBREG
)
473 return resolve_reg_p (SUBREG_REG (x
));
476 /* This is called via for_each_rtx. Look for SUBREGs which need to be
480 resolve_subreg_use (rtx
*px
, void *data
)
482 rtx insn
= (rtx
) data
;
488 if (resolve_subreg_p (x
))
490 x
= simplify_subreg_concatn (GET_MODE (x
), SUBREG_REG (x
),
493 /* It is possible for a note to contain a reference which we can
494 decompose. In this case, return 1 to the caller to indicate
495 that the note must be removed. */
502 validate_change (insn
, px
, x
, 1);
506 if (resolve_reg_p (x
))
508 /* Return 1 to the caller to indicate that we found a direct
509 reference to a register which is being decomposed. This can
510 happen inside notes. */
518 /* If there is a REG_LIBCALL note on OLD_START, move it to NEW_START,
519 and link the corresponding REG_RETVAL note to NEW_START. */
522 move_libcall_note (rtx old_start
, rtx new_start
)
524 rtx note0
, note1
, end
;
526 note0
= find_reg_note (old_start
, REG_LIBCALL
, NULL
);
527 if (note0
== NULL_RTX
)
530 remove_note (old_start
, note0
);
531 end
= XEXP (note0
, 0);
532 note1
= find_reg_note (end
, REG_RETVAL
, NULL
);
534 XEXP (note0
, 1) = REG_NOTES (new_start
);
535 REG_NOTES (new_start
) = note0
;
536 XEXP (note1
, 0) = new_start
;
539 /* Remove any REG_RETVAL note, the corresponding REG_LIBCALL note, and
540 any markers for a no-conflict block. We have decomposed the
541 registers so the non-conflict is now obvious. */
544 remove_retval_note (rtx insn1
)
546 rtx note0
, insn0
, note1
, insn
;
548 note1
= find_reg_note (insn1
, REG_RETVAL
, NULL
);
549 if (note1
== NULL_RTX
)
552 insn0
= XEXP (note1
, 0);
553 note0
= find_reg_note (insn0
, REG_LIBCALL
, NULL
);
555 remove_note (insn0
, note0
);
556 remove_note (insn1
, note1
);
558 for (insn
= insn0
; insn
!= insn1
; insn
= NEXT_INSN (insn
))
564 note
= find_reg_note (insn
, REG_NO_CONFLICT
, NULL
);
565 if (note
== NULL_RTX
)
567 remove_note (insn
, note
);
572 /* Resolve any decomposed registers which appear in register notes on
576 resolve_reg_notes (rtx insn
)
580 note
= find_reg_equal_equiv_note (insn
);
583 if (for_each_rtx (&XEXP (note
, 0), resolve_subreg_use
, NULL
))
585 remove_note (insn
, note
);
586 remove_retval_note (insn
);
590 pnote
= ®_NOTES (insn
);
591 while (*pnote
!= NULL_RTX
)
596 switch (REG_NOTE_KIND (note
))
598 case REG_NO_CONFLICT
:
599 if (resolve_reg_p (XEXP (note
, 0)))
608 *pnote
= XEXP (note
, 1);
610 pnote
= &XEXP (note
, 1);
614 /* Return whether X can be decomposed into subwords. */
617 can_decompose_p (rtx x
)
621 unsigned int regno
= REGNO (x
);
623 if (HARD_REGISTER_NUM_P (regno
))
624 return (validate_subreg (word_mode
, GET_MODE (x
), x
, UNITS_PER_WORD
)
625 && HARD_REGNO_MODE_OK (regno
, word_mode
));
627 return !bitmap_bit_p (non_decomposable_context
, regno
);
633 /* Decompose the registers used in a simple move SET within INSN. If
634 we don't change anything, return INSN, otherwise return the start
635 of the sequence of moves. */
638 resolve_simple_move (rtx set
, rtx insn
)
640 rtx src
, dest
, real_dest
, insns
;
641 enum machine_mode orig_mode
, dest_mode
;
646 dest
= SET_DEST (set
);
647 orig_mode
= GET_MODE (dest
);
649 words
= (GET_MODE_SIZE (orig_mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
655 /* We have to handle copying from a SUBREG of a decomposed reg where
656 the SUBREG is larger than word size. Rather than assume that we
657 can take a word_mode SUBREG of the destination, we copy to a new
658 register and then copy that to the destination. */
660 real_dest
= NULL_RTX
;
662 if (GET_CODE (src
) == SUBREG
663 && resolve_reg_p (SUBREG_REG (src
))
664 && (SUBREG_BYTE (src
) != 0
665 || (GET_MODE_SIZE (orig_mode
)
666 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (src
))))))
669 dest
= gen_reg_rtx (orig_mode
);
670 if (REG_P (real_dest
))
671 REG_ATTRS (dest
) = REG_ATTRS (real_dest
);
674 /* Similarly if we are copying to a SUBREG of a decomposed reg where
675 the SUBREG is larger than word size. */
677 if (GET_CODE (dest
) == SUBREG
678 && resolve_reg_p (SUBREG_REG (dest
))
679 && (SUBREG_BYTE (dest
) != 0
680 || (GET_MODE_SIZE (orig_mode
)
681 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
))))))
683 rtx reg
, minsn
, smove
;
685 reg
= gen_reg_rtx (orig_mode
);
686 minsn
= emit_move_insn (reg
, src
);
687 smove
= single_set (minsn
);
688 gcc_assert (smove
!= NULL_RTX
);
689 resolve_simple_move (smove
, minsn
);
693 /* If we didn't have any big SUBREGS of decomposed registers, and
694 neither side of the move is a register we are decomposing, then
695 we don't have to do anything here. */
697 if (src
== SET_SRC (set
)
698 && dest
== SET_DEST (set
)
699 && !resolve_reg_p (src
)
700 && !resolve_subreg_p (src
)
701 && !resolve_reg_p (dest
)
702 && !resolve_subreg_p (dest
))
708 /* If SRC is a register which we can't decompose, or has side
709 effects, we need to move via a temporary register. */
711 if (!can_decompose_p (src
)
712 || side_effects_p (src
)
713 || GET_CODE (src
) == ASM_OPERANDS
)
717 reg
= gen_reg_rtx (orig_mode
);
718 emit_move_insn (reg
, src
);
722 /* If DEST is a register which we can't decompose, or has side
723 effects, we need to first move to a temporary register. We
724 handle the common case of pushing an operand directly. We also
725 go through a temporary register if it holds a floating point
726 value. This gives us better code on systems which can't move
727 data easily between integer and floating point registers. */
729 dest_mode
= orig_mode
;
730 pushing
= push_operand (dest
, dest_mode
);
731 if (!can_decompose_p (dest
)
732 || (side_effects_p (dest
) && !pushing
)
733 || (!SCALAR_INT_MODE_P (dest_mode
)
734 && !resolve_reg_p (dest
)
735 && !resolve_subreg_p (dest
)))
737 if (real_dest
== NULL_RTX
)
739 if (!SCALAR_INT_MODE_P (dest_mode
))
741 dest_mode
= mode_for_size (GET_MODE_SIZE (dest_mode
) * BITS_PER_UNIT
,
743 gcc_assert (dest_mode
!= BLKmode
);
745 dest
= gen_reg_rtx (dest_mode
);
746 if (REG_P (real_dest
))
747 REG_ATTRS (dest
) = REG_ATTRS (real_dest
);
752 unsigned int i
, j
, jinc
;
754 gcc_assert (GET_MODE_SIZE (orig_mode
) % UNITS_PER_WORD
== 0);
755 gcc_assert (GET_CODE (XEXP (dest
, 0)) != PRE_MODIFY
);
756 gcc_assert (GET_CODE (XEXP (dest
, 0)) != POST_MODIFY
);
758 if (WORDS_BIG_ENDIAN
== STACK_GROWS_DOWNWARD
)
769 for (i
= 0; i
< words
; ++i
, j
+= jinc
)
773 temp
= copy_rtx (XEXP (dest
, 0));
774 temp
= adjust_automodify_address_nv (dest
, word_mode
, temp
,
776 emit_move_insn (temp
,
777 simplify_gen_subreg_concatn (word_mode
, src
,
779 j
* UNITS_PER_WORD
));
786 if (REG_P (dest
) && !HARD_REGISTER_NUM_P (REGNO (dest
)))
787 emit_insn (gen_rtx_CLOBBER (VOIDmode
, dest
));
789 for (i
= 0; i
< words
; ++i
)
790 emit_move_insn (simplify_gen_subreg_concatn (word_mode
, dest
,
793 simplify_gen_subreg_concatn (word_mode
, src
,
795 i
* UNITS_PER_WORD
));
798 if (real_dest
!= NULL_RTX
)
800 rtx mdest
, minsn
, smove
;
802 if (dest_mode
== orig_mode
)
805 mdest
= simplify_gen_subreg (orig_mode
, dest
, GET_MODE (dest
), 0);
806 minsn
= emit_move_insn (real_dest
, mdest
);
808 smove
= single_set (minsn
);
809 gcc_assert (smove
!= NULL_RTX
);
811 resolve_simple_move (smove
, minsn
);
814 insns
= get_insns ();
817 emit_insn_before (insns
, insn
);
819 move_libcall_note (insn
, insns
);
820 remove_retval_note (insn
);
826 /* Change a CLOBBER of a decomposed register into a CLOBBER of the
827 component registers. Return whether we changed something. */
830 resolve_clobber (rtx pat
, rtx insn
)
833 enum machine_mode orig_mode
;
834 unsigned int words
, i
;
837 if (!resolve_reg_p (reg
) && !resolve_subreg_p (reg
))
840 orig_mode
= GET_MODE (reg
);
841 words
= GET_MODE_SIZE (orig_mode
);
842 words
= (words
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
844 XEXP (pat
, 0) = simplify_gen_subreg_concatn (word_mode
, reg
, orig_mode
, 0);
845 for (i
= words
- 1; i
> 0; --i
)
849 x
= simplify_gen_subreg_concatn (word_mode
, reg
, orig_mode
,
851 x
= gen_rtx_CLOBBER (VOIDmode
, x
);
852 emit_insn_after (x
, insn
);
858 /* A USE of a decomposed register is no longer meaningful. Return
859 whether we changed something. */
862 resolve_use (rtx pat
, rtx insn
)
864 if (resolve_reg_p (XEXP (pat
, 0)) || resolve_subreg_p (XEXP (pat
, 0)))
872 /* Look for registers which are always accessed via word-sized SUBREGs
873 or via copies. Decompose these registers into several word-sized
877 decompose_multiword_subregs (bool update_life
)
882 max
= max_reg_num ();
884 /* First see if there are any multi-word pseudo-registers. If there
885 aren't, there is nothing we can do. This should speed up this
886 pass in the normal case, since it should be faster than scanning
891 for (i
= FIRST_PSEUDO_REGISTER
; i
< max
; ++i
)
893 if (regno_reg_rtx
[i
] != NULL
894 && GET_MODE_SIZE (GET_MODE (regno_reg_rtx
[i
])) > UNITS_PER_WORD
)
901 /* FIXME: When the dataflow branch is merged, we can change this
902 code to look for each multi-word pseudo-register and to find each
903 insn which sets or uses that register. That should be faster
904 than scanning all the insns. */
906 decomposable_context
= BITMAP_ALLOC (NULL
);
907 non_decomposable_context
= BITMAP_ALLOC (NULL
);
909 reg_copy_graph
= VEC_alloc (bitmap
, heap
, max
);
910 VEC_safe_grow (bitmap
, heap
, reg_copy_graph
, max
);
911 memset (VEC_address (bitmap
, reg_copy_graph
), 0, sizeof (bitmap
) * max
);
917 FOR_BB_INSNS (bb
, insn
)
920 enum classify_move_insn cmi
;
924 || GET_CODE (PATTERN (insn
)) == CLOBBER
925 || GET_CODE (PATTERN (insn
)) == USE
)
928 recog_memoized (insn
);
931 set
= simple_move (insn
);
934 cmi
= NOT_SIMPLE_MOVE
;
939 retval
= find_reg_note (insn
, REG_RETVAL
, NULL_RTX
) != NULL_RTX
;
941 if (find_pseudo_copy (set
) && !retval
)
942 cmi
= SIMPLE_PSEUDO_REG_MOVE
;
944 && REG_P (SET_SRC (set
))
945 && HARD_REGISTER_P (SET_SRC (set
)))
949 /* We don't want to decompose an assignment which
950 copies the value returned by a libcall to a
951 pseudo-register. Doing that will lose the RETVAL
952 note with no real gain. */
953 cmi
= NOT_SIMPLE_MOVE
;
955 /* If we have a RETVAL note, there should be an
956 EQUAL note. We don't want to decompose any
957 registers which that EQUAL note refers to
958 directly. If we do, we will no longer know the
959 value of the libcall. */
960 note
= find_reg_equal_equiv_note (insn
);
961 if (note
!= NULL_RTX
)
962 for_each_rtx (&XEXP (note
, 0), find_decomposable_subregs
,
969 n
= recog_data
.n_operands
;
970 for (i
= 0; i
< n
; ++i
)
972 for_each_rtx (&recog_data
.operand
[i
],
973 find_decomposable_subregs
,
976 /* We handle ASM_OPERANDS as a special case to support
977 things like x86 rdtsc which returns a DImode value.
978 We can decompose the output, which will certainly be
979 operand 0, but not the inputs. */
981 if (cmi
== SIMPLE_MOVE
982 && GET_CODE (SET_SRC (set
)) == ASM_OPERANDS
)
985 cmi
= NOT_SIMPLE_MOVE
;
991 bitmap_and_compl_into (decomposable_context
, non_decomposable_context
);
992 if (!bitmap_empty_p (decomposable_context
))
994 int hold_no_new_pseudos
= no_new_pseudos
;
995 int max_regno
= max_reg_num ();
997 bitmap_iterator iter
;
1000 propagate_pseudo_copies ();
1003 blocks
= sbitmap_alloc (last_basic_block
);
1004 sbitmap_zero (blocks
);
1006 EXECUTE_IF_SET_IN_BITMAP (decomposable_context
, 0, regno
, iter
)
1007 decompose_register (regno
);
1013 FOR_BB_INSNS (bb
, insn
)
1021 next
= NEXT_INSN (insn
);
1024 pat
= PATTERN (insn
);
1025 if (GET_CODE (pat
) == CLOBBER
)
1027 if (resolve_clobber (pat
, insn
))
1030 else if (GET_CODE (pat
) == USE
)
1032 if (resolve_use (pat
, insn
))
1040 recog_memoized (insn
);
1041 extract_insn (insn
);
1043 set
= simple_move (insn
);
1046 rtx orig_insn
= insn
;
1048 insn
= resolve_simple_move (set
, insn
);
1049 if (insn
!= orig_insn
)
1053 recog_memoized (insn
);
1054 extract_insn (insn
);
1058 for (i
= recog_data
.n_operands
- 1; i
>= 0; --i
)
1059 for_each_rtx (recog_data
.operand_loc
[i
],
1063 resolve_reg_notes (insn
);
1065 if (num_validated_changes () > 0)
1067 for (i
= recog_data
.n_dups
- 1; i
>= 0; --i
)
1069 rtx
*pl
= recog_data
.dup_loc
[i
];
1070 int dup_num
= recog_data
.dup_num
[i
];
1071 rtx
*px
= recog_data
.operand_loc
[dup_num
];
1073 validate_change (insn
, pl
, *px
, 1);
1076 i
= apply_change_group ();
1085 SET_BIT (blocks
, bb
->index
);
1086 reg_scan_update (insn
, next
, max_regno
);
1091 no_new_pseudos
= hold_no_new_pseudos
;
1094 update_life_info (blocks
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
1097 sbitmap_free (blocks
);
1104 for (i
= 0; VEC_iterate (bitmap
, reg_copy_graph
, i
, b
); ++i
)
1109 VEC_free (bitmap
, heap
, reg_copy_graph
);
1111 BITMAP_FREE (decomposable_context
);
1112 BITMAP_FREE (non_decomposable_context
);
1115 /* Gate function for lower subreg pass. */
1118 gate_handle_lower_subreg (void)
1120 return flag_split_wide_types
!= 0;
1123 /* Implement first lower subreg pass. */
1126 rest_of_handle_lower_subreg (void)
1128 decompose_multiword_subregs (false);
1132 /* Implement second lower subreg pass. */
1135 rest_of_handle_lower_subreg2 (void)
1137 decompose_multiword_subregs (true);
1141 struct tree_opt_pass pass_lower_subreg
=
1143 "subreg", /* name */
1144 gate_handle_lower_subreg
, /* gate */
1145 rest_of_handle_lower_subreg
, /* execute */
1148 0, /* static_pass_number */
1149 TV_LOWER_SUBREG
, /* tv_id */
1150 0, /* properties_required */
1151 0, /* properties_provided */
1152 0, /* properties_destroyed */
1153 0, /* todo_flags_start */
1155 TODO_ggc_collect
, /* todo_flags_finish */
1159 struct tree_opt_pass pass_lower_subreg2
=
1161 "subreg2", /* name */
1162 gate_handle_lower_subreg
, /* gate */
1163 rest_of_handle_lower_subreg2
, /* execute */
1166 0, /* static_pass_number */
1167 TV_LOWER_SUBREG
, /* tv_id */
1168 0, /* properties_required */
1169 0, /* properties_provided */
1170 0, /* properties_destroyed */
1171 0, /* todo_flags_start */
1173 TODO_ggc_collect
, /* todo_flags_finish */