xref: /dflybsd-src/contrib/gcc-4.7/gcc/rtlhooks.c (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* Generic hooks for the RTL middle-end.
2*e4b17023SJohn Marino    Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
3*e4b17023SJohn Marino 
4*e4b17023SJohn Marino This file is part of GCC.
5*e4b17023SJohn Marino 
6*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
7*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
8*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
9*e4b17023SJohn Marino version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14*e4b17023SJohn Marino for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
17*e4b17023SJohn Marino along with GCC; see the file COPYING3.  If not see
18*e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino #include "config.h"
21*e4b17023SJohn Marino #include "system.h"
22*e4b17023SJohn Marino #include "coretypes.h"
23*e4b17023SJohn Marino #include "tm.h"
24*e4b17023SJohn Marino #include "rtl.h"
25*e4b17023SJohn Marino #include "rtlhooks-def.h"
26*e4b17023SJohn Marino #include "expr.h"
27*e4b17023SJohn Marino #include "recog.h"
28*e4b17023SJohn Marino 
29*e4b17023SJohn Marino 
30*e4b17023SJohn Marino /* For speed, we will copy the RTX hooks struct member-by-member
31*e4b17023SJohn Marino    instead of doing indirect calls.  For these reason, we initialize
32*e4b17023SJohn Marino    *two* struct rtl_hooks globals: rtl_hooks is the one that is used
33*e4b17023SJohn Marino    to actually call the hooks, while general_rtl_hooks is used
34*e4b17023SJohn Marino    to restore the hooks by passes that modify them.  */
35*e4b17023SJohn Marino 
36*e4b17023SJohn Marino const struct rtl_hooks general_rtl_hooks = RTL_HOOKS_INITIALIZER;
37*e4b17023SJohn Marino struct rtl_hooks rtl_hooks = RTL_HOOKS_INITIALIZER;
38*e4b17023SJohn Marino 
39*e4b17023SJohn Marino rtx
gen_lowpart_general(enum machine_mode mode,rtx x)40*e4b17023SJohn Marino gen_lowpart_general (enum machine_mode mode, rtx x)
41*e4b17023SJohn Marino {
42*e4b17023SJohn Marino   rtx result = gen_lowpart_common (mode, x);
43*e4b17023SJohn Marino 
44*e4b17023SJohn Marino   if (result)
45*e4b17023SJohn Marino     return result;
46*e4b17023SJohn Marino   /* Handle SUBREGs and hard REGs that were rejected by
47*e4b17023SJohn Marino      simplify_gen_subreg.  */
48*e4b17023SJohn Marino   else if (REG_P (x) || GET_CODE (x) == SUBREG)
49*e4b17023SJohn Marino     {
50*e4b17023SJohn Marino       result = gen_lowpart_common (mode, copy_to_reg (x));
51*e4b17023SJohn Marino       gcc_assert (result != 0);
52*e4b17023SJohn Marino       return result;
53*e4b17023SJohn Marino     }
54*e4b17023SJohn Marino   else
55*e4b17023SJohn Marino     {
56*e4b17023SJohn Marino       int offset = 0;
57*e4b17023SJohn Marino 
58*e4b17023SJohn Marino       /* The only additional case we can do is MEM.  */
59*e4b17023SJohn Marino       gcc_assert (MEM_P (x));
60*e4b17023SJohn Marino 
61*e4b17023SJohn Marino       /* The following exposes the use of "x" to CSE.  */
62*e4b17023SJohn Marino       if (GET_MODE_SIZE (GET_MODE (x)) <= UNITS_PER_WORD
63*e4b17023SJohn Marino 	  && SCALAR_INT_MODE_P (GET_MODE (x))
64*e4b17023SJohn Marino 	  && TRULY_NOOP_TRUNCATION_MODES_P (mode, GET_MODE (x))
65*e4b17023SJohn Marino 	  && !reload_completed)
66*e4b17023SJohn Marino 	return gen_lowpart_general (mode, force_reg (GET_MODE (x), x));
67*e4b17023SJohn Marino 
68*e4b17023SJohn Marino       if (WORDS_BIG_ENDIAN)
69*e4b17023SJohn Marino 	offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
70*e4b17023SJohn Marino 		  - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
71*e4b17023SJohn Marino 
72*e4b17023SJohn Marino       if (BYTES_BIG_ENDIAN)
73*e4b17023SJohn Marino 	/* Adjust the address so that the address-after-the-data
74*e4b17023SJohn Marino 	   is unchanged.  */
75*e4b17023SJohn Marino 	offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
76*e4b17023SJohn Marino 		   - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
77*e4b17023SJohn Marino 
78*e4b17023SJohn Marino       return adjust_address (x, mode, offset);
79*e4b17023SJohn Marino     }
80*e4b17023SJohn Marino }
81*e4b17023SJohn Marino 
82*e4b17023SJohn Marino /* Similar to gen_lowpart, but cannot emit any instruction via
83*e4b17023SJohn Marino    copy_to_reg or force_reg.  Mainly used in simplify-rtx.c.  */
84*e4b17023SJohn Marino rtx
gen_lowpart_no_emit_general(enum machine_mode mode,rtx x)85*e4b17023SJohn Marino gen_lowpart_no_emit_general (enum machine_mode mode, rtx x)
86*e4b17023SJohn Marino {
87*e4b17023SJohn Marino   rtx result = gen_lowpart_if_possible (mode, x);
88*e4b17023SJohn Marino   if (result)
89*e4b17023SJohn Marino     return result;
90*e4b17023SJohn Marino   else
91*e4b17023SJohn Marino     return x;
92*e4b17023SJohn Marino }
93*e4b17023SJohn Marino 
94*e4b17023SJohn Marino rtx
reg_num_sign_bit_copies_general(const_rtx x ATTRIBUTE_UNUSED,enum machine_mode mode ATTRIBUTE_UNUSED,const_rtx known_x ATTRIBUTE_UNUSED,enum machine_mode known_mode ATTRIBUTE_UNUSED,unsigned int known_ret ATTRIBUTE_UNUSED,unsigned int * result ATTRIBUTE_UNUSED)95*e4b17023SJohn Marino reg_num_sign_bit_copies_general (const_rtx x ATTRIBUTE_UNUSED,
96*e4b17023SJohn Marino 				 enum machine_mode mode ATTRIBUTE_UNUSED,
97*e4b17023SJohn Marino                                  const_rtx known_x ATTRIBUTE_UNUSED,
98*e4b17023SJohn Marino 				 enum machine_mode known_mode ATTRIBUTE_UNUSED,
99*e4b17023SJohn Marino                                  unsigned int known_ret ATTRIBUTE_UNUSED,
100*e4b17023SJohn Marino                                  unsigned int *result ATTRIBUTE_UNUSED)
101*e4b17023SJohn Marino {
102*e4b17023SJohn Marino   return NULL;
103*e4b17023SJohn Marino }
104*e4b17023SJohn Marino 
105*e4b17023SJohn Marino rtx
reg_nonzero_bits_general(const_rtx x ATTRIBUTE_UNUSED,enum machine_mode mode ATTRIBUTE_UNUSED,const_rtx known_x ATTRIBUTE_UNUSED,enum machine_mode known_mode ATTRIBUTE_UNUSED,unsigned HOST_WIDE_INT known_ret ATTRIBUTE_UNUSED,unsigned HOST_WIDE_INT * nonzero ATTRIBUTE_UNUSED)106*e4b17023SJohn Marino reg_nonzero_bits_general (const_rtx x ATTRIBUTE_UNUSED,
107*e4b17023SJohn Marino 			  enum machine_mode mode ATTRIBUTE_UNUSED,
108*e4b17023SJohn Marino 			  const_rtx known_x ATTRIBUTE_UNUSED,
109*e4b17023SJohn Marino                           enum machine_mode known_mode ATTRIBUTE_UNUSED,
110*e4b17023SJohn Marino                           unsigned HOST_WIDE_INT known_ret ATTRIBUTE_UNUSED,
111*e4b17023SJohn Marino                           unsigned HOST_WIDE_INT *nonzero ATTRIBUTE_UNUSED)
112*e4b17023SJohn Marino {
113*e4b17023SJohn Marino   return NULL;
114*e4b17023SJohn Marino }
115*e4b17023SJohn Marino 
116*e4b17023SJohn Marino bool
reg_truncated_to_mode_general(enum machine_mode mode ATTRIBUTE_UNUSED,const_rtx x ATTRIBUTE_UNUSED)117*e4b17023SJohn Marino reg_truncated_to_mode_general (enum machine_mode mode ATTRIBUTE_UNUSED,
118*e4b17023SJohn Marino 			       const_rtx x ATTRIBUTE_UNUSED)
119*e4b17023SJohn Marino {
120*e4b17023SJohn Marino   return false;
121*e4b17023SJohn Marino }
122*e4b17023SJohn Marino 
123*e4b17023SJohn Marino /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a fixed-point
124*e4b17023SJohn Marino    number, return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
125*e4b17023SJohn Marino    least-significant part of X.
126*e4b17023SJohn Marino    MODE specifies how big a part of X to return.
127*e4b17023SJohn Marino 
128*e4b17023SJohn Marino    If the requested operation cannot be done, 0 is returned.
129*e4b17023SJohn Marino 
130*e4b17023SJohn Marino    This is similar to gen_lowpart_general.  */
131*e4b17023SJohn Marino 
132*e4b17023SJohn Marino rtx
gen_lowpart_if_possible(enum machine_mode mode,rtx x)133*e4b17023SJohn Marino gen_lowpart_if_possible (enum machine_mode mode, rtx x)
134*e4b17023SJohn Marino {
135*e4b17023SJohn Marino   rtx result = gen_lowpart_common (mode, x);
136*e4b17023SJohn Marino 
137*e4b17023SJohn Marino   if (result)
138*e4b17023SJohn Marino     return result;
139*e4b17023SJohn Marino   else if (MEM_P (x))
140*e4b17023SJohn Marino     {
141*e4b17023SJohn Marino       /* This is the only other case we handle.  */
142*e4b17023SJohn Marino       int offset = 0;
143*e4b17023SJohn Marino       rtx new_rtx;
144*e4b17023SJohn Marino 
145*e4b17023SJohn Marino       if (WORDS_BIG_ENDIAN)
146*e4b17023SJohn Marino 	offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
147*e4b17023SJohn Marino 		  - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
148*e4b17023SJohn Marino       if (BYTES_BIG_ENDIAN)
149*e4b17023SJohn Marino 	/* Adjust the address so that the address-after-the-data is
150*e4b17023SJohn Marino 	   unchanged.  */
151*e4b17023SJohn Marino 	offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
152*e4b17023SJohn Marino 		   - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
153*e4b17023SJohn Marino 
154*e4b17023SJohn Marino       new_rtx = adjust_address_nv (x, mode, offset);
155*e4b17023SJohn Marino       if (! memory_address_addr_space_p (mode, XEXP (new_rtx, 0),
156*e4b17023SJohn Marino 					 MEM_ADDR_SPACE (x)))
157*e4b17023SJohn Marino 	return 0;
158*e4b17023SJohn Marino 
159*e4b17023SJohn Marino       return new_rtx;
160*e4b17023SJohn Marino     }
161*e4b17023SJohn Marino   else if (mode != GET_MODE (x) && GET_MODE (x) != VOIDmode
162*e4b17023SJohn Marino 	   && validate_subreg (mode, GET_MODE (x), x,
163*e4b17023SJohn Marino 			        subreg_lowpart_offset (mode, GET_MODE (x))))
164*e4b17023SJohn Marino     return gen_lowpart_SUBREG (mode, x);
165*e4b17023SJohn Marino   else
166*e4b17023SJohn Marino     return 0;
167*e4b17023SJohn Marino }
168*e4b17023SJohn Marino 
169