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