darwin.md revision 1.10 1 1.1 mrg /* Machine description patterns for PowerPC running Darwin (Mac OS X).
2 1.10 mrg Copyright (C) 2004-2019 Free Software Foundation, Inc.
3 1.1 mrg Contributed by Apple Computer Inc.
4 1.1 mrg
5 1.1 mrg This file is part of GCC.
6 1.1 mrg
7 1.1 mrg GNU CC is free software; you can redistribute it and/or modify
8 1.1 mrg it under the terms of the GNU General Public License as published by
9 1.1 mrg the Free Software Foundation; either version 3, or (at your option)
10 1.1 mrg any later version.
11 1.1 mrg
12 1.1 mrg GNU CC is distributed in the hope that it will be useful,
13 1.1 mrg but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 mrg GNU General Public License for more details.
16 1.1 mrg
17 1.1 mrg You should have received a copy of the GNU General Public License
18 1.1 mrg ;; along with GCC; see the file COPYING3. If not see
19 1.1 mrg ;; <http://www.gnu.org/licenses/>. */
20 1.1 mrg
21 1.1 mrg (define_insn "adddi3_high"
22 1.1 mrg [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
23 1.1 mrg (plus:DI (match_operand:DI 1 "gpc_reg_operand" "b")
24 1.1 mrg (high:DI (match_operand 2 "" ""))))]
25 1.1 mrg "TARGET_MACHO && TARGET_64BIT"
26 1.10 mrg "addis %0,%1,ha16(%2)")
27 1.1 mrg
28 1.1 mrg (define_insn "movdf_low_si"
29 1.1 mrg [(set (match_operand:DF 0 "gpc_reg_operand" "=f,!r")
30 1.1 mrg (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
31 1.1 mrg (match_operand 2 "" ""))))]
32 1.9 mrg "TARGET_MACHO && TARGET_HARD_FLOAT && !TARGET_64BIT"
33 1.1 mrg {
34 1.1 mrg switch (which_alternative)
35 1.1 mrg {
36 1.1 mrg case 0:
37 1.9 mrg return "lfd %0,lo16(%2)(%1)";
38 1.1 mrg case 1:
39 1.1 mrg {
40 1.1 mrg if (TARGET_POWERPC64 && TARGET_32BIT)
41 1.1 mrg /* Note, old assemblers didn't support relocation here. */
42 1.9 mrg return "ld %0,lo16(%2)(%1)";
43 1.1 mrg else
44 1.1 mrg {
45 1.9 mrg output_asm_insn ("la %0,lo16(%2)(%1)", operands);
46 1.9 mrg output_asm_insn ("lwz %L0,4(%0)", operands);
47 1.9 mrg return ("lwz %0,0(%0)");
48 1.1 mrg }
49 1.1 mrg }
50 1.1 mrg default:
51 1.1 mrg gcc_unreachable ();
52 1.1 mrg }
53 1.9 mrg }
54 1.1 mrg [(set_attr "type" "load")
55 1.1 mrg (set_attr "length" "4,12")])
56 1.1 mrg
57 1.1 mrg
58 1.1 mrg (define_insn "movdf_low_di"
59 1.1 mrg [(set (match_operand:DF 0 "gpc_reg_operand" "=f,!r")
60 1.1 mrg (mem:DF (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b,b")
61 1.1 mrg (match_operand 2 "" ""))))]
62 1.9 mrg "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_64BIT"
63 1.10 mrg "@
64 1.10 mrg lfd %0,lo16(%2)(%1)
65 1.10 mrg ld %0,lo16(%2)(%1)"
66 1.10 mrg [(set_attr "type" "load")])
67 1.1 mrg
68 1.1 mrg (define_insn "movdf_low_st_si"
69 1.1 mrg [(set (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
70 1.1 mrg (match_operand 2 "" "")))
71 1.1 mrg (match_operand:DF 0 "gpc_reg_operand" "f"))]
72 1.9 mrg "TARGET_MACHO && TARGET_HARD_FLOAT && ! TARGET_64BIT"
73 1.1 mrg "stfd %0,lo16(%2)(%1)"
74 1.10 mrg [(set_attr "type" "store")])
75 1.1 mrg
76 1.1 mrg (define_insn "movdf_low_st_di"
77 1.1 mrg [(set (mem:DF (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b")
78 1.1 mrg (match_operand 2 "" "")))
79 1.1 mrg (match_operand:DF 0 "gpc_reg_operand" "f"))]
80 1.9 mrg "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_64BIT"
81 1.1 mrg "stfd %0,lo16(%2)(%1)"
82 1.10 mrg [(set_attr "type" "store")])
83 1.1 mrg
84 1.1 mrg (define_insn "movsf_low_si"
85 1.1 mrg [(set (match_operand:SF 0 "gpc_reg_operand" "=f,!r")
86 1.1 mrg (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
87 1.1 mrg (match_operand 2 "" ""))))]
88 1.9 mrg "TARGET_MACHO && TARGET_HARD_FLOAT && ! TARGET_64BIT"
89 1.1 mrg "@
90 1.1 mrg lfs %0,lo16(%2)(%1)
91 1.3 mrg lwz %0,lo16(%2)(%1)"
92 1.10 mrg [(set_attr "type" "load")])
93 1.1 mrg
94 1.1 mrg (define_insn "movsf_low_di"
95 1.1 mrg [(set (match_operand:SF 0 "gpc_reg_operand" "=f,!r")
96 1.1 mrg (mem:SF (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b,b")
97 1.1 mrg (match_operand 2 "" ""))))]
98 1.9 mrg "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_64BIT"
99 1.1 mrg "@
100 1.1 mrg lfs %0,lo16(%2)(%1)
101 1.3 mrg lwz %0,lo16(%2)(%1)"
102 1.10 mrg [(set_attr "type" "load")])
103 1.1 mrg
104 1.1 mrg (define_insn "movsf_low_st_si"
105 1.1 mrg [(set (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
106 1.1 mrg (match_operand 2 "" "")))
107 1.1 mrg (match_operand:SF 0 "gpc_reg_operand" "f,!r"))]
108 1.9 mrg "TARGET_MACHO && TARGET_HARD_FLOAT && ! TARGET_64BIT"
109 1.1 mrg "@
110 1.1 mrg stfs %0,lo16(%2)(%1)
111 1.3 mrg stw %0,lo16(%2)(%1)"
112 1.10 mrg [(set_attr "type" "store")])
113 1.1 mrg
114 1.1 mrg (define_insn "movsf_low_st_di"
115 1.1 mrg [(set (mem:SF (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b,b")
116 1.1 mrg (match_operand 2 "" "")))
117 1.1 mrg (match_operand:SF 0 "gpc_reg_operand" "f,!r"))]
118 1.9 mrg "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_64BIT"
119 1.1 mrg "@
120 1.1 mrg stfs %0,lo16(%2)(%1)
121 1.3 mrg stw %0,lo16(%2)(%1)"
122 1.10 mrg [(set_attr "type" "store")])
123 1.10 mrg
124 1.10 mrg ;; 64-bit MachO load/store support
125 1.1 mrg
126 1.1 mrg ;; Mach-O PIC trickery.
127 1.1 mrg (define_expand "macho_high"
128 1.9 mrg [(set (match_operand 0 "")
129 1.9 mrg (high (match_operand 1 "")))]
130 1.1 mrg "TARGET_MACHO"
131 1.1 mrg {
132 1.1 mrg if (TARGET_64BIT)
133 1.1 mrg emit_insn (gen_macho_high_di (operands[0], operands[1]));
134 1.1 mrg else
135 1.1 mrg emit_insn (gen_macho_high_si (operands[0], operands[1]));
136 1.1 mrg
137 1.1 mrg DONE;
138 1.1 mrg })
139 1.1 mrg
140 1.1 mrg (define_insn "macho_high_si"
141 1.1 mrg [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
142 1.1 mrg (high:SI (match_operand 1 "" "")))]
143 1.1 mrg "TARGET_MACHO && ! TARGET_64BIT"
144 1.3 mrg "lis %0,ha16(%1)")
145 1.1 mrg
146 1.1 mrg
147 1.1 mrg (define_insn "macho_high_di"
148 1.1 mrg [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
149 1.1 mrg (high:DI (match_operand 1 "" "")))]
150 1.1 mrg "TARGET_MACHO && TARGET_64BIT"
151 1.3 mrg "lis %0,ha16(%1)")
152 1.1 mrg
153 1.1 mrg (define_expand "macho_low"
154 1.9 mrg [(set (match_operand 0 "")
155 1.9 mrg (lo_sum (match_operand 1 "")
156 1.9 mrg (match_operand 2 "")))]
157 1.1 mrg "TARGET_MACHO"
158 1.1 mrg {
159 1.1 mrg if (TARGET_64BIT)
160 1.1 mrg emit_insn (gen_macho_low_di (operands[0], operands[1], operands[2]));
161 1.1 mrg else
162 1.1 mrg emit_insn (gen_macho_low_si (operands[0], operands[1], operands[2]));
163 1.1 mrg
164 1.1 mrg DONE;
165 1.1 mrg })
166 1.1 mrg
167 1.1 mrg (define_insn "macho_low_si"
168 1.5 mrg [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
169 1.5 mrg (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
170 1.1 mrg (match_operand 2 "" "")))]
171 1.1 mrg "TARGET_MACHO && ! TARGET_64BIT"
172 1.5 mrg "la %0,lo16(%2)(%1)")
173 1.1 mrg
174 1.1 mrg (define_insn "macho_low_di"
175 1.5 mrg [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
176 1.5 mrg (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b")
177 1.1 mrg (match_operand 2 "" "")))]
178 1.1 mrg "TARGET_MACHO && TARGET_64BIT"
179 1.5 mrg "la %0,lo16(%2)(%1)")
180 1.1 mrg
181 1.1 mrg (define_split
182 1.9 mrg [(set (mem:V4SI (plus:DI (match_operand:DI 0 "gpc_reg_operand")
183 1.9 mrg (match_operand:DI 1 "short_cint_operand")))
184 1.9 mrg (match_operand:V4SI 2 "register_operand"))
185 1.9 mrg (clobber (match_operand:DI 3 "gpc_reg_operand"))]
186 1.1 mrg "TARGET_MACHO && TARGET_64BIT"
187 1.1 mrg [(set (match_dup 3) (plus:DI (match_dup 0) (match_dup 1)))
188 1.1 mrg (set (mem:V4SI (match_dup 3))
189 1.1 mrg (match_dup 2))]
190 1.1 mrg "")
191 1.1 mrg
192 1.1 mrg (define_expand "load_macho_picbase"
193 1.8 mrg [(set (reg:SI LR_REGNO)
194 1.9 mrg (unspec [(match_operand 0 "")]
195 1.1 mrg UNSPEC_LD_MPIC))]
196 1.1 mrg "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
197 1.1 mrg {
198 1.1 mrg if (TARGET_32BIT)
199 1.1 mrg emit_insn (gen_load_macho_picbase_si (operands[0]));
200 1.1 mrg else
201 1.1 mrg emit_insn (gen_load_macho_picbase_di (operands[0]));
202 1.1 mrg
203 1.1 mrg DONE;
204 1.1 mrg })
205 1.1 mrg
206 1.1 mrg (define_insn "load_macho_picbase_si"
207 1.8 mrg [(set (reg:SI LR_REGNO)
208 1.1 mrg (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
209 1.1 mrg (pc)] UNSPEC_LD_MPIC))]
210 1.1 mrg "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
211 1.5 mrg {
212 1.5 mrg #if TARGET_MACHO
213 1.5 mrg machopic_should_output_picbase_label (); /* Update for new func. */
214 1.5 mrg #else
215 1.5 mrg gcc_unreachable ();
216 1.5 mrg #endif
217 1.9 mrg return "bcl 20,31,%0\n%0:";
218 1.5 mrg }
219 1.1 mrg [(set_attr "type" "branch")
220 1.10 mrg (set_attr "cannot_copy" "yes")])
221 1.1 mrg
222 1.1 mrg (define_insn "load_macho_picbase_di"
223 1.8 mrg [(set (reg:DI LR_REGNO)
224 1.1 mrg (unspec:DI [(match_operand:DI 0 "immediate_operand" "s")
225 1.1 mrg (pc)] UNSPEC_LD_MPIC))]
226 1.1 mrg "(DEFAULT_ABI == ABI_DARWIN) && flag_pic && TARGET_64BIT"
227 1.5 mrg {
228 1.5 mrg #if TARGET_MACHO
229 1.5 mrg machopic_should_output_picbase_label (); /* Update for new func. */
230 1.5 mrg #else
231 1.5 mrg gcc_unreachable ();
232 1.5 mrg #endif
233 1.9 mrg return "bcl 20,31,%0\n%0:";
234 1.5 mrg }
235 1.1 mrg [(set_attr "type" "branch")
236 1.10 mrg (set_attr "cannot_copy" "yes")])
237 1.1 mrg
238 1.1 mrg (define_expand "macho_correct_pic"
239 1.9 mrg [(set (match_operand 0 "")
240 1.9 mrg (plus (match_operand 1 "")
241 1.9 mrg (unspec [(match_operand 2 "")
242 1.9 mrg (match_operand 3 "")]
243 1.1 mrg UNSPEC_MPIC_CORRECT)))]
244 1.1 mrg "DEFAULT_ABI == ABI_DARWIN"
245 1.1 mrg {
246 1.1 mrg if (TARGET_32BIT)
247 1.1 mrg emit_insn (gen_macho_correct_pic_si (operands[0], operands[1], operands[2],
248 1.1 mrg operands[3]));
249 1.1 mrg else
250 1.1 mrg emit_insn (gen_macho_correct_pic_di (operands[0], operands[1], operands[2],
251 1.1 mrg operands[3]));
252 1.1 mrg
253 1.1 mrg DONE;
254 1.1 mrg })
255 1.1 mrg
256 1.1 mrg (define_insn "macho_correct_pic_si"
257 1.1 mrg [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
258 1.1 mrg (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
259 1.1 mrg (unspec:SI [(match_operand:SI 2 "immediate_operand" "s")
260 1.1 mrg (match_operand:SI 3 "immediate_operand" "s")]
261 1.1 mrg UNSPEC_MPIC_CORRECT)))]
262 1.1 mrg "DEFAULT_ABI == ABI_DARWIN"
263 1.1 mrg "addis %0,%1,ha16(%2-%3)\n\taddi %0,%0,lo16(%2-%3)"
264 1.1 mrg [(set_attr "length" "8")])
265 1.1 mrg
266 1.1 mrg (define_insn "macho_correct_pic_di"
267 1.1 mrg [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
268 1.1 mrg (plus:DI (match_operand:DI 1 "gpc_reg_operand" "r")
269 1.1 mrg (unspec:DI [(match_operand:DI 2 "immediate_operand" "s")
270 1.1 mrg (match_operand:DI 3 "immediate_operand" "s")]
271 1.1 mrg 16)))]
272 1.1 mrg "DEFAULT_ABI == ABI_DARWIN && TARGET_64BIT"
273 1.1 mrg "addis %0,%1,ha16(%2-%3)\n\taddi %0,%0,lo16(%2-%3)"
274 1.1 mrg [(set_attr "length" "8")])
275 1.1 mrg
276 1.5 mrg (define_expand "reload_macho_picbase"
277 1.8 mrg [(set (reg:SI LR_REGNO)
278 1.9 mrg (unspec [(match_operand 0 "")]
279 1.5 mrg UNSPEC_RELD_MPIC))]
280 1.5 mrg "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
281 1.5 mrg {
282 1.5 mrg if (TARGET_32BIT)
283 1.5 mrg emit_insn (gen_reload_macho_picbase_si (operands[0]));
284 1.5 mrg else
285 1.5 mrg emit_insn (gen_reload_macho_picbase_di (operands[0]));
286 1.5 mrg
287 1.5 mrg DONE;
288 1.5 mrg })
289 1.5 mrg
290 1.5 mrg (define_insn "reload_macho_picbase_si"
291 1.8 mrg [(set (reg:SI LR_REGNO)
292 1.5 mrg (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
293 1.5 mrg (pc)] UNSPEC_RELD_MPIC))]
294 1.5 mrg "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
295 1.5 mrg {
296 1.5 mrg #if TARGET_MACHO
297 1.5 mrg if (machopic_should_output_picbase_label ())
298 1.5 mrg {
299 1.5 mrg static char tmp[64];
300 1.5 mrg const char *cnam = machopic_get_function_picbase ();
301 1.9 mrg snprintf (tmp, 64, "bcl 20,31,%s\n%s:\n%%0:", cnam, cnam);
302 1.5 mrg return tmp;
303 1.5 mrg }
304 1.5 mrg else
305 1.5 mrg #else
306 1.5 mrg gcc_unreachable ();
307 1.5 mrg #endif
308 1.9 mrg return "bcl 20,31,%0\n%0:";
309 1.5 mrg }
310 1.5 mrg [(set_attr "type" "branch")
311 1.10 mrg (set_attr "cannot_copy" "yes")])
312 1.5 mrg
313 1.5 mrg (define_insn "reload_macho_picbase_di"
314 1.8 mrg [(set (reg:DI LR_REGNO)
315 1.5 mrg (unspec:DI [(match_operand:DI 0 "immediate_operand" "s")
316 1.5 mrg (pc)] UNSPEC_RELD_MPIC))]
317 1.5 mrg "(DEFAULT_ABI == ABI_DARWIN) && flag_pic && TARGET_64BIT"
318 1.5 mrg {
319 1.5 mrg #if TARGET_MACHO
320 1.5 mrg if (machopic_should_output_picbase_label ())
321 1.5 mrg {
322 1.5 mrg static char tmp[64];
323 1.5 mrg const char *cnam = machopic_get_function_picbase ();
324 1.9 mrg snprintf (tmp, 64, "bcl 20,31,%s\n%s:\n%%0:", cnam, cnam);
325 1.5 mrg return tmp;
326 1.5 mrg }
327 1.5 mrg else
328 1.5 mrg #else
329 1.5 mrg gcc_unreachable ();
330 1.5 mrg #endif
331 1.9 mrg return "bcl 20,31,%0\n%0:";
332 1.5 mrg }
333 1.5 mrg [(set_attr "type" "branch")
334 1.10 mrg (set_attr "cannot_copy" "yes")])
335 1.5 mrg
336 1.5 mrg ;; We need to restore the PIC register, at the site of nonlocal label.
337 1.5 mrg
338 1.5 mrg (define_insn_and_split "nonlocal_goto_receiver"
339 1.5 mrg [(unspec_volatile [(const_int 0)] UNSPECV_NLGR)]
340 1.5 mrg "TARGET_MACHO && flag_pic"
341 1.5 mrg "#"
342 1.5 mrg "&& reload_completed"
343 1.5 mrg [(const_int 0)]
344 1.5 mrg {
345 1.5 mrg #if TARGET_MACHO
346 1.5 mrg if (crtl->uses_pic_offset_table)
347 1.5 mrg {
348 1.5 mrg static unsigned n = 0;
349 1.5 mrg rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
350 1.5 mrg rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
351 1.5 mrg rtx tmplrtx;
352 1.5 mrg char tmplab[20];
353 1.5 mrg
354 1.5 mrg ASM_GENERATE_INTERNAL_LABEL(tmplab, "Lnlgr", ++n);
355 1.5 mrg tmplrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
356 1.5 mrg
357 1.5 mrg emit_insn (gen_reload_macho_picbase (tmplrtx));
358 1.5 mrg emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
359 1.5 mrg emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplrtx));
360 1.5 mrg }
361 1.5 mrg else
362 1.5 mrg /* Not using PIC reg, no reload needed. */
363 1.5 mrg emit_note (NOTE_INSN_DELETED);
364 1.5 mrg #else
365 1.5 mrg gcc_unreachable ();
366 1.5 mrg #endif
367 1.5 mrg DONE;
368 1.5 mrg })
369