1 1.1 mrg /* Subroutines used for code generation of Andes NDS32 cpu for GNU compiler 2 1.1 mrg Copyright (C) 2012-2022 Free Software Foundation, Inc. 3 1.1 mrg Contributed by Andes Technology Corporation. 4 1.1 mrg 5 1.1 mrg This file is part of GCC. 6 1.1 mrg 7 1.1 mrg GCC is free software; you can redistribute it and/or modify it 8 1.1 mrg under the terms of the GNU General Public License as published 9 1.1 mrg by the Free Software Foundation; either version 3, or (at your 10 1.1 mrg option) any later version. 11 1.1 mrg 12 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT 13 1.1 mrg ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 1.1 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 15 1.1 mrg 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 /* ------------------------------------------------------------------------ */ 22 1.1 mrg 23 1.1 mrg #define IN_TARGET_CODE 1 24 1.1 mrg 25 1.1 mrg #include "config.h" 26 1.1 mrg #include "system.h" 27 1.1 mrg #include "coretypes.h" 28 1.1 mrg #include "backend.h" 29 1.1 mrg #include "target.h" 30 1.1 mrg #include "rtl.h" 31 1.1 mrg #include "tree.h" 32 1.1 mrg #include "tree-pass.h" 33 1.1 mrg #include "stringpool.h" 34 1.1 mrg #include "attribs.h" 35 1.1 mrg #include "df.h" 36 1.1 mrg #include "memmodel.h" 37 1.1 mrg #include "tm_p.h" 38 1.1 mrg #include "optabs.h" /* For GEN_FCN. */ 39 1.1 mrg #include "regs.h" 40 1.1 mrg #include "emit-rtl.h" 41 1.1 mrg #include "recog.h" 42 1.1 mrg #include "diagnostic-core.h" 43 1.1 mrg #include "stor-layout.h" 44 1.1 mrg #include "varasm.h" 45 1.1 mrg #include "calls.h" 46 1.1 mrg #include "output.h" 47 1.1 mrg #include "explow.h" 48 1.1 mrg #include "expr.h" 49 1.1 mrg #include "tm-constrs.h" 50 1.1 mrg #include "builtins.h" 51 1.1 mrg #include "cpplib.h" 52 1.1 mrg #include "context.h" 53 1.1 mrg 54 1.1 mrg /* This file should be included last. */ 55 1.1 mrg #include "target-def.h" 56 1.1 mrg 57 1.1 mrg /* ------------------------------------------------------------------------ */ 58 1.1 mrg 59 1.1 mrg /* This file is divided into five parts: 60 1.1 mrg 61 1.1 mrg PART 1: Auxiliary static variable definitions and 62 1.1 mrg target hook static variable definitions. 63 1.1 mrg 64 1.1 mrg PART 2: Auxiliary static function definitions. 65 1.1 mrg 66 1.1 mrg PART 3: Implement target hook stuff definitions. 67 1.1 mrg 68 1.1 mrg PART 4: Implemet extern function definitions, 69 1.1 mrg the prototype is in nds32-protos.h. 70 1.1 mrg 71 1.1 mrg PART 5: Initialize target hook structure and definitions. */ 72 1.1 mrg 73 1.1 mrg /* ------------------------------------------------------------------------ */ 74 1.1 mrg 75 1.1 mrg /* PART 1: Auxiliary static variable definitions and 76 1.1 mrg target hook static variable definitions. */ 77 1.1 mrg 78 1.1 mrg /* Define intrinsic register names. 79 1.1 mrg Please refer to nds32_intrinsic.h file, the index is corresponding to 80 1.1 mrg 'enum nds32_intrinsic_registers' data type values. 81 1.1 mrg NOTE that the base value starting from 1024. */ 82 1.1 mrg static const char * const nds32_intrinsic_register_names[] = 83 1.1 mrg { 84 1.1 mrg "$CPU_VER", 85 1.1 mrg "$ICM_CFG", 86 1.1 mrg "$DCM_CFG", 87 1.1 mrg "$MMU_CFG", 88 1.1 mrg "$MSC_CFG", 89 1.1 mrg "$MSC_CFG2", 90 1.1 mrg "$CORE_ID", 91 1.1 mrg "$FUCOP_EXIST", 92 1.1 mrg 93 1.1 mrg "$PSW", 94 1.1 mrg "$IPSW", 95 1.1 mrg "$P_IPSW", 96 1.1 mrg "$IVB", 97 1.1 mrg "$EVA", 98 1.1 mrg "$P_EVA", 99 1.1 mrg "$ITYPE", 100 1.1 mrg "$P_ITYPE", 101 1.1 mrg 102 1.1 mrg "$MERR", 103 1.1 mrg "$IPC", 104 1.1 mrg "$P_IPC", 105 1.1 mrg "$OIPC", 106 1.1 mrg "$P_P0", 107 1.1 mrg "$P_P1", 108 1.1 mrg 109 1.1 mrg "$INT_MASK", 110 1.1 mrg "$INT_MASK2", 111 1.1 mrg "$INT_MASK3", 112 1.1 mrg "$INT_PEND", 113 1.1 mrg "$INT_PEND2", 114 1.1 mrg "$INT_PEND3", 115 1.1 mrg "$SP_USR", 116 1.1 mrg "$SP_PRIV", 117 1.1 mrg "$INT_PRI", 118 1.1 mrg "$INT_PRI2", 119 1.1 mrg "$INT_PRI3", 120 1.1 mrg "$INT_PRI4", 121 1.1 mrg "$INT_CTRL", 122 1.1 mrg "$INT_TRIGGER", 123 1.1 mrg "$INT_TRIGGER2", 124 1.1 mrg "$INT_GPR_PUSH_DIS", 125 1.1 mrg 126 1.1 mrg "$MMU_CTL", 127 1.1 mrg "$L1_PPTB", 128 1.1 mrg "$TLB_VPN", 129 1.1 mrg "$TLB_DATA", 130 1.1 mrg "$TLB_MISC", 131 1.1 mrg "$VLPT_IDX", 132 1.1 mrg "$ILMB", 133 1.1 mrg "$DLMB", 134 1.1 mrg 135 1.1 mrg "$CACHE_CTL", 136 1.1 mrg "$HSMP_SADDR", 137 1.1 mrg "$HSMP_EADDR", 138 1.1 mrg "$SDZ_CTL", 139 1.1 mrg "$N12MISC_CTL", 140 1.1 mrg "$MISC_CTL", 141 1.1 mrg "$ECC_MISC", 142 1.1 mrg 143 1.1 mrg "$BPC0", 144 1.1 mrg "$BPC1", 145 1.1 mrg "$BPC2", 146 1.1 mrg "$BPC3", 147 1.1 mrg "$BPC4", 148 1.1 mrg "$BPC5", 149 1.1 mrg "$BPC6", 150 1.1 mrg "$BPC7", 151 1.1 mrg 152 1.1 mrg "$BPA0", 153 1.1 mrg "$BPA1", 154 1.1 mrg "$BPA2", 155 1.1 mrg "$BPA3", 156 1.1 mrg "$BPA4", 157 1.1 mrg "$BPA5", 158 1.1 mrg "$BPA6", 159 1.1 mrg "$BPA7", 160 1.1 mrg 161 1.1 mrg "$BPAM0", 162 1.1 mrg "$BPAM1", 163 1.1 mrg "$BPAM2", 164 1.1 mrg "$BPAM3", 165 1.1 mrg "$BPAM4", 166 1.1 mrg "$BPAM5", 167 1.1 mrg "$BPAM6", 168 1.1 mrg "$BPAM7", 169 1.1 mrg 170 1.1 mrg "$BPV0", 171 1.1 mrg "$BPV1", 172 1.1 mrg "$BPV2", 173 1.1 mrg "$BPV3", 174 1.1 mrg "$BPV4", 175 1.1 mrg "$BPV5", 176 1.1 mrg "$BPV6", 177 1.1 mrg "$BPV7", 178 1.1 mrg 179 1.1 mrg "$BPCID0", 180 1.1 mrg "$BPCID1", 181 1.1 mrg "$BPCID2", 182 1.1 mrg "$BPCID3", 183 1.1 mrg "$BPCID4", 184 1.1 mrg "$BPCID5", 185 1.1 mrg "$BPCID6", 186 1.1 mrg "$BPCID7", 187 1.1 mrg 188 1.1 mrg "$EDM_CFG", 189 1.1 mrg "$EDMSW", 190 1.1 mrg "$EDM_CTL", 191 1.1 mrg "$EDM_DTR", 192 1.1 mrg "$BPMTC", 193 1.1 mrg "$DIMBR", 194 1.1 mrg 195 1.1 mrg "$TECR0", 196 1.1 mrg "$TECR1", 197 1.1 mrg "$PFMC0", 198 1.1 mrg "$PFMC1", 199 1.1 mrg "$PFMC2", 200 1.1 mrg "$PFM_CTL", 201 1.1 mrg "$PFT_CTL", 202 1.1 mrg "$HSP_CTL", 203 1.1 mrg "$SP_BOUND", 204 1.1 mrg "$SP_BOUND_PRIV", 205 1.1 mrg "$SP_BASE", 206 1.1 mrg "$SP_BASE_PRIV", 207 1.1 mrg "$FUCOP_CTL", 208 1.1 mrg "$PRUSR_ACC_CTL", 209 1.1 mrg 210 1.1 mrg "$DMA_CFG", 211 1.1 mrg "$DMA_GCSW", 212 1.1 mrg "$DMA_CHNSEL", 213 1.1 mrg "$DMA_ACT", 214 1.1 mrg "$DMA_SETUP", 215 1.1 mrg "$DMA_ISADDR", 216 1.1 mrg "$DMA_ESADDR", 217 1.1 mrg "$DMA_TCNT", 218 1.1 mrg "$DMA_STATUS", 219 1.1 mrg "$DMA_2DSET", 220 1.1 mrg "$DMA_2DSCTL", 221 1.1 mrg "$DMA_RCNT", 222 1.1 mrg "$DMA_HSTATUS", 223 1.1 mrg 224 1.1 mrg "$PC", 225 1.1 mrg "$SP_USR1", 226 1.1 mrg "$SP_USR2", 227 1.1 mrg "$SP_USR3", 228 1.1 mrg "$SP_PRIV1", 229 1.1 mrg "$SP_PRIV2", 230 1.1 mrg "$SP_PRIV3", 231 1.1 mrg "$BG_REGION", 232 1.1 mrg "$SFCR", 233 1.1 mrg "$SIGN", 234 1.1 mrg "$ISIGN", 235 1.1 mrg "$P_ISIGN", 236 1.1 mrg "$IFC_LP", 237 1.1 mrg "$ITB" 238 1.1 mrg }; 239 1.1 mrg 240 1.1 mrg /* Define instrinsic cctl names. */ 241 1.1 mrg static const char * const nds32_cctl_names[] = 242 1.1 mrg { 243 1.1 mrg "L1D_VA_FILLCK", 244 1.1 mrg "L1D_VA_ULCK", 245 1.1 mrg "L1I_VA_FILLCK", 246 1.1 mrg "L1I_VA_ULCK", 247 1.1 mrg 248 1.1 mrg "L1D_IX_WBINVAL", 249 1.1 mrg "L1D_IX_INVAL", 250 1.1 mrg "L1D_IX_WB", 251 1.1 mrg "L1I_IX_INVAL", 252 1.1 mrg 253 1.1 mrg "L1D_VA_INVAL", 254 1.1 mrg "L1D_VA_WB", 255 1.1 mrg "L1D_VA_WBINVAL", 256 1.1 mrg "L1I_VA_INVAL", 257 1.1 mrg 258 1.1 mrg "L1D_IX_RTAG", 259 1.1 mrg "L1D_IX_RWD", 260 1.1 mrg "L1I_IX_RTAG", 261 1.1 mrg "L1I_IX_RWD", 262 1.1 mrg 263 1.1 mrg "L1D_IX_WTAG", 264 1.1 mrg "L1D_IX_WWD", 265 1.1 mrg "L1I_IX_WTAG", 266 1.1 mrg "L1I_IX_WWD" 267 1.1 mrg }; 268 1.1 mrg 269 1.1 mrg static const char * const nds32_dpref_names[] = 270 1.1 mrg { 271 1.1 mrg "SRD", 272 1.1 mrg "MRD", 273 1.1 mrg "SWR", 274 1.1 mrg "MWR", 275 1.1 mrg "PTE", 276 1.1 mrg "CLWR" 277 1.1 mrg }; 278 1.1 mrg 279 1.1 mrg /* Defining register allocation order for performance. 280 1.1 mrg We want to allocate callee-saved registers after others. 281 1.1 mrg It may be used by nds32_adjust_reg_alloc_order(). */ 282 1.1 mrg static const int nds32_reg_alloc_order_for_speed[] = 283 1.1 mrg { 284 1.1 mrg 0, 1, 2, 3, 4, 5, 16, 17, 285 1.1 mrg 18, 19, 20, 21, 22, 23, 24, 25, 286 1.1 mrg 26, 27, 6, 7, 8, 9, 10, 11, 287 1.1 mrg 12, 13, 14, 15 288 1.1 mrg }; 289 1.1 mrg 290 1.1 mrg /* Defining target-specific uses of __attribute__. */ 291 1.1 mrg static const struct attribute_spec nds32_attribute_table[] = 292 1.1 mrg { 293 1.1 mrg /* Syntax: { name, min_len, max_len, decl_required, type_required, 294 1.1 mrg function_type_required, affects_type_identity, handler, 295 1.1 mrg exclude } */ 296 1.1 mrg 297 1.1 mrg /* The interrupt vid: [0-63]+ (actual vector number starts from 9 to 72). */ 298 1.1 mrg { "interrupt", 1, 64, false, false, false, false, NULL, NULL }, 299 1.1 mrg /* The exception vid: [1-8]+ (actual vector number starts from 1 to 8). */ 300 1.1 mrg { "exception", 1, 8, false, false, false, false, NULL, NULL }, 301 1.1 mrg /* Argument is user's interrupt numbers. The vector number is always 0. */ 302 1.1 mrg { "reset", 1, 1, false, false, false, false, NULL, NULL }, 303 1.1 mrg 304 1.1 mrg /* The attributes describing isr nested type. */ 305 1.1 mrg { "nested", 0, 0, false, false, false, false, NULL, NULL }, 306 1.1 mrg { "not_nested", 0, 0, false, false, false, false, NULL, NULL }, 307 1.1 mrg { "nested_ready", 0, 0, false, false, false, false, NULL, NULL }, 308 1.1 mrg { "critical", 0, 0, false, false, false, false, NULL, NULL }, 309 1.1 mrg 310 1.1 mrg /* The attributes describing isr register save scheme. */ 311 1.1 mrg { "save_all", 0, 0, false, false, false, false, NULL, NULL }, 312 1.1 mrg { "partial_save", 0, 0, false, false, false, false, NULL, NULL }, 313 1.1 mrg 314 1.1 mrg /* The attributes used by reset attribute. */ 315 1.1 mrg { "nmi", 1, 1, false, false, false, false, NULL, NULL }, 316 1.1 mrg { "warm", 1, 1, false, false, false, false, NULL, NULL }, 317 1.1 mrg 318 1.1 mrg /* The attributes describing isr security level. */ 319 1.1 mrg { "secure", 1, 1, false, false, false, false, NULL, NULL }, 320 1.1 mrg 321 1.1 mrg /* The attribute telling no prologue/epilogue. */ 322 1.1 mrg { "naked", 0, 0, false, false, false, false, NULL, NULL }, 323 1.1 mrg 324 1.1 mrg /* The attribute is used to tell this function to be ROM patch. */ 325 1.1 mrg { "indirect_call",0, 0, false, false, false, false, NULL, NULL }, 326 1.1 mrg 327 1.1 mrg /* FOR BACKWARD COMPATIBILITY, 328 1.1 mrg this attribute also tells no prologue/epilogue. */ 329 1.1 mrg { "no_prologue", 0, 0, false, false, false, false, NULL, NULL }, 330 1.1 mrg 331 1.1 mrg /* The last attribute spec is set to be NULL. */ 332 1.1 mrg { NULL, 0, 0, false, false, false, false, NULL, NULL } 333 1.1 mrg }; 334 1.1 mrg 335 1.1 mrg 336 1.1 mrg /* ------------------------------------------------------------------------ */ 337 1.1 mrg 338 1.1 mrg /* PART 2: Auxiliary static function definitions. */ 339 1.1 mrg 340 1.1 mrg /* Function to save and restore machine-specific function data. */ 341 1.1 mrg static struct machine_function * 342 1.1 mrg nds32_init_machine_status (void) 343 1.1 mrg { 344 1.1 mrg struct machine_function *machine; 345 1.1 mrg machine = ggc_cleared_alloc<machine_function> (); 346 1.1 mrg 347 1.1 mrg /* Initially assume this function does not use __builtin_eh_return. */ 348 1.1 mrg machine->use_eh_return_p = 0; 349 1.1 mrg 350 1.1 mrg /* Initially assume this function needs prologue/epilogue. */ 351 1.1 mrg machine->naked_p = 0; 352 1.1 mrg 353 1.1 mrg /* Initially assume this function does NOT use fp_as_gp optimization. */ 354 1.1 mrg machine->fp_as_gp_p = 0; 355 1.1 mrg 356 1.1 mrg /* Initially this function is not under strictly aligned situation. */ 357 1.1 mrg machine->strict_aligned_p = 0; 358 1.1 mrg 359 1.1 mrg /* Initially this function has no naked and no_prologue attributes. */ 360 1.1 mrg machine->attr_naked_p = 0; 361 1.1 mrg machine->attr_no_prologue_p = 0; 362 1.1 mrg 363 1.1 mrg return machine; 364 1.1 mrg } 365 1.1 mrg 366 1.1 mrg /* Function to compute stack frame size and 367 1.1 mrg store into cfun->machine structure. */ 368 1.1 mrg static void 369 1.1 mrg nds32_compute_stack_frame (void) 370 1.1 mrg { 371 1.1 mrg int r; 372 1.1 mrg int block_size; 373 1.1 mrg bool v3pushpop_p; 374 1.1 mrg 375 1.1 mrg /* Because nds32_compute_stack_frame() will be called from different place, 376 1.1 mrg everytime we enter this function, we have to assume this function 377 1.1 mrg needs prologue/epilogue. */ 378 1.1 mrg cfun->machine->naked_p = 0; 379 1.1 mrg 380 1.1 mrg /* We need to mark whether this function has naked and no_prologue 381 1.1 mrg attribute so that we can distinguish the difference if users applies 382 1.1 mrg -mret-in-naked-func option. */ 383 1.1 mrg cfun->machine->attr_naked_p 384 1.1 mrg = lookup_attribute ("naked", DECL_ATTRIBUTES (current_function_decl)) 385 1.1 mrg ? 1 : 0; 386 1.1 mrg cfun->machine->attr_no_prologue_p 387 1.1 mrg = lookup_attribute ("no_prologue", DECL_ATTRIBUTES (current_function_decl)) 388 1.1 mrg ? 1 : 0; 389 1.1 mrg 390 1.1 mrg /* If __builtin_eh_return is used, we better have frame pointer needed 391 1.1 mrg so that we can easily locate the stack slot of return address. */ 392 1.1 mrg if (crtl->calls_eh_return) 393 1.1 mrg { 394 1.1 mrg frame_pointer_needed = 1; 395 1.1 mrg 396 1.1 mrg /* We need to mark eh data registers that need to be saved 397 1.1 mrg in the stack. */ 398 1.1 mrg cfun->machine->eh_return_data_first_regno = EH_RETURN_DATA_REGNO (0); 399 1.1 mrg for (r = 0; EH_RETURN_DATA_REGNO (r) != INVALID_REGNUM; r++) 400 1.1 mrg cfun->machine->eh_return_data_last_regno = r; 401 1.1 mrg 402 1.1 mrg cfun->machine->eh_return_data_regs_size 403 1.1 mrg = 4 * (cfun->machine->eh_return_data_last_regno 404 1.1 mrg - cfun->machine->eh_return_data_first_regno 405 1.1 mrg + 1); 406 1.1 mrg cfun->machine->use_eh_return_p = 1; 407 1.1 mrg } 408 1.1 mrg else 409 1.1 mrg { 410 1.1 mrg /* Assigning SP_REGNUM to eh_first_regno and eh_last_regno means we 411 1.1 mrg do not need to handle __builtin_eh_return case in this function. */ 412 1.1 mrg cfun->machine->eh_return_data_first_regno = SP_REGNUM; 413 1.1 mrg cfun->machine->eh_return_data_last_regno = SP_REGNUM; 414 1.1 mrg 415 1.1 mrg cfun->machine->eh_return_data_regs_size = 0; 416 1.1 mrg cfun->machine->use_eh_return_p = 0; 417 1.1 mrg } 418 1.1 mrg 419 1.1 mrg /* Get variadic arguments size to prepare pretend arguments and 420 1.1 mrg we will push them into stack at prologue by ourself. */ 421 1.1 mrg cfun->machine->va_args_size = crtl->args.pretend_args_size; 422 1.1 mrg if (cfun->machine->va_args_size != 0) 423 1.1 mrg { 424 1.1 mrg cfun->machine->va_args_first_regno 425 1.1 mrg = NDS32_GPR_ARG_FIRST_REGNUM 426 1.1 mrg + NDS32_MAX_GPR_REGS_FOR_ARGS 427 1.1 mrg - (crtl->args.pretend_args_size / UNITS_PER_WORD); 428 1.1 mrg cfun->machine->va_args_last_regno 429 1.1 mrg = NDS32_GPR_ARG_FIRST_REGNUM + NDS32_MAX_GPR_REGS_FOR_ARGS - 1; 430 1.1 mrg } 431 1.1 mrg else 432 1.1 mrg { 433 1.1 mrg cfun->machine->va_args_first_regno = SP_REGNUM; 434 1.1 mrg cfun->machine->va_args_last_regno = SP_REGNUM; 435 1.1 mrg } 436 1.1 mrg 437 1.1 mrg /* Important: We need to make sure that varargs area is 8-byte alignment. */ 438 1.1 mrg block_size = cfun->machine->va_args_size; 439 1.1 mrg if (!NDS32_DOUBLE_WORD_ALIGN_P (block_size)) 440 1.1 mrg { 441 1.1 mrg cfun->machine->va_args_area_padding_bytes 442 1.1 mrg = NDS32_ROUND_UP_DOUBLE_WORD (block_size) - block_size; 443 1.1 mrg } 444 1.1 mrg 445 1.1 mrg /* Get local variables, incoming variables, and temporary variables size. 446 1.1 mrg Note that we need to make sure it is 8-byte alignment because 447 1.1 mrg there may be no padding bytes if we are using LRA. */ 448 1.1 mrg cfun->machine->local_size = NDS32_ROUND_UP_DOUBLE_WORD (get_frame_size ()); 449 1.1 mrg 450 1.1 mrg /* Get outgoing arguments size. */ 451 1.1 mrg cfun->machine->out_args_size = crtl->outgoing_args_size; 452 1.1 mrg 453 1.1 mrg /* If $fp value is required to be saved on stack, it needs 4 bytes space. 454 1.1 mrg Check whether $fp is ever live. */ 455 1.1 mrg cfun->machine->fp_size = (df_regs_ever_live_p (FP_REGNUM)) ? 4 : 0; 456 1.1 mrg 457 1.1 mrg /* If $gp value is required to be saved on stack, it needs 4 bytes space. 458 1.1 mrg Check whether we are using PIC code genration. */ 459 1.1 mrg cfun->machine->gp_size = 460 1.1 mrg (flag_pic && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM)) ? 4 : 0; 461 1.1 mrg 462 1.1 mrg /* If $lp value is required to be saved on stack, it needs 4 bytes space. 463 1.1 mrg Check whether $lp is ever live. */ 464 1.1 mrg cfun->machine->lp_size 465 1.1 mrg = (flag_always_save_lp || df_regs_ever_live_p (LP_REGNUM)) ? 4 : 0; 466 1.1 mrg 467 1.1 mrg /* Initially there is no padding bytes. */ 468 1.1 mrg cfun->machine->callee_saved_area_gpr_padding_bytes = 0; 469 1.1 mrg 470 1.1 mrg /* Calculate the bytes of saving callee-saved registers on stack. */ 471 1.1 mrg cfun->machine->callee_saved_gpr_regs_size = 0; 472 1.1 mrg cfun->machine->callee_saved_first_gpr_regno = SP_REGNUM; 473 1.1 mrg cfun->machine->callee_saved_last_gpr_regno = SP_REGNUM; 474 1.1 mrg cfun->machine->callee_saved_fpr_regs_size = 0; 475 1.1 mrg cfun->machine->callee_saved_first_fpr_regno = SP_REGNUM; 476 1.1 mrg cfun->machine->callee_saved_last_fpr_regno = SP_REGNUM; 477 1.1 mrg 478 1.1 mrg /* Currently, there is no need to check $r28~$r31 479 1.1 mrg because we will save them in another way. */ 480 1.1 mrg for (r = 0; r < 28; r++) 481 1.1 mrg { 482 1.1 mrg if (NDS32_REQUIRED_CALLEE_SAVED_P (r)) 483 1.1 mrg { 484 1.1 mrg /* Mark the first required callee-saved register 485 1.1 mrg (only need to set it once). 486 1.1 mrg If first regno == SP_REGNUM, we can tell that 487 1.1 mrg it is the first time to be here. */ 488 1.1 mrg if (cfun->machine->callee_saved_first_gpr_regno == SP_REGNUM) 489 1.1 mrg cfun->machine->callee_saved_first_gpr_regno = r; 490 1.1 mrg /* Mark the last required callee-saved register. */ 491 1.1 mrg cfun->machine->callee_saved_last_gpr_regno = r; 492 1.1 mrg } 493 1.1 mrg } 494 1.1 mrg 495 1.1 mrg /* Recording fpu callee-saved register. */ 496 1.1 mrg if (TARGET_HARD_FLOAT) 497 1.1 mrg { 498 1.1 mrg for (r = NDS32_FIRST_FPR_REGNUM; r < NDS32_LAST_FPR_REGNUM; r++) 499 1.1 mrg { 500 1.1 mrg if (NDS32_REQUIRED_CALLEE_SAVED_P (r)) 501 1.1 mrg { 502 1.1 mrg /* Mark the first required callee-saved register. */ 503 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno == SP_REGNUM) 504 1.1 mrg { 505 1.1 mrg /* Make first callee-saved number is even, 506 1.1 mrg bacause we use doubleword access, and this way 507 1.1 mrg promise 8-byte alignemt. */ 508 1.1 mrg if (!NDS32_FPR_REGNO_OK_FOR_DOUBLE (r)) 509 1.1 mrg cfun->machine->callee_saved_first_fpr_regno = r - 1; 510 1.1 mrg else 511 1.1 mrg cfun->machine->callee_saved_first_fpr_regno = r; 512 1.1 mrg } 513 1.1 mrg cfun->machine->callee_saved_last_fpr_regno = r; 514 1.1 mrg } 515 1.1 mrg } 516 1.1 mrg 517 1.1 mrg /* Make last callee-saved register number is odd, 518 1.1 mrg we hope callee-saved register is even. */ 519 1.1 mrg int last_fpr = cfun->machine->callee_saved_last_fpr_regno; 520 1.1 mrg if (NDS32_FPR_REGNO_OK_FOR_DOUBLE (last_fpr)) 521 1.1 mrg cfun->machine->callee_saved_last_fpr_regno++; 522 1.1 mrg } 523 1.1 mrg 524 1.1 mrg /* Check if this function can omit prologue/epilogue code fragment. 525 1.1 mrg If there is 'no_prologue'/'naked'/'secure' attribute in this function, 526 1.1 mrg we can set 'naked_p' flag to indicate that 527 1.1 mrg we do not have to generate prologue/epilogue. 528 1.1 mrg Or, if all the following conditions succeed, 529 1.1 mrg we can set this function 'naked_p' as well: 530 1.1 mrg condition 1: first_regno == last_regno == SP_REGNUM, 531 1.1 mrg which means we do not have to save 532 1.1 mrg any callee-saved registers. 533 1.1 mrg condition 2: Both $lp and $fp are NOT live in this function, 534 1.1 mrg which means we do not need to save them and there 535 1.1 mrg is no outgoing size. 536 1.1 mrg condition 3: There is no local_size, which means 537 1.1 mrg we do not need to adjust $sp. */ 538 1.1 mrg if (lookup_attribute ("no_prologue", DECL_ATTRIBUTES (current_function_decl)) 539 1.1 mrg || lookup_attribute ("naked", DECL_ATTRIBUTES (current_function_decl)) 540 1.1 mrg || lookup_attribute ("secure", DECL_ATTRIBUTES (current_function_decl)) 541 1.1 mrg || (cfun->machine->callee_saved_first_gpr_regno == SP_REGNUM 542 1.1 mrg && cfun->machine->callee_saved_last_gpr_regno == SP_REGNUM 543 1.1 mrg && cfun->machine->callee_saved_first_fpr_regno == SP_REGNUM 544 1.1 mrg && cfun->machine->callee_saved_last_fpr_regno == SP_REGNUM 545 1.1 mrg && !df_regs_ever_live_p (FP_REGNUM) 546 1.1 mrg && !df_regs_ever_live_p (LP_REGNUM) 547 1.1 mrg && cfun->machine->local_size == 0 548 1.1 mrg && !flag_pic)) 549 1.1 mrg { 550 1.1 mrg /* Set this function 'naked_p' and other functions can check this flag. 551 1.1 mrg Note that in nds32 port, the 'naked_p = 1' JUST means there is no 552 1.1 mrg callee-saved, local size, and outgoing size. 553 1.1 mrg The varargs space and ret instruction may still present in 554 1.1 mrg the prologue/epilogue expanding. */ 555 1.1 mrg cfun->machine->naked_p = 1; 556 1.1 mrg 557 1.1 mrg /* No need to save $fp, $gp, and $lp. 558 1.1 mrg We should set these value to be zero 559 1.1 mrg so that nds32_initial_elimination_offset() can work properly. */ 560 1.1 mrg cfun->machine->fp_size = 0; 561 1.1 mrg cfun->machine->gp_size = 0; 562 1.1 mrg cfun->machine->lp_size = 0; 563 1.1 mrg 564 1.1 mrg /* If stack usage computation is required, 565 1.1 mrg we need to provide the static stack size. */ 566 1.1 mrg if (flag_stack_usage_info) 567 1.1 mrg current_function_static_stack_size = 0; 568 1.1 mrg 569 1.1 mrg /* No need to do following adjustment, return immediately. */ 570 1.1 mrg return; 571 1.1 mrg } 572 1.1 mrg 573 1.1 mrg v3pushpop_p = NDS32_V3PUSH_AVAILABLE_P; 574 1.1 mrg 575 1.1 mrg /* Adjustment for v3push instructions: 576 1.1 mrg If we are using v3push (push25/pop25) instructions, 577 1.1 mrg we need to make sure Rb is $r6 and Re is 578 1.1 mrg located on $r6, $r8, $r10, or $r14. 579 1.1 mrg Some results above will be discarded and recomputed. 580 1.1 mrg Note that it is only available under V3/V3M ISA and we 581 1.1 mrg DO NOT setup following stuff for isr or variadic function. */ 582 1.1 mrg if (v3pushpop_p) 583 1.1 mrg { 584 1.1 mrg /* Recompute: 585 1.1 mrg cfun->machine->fp_size 586 1.1 mrg cfun->machine->gp_size 587 1.1 mrg cfun->machine->lp_size 588 1.1 mrg cfun->machine->callee_saved_first_gpr_regno 589 1.1 mrg cfun->machine->callee_saved_last_gpr_regno */ 590 1.1 mrg 591 1.1 mrg /* For v3push instructions, $fp, $gp, and $lp are always saved. */ 592 1.1 mrg cfun->machine->fp_size = 4; 593 1.1 mrg cfun->machine->gp_size = 4; 594 1.1 mrg cfun->machine->lp_size = 4; 595 1.1 mrg 596 1.1 mrg /* Remember to set Rb = $r6. */ 597 1.1 mrg cfun->machine->callee_saved_first_gpr_regno = 6; 598 1.1 mrg 599 1.1 mrg if (cfun->machine->callee_saved_last_gpr_regno <= 6) 600 1.1 mrg { 601 1.1 mrg /* Re = $r6 */ 602 1.1 mrg cfun->machine->callee_saved_last_gpr_regno = 6; 603 1.1 mrg } 604 1.1 mrg else if (cfun->machine->callee_saved_last_gpr_regno <= 8) 605 1.1 mrg { 606 1.1 mrg /* Re = $r8 */ 607 1.1 mrg cfun->machine->callee_saved_last_gpr_regno = 8; 608 1.1 mrg } 609 1.1 mrg else if (cfun->machine->callee_saved_last_gpr_regno <= 10) 610 1.1 mrg { 611 1.1 mrg /* Re = $r10 */ 612 1.1 mrg cfun->machine->callee_saved_last_gpr_regno = 10; 613 1.1 mrg } 614 1.1 mrg else if (cfun->machine->callee_saved_last_gpr_regno <= 14) 615 1.1 mrg { 616 1.1 mrg /* Re = $r14 */ 617 1.1 mrg cfun->machine->callee_saved_last_gpr_regno = 14; 618 1.1 mrg } 619 1.1 mrg else if (cfun->machine->callee_saved_last_gpr_regno == SP_REGNUM) 620 1.1 mrg { 621 1.1 mrg /* If last_regno is SP_REGNUM, which means 622 1.1 mrg it is never changed, so set it to Re = $r6. */ 623 1.1 mrg cfun->machine->callee_saved_last_gpr_regno = 6; 624 1.1 mrg } 625 1.1 mrg else 626 1.1 mrg { 627 1.1 mrg /* The program flow should not go here. */ 628 1.1 mrg gcc_unreachable (); 629 1.1 mrg } 630 1.1 mrg } 631 1.1 mrg 632 1.1 mrg int sp_adjust = cfun->machine->local_size 633 1.1 mrg + cfun->machine->out_args_size 634 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes 635 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 636 1.1 mrg 637 1.1 mrg if (!v3pushpop_p 638 1.1 mrg && sp_adjust == 0 639 1.1 mrg && !frame_pointer_needed) 640 1.1 mrg { 641 1.1 mrg block_size = cfun->machine->fp_size 642 1.1 mrg + cfun->machine->gp_size 643 1.1 mrg + cfun->machine->lp_size; 644 1.1 mrg 645 1.1 mrg if (cfun->machine->callee_saved_last_gpr_regno != SP_REGNUM) 646 1.1 mrg block_size += (4 * (cfun->machine->callee_saved_last_gpr_regno 647 1.1 mrg - cfun->machine->callee_saved_first_gpr_regno 648 1.1 mrg + 1)); 649 1.1 mrg 650 1.1 mrg if (!NDS32_DOUBLE_WORD_ALIGN_P (block_size)) 651 1.1 mrg { 652 1.1 mrg /* $r14 is last callee save register. */ 653 1.1 mrg if (cfun->machine->callee_saved_last_gpr_regno 654 1.1 mrg < NDS32_LAST_CALLEE_SAVE_GPR_REGNUM) 655 1.1 mrg { 656 1.1 mrg cfun->machine->callee_saved_last_gpr_regno++; 657 1.1 mrg } 658 1.1 mrg else if (cfun->machine->callee_saved_first_gpr_regno == SP_REGNUM) 659 1.1 mrg { 660 1.1 mrg cfun->machine->callee_saved_first_gpr_regno 661 1.1 mrg = NDS32_FIRST_CALLEE_SAVE_GPR_REGNUM; 662 1.1 mrg cfun->machine->callee_saved_last_gpr_regno 663 1.1 mrg = NDS32_FIRST_CALLEE_SAVE_GPR_REGNUM; 664 1.1 mrg } 665 1.1 mrg } 666 1.1 mrg } 667 1.1 mrg 668 1.1 mrg /* We have correctly set callee_saved_first_gpr_regno 669 1.1 mrg and callee_saved_last_gpr_regno. 670 1.1 mrg Initially, the callee_saved_gpr_regs_size is supposed to be 0. 671 1.1 mrg As long as callee_saved_last_gpr_regno is not SP_REGNUM, 672 1.1 mrg we can update callee_saved_gpr_regs_size with new size. */ 673 1.1 mrg if (cfun->machine->callee_saved_last_gpr_regno != SP_REGNUM) 674 1.1 mrg { 675 1.1 mrg /* Compute pushed size of callee-saved registers. */ 676 1.1 mrg cfun->machine->callee_saved_gpr_regs_size 677 1.1 mrg = 4 * (cfun->machine->callee_saved_last_gpr_regno 678 1.1 mrg - cfun->machine->callee_saved_first_gpr_regno 679 1.1 mrg + 1); 680 1.1 mrg } 681 1.1 mrg 682 1.1 mrg if (TARGET_HARD_FLOAT) 683 1.1 mrg { 684 1.1 mrg /* Compute size of callee svaed floating-point registers. */ 685 1.1 mrg if (cfun->machine->callee_saved_last_fpr_regno != SP_REGNUM) 686 1.1 mrg { 687 1.1 mrg cfun->machine->callee_saved_fpr_regs_size 688 1.1 mrg = 4 * (cfun->machine->callee_saved_last_fpr_regno 689 1.1 mrg - cfun->machine->callee_saved_first_fpr_regno 690 1.1 mrg + 1); 691 1.1 mrg } 692 1.1 mrg } 693 1.1 mrg 694 1.1 mrg /* Important: We need to make sure that 695 1.1 mrg (fp_size + gp_size + lp_size + callee_saved_gpr_regs_size) 696 1.1 mrg is 8-byte alignment. 697 1.1 mrg If it is not, calculate the padding bytes. */ 698 1.1 mrg block_size = cfun->machine->fp_size 699 1.1 mrg + cfun->machine->gp_size 700 1.1 mrg + cfun->machine->lp_size 701 1.1 mrg + cfun->machine->callee_saved_gpr_regs_size; 702 1.1 mrg if (!NDS32_DOUBLE_WORD_ALIGN_P (block_size)) 703 1.1 mrg { 704 1.1 mrg cfun->machine->callee_saved_area_gpr_padding_bytes 705 1.1 mrg = NDS32_ROUND_UP_DOUBLE_WORD (block_size) - block_size; 706 1.1 mrg } 707 1.1 mrg 708 1.1 mrg /* If stack usage computation is required, 709 1.1 mrg we need to provide the static stack size. */ 710 1.1 mrg if (flag_stack_usage_info) 711 1.1 mrg { 712 1.1 mrg current_function_static_stack_size 713 1.1 mrg = NDS32_ROUND_UP_DOUBLE_WORD (block_size) 714 1.1 mrg + cfun->machine->local_size 715 1.1 mrg + cfun->machine->out_args_size; 716 1.1 mrg } 717 1.1 mrg } 718 1.1 mrg 719 1.1 mrg /* Function to create a parallel rtx pattern 720 1.1 mrg which presents stack push multiple behavior. 721 1.1 mrg The overall concept are: 722 1.1 mrg "push registers to memory", 723 1.1 mrg "adjust stack pointer". */ 724 1.1 mrg static void 725 1.1 mrg nds32_emit_stack_push_multiple (unsigned Rb, unsigned Re, 726 1.1 mrg bool save_fp_p, bool save_gp_p, bool save_lp_p, 727 1.1 mrg bool vaarg_p) 728 1.1 mrg { 729 1.1 mrg unsigned regno; 730 1.1 mrg int extra_count; 731 1.1 mrg int num_use_regs; 732 1.1 mrg int par_index; 733 1.1 mrg int offset; 734 1.1 mrg 735 1.1 mrg rtx reg; 736 1.1 mrg rtx mem; 737 1.1 mrg rtx push_rtx; 738 1.1 mrg rtx adjust_sp_rtx; 739 1.1 mrg rtx parallel_insn; 740 1.1 mrg rtx dwarf; 741 1.1 mrg 742 1.1 mrg /* We need to provide a customized rtx which contains 743 1.1 mrg necessary information for data analysis, 744 1.1 mrg so we create a parallel rtx like this: 745 1.1 mrg (parallel [(set (mem (plus (reg:SI SP_REGNUM) (const_int -32))) 746 1.1 mrg (reg:SI Rb)) 747 1.1 mrg (set (mem (plus (reg:SI SP_REGNUM) (const_int -28))) 748 1.1 mrg (reg:SI Rb+1)) 749 1.1 mrg ... 750 1.1 mrg (set (mem (plus (reg:SI SP_REGNUM) (const_int -16))) 751 1.1 mrg (reg:SI Re)) 752 1.1 mrg (set (mem (plus (reg:SI SP_REGNUM) (const_int -12))) 753 1.1 mrg (reg:SI FP_REGNUM)) 754 1.1 mrg (set (mem (plus (reg:SI SP_REGNUM) (const_int -8))) 755 1.1 mrg (reg:SI GP_REGNUM)) 756 1.1 mrg (set (mem (plus (reg:SI SP_REGNUM) (const_int -4))) 757 1.1 mrg (reg:SI LP_REGNUM)) 758 1.1 mrg (set (reg:SI SP_REGNUM) 759 1.1 mrg (plus (reg:SI SP_REGNUM) (const_int -32)))]) */ 760 1.1 mrg 761 1.1 mrg /* Calculate the number of registers that will be pushed. */ 762 1.1 mrg extra_count = 0; 763 1.1 mrg if (save_fp_p) 764 1.1 mrg extra_count++; 765 1.1 mrg if (save_gp_p) 766 1.1 mrg extra_count++; 767 1.1 mrg if (save_lp_p) 768 1.1 mrg extra_count++; 769 1.1 mrg /* Note that Rb and Re may be SP_REGNUM. DO NOT count it in. */ 770 1.1 mrg if (Rb == SP_REGNUM && Re == SP_REGNUM) 771 1.1 mrg num_use_regs = extra_count; 772 1.1 mrg else 773 1.1 mrg num_use_regs = Re - Rb + 1 + extra_count; 774 1.1 mrg 775 1.1 mrg /* In addition to used registers, 776 1.1 mrg we need one more space for (set sp sp-x) rtx. */ 777 1.1 mrg parallel_insn = gen_rtx_PARALLEL (VOIDmode, 778 1.1 mrg rtvec_alloc (num_use_regs + 1)); 779 1.1 mrg par_index = 0; 780 1.1 mrg 781 1.1 mrg /* Initialize offset and start to create push behavior. */ 782 1.1 mrg offset = -(num_use_regs * 4); 783 1.1 mrg 784 1.1 mrg /* Create (set mem regX) from Rb, Rb+1 up to Re. */ 785 1.1 mrg for (regno = Rb; regno <= Re; regno++) 786 1.1 mrg { 787 1.1 mrg /* Rb and Re may be SP_REGNUM. 788 1.1 mrg We need to break this loop immediately. */ 789 1.1 mrg if (regno == SP_REGNUM) 790 1.1 mrg break; 791 1.1 mrg 792 1.1 mrg reg = gen_rtx_REG (SImode, regno); 793 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 794 1.1 mrg stack_pointer_rtx, 795 1.1 mrg offset)); 796 1.1 mrg push_rtx = gen_rtx_SET (mem, reg); 797 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = push_rtx; 798 1.1 mrg RTX_FRAME_RELATED_P (push_rtx) = 1; 799 1.1 mrg offset = offset + 4; 800 1.1 mrg par_index++; 801 1.1 mrg } 802 1.1 mrg 803 1.1 mrg /* Create (set mem fp), (set mem gp), and (set mem lp) if necessary. */ 804 1.1 mrg if (save_fp_p) 805 1.1 mrg { 806 1.1 mrg reg = gen_rtx_REG (SImode, FP_REGNUM); 807 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 808 1.1 mrg stack_pointer_rtx, 809 1.1 mrg offset)); 810 1.1 mrg push_rtx = gen_rtx_SET (mem, reg); 811 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = push_rtx; 812 1.1 mrg RTX_FRAME_RELATED_P (push_rtx) = 1; 813 1.1 mrg offset = offset + 4; 814 1.1 mrg par_index++; 815 1.1 mrg } 816 1.1 mrg if (save_gp_p) 817 1.1 mrg { 818 1.1 mrg reg = gen_rtx_REG (SImode, GP_REGNUM); 819 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 820 1.1 mrg stack_pointer_rtx, 821 1.1 mrg offset)); 822 1.1 mrg push_rtx = gen_rtx_SET (mem, reg); 823 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = push_rtx; 824 1.1 mrg RTX_FRAME_RELATED_P (push_rtx) = 1; 825 1.1 mrg offset = offset + 4; 826 1.1 mrg par_index++; 827 1.1 mrg } 828 1.1 mrg if (save_lp_p) 829 1.1 mrg { 830 1.1 mrg reg = gen_rtx_REG (SImode, LP_REGNUM); 831 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 832 1.1 mrg stack_pointer_rtx, 833 1.1 mrg offset)); 834 1.1 mrg push_rtx = gen_rtx_SET (mem, reg); 835 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = push_rtx; 836 1.1 mrg RTX_FRAME_RELATED_P (push_rtx) = 1; 837 1.1 mrg offset = offset + 4; 838 1.1 mrg par_index++; 839 1.1 mrg } 840 1.1 mrg 841 1.1 mrg /* Create (set sp sp-x). */ 842 1.1 mrg 843 1.1 mrg /* We need to re-calculate the offset value again for adjustment. */ 844 1.1 mrg offset = -(num_use_regs * 4); 845 1.1 mrg adjust_sp_rtx 846 1.1 mrg = gen_rtx_SET (stack_pointer_rtx, 847 1.1 mrg plus_constant (Pmode, stack_pointer_rtx, offset)); 848 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = adjust_sp_rtx; 849 1.1 mrg RTX_FRAME_RELATED_P (adjust_sp_rtx) = 1; 850 1.1 mrg 851 1.1 mrg parallel_insn = emit_insn (parallel_insn); 852 1.1 mrg 853 1.1 mrg /* The insn rtx 'parallel_insn' will change frame layout. 854 1.1 mrg We need to use RTX_FRAME_RELATED_P so that GCC is able to 855 1.1 mrg generate CFI (Call Frame Information) stuff. */ 856 1.1 mrg RTX_FRAME_RELATED_P (parallel_insn) = 1; 857 1.1 mrg 858 1.1 mrg /* Don't use GCC's logic for CFI info if we are generate a push for VAARG 859 1.1 mrg since we will not restore those register at epilogue. */ 860 1.1 mrg if (vaarg_p) 861 1.1 mrg { 862 1.1 mrg dwarf = alloc_reg_note (REG_CFA_ADJUST_CFA, 863 1.1 mrg copy_rtx (adjust_sp_rtx), NULL_RTX); 864 1.1 mrg REG_NOTES (parallel_insn) = dwarf; 865 1.1 mrg } 866 1.1 mrg } 867 1.1 mrg 868 1.1 mrg /* Function to create a parallel rtx pattern 869 1.1 mrg which presents stack pop multiple behavior. 870 1.1 mrg The overall concept are: 871 1.1 mrg "pop registers from memory", 872 1.1 mrg "adjust stack pointer". */ 873 1.1 mrg static void 874 1.1 mrg nds32_emit_stack_pop_multiple (unsigned Rb, unsigned Re, 875 1.1 mrg bool save_fp_p, bool save_gp_p, bool save_lp_p) 876 1.1 mrg { 877 1.1 mrg unsigned regno; 878 1.1 mrg int extra_count; 879 1.1 mrg int num_use_regs; 880 1.1 mrg int par_index; 881 1.1 mrg int offset; 882 1.1 mrg 883 1.1 mrg rtx reg; 884 1.1 mrg rtx mem; 885 1.1 mrg rtx pop_rtx; 886 1.1 mrg rtx adjust_sp_rtx; 887 1.1 mrg rtx parallel_insn; 888 1.1 mrg rtx dwarf = NULL_RTX; 889 1.1 mrg 890 1.1 mrg /* We need to provide a customized rtx which contains 891 1.1 mrg necessary information for data analysis, 892 1.1 mrg so we create a parallel rtx like this: 893 1.1 mrg (parallel [(set (reg:SI Rb) 894 1.1 mrg (mem (reg:SI SP_REGNUM))) 895 1.1 mrg (set (reg:SI Rb+1) 896 1.1 mrg (mem (plus (reg:SI SP_REGNUM) (const_int 4)))) 897 1.1 mrg ... 898 1.1 mrg (set (reg:SI Re) 899 1.1 mrg (mem (plus (reg:SI SP_REGNUM) (const_int 16)))) 900 1.1 mrg (set (reg:SI FP_REGNUM) 901 1.1 mrg (mem (plus (reg:SI SP_REGNUM) (const_int 20)))) 902 1.1 mrg (set (reg:SI GP_REGNUM) 903 1.1 mrg (mem (plus (reg:SI SP_REGNUM) (const_int 24)))) 904 1.1 mrg (set (reg:SI LP_REGNUM) 905 1.1 mrg (mem (plus (reg:SI SP_REGNUM) (const_int 28)))) 906 1.1 mrg (set (reg:SI SP_REGNUM) 907 1.1 mrg (plus (reg:SI SP_REGNUM) (const_int 32)))]) */ 908 1.1 mrg 909 1.1 mrg /* Calculate the number of registers that will be poped. */ 910 1.1 mrg extra_count = 0; 911 1.1 mrg if (save_fp_p) 912 1.1 mrg extra_count++; 913 1.1 mrg if (save_gp_p) 914 1.1 mrg extra_count++; 915 1.1 mrg if (save_lp_p) 916 1.1 mrg extra_count++; 917 1.1 mrg /* Note that Rb and Re may be SP_REGNUM. DO NOT count it in. */ 918 1.1 mrg if (Rb == SP_REGNUM && Re == SP_REGNUM) 919 1.1 mrg num_use_regs = extra_count; 920 1.1 mrg else 921 1.1 mrg num_use_regs = Re - Rb + 1 + extra_count; 922 1.1 mrg 923 1.1 mrg /* In addition to used registers, 924 1.1 mrg we need one more space for (set sp sp+x) rtx. */ 925 1.1 mrg parallel_insn = gen_rtx_PARALLEL (VOIDmode, 926 1.1 mrg rtvec_alloc (num_use_regs + 1)); 927 1.1 mrg par_index = 0; 928 1.1 mrg 929 1.1 mrg /* Initialize offset and start to create pop behavior. */ 930 1.1 mrg offset = 0; 931 1.1 mrg 932 1.1 mrg /* Create (set regX mem) from Rb, Rb+1 up to Re. */ 933 1.1 mrg for (regno = Rb; regno <= Re; regno++) 934 1.1 mrg { 935 1.1 mrg /* Rb and Re may be SP_REGNUM. 936 1.1 mrg We need to break this loop immediately. */ 937 1.1 mrg if (regno == SP_REGNUM) 938 1.1 mrg break; 939 1.1 mrg 940 1.1 mrg reg = gen_rtx_REG (SImode, regno); 941 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 942 1.1 mrg stack_pointer_rtx, 943 1.1 mrg offset)); 944 1.1 mrg pop_rtx = gen_rtx_SET (reg, mem); 945 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = pop_rtx; 946 1.1 mrg RTX_FRAME_RELATED_P (pop_rtx) = 1; 947 1.1 mrg offset = offset + 4; 948 1.1 mrg par_index++; 949 1.1 mrg 950 1.1 mrg dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); 951 1.1 mrg } 952 1.1 mrg 953 1.1 mrg /* Create (set fp mem), (set gp mem), and (set lp mem) if necessary. */ 954 1.1 mrg if (save_fp_p) 955 1.1 mrg { 956 1.1 mrg reg = gen_rtx_REG (SImode, FP_REGNUM); 957 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 958 1.1 mrg stack_pointer_rtx, 959 1.1 mrg offset)); 960 1.1 mrg pop_rtx = gen_rtx_SET (reg, mem); 961 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = pop_rtx; 962 1.1 mrg RTX_FRAME_RELATED_P (pop_rtx) = 1; 963 1.1 mrg offset = offset + 4; 964 1.1 mrg par_index++; 965 1.1 mrg 966 1.1 mrg dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); 967 1.1 mrg } 968 1.1 mrg if (save_gp_p) 969 1.1 mrg { 970 1.1 mrg reg = gen_rtx_REG (SImode, GP_REGNUM); 971 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 972 1.1 mrg stack_pointer_rtx, 973 1.1 mrg offset)); 974 1.1 mrg pop_rtx = gen_rtx_SET (reg, mem); 975 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = pop_rtx; 976 1.1 mrg RTX_FRAME_RELATED_P (pop_rtx) = 1; 977 1.1 mrg offset = offset + 4; 978 1.1 mrg par_index++; 979 1.1 mrg 980 1.1 mrg dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); 981 1.1 mrg } 982 1.1 mrg if (save_lp_p) 983 1.1 mrg { 984 1.1 mrg reg = gen_rtx_REG (SImode, LP_REGNUM); 985 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 986 1.1 mrg stack_pointer_rtx, 987 1.1 mrg offset)); 988 1.1 mrg pop_rtx = gen_rtx_SET (reg, mem); 989 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = pop_rtx; 990 1.1 mrg RTX_FRAME_RELATED_P (pop_rtx) = 1; 991 1.1 mrg offset = offset + 4; 992 1.1 mrg par_index++; 993 1.1 mrg 994 1.1 mrg dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); 995 1.1 mrg } 996 1.1 mrg 997 1.1 mrg /* Create (set sp sp+x). */ 998 1.1 mrg 999 1.1 mrg /* The offset value is already in place. No need to re-calculate it. */ 1000 1.1 mrg adjust_sp_rtx 1001 1.1 mrg = gen_rtx_SET (stack_pointer_rtx, 1002 1.1 mrg plus_constant (Pmode, stack_pointer_rtx, offset)); 1003 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = adjust_sp_rtx; 1004 1.1 mrg 1005 1.1 mrg /* Tell gcc we adjust SP in this insn. */ 1006 1.1 mrg dwarf = alloc_reg_note (REG_CFA_ADJUST_CFA, copy_rtx (adjust_sp_rtx), dwarf); 1007 1.1 mrg 1008 1.1 mrg parallel_insn = emit_insn (parallel_insn); 1009 1.1 mrg 1010 1.1 mrg /* The insn rtx 'parallel_insn' will change frame layout. 1011 1.1 mrg We need to use RTX_FRAME_RELATED_P so that GCC is able to 1012 1.1 mrg generate CFI (Call Frame Information) stuff. */ 1013 1.1 mrg RTX_FRAME_RELATED_P (parallel_insn) = 1; 1014 1.1 mrg 1015 1.1 mrg /* Add CFI info by manual. */ 1016 1.1 mrg REG_NOTES (parallel_insn) = dwarf; 1017 1.1 mrg } 1018 1.1 mrg 1019 1.1 mrg /* Function to create a parallel rtx pattern 1020 1.1 mrg which presents stack v3push behavior. 1021 1.1 mrg The overall concept are: 1022 1.1 mrg "push registers to memory", 1023 1.1 mrg "adjust stack pointer". */ 1024 1.1 mrg static void 1025 1.1 mrg nds32_emit_stack_v3push (unsigned Rb, 1026 1.1 mrg unsigned Re, 1027 1.1 mrg unsigned imm8u) 1028 1.1 mrg { 1029 1.1 mrg unsigned regno; 1030 1.1 mrg int num_use_regs; 1031 1.1 mrg int par_index; 1032 1.1 mrg int offset; 1033 1.1 mrg 1034 1.1 mrg rtx reg; 1035 1.1 mrg rtx mem; 1036 1.1 mrg rtx push_rtx; 1037 1.1 mrg rtx adjust_sp_rtx; 1038 1.1 mrg rtx parallel_insn; 1039 1.1 mrg 1040 1.1 mrg /* We need to provide a customized rtx which contains 1041 1.1 mrg necessary information for data analysis, 1042 1.1 mrg so we create a parallel rtx like this: 1043 1.1 mrg (parallel [(set (mem (plus (reg:SI SP_REGNUM) (const_int -32))) 1044 1.1 mrg (reg:SI Rb)) 1045 1.1 mrg (set (mem (plus (reg:SI SP_REGNUM) (const_int -28))) 1046 1.1 mrg (reg:SI Rb+1)) 1047 1.1 mrg ... 1048 1.1 mrg (set (mem (plus (reg:SI SP_REGNUM) (const_int -16))) 1049 1.1 mrg (reg:SI Re)) 1050 1.1 mrg (set (mem (plus (reg:SI SP_REGNUM) (const_int -12))) 1051 1.1 mrg (reg:SI FP_REGNUM)) 1052 1.1 mrg (set (mem (plus (reg:SI SP_REGNUM) (const_int -8))) 1053 1.1 mrg (reg:SI GP_REGNUM)) 1054 1.1 mrg (set (mem (plus (reg:SI SP_REGNUM) (const_int -4))) 1055 1.1 mrg (reg:SI LP_REGNUM)) 1056 1.1 mrg (set (reg:SI SP_REGNUM) 1057 1.1 mrg (plus (reg:SI SP_REGNUM) (const_int -32-imm8u)))]) */ 1058 1.1 mrg 1059 1.1 mrg /* Calculate the number of registers that will be pushed. 1060 1.1 mrg Since $fp, $gp, and $lp is always pushed with v3push instruction, 1061 1.1 mrg we need to count these three registers. 1062 1.1 mrg Under v3push, Rb is $r6, while Re is $r6, $r8, $r10, or $r14. 1063 1.1 mrg So there is no need to worry about Rb=Re=SP_REGNUM case. */ 1064 1.1 mrg num_use_regs = Re - Rb + 1 + 3; 1065 1.1 mrg 1066 1.1 mrg /* In addition to used registers, 1067 1.1 mrg we need one more space for (set sp sp-x-imm8u) rtx. */ 1068 1.1 mrg parallel_insn = gen_rtx_PARALLEL (VOIDmode, 1069 1.1 mrg rtvec_alloc (num_use_regs + 1)); 1070 1.1 mrg par_index = 0; 1071 1.1 mrg 1072 1.1 mrg /* Initialize offset and start to create push behavior. */ 1073 1.1 mrg offset = -(num_use_regs * 4); 1074 1.1 mrg 1075 1.1 mrg /* Create (set mem regX) from Rb, Rb+1 up to Re. 1076 1.1 mrg Under v3push, Rb is $r6, while Re is $r6, $r8, $r10, or $r14. 1077 1.1 mrg So there is no need to worry about Rb=Re=SP_REGNUM case. */ 1078 1.1 mrg for (regno = Rb; regno <= Re; regno++) 1079 1.1 mrg { 1080 1.1 mrg reg = gen_rtx_REG (SImode, regno); 1081 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 1082 1.1 mrg stack_pointer_rtx, 1083 1.1 mrg offset)); 1084 1.1 mrg push_rtx = gen_rtx_SET (mem, reg); 1085 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = push_rtx; 1086 1.1 mrg RTX_FRAME_RELATED_P (push_rtx) = 1; 1087 1.1 mrg offset = offset + 4; 1088 1.1 mrg par_index++; 1089 1.1 mrg } 1090 1.1 mrg 1091 1.1 mrg /* Create (set mem fp). */ 1092 1.1 mrg reg = gen_rtx_REG (SImode, FP_REGNUM); 1093 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 1094 1.1 mrg stack_pointer_rtx, 1095 1.1 mrg offset)); 1096 1.1 mrg push_rtx = gen_rtx_SET (mem, reg); 1097 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = push_rtx; 1098 1.1 mrg RTX_FRAME_RELATED_P (push_rtx) = 1; 1099 1.1 mrg offset = offset + 4; 1100 1.1 mrg par_index++; 1101 1.1 mrg /* Create (set mem gp). */ 1102 1.1 mrg reg = gen_rtx_REG (SImode, GP_REGNUM); 1103 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 1104 1.1 mrg stack_pointer_rtx, 1105 1.1 mrg offset)); 1106 1.1 mrg push_rtx = gen_rtx_SET (mem, reg); 1107 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = push_rtx; 1108 1.1 mrg RTX_FRAME_RELATED_P (push_rtx) = 1; 1109 1.1 mrg offset = offset + 4; 1110 1.1 mrg par_index++; 1111 1.1 mrg /* Create (set mem lp). */ 1112 1.1 mrg reg = gen_rtx_REG (SImode, LP_REGNUM); 1113 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 1114 1.1 mrg stack_pointer_rtx, 1115 1.1 mrg offset)); 1116 1.1 mrg push_rtx = gen_rtx_SET (mem, reg); 1117 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = push_rtx; 1118 1.1 mrg RTX_FRAME_RELATED_P (push_rtx) = 1; 1119 1.1 mrg offset = offset + 4; 1120 1.1 mrg par_index++; 1121 1.1 mrg 1122 1.1 mrg /* Create (set sp sp-x-imm8u). */ 1123 1.1 mrg 1124 1.1 mrg /* We need to re-calculate the offset value again for adjustment. */ 1125 1.1 mrg offset = -(num_use_regs * 4); 1126 1.1 mrg adjust_sp_rtx 1127 1.1 mrg = gen_rtx_SET (stack_pointer_rtx, 1128 1.1 mrg plus_constant (Pmode, 1129 1.1 mrg stack_pointer_rtx, 1130 1.1 mrg offset - imm8u)); 1131 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = adjust_sp_rtx; 1132 1.1 mrg RTX_FRAME_RELATED_P (adjust_sp_rtx) = 1; 1133 1.1 mrg 1134 1.1 mrg parallel_insn = emit_insn (parallel_insn); 1135 1.1 mrg 1136 1.1 mrg /* The insn rtx 'parallel_insn' will change frame layout. 1137 1.1 mrg We need to use RTX_FRAME_RELATED_P so that GCC is able to 1138 1.1 mrg generate CFI (Call Frame Information) stuff. */ 1139 1.1 mrg RTX_FRAME_RELATED_P (parallel_insn) = 1; 1140 1.1 mrg } 1141 1.1 mrg 1142 1.1 mrg /* Function to create a parallel rtx pattern 1143 1.1 mrg which presents stack v3pop behavior. 1144 1.1 mrg The overall concept are: 1145 1.1 mrg "pop registers from memory", 1146 1.1 mrg "adjust stack pointer". */ 1147 1.1 mrg static void 1148 1.1 mrg nds32_emit_stack_v3pop (unsigned Rb, 1149 1.1 mrg unsigned Re, 1150 1.1 mrg unsigned imm8u) 1151 1.1 mrg { 1152 1.1 mrg unsigned regno; 1153 1.1 mrg int num_use_regs; 1154 1.1 mrg int par_index; 1155 1.1 mrg int offset; 1156 1.1 mrg 1157 1.1 mrg rtx reg; 1158 1.1 mrg rtx mem; 1159 1.1 mrg rtx pop_rtx; 1160 1.1 mrg rtx adjust_sp_rtx; 1161 1.1 mrg rtx parallel_insn; 1162 1.1 mrg rtx dwarf = NULL_RTX; 1163 1.1 mrg 1164 1.1 mrg /* We need to provide a customized rtx which contains 1165 1.1 mrg necessary information for data analysis, 1166 1.1 mrg so we create a parallel rtx like this: 1167 1.1 mrg (parallel [(set (reg:SI Rb) 1168 1.1 mrg (mem (reg:SI SP_REGNUM))) 1169 1.1 mrg (set (reg:SI Rb+1) 1170 1.1 mrg (mem (plus (reg:SI SP_REGNUM) (const_int 4)))) 1171 1.1 mrg ... 1172 1.1 mrg (set (reg:SI Re) 1173 1.1 mrg (mem (plus (reg:SI SP_REGNUM) (const_int 16)))) 1174 1.1 mrg (set (reg:SI FP_REGNUM) 1175 1.1 mrg (mem (plus (reg:SI SP_REGNUM) (const_int 20)))) 1176 1.1 mrg (set (reg:SI GP_REGNUM) 1177 1.1 mrg (mem (plus (reg:SI SP_REGNUM) (const_int 24)))) 1178 1.1 mrg (set (reg:SI LP_REGNUM) 1179 1.1 mrg (mem (plus (reg:SI SP_REGNUM) (const_int 28)))) 1180 1.1 mrg (set (reg:SI SP_REGNUM) 1181 1.1 mrg (plus (reg:SI SP_REGNUM) (const_int 32+imm8u)))]) */ 1182 1.1 mrg 1183 1.1 mrg /* Calculate the number of registers that will be poped. 1184 1.1 mrg Since $fp, $gp, and $lp is always poped with v3pop instruction, 1185 1.1 mrg we need to count these three registers. 1186 1.1 mrg Under v3push, Rb is $r6, while Re is $r6, $r8, $r10, or $r14. 1187 1.1 mrg So there is no need to worry about Rb=Re=SP_REGNUM case. */ 1188 1.1 mrg num_use_regs = Re - Rb + 1 + 3; 1189 1.1 mrg 1190 1.1 mrg /* In addition to used registers, 1191 1.1 mrg we need one more space for (set sp sp+x+imm8u) rtx. */ 1192 1.1 mrg parallel_insn = gen_rtx_PARALLEL (VOIDmode, 1193 1.1 mrg rtvec_alloc (num_use_regs + 1)); 1194 1.1 mrg par_index = 0; 1195 1.1 mrg 1196 1.1 mrg /* Initialize offset and start to create pop behavior. */ 1197 1.1 mrg offset = 0; 1198 1.1 mrg 1199 1.1 mrg /* Create (set regX mem) from Rb, Rb+1 up to Re. 1200 1.1 mrg Under v3pop, Rb is $r6, while Re is $r6, $r8, $r10, or $r14. 1201 1.1 mrg So there is no need to worry about Rb=Re=SP_REGNUM case. */ 1202 1.1 mrg for (regno = Rb; regno <= Re; regno++) 1203 1.1 mrg { 1204 1.1 mrg reg = gen_rtx_REG (SImode, regno); 1205 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 1206 1.1 mrg stack_pointer_rtx, 1207 1.1 mrg offset)); 1208 1.1 mrg pop_rtx = gen_rtx_SET (reg, mem); 1209 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = pop_rtx; 1210 1.1 mrg RTX_FRAME_RELATED_P (pop_rtx) = 1; 1211 1.1 mrg offset = offset + 4; 1212 1.1 mrg par_index++; 1213 1.1 mrg 1214 1.1 mrg dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); 1215 1.1 mrg } 1216 1.1 mrg 1217 1.1 mrg /* Create (set fp mem). */ 1218 1.1 mrg reg = gen_rtx_REG (SImode, FP_REGNUM); 1219 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 1220 1.1 mrg stack_pointer_rtx, 1221 1.1 mrg offset)); 1222 1.1 mrg pop_rtx = gen_rtx_SET (reg, mem); 1223 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = pop_rtx; 1224 1.1 mrg RTX_FRAME_RELATED_P (pop_rtx) = 1; 1225 1.1 mrg offset = offset + 4; 1226 1.1 mrg par_index++; 1227 1.1 mrg dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); 1228 1.1 mrg 1229 1.1 mrg /* Create (set gp mem). */ 1230 1.1 mrg reg = gen_rtx_REG (SImode, GP_REGNUM); 1231 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 1232 1.1 mrg stack_pointer_rtx, 1233 1.1 mrg offset)); 1234 1.1 mrg pop_rtx = gen_rtx_SET (reg, mem); 1235 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = pop_rtx; 1236 1.1 mrg RTX_FRAME_RELATED_P (pop_rtx) = 1; 1237 1.1 mrg offset = offset + 4; 1238 1.1 mrg par_index++; 1239 1.1 mrg dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); 1240 1.1 mrg 1241 1.1 mrg /* Create (set lp mem ). */ 1242 1.1 mrg reg = gen_rtx_REG (SImode, LP_REGNUM); 1243 1.1 mrg mem = gen_frame_mem (SImode, plus_constant (Pmode, 1244 1.1 mrg stack_pointer_rtx, 1245 1.1 mrg offset)); 1246 1.1 mrg pop_rtx = gen_rtx_SET (reg, mem); 1247 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = pop_rtx; 1248 1.1 mrg RTX_FRAME_RELATED_P (pop_rtx) = 1; 1249 1.1 mrg offset = offset + 4; 1250 1.1 mrg par_index++; 1251 1.1 mrg dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); 1252 1.1 mrg 1253 1.1 mrg /* Create (set sp sp+x+imm8u). */ 1254 1.1 mrg 1255 1.1 mrg /* The offset value is already in place. No need to re-calculate it. */ 1256 1.1 mrg adjust_sp_rtx 1257 1.1 mrg = gen_rtx_SET (stack_pointer_rtx, 1258 1.1 mrg plus_constant (Pmode, 1259 1.1 mrg stack_pointer_rtx, 1260 1.1 mrg offset + imm8u)); 1261 1.1 mrg XVECEXP (parallel_insn, 0, par_index) = adjust_sp_rtx; 1262 1.1 mrg 1263 1.1 mrg if (frame_pointer_needed) 1264 1.1 mrg { 1265 1.1 mrg /* (expr_list:REG_CFA_DEF_CFA (plus:SI (reg/f:SI $sp) 1266 1.1 mrg (const_int 0)) 1267 1.1 mrg mean reset frame pointer to $sp and reset to offset 0. */ 1268 1.1 mrg rtx cfa_adjust_rtx = gen_rtx_PLUS (Pmode, stack_pointer_rtx, 1269 1.1 mrg const0_rtx); 1270 1.1 mrg dwarf = alloc_reg_note (REG_CFA_DEF_CFA, cfa_adjust_rtx, dwarf); 1271 1.1 mrg } 1272 1.1 mrg else 1273 1.1 mrg { 1274 1.1 mrg /* Tell gcc we adjust SP in this insn. */ 1275 1.1 mrg dwarf = alloc_reg_note (REG_CFA_ADJUST_CFA, 1276 1.1 mrg copy_rtx (adjust_sp_rtx), dwarf); 1277 1.1 mrg } 1278 1.1 mrg 1279 1.1 mrg parallel_insn = emit_insn (parallel_insn); 1280 1.1 mrg 1281 1.1 mrg /* The insn rtx 'parallel_insn' will change frame layout. 1282 1.1 mrg We need to use RTX_FRAME_RELATED_P so that GCC is able to 1283 1.1 mrg generate CFI (Call Frame Information) stuff. */ 1284 1.1 mrg RTX_FRAME_RELATED_P (parallel_insn) = 1; 1285 1.1 mrg 1286 1.1 mrg /* Add CFI info by manual. */ 1287 1.1 mrg REG_NOTES (parallel_insn) = dwarf; 1288 1.1 mrg } 1289 1.1 mrg 1290 1.1 mrg static void 1291 1.1 mrg nds32_emit_load_gp (void) 1292 1.1 mrg { 1293 1.1 mrg rtx got_symbol, pat; 1294 1.1 mrg 1295 1.1 mrg /* Initial GLOBAL OFFSET TABLE don't do the scheduling. */ 1296 1.1 mrg emit_insn (gen_blockage ()); 1297 1.1 mrg 1298 1.1 mrg got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_"); 1299 1.1 mrg /* sethi $gp, _GLOBAL_OFFSET_TABLE_ -8 */ 1300 1.1 mrg pat = gen_rtx_UNSPEC (SImode, gen_rtvec (1, got_symbol), UNSPEC_GOTINIT); 1301 1.1 mrg pat = gen_rtx_CONST (SImode, gen_rtx_PLUS (Pmode, pat, GEN_INT (-8))); 1302 1.1 mrg emit_insn (gen_sethi (pic_offset_table_rtx,pat)); 1303 1.1 mrg 1304 1.1 mrg /* ori $gp, $gp, _GLOBAL_OFFSET_TABLE_ -4 */ 1305 1.1 mrg pat = gen_rtx_UNSPEC (SImode, gen_rtvec (1, got_symbol), UNSPEC_GOTINIT); 1306 1.1 mrg pat = gen_rtx_CONST (SImode, gen_rtx_PLUS (Pmode, pat, GEN_INT (-4))); 1307 1.1 mrg emit_insn (gen_lo_sum (pic_offset_table_rtx, pic_offset_table_rtx, pat)); 1308 1.1 mrg 1309 1.1 mrg /* add5.pc $gp */ 1310 1.1 mrg emit_insn (gen_add_pc (pic_offset_table_rtx, pic_offset_table_rtx)); 1311 1.1 mrg 1312 1.1 mrg /* Initial GLOBAL OFFSET TABLE don't do the scheduling. */ 1313 1.1 mrg emit_insn (gen_blockage ()); 1314 1.1 mrg } 1315 1.1 mrg 1316 1.1 mrg /* Function that may creates more instructions 1317 1.1 mrg for large value on adjusting stack pointer. 1318 1.1 mrg 1319 1.1 mrg In nds32 target, 'addi' can be used for stack pointer 1320 1.1 mrg adjustment in prologue/epilogue stage. 1321 1.1 mrg However, sometimes there are too many local variables so that 1322 1.1 mrg the adjustment value is not able to be fit in the 'addi' instruction. 1323 1.1 mrg One solution is to move value into a register 1324 1.1 mrg and then use 'add' instruction. 1325 1.1 mrg In practice, we use TA_REGNUM ($r15) to accomplish this purpose. */ 1326 1.1 mrg static void 1327 1.1 mrg nds32_emit_adjust_frame (rtx to_reg, rtx from_reg, int adjust_value) 1328 1.1 mrg { 1329 1.1 mrg rtx tmp_reg; 1330 1.1 mrg rtx frame_adjust_insn; 1331 1.1 mrg rtx adjust_value_rtx = GEN_INT (adjust_value); 1332 1.1 mrg 1333 1.1 mrg if (adjust_value == 0) 1334 1.1 mrg return; 1335 1.1 mrg 1336 1.1 mrg if (!satisfies_constraint_Is15 (adjust_value_rtx)) 1337 1.1 mrg { 1338 1.1 mrg /* The value is not able to fit in single addi instruction. 1339 1.1 mrg Create more instructions of moving value into a register 1340 1.1 mrg and then add stack pointer with it. */ 1341 1.1 mrg 1342 1.1 mrg /* $r15 is going to be temporary register to hold the value. */ 1343 1.1 mrg tmp_reg = gen_rtx_REG (SImode, TA_REGNUM); 1344 1.1 mrg 1345 1.1 mrg /* Create one more instruction to move value 1346 1.1 mrg into the temporary register. */ 1347 1.1 mrg emit_move_insn (tmp_reg, adjust_value_rtx); 1348 1.1 mrg 1349 1.1 mrg /* Create new 'add' rtx. */ 1350 1.1 mrg frame_adjust_insn = gen_addsi3 (to_reg, 1351 1.1 mrg from_reg, 1352 1.1 mrg tmp_reg); 1353 1.1 mrg /* Emit rtx into insn list and receive its transformed insn rtx. */ 1354 1.1 mrg frame_adjust_insn = emit_insn (frame_adjust_insn); 1355 1.1 mrg 1356 1.1 mrg /* Because (tmp_reg <- full_value) may be split into two 1357 1.1 mrg rtl patterns, we cannot set its RTX_FRAME_RELATED_P. 1358 1.1 mrg We need to construct another (sp <- sp + full_value) 1359 1.1 mrg and then insert it into sp_adjust_insn's reg note to 1360 1.1 mrg represent a frame related expression. 1361 1.1 mrg GCC knows how to refer it and output debug information. */ 1362 1.1 mrg 1363 1.1 mrg rtx plus_rtx; 1364 1.1 mrg rtx set_rtx; 1365 1.1 mrg 1366 1.1 mrg plus_rtx = plus_constant (Pmode, from_reg, adjust_value); 1367 1.1 mrg set_rtx = gen_rtx_SET (to_reg, plus_rtx); 1368 1.1 mrg add_reg_note (frame_adjust_insn, REG_FRAME_RELATED_EXPR, set_rtx); 1369 1.1 mrg } 1370 1.1 mrg else 1371 1.1 mrg { 1372 1.1 mrg /* Generate sp adjustment instruction if and only if sp_adjust != 0. */ 1373 1.1 mrg frame_adjust_insn = gen_addsi3 (to_reg, 1374 1.1 mrg from_reg, 1375 1.1 mrg adjust_value_rtx); 1376 1.1 mrg /* Emit rtx into instructions list and receive INSN rtx form. */ 1377 1.1 mrg frame_adjust_insn = emit_insn (frame_adjust_insn); 1378 1.1 mrg } 1379 1.1 mrg 1380 1.1 mrg /* The insn rtx 'sp_adjust_insn' will change frame layout. 1381 1.1 mrg We need to use RTX_FRAME_RELATED_P so that GCC is able to 1382 1.1 mrg generate CFI (Call Frame Information) stuff. */ 1383 1.1 mrg RTX_FRAME_RELATED_P (frame_adjust_insn) = 1; 1384 1.1 mrg } 1385 1.1 mrg 1386 1.1 mrg /* Return true if MODE/TYPE need double word alignment. */ 1387 1.1 mrg static bool 1388 1.1 mrg nds32_needs_double_word_align (machine_mode mode, const_tree type) 1389 1.1 mrg { 1390 1.1 mrg unsigned int align; 1391 1.1 mrg 1392 1.1 mrg /* Pick up the alignment according to the mode or type. */ 1393 1.1 mrg align = NDS32_MODE_TYPE_ALIGN (mode, type); 1394 1.1 mrg 1395 1.1 mrg return (align > PARM_BOUNDARY); 1396 1.1 mrg } 1397 1.1 mrg 1398 1.1 mrg /* Return true if FUNC is a naked function. */ 1399 1.1 mrg bool 1400 1.1 mrg nds32_naked_function_p (tree func) 1401 1.1 mrg { 1402 1.1 mrg /* FOR BACKWARD COMPATIBILITY, 1403 1.1 mrg we need to support 'no_prologue' attribute as well. */ 1404 1.1 mrg tree t_naked; 1405 1.1 mrg tree t_no_prologue; 1406 1.1 mrg 1407 1.1 mrg if (TREE_CODE (func) != FUNCTION_DECL) 1408 1.1 mrg abort (); 1409 1.1 mrg 1410 1.1 mrg /* We have to use lookup_attribute() to check attributes. 1411 1.1 mrg Because attr_naked_p and attr_no_prologue_p are set in 1412 1.1 mrg nds32_compute_stack_frame() and the function has not been 1413 1.1 mrg invoked yet. */ 1414 1.1 mrg t_naked = lookup_attribute ("naked", DECL_ATTRIBUTES (func)); 1415 1.1 mrg t_no_prologue = lookup_attribute ("no_prologue", DECL_ATTRIBUTES (func)); 1416 1.1 mrg 1417 1.1 mrg return ((t_naked != NULL_TREE) || (t_no_prologue != NULL_TREE)); 1418 1.1 mrg } 1419 1.1 mrg 1420 1.1 mrg /* Function that determine whether a load postincrement is a good thing to use 1421 1.1 mrg for a given mode. */ 1422 1.1 mrg bool 1423 1.1 mrg nds32_use_load_post_increment (machine_mode mode) 1424 1.1 mrg { 1425 1.1 mrg return (GET_MODE_SIZE (mode) <= GET_MODE_SIZE(E_DImode)); 1426 1.1 mrg } 1427 1.1 mrg 1428 1.1 mrg /* Function that check if 'X' is a valid address register. 1429 1.1 mrg The variable 'STRICT' is very important to 1430 1.1 mrg make decision for register number. 1431 1.1 mrg 1432 1.1 mrg STRICT : true 1433 1.1 mrg => We are in reload pass or after reload pass. 1434 1.1 mrg The register number should be strictly limited in general registers. 1435 1.1 mrg 1436 1.1 mrg STRICT : false 1437 1.1 mrg => Before reload pass, we are free to use any register number. */ 1438 1.1 mrg static bool 1439 1.1 mrg nds32_address_register_rtx_p (rtx x, bool strict) 1440 1.1 mrg { 1441 1.1 mrg int regno; 1442 1.1 mrg 1443 1.1 mrg if (GET_CODE (x) != REG) 1444 1.1 mrg return false; 1445 1.1 mrg 1446 1.1 mrg regno = REGNO (x); 1447 1.1 mrg 1448 1.1 mrg if (strict) 1449 1.1 mrg return REGNO_OK_FOR_BASE_P (regno); 1450 1.1 mrg else 1451 1.1 mrg return true; 1452 1.1 mrg } 1453 1.1 mrg 1454 1.1 mrg /* Function that check if 'INDEX' is valid to be a index rtx for address. 1455 1.1 mrg 1456 1.1 mrg OUTER_MODE : Machine mode of outer address rtx. 1457 1.1 mrg INDEX : Check if this rtx is valid to be a index for address. 1458 1.1 mrg STRICT : If it is true, we are in reload pass or after reload pass. */ 1459 1.1 mrg static bool 1460 1.1 mrg nds32_legitimate_index_p (machine_mode outer_mode, 1461 1.1 mrg rtx index, 1462 1.1 mrg bool strict) 1463 1.1 mrg { 1464 1.1 mrg int regno; 1465 1.1 mrg rtx op0; 1466 1.1 mrg rtx op1; 1467 1.1 mrg 1468 1.1 mrg switch (GET_CODE (index)) 1469 1.1 mrg { 1470 1.1 mrg case REG: 1471 1.1 mrg regno = REGNO (index); 1472 1.1 mrg /* If we are in reload pass or after reload pass, 1473 1.1 mrg we need to limit it to general register. */ 1474 1.1 mrg if (strict) 1475 1.1 mrg return REGNO_OK_FOR_INDEX_P (regno); 1476 1.1 mrg else 1477 1.1 mrg return true; 1478 1.1 mrg 1479 1.1 mrg case CONST_INT: 1480 1.1 mrg /* The alignment of the integer value is determined by 'outer_mode'. */ 1481 1.1 mrg switch (GET_MODE_SIZE (outer_mode)) 1482 1.1 mrg { 1483 1.1 mrg case 1: 1484 1.1 mrg /* Further check if the value is legal for the 'outer_mode'. */ 1485 1.1 mrg if (satisfies_constraint_Is15 (index)) 1486 1.1 mrg return true; 1487 1.1 mrg break; 1488 1.1 mrg 1489 1.1 mrg case 2: 1490 1.1 mrg /* Further check if the value is legal for the 'outer_mode'. */ 1491 1.1 mrg if (satisfies_constraint_Is16 (index)) 1492 1.1 mrg { 1493 1.1 mrg /* If it is not under strictly aligned situation, 1494 1.1 mrg we can return true without checking alignment. */ 1495 1.1 mrg if (!cfun->machine->strict_aligned_p) 1496 1.1 mrg return true; 1497 1.1 mrg /* Make sure address is half word alignment. */ 1498 1.1 mrg else if (NDS32_HALF_WORD_ALIGN_P (INTVAL (index))) 1499 1.1 mrg return true; 1500 1.1 mrg } 1501 1.1 mrg break; 1502 1.1 mrg 1503 1.1 mrg case 4: 1504 1.1 mrg /* Further check if the value is legal for the 'outer_mode'. */ 1505 1.1 mrg if (satisfies_constraint_Is17 (index)) 1506 1.1 mrg { 1507 1.1 mrg if ((TARGET_FPU_SINGLE || TARGET_FPU_DOUBLE)) 1508 1.1 mrg { 1509 1.1 mrg if (!satisfies_constraint_Is14 (index)) 1510 1.1 mrg return false; 1511 1.1 mrg } 1512 1.1 mrg 1513 1.1 mrg /* If it is not under strictly aligned situation, 1514 1.1 mrg we can return true without checking alignment. */ 1515 1.1 mrg if (!cfun->machine->strict_aligned_p) 1516 1.1 mrg return true; 1517 1.1 mrg /* Make sure address is word alignment. */ 1518 1.1 mrg else if (NDS32_SINGLE_WORD_ALIGN_P (INTVAL (index))) 1519 1.1 mrg return true; 1520 1.1 mrg } 1521 1.1 mrg break; 1522 1.1 mrg 1523 1.1 mrg case 8: 1524 1.1 mrg if (satisfies_constraint_Is17 (gen_int_mode (INTVAL (index) + 4, 1525 1.1 mrg SImode))) 1526 1.1 mrg { 1527 1.1 mrg if ((TARGET_FPU_SINGLE || TARGET_FPU_DOUBLE)) 1528 1.1 mrg { 1529 1.1 mrg if (!satisfies_constraint_Is14 (index)) 1530 1.1 mrg return false; 1531 1.1 mrg } 1532 1.1 mrg 1533 1.1 mrg /* If it is not under strictly aligned situation, 1534 1.1 mrg we can return true without checking alignment. */ 1535 1.1 mrg if (!cfun->machine->strict_aligned_p) 1536 1.1 mrg return true; 1537 1.1 mrg /* Make sure address is word alignment. 1538 1.1 mrg Currently we do not have 64-bit load/store yet, 1539 1.1 mrg so we will use two 32-bit load/store instructions to do 1540 1.1 mrg memory access and they are single word alignment. */ 1541 1.1 mrg else if (NDS32_SINGLE_WORD_ALIGN_P (INTVAL (index))) 1542 1.1 mrg return true; 1543 1.1 mrg } 1544 1.1 mrg break; 1545 1.1 mrg 1546 1.1 mrg default: 1547 1.1 mrg return false; 1548 1.1 mrg } 1549 1.1 mrg 1550 1.1 mrg return false; 1551 1.1 mrg 1552 1.1 mrg case MULT: 1553 1.1 mrg op0 = XEXP (index, 0); 1554 1.1 mrg op1 = XEXP (index, 1); 1555 1.1 mrg 1556 1.1 mrg if (REG_P (op0) && CONST_INT_P (op1)) 1557 1.1 mrg { 1558 1.1 mrg int multiplier; 1559 1.1 mrg multiplier = INTVAL (op1); 1560 1.1 mrg 1561 1.1 mrg /* We only allow (mult reg const_int_1), (mult reg const_int_2), 1562 1.1 mrg (mult reg const_int_4) or (mult reg const_int_8). */ 1563 1.1 mrg if (multiplier != 1 && multiplier != 2 1564 1.1 mrg && multiplier != 4 && multiplier != 8) 1565 1.1 mrg return false; 1566 1.1 mrg 1567 1.1 mrg regno = REGNO (op0); 1568 1.1 mrg /* Limit it in general registers if we are 1569 1.1 mrg in reload pass or after reload pass. */ 1570 1.1 mrg if(strict) 1571 1.1 mrg return REGNO_OK_FOR_INDEX_P (regno); 1572 1.1 mrg else 1573 1.1 mrg return true; 1574 1.1 mrg } 1575 1.1 mrg 1576 1.1 mrg return false; 1577 1.1 mrg 1578 1.1 mrg case ASHIFT: 1579 1.1 mrg op0 = XEXP (index, 0); 1580 1.1 mrg op1 = XEXP (index, 1); 1581 1.1 mrg 1582 1.1 mrg if (REG_P (op0) && CONST_INT_P (op1)) 1583 1.1 mrg { 1584 1.1 mrg int sv; 1585 1.1 mrg /* op1 is already the sv value for use to do left shift. */ 1586 1.1 mrg sv = INTVAL (op1); 1587 1.1 mrg 1588 1.1 mrg /* We only allow (ashift reg const_int_0) 1589 1.1 mrg or (ashift reg const_int_1) or (ashift reg const_int_2) or 1590 1.1 mrg (ashift reg const_int_3). */ 1591 1.1 mrg if (sv != 0 && sv != 1 && sv !=2 && sv != 3) 1592 1.1 mrg return false; 1593 1.1 mrg 1594 1.1 mrg regno = REGNO (op0); 1595 1.1 mrg /* Limit it in general registers if we are 1596 1.1 mrg in reload pass or after reload pass. */ 1597 1.1 mrg if(strict) 1598 1.1 mrg return REGNO_OK_FOR_INDEX_P (regno); 1599 1.1 mrg else 1600 1.1 mrg return true; 1601 1.1 mrg } 1602 1.1 mrg 1603 1.1 mrg return false; 1604 1.1 mrg 1605 1.1 mrg default: 1606 1.1 mrg return false; 1607 1.1 mrg } 1608 1.1 mrg } 1609 1.1 mrg 1610 1.1 mrg static void 1611 1.1 mrg nds32_register_pass ( 1612 1.1 mrg rtl_opt_pass *(*make_pass_func) (gcc::context *), 1613 1.1 mrg enum pass_positioning_ops pass_pos, 1614 1.1 mrg const char *ref_pass_name) 1615 1.1 mrg { 1616 1.1 mrg opt_pass *new_opt_pass = make_pass_func (g); 1617 1.1 mrg 1618 1.1 mrg struct register_pass_info insert_pass = 1619 1.1 mrg { 1620 1.1 mrg new_opt_pass, /* pass */ 1621 1.1 mrg ref_pass_name, /* reference_pass_name */ 1622 1.1 mrg 1, /* ref_pass_instance_number */ 1623 1.1 mrg pass_pos /* po_op */ 1624 1.1 mrg }; 1625 1.1 mrg 1626 1.1 mrg register_pass (&insert_pass); 1627 1.1 mrg } 1628 1.1 mrg 1629 1.1 mrg /* This function is called from nds32_option_override (). 1630 1.1 mrg All new passes should be registered here. */ 1631 1.1 mrg static void 1632 1.1 mrg nds32_register_passes (void) 1633 1.1 mrg { 1634 1.1 mrg nds32_register_pass ( 1635 1.1 mrg make_pass_nds32_fp_as_gp, 1636 1.1 mrg PASS_POS_INSERT_BEFORE, 1637 1.1 mrg "ira"); 1638 1.1 mrg 1639 1.1 mrg nds32_register_pass ( 1640 1.1 mrg make_pass_nds32_relax_opt, 1641 1.1 mrg PASS_POS_INSERT_AFTER, 1642 1.1 mrg "mach"); 1643 1.1 mrg } 1644 1.1 mrg 1645 1.1 mrg /* ------------------------------------------------------------------------ */ 1646 1.1 mrg 1647 1.1 mrg /* PART 3: Implement target hook stuff definitions. */ 1648 1.1 mrg 1649 1.1 mrg 1651 1.1 mrg /* Computing the Length of an Insn. 1652 1.1 mrg Modifies the length assigned to instruction INSN. 1653 1.1 mrg LEN is the initially computed length of the insn. */ 1654 1.1 mrg int 1655 1.1 mrg nds32_adjust_insn_length (rtx_insn *insn, int length) 1656 1.1 mrg { 1657 1.1 mrg int adjust_value = 0; 1658 1.1 mrg switch (recog_memoized (insn)) 1659 1.1 mrg { 1660 1.1 mrg case CODE_FOR_call_internal: 1661 1.1 mrg case CODE_FOR_call_value_internal: 1662 1.1 mrg { 1663 1.1 mrg if (NDS32_ALIGN_P ()) 1664 1.1 mrg { 1665 1.1 mrg rtx_insn *next_insn = next_active_insn (insn); 1666 1.1 mrg if (next_insn && get_attr_length (next_insn) != 2) 1667 1.1 mrg adjust_value += 2; 1668 1.1 mrg } 1669 1.1 mrg /* We need insert a nop after a noretun function call 1670 1.1 mrg to prevent software breakpoint corrupt the next function. */ 1671 1.1 mrg if (find_reg_note (insn, REG_NORETURN, NULL_RTX)) 1672 1.1 mrg { 1673 1.1 mrg if (TARGET_16_BIT) 1674 1.1 mrg adjust_value += 2; 1675 1.1 mrg else 1676 1.1 mrg adjust_value += 4; 1677 1.1 mrg } 1678 1.1 mrg } 1679 1.1 mrg return length + adjust_value; 1680 1.1 mrg 1681 1.1 mrg default: 1682 1.1 mrg return length; 1683 1.1 mrg } 1684 1.1 mrg } 1685 1.1 mrg 1686 1.1 mrg /* Storage Layout. */ 1687 1.1 mrg 1688 1.1 mrg /* This function will be called just before expansion into rtl. */ 1689 1.1 mrg static void 1690 1.1 mrg nds32_expand_to_rtl_hook (void) 1691 1.1 mrg { 1692 1.1 mrg /* We need to set strictly aligned situation. 1693 1.1 mrg After that, the memory address checking in nds32_legitimate_address_p() 1694 1.1 mrg will take alignment offset into consideration so that it will not create 1695 1.1 mrg unaligned [base + offset] access during the rtl optimization. */ 1696 1.1 mrg cfun->machine->strict_aligned_p = 1; 1697 1.1 mrg } 1698 1.1 mrg 1699 1.1 mrg 1700 1.1 mrg /* Register Usage. */ 1702 1.1 mrg 1703 1.1 mrg static void 1704 1.1 mrg nds32_conditional_register_usage (void) 1705 1.1 mrg { 1706 1.1 mrg int regno; 1707 1.1 mrg 1708 1.1 mrg if (TARGET_LINUX_ABI) 1709 1.1 mrg fixed_regs[TP_REGNUM] = 1; 1710 1.1 mrg 1711 1.1 mrg if (TARGET_HARD_FLOAT) 1712 1.1 mrg { 1713 1.1 mrg for (regno = NDS32_FIRST_FPR_REGNUM; 1714 1.1 mrg regno <= NDS32_LAST_FPR_REGNUM; regno++) 1715 1.1 mrg { 1716 1.1 mrg fixed_regs[regno] = 0; 1717 1.1 mrg if (regno < NDS32_FIRST_FPR_REGNUM + NDS32_MAX_FPR_REGS_FOR_ARGS) 1718 1.1 mrg call_used_regs[regno] = 1; 1719 1.1 mrg else if (regno >= NDS32_FIRST_FPR_REGNUM + 22 1720 1.1 mrg && regno < NDS32_FIRST_FPR_REGNUM + 48) 1721 1.1 mrg call_used_regs[regno] = 1; 1722 1.1 mrg else 1723 1.1 mrg call_used_regs[regno] = 0; 1724 1.1 mrg } 1725 1.1 mrg } 1726 1.1 mrg else if (TARGET_FPU_SINGLE || TARGET_FPU_DOUBLE) 1727 1.1 mrg { 1728 1.1 mrg for (regno = NDS32_FIRST_FPR_REGNUM; 1729 1.1 mrg regno <= NDS32_LAST_FPR_REGNUM; 1730 1.1 mrg regno++) 1731 1.1 mrg fixed_regs[regno] = 0; 1732 1.1 mrg } 1733 1.1 mrg } 1734 1.1 mrg 1735 1.1 mrg 1736 1.1 mrg /* Register Classes. */ 1738 1.1 mrg 1739 1.1 mrg static unsigned char 1740 1.1 mrg nds32_class_max_nregs (reg_class_t rclass ATTRIBUTE_UNUSED, 1741 1.1 mrg machine_mode mode) 1742 1.1 mrg { 1743 1.1 mrg /* Return the maximum number of consecutive registers 1744 1.1 mrg needed to represent "mode" in a register of "rclass". */ 1745 1.1 mrg return ((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD); 1746 1.1 mrg } 1747 1.1 mrg 1748 1.1 mrg static int 1749 1.1 mrg nds32_register_priority (int hard_regno) 1750 1.1 mrg { 1751 1.1 mrg /* Encourage to use r0-r7 for LRA when optimize for size. */ 1752 1.1 mrg if (optimize_size) 1753 1.1 mrg { 1754 1.1 mrg if (hard_regno < 8) 1755 1.1 mrg return 4; 1756 1.1 mrg else if (hard_regno < 16) 1757 1.1 mrg return 3; 1758 1.1 mrg else if (hard_regno < 28) 1759 1.1 mrg return 2; 1760 1.1 mrg else 1761 1.1 mrg return 1; 1762 1.1 mrg } 1763 1.1 mrg else 1764 1.1 mrg { 1765 1.1 mrg if (hard_regno > 27) 1766 1.1 mrg return 1; 1767 1.1 mrg else 1768 1.1 mrg return 4; 1769 1.1 mrg } 1770 1.1 mrg } 1771 1.1 mrg 1772 1.1 mrg static bool 1773 1.1 mrg nds32_can_change_mode_class (machine_mode from, 1774 1.1 mrg machine_mode to, 1775 1.1 mrg reg_class_t rclass) 1776 1.1 mrg { 1777 1.1 mrg /* Don't spill double-precision register to two singal-precision 1778 1.1 mrg registers */ 1779 1.1 mrg if ((TARGET_FPU_SINGLE || TARGET_FPU_DOUBLE) 1780 1.1 mrg && GET_MODE_SIZE (from) != GET_MODE_SIZE (to)) 1781 1.1 mrg { 1782 1.1 mrg return !reg_classes_intersect_p (rclass, FP_REGS); 1783 1.1 mrg } 1784 1.1 mrg 1785 1.1 mrg return true; 1786 1.1 mrg } 1787 1.1 mrg 1788 1.1 mrg 1789 1.1 mrg /* Stack Layout and Calling Conventions. */ 1791 1.1 mrg 1792 1.1 mrg /* There are three kinds of pointer concepts using in GCC compiler: 1793 1.1 mrg 1794 1.1 mrg frame pointer: A pointer to the first location of local variables. 1795 1.1 mrg stack pointer: A pointer to the top of a stack frame. 1796 1.1 mrg argument pointer: A pointer to the incoming arguments. 1797 1.1 mrg 1798 1.1 mrg In nds32 target calling convention, we are using 8-byte alignment. 1799 1.1 mrg Besides, we would like to have each stack frame of a function includes: 1800 1.1 mrg 1801 1.1 mrg [Block A] 1802 1.1 mrg 1. previous hard frame pointer 1803 1.1 mrg 2. return address 1804 1.1 mrg 3. callee-saved registers 1805 1.1 mrg 4. <padding bytes> (we will calculte in nds32_compute_stack_frame() 1806 1.1 mrg and save it at 1807 1.1 mrg cfun->machine->callee_saved_area_padding_bytes) 1808 1.1 mrg 1809 1.1 mrg [Block B] 1810 1.1 mrg 1. local variables 1811 1.1 mrg 2. spilling location 1812 1.1 mrg 3. <padding bytes> (it will be calculated by GCC itself) 1813 1.1 mrg 4. incoming arguments 1814 1.1 mrg 5. <padding bytes> (it will be calculated by GCC itself) 1815 1.1 mrg 1816 1.1 mrg [Block C] 1817 1.1 mrg 1. <padding bytes> (it will be calculated by GCC itself) 1818 1.1 mrg 2. outgoing arguments 1819 1.1 mrg 1820 1.1 mrg We 'wrap' these blocks together with 1821 1.1 mrg hard frame pointer ($r28) and stack pointer ($r31). 1822 1.1 mrg By applying the basic frame/stack/argument pointers concept, 1823 1.1 mrg the layout of a stack frame shoule be like this: 1824 1.1 mrg 1825 1.1 mrg | | 1826 1.1 mrg old stack pointer -> ---- 1827 1.1 mrg | | \ 1828 1.1 mrg | | saved arguments for 1829 1.1 mrg | | vararg functions 1830 1.1 mrg | | / 1831 1.1 mrg hard frame pointer -> -- 1832 1.1 mrg & argument pointer | | \ 1833 1.1 mrg | | previous hardware frame pointer 1834 1.1 mrg | | return address 1835 1.1 mrg | | callee-saved registers 1836 1.1 mrg | | / 1837 1.1 mrg frame pointer -> -- 1838 1.1 mrg | | \ 1839 1.1 mrg | | local variables 1840 1.1 mrg | | and incoming arguments 1841 1.1 mrg | | / 1842 1.1 mrg -- 1843 1.1 mrg | | \ 1844 1.1 mrg | | outgoing 1845 1.1 mrg | | arguments 1846 1.1 mrg | | / 1847 1.1 mrg stack pointer -> ---- 1848 1.1 mrg 1849 1.1 mrg $SFP and $AP are used to represent frame pointer and arguments pointer, 1850 1.1 mrg which will be both eliminated as hard frame pointer. */ 1851 1.1 mrg 1852 1.1 mrg /* -- Eliminating Frame Pointer and Arg Pointer. */ 1853 1.1 mrg 1854 1.1 mrg static bool 1855 1.1 mrg nds32_can_eliminate (const int from_reg, const int to_reg) 1856 1.1 mrg { 1857 1.1 mrg if (from_reg == ARG_POINTER_REGNUM && to_reg == STACK_POINTER_REGNUM) 1858 1.1 mrg return true; 1859 1.1 mrg 1860 1.1 mrg if (from_reg == ARG_POINTER_REGNUM && to_reg == HARD_FRAME_POINTER_REGNUM) 1861 1.1 mrg return true; 1862 1.1 mrg 1863 1.1 mrg if (from_reg == FRAME_POINTER_REGNUM && to_reg == STACK_POINTER_REGNUM) 1864 1.1 mrg return true; 1865 1.1 mrg 1866 1.1 mrg if (from_reg == FRAME_POINTER_REGNUM && to_reg == HARD_FRAME_POINTER_REGNUM) 1867 1.1 mrg return true; 1868 1.1 mrg 1869 1.1 mrg return false; 1870 1.1 mrg } 1871 1.1 mrg 1872 1.1 mrg /* -- Passing Arguments in Registers. */ 1873 1.1 mrg 1874 1.1 mrg static rtx 1875 1.1 mrg nds32_function_arg (cumulative_args_t ca, const function_arg_info &arg) 1876 1.1 mrg { 1877 1.1 mrg unsigned int regno; 1878 1.1 mrg CUMULATIVE_ARGS *cum = get_cumulative_args (ca); 1879 1.1 mrg tree type = arg.type; 1880 1.1 mrg machine_mode mode = arg.mode; 1881 1.1 mrg 1882 1.1 mrg /* The last time this hook is called, 1883 1.1 mrg it is called with an end marker. */ 1884 1.1 mrg if (arg.end_marker_p ()) 1885 1.1 mrg return NULL_RTX; 1886 1.1 mrg 1887 1.1 mrg /* For nameless arguments, we need to take care it individually. */ 1888 1.1 mrg if (!arg.named) 1889 1.1 mrg { 1890 1.1 mrg /* If we are under hard float abi, we have arguments passed on the 1891 1.1 mrg stack and all situation can be handled by GCC itself. */ 1892 1.1 mrg if (TARGET_HARD_FLOAT) 1893 1.1 mrg return NULL_RTX; 1894 1.1 mrg 1895 1.1 mrg if (NDS32_ARG_PARTIAL_IN_GPR_REG_P (cum->gpr_offset, mode, type)) 1896 1.1 mrg { 1897 1.1 mrg /* If we still have enough registers to pass argument, pick up 1898 1.1 mrg next available register number. */ 1899 1.1 mrg regno 1900 1.1 mrg = NDS32_AVAILABLE_REGNUM_FOR_GPR_ARG (cum->gpr_offset, mode, type); 1901 1.1 mrg return gen_rtx_REG (mode, regno); 1902 1.1 mrg } 1903 1.1 mrg 1904 1.1 mrg /* No register available, return NULL_RTX. 1905 1.1 mrg The compiler will use stack to pass argument instead. */ 1906 1.1 mrg return NULL_RTX; 1907 1.1 mrg } 1908 1.1 mrg 1909 1.1 mrg /* The following is to handle named argument. 1910 1.1 mrg Note that the strategies of TARGET_HARD_FLOAT and !TARGET_HARD_FLOAT 1911 1.1 mrg are different. */ 1912 1.1 mrg if (TARGET_HARD_FLOAT) 1913 1.1 mrg { 1914 1.1 mrg /* For TARGET_HARD_FLOAT calling convention, we use GPR and FPR 1915 1.1 mrg to pass argument. We have to further check TYPE and MODE so 1916 1.1 mrg that we can determine which kind of register we shall use. */ 1917 1.1 mrg 1918 1.1 mrg /* Note that we need to pass argument entirely in registers under 1919 1.1 mrg hard float abi. */ 1920 1.1 mrg if (GET_MODE_CLASS (mode) == MODE_FLOAT 1921 1.1 mrg && NDS32_ARG_ENTIRE_IN_FPR_REG_P (cum->fpr_offset, mode, type)) 1922 1.1 mrg { 1923 1.1 mrg /* Pick up the next available FPR register number. */ 1924 1.1 mrg regno 1925 1.1 mrg = NDS32_AVAILABLE_REGNUM_FOR_FPR_ARG (cum->fpr_offset, mode, type); 1926 1.1 mrg return gen_rtx_REG (mode, regno); 1927 1.1 mrg } 1928 1.1 mrg else if (GET_MODE_CLASS (mode) != MODE_FLOAT 1929 1.1 mrg && NDS32_ARG_ENTIRE_IN_GPR_REG_P (cum->gpr_offset, mode, type)) 1930 1.1 mrg { 1931 1.1 mrg /* Pick up the next available GPR register number. */ 1932 1.1 mrg regno 1933 1.1 mrg = NDS32_AVAILABLE_REGNUM_FOR_GPR_ARG (cum->gpr_offset, mode, type); 1934 1.1 mrg return gen_rtx_REG (mode, regno); 1935 1.1 mrg } 1936 1.1 mrg } 1937 1.1 mrg else 1938 1.1 mrg { 1939 1.1 mrg /* For !TARGET_HARD_FLOAT calling convention, we always use GPR to pass 1940 1.1 mrg argument. Since we allow to pass argument partially in registers, 1941 1.1 mrg we can just return it if there are still registers available. */ 1942 1.1 mrg if (NDS32_ARG_PARTIAL_IN_GPR_REG_P (cum->gpr_offset, mode, type)) 1943 1.1 mrg { 1944 1.1 mrg /* Pick up the next available register number. */ 1945 1.1 mrg regno 1946 1.1 mrg = NDS32_AVAILABLE_REGNUM_FOR_GPR_ARG (cum->gpr_offset, mode, type); 1947 1.1 mrg return gen_rtx_REG (mode, regno); 1948 1.1 mrg } 1949 1.1 mrg 1950 1.1 mrg } 1951 1.1 mrg 1952 1.1 mrg /* No register available, return NULL_RTX. 1953 1.1 mrg The compiler will use stack to pass argument instead. */ 1954 1.1 mrg return NULL_RTX; 1955 1.1 mrg } 1956 1.1 mrg 1957 1.1 mrg static bool 1958 1.1 mrg nds32_must_pass_in_stack (const function_arg_info &arg) 1959 1.1 mrg { 1960 1.1 mrg /* Return true if a type must be passed in memory. 1961 1.1 mrg If it is NOT using hard float abi, small aggregates can be 1962 1.1 mrg passed in a register even we are calling a variadic function. 1963 1.1 mrg So there is no need to take padding into consideration. */ 1964 1.1 mrg if (TARGET_HARD_FLOAT) 1965 1.1 mrg return must_pass_in_stack_var_size_or_pad (arg); 1966 1.1 mrg else 1967 1.1 mrg return must_pass_in_stack_var_size (arg); 1968 1.1 mrg } 1969 1.1 mrg 1970 1.1 mrg static int 1971 1.1 mrg nds32_arg_partial_bytes (cumulative_args_t ca, const function_arg_info &arg) 1972 1.1 mrg { 1973 1.1 mrg /* Returns the number of bytes at the beginning of an argument that 1974 1.1 mrg must be put in registers. The value must be zero for arguments that are 1975 1.1 mrg passed entirely in registers or that are entirely pushed on the stack. 1976 1.1 mrg Besides, TARGET_FUNCTION_ARG for these arguments should return the 1977 1.1 mrg first register to be used by the caller for this argument. */ 1978 1.1 mrg unsigned int needed_reg_count; 1979 1.1 mrg unsigned int remaining_reg_count; 1980 1.1 mrg CUMULATIVE_ARGS *cum; 1981 1.1 mrg 1982 1.1 mrg cum = get_cumulative_args (ca); 1983 1.1 mrg 1984 1.1 mrg /* Under hard float abi, we better have argument entirely passed in 1985 1.1 mrg registers or pushed on the stack so that we can reduce the complexity 1986 1.1 mrg of dealing with cum->gpr_offset and cum->fpr_offset. */ 1987 1.1 mrg if (TARGET_HARD_FLOAT) 1988 1.1 mrg return 0; 1989 1.1 mrg 1990 1.1 mrg /* If we have already runned out of argument registers, return zero 1991 1.1 mrg so that the argument will be entirely pushed on the stack. */ 1992 1.1 mrg if (NDS32_AVAILABLE_REGNUM_FOR_GPR_ARG (cum->gpr_offset, arg.mode, arg.type) 1993 1.1 mrg >= NDS32_GPR_ARG_FIRST_REGNUM + NDS32_MAX_GPR_REGS_FOR_ARGS) 1994 1.1 mrg return 0; 1995 1.1 mrg 1996 1.1 mrg /* Calculate how many registers do we need for this argument. */ 1997 1.1 mrg needed_reg_count = NDS32_NEED_N_REGS_FOR_ARG (arg.mode, arg.type); 1998 1.1 mrg 1999 1.1 mrg /* Calculate how many argument registers have left for passing argument. 2000 1.1 mrg Note that we should count it from next available register number. */ 2001 1.1 mrg remaining_reg_count 2002 1.1 mrg = NDS32_MAX_GPR_REGS_FOR_ARGS 2003 1.1 mrg - (NDS32_AVAILABLE_REGNUM_FOR_GPR_ARG (cum->gpr_offset, 2004 1.1 mrg arg.mode, arg.type) 2005 1.1 mrg - NDS32_GPR_ARG_FIRST_REGNUM); 2006 1.1 mrg 2007 1.1 mrg /* Note that we have to return the nubmer of bytes, not registers count. */ 2008 1.1 mrg if (needed_reg_count > remaining_reg_count) 2009 1.1 mrg return remaining_reg_count * UNITS_PER_WORD; 2010 1.1 mrg 2011 1.1 mrg return 0; 2012 1.1 mrg } 2013 1.1 mrg 2014 1.1 mrg static void 2015 1.1 mrg nds32_function_arg_advance (cumulative_args_t ca, 2016 1.1 mrg const function_arg_info &arg) 2017 1.1 mrg { 2018 1.1 mrg CUMULATIVE_ARGS *cum = get_cumulative_args (ca); 2019 1.1 mrg tree type = arg.type; 2020 1.1 mrg machine_mode mode = arg.mode; 2021 1.1 mrg 2022 1.1 mrg if (arg.named) 2023 1.1 mrg { 2024 1.1 mrg /* We need to further check TYPE and MODE so that we can determine 2025 1.1 mrg which kind of register we shall advance. */ 2026 1.1 mrg 2027 1.1 mrg /* Under hard float abi, we may advance FPR registers. */ 2028 1.1 mrg if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT) 2029 1.1 mrg { 2030 1.1 mrg cum->fpr_offset 2031 1.1 mrg = NDS32_AVAILABLE_REGNUM_FOR_FPR_ARG (cum->fpr_offset, mode, type) 2032 1.1 mrg - NDS32_FPR_ARG_FIRST_REGNUM 2033 1.1 mrg + NDS32_NEED_N_REGS_FOR_ARG (mode, type); 2034 1.1 mrg } 2035 1.1 mrg else 2036 1.1 mrg { 2037 1.1 mrg cum->gpr_offset 2038 1.1 mrg = NDS32_AVAILABLE_REGNUM_FOR_GPR_ARG (cum->gpr_offset, mode, type) 2039 1.1 mrg - NDS32_GPR_ARG_FIRST_REGNUM 2040 1.1 mrg + NDS32_NEED_N_REGS_FOR_ARG (mode, type); 2041 1.1 mrg } 2042 1.1 mrg } 2043 1.1 mrg else 2044 1.1 mrg { 2045 1.1 mrg /* If this nameless argument is NOT under TARGET_HARD_FLOAT, 2046 1.1 mrg we can advance next register as well so that caller is 2047 1.1 mrg able to pass arguments in registers and callee must be 2048 1.1 mrg in charge of pushing all of them into stack. */ 2049 1.1 mrg if (!TARGET_HARD_FLOAT) 2050 1.1 mrg { 2051 1.1 mrg cum->gpr_offset 2052 1.1 mrg = NDS32_AVAILABLE_REGNUM_FOR_GPR_ARG (cum->gpr_offset, mode, type) 2053 1.1 mrg - NDS32_GPR_ARG_FIRST_REGNUM 2054 1.1 mrg + NDS32_NEED_N_REGS_FOR_ARG (mode, type); 2055 1.1 mrg } 2056 1.1 mrg } 2057 1.1 mrg } 2058 1.1 mrg 2059 1.1 mrg static unsigned int 2060 1.1 mrg nds32_function_arg_boundary (machine_mode mode, const_tree type) 2061 1.1 mrg { 2062 1.1 mrg return (nds32_needs_double_word_align (mode, type) 2063 1.1 mrg ? NDS32_DOUBLE_WORD_ALIGNMENT 2064 1.1 mrg : PARM_BOUNDARY); 2065 1.1 mrg } 2066 1.1 mrg 2067 1.1 mrg bool 2068 1.1 mrg nds32_vector_mode_supported_p (machine_mode mode) 2069 1.1 mrg { 2070 1.1 mrg if (mode == V4QImode 2071 1.1 mrg || mode == V2HImode) 2072 1.1 mrg return NDS32_EXT_DSP_P (); 2073 1.1 mrg 2074 1.1 mrg return false; 2075 1.1 mrg } 2076 1.1 mrg 2077 1.1 mrg /* -- How Scalar Function Values Are Returned. */ 2078 1.1 mrg 2079 1.1 mrg static rtx 2080 1.1 mrg nds32_function_value (const_tree ret_type, 2081 1.1 mrg const_tree fn_decl_or_type ATTRIBUTE_UNUSED, 2082 1.1 mrg bool outgoing ATTRIBUTE_UNUSED) 2083 1.1 mrg { 2084 1.1 mrg machine_mode mode; 2085 1.1 mrg int unsignedp; 2086 1.1 mrg 2087 1.1 mrg mode = TYPE_MODE (ret_type); 2088 1.1 mrg unsignedp = TYPE_UNSIGNED (ret_type); 2089 1.1 mrg 2090 1.1 mrg if (INTEGRAL_TYPE_P (ret_type)) 2091 1.1 mrg mode = promote_mode (ret_type, mode, &unsignedp); 2092 1.1 mrg 2093 1.1 mrg if (TARGET_HARD_FLOAT && (mode == SFmode || mode == DFmode)) 2094 1.1 mrg return gen_rtx_REG (mode, NDS32_FPR_RET_FIRST_REGNUM); 2095 1.1 mrg else 2096 1.1 mrg return gen_rtx_REG (mode, NDS32_GPR_RET_FIRST_REGNUM); 2097 1.1 mrg } 2098 1.1 mrg 2099 1.1 mrg static rtx 2100 1.1 mrg nds32_libcall_value (machine_mode mode, 2101 1.1 mrg const_rtx fun ATTRIBUTE_UNUSED) 2102 1.1 mrg { 2103 1.1 mrg if (TARGET_HARD_FLOAT && (mode == SFmode || mode == DFmode)) 2104 1.1 mrg return gen_rtx_REG (mode, NDS32_FPR_RET_FIRST_REGNUM); 2105 1.1 mrg 2106 1.1 mrg return gen_rtx_REG (mode, NDS32_GPR_RET_FIRST_REGNUM); 2107 1.1 mrg } 2108 1.1 mrg 2109 1.1 mrg static bool 2110 1.1 mrg nds32_function_value_regno_p (const unsigned int regno) 2111 1.1 mrg { 2112 1.1 mrg if (regno == NDS32_GPR_RET_FIRST_REGNUM 2113 1.1 mrg || (TARGET_HARD_FLOAT 2114 1.1 mrg && regno == NDS32_FPR_RET_FIRST_REGNUM)) 2115 1.1 mrg return true; 2116 1.1 mrg 2117 1.1 mrg return false; 2118 1.1 mrg } 2119 1.1 mrg 2120 1.1 mrg /* -- How Large Values Are Returned. */ 2121 1.1 mrg 2122 1.1 mrg static bool 2123 1.1 mrg nds32_return_in_memory (const_tree type, 2124 1.1 mrg const_tree fntype ATTRIBUTE_UNUSED) 2125 1.1 mrg { 2126 1.1 mrg /* Note that int_size_in_bytes can return -1 if the size can vary 2127 1.1 mrg or is larger than an integer. */ 2128 1.1 mrg HOST_WIDE_INT size = int_size_in_bytes (type); 2129 1.1 mrg 2130 1.1 mrg /* For COMPLEX_TYPE, if the total size cannot be hold within two registers, 2131 1.1 mrg the return value is supposed to be in memory. We need to be aware of 2132 1.1 mrg that the size may be -1. */ 2133 1.1 mrg if (TREE_CODE (type) == COMPLEX_TYPE) 2134 1.1 mrg if (size < 0 || size > 2 * UNITS_PER_WORD) 2135 1.1 mrg return true; 2136 1.1 mrg 2137 1.1 mrg /* If it is BLKmode and the total size cannot be hold within two registers, 2138 1.1 mrg the return value is supposed to be in memory. We need to be aware of 2139 1.1 mrg that the size may be -1. */ 2140 1.1 mrg if (TYPE_MODE (type) == BLKmode) 2141 1.1 mrg if (size < 0 || size > 2 * UNITS_PER_WORD) 2142 1.1 mrg return true; 2143 1.1 mrg 2144 1.1 mrg /* For other cases, having result in memory is unnecessary. */ 2145 1.1 mrg return false; 2146 1.1 mrg } 2147 1.1 mrg 2148 1.1 mrg /* -- Function Entry and Exit. */ 2149 1.1 mrg 2150 1.1 mrg /* The content produced from this function 2151 1.1 mrg will be placed before prologue body. */ 2152 1.1 mrg static void 2153 1.1 mrg nds32_asm_function_prologue (FILE *file) 2154 1.1 mrg { 2155 1.1 mrg int r; 2156 1.1 mrg const char *func_name; 2157 1.1 mrg tree attrs; 2158 1.1 mrg tree name; 2159 1.1 mrg 2160 1.1 mrg /* All stack frame information is supposed to be 2161 1.1 mrg already computed when expanding prologue. 2162 1.1 mrg The result is in cfun->machine. 2163 1.1 mrg DO NOT call nds32_compute_stack_frame() here 2164 1.1 mrg because it may corrupt the essential information. */ 2165 1.1 mrg 2166 1.1 mrg fprintf (file, "\t! BEGIN PROLOGUE\n"); 2167 1.1 mrg fprintf (file, "\t! fp needed: %d\n", frame_pointer_needed); 2168 1.1 mrg fprintf (file, "\t! pretend_args: %d\n", cfun->machine->va_args_size); 2169 1.1 mrg fprintf (file, "\t! local_size: %d\n", cfun->machine->local_size); 2170 1.1 mrg fprintf (file, "\t! out_args_size: %d\n", cfun->machine->out_args_size); 2171 1.1 mrg 2172 1.1 mrg /* Use df_regs_ever_live_p() to detect if the register 2173 1.1 mrg is ever used in the current function. */ 2174 1.1 mrg fprintf (file, "\t! registers ever_live: "); 2175 1.1 mrg for (r = 0; r < 65; r++) 2176 1.1 mrg { 2177 1.1 mrg if (df_regs_ever_live_p (r)) 2178 1.1 mrg fprintf (file, "%s, ", reg_names[r]); 2179 1.1 mrg } 2180 1.1 mrg fputc ('\n', file); 2181 1.1 mrg 2182 1.1 mrg /* Display the attributes of this function. */ 2183 1.1 mrg fprintf (file, "\t! function attributes: "); 2184 1.1 mrg /* Get the attributes tree list. 2185 1.1 mrg Note that GCC builds attributes list with reverse order. */ 2186 1.1 mrg attrs = DECL_ATTRIBUTES (current_function_decl); 2187 1.1 mrg 2188 1.1 mrg /* If there is no any attribute, print out "None". */ 2189 1.1 mrg if (!attrs) 2190 1.1 mrg fprintf (file, "None"); 2191 1.1 mrg 2192 1.1 mrg /* If there are some attributes, try if we need to 2193 1.1 mrg construct isr vector information. */ 2194 1.1 mrg func_name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl)); 2195 1.1 mrg nds32_construct_isr_vectors_information (attrs, func_name); 2196 1.1 mrg 2197 1.1 mrg /* Display all attributes of this function. */ 2198 1.1 mrg while (attrs) 2199 1.1 mrg { 2200 1.1 mrg name = TREE_PURPOSE (attrs); 2201 1.1 mrg fprintf (file, "%s ", IDENTIFIER_POINTER (name)); 2202 1.1 mrg 2203 1.1 mrg /* Pick up the next attribute. */ 2204 1.1 mrg attrs = TREE_CHAIN (attrs); 2205 1.1 mrg } 2206 1.1 mrg fputc ('\n', file); 2207 1.1 mrg } 2208 1.1 mrg 2209 1.1 mrg /* After rtl prologue has been expanded, this function is used. */ 2210 1.1 mrg static void 2211 1.1 mrg nds32_asm_function_end_prologue (FILE *file) 2212 1.1 mrg { 2213 1.1 mrg fprintf (file, "\t! END PROLOGUE\n"); 2214 1.1 mrg } 2215 1.1 mrg 2216 1.1 mrg /* Before rtl epilogue has been expanded, this function is used. */ 2217 1.1 mrg static void 2218 1.1 mrg nds32_asm_function_begin_epilogue (FILE *file) 2219 1.1 mrg { 2220 1.1 mrg fprintf (file, "\t! BEGIN EPILOGUE\n"); 2221 1.1 mrg } 2222 1.1 mrg 2223 1.1 mrg /* The content produced from this function 2224 1.1 mrg will be placed after epilogue body. */ 2225 1.1 mrg static void 2226 1.1 mrg nds32_asm_function_epilogue (FILE *file) 2227 1.1 mrg { 2228 1.1 mrg fprintf (file, "\t! END EPILOGUE\n"); 2229 1.1 mrg } 2230 1.1 mrg 2231 1.1 mrg static void 2232 1.1 mrg nds32_asm_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED, 2233 1.1 mrg HOST_WIDE_INT delta, 2234 1.1 mrg HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED, 2235 1.1 mrg tree function) 2236 1.1 mrg { 2237 1.1 mrg const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk)); 2238 1.1 mrg int this_regno; 2239 1.1 mrg 2240 1.1 mrg assemble_start_function (thunk, fnname); 2241 1.1 mrg /* Make sure unwind info is emitted for the thunk if needed. */ 2242 1.1 mrg final_start_function (emit_barrier (), file, 1); 2243 1.1 mrg 2244 1.1 mrg this_regno = (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function) 2245 1.1 mrg ? 1 2246 1.1 mrg : 0); 2247 1.1 mrg 2248 1.1 mrg if (flag_pic) 2249 1.1 mrg { 2250 1.1 mrg fprintf (file, "\tsmw.adm\t$r31, [$r31], $r31, 4\n"); 2251 1.1 mrg fprintf (file, "\tsethi\t%s, hi20(_GLOBAL_OFFSET_TABLE_-8)\n", 2252 1.1 mrg reg_names [PIC_OFFSET_TABLE_REGNUM]); 2253 1.1 mrg fprintf (file, "\tori\t%s, %s, lo12(_GLOBAL_OFFSET_TABLE_-4)\n", 2254 1.1 mrg reg_names [PIC_OFFSET_TABLE_REGNUM], 2255 1.1 mrg reg_names [PIC_OFFSET_TABLE_REGNUM]); 2256 1.1 mrg 2257 1.1 mrg if (TARGET_ISA_V3) 2258 1.1 mrg fprintf (file, "\tadd5.pc\t$gp\n"); 2259 1.1 mrg else 2260 1.1 mrg { 2261 1.1 mrg fprintf (file, "\tmfusr\t$ta, $pc\n"); 2262 1.1 mrg fprintf (file, "\tadd\t%s, $ta, %s\n", 2263 1.1 mrg reg_names [PIC_OFFSET_TABLE_REGNUM], 2264 1.1 mrg reg_names [PIC_OFFSET_TABLE_REGNUM]); 2265 1.1 mrg } 2266 1.1 mrg } 2267 1.1 mrg 2268 1.1 mrg if (delta != 0) 2269 1.1 mrg { 2270 1.1 mrg if (satisfies_constraint_Is15 (GEN_INT (delta))) 2271 1.1 mrg { 2272 1.1 mrg fprintf (file, "\taddi\t$r%d, $r%d, " HOST_WIDE_INT_PRINT_DEC "\n", 2273 1.1 mrg this_regno, this_regno, delta); 2274 1.1 mrg } 2275 1.1 mrg else if (satisfies_constraint_Is20 (GEN_INT (delta))) 2276 1.1 mrg { 2277 1.1 mrg fprintf (file, "\tmovi\t$ta, " HOST_WIDE_INT_PRINT_DEC "\n", delta); 2278 1.1 mrg fprintf (file, "\tadd\t$r%d, $r%d, $ta\n", this_regno, this_regno); 2279 1.1 mrg } 2280 1.1 mrg else 2281 1.1 mrg { 2282 1.1 mrg fprintf (file, 2283 1.1 mrg "\tsethi\t$ta, hi20(" HOST_WIDE_INT_PRINT_DEC ")\n", 2284 1.1 mrg delta); 2285 1.1 mrg fprintf (file, 2286 1.1 mrg "\tori\t$ta, $ta, lo12(" HOST_WIDE_INT_PRINT_DEC ")\n", 2287 1.1 mrg delta); 2288 1.1 mrg fprintf (file, "\tadd\t$r%d, $r%d, $ta\n", this_regno, this_regno); 2289 1.1 mrg } 2290 1.1 mrg } 2291 1.1 mrg 2292 1.1 mrg if (flag_pic) 2293 1.1 mrg { 2294 1.1 mrg fprintf (file, "\tla\t$ta, "); 2295 1.1 mrg assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0)); 2296 1.1 mrg fprintf (file, "@PLT\n"); 2297 1.1 mrg fprintf (file, "\t! epilogue\n"); 2298 1.1 mrg fprintf (file, "\tlwi.bi\t%s, [%s], 4\n", 2299 1.1 mrg reg_names[PIC_OFFSET_TABLE_REGNUM], 2300 1.1 mrg reg_names[STACK_POINTER_REGNUM]); 2301 1.1 mrg fprintf (file, "\tbr\t$ta\n"); 2302 1.1 mrg } 2303 1.1 mrg else 2304 1.1 mrg { 2305 1.1 mrg fprintf (file, "\tb\t"); 2306 1.1 mrg assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0)); 2307 1.1 mrg fprintf (file, "\n"); 2308 1.1 mrg } 2309 1.1 mrg 2310 1.1 mrg final_end_function (); 2311 1.1 mrg assemble_end_function (thunk, fnname); 2312 1.1 mrg } 2313 1.1 mrg 2314 1.1 mrg /* -- Permitting tail calls. */ 2315 1.1 mrg 2316 1.1 mrg /* Return true if it is ok to do sibling call optimization. */ 2317 1.1 mrg static bool 2318 1.1 mrg nds32_function_ok_for_sibcall (tree decl, 2319 1.1 mrg tree exp ATTRIBUTE_UNUSED) 2320 1.1 mrg { 2321 1.1 mrg /* The DECL is NULL if it is an indirect call. */ 2322 1.1 mrg 2323 1.1 mrg /* 1. Do not apply sibling call if -mv3push is enabled, 2324 1.1 mrg because pop25 instruction also represents return behavior. 2325 1.1 mrg 2. If this function is a isr function, do not apply sibling call 2326 1.1 mrg because it may perform the behavior that user does not expect. 2327 1.1 mrg 3. If this function is a variadic function, do not apply sibling call 2328 1.1 mrg because the stack layout may be a mess. 2329 1.1 mrg 4. We don't want to apply sibling call optimization for indirect 2330 1.1 mrg sibcall because the pop behavior in epilogue may pollute the 2331 1.1 mrg content of caller-saved regsiter when the register is used for 2332 1.1 mrg indirect sibcall. 2333 1.1 mrg 5. In pic mode, it may use some registers for PLT call. */ 2334 1.1 mrg return (!TARGET_V3PUSH 2335 1.1 mrg && !nds32_isr_function_p (current_function_decl) 2336 1.1 mrg && (cfun->machine->va_args_size == 0) 2337 1.1 mrg && decl 2338 1.1 mrg && !flag_pic); 2339 1.1 mrg } 2340 1.1 mrg 2341 1.1 mrg /* Determine whether we need to enable warning for function return check. */ 2342 1.1 mrg static bool 2343 1.1 mrg nds32_warn_func_return (tree decl) 2344 1.1 mrg { 2345 1.1 mrg /* Naked functions are implemented entirely in assembly, including the 2346 1.1 mrg return sequence, so suppress warnings about this. */ 2347 1.1 mrg return !nds32_naked_function_p (decl); 2348 1.1 mrg } 2349 1.1 mrg 2350 1.1 mrg 2351 1.1 mrg /* Implementing the Varargs Macros. */ 2353 1.1 mrg 2354 1.1 mrg static void 2355 1.1 mrg nds32_setup_incoming_varargs (cumulative_args_t ca, 2356 1.1 mrg const function_arg_info &arg, 2357 1.1 mrg int *pretend_args_size, 2358 1.1 mrg int second_time ATTRIBUTE_UNUSED) 2359 1.1 mrg { 2360 1.1 mrg unsigned int total_args_regs; 2361 1.1 mrg unsigned int num_of_used_regs; 2362 1.1 mrg unsigned int remaining_reg_count; 2363 1.1 mrg CUMULATIVE_ARGS *cum; 2364 1.1 mrg 2365 1.1 mrg /* If we are under hard float abi, we do not need to set *pretend_args_size. 2366 1.1 mrg So that all nameless arguments are pushed by caller and all situation 2367 1.1 mrg can be handled by GCC itself. */ 2368 1.1 mrg if (TARGET_HARD_FLOAT) 2369 1.1 mrg return; 2370 1.1 mrg 2371 1.1 mrg /* We are using NDS32_MAX_GPR_REGS_FOR_ARGS registers, 2372 1.1 mrg counting from NDS32_GPR_ARG_FIRST_REGNUM, for saving incoming arguments. 2373 1.1 mrg However, for nameless(anonymous) arguments, we should push them on the 2374 1.1 mrg stack so that all the nameless arguments appear to have been passed 2375 1.1 mrg consecutively in the memory for accessing. Hence, we need to check and 2376 1.1 mrg exclude the registers that are used for named arguments. */ 2377 1.1 mrg 2378 1.1 mrg cum = get_cumulative_args (ca); 2379 1.1 mrg 2380 1.1 mrg /* ARG describes the last argument. 2381 1.1 mrg We need those information to determine the remaining registers 2382 1.1 mrg for varargs. */ 2383 1.1 mrg total_args_regs 2384 1.1 mrg = NDS32_MAX_GPR_REGS_FOR_ARGS + NDS32_GPR_ARG_FIRST_REGNUM; 2385 1.1 mrg num_of_used_regs 2386 1.1 mrg = NDS32_AVAILABLE_REGNUM_FOR_GPR_ARG (cum->gpr_offset, arg.mode, arg.type) 2387 1.1 mrg + NDS32_NEED_N_REGS_FOR_ARG (arg.mode, arg.type); 2388 1.1 mrg 2389 1.1 mrg remaining_reg_count = total_args_regs - num_of_used_regs; 2390 1.1 mrg *pretend_args_size = remaining_reg_count * UNITS_PER_WORD; 2391 1.1 mrg 2392 1.1 mrg return; 2393 1.1 mrg } 2394 1.1 mrg 2395 1.1 mrg static bool 2396 1.1 mrg nds32_strict_argument_naming (cumulative_args_t ca ATTRIBUTE_UNUSED) 2397 1.1 mrg { 2398 1.1 mrg /* If this hook returns true, the named argument of FUNCTION_ARG is always 2399 1.1 mrg true for named arguments, and false for unnamed arguments. */ 2400 1.1 mrg return true; 2401 1.1 mrg } 2402 1.1 mrg 2403 1.1 mrg 2404 1.1 mrg /* Trampolines for Nested Functions. */ 2406 1.1 mrg 2407 1.1 mrg static void 2408 1.1 mrg nds32_asm_trampoline_template (FILE *f) 2409 1.1 mrg { 2410 1.1 mrg if (TARGET_REDUCED_REGS) 2411 1.1 mrg { 2412 1.1 mrg /* Trampoline is not supported on reduced-set registers yet. */ 2413 1.1 mrg sorry ("a nested function is not supported for reduced registers"); 2414 1.1 mrg } 2415 1.1 mrg else 2416 1.1 mrg { 2417 1.1 mrg asm_fprintf (f, "\t! Trampoline code template\n"); 2418 1.1 mrg asm_fprintf (f, "\t! This code fragment will be copied " 2419 1.1 mrg "into stack on demand\n"); 2420 1.1 mrg 2421 1.1 mrg asm_fprintf (f, "\tmfusr\t$r16,$pc\n"); 2422 1.1 mrg asm_fprintf (f, "\tlwi\t$r15,[$r16 + 20] " 2423 1.1 mrg "! load nested function address\n"); 2424 1.1 mrg asm_fprintf (f, "\tlwi\t$r16,[$r16 + 16] " 2425 1.1 mrg "! load chain_value\n"); 2426 1.1 mrg asm_fprintf (f, "\tjr\t$r15\n"); 2427 1.1 mrg } 2428 1.1 mrg 2429 1.1 mrg /* Preserve space ($pc + 16) for saving chain_value, 2430 1.1 mrg nds32_trampoline_init will fill the value in this slot. */ 2431 1.1 mrg asm_fprintf (f, "\t! space for saving chain_value\n"); 2432 1.1 mrg assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); 2433 1.1 mrg 2434 1.1 mrg /* Preserve space ($pc + 20) for saving nested function address, 2435 1.1 mrg nds32_trampoline_init will fill the value in this slot. */ 2436 1.1 mrg asm_fprintf (f, "\t! space for saving nested function address\n"); 2437 1.1 mrg assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); 2438 1.1 mrg } 2439 1.1 mrg 2440 1.1 mrg /* Emit RTL insns to initialize the variable parts of a trampoline. */ 2441 1.1 mrg static void 2442 1.1 mrg nds32_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) 2443 1.1 mrg { 2444 1.1 mrg int i; 2445 1.1 mrg 2446 1.1 mrg /* Nested function address. */ 2447 1.1 mrg rtx fnaddr; 2448 1.1 mrg /* The memory rtx that is going to 2449 1.1 mrg be filled with chain_value. */ 2450 1.1 mrg rtx chain_value_mem; 2451 1.1 mrg /* The memory rtx that is going to 2452 1.1 mrg be filled with nested function address. */ 2453 1.1 mrg rtx nested_func_mem; 2454 1.1 mrg 2455 1.1 mrg /* Start address of trampoline code in stack, for doing cache sync. */ 2456 1.1 mrg rtx sync_cache_addr; 2457 1.1 mrg /* Temporary register for sync instruction. */ 2458 1.1 mrg rtx tmp_reg; 2459 1.1 mrg /* Instruction-cache sync instruction, 2460 1.1 mrg requesting an argument as starting address. */ 2461 1.1 mrg rtx isync_insn; 2462 1.1 mrg /* For convenience reason of doing comparison. */ 2463 1.1 mrg int tramp_align_in_bytes; 2464 1.1 mrg 2465 1.1 mrg /* Trampoline is not supported on reduced-set registers yet. */ 2466 1.1 mrg if (TARGET_REDUCED_REGS) 2467 1.1 mrg sorry ("a nested function is not supported for reduced registers"); 2468 1.1 mrg 2469 1.1 mrg /* STEP 1: Copy trampoline code template into stack, 2470 1.1 mrg fill up essential data into stack. */ 2471 1.1 mrg 2472 1.1 mrg /* Extract nested function address rtx. */ 2473 1.1 mrg fnaddr = XEXP (DECL_RTL (fndecl), 0); 2474 1.1 mrg 2475 1.1 mrg /* m_tramp is memory rtx that is going to be filled with trampoline code. 2476 1.1 mrg We have nds32_asm_trampoline_template() to emit template pattern. */ 2477 1.1 mrg emit_block_move (m_tramp, assemble_trampoline_template (), 2478 1.1 mrg GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL); 2479 1.1 mrg 2480 1.1 mrg /* After copying trampoline code into stack, 2481 1.1 mrg fill chain_value into stack. */ 2482 1.1 mrg chain_value_mem = adjust_address (m_tramp, SImode, 16); 2483 1.1 mrg emit_move_insn (chain_value_mem, chain_value); 2484 1.1 mrg /* After copying trampoline code int stack, 2485 1.1 mrg fill nested function address into stack. */ 2486 1.1 mrg nested_func_mem = adjust_address (m_tramp, SImode, 20); 2487 1.1 mrg emit_move_insn (nested_func_mem, fnaddr); 2488 1.1 mrg 2489 1.1 mrg /* STEP 2: Sync instruction-cache. */ 2490 1.1 mrg 2491 1.1 mrg /* We have successfully filled trampoline code into stack. 2492 1.1 mrg However, in order to execute code in stack correctly, 2493 1.1 mrg we must sync instruction cache. */ 2494 1.1 mrg sync_cache_addr = XEXP (m_tramp, 0); 2495 1.1 mrg tmp_reg = gen_reg_rtx (SImode); 2496 1.1 mrg isync_insn = gen_unspec_volatile_isync (tmp_reg); 2497 1.1 mrg 2498 1.1 mrg /* Because nds32_cache_block_size is in bytes, 2499 1.1 mrg we get trampoline alignment in bytes for convenient comparison. */ 2500 1.1 mrg tramp_align_in_bytes = TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT; 2501 1.1 mrg 2502 1.1 mrg if (tramp_align_in_bytes >= nds32_cache_block_size 2503 1.1 mrg && (tramp_align_in_bytes % nds32_cache_block_size) == 0) 2504 1.1 mrg { 2505 1.1 mrg /* Under this condition, the starting address of trampoline 2506 1.1 mrg must be aligned to the starting address of each cache block 2507 1.1 mrg and we do not have to worry about cross-boundary issue. */ 2508 1.1 mrg for (i = 0; 2509 1.1 mrg i < (TRAMPOLINE_SIZE + nds32_cache_block_size - 1) 2510 1.1 mrg / nds32_cache_block_size; 2511 1.1 mrg i++) 2512 1.1 mrg { 2513 1.1 mrg emit_move_insn (tmp_reg, 2514 1.1 mrg plus_constant (Pmode, sync_cache_addr, 2515 1.1 mrg nds32_cache_block_size * i)); 2516 1.1 mrg emit_insn (isync_insn); 2517 1.1 mrg } 2518 1.1 mrg } 2519 1.1 mrg else if (TRAMPOLINE_SIZE > nds32_cache_block_size) 2520 1.1 mrg { 2521 1.1 mrg /* The starting address of trampoline code 2522 1.1 mrg may not be aligned to the cache block, 2523 1.1 mrg so the trampoline code may be across two cache block. 2524 1.1 mrg We need to sync the last element, which is 4-byte size, 2525 1.1 mrg of trampoline template. */ 2526 1.1 mrg for (i = 0; 2527 1.1 mrg i < (TRAMPOLINE_SIZE + nds32_cache_block_size - 1) 2528 1.1 mrg / nds32_cache_block_size; 2529 1.1 mrg i++) 2530 1.1 mrg { 2531 1.1 mrg emit_move_insn (tmp_reg, 2532 1.1 mrg plus_constant (Pmode, sync_cache_addr, 2533 1.1 mrg nds32_cache_block_size * i)); 2534 1.1 mrg emit_insn (isync_insn); 2535 1.1 mrg } 2536 1.1 mrg 2537 1.1 mrg /* The last element of trampoline template is 4-byte size. */ 2538 1.1 mrg emit_move_insn (tmp_reg, 2539 1.1 mrg plus_constant (Pmode, sync_cache_addr, 2540 1.1 mrg TRAMPOLINE_SIZE - 4)); 2541 1.1 mrg emit_insn (isync_insn); 2542 1.1 mrg } 2543 1.1 mrg else 2544 1.1 mrg { 2545 1.1 mrg /* This is the simplest case. 2546 1.1 mrg Because TRAMPOLINE_SIZE is less than or 2547 1.1 mrg equal to nds32_cache_block_size, 2548 1.1 mrg we can just sync start address and 2549 1.1 mrg the last element of trampoline code. */ 2550 1.1 mrg 2551 1.1 mrg /* Sync starting address of tampoline code. */ 2552 1.1 mrg emit_move_insn (tmp_reg, sync_cache_addr); 2553 1.1 mrg emit_insn (isync_insn); 2554 1.1 mrg /* Sync the last element, which is 4-byte size, 2555 1.1 mrg of trampoline template. */ 2556 1.1 mrg emit_move_insn (tmp_reg, 2557 1.1 mrg plus_constant (Pmode, sync_cache_addr, 2558 1.1 mrg TRAMPOLINE_SIZE - 4)); 2559 1.1 mrg emit_insn (isync_insn); 2560 1.1 mrg } 2561 1.1 mrg 2562 1.1 mrg /* Set instruction serialization barrier 2563 1.1 mrg to guarantee the correct operations. */ 2564 1.1 mrg emit_insn (gen_unspec_volatile_isb ()); 2565 1.1 mrg } 2566 1.1 mrg 2567 1.1 mrg 2568 1.1 mrg /* Addressing Modes. */ 2570 1.1 mrg 2571 1.1 mrg static bool 2572 1.1 mrg nds32_legitimate_address_p (machine_mode mode, rtx x, bool strict) 2573 1.1 mrg { 2574 1.1 mrg if (TARGET_FPU_SINGLE || TARGET_FPU_DOUBLE) 2575 1.1 mrg { 2576 1.1 mrg /* When using floating-point instructions, 2577 1.1 mrg we don't allow 'addr' to be [symbol_ref], [CONST] pattern. */ 2578 1.1 mrg if ((mode == DFmode || mode == SFmode) 2579 1.1 mrg && (GET_CODE (x) == SYMBOL_REF 2580 1.1 mrg || GET_CODE(x) == CONST)) 2581 1.1 mrg return false; 2582 1.1 mrg 2583 1.1 mrg /* Allow [post_modify] addressing mode, when using FPU instructions. */ 2584 1.1 mrg if (GET_CODE (x) == POST_MODIFY 2585 1.1 mrg && mode == DFmode) 2586 1.1 mrg { 2587 1.1 mrg if (GET_CODE (XEXP (x, 0)) == REG 2588 1.1 mrg && GET_CODE (XEXP (x, 1)) == PLUS) 2589 1.1 mrg { 2590 1.1 mrg rtx plus_op = XEXP (x, 1); 2591 1.1 mrg rtx op0 = XEXP (plus_op, 0); 2592 1.1 mrg rtx op1 = XEXP (plus_op, 1); 2593 1.1 mrg 2594 1.1 mrg if (nds32_address_register_rtx_p (op0, strict) 2595 1.1 mrg && CONST_INT_P (op1)) 2596 1.1 mrg { 2597 1.1 mrg if (satisfies_constraint_Is14 (op1)) 2598 1.1 mrg { 2599 1.1 mrg /* If it is not under strictly aligned situation, 2600 1.1 mrg we can return true without checking alignment. */ 2601 1.1 mrg if (!cfun->machine->strict_aligned_p) 2602 1.1 mrg return true; 2603 1.1 mrg /* Make sure address is word alignment. 2604 1.1 mrg Currently we do not have 64-bit load/store yet, 2605 1.1 mrg so we will use two 32-bit load/store instructions to do 2606 1.1 mrg memory access and they are single word alignment. */ 2607 1.1 mrg else if (NDS32_SINGLE_WORD_ALIGN_P (INTVAL (op1))) 2608 1.1 mrg return true; 2609 1.1 mrg } 2610 1.1 mrg } 2611 1.1 mrg } 2612 1.1 mrg } 2613 1.1 mrg } 2614 1.1 mrg 2615 1.1 mrg /* For (mem:DI addr) or (mem:DF addr) case, 2616 1.1 mrg we only allow 'addr' to be [reg], [symbol_ref], 2617 1.1 mrg [const], or [reg + const_int] pattern. */ 2618 1.1 mrg if (mode == DImode || mode == DFmode) 2619 1.1 mrg { 2620 1.1 mrg /* Allow [Reg + const_int] addressing mode. */ 2621 1.1 mrg if (GET_CODE (x) == PLUS) 2622 1.1 mrg { 2623 1.1 mrg if (nds32_address_register_rtx_p (XEXP (x, 0), strict) 2624 1.1 mrg && nds32_legitimate_index_p (mode, XEXP (x, 1), strict) 2625 1.1 mrg && CONST_INT_P (XEXP (x, 1))) 2626 1.1 mrg return true; 2627 1.1 mrg else if (nds32_address_register_rtx_p (XEXP (x, 1), strict) 2628 1.1 mrg && nds32_legitimate_index_p (mode, XEXP (x, 0), strict) 2629 1.1 mrg && CONST_INT_P (XEXP (x, 0))) 2630 1.1 mrg return true; 2631 1.1 mrg } 2632 1.1 mrg 2633 1.1 mrg /* Allow [post_inc] and [post_dec] addressing mode. */ 2634 1.1 mrg if (GET_CODE (x) == POST_INC || GET_CODE (x) == POST_DEC) 2635 1.1 mrg { 2636 1.1 mrg if (nds32_address_register_rtx_p (XEXP (x, 0), strict)) 2637 1.1 mrg return true; 2638 1.1 mrg } 2639 1.1 mrg 2640 1.1 mrg /* Now check [reg], [symbol_ref], and [const]. */ 2641 1.1 mrg if (GET_CODE (x) != REG 2642 1.1 mrg && GET_CODE (x) != SYMBOL_REF 2643 1.1 mrg && GET_CODE (x) != CONST) 2644 1.1 mrg return false; 2645 1.1 mrg } 2646 1.1 mrg 2647 1.1 mrg /* Check if 'x' is a valid address. */ 2648 1.1 mrg switch (GET_CODE (x)) 2649 1.1 mrg { 2650 1.1 mrg case REG: 2651 1.1 mrg /* (mem (reg A)) => [Ra] */ 2652 1.1 mrg return nds32_address_register_rtx_p (x, strict); 2653 1.1 mrg 2654 1.1 mrg case SYMBOL_REF: 2655 1.1 mrg /* (mem (symbol_ref A)) => [symbol_ref] */ 2656 1.1 mrg 2657 1.1 mrg if (flag_pic || SYMBOL_REF_TLS_MODEL (x)) 2658 1.1 mrg return false; 2659 1.1 mrg 2660 1.1 mrg if (TARGET_ICT_MODEL_LARGE && nds32_indirect_call_referenced_p (x)) 2661 1.1 mrg return false; 2662 1.1 mrg 2663 1.1 mrg /* If -mcmodel=large, the 'symbol_ref' is not a valid address 2664 1.1 mrg during or after LRA/reload phase. */ 2665 1.1 mrg if (TARGET_CMODEL_LARGE 2666 1.1 mrg && (reload_completed 2667 1.1 mrg || reload_in_progress 2668 1.1 mrg || lra_in_progress)) 2669 1.1 mrg return false; 2670 1.1 mrg /* If -mcmodel=medium and the symbol references to rodata section, 2671 1.1 mrg the 'symbol_ref' is not a valid address during or after 2672 1.1 mrg LRA/reload phase. */ 2673 1.1 mrg if (TARGET_CMODEL_MEDIUM 2674 1.1 mrg && (NDS32_SYMBOL_REF_RODATA_P (x) 2675 1.1 mrg || CONSTANT_POOL_ADDRESS_P (x)) 2676 1.1 mrg && (reload_completed 2677 1.1 mrg || reload_in_progress 2678 1.1 mrg || lra_in_progress)) 2679 1.1 mrg return false; 2680 1.1 mrg 2681 1.1 mrg return true; 2682 1.1 mrg 2683 1.1 mrg case CONST: 2684 1.1 mrg /* (mem (const (...))) 2685 1.1 mrg => [ + const_addr ], where const_addr = symbol_ref + const_int */ 2686 1.1 mrg if (GET_CODE (XEXP (x, 0)) == PLUS) 2687 1.1 mrg { 2688 1.1 mrg rtx plus_op = XEXP (x, 0); 2689 1.1 mrg 2690 1.1 mrg rtx op0 = XEXP (plus_op, 0); 2691 1.1 mrg rtx op1 = XEXP (plus_op, 1); 2692 1.1 mrg 2693 1.1 mrg if (GET_CODE (op0) == SYMBOL_REF && CONST_INT_P (op1)) 2694 1.1 mrg { 2695 1.1 mrg /* Now we see the [ + const_addr ] pattern, but we need 2696 1.1 mrg some further checking. */ 2697 1.1 mrg 2698 1.1 mrg if (flag_pic || SYMBOL_REF_TLS_MODEL (op0)) 2699 1.1 mrg return false; 2700 1.1 mrg 2701 1.1 mrg /* If -mcmodel=large, the 'const_addr' is not a valid address 2702 1.1 mrg during or after LRA/reload phase. */ 2703 1.1 mrg if (TARGET_CMODEL_LARGE 2704 1.1 mrg && (reload_completed 2705 1.1 mrg || reload_in_progress 2706 1.1 mrg || lra_in_progress)) 2707 1.1 mrg return false; 2708 1.1 mrg /* If -mcmodel=medium and the symbol references to rodata section, 2709 1.1 mrg the 'const_addr' is not a valid address during or after 2710 1.1 mrg LRA/reload phase. */ 2711 1.1 mrg if (TARGET_CMODEL_MEDIUM 2712 1.1 mrg && NDS32_SYMBOL_REF_RODATA_P (op0) 2713 1.1 mrg && (reload_completed 2714 1.1 mrg || reload_in_progress 2715 1.1 mrg || lra_in_progress)) 2716 1.1 mrg return false; 2717 1.1 mrg 2718 1.1 mrg /* At this point we can make sure 'const_addr' is a 2719 1.1 mrg valid address. */ 2720 1.1 mrg return true; 2721 1.1 mrg } 2722 1.1 mrg } 2723 1.1 mrg 2724 1.1 mrg return false; 2725 1.1 mrg 2726 1.1 mrg case POST_MODIFY: 2727 1.1 mrg /* (mem (post_modify (reg) (plus (reg) (reg)))) 2728 1.1 mrg => [Ra], Rb */ 2729 1.1 mrg /* (mem (post_modify (reg) (plus (reg) (const_int)))) 2730 1.1 mrg => [Ra], const_int */ 2731 1.1 mrg if (GET_CODE (XEXP (x, 0)) == REG 2732 1.1 mrg && GET_CODE (XEXP (x, 1)) == PLUS) 2733 1.1 mrg { 2734 1.1 mrg rtx plus_op = XEXP (x, 1); 2735 1.1 mrg 2736 1.1 mrg rtx op0 = XEXP (plus_op, 0); 2737 1.1 mrg rtx op1 = XEXP (plus_op, 1); 2738 1.1 mrg 2739 1.1 mrg if (nds32_address_register_rtx_p (op0, strict) 2740 1.1 mrg && nds32_legitimate_index_p (mode, op1, strict)) 2741 1.1 mrg return true; 2742 1.1 mrg else 2743 1.1 mrg return false; 2744 1.1 mrg } 2745 1.1 mrg 2746 1.1 mrg return false; 2747 1.1 mrg 2748 1.1 mrg case POST_INC: 2749 1.1 mrg case POST_DEC: 2750 1.1 mrg /* (mem (post_inc reg)) => [Ra], 1/2/4 */ 2751 1.1 mrg /* (mem (post_dec reg)) => [Ra], -1/-2/-4 */ 2752 1.1 mrg /* The 1/2/4 or -1/-2/-4 have been displayed in nds32.md. 2753 1.1 mrg We only need to deal with register Ra. */ 2754 1.1 mrg if (nds32_address_register_rtx_p (XEXP (x, 0), strict)) 2755 1.1 mrg return true; 2756 1.1 mrg else 2757 1.1 mrg return false; 2758 1.1 mrg 2759 1.1 mrg case PLUS: 2760 1.1 mrg /* (mem (plus reg const_int)) 2761 1.1 mrg => [Ra + imm] */ 2762 1.1 mrg /* (mem (plus reg reg)) 2763 1.1 mrg => [Ra + Rb] */ 2764 1.1 mrg /* (mem (plus (mult reg const_int) reg)) 2765 1.1 mrg => [Ra + Rb << sv] */ 2766 1.1 mrg if (nds32_address_register_rtx_p (XEXP (x, 0), strict) 2767 1.1 mrg && nds32_legitimate_index_p (mode, XEXP (x, 1), strict)) 2768 1.1 mrg return true; 2769 1.1 mrg else if (nds32_address_register_rtx_p (XEXP (x, 1), strict) 2770 1.1 mrg && nds32_legitimate_index_p (mode, XEXP (x, 0), strict)) 2771 1.1 mrg return true; 2772 1.1 mrg else 2773 1.1 mrg return false; 2774 1.1 mrg 2775 1.1 mrg case LO_SUM: 2776 1.1 mrg /* (mem (lo_sum (reg) (symbol_ref))) */ 2777 1.1 mrg /* (mem (lo_sum (reg) (const (plus (symbol_ref) (reg)))) */ 2778 1.1 mrg /* TLS case: (mem (lo_sum (reg) (const (unspec symbol_ref X)))) */ 2779 1.1 mrg /* The LO_SUM is a valid address if and only if we would like to 2780 1.1 mrg generate 32-bit full address memory access with any of following 2781 1.1 mrg circumstance: 2782 1.1 mrg 1. -mcmodel=large. 2783 1.1 mrg 2. -mcmodel=medium and the symbol_ref references to rodata. */ 2784 1.1 mrg { 2785 1.1 mrg rtx sym = NULL_RTX; 2786 1.1 mrg 2787 1.1 mrg if (flag_pic) 2788 1.1 mrg return false; 2789 1.1 mrg 2790 1.1 mrg if (!REG_P (XEXP (x, 0))) 2791 1.1 mrg return false; 2792 1.1 mrg 2793 1.1 mrg if (GET_CODE (XEXP (x, 1)) == SYMBOL_REF) 2794 1.1 mrg sym = XEXP (x, 1); 2795 1.1 mrg else if (GET_CODE (XEXP (x, 1)) == CONST) 2796 1.1 mrg { 2797 1.1 mrg rtx plus = XEXP(XEXP (x, 1), 0); 2798 1.1 mrg if (GET_CODE (plus) == PLUS) 2799 1.1 mrg sym = XEXP (plus, 0); 2800 1.1 mrg else if (GET_CODE (plus) == UNSPEC) 2801 1.1 mrg sym = XVECEXP (plus, 0, 0); 2802 1.1 mrg } 2803 1.1 mrg else 2804 1.1 mrg return false; 2805 1.1 mrg 2806 1.1 mrg gcc_assert (GET_CODE (sym) == SYMBOL_REF); 2807 1.1 mrg 2808 1.1 mrg if (TARGET_ICT_MODEL_LARGE 2809 1.1 mrg && nds32_indirect_call_referenced_p (sym)) 2810 1.1 mrg return true; 2811 1.1 mrg 2812 1.1 mrg if (TARGET_CMODEL_LARGE) 2813 1.1 mrg return true; 2814 1.1 mrg else if (TARGET_CMODEL_MEDIUM 2815 1.1 mrg && NDS32_SYMBOL_REF_RODATA_P (sym)) 2816 1.1 mrg return true; 2817 1.1 mrg else 2818 1.1 mrg return false; 2819 1.1 mrg } 2820 1.1 mrg 2821 1.1 mrg default: 2822 1.1 mrg return false; 2823 1.1 mrg } 2824 1.1 mrg } 2825 1.1 mrg 2826 1.1 mrg static rtx 2827 1.1 mrg nds32_legitimize_address (rtx x, 2828 1.1 mrg rtx oldx ATTRIBUTE_UNUSED, 2829 1.1 mrg machine_mode mode ATTRIBUTE_UNUSED) 2830 1.1 mrg { 2831 1.1 mrg if (nds32_tls_referenced_p (x)) 2832 1.1 mrg x = nds32_legitimize_tls_address (x); 2833 1.1 mrg else if (flag_pic && SYMBOLIC_CONST_P (x)) 2834 1.1 mrg x = nds32_legitimize_pic_address (x); 2835 1.1 mrg else if (TARGET_ICT_MODEL_LARGE && nds32_indirect_call_referenced_p (x)) 2836 1.1 mrg x = nds32_legitimize_ict_address (x); 2837 1.1 mrg 2838 1.1 mrg return x; 2839 1.1 mrg } 2840 1.1 mrg 2841 1.1 mrg static bool 2842 1.1 mrg nds32_legitimate_constant_p (machine_mode mode, rtx x) 2843 1.1 mrg { 2844 1.1 mrg switch (GET_CODE (x)) 2845 1.1 mrg { 2846 1.1 mrg case CONST_DOUBLE: 2847 1.1 mrg if ((TARGET_FPU_SINGLE || TARGET_FPU_DOUBLE) 2848 1.1 mrg && (mode == DFmode || mode == SFmode)) 2849 1.1 mrg return false; 2850 1.1 mrg break; 2851 1.1 mrg case CONST: 2852 1.1 mrg x = XEXP (x, 0); 2853 1.1 mrg 2854 1.1 mrg if (GET_CODE (x) == PLUS) 2855 1.1 mrg { 2856 1.1 mrg if (!CONST_INT_P (XEXP (x, 1))) 2857 1.1 mrg return false; 2858 1.1 mrg x = XEXP (x, 0); 2859 1.1 mrg } 2860 1.1 mrg 2861 1.1 mrg if (GET_CODE (x) == UNSPEC) 2862 1.1 mrg { 2863 1.1 mrg switch (XINT (x, 1)) 2864 1.1 mrg { 2865 1.1 mrg case UNSPEC_GOT: 2866 1.1 mrg case UNSPEC_GOTOFF: 2867 1.1 mrg case UNSPEC_PLT: 2868 1.1 mrg case UNSPEC_TLSGD: 2869 1.1 mrg case UNSPEC_TLSLD: 2870 1.1 mrg case UNSPEC_TLSIE: 2871 1.1 mrg case UNSPEC_TLSLE: 2872 1.1 mrg case UNSPEC_ICT: 2873 1.1 mrg return false; 2874 1.1 mrg default: 2875 1.1 mrg return true; 2876 1.1 mrg } 2877 1.1 mrg } 2878 1.1 mrg break; 2879 1.1 mrg case SYMBOL_REF: 2880 1.1 mrg /* TLS symbols need a call to resolve in 2881 1.1 mrg precompute_register_parameters. */ 2882 1.1 mrg if (SYMBOL_REF_TLS_MODEL (x)) 2883 1.1 mrg return false; 2884 1.1 mrg break; 2885 1.1 mrg default: 2886 1.1 mrg return true; 2887 1.1 mrg } 2888 1.1 mrg 2889 1.1 mrg return true; 2890 1.1 mrg } 2891 1.1 mrg 2892 1.1 mrg /* Reorgnize the UNSPEC CONST and return its direct symbol. */ 2893 1.1 mrg static rtx 2894 1.1 mrg nds32_delegitimize_address (rtx x) 2895 1.1 mrg { 2896 1.1 mrg x = delegitimize_mem_from_attrs (x); 2897 1.1 mrg 2898 1.1 mrg if (GET_CODE(x) == CONST) 2899 1.1 mrg { 2900 1.1 mrg rtx inner = XEXP (x, 0); 2901 1.1 mrg 2902 1.1 mrg /* Handle for GOTOFF. */ 2903 1.1 mrg if (GET_CODE (inner) == PLUS) 2904 1.1 mrg inner = XEXP (inner, 0); 2905 1.1 mrg 2906 1.1 mrg if (GET_CODE (inner) == UNSPEC) 2907 1.1 mrg { 2908 1.1 mrg switch (XINT (inner, 1)) 2909 1.1 mrg { 2910 1.1 mrg case UNSPEC_GOTINIT: 2911 1.1 mrg case UNSPEC_GOT: 2912 1.1 mrg case UNSPEC_GOTOFF: 2913 1.1 mrg case UNSPEC_PLT: 2914 1.1 mrg case UNSPEC_TLSGD: 2915 1.1 mrg case UNSPEC_TLSLD: 2916 1.1 mrg case UNSPEC_TLSIE: 2917 1.1 mrg case UNSPEC_TLSLE: 2918 1.1 mrg case UNSPEC_ICT: 2919 1.1 mrg x = XVECEXP (inner, 0, 0); 2920 1.1 mrg break; 2921 1.1 mrg default: 2922 1.1 mrg break; 2923 1.1 mrg } 2924 1.1 mrg } 2925 1.1 mrg } 2926 1.1 mrg return x; 2927 1.1 mrg } 2928 1.1 mrg 2929 1.1 mrg static machine_mode 2930 1.1 mrg nds32_vectorize_preferred_simd_mode (scalar_mode mode) 2931 1.1 mrg { 2932 1.1 mrg if (!NDS32_EXT_DSP_P ()) 2933 1.1 mrg return word_mode; 2934 1.1 mrg 2935 1.1 mrg switch (mode) 2936 1.1 mrg { 2937 1.1 mrg case E_QImode: 2938 1.1 mrg return V4QImode; 2939 1.1 mrg case E_HImode: 2940 1.1 mrg return V2HImode; 2941 1.1 mrg default: 2942 1.1 mrg return word_mode; 2943 1.1 mrg } 2944 1.1 mrg } 2945 1.1 mrg 2946 1.1 mrg static bool 2947 1.1 mrg nds32_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x) 2948 1.1 mrg { 2949 1.1 mrg switch (GET_CODE (x)) 2950 1.1 mrg { 2951 1.1 mrg case CONST: 2952 1.1 mrg return !nds32_legitimate_constant_p (mode, x); 2953 1.1 mrg case SYMBOL_REF: 2954 1.1 mrg /* All symbols have to be accessed through gp-relative in PIC mode. */ 2955 1.1 mrg /* We don't want to force symbol as constant pool in .text section, 2956 1.1 mrg because we use the gp-relatived instruction to load in small 2957 1.1 mrg or medium model. */ 2958 1.1 mrg if (flag_pic 2959 1.1 mrg || SYMBOL_REF_TLS_MODEL (x) 2960 1.1 mrg || TARGET_CMODEL_SMALL 2961 1.1 mrg || TARGET_CMODEL_MEDIUM) 2962 1.1 mrg return true; 2963 1.1 mrg break; 2964 1.1 mrg case CONST_INT: 2965 1.1 mrg case CONST_DOUBLE: 2966 1.1 mrg if (flag_pic && (lra_in_progress || reload_completed)) 2967 1.1 mrg return true; 2968 1.1 mrg break; 2969 1.1 mrg default: 2970 1.1 mrg return false; 2971 1.1 mrg } 2972 1.1 mrg return false; 2973 1.1 mrg } 2974 1.1 mrg 2975 1.1 mrg 2976 1.1 mrg /* Condition Code Status. */ 2978 1.1 mrg 2979 1.1 mrg /* -- Representation of condition codes using registers. */ 2980 1.1 mrg 2981 1.1 mrg static void 2982 1.1 mrg nds32_canonicalize_comparison (int *code, 2983 1.1 mrg rtx *op0 ATTRIBUTE_UNUSED, 2984 1.1 mrg rtx *op1, 2985 1.1 mrg bool op0_preserve_value ATTRIBUTE_UNUSED) 2986 1.1 mrg { 2987 1.1 mrg /* When the instruction combination pass tries to combine a comparison insn 2988 1.1 mrg with its previous insns, it also transforms the operator in order to 2989 1.1 mrg minimize its constant field. For example, it tries to transform a 2990 1.1 mrg comparison insn from 2991 1.1 mrg (set (reg:SI 54) 2992 1.1 mrg (ltu:SI (reg:SI 52) 2993 1.1 mrg (const_int 10 [0xa]))) 2994 1.1 mrg to 2995 1.1 mrg (set (reg:SI 54) 2996 1.1 mrg (leu:SI (reg:SI 52) 2997 1.1 mrg (const_int 9 [0x9]))) 2998 1.1 mrg 2999 1.1 mrg However, the nds32 target only provides instructions supporting the LTU 3000 1.1 mrg operation directly, and the implementation of the pattern "cbranchsi4" 3001 1.1 mrg only expands the LTU form. In order to handle the non-LTU operations 3002 1.1 mrg generated from passes other than the RTL expansion pass, we have to 3003 1.1 mrg implement this hook to revert those changes. Since we only expand the LTU 3004 1.1 mrg operator in the RTL expansion pass, we might only need to handle the LEU 3005 1.1 mrg case, unless we find other optimization passes perform more aggressive 3006 1.1 mrg transformations. */ 3007 1.1 mrg 3008 1.1 mrg if (*code == LEU && CONST_INT_P (*op1)) 3009 1.1 mrg { 3010 1.1 mrg *op1 = gen_int_mode (INTVAL (*op1) + 1, SImode); 3011 1.1 mrg *code = LTU; 3012 1.1 mrg } 3013 1.1 mrg } 3014 1.1 mrg 3015 1.1 mrg 3016 1.1 mrg /* Describing Relative Costs of Operations. */ 3018 1.1 mrg 3019 1.1 mrg static int 3020 1.1 mrg nds32_register_move_cost (machine_mode mode, 3021 1.1 mrg reg_class_t from, 3022 1.1 mrg reg_class_t to) 3023 1.1 mrg { 3024 1.1 mrg /* In garywolf cpu, FPR to GPR is chaper than other cpu. */ 3025 1.1 mrg if (TARGET_PIPELINE_GRAYWOLF) 3026 1.1 mrg { 3027 1.1 mrg if (GET_MODE_SIZE (mode) == 8) 3028 1.1 mrg { 3029 1.1 mrg /* DPR to GPR. */ 3030 1.1 mrg if (from == FP_REGS && to != FP_REGS) 3031 1.1 mrg return 3; 3032 1.1 mrg /* GPR to DPR. */ 3033 1.1 mrg if (from != FP_REGS && to == FP_REGS) 3034 1.1 mrg return 2; 3035 1.1 mrg } 3036 1.1 mrg else 3037 1.1 mrg { 3038 1.1 mrg if ((from == FP_REGS && to != FP_REGS) 3039 1.1 mrg || (from != FP_REGS && to == FP_REGS)) 3040 1.1 mrg return 2; 3041 1.1 mrg } 3042 1.1 mrg } 3043 1.1 mrg 3044 1.1 mrg if ((from == FP_REGS && to != FP_REGS) 3045 1.1 mrg || (from != FP_REGS && to == FP_REGS)) 3046 1.1 mrg return 3; 3047 1.1 mrg else if (from == HIGH_REGS || to == HIGH_REGS) 3048 1.1 mrg return optimize_size ? 6 : 2; 3049 1.1 mrg else 3050 1.1 mrg return 2; 3051 1.1 mrg } 3052 1.1 mrg 3053 1.1 mrg static int 3054 1.1 mrg nds32_memory_move_cost (machine_mode mode ATTRIBUTE_UNUSED, 3055 1.1 mrg reg_class_t rclass ATTRIBUTE_UNUSED, 3056 1.1 mrg bool in ATTRIBUTE_UNUSED) 3057 1.1 mrg { 3058 1.1 mrg return 8; 3059 1.1 mrg } 3060 1.1 mrg 3061 1.1 mrg /* This target hook describes the relative costs of RTL expressions. 3062 1.1 mrg Return 'true' when all subexpressions of x have been processed. 3063 1.1 mrg Return 'false' to sum the costs of sub-rtx, plus cost of this operation. 3064 1.1 mrg Refer to gcc/rtlanal.cc for more information. */ 3065 1.1 mrg static bool 3066 1.1 mrg nds32_rtx_costs (rtx x, 3067 1.1 mrg machine_mode mode, 3068 1.1 mrg int outer_code, 3069 1.1 mrg int opno, 3070 1.1 mrg int *total, 3071 1.1 mrg bool speed) 3072 1.1 mrg { 3073 1.1 mrg return nds32_rtx_costs_impl (x, mode, outer_code, opno, total, speed); 3074 1.1 mrg } 3075 1.1 mrg 3076 1.1 mrg static int 3077 1.1 mrg nds32_address_cost (rtx address, 3078 1.1 mrg machine_mode mode, 3079 1.1 mrg addr_space_t as, 3080 1.1 mrg bool speed) 3081 1.1 mrg { 3082 1.1 mrg return nds32_address_cost_impl (address, mode, as, speed); 3083 1.1 mrg } 3084 1.1 mrg 3085 1.1 mrg 3086 1.1 mrg /* Dividing the Output into Sections (Texts, Data, . . . ). */ 3088 1.1 mrg 3089 1.1 mrg /* If references to a symbol or a constant must be treated differently 3090 1.1 mrg depending on something about the variable or function named by the symbol 3091 1.1 mrg (such as what section it is in), we use this hook to store flags 3092 1.1 mrg in symbol_ref rtx. */ 3093 1.1 mrg static void 3094 1.1 mrg nds32_encode_section_info (tree decl, rtx rtl, int new_decl_p) 3095 1.1 mrg { 3096 1.1 mrg default_encode_section_info (decl, rtl, new_decl_p); 3097 1.1 mrg 3098 1.1 mrg /* For the memory rtx, if it references to rodata section, we can store 3099 1.1 mrg NDS32_SYMBOL_FLAG_RODATA flag into symbol_ref rtx so that the 3100 1.1 mrg nds32_legitimate_address_p() can determine how to treat such symbol_ref 3101 1.1 mrg based on -mcmodel=X and this information. */ 3102 1.1 mrg if (MEM_P (rtl) && MEM_READONLY_P (rtl)) 3103 1.1 mrg { 3104 1.1 mrg rtx addr = XEXP (rtl, 0); 3105 1.1 mrg 3106 1.1 mrg if (GET_CODE (addr) == SYMBOL_REF) 3107 1.1 mrg { 3108 1.1 mrg /* For (mem (symbol_ref X)) case. */ 3109 1.1 mrg SYMBOL_REF_FLAGS (addr) |= NDS32_SYMBOL_FLAG_RODATA; 3110 1.1 mrg } 3111 1.1 mrg else if (GET_CODE (addr) == CONST 3112 1.1 mrg && GET_CODE (XEXP (addr, 0)) == PLUS) 3113 1.1 mrg { 3114 1.1 mrg /* For (mem (const (plus (symbol_ref X) (const_int N)))) case. */ 3115 1.1 mrg rtx plus_op = XEXP (addr, 0); 3116 1.1 mrg rtx op0 = XEXP (plus_op, 0); 3117 1.1 mrg rtx op1 = XEXP (plus_op, 1); 3118 1.1 mrg 3119 1.1 mrg if (GET_CODE (op0) == SYMBOL_REF && CONST_INT_P (op1)) 3120 1.1 mrg SYMBOL_REF_FLAGS (op0) |= NDS32_SYMBOL_FLAG_RODATA; 3121 1.1 mrg } 3122 1.1 mrg } 3123 1.1 mrg } 3124 1.1 mrg 3125 1.1 mrg 3126 1.1 mrg /* Defining the Output Assembler Language. */ 3128 1.1 mrg 3129 1.1 mrg /* -- The Overall Framework of an Assembler File. */ 3130 1.1 mrg 3131 1.1 mrg static void 3132 1.1 mrg nds32_asm_file_start (void) 3133 1.1 mrg { 3134 1.1 mrg default_file_start (); 3135 1.1 mrg 3136 1.1 mrg if (flag_pic) 3137 1.1 mrg fprintf (asm_out_file, "\t.pic\n"); 3138 1.1 mrg 3139 1.1 mrg /* Tell assembler which ABI we are using. */ 3140 1.1 mrg fprintf (asm_out_file, "\t! ABI version\n"); 3141 1.1 mrg if (TARGET_HARD_FLOAT) 3142 1.1 mrg fprintf (asm_out_file, "\t.abi_2fp_plus\n"); 3143 1.1 mrg else 3144 1.1 mrg fprintf (asm_out_file, "\t.abi_2\n"); 3145 1.1 mrg 3146 1.1 mrg /* Tell assembler that this asm code is generated by compiler. */ 3147 1.1 mrg fprintf (asm_out_file, "\t! This asm file is generated by compiler\n"); 3148 1.1 mrg fprintf (asm_out_file, "\t.flag\tverbatim\n"); 3149 1.1 mrg 3150 1.1 mrg /* Insert directive for linker to distinguish object's ict flag. */ 3151 1.1 mrg if (!TARGET_LINUX_ABI) 3152 1.1 mrg { 3153 1.1 mrg if (TARGET_ICT_MODEL_LARGE) 3154 1.1 mrg fprintf (asm_out_file, "\t.ict_model\tlarge\n"); 3155 1.1 mrg else 3156 1.1 mrg fprintf (asm_out_file, "\t.ict_model\tsmall\n"); 3157 1.1 mrg } 3158 1.1 mrg 3159 1.1 mrg /* We need to provide the size of each vector for interrupt handler 3160 1.1 mrg under elf toolchain. */ 3161 1.1 mrg if (!TARGET_LINUX_ABI) 3162 1.1 mrg { 3163 1.1 mrg fprintf (asm_out_file, "\t! This vector size directive is required " 3164 1.1 mrg "for checking inconsistency on interrupt handler\n"); 3165 1.1 mrg fprintf (asm_out_file, "\t.vec_size\t%d\n", nds32_isr_vector_size); 3166 1.1 mrg } 3167 1.1 mrg 3168 1.1 mrg /* If user enables '-mforce-fp-as-gp' or compiles programs with -Os, 3169 1.1 mrg the compiler may produce 'la $fp,_FP_BASE_' instruction 3170 1.1 mrg at prologue for fp-as-gp optimization. 3171 1.1 mrg We should emit weak reference of _FP_BASE_ to avoid undefined reference 3172 1.1 mrg in case user does not pass '--relax' option to linker. */ 3173 1.1 mrg if (!TARGET_LINUX_ABI && (TARGET_FORCE_FP_AS_GP || optimize_size)) 3174 1.1 mrg { 3175 1.1 mrg fprintf (asm_out_file, "\t! This weak reference is required to do " 3176 1.1 mrg "fp-as-gp link time optimization\n"); 3177 1.1 mrg fprintf (asm_out_file, "\t.weak\t_FP_BASE_\n"); 3178 1.1 mrg } 3179 1.1 mrg 3180 1.1 mrg fprintf (asm_out_file, "\t! ------------------------------------\n"); 3181 1.1 mrg 3182 1.1 mrg if (TARGET_ISA_V2) 3183 1.1 mrg fprintf (asm_out_file, "\t! ISA family\t\t: %s\n", "V2"); 3184 1.1 mrg if (TARGET_ISA_V3) 3185 1.1 mrg fprintf (asm_out_file, "\t! ISA family\t\t: %s\n", "V3"); 3186 1.1 mrg if (TARGET_ISA_V3M) 3187 1.1 mrg fprintf (asm_out_file, "\t! ISA family\t\t: %s\n", "V3M"); 3188 1.1 mrg 3189 1.1 mrg switch (nds32_cpu_option) 3190 1.1 mrg { 3191 1.1 mrg case CPU_N6: 3192 1.1 mrg fprintf (asm_out_file, "\t! Pipeline model\t: %s\n", "N6"); 3193 1.1 mrg break; 3194 1.1 mrg 3195 1.1 mrg case CPU_N7: 3196 1.1 mrg fprintf (asm_out_file, "\t! Pipeline model\t: %s\n", "N7"); 3197 1.1 mrg break; 3198 1.1 mrg 3199 1.1 mrg case CPU_N8: 3200 1.1 mrg fprintf (asm_out_file, "\t! Pipeline model\t: %s\n", "N8"); 3201 1.1 mrg break; 3202 1.1 mrg 3203 1.1 mrg case CPU_E8: 3204 1.1 mrg fprintf (asm_out_file, "\t! Pipeline model\t: %s\n", "E8"); 3205 1.1 mrg break; 3206 1.1 mrg 3207 1.1 mrg case CPU_N9: 3208 1.1 mrg fprintf (asm_out_file, "\t! Pipeline model\t: %s\n", "N9"); 3209 1.1 mrg break; 3210 1.1 mrg 3211 1.1 mrg case CPU_N10: 3212 1.1 mrg fprintf (asm_out_file, "\t! Pipeline model\t: %s\n", "N10"); 3213 1.1 mrg break; 3214 1.1 mrg 3215 1.1 mrg case CPU_GRAYWOLF: 3216 1.1 mrg fprintf (asm_out_file, "\t! Pipeline model\t: %s\n", "Graywolf"); 3217 1.1 mrg break; 3218 1.1 mrg 3219 1.1 mrg case CPU_N12: 3220 1.1 mrg case CPU_N13: 3221 1.1 mrg fprintf (asm_out_file, "\t! Pipeline model\t: %s\n", "N13"); 3222 1.1 mrg break; 3223 1.1 mrg 3224 1.1 mrg case CPU_SIMPLE: 3225 1.1 mrg fprintf (asm_out_file, "\t! Pipeline model\t: %s\n", "SIMPLE"); 3226 1.1 mrg break; 3227 1.1 mrg 3228 1.1 mrg default: 3229 1.1 mrg gcc_unreachable (); 3230 1.1 mrg } 3231 1.1 mrg 3232 1.1 mrg if (TARGET_CMODEL_SMALL) 3233 1.1 mrg fprintf (asm_out_file, "\t! Code model\t\t: %s\n", "SMALL"); 3234 1.1 mrg if (TARGET_CMODEL_MEDIUM) 3235 1.1 mrg fprintf (asm_out_file, "\t! Code model\t\t: %s\n", "MEDIUM"); 3236 1.1 mrg if (TARGET_CMODEL_LARGE) 3237 1.1 mrg fprintf (asm_out_file, "\t! Code model\t\t: %s\n", "LARGE"); 3238 1.1 mrg 3239 1.1 mrg fprintf (asm_out_file, "\t! Endian setting\t: %s\n", 3240 1.1 mrg ((TARGET_BIG_ENDIAN) ? "big-endian" 3241 1.1 mrg : "little-endian")); 3242 1.1 mrg fprintf (asm_out_file, "\t! Use SP floating-point instruction\t: %s\n", 3243 1.1 mrg ((TARGET_FPU_SINGLE) ? "Yes" 3244 1.1 mrg : "No")); 3245 1.1 mrg fprintf (asm_out_file, "\t! Use DP floating-point instruction\t: %s\n", 3246 1.1 mrg ((TARGET_FPU_DOUBLE) ? "Yes" 3247 1.1 mrg : "No")); 3248 1.1 mrg fprintf (asm_out_file, "\t! ABI version\t\t: %s\n", 3249 1.1 mrg ((TARGET_HARD_FLOAT) ? "ABI2FP+" 3250 1.1 mrg : "ABI2")); 3251 1.1 mrg 3252 1.1 mrg fprintf (asm_out_file, "\t! ------------------------------------\n"); 3253 1.1 mrg 3254 1.1 mrg fprintf (asm_out_file, "\t! Use conditional move\t\t: %s\n", 3255 1.1 mrg ((TARGET_CMOV) ? "Yes" 3256 1.1 mrg : "No")); 3257 1.1 mrg fprintf (asm_out_file, "\t! Use performance extension\t: %s\n", 3258 1.1 mrg ((TARGET_EXT_PERF) ? "Yes" 3259 1.1 mrg : "No")); 3260 1.1 mrg fprintf (asm_out_file, "\t! Use performance extension 2\t: %s\n", 3261 1.1 mrg ((TARGET_EXT_PERF2) ? "Yes" 3262 1.1 mrg : "No")); 3263 1.1 mrg fprintf (asm_out_file, "\t! Use string extension\t\t: %s\n", 3264 1.1 mrg ((TARGET_EXT_STRING) ? "Yes" 3265 1.1 mrg : "No")); 3266 1.1 mrg 3267 1.1 mrg fprintf (asm_out_file, "\t! ------------------------------------\n"); 3268 1.1 mrg 3269 1.1 mrg fprintf (asm_out_file, "\t! V3PUSH instructions\t: %s\n", 3270 1.1 mrg ((TARGET_V3PUSH) ? "Yes" 3271 1.1 mrg : "No")); 3272 1.1 mrg fprintf (asm_out_file, "\t! 16-bit instructions\t: %s\n", 3273 1.1 mrg ((TARGET_16_BIT) ? "Yes" 3274 1.1 mrg : "No")); 3275 1.1 mrg fprintf (asm_out_file, "\t! Reduced registers set\t: %s\n", 3276 1.1 mrg ((TARGET_REDUCED_REGS) ? "Yes" 3277 1.1 mrg : "No")); 3278 1.1 mrg 3279 1.1 mrg fprintf (asm_out_file, "\t! Support unaligned access\t\t: %s\n", 3280 1.1 mrg (flag_unaligned_access ? "Yes" 3281 1.1 mrg : "No")); 3282 1.1 mrg 3283 1.1 mrg fprintf (asm_out_file, "\t! ------------------------------------\n"); 3284 1.1 mrg 3285 1.1 mrg if (optimize_size) 3286 1.1 mrg fprintf (asm_out_file, "\t! Optimization level\t: -Os\n"); 3287 1.1 mrg else if (optimize_fast) 3288 1.1 mrg fprintf (asm_out_file, "\t! Optimization level\t: -Ofast\n"); 3289 1.1 mrg else if (optimize_debug) 3290 1.1 mrg fprintf (asm_out_file, "\t! Optimization level\t: -Og\n"); 3291 1.1 mrg else 3292 1.1 mrg fprintf (asm_out_file, "\t! Optimization level\t: -O%d\n", optimize); 3293 1.1 mrg 3294 1.1 mrg fprintf (asm_out_file, "\t! ------------------------------------\n"); 3295 1.1 mrg 3296 1.1 mrg fprintf (asm_out_file, "\t! Cache block size\t: %d\n", 3297 1.1 mrg nds32_cache_block_size); 3298 1.1 mrg 3299 1.1 mrg fprintf (asm_out_file, "\t! ------------------------------------\n"); 3300 1.1 mrg 3301 1.1 mrg nds32_asm_file_start_for_isr (); 3302 1.1 mrg } 3303 1.1 mrg 3304 1.1 mrg static void 3305 1.1 mrg nds32_asm_file_end (void) 3306 1.1 mrg { 3307 1.1 mrg nds32_asm_file_end_for_isr (); 3308 1.1 mrg 3309 1.1 mrg /* The NDS32 Linux stack is mapped non-executable by default, so add a 3310 1.1 mrg .note.GNU-stack section. */ 3311 1.1 mrg if (TARGET_LINUX_ABI) 3312 1.1 mrg file_end_indicate_exec_stack (); 3313 1.1 mrg 3314 1.1 mrg fprintf (asm_out_file, "\t! ------------------------------------\n"); 3315 1.1 mrg } 3316 1.1 mrg 3317 1.1 mrg static bool 3318 1.1 mrg nds32_asm_output_addr_const_extra (FILE *file, rtx x) 3319 1.1 mrg { 3320 1.1 mrg if (GET_CODE (x) == UNSPEC) 3321 1.1 mrg { 3322 1.1 mrg switch (XINT (x, 1)) 3323 1.1 mrg { 3324 1.1 mrg case UNSPEC_GOTINIT: 3325 1.1 mrg output_addr_const (file, XVECEXP (x, 0, 0)); 3326 1.1 mrg break; 3327 1.1 mrg case UNSPEC_GOTOFF: 3328 1.1 mrg output_addr_const (file, XVECEXP (x, 0, 0)); 3329 1.1 mrg fputs ("@GOTOFF", file); 3330 1.1 mrg break; 3331 1.1 mrg case UNSPEC_GOT: 3332 1.1 mrg output_addr_const (file, XVECEXP (x, 0, 0)); 3333 1.1 mrg fputs ("@GOT", file); 3334 1.1 mrg break; 3335 1.1 mrg case UNSPEC_PLT: 3336 1.1 mrg output_addr_const (file, XVECEXP (x, 0, 0)); 3337 1.1 mrg fputs ("@PLT", file); 3338 1.1 mrg break; 3339 1.1 mrg case UNSPEC_TLSGD: 3340 1.1 mrg output_addr_const (file, XVECEXP (x, 0, 0)); 3341 1.1 mrg fputs ("@TLSDESC", file); 3342 1.1 mrg break; 3343 1.1 mrg case UNSPEC_TLSLD: 3344 1.1 mrg output_addr_const (file, XVECEXP (x, 0, 0)); 3345 1.1 mrg fputs ("@TLSDESC", file); 3346 1.1 mrg break; 3347 1.1 mrg case UNSPEC_TLSIE: 3348 1.1 mrg output_addr_const (file, XVECEXP (x, 0, 0)); 3349 1.1 mrg fputs ("@GOTTPOFF", file); 3350 1.1 mrg break; 3351 1.1 mrg case UNSPEC_TLSLE: 3352 1.1 mrg output_addr_const (file, XVECEXP (x, 0, 0)); 3353 1.1 mrg fputs ("@TPOFF", file); 3354 1.1 mrg break; 3355 1.1 mrg case UNSPEC_ICT: 3356 1.1 mrg output_addr_const (file, XVECEXP (x, 0, 0)); 3357 1.1 mrg fputs ("@ICT", file); 3358 1.1 mrg break; 3359 1.1 mrg default: 3360 1.1 mrg return false; 3361 1.1 mrg } 3362 1.1 mrg return true; 3363 1.1 mrg } 3364 1.1 mrg else 3365 1.1 mrg return false; 3366 1.1 mrg } 3367 1.1 mrg 3368 1.1 mrg /* -- Output and Generation of Labels. */ 3369 1.1 mrg 3370 1.1 mrg static void 3371 1.1 mrg nds32_asm_globalize_label (FILE *stream, const char *name) 3372 1.1 mrg { 3373 1.1 mrg fputs ("\t.global\t", stream); 3374 1.1 mrg assemble_name (stream, name); 3375 1.1 mrg fputs ("\n", stream); 3376 1.1 mrg } 3377 1.1 mrg 3378 1.1 mrg /* -- Output of Assembler Instructions. */ 3379 1.1 mrg 3380 1.1 mrg static void 3381 1.1 mrg nds32_print_operand (FILE *stream, rtx x, int code) 3382 1.1 mrg { 3383 1.1 mrg HOST_WIDE_INT op_value = 0; 3384 1.1 mrg HOST_WIDE_INT one_position; 3385 1.1 mrg HOST_WIDE_INT zero_position; 3386 1.1 mrg bool pick_lsb_p = false; 3387 1.1 mrg bool pick_msb_p = false; 3388 1.1 mrg int regno; 3389 1.1 mrg 3390 1.1 mrg if (CONST_INT_P (x)) 3391 1.1 mrg op_value = INTVAL (x); 3392 1.1 mrg 3393 1.1 mrg switch (code) 3394 1.1 mrg { 3395 1.1 mrg case 0 : 3396 1.1 mrg /* Do nothing special. */ 3397 1.1 mrg break; 3398 1.1 mrg 3399 1.1 mrg case 'b': 3400 1.1 mrg /* Use exact_log2() to search the 0-bit position. */ 3401 1.1 mrg gcc_assert (CONST_INT_P (x)); 3402 1.1 mrg zero_position = exact_log2 (~UINTVAL (x) & GET_MODE_MASK (SImode)); 3403 1.1 mrg gcc_assert (zero_position != -1); 3404 1.1 mrg fprintf (stream, HOST_WIDE_INT_PRINT_DEC, zero_position); 3405 1.1 mrg 3406 1.1 mrg /* No need to handle following process, so return immediately. */ 3407 1.1 mrg return; 3408 1.1 mrg 3409 1.1 mrg case 'e': 3410 1.1 mrg gcc_assert (MEM_P (x) 3411 1.1 mrg && GET_CODE (XEXP (x, 0)) == PLUS 3412 1.1 mrg && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT); 3413 1.1 mrg fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (XEXP (x, 0), 1))); 3414 1.1 mrg 3415 1.1 mrg /* No need to handle following process, so return immediately. */ 3416 1.1 mrg return; 3417 1.1 mrg 3418 1.1 mrg case 'v': 3419 1.1 mrg gcc_assert (CONST_INT_P (x) 3420 1.1 mrg && (INTVAL (x) == 0 3421 1.1 mrg || INTVAL (x) == 8 3422 1.1 mrg || INTVAL (x) == 16 3423 1.1 mrg || INTVAL (x) == 24)); 3424 1.1 mrg fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) / 8); 3425 1.1 mrg 3426 1.1 mrg /* No need to handle following process, so return immediately. */ 3427 1.1 mrg return; 3428 1.1 mrg 3429 1.1 mrg case 'B': 3430 1.1 mrg /* Use exact_log2() to search the 1-bit position. */ 3431 1.1 mrg gcc_assert (CONST_INT_P (x)); 3432 1.1 mrg one_position = exact_log2 (UINTVAL (x) & GET_MODE_MASK (SImode)); 3433 1.1 mrg gcc_assert (one_position != -1); 3434 1.1 mrg fprintf (stream, HOST_WIDE_INT_PRINT_DEC, one_position); 3435 1.1 mrg 3436 1.1 mrg /* No need to handle following process, so return immediately. */ 3437 1.1 mrg return; 3438 1.1 mrg 3439 1.1 mrg case 'L': 3440 1.1 mrg /* X is supposed to be REG rtx. */ 3441 1.1 mrg gcc_assert (REG_P (x)); 3442 1.1 mrg /* Claim that we are going to pick LSB part of X. */ 3443 1.1 mrg pick_lsb_p = true; 3444 1.1 mrg break; 3445 1.1 mrg 3446 1.1 mrg case 'H': 3447 1.1 mrg /* X is supposed to be REG rtx. */ 3448 1.1 mrg gcc_assert (REG_P (x)); 3449 1.1 mrg /* Claim that we are going to pick MSB part of X. */ 3450 1.1 mrg pick_msb_p = true; 3451 1.1 mrg break; 3452 1.1 mrg 3453 1.1 mrg case 'V': 3454 1.1 mrg /* 'x' is supposed to be CONST_INT, get the value. */ 3455 1.1 mrg gcc_assert (CONST_INT_P (x)); 3456 1.1 mrg 3457 1.1 mrg /* According to the Andes architecture, 3458 1.1 mrg the system/user register index range is 0 ~ 1023. 3459 1.1 mrg In order to avoid conflict between user-specified-integer value 3460 1.1 mrg and enum-specified-register value, 3461 1.1 mrg the 'enum nds32_intrinsic_registers' value 3462 1.1 mrg in nds32_intrinsic.h starts from 1024. */ 3463 1.1 mrg if (op_value < 1024 && op_value >= 0) 3464 1.1 mrg { 3465 1.1 mrg /* If user gives integer value directly (0~1023), 3466 1.1 mrg we just print out the value. */ 3467 1.1 mrg fprintf (stream, HOST_WIDE_INT_PRINT_DEC, op_value); 3468 1.1 mrg } 3469 1.1 mrg else if (op_value < 0 3470 1.1 mrg || op_value >= ((int) ARRAY_SIZE (nds32_intrinsic_register_names) 3471 1.1 mrg + 1024)) 3472 1.1 mrg { 3473 1.1 mrg /* The enum index value for array size is out of range. */ 3474 1.1 mrg error ("intrinsic register index is out of range"); 3475 1.1 mrg } 3476 1.1 mrg else 3477 1.1 mrg { 3478 1.1 mrg /* If user applies normal way with __NDS32_REG_XXX__ enum data, 3479 1.1 mrg we can print out register name. Remember to substract 1024. */ 3480 1.1 mrg fprintf (stream, "%s", 3481 1.1 mrg nds32_intrinsic_register_names[op_value - 1024]); 3482 1.1 mrg } 3483 1.1 mrg 3484 1.1 mrg /* No need to handle following process, so return immediately. */ 3485 1.1 mrg return; 3486 1.1 mrg 3487 1.1 mrg case 'R': /* cctl valck */ 3488 1.1 mrg /* Note the cctl divide to 5 group and share the same name table. */ 3489 1.1 mrg if (op_value < 0 || op_value > 4) 3490 1.1 mrg error ("CCTL intrinsic function subtype out of range"); 3491 1.1 mrg fprintf (stream, "%s", nds32_cctl_names[op_value]); 3492 1.1 mrg return; 3493 1.1 mrg 3494 1.1 mrg case 'T': /* cctl idxwbinv */ 3495 1.1 mrg /* Note the cctl divide to 5 group and share the same name table. */ 3496 1.1 mrg if (op_value < 0 || op_value > 4) 3497 1.1 mrg error ("CCTL intrinsic function subtype out of range"); 3498 1.1 mrg fprintf (stream, "%s", nds32_cctl_names[op_value + 4]); 3499 1.1 mrg return; 3500 1.1 mrg 3501 1.1 mrg case 'U': /* cctl vawbinv */ 3502 1.1 mrg /* Note the cctl divide to 5 group and share the same name table. */ 3503 1.1 mrg if (op_value < 0 || op_value > 4) 3504 1.1 mrg error ("CCTL intrinsic function subtype out of range"); 3505 1.1 mrg fprintf (stream, "%s", nds32_cctl_names[op_value + 8]); 3506 1.1 mrg return; 3507 1.1 mrg 3508 1.1 mrg case 'X': /* cctl idxread */ 3509 1.1 mrg /* Note the cctl divide to 5 group and share the same name table. */ 3510 1.1 mrg if (op_value < 0 || op_value > 4) 3511 1.1 mrg error ("CCTL intrinsic function subtype out of range"); 3512 1.1 mrg fprintf (stream, "%s", nds32_cctl_names[op_value + 12]); 3513 1.1 mrg return; 3514 1.1 mrg 3515 1.1 mrg case 'W': /* cctl idxwitre */ 3516 1.1 mrg /* Note the cctl divide to 5 group and share the same name table. */ 3517 1.1 mrg if (op_value < 0 || op_value > 4) 3518 1.1 mrg error ("CCTL intrinsic function subtype out of range"); 3519 1.1 mrg fprintf (stream, "%s", nds32_cctl_names[op_value + 16]); 3520 1.1 mrg return; 3521 1.1 mrg 3522 1.1 mrg case 'Z': /* dpref */ 3523 1.1 mrg fprintf (stream, "%s", nds32_dpref_names[op_value]); 3524 1.1 mrg return; 3525 1.1 mrg 3526 1.1 mrg default : 3527 1.1 mrg /* Unknown flag. */ 3528 1.1 mrg output_operand_lossage ("invalid operand output code"); 3529 1.1 mrg break; 3530 1.1 mrg } 3531 1.1 mrg 3532 1.1 mrg switch (GET_CODE (x)) 3533 1.1 mrg { 3534 1.1 mrg case LABEL_REF: 3535 1.1 mrg output_addr_const (stream, x); 3536 1.1 mrg break; 3537 1.1 mrg 3538 1.1 mrg case SYMBOL_REF: 3539 1.1 mrg output_addr_const (stream, x); 3540 1.1 mrg 3541 1.1 mrg if (!TARGET_LINUX_ABI && nds32_indirect_call_referenced_p (x)) 3542 1.1 mrg fprintf (stream, "@ICT"); 3543 1.1 mrg 3544 1.1 mrg break; 3545 1.1 mrg 3546 1.1 mrg case REG: 3547 1.1 mrg /* Print a Double-precision register name. */ 3548 1.1 mrg if ((GET_MODE (x) == DImode || GET_MODE (x) == DFmode) 3549 1.1 mrg && NDS32_IS_FPR_REGNUM (REGNO (x))) 3550 1.1 mrg { 3551 1.1 mrg regno = REGNO (x); 3552 1.1 mrg if (!NDS32_FPR_REGNO_OK_FOR_DOUBLE (regno)) 3553 1.1 mrg { 3554 1.1 mrg output_operand_lossage ("invalid operand for code '%c'", code); 3555 1.1 mrg break; 3556 1.1 mrg } 3557 1.1 mrg fprintf (stream, "$fd%d", (regno - NDS32_FIRST_FPR_REGNUM) >> 1); 3558 1.1 mrg break; 3559 1.1 mrg } 3560 1.1 mrg 3561 1.1 mrg /* Print LSB or MSB part of register pair if the 3562 1.1 mrg constraint modifier 'L' or 'H' is specified. */ 3563 1.1 mrg if ((GET_MODE (x) == DImode || GET_MODE (x) == DFmode) 3564 1.1 mrg && NDS32_IS_GPR_REGNUM (REGNO (x))) 3565 1.1 mrg { 3566 1.1 mrg if ((pick_lsb_p && WORDS_BIG_ENDIAN) 3567 1.1 mrg || (pick_msb_p && !WORDS_BIG_ENDIAN)) 3568 1.1 mrg { 3569 1.1 mrg /* If we would like to print out LSB register under big-endian, 3570 1.1 mrg or print out MSB register under little-endian, we need to 3571 1.1 mrg increase register number. */ 3572 1.1 mrg regno = REGNO (x); 3573 1.1 mrg regno++; 3574 1.1 mrg fputs (reg_names[regno], stream); 3575 1.1 mrg break; 3576 1.1 mrg } 3577 1.1 mrg } 3578 1.1 mrg 3579 1.1 mrg /* Forbid using static chain register ($r16) 3580 1.1 mrg on reduced-set registers configuration. */ 3581 1.1 mrg if (TARGET_REDUCED_REGS 3582 1.1 mrg && REGNO (x) == STATIC_CHAIN_REGNUM) 3583 1.1 mrg sorry ("a nested function is not supported for reduced registers"); 3584 1.1 mrg 3585 1.1 mrg /* Normal cases, print out register name. */ 3586 1.1 mrg fputs (reg_names[REGNO (x)], stream); 3587 1.1 mrg break; 3588 1.1 mrg 3589 1.1 mrg case MEM: 3590 1.1 mrg output_address (GET_MODE (x), XEXP (x, 0)); 3591 1.1 mrg break; 3592 1.1 mrg 3593 1.1 mrg case HIGH: 3594 1.1 mrg if (GET_CODE (XEXP (x, 0)) == CONST_DOUBLE) 3595 1.1 mrg { 3596 1.1 mrg const REAL_VALUE_TYPE *rv; 3597 1.1 mrg long val; 3598 1.1 mrg gcc_assert (GET_MODE (x) == SFmode); 3599 1.1 mrg 3600 1.1 mrg rv = CONST_DOUBLE_REAL_VALUE (XEXP (x, 0)); 3601 1.1 mrg REAL_VALUE_TO_TARGET_SINGLE (*rv, val); 3602 1.1 mrg 3603 1.1 mrg fprintf (stream, "hi20(0x%lx)", val); 3604 1.1 mrg } 3605 1.1 mrg else 3606 1.1 mrg gcc_unreachable (); 3607 1.1 mrg break; 3608 1.1 mrg 3609 1.1 mrg case CONST_DOUBLE: 3610 1.1 mrg const REAL_VALUE_TYPE *rv; 3611 1.1 mrg long val; 3612 1.1 mrg gcc_assert (GET_MODE (x) == SFmode); 3613 1.1 mrg 3614 1.1 mrg rv = CONST_DOUBLE_REAL_VALUE (x); 3615 1.1 mrg REAL_VALUE_TO_TARGET_SINGLE (*rv, val); 3616 1.1 mrg 3617 1.1 mrg fprintf (stream, "0x%lx", val); 3618 1.1 mrg break; 3619 1.1 mrg 3620 1.1 mrg case CODE_LABEL: 3621 1.1 mrg case CONST_INT: 3622 1.1 mrg case CONST: 3623 1.1 mrg output_addr_const (stream, x); 3624 1.1 mrg break; 3625 1.1 mrg 3626 1.1 mrg case CONST_VECTOR: 3627 1.1 mrg fprintf (stream, HOST_WIDE_INT_PRINT_HEX, const_vector_to_hwint (x)); 3628 1.1 mrg break; 3629 1.1 mrg 3630 1.1 mrg case LO_SUM: 3631 1.1 mrg /* This is a special case for inline assembly using memory address 'p'. 3632 1.1 mrg The inline assembly code is expected to use pesudo instruction 3633 1.1 mrg for the operand. EX: la */ 3634 1.1 mrg output_addr_const (stream, XEXP(x, 1)); 3635 1.1 mrg break; 3636 1.1 mrg 3637 1.1 mrg default: 3638 1.1 mrg /* Generally, output_addr_const () is able to handle most cases. 3639 1.1 mrg We want to see what CODE could appear, 3640 1.1 mrg so we use gcc_unreachable() to stop it. */ 3641 1.1 mrg debug_rtx (x); 3642 1.1 mrg gcc_unreachable (); 3643 1.1 mrg break; 3644 1.1 mrg } 3645 1.1 mrg } 3646 1.1 mrg 3647 1.1 mrg static void 3648 1.1 mrg nds32_print_operand_address (FILE *stream, 3649 1.1 mrg machine_mode mode ATTRIBUTE_UNUSED, 3650 1.1 mrg rtx x) 3651 1.1 mrg { 3652 1.1 mrg rtx op0, op1; 3653 1.1 mrg 3654 1.1 mrg switch (GET_CODE (x)) 3655 1.1 mrg { 3656 1.1 mrg case SYMBOL_REF: 3657 1.1 mrg case CONST: 3658 1.1 mrg /* [ + symbol_ref] */ 3659 1.1 mrg /* [ + const_addr], where const_addr = symbol_ref + const_int */ 3660 1.1 mrg fputs ("[ + ", stream); 3661 1.1 mrg output_addr_const (stream, x); 3662 1.1 mrg fputs ("]", stream); 3663 1.1 mrg break; 3664 1.1 mrg 3665 1.1 mrg case LO_SUM: 3666 1.1 mrg /* This is a special case for inline assembly using memory operand 'm'. 3667 1.1 mrg The inline assembly code is expected to use pesudo instruction 3668 1.1 mrg for the operand. EX: [ls].[bhw] */ 3669 1.1 mrg fputs ("[ + ", stream); 3670 1.1 mrg op1 = XEXP (x, 1); 3671 1.1 mrg output_addr_const (stream, op1); 3672 1.1 mrg fputs ("]", stream); 3673 1.1 mrg break; 3674 1.1 mrg 3675 1.1 mrg case REG: 3676 1.1 mrg /* Forbid using static chain register ($r16) 3677 1.1 mrg on reduced-set registers configuration. */ 3678 1.1 mrg if (TARGET_REDUCED_REGS 3679 1.1 mrg && REGNO (x) == STATIC_CHAIN_REGNUM) 3680 1.1 mrg sorry ("a nested function is not supported for reduced registers"); 3681 1.1 mrg 3682 1.1 mrg /* [Ra] */ 3683 1.1 mrg fprintf (stream, "[%s]", reg_names[REGNO (x)]); 3684 1.1 mrg break; 3685 1.1 mrg 3686 1.1 mrg case PLUS: 3687 1.1 mrg op0 = XEXP (x, 0); 3688 1.1 mrg op1 = XEXP (x, 1); 3689 1.1 mrg 3690 1.1 mrg /* Checking op0, forbid using static chain register ($r16) 3691 1.1 mrg on reduced-set registers configuration. */ 3692 1.1 mrg if (TARGET_REDUCED_REGS 3693 1.1 mrg && REG_P (op0) 3694 1.1 mrg && REGNO (op0) == STATIC_CHAIN_REGNUM) 3695 1.1 mrg sorry ("a nested function is not supported for reduced registers"); 3696 1.1 mrg /* Checking op1, forbid using static chain register ($r16) 3697 1.1 mrg on reduced-set registers configuration. */ 3698 1.1 mrg if (TARGET_REDUCED_REGS 3699 1.1 mrg && REG_P (op1) 3700 1.1 mrg && REGNO (op1) == STATIC_CHAIN_REGNUM) 3701 1.1 mrg sorry ("a nested function is not supported for reduced registers"); 3702 1.1 mrg 3703 1.1 mrg if (REG_P (op0) && CONST_INT_P (op1)) 3704 1.1 mrg { 3705 1.1 mrg /* [Ra + imm] */ 3706 1.1 mrg fprintf (stream, "[%s + (" HOST_WIDE_INT_PRINT_DEC ")]", 3707 1.1 mrg reg_names[REGNO (op0)], INTVAL (op1)); 3708 1.1 mrg } 3709 1.1 mrg else if (REG_P (op0) && REG_P (op1)) 3710 1.1 mrg { 3711 1.1 mrg /* [Ra + Rb] */ 3712 1.1 mrg fprintf (stream, "[%s + %s]", 3713 1.1 mrg reg_names[REGNO (op0)], reg_names[REGNO (op1)]); 3714 1.1 mrg } 3715 1.1 mrg else if (GET_CODE (op0) == MULT && REG_P (op1)) 3716 1.1 mrg { 3717 1.1 mrg /* [Ra + Rb << sv] 3718 1.1 mrg From observation, the pattern looks like: 3719 1.1 mrg (plus:SI (mult:SI (reg:SI 58) 3720 1.1 mrg (const_int 4 [0x4])) 3721 1.1 mrg (reg/f:SI 57)) */ 3722 1.1 mrg int sv; 3723 1.1 mrg 3724 1.1 mrg /* We need to set sv to output shift value. */ 3725 1.1 mrg if (INTVAL (XEXP (op0, 1)) == 1) 3726 1.1 mrg sv = 0; 3727 1.1 mrg else if (INTVAL (XEXP (op0, 1)) == 2) 3728 1.1 mrg sv = 1; 3729 1.1 mrg else if (INTVAL (XEXP (op0, 1)) == 4) 3730 1.1 mrg sv = 2; 3731 1.1 mrg else if (INTVAL (XEXP (op0, 1)) == 8) 3732 1.1 mrg sv = 3; 3733 1.1 mrg else 3734 1.1 mrg gcc_unreachable (); 3735 1.1 mrg 3736 1.1 mrg fprintf (stream, "[%s + %s << %d]", 3737 1.1 mrg reg_names[REGNO (op1)], 3738 1.1 mrg reg_names[REGNO (XEXP (op0, 0))], 3739 1.1 mrg sv); 3740 1.1 mrg } 3741 1.1 mrg else if (GET_CODE (op0) == ASHIFT && REG_P (op1)) 3742 1.1 mrg { 3743 1.1 mrg /* [Ra + Rb << sv] 3744 1.1 mrg In normal, ASHIFT can be converted to MULT like above case. 3745 1.1 mrg But when the address rtx does not go through canonicalize_address 3746 1.1 mrg defined in fwprop, we'll need this case. */ 3747 1.1 mrg int sv = INTVAL (XEXP (op0, 1)); 3748 1.1 mrg gcc_assert (sv <= 3 && sv >=0); 3749 1.1 mrg 3750 1.1 mrg fprintf (stream, "[%s + %s << %d]", 3751 1.1 mrg reg_names[REGNO (op1)], 3752 1.1 mrg reg_names[REGNO (XEXP (op0, 0))], 3753 1.1 mrg sv); 3754 1.1 mrg } 3755 1.1 mrg else 3756 1.1 mrg { 3757 1.1 mrg /* The control flow is not supposed to be here. */ 3758 1.1 mrg debug_rtx (x); 3759 1.1 mrg gcc_unreachable (); 3760 1.1 mrg } 3761 1.1 mrg 3762 1.1 mrg break; 3763 1.1 mrg 3764 1.1 mrg case POST_MODIFY: 3765 1.1 mrg /* (post_modify (regA) (plus (regA) (regB))) 3766 1.1 mrg (post_modify (regA) (plus (regA) (const_int))) 3767 1.1 mrg We would like to extract 3768 1.1 mrg regA and regB (or const_int) from plus rtx. */ 3769 1.1 mrg op0 = XEXP (XEXP (x, 1), 0); 3770 1.1 mrg op1 = XEXP (XEXP (x, 1), 1); 3771 1.1 mrg 3772 1.1 mrg /* Checking op0, forbid using static chain register ($r16) 3773 1.1 mrg on reduced-set registers configuration. */ 3774 1.1 mrg if (TARGET_REDUCED_REGS 3775 1.1 mrg && REG_P (op0) 3776 1.1 mrg && REGNO (op0) == STATIC_CHAIN_REGNUM) 3777 1.1 mrg sorry ("a nested function is not supported for reduced registers"); 3778 1.1 mrg /* Checking op1, forbid using static chain register ($r16) 3779 1.1 mrg on reduced-set registers configuration. */ 3780 1.1 mrg if (TARGET_REDUCED_REGS 3781 1.1 mrg && REG_P (op1) 3782 1.1 mrg && REGNO (op1) == STATIC_CHAIN_REGNUM) 3783 1.1 mrg sorry ("a nested function is not supported for reduced registers"); 3784 1.1 mrg 3785 1.1 mrg if (REG_P (op0) && REG_P (op1)) 3786 1.1 mrg { 3787 1.1 mrg /* [Ra], Rb */ 3788 1.1 mrg fprintf (stream, "[%s], %s", 3789 1.1 mrg reg_names[REGNO (op0)], reg_names[REGNO (op1)]); 3790 1.1 mrg } 3791 1.1 mrg else if (REG_P (op0) && CONST_INT_P (op1)) 3792 1.1 mrg { 3793 1.1 mrg /* [Ra], imm */ 3794 1.1 mrg fprintf (stream, "[%s], " HOST_WIDE_INT_PRINT_DEC, 3795 1.1 mrg reg_names[REGNO (op0)], INTVAL (op1)); 3796 1.1 mrg } 3797 1.1 mrg else 3798 1.1 mrg { 3799 1.1 mrg /* The control flow is not supposed to be here. */ 3800 1.1 mrg debug_rtx (x); 3801 1.1 mrg gcc_unreachable (); 3802 1.1 mrg } 3803 1.1 mrg 3804 1.1 mrg break; 3805 1.1 mrg 3806 1.1 mrg case POST_INC: 3807 1.1 mrg case POST_DEC: 3808 1.1 mrg op0 = XEXP (x, 0); 3809 1.1 mrg 3810 1.1 mrg /* Checking op0, forbid using static chain register ($r16) 3811 1.1 mrg on reduced-set registers configuration. */ 3812 1.1 mrg if (TARGET_REDUCED_REGS 3813 1.1 mrg && REG_P (op0) 3814 1.1 mrg && REGNO (op0) == STATIC_CHAIN_REGNUM) 3815 1.1 mrg sorry ("a nested function is not supported for reduced registers"); 3816 1.1 mrg 3817 1.1 mrg if (REG_P (op0)) 3818 1.1 mrg { 3819 1.1 mrg /* "[Ra], 1/2/4" or "[Ra], -1/-2/-4" 3820 1.1 mrg The 1/2/4 or -1/-2/-4 have been displayed in nds32.md. 3821 1.1 mrg We only need to deal with register Ra. */ 3822 1.1 mrg fprintf (stream, "[%s]", reg_names[REGNO (op0)]); 3823 1.1 mrg } 3824 1.1 mrg else 3825 1.1 mrg { 3826 1.1 mrg /* The control flow is not supposed to be here. */ 3827 1.1 mrg debug_rtx (x); 3828 1.1 mrg gcc_unreachable (); 3829 1.1 mrg } 3830 1.1 mrg 3831 1.1 mrg break; 3832 1.1 mrg 3833 1.1 mrg default : 3834 1.1 mrg /* Generally, output_addr_const () is able to handle most cases. 3835 1.1 mrg We want to see what CODE could appear, 3836 1.1 mrg so we use gcc_unreachable() to stop it. */ 3837 1.1 mrg debug_rtx (x); 3838 1.1 mrg gcc_unreachable (); 3839 1.1 mrg break; 3840 1.1 mrg } 3841 1.1 mrg } 3842 1.1 mrg 3843 1.1 mrg /* -- Assembler Commands for Exception Regions. */ 3844 1.1 mrg 3845 1.1 mrg static rtx 3846 1.1 mrg nds32_dwarf_register_span (rtx reg) 3847 1.1 mrg { 3848 1.1 mrg rtx dwarf_high, dwarf_low; 3849 1.1 mrg rtx dwarf_single; 3850 1.1 mrg machine_mode mode; 3851 1.1 mrg int regno; 3852 1.1 mrg 3853 1.1 mrg mode = GET_MODE (reg); 3854 1.1 mrg regno = REGNO (reg); 3855 1.1 mrg 3856 1.1 mrg /* We need to adjust dwarf register information for floating-point registers 3857 1.1 mrg rather than using default register number mapping. */ 3858 1.1 mrg if (regno >= NDS32_FIRST_FPR_REGNUM 3859 1.1 mrg && regno <= NDS32_LAST_FPR_REGNUM) 3860 1.1 mrg { 3861 1.1 mrg if (mode == DFmode || mode == SCmode) 3862 1.1 mrg { 3863 1.1 mrg /* By default, GCC maps increasing register numbers to increasing 3864 1.1 mrg memory locations, but paired FPRs in NDS32 target are always 3865 1.1 mrg big-endian, i.e.: 3866 1.1 mrg 3867 1.1 mrg fd0 : fs0 fs1 3868 1.1 mrg (MSB) (LSB) 3869 1.1 mrg 3870 1.1 mrg We must return parallel rtx to represent such layout. */ 3871 1.1 mrg dwarf_high = gen_rtx_REG (word_mode, regno); 3872 1.1 mrg dwarf_low = gen_rtx_REG (word_mode, regno + 1); 3873 1.1 mrg return gen_rtx_PARALLEL (VOIDmode, 3874 1.1 mrg gen_rtvec (2, dwarf_low, dwarf_high)); 3875 1.1 mrg } 3876 1.1 mrg else if (mode == DCmode) 3877 1.1 mrg { 3878 1.1 mrg rtx dwarf_high_re = gen_rtx_REG (word_mode, regno); 3879 1.1 mrg rtx dwarf_low_re = gen_rtx_REG (word_mode, regno + 1); 3880 1.1 mrg rtx dwarf_high_im = gen_rtx_REG (word_mode, regno); 3881 1.1 mrg rtx dwarf_low_im = gen_rtx_REG (word_mode, regno + 1); 3882 1.1 mrg return gen_rtx_PARALLEL (VOIDmode, 3883 1.1 mrg gen_rtvec (4, dwarf_low_re, dwarf_high_re, 3884 1.1 mrg dwarf_high_im, dwarf_low_im)); 3885 1.1 mrg } 3886 1.1 mrg else if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD) 3887 1.1 mrg { 3888 1.1 mrg return NULL_RTX; 3889 1.1 mrg } 3890 1.1 mrg else 3891 1.1 mrg { 3892 1.1 mrg /* We should not be here. */ 3893 1.1 mrg gcc_unreachable (); 3894 1.1 mrg } 3895 1.1 mrg } 3896 1.1 mrg 3897 1.1 mrg return NULL_RTX; 3898 1.1 mrg } 3899 1.1 mrg 3900 1.1 mrg /* Map internal gcc register numbers to DWARF2 register numbers. */ 3901 1.1 mrg 3902 1.1 mrg unsigned int 3903 1.1 mrg nds32_dbx_register_number (unsigned int regno) 3904 1.1 mrg { 3905 1.1 mrg /* The nds32 port in GDB maintains a mapping between dwarf register 3906 1.1 mrg number and displayed register name. For backward compatibility to 3907 1.1 mrg previous toolchain, currently our gdb still has four registers 3908 1.1 mrg (d0.l, d0.h, d1.l, and d1.h) between GPR and FPR while compiler 3909 1.1 mrg does not count those four registers in its register number table. 3910 1.1 mrg So we have to add 4 on its register number and then create new 3911 1.1 mrg dwarf information. Hopefully we can discard such workaround 3912 1.1 mrg in the future. */ 3913 1.1 mrg if (NDS32_IS_FPR_REGNUM (regno)) 3914 1.1 mrg return regno + 4; 3915 1.1 mrg 3916 1.1 mrg return regno; 3917 1.1 mrg } 3918 1.1 mrg 3919 1.1 mrg 3920 1.1 mrg /* Defining target-specific uses of __attribute__. */ 3922 1.1 mrg 3923 1.1 mrg /* Add some checking after merging attributes. */ 3924 1.1 mrg static tree 3925 1.1 mrg nds32_merge_decl_attributes (tree olddecl, tree newdecl) 3926 1.1 mrg { 3927 1.1 mrg tree combined_attrs; 3928 1.1 mrg 3929 1.1 mrg /* Create combined attributes. */ 3930 1.1 mrg combined_attrs = merge_attributes (DECL_ATTRIBUTES (olddecl), 3931 1.1 mrg DECL_ATTRIBUTES (newdecl)); 3932 1.1 mrg 3933 1.1 mrg /* Since newdecl is acutally a duplicate of olddecl, 3934 1.1 mrg we can take olddecl for some operations. */ 3935 1.1 mrg if (TREE_CODE (olddecl) == FUNCTION_DECL) 3936 1.1 mrg { 3937 1.1 mrg /* Check isr-specific attributes conflict. */ 3938 1.1 mrg nds32_check_isr_attrs_conflict (olddecl, combined_attrs); 3939 1.1 mrg } 3940 1.1 mrg 3941 1.1 mrg return combined_attrs; 3942 1.1 mrg } 3943 1.1 mrg 3944 1.1 mrg /* Add some checking when inserting attributes. */ 3945 1.1 mrg static void 3946 1.1 mrg nds32_insert_attributes (tree decl, tree *attributes) 3947 1.1 mrg { 3948 1.1 mrg /* A "indirect_call" function attribute implies "noinline" and "noclone" 3949 1.1 mrg for elf toolchain to support ROM patch mechanism. */ 3950 1.1 mrg if (TREE_CODE (decl) == FUNCTION_DECL 3951 1.1 mrg && lookup_attribute ("indirect_call", *attributes) != NULL) 3952 1.1 mrg { 3953 1.1 mrg tree new_attrs = *attributes; 3954 1.1 mrg 3955 1.1 mrg if (TARGET_LINUX_ABI) 3956 1.1 mrg error ("cannot use %<indirect_call%> attribute under linux toolchain"); 3957 1.1 mrg 3958 1.1 mrg if (lookup_attribute ("noinline", new_attrs) == NULL) 3959 1.1 mrg new_attrs = tree_cons (get_identifier ("noinline"), NULL, new_attrs); 3960 1.1 mrg if (lookup_attribute ("noclone", new_attrs) == NULL) 3961 1.1 mrg new_attrs = tree_cons (get_identifier ("noclone"), NULL, new_attrs); 3962 1.1 mrg 3963 1.1 mrg if (!TREE_PUBLIC (decl)) 3964 1.1 mrg error ("%<indirect_call%> attribute cannot apply for static function"); 3965 1.1 mrg 3966 1.1 mrg *attributes = new_attrs; 3967 1.1 mrg } 3968 1.1 mrg 3969 1.1 mrg /* For function declaration, we need to check isr-specific attributes: 3970 1.1 mrg 1. Call nds32_check_isr_attrs_conflict() to check any conflict. 3971 1.1 mrg 2. Check valid integer value for interrupt/exception. 3972 1.1 mrg 3. Check valid integer value for reset. 3973 1.1 mrg 4. Check valid function for nmi/warm. */ 3974 1.1 mrg if (TREE_CODE (decl) == FUNCTION_DECL) 3975 1.1 mrg { 3976 1.1 mrg tree func_attrs; 3977 1.1 mrg tree intr, excp, reset; 3978 1.1 mrg 3979 1.1 mrg /* Pick up function attributes. */ 3980 1.1 mrg func_attrs = *attributes; 3981 1.1 mrg 3982 1.1 mrg /* 1. Call nds32_check_isr_attrs_conflict() to check any conflict. */ 3983 1.1 mrg nds32_check_isr_attrs_conflict (decl, func_attrs); 3984 1.1 mrg 3985 1.1 mrg /* Now we are starting to check valid id value 3986 1.1 mrg for interrupt/exception/reset. 3987 1.1 mrg Note that we ONLY check its validity here. 3988 1.1 mrg To construct isr vector information, it is still performed 3989 1.1 mrg by nds32_construct_isr_vectors_information(). */ 3990 1.1 mrg intr = lookup_attribute ("interrupt", func_attrs); 3991 1.1 mrg excp = lookup_attribute ("exception", func_attrs); 3992 1.1 mrg reset = lookup_attribute ("reset", func_attrs); 3993 1.1 mrg 3994 1.1 mrg /* The following code may use attribute arguments. If there is no 3995 1.1 mrg argument from source code, it will cause segmentation fault. 3996 1.1 mrg Therefore, return dircetly and report error message later. */ 3997 1.1 mrg if ((intr && TREE_VALUE (intr) == NULL) 3998 1.1 mrg || (excp && TREE_VALUE (excp) == NULL) 3999 1.1 mrg || (reset && TREE_VALUE (reset) == NULL)) 4000 1.1 mrg return; 4001 1.1 mrg 4002 1.1 mrg /* ------------------------------------------------------------- */ 4003 1.1 mrg /* FIXME: 4004 1.1 mrg FOR BACKWARD COMPATIBILITY, we need to support following patterns: 4005 1.1 mrg 4006 1.1 mrg __attribute__((interrupt("XXX;YYY;id=ZZZ"))) 4007 1.1 mrg __attribute__((exception("XXX;YYY;id=ZZZ"))) 4008 1.1 mrg __attribute__((reset("vectors=XXX;nmi_func=YYY;warm_func=ZZZ"))) 4009 1.1 mrg 4010 1.1 mrg If interrupt/exception/reset appears and its argument is a 4011 1.1 mrg STRING_CST, we will use other functions to parse string in the 4012 1.1 mrg nds32_construct_isr_vectors_information() and then set necessary 4013 1.1 mrg isr information in the nds32_isr_vectors[] array. Here we can 4014 1.1 mrg just return immediately to avoid new-syntax checking. */ 4015 1.1 mrg if (intr != NULL_TREE 4016 1.1 mrg && TREE_CODE (TREE_VALUE (TREE_VALUE (intr))) == STRING_CST) 4017 1.1 mrg return; 4018 1.1 mrg if (excp != NULL_TREE 4019 1.1 mrg && TREE_CODE (TREE_VALUE (TREE_VALUE (excp))) == STRING_CST) 4020 1.1 mrg return; 4021 1.1 mrg if (reset != NULL_TREE 4022 1.1 mrg && TREE_CODE (TREE_VALUE (TREE_VALUE (reset))) == STRING_CST) 4023 1.1 mrg return; 4024 1.1 mrg /* ------------------------------------------------------------- */ 4025 1.1 mrg 4026 1.1 mrg if (intr || excp) 4027 1.1 mrg { 4028 1.1 mrg /* Deal with interrupt/exception. */ 4029 1.1 mrg tree id_list; 4030 1.1 mrg unsigned int lower_bound, upper_bound; 4031 1.1 mrg 4032 1.1 mrg /* The way to handle interrupt or exception is the same, 4033 1.1 mrg we just need to take care of actual vector number. 4034 1.1 mrg For interrupt(0..63), the actual vector number is (9..72). 4035 1.1 mrg For exception(1..8), the actual vector number is (1..8). */ 4036 1.1 mrg lower_bound = (intr) ? (0) : (1); 4037 1.1 mrg upper_bound = (intr) ? (63) : (8); 4038 1.1 mrg 4039 1.1 mrg /* Prepare id list so that we can traverse id value. */ 4040 1.1 mrg id_list = (intr) ? (TREE_VALUE (intr)) : (TREE_VALUE (excp)); 4041 1.1 mrg 4042 1.1 mrg /* 2. Check valid integer value for interrupt/exception. */ 4043 1.1 mrg while (id_list) 4044 1.1 mrg { 4045 1.1 mrg tree id; 4046 1.1 mrg 4047 1.1 mrg /* Pick up each vector id value. */ 4048 1.1 mrg id = TREE_VALUE (id_list); 4049 1.1 mrg /* Issue error if it is not a valid integer value. */ 4050 1.1 mrg if (TREE_CODE (id) != INTEGER_CST 4051 1.1 mrg || wi::ltu_p (wi::to_wide (id), lower_bound) 4052 1.1 mrg || wi::gtu_p (wi::to_wide (id), upper_bound)) 4053 1.1 mrg error ("invalid id value for interrupt/exception attribute"); 4054 1.1 mrg 4055 1.1 mrg /* Advance to next id. */ 4056 1.1 mrg id_list = TREE_CHAIN (id_list); 4057 1.1 mrg } 4058 1.1 mrg } 4059 1.1 mrg else if (reset) 4060 1.1 mrg { 4061 1.1 mrg /* Deal with reset. */ 4062 1.1 mrg tree id_list; 4063 1.1 mrg tree id; 4064 1.1 mrg tree nmi, warm; 4065 1.1 mrg unsigned int lower_bound; 4066 1.1 mrg unsigned int upper_bound; 4067 1.1 mrg 4068 1.1 mrg /* Prepare id_list and identify id value so that 4069 1.1 mrg we can check if total number of vectors is valid. */ 4070 1.1 mrg id_list = TREE_VALUE (reset); 4071 1.1 mrg id = TREE_VALUE (id_list); 4072 1.1 mrg 4073 1.1 mrg /* The maximum numbers for user's interrupt is 64. */ 4074 1.1 mrg lower_bound = 0; 4075 1.1 mrg upper_bound = 64; 4076 1.1 mrg 4077 1.1 mrg /* 3. Check valid integer value for reset. */ 4078 1.1 mrg if (TREE_CODE (id) != INTEGER_CST 4079 1.1 mrg || wi::ltu_p (wi::to_wide (id), lower_bound) 4080 1.1 mrg || wi::gtu_p (wi::to_wide (id), upper_bound)) 4081 1.1 mrg error ("invalid id value for reset attribute"); 4082 1.1 mrg 4083 1.1 mrg /* 4. Check valid function for nmi/warm. */ 4084 1.1 mrg nmi = lookup_attribute ("nmi", func_attrs); 4085 1.1 mrg warm = lookup_attribute ("warm", func_attrs); 4086 1.1 mrg 4087 1.1 mrg if (nmi != NULL_TREE) 4088 1.1 mrg { 4089 1.1 mrg tree nmi_func_list; 4090 1.1 mrg tree nmi_func; 4091 1.1 mrg 4092 1.1 mrg nmi_func_list = TREE_VALUE (nmi); 4093 1.1 mrg nmi_func = TREE_VALUE (nmi_func_list); 4094 1.1 mrg 4095 1.1 mrg /* Issue error if it is not a valid nmi function. */ 4096 1.1 mrg if (TREE_CODE (nmi_func) != IDENTIFIER_NODE) 4097 1.1 mrg error ("invalid nmi function for reset attribute"); 4098 1.1 mrg } 4099 1.1 mrg 4100 1.1 mrg if (warm != NULL_TREE) 4101 1.1 mrg { 4102 1.1 mrg tree warm_func_list; 4103 1.1 mrg tree warm_func; 4104 1.1 mrg 4105 1.1 mrg warm_func_list = TREE_VALUE (warm); 4106 1.1 mrg warm_func = TREE_VALUE (warm_func_list); 4107 1.1 mrg 4108 1.1 mrg /* Issue error if it is not a valid warm function. */ 4109 1.1 mrg if (TREE_CODE (warm_func) != IDENTIFIER_NODE) 4110 1.1 mrg error ("invalid warm function for reset attribute"); 4111 1.1 mrg } 4112 1.1 mrg } 4113 1.1 mrg else 4114 1.1 mrg { 4115 1.1 mrg /* No interrupt, exception, or reset attribute is set. */ 4116 1.1 mrg return; 4117 1.1 mrg } 4118 1.1 mrg } 4119 1.1 mrg } 4120 1.1 mrg 4121 1.1 mrg static bool 4122 1.1 mrg nds32_option_pragma_parse (tree args ATTRIBUTE_UNUSED, 4123 1.1 mrg tree pop_target ATTRIBUTE_UNUSED) 4124 1.1 mrg { 4125 1.1 mrg /* Currently, we do not parse any pragma target by ourself, 4126 1.1 mrg so just simply return false. */ 4127 1.1 mrg return false; 4128 1.1 mrg } 4129 1.1 mrg 4130 1.1 mrg static void 4131 1.1 mrg nds32_option_override (void) 4132 1.1 mrg { 4133 1.1 mrg /* After all the command options have been parsed, 4134 1.1 mrg we shall deal with some flags for changing compiler settings. */ 4135 1.1 mrg 4136 1.1 mrg /* At first, we check if we have to strictly 4137 1.1 mrg set some flags based on ISA family. */ 4138 1.1 mrg if (TARGET_ISA_V2) 4139 1.1 mrg { 4140 1.1 mrg /* Under V2 ISA, we need to strictly disable TARGET_V3PUSH. */ 4141 1.1 mrg target_flags &= ~MASK_V3PUSH; 4142 1.1 mrg } 4143 1.1 mrg if (TARGET_ISA_V3) 4144 1.1 mrg { 4145 1.1 mrg /* If this is ARCH_V3J, we need to enable TARGET_REDUCED_REGS. */ 4146 1.1 mrg if (nds32_arch_option == ARCH_V3J) 4147 1.1 mrg target_flags |= MASK_REDUCED_REGS; 4148 1.1 mrg } 4149 1.1 mrg if (TARGET_ISA_V3M) 4150 1.1 mrg { 4151 1.1 mrg /* Under V3M ISA, we need to strictly enable TARGET_REDUCED_REGS. */ 4152 1.1 mrg target_flags |= MASK_REDUCED_REGS; 4153 1.1 mrg /* Under V3M ISA, we need to strictly disable TARGET_EXT_PERF. */ 4154 1.1 mrg target_flags &= ~MASK_EXT_PERF; 4155 1.1 mrg /* Under V3M ISA, we need to strictly disable TARGET_EXT_PERF2. */ 4156 1.1 mrg target_flags &= ~MASK_EXT_PERF2; 4157 1.1 mrg /* Under V3M ISA, we need to strictly disable TARGET_EXT_STRING. */ 4158 1.1 mrg target_flags &= ~MASK_EXT_STRING; 4159 1.1 mrg 4160 1.1 mrg if (flag_pic) 4161 1.1 mrg error ("not support %<-fpic%> option for v3m toolchain"); 4162 1.1 mrg } 4163 1.1 mrg 4164 1.1 mrg /* See if we are using reduced-set registers: 4165 1.1 mrg $r0~$r5, $r6~$r10, $r15, $r28, $r29, $r30, $r31 4166 1.1 mrg If so, we must forbid using $r11~$r14, $r16~$r27. */ 4167 1.1 mrg if (TARGET_REDUCED_REGS) 4168 1.1 mrg { 4169 1.1 mrg int r; 4170 1.1 mrg 4171 1.1 mrg /* Prevent register allocator from 4172 1.1 mrg choosing it as doing register allocation. */ 4173 1.1 mrg for (r = 11; r <= 14; r++) 4174 1.1 mrg fixed_regs[r] = call_used_regs[r] = 1; 4175 1.1 mrg for (r = 16; r <= 27; r++) 4176 1.1 mrg fixed_regs[r] = call_used_regs[r] = 1; 4177 1.1 mrg } 4178 1.1 mrg 4179 1.1 mrg /* See if user explicitly would like to use fp-as-gp optimization. 4180 1.1 mrg If so, we must prevent $fp from being allocated 4181 1.1 mrg during register allocation. */ 4182 1.1 mrg if (TARGET_FORCE_FP_AS_GP) 4183 1.1 mrg fixed_regs[FP_REGNUM] = call_used_regs[FP_REGNUM] = 1; 4184 1.1 mrg 4185 1.1 mrg if (!TARGET_16_BIT) 4186 1.1 mrg { 4187 1.1 mrg /* Under no 16 bit ISA, we need to strictly disable TARGET_V3PUSH. */ 4188 1.1 mrg target_flags &= ~MASK_V3PUSH; 4189 1.1 mrg } 4190 1.1 mrg 4191 1.1 mrg if (TARGET_HARD_FLOAT && !(TARGET_FPU_SINGLE || TARGET_FPU_DOUBLE)) 4192 1.1 mrg { 4193 1.1 mrg if (nds32_arch_option == ARCH_V3S || nds32_arch_option == ARCH_V3F) 4194 1.1 mrg error ("Disable FPU ISA, " 4195 1.1 mrg "the ABI option must be enable %<-mfloat-abi=soft%>"); 4196 1.1 mrg else 4197 1.1 mrg error ("%<-mabi=2fp+%> option only support when FPU available, " 4198 1.1 mrg "must be enable %<-mext-fpu-sp%> or %<-mext-fpu-dp%>"); 4199 1.1 mrg } 4200 1.1 mrg 4201 1.1 mrg nds32_init_rtx_costs (); 4202 1.1 mrg 4203 1.1 mrg nds32_register_passes (); 4204 1.1 mrg } 4205 1.1 mrg 4206 1.1 mrg 4207 1.1 mrg /* Miscellaneous Parameters. */ 4209 1.1 mrg 4210 1.1 mrg static rtx_insn * 4211 1.1 mrg nds32_md_asm_adjust (vec<rtx> &outputs ATTRIBUTE_UNUSED, 4212 1.1 mrg vec<rtx> &inputs ATTRIBUTE_UNUSED, 4213 1.1 mrg vec<machine_mode> &input_modes ATTRIBUTE_UNUSED, 4214 1.1 mrg vec<const char *> &constraints ATTRIBUTE_UNUSED, 4215 1.1 mrg vec<rtx> &clobbers, HARD_REG_SET &clobbered_regs, 4216 1.1 mrg location_t /*loc*/) 4217 1.1 mrg { 4218 1.1 mrg if (!flag_inline_asm_r15) 4219 1.1 mrg { 4220 1.1 mrg clobbers.safe_push (gen_rtx_REG (SImode, TA_REGNUM)); 4221 1.1 mrg SET_HARD_REG_BIT (clobbered_regs, TA_REGNUM); 4222 1.1 mrg } 4223 1.1 mrg return NULL; 4224 1.1 mrg } 4225 1.1 mrg 4226 1.1 mrg static void 4227 1.1 mrg nds32_init_builtins (void) 4228 1.1 mrg { 4229 1.1 mrg nds32_init_builtins_impl (); 4230 1.1 mrg } 4231 1.1 mrg 4232 1.1 mrg static tree 4233 1.1 mrg nds32_builtin_decl (unsigned code, bool initialize_p) 4234 1.1 mrg { 4235 1.1 mrg /* Implement in nds32-intrinsic.cc. */ 4236 1.1 mrg return nds32_builtin_decl_impl (code, initialize_p); 4237 1.1 mrg } 4238 1.1 mrg 4239 1.1 mrg static rtx 4240 1.1 mrg nds32_expand_builtin (tree exp, 4241 1.1 mrg rtx target, 4242 1.1 mrg rtx subtarget, 4243 1.1 mrg machine_mode mode, 4244 1.1 mrg int ignore) 4245 1.1 mrg { 4246 1.1 mrg return nds32_expand_builtin_impl (exp, target, subtarget, mode, ignore); 4247 1.1 mrg } 4248 1.1 mrg 4249 1.1 mrg /* Implement TARGET_INIT_LIBFUNCS. */ 4250 1.1 mrg static void 4251 1.1 mrg nds32_init_libfuncs (void) 4252 1.1 mrg { 4253 1.1 mrg if (TARGET_LINUX_ABI) 4254 1.1 mrg init_sync_libfuncs (UNITS_PER_WORD); 4255 1.1 mrg } 4256 1.1 mrg 4257 1.1 mrg /* ------------------------------------------------------------------------ */ 4258 1.1 mrg 4259 1.1 mrg /* PART 4: Implemet extern function definitions, 4260 1.1 mrg the prototype is in nds32-protos.h. */ 4261 1.1 mrg 4262 1.1 mrg /* Run-time Target Specification. */ 4264 1.1 mrg 4265 1.1 mrg void 4266 1.1 mrg nds32_cpu_cpp_builtins(struct cpp_reader *pfile) 4267 1.1 mrg { 4268 1.1 mrg #define builtin_define(TXT) cpp_define (pfile, TXT) 4269 1.1 mrg #define builtin_assert(TXT) cpp_assert (pfile, TXT) 4270 1.1 mrg builtin_define ("__nds32__"); 4271 1.1 mrg builtin_define ("__NDS32__"); 4272 1.1 mrg 4273 1.1 mrg /* We need to provide builtin macro to describe the size of 4274 1.1 mrg each vector for interrupt handler under elf toolchain. */ 4275 1.1 mrg if (!TARGET_LINUX_ABI) 4276 1.1 mrg { 4277 1.1 mrg if (TARGET_ISR_VECTOR_SIZE_4_BYTE) 4278 1.1 mrg builtin_define ("__NDS32_ISR_VECTOR_SIZE_4__"); 4279 1.1 mrg else 4280 1.1 mrg builtin_define ("__NDS32_ISR_VECTOR_SIZE_16__"); 4281 1.1 mrg } 4282 1.1 mrg 4283 1.1 mrg if (TARGET_HARD_FLOAT) 4284 1.1 mrg builtin_define ("__NDS32_ABI_2FP_PLUS__"); 4285 1.1 mrg else 4286 1.1 mrg builtin_define ("__NDS32_ABI_2__"); 4287 1.1 mrg 4288 1.1 mrg if (TARGET_ISA_V2) 4289 1.1 mrg builtin_define ("__NDS32_ISA_V2__"); 4290 1.1 mrg if (TARGET_ISA_V3) 4291 1.1 mrg builtin_define ("__NDS32_ISA_V3__"); 4292 1.1 mrg if (TARGET_ISA_V3M) 4293 1.1 mrg builtin_define ("__NDS32_ISA_V3M__"); 4294 1.1 mrg 4295 1.1 mrg if (TARGET_FPU_SINGLE) 4296 1.1 mrg builtin_define ("__NDS32_EXT_FPU_SP__"); 4297 1.1 mrg if (TARGET_FPU_DOUBLE) 4298 1.1 mrg builtin_define ("__NDS32_EXT_FPU_DP__"); 4299 1.1 mrg 4300 1.1 mrg if (TARGET_EXT_FPU_FMA) 4301 1.1 mrg builtin_define ("__NDS32_EXT_FPU_FMA__"); 4302 1.1 mrg if (NDS32_EXT_FPU_DOT_E) 4303 1.1 mrg builtin_define ("__NDS32_EXT_FPU_DOT_E__"); 4304 1.1 mrg if (TARGET_FPU_SINGLE || TARGET_FPU_DOUBLE) 4305 1.1 mrg { 4306 1.1 mrg switch (nds32_fp_regnum) 4307 1.1 mrg { 4308 1.1 mrg case 0: 4309 1.1 mrg case 4: 4310 1.1 mrg builtin_define ("__NDS32_EXT_FPU_CONFIG_0__"); 4311 1.1 mrg break; 4312 1.1 mrg case 1: 4313 1.1 mrg case 5: 4314 1.1 mrg builtin_define ("__NDS32_EXT_FPU_CONFIG_1__"); 4315 1.1 mrg break; 4316 1.1 mrg case 2: 4317 1.1 mrg case 6: 4318 1.1 mrg builtin_define ("__NDS32_EXT_FPU_CONFIG_2__"); 4319 1.1 mrg break; 4320 1.1 mrg case 3: 4321 1.1 mrg case 7: 4322 1.1 mrg builtin_define ("__NDS32_EXT_FPU_CONFIG_3__"); 4323 1.1 mrg break; 4324 1.1 mrg default: 4325 1.1 mrg abort (); 4326 1.1 mrg } 4327 1.1 mrg } 4328 1.1 mrg 4329 1.1 mrg if (TARGET_BIG_ENDIAN) 4330 1.1 mrg builtin_define ("__NDS32_EB__"); 4331 1.1 mrg else 4332 1.1 mrg builtin_define ("__NDS32_EL__"); 4333 1.1 mrg 4334 1.1 mrg if (TARGET_REDUCED_REGS) 4335 1.1 mrg builtin_define ("__NDS32_REDUCED_REGS__"); 4336 1.1 mrg if (TARGET_CMOV) 4337 1.1 mrg builtin_define ("__NDS32_CMOV__"); 4338 1.1 mrg if (TARGET_EXT_PERF) 4339 1.1 mrg builtin_define ("__NDS32_EXT_PERF__"); 4340 1.1 mrg if (TARGET_EXT_PERF2) 4341 1.1 mrg builtin_define ("__NDS32_EXT_PERF2__"); 4342 1.1 mrg if (TARGET_EXT_STRING) 4343 1.1 mrg builtin_define ("__NDS32_EXT_STRING__"); 4344 1.1 mrg if (TARGET_16_BIT) 4345 1.1 mrg builtin_define ("__NDS32_16_BIT__"); 4346 1.1 mrg if (TARGET_GP_DIRECT) 4347 1.1 mrg builtin_define ("__NDS32_GP_DIRECT__"); 4348 1.1 mrg if (TARGET_VH) 4349 1.1 mrg builtin_define ("__NDS32_VH__"); 4350 1.1 mrg if (NDS32_EXT_DSP_P ()) 4351 1.1 mrg builtin_define ("__NDS32_EXT_DSP__"); 4352 1.1 mrg 4353 1.1 mrg if (TARGET_BIG_ENDIAN) 4354 1.1 mrg builtin_define ("__big_endian__"); 4355 1.1 mrg 4356 1.1 mrg builtin_assert ("cpu=nds32"); 4357 1.1 mrg builtin_assert ("machine=nds32"); 4358 1.1 mrg 4359 1.1 mrg if (TARGET_HARD_FLOAT) 4360 1.1 mrg builtin_define ("__NDS32_ABI_2FP_PLUS"); 4361 1.1 mrg else 4362 1.1 mrg builtin_define ("__NDS32_ABI_2"); 4363 1.1 mrg 4364 1.1 mrg #undef builtin_define 4365 1.1 mrg #undef builtin_assert 4366 1.1 mrg } 4367 1.1 mrg 4368 1.1 mrg 4369 1.1 mrg /* Defining Data Structures for Per-function Information. */ 4371 1.1 mrg 4372 1.1 mrg void 4373 1.1 mrg nds32_init_expanders (void) 4374 1.1 mrg { 4375 1.1 mrg /* Arrange to initialize and mark the machine per-function status. */ 4376 1.1 mrg init_machine_status = nds32_init_machine_status; 4377 1.1 mrg } 4378 1.1 mrg 4379 1.1 mrg 4380 1.1 mrg /* Register Usage. */ 4382 1.1 mrg 4383 1.1 mrg /* -- Order of Allocation of Registers. */ 4384 1.1 mrg 4385 1.1 mrg void 4386 1.1 mrg nds32_adjust_reg_alloc_order (void) 4387 1.1 mrg { 4388 1.1 mrg const int nds32_reg_alloc_order[] = REG_ALLOC_ORDER; 4389 1.1 mrg 4390 1.1 mrg /* Copy the default register allocation order, which is designed 4391 1.1 mrg to optimize for code size. */ 4392 1.1 mrg memcpy(reg_alloc_order, nds32_reg_alloc_order, sizeof (reg_alloc_order)); 4393 1.1 mrg 4394 1.1 mrg /* Adjust few register allocation order when optimizing for speed. */ 4395 1.1 mrg if (!optimize_size) 4396 1.1 mrg { 4397 1.1 mrg memcpy (reg_alloc_order, nds32_reg_alloc_order_for_speed, 4398 1.1 mrg sizeof (nds32_reg_alloc_order_for_speed)); 4399 1.1 mrg } 4400 1.1 mrg } 4401 1.1 mrg 4402 1.1 mrg /* -- How Values Fit in Registers. */ 4403 1.1 mrg 4404 1.1 mrg static unsigned 4405 1.1 mrg nds32_hard_regno_nregs (unsigned regno ATTRIBUTE_UNUSED, 4406 1.1 mrg machine_mode mode) 4407 1.1 mrg { 4408 1.1 mrg return ((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD); 4409 1.1 mrg } 4410 1.1 mrg 4411 1.1 mrg /* Implement TARGET_HARD_REGNO_MODE_OK. */ 4412 1.1 mrg 4413 1.1 mrg static bool 4414 1.1 mrg nds32_hard_regno_mode_ok (unsigned int regno, machine_mode mode) 4415 1.1 mrg { 4416 1.1 mrg if (regno >= FIRST_PSEUDO_REGISTER) 4417 1.1 mrg return true; 4418 1.1 mrg 4419 1.1 mrg if ((TARGET_FPU_SINGLE || TARGET_FPU_DOUBLE) && NDS32_IS_FPR_REGNUM (regno)) 4420 1.1 mrg { 4421 1.1 mrg if (NDS32_IS_EXT_FPR_REGNUM(regno)) 4422 1.1 mrg return (NDS32_FPR_REGNO_OK_FOR_DOUBLE(regno) && (mode == DFmode)); 4423 1.1 mrg else if (mode == SFmode || mode == SImode) 4424 1.1 mrg return NDS32_FPR_REGNO_OK_FOR_SINGLE (regno); 4425 1.1 mrg else if (mode == DFmode) 4426 1.1 mrg return NDS32_FPR_REGNO_OK_FOR_DOUBLE (regno); 4427 1.1 mrg 4428 1.1 mrg return false; 4429 1.1 mrg } 4430 1.1 mrg 4431 1.1 mrg /* Restrict double-word quantities to even register pairs. */ 4432 1.1 mrg if (regno <= NDS32_LAST_GPR_REGNUM) 4433 1.1 mrg return (targetm.hard_regno_nregs (regno, mode) == 1 4434 1.1 mrg || !((regno) & 1)); 4435 1.1 mrg 4436 1.1 mrg return false; 4437 1.1 mrg } 4438 1.1 mrg 4439 1.1 mrg /* Implement TARGET_MODES_TIEABLE_P. We can use general registers to 4440 1.1 mrg tie QI/HI/SI modes together. */ 4441 1.1 mrg 4442 1.1 mrg static bool 4443 1.1 mrg nds32_modes_tieable_p (machine_mode mode1, machine_mode mode2) 4444 1.1 mrg { 4445 1.1 mrg if ((GET_MODE_CLASS (mode1) == MODE_INT 4446 1.1 mrg && GET_MODE_CLASS (mode2) == MODE_INT) 4447 1.1 mrg && GET_MODE_SIZE (mode1) <= UNITS_PER_WORD 4448 1.1 mrg && GET_MODE_SIZE (mode2) <= UNITS_PER_WORD) 4449 1.1 mrg return true; 4450 1.1 mrg 4451 1.1 mrg if (GET_MODE_SIZE (mode1) == GET_MODE_SIZE (mode2)) 4452 1.1 mrg { 4453 1.1 mrg if ((TARGET_FPU_SINGLE && !TARGET_FPU_DOUBLE) 4454 1.1 mrg && (mode1 == DFmode || mode2 == DFmode)) 4455 1.1 mrg return false; 4456 1.1 mrg else 4457 1.1 mrg return true; 4458 1.1 mrg } 4459 1.1 mrg 4460 1.1 mrg return false; 4461 1.1 mrg } 4462 1.1 mrg 4463 1.1 mrg /* Register Classes. */ 4465 1.1 mrg 4466 1.1 mrg enum reg_class 4467 1.1 mrg nds32_regno_reg_class (int regno) 4468 1.1 mrg { 4469 1.1 mrg /* Refer to nds32.h for more register class details. */ 4470 1.1 mrg 4471 1.1 mrg if (regno >= 0 && regno <= 7) 4472 1.1 mrg return LOW_REGS; 4473 1.1 mrg else if (regno >= 8 && regno <= 11) 4474 1.1 mrg return MIDDLE_REGS; 4475 1.1 mrg else if (regno >= 12 && regno <= 14) 4476 1.1 mrg return HIGH_REGS; 4477 1.1 mrg else if (regno == 15) 4478 1.1 mrg return R15_TA_REG; 4479 1.1 mrg else if (regno >= 16 && regno <= 19) 4480 1.1 mrg return MIDDLE_REGS; 4481 1.1 mrg else if (regno >= 20 && regno <= 31) 4482 1.1 mrg return HIGH_REGS; 4483 1.1 mrg else if (regno == 32 || regno == 33) 4484 1.1 mrg { 4485 1.1 mrg /* $SFP and $AP is FRAME_REGS in fact, However prevent IRA don't 4486 1.1 mrg know how to allocate register for $SFP and $AP, just tell IRA they 4487 1.1 mrg are GENERAL_REGS, and ARM do this hack too. */ 4488 1.1 mrg return GENERAL_REGS; 4489 1.1 mrg } 4490 1.1 mrg else if (regno >= 34 && regno <= 97) 4491 1.1 mrg return FP_REGS; 4492 1.1 mrg else 4493 1.1 mrg return NO_REGS; 4494 1.1 mrg } 4495 1.1 mrg 4496 1.1 mrg 4497 1.1 mrg /* Stack Layout and Calling Conventions. */ 4499 1.1 mrg 4500 1.1 mrg /* -- Basic Stack Layout. */ 4501 1.1 mrg 4502 1.1 mrg rtx 4503 1.1 mrg nds32_dynamic_chain_address (rtx frameaddr) 4504 1.1 mrg { 4505 1.1 mrg if (TARGET_V3PUSH) 4506 1.1 mrg { 4507 1.1 mrg /* If -mv3push is specified, we push $fp, $gp, and $lp into stack. 4508 1.1 mrg We can access dynamic chain address from stack by [$fp - 12]. */ 4509 1.1 mrg return plus_constant (Pmode, frameaddr, -12); 4510 1.1 mrg } 4511 1.1 mrg else 4512 1.1 mrg { 4513 1.1 mrg /* For general case we push $fp and $lp into stack at prologue. 4514 1.1 mrg We can access dynamic chain address from stack by [$fp - 8]. */ 4515 1.1 mrg return plus_constant (Pmode, frameaddr, -8); 4516 1.1 mrg } 4517 1.1 mrg } 4518 1.1 mrg 4519 1.1 mrg rtx 4520 1.1 mrg nds32_return_addr_rtx (int count, 4521 1.1 mrg rtx frameaddr) 4522 1.1 mrg { 4523 1.1 mrg int offset; 4524 1.1 mrg rtx addr; 4525 1.1 mrg 4526 1.1 mrg if (count != 0) 4527 1.1 mrg { 4528 1.1 mrg /* In nds32 ABI design, we can expect that $lp is always available 4529 1.1 mrg from stack by [$fp - 4] location. */ 4530 1.1 mrg offset = -4; 4531 1.1 mrg addr = plus_constant (Pmode, frameaddr, offset); 4532 1.1 mrg addr = memory_address (Pmode, addr); 4533 1.1 mrg 4534 1.1 mrg return gen_rtx_MEM (Pmode, addr); 4535 1.1 mrg } 4536 1.1 mrg 4537 1.1 mrg /* If count == 0, it means we are at current frame, 4538 1.1 mrg the return address is $r30 ($lp). */ 4539 1.1 mrg return get_hard_reg_initial_val (Pmode, LP_REGNUM); 4540 1.1 mrg } 4541 1.1 mrg 4542 1.1 mrg /* -- Eliminating Frame Pointer and Arg Pointer. */ 4543 1.1 mrg 4544 1.1 mrg HOST_WIDE_INT 4545 1.1 mrg nds32_initial_elimination_offset (unsigned int from_reg, unsigned int to_reg) 4546 1.1 mrg { 4547 1.1 mrg HOST_WIDE_INT offset; 4548 1.1 mrg 4549 1.1 mrg /* Compute and setup stack frame size. 4550 1.1 mrg The result will be in cfun->machine. */ 4551 1.1 mrg nds32_compute_stack_frame (); 4552 1.1 mrg 4553 1.1 mrg /* Remember to consider 4554 1.1 mrg cfun->machine->callee_saved_area_gpr_padding_bytes and 4555 1.1 mrg cfun->machine->eh_return_data_regs_size 4556 1.1 mrg when calculating offset. */ 4557 1.1 mrg if (from_reg == ARG_POINTER_REGNUM && to_reg == STACK_POINTER_REGNUM) 4558 1.1 mrg { 4559 1.1 mrg offset = (cfun->machine->fp_size 4560 1.1 mrg + cfun->machine->gp_size 4561 1.1 mrg + cfun->machine->lp_size 4562 1.1 mrg + cfun->machine->callee_saved_gpr_regs_size 4563 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes 4564 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size 4565 1.1 mrg + cfun->machine->eh_return_data_regs_size 4566 1.1 mrg + cfun->machine->local_size 4567 1.1 mrg + cfun->machine->out_args_size); 4568 1.1 mrg } 4569 1.1 mrg else if (from_reg == ARG_POINTER_REGNUM 4570 1.1 mrg && to_reg == HARD_FRAME_POINTER_REGNUM) 4571 1.1 mrg { 4572 1.1 mrg offset = 0; 4573 1.1 mrg } 4574 1.1 mrg else if (from_reg == FRAME_POINTER_REGNUM 4575 1.1 mrg && to_reg == STACK_POINTER_REGNUM) 4576 1.1 mrg { 4577 1.1 mrg offset = (cfun->machine->local_size + cfun->machine->out_args_size); 4578 1.1 mrg } 4579 1.1 mrg else if (from_reg == FRAME_POINTER_REGNUM 4580 1.1 mrg && to_reg == HARD_FRAME_POINTER_REGNUM) 4581 1.1 mrg { 4582 1.1 mrg offset = (-1) * (cfun->machine->fp_size 4583 1.1 mrg + cfun->machine->gp_size 4584 1.1 mrg + cfun->machine->lp_size 4585 1.1 mrg + cfun->machine->callee_saved_gpr_regs_size 4586 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes 4587 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size 4588 1.1 mrg + cfun->machine->eh_return_data_regs_size); 4589 1.1 mrg } 4590 1.1 mrg else 4591 1.1 mrg { 4592 1.1 mrg gcc_unreachable (); 4593 1.1 mrg } 4594 1.1 mrg 4595 1.1 mrg return offset; 4596 1.1 mrg } 4597 1.1 mrg 4598 1.1 mrg /* -- Passing Arguments in Registers. */ 4599 1.1 mrg 4600 1.1 mrg void 4601 1.1 mrg nds32_init_cumulative_args (CUMULATIVE_ARGS *cum, 4602 1.1 mrg tree fntype ATTRIBUTE_UNUSED, 4603 1.1 mrg rtx libname ATTRIBUTE_UNUSED, 4604 1.1 mrg tree fndecl ATTRIBUTE_UNUSED, 4605 1.1 mrg int n_named_args ATTRIBUTE_UNUSED) 4606 1.1 mrg { 4607 1.1 mrg /* Initial available registers. The values are offset against 4608 1.1 mrg NDS32_GPR_ARG_FIRST_REGNUM and NDS32_FPR_ARG_FIRST_REGNUM 4609 1.1 mrg for passing arguments. */ 4610 1.1 mrg cum->gpr_offset = 0; 4611 1.1 mrg cum->fpr_offset = 0; 4612 1.1 mrg } 4613 1.1 mrg 4614 1.1 mrg /* -- Function Entry and Exit. */ 4615 1.1 mrg 4616 1.1 mrg /* Function for normal multiple push prologue. */ 4617 1.1 mrg void 4618 1.1 mrg nds32_expand_prologue (void) 4619 1.1 mrg { 4620 1.1 mrg int fp_adjust; 4621 1.1 mrg int sp_adjust; 4622 1.1 mrg unsigned Rb, Re; 4623 1.1 mrg 4624 1.1 mrg /* Compute and setup stack frame size. 4625 1.1 mrg The result will be in cfun->machine. */ 4626 1.1 mrg nds32_compute_stack_frame (); 4627 1.1 mrg 4628 1.1 mrg /* Check frame_pointer_needed again to prevent fp is need after reload. */ 4629 1.1 mrg if (frame_pointer_needed) 4630 1.1 mrg cfun->machine->fp_as_gp_p = false; 4631 1.1 mrg 4632 1.1 mrg /* If this is a variadic function, first we need to push argument 4633 1.1 mrg registers that hold the unnamed argument value. */ 4634 1.1 mrg if (cfun->machine->va_args_size != 0) 4635 1.1 mrg { 4636 1.1 mrg Rb = cfun->machine->va_args_first_regno; 4637 1.1 mrg Re = cfun->machine->va_args_last_regno; 4638 1.1 mrg /* No need to push $fp, $gp, or $lp. */ 4639 1.1 mrg nds32_emit_stack_push_multiple (Rb, Re, false, false, false, true); 4640 1.1 mrg 4641 1.1 mrg /* We may also need to adjust stack pointer for padding bytes 4642 1.1 mrg because varargs may cause $sp not 8-byte aligned. */ 4643 1.1 mrg if (cfun->machine->va_args_area_padding_bytes) 4644 1.1 mrg { 4645 1.1 mrg /* Generate sp adjustment instruction. */ 4646 1.1 mrg sp_adjust = cfun->machine->va_args_area_padding_bytes; 4647 1.1 mrg 4648 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4649 1.1 mrg stack_pointer_rtx, 4650 1.1 mrg -1 * sp_adjust); 4651 1.1 mrg } 4652 1.1 mrg } 4653 1.1 mrg 4654 1.1 mrg /* If the function is 'naked', 4655 1.1 mrg we do not have to generate prologue code fragment. */ 4656 1.1 mrg if (cfun->machine->naked_p && !flag_pic) 4657 1.1 mrg return; 4658 1.1 mrg 4659 1.1 mrg /* Get callee_first_regno and callee_last_regno. */ 4660 1.1 mrg Rb = cfun->machine->callee_saved_first_gpr_regno; 4661 1.1 mrg Re = cfun->machine->callee_saved_last_gpr_regno; 4662 1.1 mrg 4663 1.1 mrg /* If $fp, $gp, $lp, and all callee-save registers are NOT required 4664 1.1 mrg to be saved, we don't have to create multiple push instruction. 4665 1.1 mrg Otherwise, a multiple push instruction is needed. */ 4666 1.1 mrg if (!(Rb == SP_REGNUM && Re == SP_REGNUM 4667 1.1 mrg && cfun->machine->fp_size == 0 4668 1.1 mrg && cfun->machine->gp_size == 0 4669 1.1 mrg && cfun->machine->lp_size == 0)) 4670 1.1 mrg { 4671 1.1 mrg /* Create multiple push instruction rtx. */ 4672 1.1 mrg nds32_emit_stack_push_multiple ( 4673 1.1 mrg Rb, Re, 4674 1.1 mrg cfun->machine->fp_size, cfun->machine->gp_size, cfun->machine->lp_size, 4675 1.1 mrg false); 4676 1.1 mrg } 4677 1.1 mrg 4678 1.1 mrg /* Save eh data registers. */ 4679 1.1 mrg if (cfun->machine->use_eh_return_p) 4680 1.1 mrg { 4681 1.1 mrg Rb = cfun->machine->eh_return_data_first_regno; 4682 1.1 mrg Re = cfun->machine->eh_return_data_last_regno; 4683 1.1 mrg 4684 1.1 mrg /* No need to push $fp, $gp, or $lp. 4685 1.1 mrg Also, this is not variadic arguments push. */ 4686 1.1 mrg nds32_emit_stack_push_multiple (Rb, Re, false, false, false, false); 4687 1.1 mrg } 4688 1.1 mrg 4689 1.1 mrg /* Check frame_pointer_needed to see 4690 1.1 mrg if we shall emit fp adjustment instruction. */ 4691 1.1 mrg if (frame_pointer_needed) 4692 1.1 mrg { 4693 1.1 mrg /* adjust $fp = $sp + ($fp size) + ($gp size) + ($lp size) 4694 1.1 mrg + (4 * callee-saved-registers) 4695 1.1 mrg + (4 * exception-handling-data-registers) 4696 1.1 mrg Note: No need to adjust 4697 1.1 mrg cfun->machine->callee_saved_area_gpr_padding_bytes, 4698 1.1 mrg because, at this point, stack pointer is just 4699 1.1 mrg at the position after push instruction. */ 4700 1.1 mrg fp_adjust = cfun->machine->fp_size 4701 1.1 mrg + cfun->machine->gp_size 4702 1.1 mrg + cfun->machine->lp_size 4703 1.1 mrg + cfun->machine->callee_saved_gpr_regs_size 4704 1.1 mrg + cfun->machine->eh_return_data_regs_size; 4705 1.1 mrg 4706 1.1 mrg nds32_emit_adjust_frame (hard_frame_pointer_rtx, 4707 1.1 mrg stack_pointer_rtx, 4708 1.1 mrg fp_adjust); 4709 1.1 mrg } 4710 1.1 mrg 4711 1.1 mrg /* Save fpu registers. */ 4712 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 4713 1.1 mrg { 4714 1.1 mrg /* When $sp moved to bottom of stack, we need to check whether 4715 1.1 mrg the range of offset in the FPU instruction. */ 4716 1.1 mrg int fpr_offset = cfun->machine->local_size 4717 1.1 mrg + cfun->machine->out_args_size 4718 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 4719 1.1 mrg 4720 1.1 mrg /* Check FPU instruction offset imm14s. */ 4721 1.1 mrg if (!satisfies_constraint_Is14 (GEN_INT (fpr_offset))) 4722 1.1 mrg { 4723 1.1 mrg int fpr_space = cfun->machine->callee_saved_area_gpr_padding_bytes 4724 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 4725 1.1 mrg 4726 1.1 mrg /* Save fpu registers, need to allocate stack space 4727 1.1 mrg for fpu callee registers. And now $sp position 4728 1.1 mrg on callee saved fpr registers. */ 4729 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4730 1.1 mrg stack_pointer_rtx, 4731 1.1 mrg -1 * fpr_space); 4732 1.1 mrg 4733 1.1 mrg /* Emit fpu store instruction, using [$sp + offset] store 4734 1.1 mrg fpu registers. */ 4735 1.1 mrg nds32_emit_push_fpr_callee_saved (0); 4736 1.1 mrg 4737 1.1 mrg /* Adjust $sp = $sp - local_size - out_args_size. */ 4738 1.1 mrg sp_adjust = cfun->machine->local_size 4739 1.1 mrg + cfun->machine->out_args_size; 4740 1.1 mrg 4741 1.1 mrg /* Allocate stack space for local size and out args size. */ 4742 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4743 1.1 mrg stack_pointer_rtx, 4744 1.1 mrg -1 * sp_adjust); 4745 1.1 mrg } 4746 1.1 mrg else 4747 1.1 mrg { 4748 1.1 mrg /* Offset range in Is14, so $sp moved to bottom of stack. */ 4749 1.1 mrg 4750 1.1 mrg /* Adjust $sp = $sp - local_size - out_args_size 4751 1.1 mrg - callee_saved_area_gpr_padding_bytes 4752 1.1 mrg - callee_saved_fpr_regs_size. */ 4753 1.1 mrg sp_adjust = cfun->machine->local_size 4754 1.1 mrg + cfun->machine->out_args_size 4755 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes 4756 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 4757 1.1 mrg 4758 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4759 1.1 mrg stack_pointer_rtx, 4760 1.1 mrg -1 * sp_adjust); 4761 1.1 mrg 4762 1.1 mrg /* Emit fpu store instruction, using [$sp + offset] store 4763 1.1 mrg fpu registers. */ 4764 1.1 mrg int fpr_position = cfun->machine->out_args_size 4765 1.1 mrg + cfun->machine->local_size; 4766 1.1 mrg nds32_emit_push_fpr_callee_saved (fpr_position); 4767 1.1 mrg } 4768 1.1 mrg } 4769 1.1 mrg else 4770 1.1 mrg { 4771 1.1 mrg /* Adjust $sp = $sp - local_size - out_args_size 4772 1.1 mrg - callee_saved_area_gpr_padding_bytes. */ 4773 1.1 mrg sp_adjust = cfun->machine->local_size 4774 1.1 mrg + cfun->machine->out_args_size 4775 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes; 4776 1.1 mrg 4777 1.1 mrg /* sp_adjust value may be out of range of the addi instruction, 4778 1.1 mrg create alternative add behavior with TA_REGNUM if necessary, 4779 1.1 mrg using NEGATIVE value to tell that we are decreasing address. */ 4780 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4781 1.1 mrg stack_pointer_rtx, 4782 1.1 mrg -1 * sp_adjust); 4783 1.1 mrg } 4784 1.1 mrg 4785 1.1 mrg /* Emit gp setup instructions for -fpic. */ 4786 1.1 mrg if (flag_pic && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM)) 4787 1.1 mrg nds32_emit_load_gp (); 4788 1.1 mrg 4789 1.1 mrg /* If user applies -mno-sched-prolog-epilog option, 4790 1.1 mrg we need to prevent instructions of function body from being 4791 1.1 mrg scheduled with stack adjustment in prologue. */ 4792 1.1 mrg if (!flag_sched_prolog_epilog) 4793 1.1 mrg emit_insn (gen_blockage ()); 4794 1.1 mrg } 4795 1.1 mrg 4796 1.1 mrg /* Function for normal multiple pop epilogue. */ 4797 1.1 mrg void 4798 1.1 mrg nds32_expand_epilogue (bool sibcall_p) 4799 1.1 mrg { 4800 1.1 mrg int sp_adjust; 4801 1.1 mrg unsigned Rb, Re; 4802 1.1 mrg 4803 1.1 mrg /* Compute and setup stack frame size. 4804 1.1 mrg The result will be in cfun->machine. */ 4805 1.1 mrg nds32_compute_stack_frame (); 4806 1.1 mrg 4807 1.1 mrg /* If user applies -mno-sched-prolog-epilog option, 4808 1.1 mrg we need to prevent instructions of function body from being 4809 1.1 mrg scheduled with stack adjustment in epilogue. */ 4810 1.1 mrg if (!flag_sched_prolog_epilog) 4811 1.1 mrg emit_insn (gen_blockage ()); 4812 1.1 mrg 4813 1.1 mrg /* If the function is 'naked', we do not have to generate 4814 1.1 mrg epilogue code fragment BUT 'ret' instruction. 4815 1.1 mrg However, if this function is also a variadic function, 4816 1.1 mrg we need to create adjust stack pointer before 'ret' instruction. */ 4817 1.1 mrg if (cfun->machine->naked_p) 4818 1.1 mrg { 4819 1.1 mrg /* If this is a variadic function, we do not have to restore argument 4820 1.1 mrg registers but need to adjust stack pointer back to previous stack 4821 1.1 mrg frame location before return. */ 4822 1.1 mrg if (cfun->machine->va_args_size != 0) 4823 1.1 mrg { 4824 1.1 mrg /* Generate sp adjustment instruction. 4825 1.1 mrg We need to consider padding bytes here. */ 4826 1.1 mrg sp_adjust = cfun->machine->va_args_size 4827 1.1 mrg + cfun->machine->va_args_area_padding_bytes; 4828 1.1 mrg 4829 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4830 1.1 mrg stack_pointer_rtx, 4831 1.1 mrg sp_adjust); 4832 1.1 mrg } 4833 1.1 mrg 4834 1.1 mrg /* Generate return instruction by using 'return_internal' pattern. 4835 1.1 mrg Make sure this instruction is after gen_blockage(). */ 4836 1.1 mrg if (!sibcall_p) 4837 1.1 mrg { 4838 1.1 mrg /* We need to further check attributes to determine whether 4839 1.1 mrg there should be return instruction at epilogue. 4840 1.1 mrg If the attribute naked exists but -mno-ret-in-naked-func 4841 1.1 mrg is issued, there is NO need to generate return instruction. */ 4842 1.1 mrg if (cfun->machine->attr_naked_p && !flag_ret_in_naked_func) 4843 1.1 mrg return; 4844 1.1 mrg 4845 1.1 mrg emit_jump_insn (gen_return_internal ()); 4846 1.1 mrg } 4847 1.1 mrg return; 4848 1.1 mrg } 4849 1.1 mrg 4850 1.1 mrg if (frame_pointer_needed) 4851 1.1 mrg { 4852 1.1 mrg /* Restore fpu registers. */ 4853 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 4854 1.1 mrg { 4855 1.1 mrg int gpr_padding = cfun->machine->callee_saved_area_gpr_padding_bytes; 4856 1.1 mrg 4857 1.1 mrg /* adjust $sp = $fp - ($fp size) - ($gp size) - ($lp size) 4858 1.1 mrg - (4 * callee-saved-registers) 4859 1.1 mrg - (4 * exception-handling-data-registers) 4860 1.1 mrg - (4 * callee-saved-gpr-registers padding byte) 4861 1.1 mrg - (4 * callee-saved-fpr-registers) 4862 1.1 mrg Note: we want to adjust stack pointer 4863 1.1 mrg to the position for callee-saved fpr register, 4864 1.1 mrg And restore fpu register use .bi instruction to adjust $sp 4865 1.1 mrg from callee-saved fpr register to pop instruction. */ 4866 1.1 mrg sp_adjust = cfun->machine->fp_size 4867 1.1 mrg + cfun->machine->gp_size 4868 1.1 mrg + cfun->machine->lp_size 4869 1.1 mrg + cfun->machine->callee_saved_gpr_regs_size 4870 1.1 mrg + cfun->machine->eh_return_data_regs_size 4871 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes 4872 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 4873 1.1 mrg 4874 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4875 1.1 mrg hard_frame_pointer_rtx, 4876 1.1 mrg -1 * sp_adjust); 4877 1.1 mrg 4878 1.1 mrg /* Emit fpu load instruction, using .bi instruction 4879 1.1 mrg load fpu registers. */ 4880 1.1 mrg nds32_emit_pop_fpr_callee_saved (gpr_padding); 4881 1.1 mrg } 4882 1.1 mrg else 4883 1.1 mrg { 4884 1.1 mrg /* adjust $sp = $fp - ($fp size) - ($gp size) - ($lp size) 4885 1.1 mrg - (4 * callee-saved-registers) 4886 1.1 mrg - (4 * exception-handling-data-registers) 4887 1.1 mrg Note: No need to adjust 4888 1.1 mrg cfun->machine->callee_saved_area_gpr_padding_bytes, 4889 1.1 mrg because we want to adjust stack pointer 4890 1.1 mrg to the position for pop instruction. */ 4891 1.1 mrg sp_adjust = cfun->machine->fp_size 4892 1.1 mrg + cfun->machine->gp_size 4893 1.1 mrg + cfun->machine->lp_size 4894 1.1 mrg + cfun->machine->callee_saved_gpr_regs_size 4895 1.1 mrg + cfun->machine->eh_return_data_regs_size; 4896 1.1 mrg 4897 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4898 1.1 mrg hard_frame_pointer_rtx, 4899 1.1 mrg -1 * sp_adjust); 4900 1.1 mrg } 4901 1.1 mrg } 4902 1.1 mrg else 4903 1.1 mrg { 4904 1.1 mrg /* Restore fpu registers. */ 4905 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 4906 1.1 mrg { 4907 1.1 mrg int gpr_padding = cfun->machine->callee_saved_area_gpr_padding_bytes; 4908 1.1 mrg 4909 1.1 mrg /* Adjust $sp = $sp + local_size + out_args_size. */ 4910 1.1 mrg sp_adjust = cfun->machine->local_size 4911 1.1 mrg + cfun->machine->out_args_size; 4912 1.1 mrg 4913 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4914 1.1 mrg stack_pointer_rtx, 4915 1.1 mrg sp_adjust); 4916 1.1 mrg 4917 1.1 mrg /* Emit fpu load instruction, using .bi instruction 4918 1.1 mrg load fpu registers, and adjust $sp from callee-saved fpr register 4919 1.1 mrg to callee-saved gpr register. */ 4920 1.1 mrg nds32_emit_pop_fpr_callee_saved (gpr_padding); 4921 1.1 mrg } 4922 1.1 mrg else 4923 1.1 mrg { 4924 1.1 mrg /* If frame pointer is NOT needed, 4925 1.1 mrg we cannot calculate the sp adjustment from frame pointer. 4926 1.1 mrg Instead, we calculate the adjustment by local_size, 4927 1.1 mrg out_args_size, and callee_saved_area_gpr_padding_bytes. 4928 1.1 mrg Notice that such sp adjustment value may be out of range, 4929 1.1 mrg so we have to deal with it as well. */ 4930 1.1 mrg 4931 1.1 mrg /* Adjust $sp = $sp + local_size + out_args_size 4932 1.1 mrg + callee_saved_area_gpr_padding_bytes. */ 4933 1.1 mrg sp_adjust = cfun->machine->local_size 4934 1.1 mrg + cfun->machine->out_args_size 4935 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes; 4936 1.1 mrg 4937 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4938 1.1 mrg stack_pointer_rtx, 4939 1.1 mrg sp_adjust); 4940 1.1 mrg } 4941 1.1 mrg } 4942 1.1 mrg 4943 1.1 mrg /* Restore eh data registers. */ 4944 1.1 mrg if (cfun->machine->use_eh_return_p) 4945 1.1 mrg { 4946 1.1 mrg Rb = cfun->machine->eh_return_data_first_regno; 4947 1.1 mrg Re = cfun->machine->eh_return_data_last_regno; 4948 1.1 mrg 4949 1.1 mrg /* No need to pop $fp, $gp, or $lp. */ 4950 1.1 mrg nds32_emit_stack_pop_multiple (Rb, Re, false, false, false); 4951 1.1 mrg } 4952 1.1 mrg 4953 1.1 mrg /* Get callee_first_regno and callee_last_regno. */ 4954 1.1 mrg Rb = cfun->machine->callee_saved_first_gpr_regno; 4955 1.1 mrg Re = cfun->machine->callee_saved_last_gpr_regno; 4956 1.1 mrg 4957 1.1 mrg /* If $fp, $gp, $lp, and all callee-save registers are NOT required 4958 1.1 mrg to be saved, we don't have to create multiple pop instruction. 4959 1.1 mrg Otherwise, a multiple pop instruction is needed. */ 4960 1.1 mrg if (!(Rb == SP_REGNUM && Re == SP_REGNUM 4961 1.1 mrg && cfun->machine->fp_size == 0 4962 1.1 mrg && cfun->machine->gp_size == 0 4963 1.1 mrg && cfun->machine->lp_size == 0)) 4964 1.1 mrg { 4965 1.1 mrg /* Create multiple pop instruction rtx. */ 4966 1.1 mrg nds32_emit_stack_pop_multiple ( 4967 1.1 mrg Rb, Re, 4968 1.1 mrg cfun->machine->fp_size, cfun->machine->gp_size, cfun->machine->lp_size); 4969 1.1 mrg } 4970 1.1 mrg 4971 1.1 mrg /* If this is a variadic function, we do not have to restore argument 4972 1.1 mrg registers but need to adjust stack pointer back to previous stack 4973 1.1 mrg frame location before return. */ 4974 1.1 mrg if (cfun->machine->va_args_size != 0) 4975 1.1 mrg { 4976 1.1 mrg /* Generate sp adjustment instruction. 4977 1.1 mrg We need to consider padding bytes here. */ 4978 1.1 mrg sp_adjust = cfun->machine->va_args_size 4979 1.1 mrg + cfun->machine->va_args_area_padding_bytes; 4980 1.1 mrg 4981 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 4982 1.1 mrg stack_pointer_rtx, 4983 1.1 mrg sp_adjust); 4984 1.1 mrg } 4985 1.1 mrg 4986 1.1 mrg /* If this function uses __builtin_eh_return, make stack adjustment 4987 1.1 mrg for exception handler. */ 4988 1.1 mrg if (cfun->machine->use_eh_return_p) 4989 1.1 mrg { 4990 1.1 mrg /* We need to unwind the stack by the offset computed by 4991 1.1 mrg EH_RETURN_STACKADJ_RTX. However, at this point the CFA is 4992 1.1 mrg based on SP. Ideally we would update the SP and define the 4993 1.1 mrg CFA along the lines of: 4994 1.1 mrg 4995 1.1 mrg SP = SP + EH_RETURN_STACKADJ_RTX 4996 1.1 mrg (regnote CFA = SP - EH_RETURN_STACKADJ_RTX) 4997 1.1 mrg 4998 1.1 mrg However the dwarf emitter only understands a constant 4999 1.1 mrg register offset. 5000 1.1 mrg 5001 1.1 mrg The solution chosen here is to use the otherwise $ta ($r15) 5002 1.1 mrg as a temporary register to hold the current SP value. The 5003 1.1 mrg CFA is described using $ta then SP is modified. */ 5004 1.1 mrg 5005 1.1 mrg rtx ta_reg; 5006 1.1 mrg rtx insn; 5007 1.1 mrg 5008 1.1 mrg ta_reg = gen_rtx_REG (SImode, TA_REGNUM); 5009 1.1 mrg 5010 1.1 mrg insn = emit_move_insn (ta_reg, stack_pointer_rtx); 5011 1.1 mrg add_reg_note (insn, REG_CFA_DEF_CFA, ta_reg); 5012 1.1 mrg RTX_FRAME_RELATED_P (insn) = 1; 5013 1.1 mrg 5014 1.1 mrg emit_insn (gen_addsi3 (stack_pointer_rtx, 5015 1.1 mrg stack_pointer_rtx, 5016 1.1 mrg EH_RETURN_STACKADJ_RTX)); 5017 1.1 mrg 5018 1.1 mrg /* Ensure the assignment to $ta does not get optimized away. */ 5019 1.1 mrg emit_use (ta_reg); 5020 1.1 mrg } 5021 1.1 mrg 5022 1.1 mrg /* Generate return instruction. */ 5023 1.1 mrg if (!sibcall_p) 5024 1.1 mrg emit_jump_insn (gen_return_internal ()); 5025 1.1 mrg } 5026 1.1 mrg 5027 1.1 mrg /* Function for v3push prologue. */ 5028 1.1 mrg void 5029 1.1 mrg nds32_expand_prologue_v3push (void) 5030 1.1 mrg { 5031 1.1 mrg int fp_adjust; 5032 1.1 mrg int sp_adjust; 5033 1.1 mrg int fpr_space = 0; 5034 1.1 mrg unsigned Rb, Re; 5035 1.1 mrg 5036 1.1 mrg /* Compute and setup stack frame size. 5037 1.1 mrg The result will be in cfun->machine. */ 5038 1.1 mrg nds32_compute_stack_frame (); 5039 1.1 mrg 5040 1.1 mrg if (cfun->machine->callee_saved_gpr_regs_size > 0) 5041 1.1 mrg df_set_regs_ever_live (FP_REGNUM, 1); 5042 1.1 mrg 5043 1.1 mrg /* Check frame_pointer_needed again to prevent fp is need after reload. */ 5044 1.1 mrg if (frame_pointer_needed) 5045 1.1 mrg cfun->machine->fp_as_gp_p = false; 5046 1.1 mrg 5047 1.1 mrg /* If the function is 'naked', 5048 1.1 mrg we do not have to generate prologue code fragment. */ 5049 1.1 mrg if (cfun->machine->naked_p && !flag_pic) 5050 1.1 mrg return; 5051 1.1 mrg 5052 1.1 mrg /* Get callee_first_regno and callee_last_regno. */ 5053 1.1 mrg Rb = cfun->machine->callee_saved_first_gpr_regno; 5054 1.1 mrg Re = cfun->machine->callee_saved_last_gpr_regno; 5055 1.1 mrg 5056 1.1 mrg /* Calculate sp_adjust first to test if 'push25 Re,imm8u' is available, 5057 1.1 mrg where imm8u has to be 8-byte alignment. */ 5058 1.1 mrg sp_adjust = cfun->machine->local_size 5059 1.1 mrg + cfun->machine->out_args_size 5060 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes 5061 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 5062 1.1 mrg 5063 1.1 mrg if (satisfies_constraint_Iu08 (GEN_INT (sp_adjust)) 5064 1.1 mrg && NDS32_DOUBLE_WORD_ALIGN_P (sp_adjust)) 5065 1.1 mrg { 5066 1.1 mrg /* We can use 'push25 Re,imm8u'. */ 5067 1.1 mrg 5068 1.1 mrg /* nds32_emit_stack_v3push(last_regno, sp_adjust), 5069 1.1 mrg the pattern 'stack_v3push' is implemented in nds32.md. */ 5070 1.1 mrg nds32_emit_stack_v3push (Rb, Re, sp_adjust); 5071 1.1 mrg 5072 1.1 mrg /* Save fpu registers. */ 5073 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 5074 1.1 mrg { 5075 1.1 mrg /* Calculate fpr position. */ 5076 1.1 mrg int fpr_position = cfun->machine->local_size 5077 1.1 mrg + cfun->machine->out_args_size; 5078 1.1 mrg /* Emit fpu store instruction, using [$sp + offset] store 5079 1.1 mrg fpu registers. */ 5080 1.1 mrg nds32_emit_push_fpr_callee_saved (fpr_position); 5081 1.1 mrg } 5082 1.1 mrg 5083 1.1 mrg /* Check frame_pointer_needed to see 5084 1.1 mrg if we shall emit fp adjustment instruction. */ 5085 1.1 mrg if (frame_pointer_needed) 5086 1.1 mrg { 5087 1.1 mrg /* adjust $fp = $sp + 4 ($fp size) 5088 1.1 mrg + 4 ($gp size) 5089 1.1 mrg + 4 ($lp size) 5090 1.1 mrg + (4 * n) (callee-saved registers) 5091 1.1 mrg + sp_adjust ('push25 Re,imm8u') 5092 1.1 mrg Note: Since we use 'push25 Re,imm8u', 5093 1.1 mrg the position of stack pointer is further 5094 1.1 mrg changed after push instruction. 5095 1.1 mrg Hence, we need to take sp_adjust value 5096 1.1 mrg into consideration. */ 5097 1.1 mrg fp_adjust = cfun->machine->fp_size 5098 1.1 mrg + cfun->machine->gp_size 5099 1.1 mrg + cfun->machine->lp_size 5100 1.1 mrg + cfun->machine->callee_saved_gpr_regs_size 5101 1.1 mrg + sp_adjust; 5102 1.1 mrg 5103 1.1 mrg nds32_emit_adjust_frame (hard_frame_pointer_rtx, 5104 1.1 mrg stack_pointer_rtx, 5105 1.1 mrg fp_adjust); 5106 1.1 mrg } 5107 1.1 mrg } 5108 1.1 mrg else 5109 1.1 mrg { 5110 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 5111 1.1 mrg { 5112 1.1 mrg /* Calculate fpr space. */ 5113 1.1 mrg fpr_space = cfun->machine->callee_saved_area_gpr_padding_bytes 5114 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 5115 1.1 mrg 5116 1.1 mrg /* We have to use 'push25 Re, fpr_space', to pre-allocate 5117 1.1 mrg callee saved fpr registers space. */ 5118 1.1 mrg nds32_emit_stack_v3push (Rb, Re, fpr_space); 5119 1.1 mrg nds32_emit_push_fpr_callee_saved (0); 5120 1.1 mrg } 5121 1.1 mrg else 5122 1.1 mrg { 5123 1.1 mrg /* We have to use 'push25 Re,0' and 5124 1.1 mrg expand one more instruction to adjust $sp later. */ 5125 1.1 mrg 5126 1.1 mrg /* nds32_emit_stack_v3push(last_regno, sp_adjust), 5127 1.1 mrg the pattern 'stack_v3push' is implemented in nds32.md. */ 5128 1.1 mrg nds32_emit_stack_v3push (Rb, Re, 0); 5129 1.1 mrg } 5130 1.1 mrg 5131 1.1 mrg /* Check frame_pointer_needed to see 5132 1.1 mrg if we shall emit fp adjustment instruction. */ 5133 1.1 mrg if (frame_pointer_needed) 5134 1.1 mrg { 5135 1.1 mrg /* adjust $fp = $sp + 4 ($fp size) 5136 1.1 mrg + 4 ($gp size) 5137 1.1 mrg + 4 ($lp size) 5138 1.1 mrg + (4 * n) (callee-saved registers) 5139 1.1 mrg Note: Since we use 'push25 Re,0', 5140 1.1 mrg the stack pointer is just at the position 5141 1.1 mrg after push instruction. 5142 1.1 mrg No need to take sp_adjust into consideration. */ 5143 1.1 mrg fp_adjust = cfun->machine->fp_size 5144 1.1 mrg + cfun->machine->gp_size 5145 1.1 mrg + cfun->machine->lp_size 5146 1.1 mrg + cfun->machine->callee_saved_gpr_regs_size; 5147 1.1 mrg 5148 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 5149 1.1 mrg { 5150 1.1 mrg /* We use 'push25 Re, fpr_space', the $sp is 5151 1.1 mrg on callee saved fpr position, so need to consider 5152 1.1 mrg fpr space. */ 5153 1.1 mrg fp_adjust = fp_adjust + fpr_space; 5154 1.1 mrg } 5155 1.1 mrg 5156 1.1 mrg nds32_emit_adjust_frame (hard_frame_pointer_rtx, 5157 1.1 mrg stack_pointer_rtx, 5158 1.1 mrg fp_adjust); 5159 1.1 mrg } 5160 1.1 mrg 5161 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 5162 1.1 mrg { 5163 1.1 mrg /* We use 'push25 Re, fpr_space', 5164 1.1 mrg the $sp is on callee saved fpr position, 5165 1.1 mrg no need to consider fpr space. */ 5166 1.1 mrg sp_adjust = sp_adjust - fpr_space; 5167 1.1 mrg } 5168 1.1 mrg 5169 1.1 mrg /* Because we use 'push25 Re,0', 5170 1.1 mrg we need to expand one more instruction to adjust $sp. 5171 1.1 mrg using NEGATIVE value to tell that we are decreasing address. */ 5172 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 5173 1.1 mrg stack_pointer_rtx, 5174 1.1 mrg -1 * sp_adjust); 5175 1.1 mrg } 5176 1.1 mrg 5177 1.1 mrg /* Emit gp setup instructions for -fpic. */ 5178 1.1 mrg if (flag_pic && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM)) 5179 1.1 mrg nds32_emit_load_gp (); 5180 1.1 mrg 5181 1.1 mrg /* Prevent the instruction scheduler from 5182 1.1 mrg moving instructions across the boundary. */ 5183 1.1 mrg emit_insn (gen_blockage ()); 5184 1.1 mrg } 5185 1.1 mrg 5186 1.1 mrg /* Function for v3pop epilogue. */ 5187 1.1 mrg void 5188 1.1 mrg nds32_expand_epilogue_v3pop (bool sibcall_p) 5189 1.1 mrg { 5190 1.1 mrg int sp_adjust; 5191 1.1 mrg unsigned Rb, Re; 5192 1.1 mrg 5193 1.1 mrg /* Compute and setup stack frame size. 5194 1.1 mrg The result will be in cfun->machine. */ 5195 1.1 mrg nds32_compute_stack_frame (); 5196 1.1 mrg 5197 1.1 mrg /* Prevent the instruction scheduler from 5198 1.1 mrg moving instructions across the boundary. */ 5199 1.1 mrg emit_insn (gen_blockage ()); 5200 1.1 mrg 5201 1.1 mrg /* If the function is 'naked', we do not have to generate 5202 1.1 mrg epilogue code fragment BUT 'ret' instruction. */ 5203 1.1 mrg if (cfun->machine->naked_p) 5204 1.1 mrg { 5205 1.1 mrg /* Generate return instruction by using 'return_internal' pattern. 5206 1.1 mrg Make sure this instruction is after gen_blockage(). 5207 1.1 mrg First we need to check this is a function without sibling call. */ 5208 1.1 mrg if (!sibcall_p) 5209 1.1 mrg { 5210 1.1 mrg /* We need to further check attributes to determine whether 5211 1.1 mrg there should be return instruction at epilogue. 5212 1.1 mrg If the attribute naked exists but -mno-ret-in-naked-func 5213 1.1 mrg is issued, there is NO need to generate return instruction. */ 5214 1.1 mrg if (cfun->machine->attr_naked_p && !flag_ret_in_naked_func) 5215 1.1 mrg return; 5216 1.1 mrg 5217 1.1 mrg emit_jump_insn (gen_return_internal ()); 5218 1.1 mrg } 5219 1.1 mrg return; 5220 1.1 mrg } 5221 1.1 mrg 5222 1.1 mrg /* Get callee_first_regno and callee_last_regno. */ 5223 1.1 mrg Rb = cfun->machine->callee_saved_first_gpr_regno; 5224 1.1 mrg Re = cfun->machine->callee_saved_last_gpr_regno; 5225 1.1 mrg 5226 1.1 mrg /* Calculate sp_adjust first to test if 'pop25 Re,imm8u' is available, 5227 1.1 mrg where imm8u has to be 8-byte alignment. */ 5228 1.1 mrg sp_adjust = cfun->machine->local_size 5229 1.1 mrg + cfun->machine->out_args_size 5230 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes 5231 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 5232 1.1 mrg 5233 1.1 mrg /* We have to consider alloca issue as well. 5234 1.1 mrg If the function does call alloca(), the stack pointer is not fixed. 5235 1.1 mrg In that case, we cannot use 'pop25 Re,imm8u' directly. 5236 1.1 mrg We have to caculate stack pointer from frame pointer 5237 1.1 mrg and then use 'pop25 Re,0'. 5238 1.1 mrg Of course, the frame_pointer_needed should be nonzero 5239 1.1 mrg if the function calls alloca(). */ 5240 1.1 mrg if (satisfies_constraint_Iu08 (GEN_INT (sp_adjust)) 5241 1.1 mrg && NDS32_DOUBLE_WORD_ALIGN_P (sp_adjust) 5242 1.1 mrg && !cfun->calls_alloca) 5243 1.1 mrg { 5244 1.1 mrg /* Restore fpu registers. */ 5245 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 5246 1.1 mrg { 5247 1.1 mrg int fpr_position = cfun->machine->local_size 5248 1.1 mrg + cfun->machine->out_args_size; 5249 1.1 mrg /* Emit fpu load instruction, using [$sp + offset] restore 5250 1.1 mrg fpu registers. */ 5251 1.1 mrg nds32_emit_v3pop_fpr_callee_saved (fpr_position); 5252 1.1 mrg } 5253 1.1 mrg 5254 1.1 mrg /* We can use 'pop25 Re,imm8u'. */ 5255 1.1 mrg 5256 1.1 mrg /* nds32_emit_stack_v3pop(last_regno, sp_adjust), 5257 1.1 mrg the pattern 'stack_v3pop' is implementad in nds32.md. */ 5258 1.1 mrg nds32_emit_stack_v3pop (Rb, Re, sp_adjust); 5259 1.1 mrg } 5260 1.1 mrg else 5261 1.1 mrg { 5262 1.1 mrg /* We have to use 'pop25 Re,0', and prior to it, 5263 1.1 mrg we must expand one more instruction to adjust $sp. */ 5264 1.1 mrg 5265 1.1 mrg if (frame_pointer_needed) 5266 1.1 mrg { 5267 1.1 mrg /* adjust $sp = $fp - 4 ($fp size) 5268 1.1 mrg - 4 ($gp size) 5269 1.1 mrg - 4 ($lp size) 5270 1.1 mrg - (4 * n) (callee-saved registers) 5271 1.1 mrg Note: No need to adjust 5272 1.1 mrg cfun->machine->callee_saved_area_gpr_padding_bytes, 5273 1.1 mrg because we want to adjust stack pointer 5274 1.1 mrg to the position for pop instruction. */ 5275 1.1 mrg sp_adjust = cfun->machine->fp_size 5276 1.1 mrg + cfun->machine->gp_size 5277 1.1 mrg + cfun->machine->lp_size 5278 1.1 mrg + cfun->machine->callee_saved_gpr_regs_size; 5279 1.1 mrg 5280 1.1 mrg /* Restore fpu registers. */ 5281 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 5282 1.1 mrg { 5283 1.1 mrg /* Set $sp to callee saved fpr position, we need to restore 5284 1.1 mrg fpr registers. */ 5285 1.1 mrg sp_adjust = sp_adjust 5286 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes 5287 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 5288 1.1 mrg 5289 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 5290 1.1 mrg hard_frame_pointer_rtx, 5291 1.1 mrg -1 * sp_adjust); 5292 1.1 mrg 5293 1.1 mrg /* Emit fpu load instruction, using [$sp + offset] restore 5294 1.1 mrg fpu registers. */ 5295 1.1 mrg nds32_emit_v3pop_fpr_callee_saved (0); 5296 1.1 mrg } 5297 1.1 mrg else 5298 1.1 mrg { 5299 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 5300 1.1 mrg hard_frame_pointer_rtx, 5301 1.1 mrg -1 * sp_adjust); 5302 1.1 mrg } 5303 1.1 mrg } 5304 1.1 mrg else 5305 1.1 mrg { 5306 1.1 mrg /* If frame pointer is NOT needed, 5307 1.1 mrg we cannot calculate the sp adjustment from frame pointer. 5308 1.1 mrg Instead, we calculate the adjustment by local_size, 5309 1.1 mrg out_args_size, and callee_saved_area_padding_bytes. 5310 1.1 mrg Notice that such sp adjustment value may be out of range, 5311 1.1 mrg so we have to deal with it as well. */ 5312 1.1 mrg 5313 1.1 mrg /* Adjust $sp = $sp + local_size + out_args_size 5314 1.1 mrg + callee_saved_area_gpr_padding_bytes 5315 1.1 mrg + callee_saved_fpr_regs_size. */ 5316 1.1 mrg sp_adjust = cfun->machine->local_size 5317 1.1 mrg + cfun->machine->out_args_size 5318 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes 5319 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 5320 1.1 mrg 5321 1.1 mrg /* Restore fpu registers. */ 5322 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 5323 1.1 mrg { 5324 1.1 mrg /* Set $sp to callee saved fpr position, we need to restore 5325 1.1 mrg fpr registers. */ 5326 1.1 mrg sp_adjust = sp_adjust 5327 1.1 mrg - cfun->machine->callee_saved_area_gpr_padding_bytes 5328 1.1 mrg - cfun->machine->callee_saved_fpr_regs_size; 5329 1.1 mrg 5330 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 5331 1.1 mrg stack_pointer_rtx, 5332 1.1 mrg sp_adjust); 5333 1.1 mrg 5334 1.1 mrg /* Emit fpu load instruction, using [$sp + offset] restore 5335 1.1 mrg fpu registers. */ 5336 1.1 mrg nds32_emit_v3pop_fpr_callee_saved (0); 5337 1.1 mrg } 5338 1.1 mrg else 5339 1.1 mrg { 5340 1.1 mrg /* sp_adjust value may be out of range of the addi instruction, 5341 1.1 mrg create alternative add behavior with TA_REGNUM if necessary, 5342 1.1 mrg using POSITIVE value to tell that we are increasing 5343 1.1 mrg address. */ 5344 1.1 mrg nds32_emit_adjust_frame (stack_pointer_rtx, 5345 1.1 mrg stack_pointer_rtx, 5346 1.1 mrg sp_adjust); 5347 1.1 mrg } 5348 1.1 mrg } 5349 1.1 mrg 5350 1.1 mrg if (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM) 5351 1.1 mrg { 5352 1.1 mrg /* We have fpr need to restore, so $sp is set on callee saved fpr 5353 1.1 mrg position. And we use 'pop25 Re, fpr_space' to adjust $sp. */ 5354 1.1 mrg int fpr_space = cfun->machine->callee_saved_area_gpr_padding_bytes 5355 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 5356 1.1 mrg nds32_emit_stack_v3pop (Rb, Re, fpr_space); 5357 1.1 mrg } 5358 1.1 mrg else 5359 1.1 mrg { 5360 1.1 mrg /* nds32_emit_stack_v3pop(last_regno, sp_adjust), 5361 1.1 mrg the pattern 'stack_v3pop' is implementad in nds32.md. */ 5362 1.1 mrg nds32_emit_stack_v3pop (Rb, Re, 0); 5363 1.1 mrg } 5364 1.1 mrg } 5365 1.1 mrg /* Generate return instruction. */ 5366 1.1 mrg emit_jump_insn (gen_pop25return ()); 5367 1.1 mrg } 5368 1.1 mrg 5369 1.1 mrg /* Return nonzero if this function is known to have a null epilogue. 5370 1.1 mrg This allows the optimizer to omit jumps to jumps if no stack 5371 1.1 mrg was created. */ 5372 1.1 mrg int 5373 1.1 mrg nds32_can_use_return_insn (void) 5374 1.1 mrg { 5375 1.1 mrg int sp_adjust; 5376 1.1 mrg 5377 1.1 mrg /* Prior to reloading, we can't tell how many registers must be saved. 5378 1.1 mrg Thus we cannot determine whether this function has null epilogue. */ 5379 1.1 mrg if (!reload_completed) 5380 1.1 mrg return 0; 5381 1.1 mrg 5382 1.1 mrg /* If attribute 'naked' appears but -mno-ret-in-naked-func is used, 5383 1.1 mrg we cannot use return instruction. */ 5384 1.1 mrg if (cfun->machine->attr_naked_p && !flag_ret_in_naked_func) 5385 1.1 mrg return 0; 5386 1.1 mrg 5387 1.1 mrg sp_adjust = cfun->machine->local_size 5388 1.1 mrg + cfun->machine->out_args_size 5389 1.1 mrg + cfun->machine->callee_saved_area_gpr_padding_bytes 5390 1.1 mrg + cfun->machine->callee_saved_fpr_regs_size; 5391 1.1 mrg if (!cfun->machine->fp_as_gp_p 5392 1.1 mrg && satisfies_constraint_Iu08 (GEN_INT (sp_adjust)) 5393 1.1 mrg && NDS32_DOUBLE_WORD_ALIGN_P (sp_adjust) 5394 1.1 mrg && !cfun->calls_alloca 5395 1.1 mrg && NDS32_V3PUSH_AVAILABLE_P 5396 1.1 mrg && !(TARGET_HARD_FLOAT 5397 1.1 mrg && (cfun->machine->callee_saved_first_fpr_regno != SP_REGNUM))) 5398 1.1 mrg return 1; 5399 1.1 mrg 5400 1.1 mrg /* If no stack was created, two conditions must be satisfied: 5401 1.1 mrg 1. This is a naked function. 5402 1.1 mrg So there is no callee-saved, local size, or outgoing size. 5403 1.1 mrg 2. This is NOT a variadic function. 5404 1.1 mrg So there is no pushing arguement registers into the stack. */ 5405 1.1 mrg return (cfun->machine->naked_p && (cfun->machine->va_args_size == 0)); 5406 1.1 mrg } 5407 1.1 mrg 5408 1.1 mrg scalar_int_mode 5409 1.1 mrg nds32_case_vector_shorten_mode (int min_offset, int max_offset, 5410 1.1 mrg rtx body ATTRIBUTE_UNUSED) 5411 1.1 mrg { 5412 1.1 mrg if (min_offset < 0 || max_offset >= 0x2000) 5413 1.1 mrg return SImode; 5414 1.1 mrg else 5415 1.1 mrg { 5416 1.1 mrg /* The jump table maybe need to 2 byte alignment, 5417 1.1 mrg so reserved 1 byte for check max_offset. */ 5418 1.1 mrg if (max_offset >= 0xff) 5419 1.1 mrg return HImode; 5420 1.1 mrg else 5421 1.1 mrg return QImode; 5422 1.1 mrg } 5423 1.1 mrg } 5424 1.1 mrg 5425 1.1 mrg /* ------------------------------------------------------------------------ */ 5426 1.1 mrg 5427 1.1 mrg /* Return alignment for the label. */ 5428 1.1 mrg int 5429 1.1 mrg nds32_target_alignment (rtx_insn *label) 5430 1.1 mrg { 5431 1.1 mrg rtx_insn *insn; 5432 1.1 mrg 5433 1.1 mrg if (!NDS32_ALIGN_P ()) 5434 1.1 mrg return 0; 5435 1.1 mrg 5436 1.1 mrg insn = next_active_insn (label); 5437 1.1 mrg 5438 1.1 mrg /* Always align to 4 byte when first instruction after label is jump 5439 1.1 mrg instruction since length for that might changed, so let's always align 5440 1.1 mrg it for make sure we don't lose any perfomance here. */ 5441 1.1 mrg if (insn == 0 5442 1.1 mrg || (get_attr_length (insn) == 2 5443 1.1 mrg && !JUMP_P (insn) && !CALL_P (insn))) 5444 1.1 mrg return 0; 5445 1.1 mrg else 5446 1.1 mrg return 2; 5447 1.1 mrg } 5448 1.1 mrg 5449 1.1 mrg /* Return alignment for data. */ 5450 1.1 mrg unsigned int 5451 1.1 mrg nds32_data_alignment (tree data, 5452 1.1 mrg unsigned int basic_align) 5453 1.1 mrg { 5454 1.1 mrg if ((basic_align < BITS_PER_WORD) 5455 1.1 mrg && (TREE_CODE (data) == ARRAY_TYPE 5456 1.1 mrg || TREE_CODE (data) == UNION_TYPE 5457 1.1 mrg || TREE_CODE (data) == RECORD_TYPE)) 5458 1.1 mrg return BITS_PER_WORD; 5459 1.1 mrg else 5460 1.1 mrg return basic_align; 5461 1.1 mrg } 5462 1.1 mrg 5463 1.1 mrg /* Return alignment for constant value. */ 5464 1.1 mrg static HOST_WIDE_INT 5465 1.1 mrg nds32_constant_alignment (const_tree constant, 5466 1.1 mrg HOST_WIDE_INT basic_align) 5467 1.1 mrg { 5468 1.1 mrg /* Make string literal and constant for constructor to word align. */ 5469 1.1 mrg if (((TREE_CODE (constant) == STRING_CST 5470 1.1 mrg || TREE_CODE (constant) == CONSTRUCTOR 5471 1.1 mrg || TREE_CODE (constant) == UNION_TYPE 5472 1.1 mrg || TREE_CODE (constant) == RECORD_TYPE 5473 1.1 mrg || TREE_CODE (constant) == ARRAY_TYPE) 5474 1.1 mrg && basic_align < BITS_PER_WORD)) 5475 1.1 mrg return BITS_PER_WORD; 5476 1.1 mrg else 5477 1.1 mrg return basic_align; 5478 1.1 mrg } 5479 1.1 mrg 5480 1.1 mrg /* Return alignment for local variable. */ 5481 1.1 mrg unsigned int 5482 1.1 mrg nds32_local_alignment (tree local ATTRIBUTE_UNUSED, 5483 1.1 mrg unsigned int basic_align) 5484 1.1 mrg { 5485 1.1 mrg bool at_least_align_to_word = false; 5486 1.1 mrg /* Make local array, struct and union at least align to word for make 5487 1.1 mrg sure it can unroll memcpy when initialize by constant. */ 5488 1.1 mrg switch (TREE_CODE (local)) 5489 1.1 mrg { 5490 1.1 mrg case ARRAY_TYPE: 5491 1.1 mrg case RECORD_TYPE: 5492 1.1 mrg case UNION_TYPE: 5493 1.1 mrg at_least_align_to_word = true; 5494 1.1 mrg break; 5495 1.1 mrg default: 5496 1.1 mrg at_least_align_to_word = false; 5497 1.1 mrg break; 5498 1.1 mrg } 5499 1.1 mrg if (at_least_align_to_word 5500 1.1 mrg && (basic_align < BITS_PER_WORD)) 5501 1.1 mrg return BITS_PER_WORD; 5502 1.1 mrg else 5503 1.1 mrg return basic_align; 5504 1.1 mrg } 5505 1.1 mrg 5506 1.1 mrg bool 5507 1.1 mrg nds32_split_double_word_load_store_p(rtx *operands, bool load_p) 5508 1.1 mrg { 5509 1.1 mrg rtx mem = load_p ? operands[1] : operands[0]; 5510 1.1 mrg /* Do split at split2 if -O0 or schedule 2 not enable. */ 5511 1.1 mrg if (optimize == 0 || !flag_schedule_insns_after_reload) 5512 1.1 mrg return !satisfies_constraint_Da (mem) || MEM_VOLATILE_P (mem); 5513 1.1 mrg 5514 1.1 mrg /* Split double word load store after copy propgation. */ 5515 1.1 mrg if (current_pass == NULL) 5516 1.1 mrg return false; 5517 1.1 mrg 5518 1.1 mrg const char *pass_name = current_pass->name; 5519 1.1 mrg if (pass_name && ((strcmp (pass_name, "split3") == 0) 5520 1.1 mrg || (strcmp (pass_name, "split5") == 0))) 5521 1.1 mrg return !satisfies_constraint_Da (mem) || MEM_VOLATILE_P (mem); 5522 1.1 mrg 5523 1.1 mrg return false; 5524 1.1 mrg } 5525 1.1 mrg 5526 1.1 mrg static bool 5527 1.1 mrg nds32_use_blocks_for_constant_p (machine_mode mode, 5528 1.1 mrg const_rtx x ATTRIBUTE_UNUSED) 5529 1.1 mrg { 5530 1.1 mrg if ((TARGET_FPU_SINGLE || TARGET_FPU_DOUBLE) 5531 1.1 mrg && (mode == DFmode || mode == SFmode)) 5532 1.1 mrg return true; 5533 1.1 mrg else 5534 1.1 mrg return false; 5535 1.1 mrg } 5536 1.1 mrg 5537 1.1 mrg /* ------------------------------------------------------------------------ */ 5538 1.1 mrg 5539 1.1 mrg /* PART 5: Initialize target hook structure and definitions. */ 5540 1.1 mrg 5541 1.1 mrg /* Controlling the Compilation Driver. */ 5543 1.1 mrg 5544 1.1 mrg 5545 1.1 mrg /* Run-time Target Specification. */ 5547 1.1 mrg 5548 1.1 mrg 5549 1.1 mrg /* Defining Data Structures for Per-function Information. */ 5551 1.1 mrg 5552 1.1 mrg 5553 1.1 mrg /* Storage Layout. */ 5555 1.1 mrg 5556 1.1 mrg #undef TARGET_PROMOTE_FUNCTION_MODE 5557 1.1 mrg #define TARGET_PROMOTE_FUNCTION_MODE \ 5558 1.1 mrg default_promote_function_mode_always_promote 5559 1.1 mrg 5560 1.1 mrg #undef TARGET_EXPAND_TO_RTL_HOOK 5561 1.1 mrg #define TARGET_EXPAND_TO_RTL_HOOK nds32_expand_to_rtl_hook 5562 1.1 mrg 5563 1.1 mrg #undef TARGET_CONSTANT_ALIGNMENT 5564 1.1 mrg #define TARGET_CONSTANT_ALIGNMENT nds32_constant_alignment 5565 1.1 mrg 5566 1.1 mrg 5567 1.1 mrg /* Layout of Source Language Data Types. */ 5569 1.1 mrg 5570 1.1 mrg 5571 1.1 mrg /* Register Usage. */ 5573 1.1 mrg 5574 1.1 mrg /* -- Basic Characteristics of Registers. */ 5575 1.1 mrg 5576 1.1 mrg #undef TARGET_CONDITIONAL_REGISTER_USAGE 5577 1.1 mrg #define TARGET_CONDITIONAL_REGISTER_USAGE nds32_conditional_register_usage 5578 1.1 mrg 5579 1.1 mrg /* -- Order of Allocation of Registers. */ 5580 1.1 mrg 5581 1.1 mrg /* -- How Values Fit in Registers. */ 5582 1.1 mrg 5583 1.1 mrg #undef TARGET_HARD_REGNO_NREGS 5584 1.1 mrg #define TARGET_HARD_REGNO_NREGS nds32_hard_regno_nregs 5585 1.1 mrg 5586 1.1 mrg #undef TARGET_HARD_REGNO_MODE_OK 5587 1.1 mrg #define TARGET_HARD_REGNO_MODE_OK nds32_hard_regno_mode_ok 5588 1.1 mrg 5589 1.1 mrg #undef TARGET_MODES_TIEABLE_P 5590 1.1 mrg #define TARGET_MODES_TIEABLE_P nds32_modes_tieable_p 5591 1.1 mrg 5592 1.1 mrg /* -- Handling Leaf Functions. */ 5593 1.1 mrg 5594 1.1 mrg /* -- Registers That Form a Stack. */ 5595 1.1 mrg 5596 1.1 mrg 5597 1.1 mrg /* Register Classes. */ 5599 1.1 mrg 5600 1.1 mrg #undef TARGET_CLASS_MAX_NREGS 5601 1.1 mrg #define TARGET_CLASS_MAX_NREGS nds32_class_max_nregs 5602 1.1 mrg 5603 1.1 mrg #undef TARGET_REGISTER_PRIORITY 5604 1.1 mrg #define TARGET_REGISTER_PRIORITY nds32_register_priority 5605 1.1 mrg 5606 1.1 mrg #undef TARGET_CAN_CHANGE_MODE_CLASS 5607 1.1 mrg #define TARGET_CAN_CHANGE_MODE_CLASS nds32_can_change_mode_class 5608 1.1 mrg 5609 1.1 mrg 5610 1.1 mrg /* Obsolete Macros for Defining Constraints. */ 5612 1.1 mrg 5613 1.1 mrg 5614 1.1 mrg /* Stack Layout and Calling Conventions. */ 5616 1.1 mrg 5617 1.1 mrg /* -- Basic Stack Layout. */ 5618 1.1 mrg 5619 1.1 mrg /* -- Exception Handling Support. */ 5620 1.1 mrg 5621 1.1 mrg /* -- Specifying How Stack Checking is Done. */ 5622 1.1 mrg 5623 1.1 mrg /* -- Registers That Address the Stack Frame. */ 5624 1.1 mrg 5625 1.1 mrg /* -- Eliminating Frame Pointer and Arg Pointer. */ 5626 1.1 mrg 5627 1.1 mrg #undef TARGET_CAN_ELIMINATE 5628 1.1 mrg #define TARGET_CAN_ELIMINATE nds32_can_eliminate 5629 1.1 mrg 5630 1.1 mrg /* -- Passing Function Arguments on the Stack. */ 5631 1.1 mrg 5632 1.1 mrg /* -- Passing Arguments in Registers. */ 5633 1.1 mrg 5634 1.1 mrg #undef TARGET_FUNCTION_ARG 5635 1.1 mrg #define TARGET_FUNCTION_ARG nds32_function_arg 5636 1.1 mrg 5637 1.1 mrg #undef TARGET_MUST_PASS_IN_STACK 5638 1.1 mrg #define TARGET_MUST_PASS_IN_STACK nds32_must_pass_in_stack 5639 1.1 mrg 5640 1.1 mrg #undef TARGET_ARG_PARTIAL_BYTES 5641 1.1 mrg #define TARGET_ARG_PARTIAL_BYTES nds32_arg_partial_bytes 5642 1.1 mrg 5643 1.1 mrg #undef TARGET_FUNCTION_ARG_ADVANCE 5644 1.1 mrg #define TARGET_FUNCTION_ARG_ADVANCE nds32_function_arg_advance 5645 1.1 mrg 5646 1.1 mrg #undef TARGET_FUNCTION_ARG_BOUNDARY 5647 1.1 mrg #define TARGET_FUNCTION_ARG_BOUNDARY nds32_function_arg_boundary 5648 1.1 mrg 5649 1.1 mrg #undef TARGET_VECTOR_MODE_SUPPORTED_P 5650 1.1 mrg #define TARGET_VECTOR_MODE_SUPPORTED_P nds32_vector_mode_supported_p 5651 1.1 mrg 5652 1.1 mrg /* -- How Scalar Function Values Are Returned. */ 5653 1.1 mrg 5654 1.1 mrg #undef TARGET_FUNCTION_VALUE 5655 1.1 mrg #define TARGET_FUNCTION_VALUE nds32_function_value 5656 1.1 mrg 5657 1.1 mrg #undef TARGET_LIBCALL_VALUE 5658 1.1 mrg #define TARGET_LIBCALL_VALUE nds32_libcall_value 5659 1.1 mrg 5660 1.1 mrg #undef TARGET_FUNCTION_VALUE_REGNO_P 5661 1.1 mrg #define TARGET_FUNCTION_VALUE_REGNO_P nds32_function_value_regno_p 5662 1.1 mrg 5663 1.1 mrg /* -- How Large Values Are Returned. */ 5664 1.1 mrg 5665 1.1 mrg #undef TARGET_RETURN_IN_MEMORY 5666 1.1 mrg #define TARGET_RETURN_IN_MEMORY nds32_return_in_memory 5667 1.1 mrg 5668 1.1 mrg /* -- Caller-Saves Register Allocation. */ 5669 1.1 mrg 5670 1.1 mrg /* -- Function Entry and Exit. */ 5671 1.1 mrg 5672 1.1 mrg #undef TARGET_ASM_FUNCTION_PROLOGUE 5673 1.1 mrg #define TARGET_ASM_FUNCTION_PROLOGUE nds32_asm_function_prologue 5674 1.1 mrg 5675 1.1 mrg #undef TARGET_ASM_FUNCTION_END_PROLOGUE 5676 1.1 mrg #define TARGET_ASM_FUNCTION_END_PROLOGUE nds32_asm_function_end_prologue 5677 1.1 mrg 5678 1.1 mrg #undef TARGET_ASM_FUNCTION_BEGIN_EPILOGUE 5679 1.1 mrg #define TARGET_ASM_FUNCTION_BEGIN_EPILOGUE nds32_asm_function_begin_epilogue 5680 1.1 mrg 5681 1.1 mrg #undef TARGET_ASM_FUNCTION_EPILOGUE 5682 1.1 mrg #define TARGET_ASM_FUNCTION_EPILOGUE nds32_asm_function_epilogue 5683 1.1 mrg 5684 1.1 mrg #undef TARGET_ASM_OUTPUT_MI_THUNK 5685 1.1 mrg #define TARGET_ASM_OUTPUT_MI_THUNK nds32_asm_output_mi_thunk 5686 1.1 mrg 5687 1.1 mrg #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK 5688 1.1 mrg #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall 5689 1.1 mrg 5690 1.1 mrg /* -- Generating Code for Profiling. */ 5691 1.1 mrg 5692 1.1 mrg /* -- Permitting tail calls. */ 5693 1.1 mrg 5694 1.1 mrg #undef TARGET_FUNCTION_OK_FOR_SIBCALL 5695 1.1 mrg #define TARGET_FUNCTION_OK_FOR_SIBCALL nds32_function_ok_for_sibcall 5696 1.1 mrg 5697 1.1 mrg #undef TARGET_WARN_FUNC_RETURN 5698 1.1 mrg #define TARGET_WARN_FUNC_RETURN nds32_warn_func_return 5699 1.1 mrg 5700 1.1 mrg /* Stack smashing protection. */ 5701 1.1 mrg 5702 1.1 mrg 5703 1.1 mrg /* Implementing the Varargs Macros. */ 5705 1.1 mrg 5706 1.1 mrg #undef TARGET_SETUP_INCOMING_VARARGS 5707 1.1 mrg #define TARGET_SETUP_INCOMING_VARARGS nds32_setup_incoming_varargs 5708 1.1 mrg 5709 1.1 mrg #undef TARGET_STRICT_ARGUMENT_NAMING 5710 1.1 mrg #define TARGET_STRICT_ARGUMENT_NAMING nds32_strict_argument_naming 5711 1.1 mrg 5712 1.1 mrg 5713 1.1 mrg /* Trampolines for Nested Functions. */ 5715 1.1 mrg 5716 1.1 mrg #undef TARGET_ASM_TRAMPOLINE_TEMPLATE 5717 1.1 mrg #define TARGET_ASM_TRAMPOLINE_TEMPLATE nds32_asm_trampoline_template 5718 1.1 mrg 5719 1.1 mrg #undef TARGET_TRAMPOLINE_INIT 5720 1.1 mrg #define TARGET_TRAMPOLINE_INIT nds32_trampoline_init 5721 1.1 mrg 5722 1.1 mrg 5723 1.1 mrg /* Implicit Calls to Library Routines. */ 5725 1.1 mrg 5726 1.1 mrg 5727 1.1 mrg /* Addressing Modes. */ 5729 1.1 mrg 5730 1.1 mrg #undef TARGET_LEGITIMATE_ADDRESS_P 5731 1.1 mrg #define TARGET_LEGITIMATE_ADDRESS_P nds32_legitimate_address_p 5732 1.1 mrg 5733 1.1 mrg #undef TARGET_LEGITIMIZE_ADDRESS 5734 1.1 mrg #define TARGET_LEGITIMIZE_ADDRESS nds32_legitimize_address 5735 1.1 mrg 5736 1.1 mrg #undef TARGET_LEGITIMATE_CONSTANT_P 5737 1.1 mrg #define TARGET_LEGITIMATE_CONSTANT_P nds32_legitimate_constant_p 5738 1.1 mrg 5739 1.1 mrg #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE 5740 1.1 mrg #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE nds32_vectorize_preferred_simd_mode 5741 1.1 mrg 5742 1.1 mrg #undef TARGET_CANNOT_FORCE_CONST_MEM 5743 1.1 mrg #define TARGET_CANNOT_FORCE_CONST_MEM nds32_cannot_force_const_mem 5744 1.1 mrg 5745 1.1 mrg #undef TARGET_DELEGITIMIZE_ADDRESS 5746 1.1 mrg #define TARGET_DELEGITIMIZE_ADDRESS nds32_delegitimize_address 5747 1.1 mrg 5748 1.1 mrg 5749 1.1 mrg /* Anchored Addresses. */ 5751 1.1 mrg 5752 1.1 mrg 5753 1.1 mrg /* Condition Code Status. */ 5755 1.1 mrg 5756 1.1 mrg /* -- Representation of condition codes using (cc0). */ 5757 1.1 mrg 5758 1.1 mrg /* -- Representation of condition codes using registers. */ 5759 1.1 mrg 5760 1.1 mrg #undef TARGET_CANONICALIZE_COMPARISON 5761 1.1 mrg #define TARGET_CANONICALIZE_COMPARISON nds32_canonicalize_comparison 5762 1.1 mrg 5763 1.1 mrg /* -- Macros to control conditional execution. */ 5764 1.1 mrg 5765 1.1 mrg 5766 1.1 mrg /* Describing Relative Costs of Operations. */ 5768 1.1 mrg 5769 1.1 mrg #undef TARGET_REGISTER_MOVE_COST 5770 1.1 mrg #define TARGET_REGISTER_MOVE_COST nds32_register_move_cost 5771 1.1 mrg 5772 1.1 mrg #undef TARGET_MEMORY_MOVE_COST 5773 1.1 mrg #define TARGET_MEMORY_MOVE_COST nds32_memory_move_cost 5774 1.1 mrg 5775 1.1 mrg #undef TARGET_RTX_COSTS 5776 1.1 mrg #define TARGET_RTX_COSTS nds32_rtx_costs 5777 1.1 mrg 5778 1.1 mrg #undef TARGET_ADDRESS_COST 5779 1.1 mrg #define TARGET_ADDRESS_COST nds32_address_cost 5780 1.1 mrg 5781 1.1 mrg 5782 1.1 mrg /* Adjusting the Instruction Scheduler. */ 5784 1.1 mrg 5785 1.1 mrg 5786 1.1 mrg /* Dividing the Output into Sections (Texts, Data, . . . ). */ 5788 1.1 mrg 5789 1.1 mrg #undef TARGET_ENCODE_SECTION_INFO 5790 1.1 mrg #define TARGET_ENCODE_SECTION_INFO nds32_encode_section_info 5791 1.1 mrg 5792 1.1 mrg 5793 1.1 mrg /* Position Independent Code. */ 5795 1.1 mrg 5796 1.1 mrg 5797 1.1 mrg /* Defining the Output Assembler Language. */ 5799 1.1 mrg 5800 1.1 mrg /* -- The Overall Framework of an Assembler File. */ 5801 1.1 mrg 5802 1.1 mrg #undef TARGET_ASM_FILE_START 5803 1.1 mrg #define TARGET_ASM_FILE_START nds32_asm_file_start 5804 1.1 mrg #undef TARGET_ASM_FILE_END 5805 1.1 mrg #define TARGET_ASM_FILE_END nds32_asm_file_end 5806 1.1 mrg 5807 1.1 mrg /* -- Output of Data. */ 5808 1.1 mrg 5809 1.1 mrg #undef TARGET_ASM_ALIGNED_HI_OP 5810 1.1 mrg #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t" 5811 1.1 mrg 5812 1.1 mrg #undef TARGET_ASM_ALIGNED_SI_OP 5813 1.1 mrg #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t" 5814 1.1 mrg 5815 1.1 mrg #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA 5816 1.1 mrg #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA nds32_asm_output_addr_const_extra 5817 1.1 mrg 5818 1.1 mrg /* -- Output of Uninitialized Variables. */ 5819 1.1 mrg 5820 1.1 mrg /* -- Output and Generation of Labels. */ 5821 1.1 mrg 5822 1.1 mrg #undef TARGET_ASM_GLOBALIZE_LABEL 5823 1.1 mrg #define TARGET_ASM_GLOBALIZE_LABEL nds32_asm_globalize_label 5824 1.1 mrg 5825 1.1 mrg /* -- How Initialization Functions Are Handled. */ 5826 1.1 mrg 5827 1.1 mrg /* -- Macros Controlling Initialization Routines. */ 5828 1.1 mrg 5829 1.1 mrg /* -- Output of Assembler Instructions. */ 5830 1.1 mrg 5831 1.1 mrg #undef TARGET_PRINT_OPERAND 5832 1.1 mrg #define TARGET_PRINT_OPERAND nds32_print_operand 5833 1.1 mrg #undef TARGET_PRINT_OPERAND_ADDRESS 5834 1.1 mrg #define TARGET_PRINT_OPERAND_ADDRESS nds32_print_operand_address 5835 1.1 mrg 5836 1.1 mrg /* -- Output of Dispatch Tables. */ 5837 1.1 mrg 5838 1.1 mrg /* -- Assembler Commands for Exception Regions. */ 5839 1.1 mrg 5840 1.1 mrg #undef TARGET_DWARF_REGISTER_SPAN 5841 1.1 mrg #define TARGET_DWARF_REGISTER_SPAN nds32_dwarf_register_span 5842 1.1 mrg 5843 1.1 mrg /* -- Assembler Commands for Alignment. */ 5844 1.1 mrg 5845 1.1 mrg 5846 1.1 mrg /* Controlling Debugging Information Format. */ 5848 1.1 mrg 5849 1.1 mrg /* -- Macros Affecting All Debugging Formats. */ 5850 1.1 mrg 5851 1.1 mrg /* -- Specific Options for DBX Output. */ 5852 1.1 mrg 5853 1.1 mrg /* -- Open-Ended Hooks for DBX Format. */ 5854 1.1 mrg 5855 1.1 mrg /* -- File Names in DBX Format. */ 5856 1.1 mrg 5857 1.1 mrg /* -- Macros for DWARF Output. */ 5858 1.1 mrg 5859 1.1 mrg /* -- Macros for VMS Debug Format. */ 5860 1.1 mrg 5861 1.1 mrg 5862 1.1 mrg /* Cross Compilation and Floating Point. */ 5864 1.1 mrg 5865 1.1 mrg 5866 1.1 mrg /* Mode Switching Instructions. */ 5868 1.1 mrg 5869 1.1 mrg 5870 1.1 mrg /* Defining target-specific uses of __attribute__. */ 5872 1.1 mrg 5873 1.1 mrg #undef TARGET_ATTRIBUTE_TABLE 5874 1.1 mrg #define TARGET_ATTRIBUTE_TABLE nds32_attribute_table 5875 1.1 mrg 5876 1.1 mrg #undef TARGET_MERGE_DECL_ATTRIBUTES 5877 1.1 mrg #define TARGET_MERGE_DECL_ATTRIBUTES nds32_merge_decl_attributes 5878 1.1 mrg 5879 1.1 mrg #undef TARGET_INSERT_ATTRIBUTES 5880 1.1 mrg #define TARGET_INSERT_ATTRIBUTES nds32_insert_attributes 5881 1.1 mrg 5882 1.1 mrg #undef TARGET_OPTION_PRAGMA_PARSE 5883 1.1 mrg #define TARGET_OPTION_PRAGMA_PARSE nds32_option_pragma_parse 5884 1.1 mrg 5885 1.1 mrg #undef TARGET_OPTION_OVERRIDE 5886 1.1 mrg #define TARGET_OPTION_OVERRIDE nds32_option_override 5887 1.1 mrg 5888 1.1 mrg 5889 1.1 mrg /* Emulating TLS. */ 5891 1.1 mrg 5892 1.1 mrg #undef TARGET_HAVE_TLS 5893 1.1 mrg #define TARGET_HAVE_TLS TARGET_LINUX_ABI 5894 1.1 mrg 5895 1.1 mrg 5896 /* Defining coprocessor specifics for MIPS targets. */ 5898 5899 5900 /* Parameters for Precompiled Header Validity Checking. */ 5902 5903 5904 /* C++ ABI parameters. */ 5906 5907 5908 /* Adding support for named address spaces. */ 5910 5911 5912 /* Miscellaneous Parameters. */ 5914 5915 #undef TARGET_MD_ASM_ADJUST 5916 #define TARGET_MD_ASM_ADJUST nds32_md_asm_adjust 5917 5918 #undef TARGET_INIT_BUILTINS 5919 #define TARGET_INIT_BUILTINS nds32_init_builtins 5920 5921 #undef TARGET_BUILTIN_DECL 5922 #define TARGET_BUILTIN_DECL nds32_builtin_decl 5923 5924 #undef TARGET_EXPAND_BUILTIN 5925 #define TARGET_EXPAND_BUILTIN nds32_expand_builtin 5926 5927 #undef TARGET_INIT_LIBFUNCS 5928 #define TARGET_INIT_LIBFUNCS nds32_init_libfuncs 5929 5930 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P 5931 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P nds32_use_blocks_for_constant_p 5932 5933 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE 5934 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed 5935 5936 5937 /* ------------------------------------------------------------------------ */ 5939 5940 /* Initialize the GCC target structure. */ 5941 5942 struct gcc_target targetm = TARGET_INITIALIZER; 5943 5944 /* ------------------------------------------------------------------------ */ 5945