1 1.1 mrg /* Machine description patterns for PowerPC running Darwin (Mac OS X). 2 1.12 mrg Copyright (C) 2004-2022 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.11 mrg ;; Mach-O PIC. 125 1.1 mrg 126 1.11 mrg (define_insn "@macho_high_<mode>" 127 1.11 mrg [(set (match_operand:P 0 "gpc_reg_operand" "=b*r") 128 1.11 mrg (high:P (match_operand 1 "" "")))] 129 1.11 mrg "TARGET_MACHO && (DEFAULT_ABI == ABI_DARWIN) && !flag_pic" 130 1.3 mrg "lis %0,ha16(%1)") 131 1.1 mrg 132 1.11 mrg (define_insn "@macho_low_<mode>" 133 1.11 mrg [(set (match_operand:P 0 "gpc_reg_operand" "=r") 134 1.11 mrg (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b") 135 1.1 mrg (match_operand 2 "" "")))] 136 1.11 mrg "TARGET_MACHO && (DEFAULT_ABI == ABI_DARWIN) && !flag_pic" 137 1.5 mrg "la %0,lo16(%2)(%1)") 138 1.1 mrg 139 1.11 mrg (define_insn "@machopic_high_<mode>" 140 1.11 mrg [(set (match_operand:P 0 "gpc_reg_operand" "=b*r") 141 1.11 mrg (high:P (match_operand 1 "macho_pic_address" "")))] 142 1.11 mrg "TARGET_MACHO && flag_pic" 143 1.11 mrg "lis %0,ha16(%1)") 144 1.11 mrg 145 1.11 mrg (define_insn "@machopic_low_<mode>" 146 1.11 mrg [(set (match_operand:P 0 "gpc_reg_operand" "=r") 147 1.11 mrg (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b") 148 1.11 mrg (match_operand 2 "macho_pic_address" "")))] 149 1.11 mrg "TARGET_MACHO && flag_pic" 150 1.5 mrg "la %0,lo16(%2)(%1)") 151 1.1 mrg 152 1.1 mrg (define_split 153 1.9 mrg [(set (mem:V4SI (plus:DI (match_operand:DI 0 "gpc_reg_operand") 154 1.9 mrg (match_operand:DI 1 "short_cint_operand"))) 155 1.9 mrg (match_operand:V4SI 2 "register_operand")) 156 1.9 mrg (clobber (match_operand:DI 3 "gpc_reg_operand"))] 157 1.1 mrg "TARGET_MACHO && TARGET_64BIT" 158 1.1 mrg [(set (match_dup 3) (plus:DI (match_dup 0) (match_dup 1))) 159 1.1 mrg (set (mem:V4SI (match_dup 3)) 160 1.1 mrg (match_dup 2))] 161 1.1 mrg "") 162 1.1 mrg 163 1.11 mrg (define_insn "@macho_correct_pic_<mode>" 164 1.11 mrg [(set (match_operand:P 0 "gpc_reg_operand" "=r") 165 1.11 mrg (plus:P (match_operand:P 1 "gpc_reg_operand" "r") 166 1.11 mrg (unspec:P [(match_operand:P 2 "immediate_operand" "s") 167 1.11 mrg (match_operand:P 3 "immediate_operand" "s")] 168 1.11 mrg UNSPEC_MPIC_CORRECT)))] 169 1.11 mrg "DEFAULT_ABI == ABI_DARWIN" 170 1.11 mrg "addis %0,%1,ha16(%2-%3)\n\taddi %0,%0,lo16(%2-%3)" 171 1.11 mrg [(set_attr "length" "8")]) 172 1.1 mrg 173 1.11 mrg (define_insn "@load_macho_picbase_<mode>" 174 1.11 mrg [(set (reg:P LR_REGNO) 175 1.11 mrg (unspec:P [(match_operand:P 0 "immediate_operand" "s") 176 1.1 mrg (pc)] UNSPEC_LD_MPIC))] 177 1.1 mrg "(DEFAULT_ABI == ABI_DARWIN) && flag_pic" 178 1.5 mrg { 179 1.5 mrg #if TARGET_MACHO 180 1.5 mrg machopic_should_output_picbase_label (); /* Update for new func. */ 181 1.5 mrg #else 182 1.5 mrg gcc_unreachable (); 183 1.5 mrg #endif 184 1.9 mrg return "bcl 20,31,%0\n%0:"; 185 1.5 mrg } 186 1.1 mrg [(set_attr "type" "branch") 187 1.10 mrg (set_attr "cannot_copy" "yes")]) 188 1.1 mrg 189 1.11 mrg (define_insn "@reload_macho_picbase_<mode>" 190 1.11 mrg [(set (reg:P LR_REGNO) 191 1.11 mrg (unspec:P [(match_operand:P 0 "immediate_operand" "s") 192 1.5 mrg (pc)] UNSPEC_RELD_MPIC))] 193 1.5 mrg "(DEFAULT_ABI == ABI_DARWIN) && flag_pic" 194 1.5 mrg { 195 1.5 mrg #if TARGET_MACHO 196 1.5 mrg if (machopic_should_output_picbase_label ()) 197 1.5 mrg { 198 1.5 mrg static char tmp[64]; 199 1.5 mrg const char *cnam = machopic_get_function_picbase (); 200 1.9 mrg snprintf (tmp, 64, "bcl 20,31,%s\n%s:\n%%0:", cnam, cnam); 201 1.5 mrg return tmp; 202 1.5 mrg } 203 1.5 mrg else 204 1.5 mrg #else 205 1.5 mrg gcc_unreachable (); 206 1.5 mrg #endif 207 1.9 mrg return "bcl 20,31,%0\n%0:"; 208 1.5 mrg } 209 1.5 mrg [(set_attr "type" "branch") 210 1.10 mrg (set_attr "cannot_copy" "yes")]) 211 1.5 mrg 212 1.5 mrg ;; We need to restore the PIC register, at the site of nonlocal label. 213 1.5 mrg 214 1.5 mrg (define_insn_and_split "nonlocal_goto_receiver" 215 1.5 mrg [(unspec_volatile [(const_int 0)] UNSPECV_NLGR)] 216 1.5 mrg "TARGET_MACHO && flag_pic" 217 1.5 mrg "#" 218 1.5 mrg "&& reload_completed" 219 1.5 mrg [(const_int 0)] 220 1.5 mrg { 221 1.5 mrg #if TARGET_MACHO 222 1.5 mrg if (crtl->uses_pic_offset_table) 223 1.5 mrg { 224 1.5 mrg static unsigned n = 0; 225 1.5 mrg rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME); 226 1.5 mrg rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); 227 1.5 mrg rtx tmplrtx; 228 1.5 mrg char tmplab[20]; 229 1.5 mrg 230 1.5 mrg ASM_GENERATE_INTERNAL_LABEL(tmplab, "Lnlgr", ++n); 231 1.5 mrg tmplrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab)); 232 1.5 mrg 233 1.11 mrg emit_insn (gen_reload_macho_picbase (Pmode, tmplrtx)); 234 1.5 mrg emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO)); 235 1.11 mrg emit_insn (gen_macho_correct_pic (Pmode, picreg, picreg, 236 1.11 mrg picrtx, tmplrtx)); 237 1.5 mrg } 238 1.5 mrg else 239 1.5 mrg /* Not using PIC reg, no reload needed. */ 240 1.5 mrg emit_note (NOTE_INSN_DELETED); 241 1.5 mrg #else 242 1.5 mrg gcc_unreachable (); 243 1.5 mrg #endif 244 1.5 mrg DONE; 245 1.5 mrg }) 246