Home | History | Annotate | Line # | Download | only in pdp11
pdp11.cc revision 1.1
      1 /* Subroutines for gcc2 for pdp11.
      2    Copyright (C) 1994-2022 Free Software Foundation, Inc.
      3    Contributed by Michael K. Gschwind (mike (at) vlsivie.tuwien.ac.at).
      4 
      5 This file is part of GCC.
      6 
      7 GCC is free software; you can redistribute it and/or modify
      8 it under the terms of the GNU General Public License as published by
      9 the Free Software Foundation; either version 3, or (at your option)
     10 any later version.
     11 
     12 GCC is distributed in the hope that it will be useful,
     13 but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 GNU General Public License for more details.
     16 
     17 You should have received a copy of the GNU General Public License
     18 along with GCC; see the file COPYING3.  If not see
     19 <http://www.gnu.org/licenses/>.  */
     20 
     21 #define IN_TARGET_CODE 1
     22 
     23 #include "config.h"
     24 #include "system.h"
     25 #include "coretypes.h"
     26 #include "backend.h"
     27 #include "target.h"
     28 #include "rtl.h"
     29 #include "tree.h"
     30 #include "stringpool.h"
     31 #include "attribs.h"
     32 #include "df.h"
     33 #include "memmodel.h"
     34 #include "tm_p.h"
     35 #include "insn-config.h"
     36 #include "insn-attr.h"
     37 #include "regs.h"
     38 #include "emit-rtl.h"
     39 #include "recog.h"
     40 #include "conditions.h"
     41 #include "output.h"
     42 #include "stor-layout.h"
     43 #include "varasm.h"
     44 #include "calls.h"
     45 #include "expr.h"
     46 #include "builtins.h"
     47 #include "dbxout.h"
     48 #include "explow.h"
     49 #include "expmed.h"
     50 
     51 /* This file should be included last.  */
     52 #include "target-def.h"
     53 
     54 /* this is the current value returned by the macro FIRST_PARM_OFFSET
     55    defined in tm.h */
     56 int current_first_parm_offset;
     57 
     58 /* Routines to encode/decode pdp11 floats */
     59 static void encode_pdp11_f (const struct real_format *fmt,
     60 			    long *, const REAL_VALUE_TYPE *);
     61 static void decode_pdp11_f (const struct real_format *,
     62 			    REAL_VALUE_TYPE *, const long *);
     63 static void encode_pdp11_d (const struct real_format *fmt,
     64 			    long *, const REAL_VALUE_TYPE *);
     65 static void decode_pdp11_d (const struct real_format *,
     66 			    REAL_VALUE_TYPE *, const long *);
     67 
     68 /* These two are taken from the corresponding vax descriptors
     69    in real.cc, changing only the encode/decode routine pointers.  */
     70 const struct real_format pdp11_f_format =
     71   {
     72     encode_pdp11_f,
     73     decode_pdp11_f,
     74     2,
     75     24,
     76     24,
     77     -127,
     78     127,
     79     15,
     80     15,
     81     0,
     82     false,
     83     false,
     84     false,
     85     false,
     86     false,
     87     false,
     88     false,
     89     false,
     90     "pdp11_f"
     91   };
     92 
     93 const struct real_format pdp11_d_format =
     94   {
     95     encode_pdp11_d,
     96     decode_pdp11_d,
     97     2,
     98     56,
     99     56,
    100     -127,
    101     127,
    102     15,
    103     15,
    104     0,
    105     false,
    106     false,
    107     false,
    108     false,
    109     false,
    110     false,
    111     false,
    112     false,
    113     "pdp11_d"
    114   };
    115 
    116 static void
    117 encode_pdp11_f (const struct real_format *fmt ATTRIBUTE_UNUSED, long *buf,
    118 		const REAL_VALUE_TYPE *r)
    119 {
    120   (*vax_f_format.encode) (fmt, buf, r);
    121   buf[0] = ((buf[0] >> 16) & 0xffff) | ((buf[0] & 0xffff) << 16);
    122 }
    123 
    124 static void
    125 decode_pdp11_f (const struct real_format *fmt ATTRIBUTE_UNUSED,
    126 		REAL_VALUE_TYPE *r, const long *buf)
    127 {
    128   long tbuf;
    129   tbuf = ((buf[0] >> 16) & 0xffff) | ((buf[0] & 0xffff) << 16);
    130   (*vax_f_format.decode) (fmt, r, &tbuf);
    131 }
    132 
    133 static void
    134 encode_pdp11_d (const struct real_format *fmt ATTRIBUTE_UNUSED, long *buf,
    135 		const REAL_VALUE_TYPE *r)
    136 {
    137   (*vax_d_format.encode) (fmt, buf, r);
    138   buf[0] = ((buf[0] >> 16) & 0xffff) | ((buf[0] & 0xffff) << 16);
    139   buf[1] = ((buf[1] >> 16) & 0xffff) | ((buf[1] & 0xffff) << 16);
    140 }
    141 
    142 static void
    143 decode_pdp11_d (const struct real_format *fmt ATTRIBUTE_UNUSED,
    144 		REAL_VALUE_TYPE *r, const long *buf)
    145 {
    146   long tbuf[2];
    147   tbuf[0] = ((buf[0] >> 16) & 0xffff) | ((buf[0] & 0xffff) << 16);
    148   tbuf[1] = ((buf[1] >> 16) & 0xffff) | ((buf[1] & 0xffff) << 16);
    149   (*vax_d_format.decode) (fmt, r, tbuf);
    150 }
    151 
    152 static const char *singlemove_string (rtx *);
    153 static bool pdp11_assemble_integer (rtx, unsigned int, int);
    154 static bool pdp11_rtx_costs (rtx, machine_mode, int, int, int *, bool);
    155 static int pdp11_addr_cost (rtx, machine_mode, addr_space_t, bool);
    156 static int pdp11_insn_cost (rtx_insn *insn, bool speed);
    157 static rtx_insn *pdp11_md_asm_adjust (vec<rtx> &, vec<rtx> &,
    158 				      vec<machine_mode> &, vec<const char *> &,
    159 				      vec<rtx> &, HARD_REG_SET &, location_t);
    160 static bool pdp11_return_in_memory (const_tree, const_tree);
    161 static rtx pdp11_function_value (const_tree, const_tree, bool);
    162 static rtx pdp11_libcall_value (machine_mode, const_rtx);
    163 static bool pdp11_function_value_regno_p (const unsigned int);
    164 static void pdp11_trampoline_init (rtx, tree, rtx);
    165 static rtx pdp11_function_arg (cumulative_args_t, const function_arg_info &);
    166 static void pdp11_function_arg_advance (cumulative_args_t,
    167 					const function_arg_info &);
    168 static void pdp11_conditional_register_usage (void);
    169 static bool pdp11_legitimate_constant_p (machine_mode, rtx);
    170 
    171 static bool pdp11_scalar_mode_supported_p (scalar_mode);
    172 
    173 /* Initialize the GCC target structure.  */
    175 #undef TARGET_ASM_BYTE_OP
    176 #define TARGET_ASM_BYTE_OP NULL
    177 #undef TARGET_ASM_ALIGNED_HI_OP
    178 #define TARGET_ASM_ALIGNED_HI_OP NULL
    179 #undef TARGET_ASM_ALIGNED_SI_OP
    180 #define TARGET_ASM_ALIGNED_SI_OP NULL
    181 #undef TARGET_ASM_INTEGER
    182 #define TARGET_ASM_INTEGER pdp11_assemble_integer
    183 
    184 /* These two apply to Unix and GNU assembler; for DEC, they are
    185    overridden during option processing.  */
    186 #undef TARGET_ASM_OPEN_PAREN
    187 #define TARGET_ASM_OPEN_PAREN "["
    188 #undef TARGET_ASM_CLOSE_PAREN
    189 #define TARGET_ASM_CLOSE_PAREN "]"
    190 
    191 #undef TARGET_RTX_COSTS
    192 #define TARGET_RTX_COSTS pdp11_rtx_costs
    193 
    194 #undef  TARGET_ADDRESS_COST
    195 #define TARGET_ADDRESS_COST pdp11_addr_cost
    196 
    197 #undef  TARGET_INSN_COST
    198 #define TARGET_INSN_COST pdp11_insn_cost
    199 
    200 #undef  TARGET_MD_ASM_ADJUST
    201 #define TARGET_MD_ASM_ADJUST pdp11_md_asm_adjust
    202 
    203 #undef TARGET_FUNCTION_ARG
    204 #define TARGET_FUNCTION_ARG pdp11_function_arg
    205 #undef TARGET_FUNCTION_ARG_ADVANCE
    206 #define TARGET_FUNCTION_ARG_ADVANCE pdp11_function_arg_advance
    207 
    208 #undef TARGET_RETURN_IN_MEMORY
    209 #define TARGET_RETURN_IN_MEMORY pdp11_return_in_memory
    210 
    211 #undef TARGET_FUNCTION_VALUE
    212 #define TARGET_FUNCTION_VALUE pdp11_function_value
    213 #undef TARGET_LIBCALL_VALUE
    214 #define TARGET_LIBCALL_VALUE pdp11_libcall_value
    215 #undef TARGET_FUNCTION_VALUE_REGNO_P
    216 #define TARGET_FUNCTION_VALUE_REGNO_P pdp11_function_value_regno_p
    217 
    218 #undef TARGET_TRAMPOLINE_INIT
    219 #define TARGET_TRAMPOLINE_INIT pdp11_trampoline_init
    220 
    221 #undef  TARGET_SECONDARY_RELOAD
    222 #define TARGET_SECONDARY_RELOAD pdp11_secondary_reload
    223 
    224 #undef  TARGET_REGISTER_MOVE_COST
    225 #define TARGET_REGISTER_MOVE_COST pdp11_register_move_cost
    226 
    227 #undef  TARGET_PREFERRED_RELOAD_CLASS
    228 #define TARGET_PREFERRED_RELOAD_CLASS pdp11_preferred_reload_class
    229 
    230 #undef  TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
    231 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS pdp11_preferred_output_reload_class
    232 
    233 #undef  TARGET_LRA_P
    234 #define TARGET_LRA_P pdp11_lra_p
    235 
    236 #undef  TARGET_LEGITIMATE_ADDRESS_P
    237 #define TARGET_LEGITIMATE_ADDRESS_P pdp11_legitimate_address_p
    238 
    239 #undef  TARGET_CONDITIONAL_REGISTER_USAGE
    240 #define TARGET_CONDITIONAL_REGISTER_USAGE pdp11_conditional_register_usage
    241 
    242 #undef  TARGET_OPTION_OVERRIDE
    243 #define TARGET_OPTION_OVERRIDE pdp11_option_override
    244 
    245 #undef  TARGET_ASM_FILE_START_FILE_DIRECTIVE
    246 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
    247 
    248 #undef  TARGET_ASM_OUTPUT_IDENT
    249 #define TARGET_ASM_OUTPUT_IDENT pdp11_output_ident
    250 
    251 #undef  TARGET_ASM_FUNCTION_SECTION
    252 #define TARGET_ASM_FUNCTION_SECTION pdp11_function_section
    253 
    254 #undef  TARGET_ASM_NAMED_SECTION
    255 #define	TARGET_ASM_NAMED_SECTION pdp11_asm_named_section
    256 
    257 #undef  TARGET_ASM_INIT_SECTIONS
    258 #define TARGET_ASM_INIT_SECTIONS pdp11_asm_init_sections
    259 
    260 #undef  TARGET_ASM_FILE_START
    261 #define TARGET_ASM_FILE_START pdp11_file_start
    262 
    263 #undef  TARGET_ASM_FILE_END
    264 #define TARGET_ASM_FILE_END pdp11_file_end
    265 
    266 #undef  TARGET_PRINT_OPERAND
    267 #define TARGET_PRINT_OPERAND pdp11_asm_print_operand
    268 
    269 #undef  TARGET_PRINT_OPERAND_PUNCT_VALID_P
    270 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P pdp11_asm_print_operand_punct_valid_p
    271 
    272 #undef  TARGET_LEGITIMATE_CONSTANT_P
    273 #define TARGET_LEGITIMATE_CONSTANT_P pdp11_legitimate_constant_p
    274 
    275 #undef  TARGET_SCALAR_MODE_SUPPORTED_P
    276 #define TARGET_SCALAR_MODE_SUPPORTED_P pdp11_scalar_mode_supported_p
    277 
    278 #undef  TARGET_HARD_REGNO_NREGS
    279 #define TARGET_HARD_REGNO_NREGS pdp11_hard_regno_nregs
    280 
    281 #undef  TARGET_HARD_REGNO_MODE_OK
    282 #define TARGET_HARD_REGNO_MODE_OK pdp11_hard_regno_mode_ok
    283 
    284 #undef  TARGET_MODES_TIEABLE_P
    285 #define TARGET_MODES_TIEABLE_P pdp11_modes_tieable_p
    286 
    287 #undef  TARGET_SECONDARY_MEMORY_NEEDED
    288 #define TARGET_SECONDARY_MEMORY_NEEDED pdp11_secondary_memory_needed
    289 
    290 #undef  TARGET_CAN_CHANGE_MODE_CLASS
    291 #define TARGET_CAN_CHANGE_MODE_CLASS pdp11_can_change_mode_class
    292 
    293 #undef TARGET_INVALID_WITHIN_DOLOOP
    294 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_const_rtx_insn_null
    295 
    296 #undef  TARGET_CXX_GUARD_TYPE
    297 #define TARGET_CXX_GUARD_TYPE pdp11_guard_type
    298 
    299 #undef  TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT
    300 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT hook_bool_void_false
    301 
    302 #undef  TARGET_CXX_LIBRARY_RTTI_COMDAT
    303 #define TARGET_CXX_LIBRARY_RTTI_COMDAT hook_bool_void_false
    304 
    305 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
    306 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
    307 
    308 #undef  TARGET_STACK_PROTECT_RUNTIME_ENABLED_P
    309 #define TARGET_STACK_PROTECT_RUNTIME_ENABLED_P hook_bool_void_false
    310 
    311 /* A helper function to determine if REGNO should be saved in the
    313    current function's stack frame.  */
    314 
    315 static inline bool
    316 pdp11_saved_regno (unsigned regno)
    317 {
    318   return !call_used_or_fixed_reg_p (regno) && df_regs_ever_live_p (regno);
    319 }
    320 
    321 /* Expand the function prologue.  */
    322 
    323 /* Frame layout, from high to low memory (stack push order):
    324    return address (from jsr instruction)
    325    saved CPU registers, lowest number first
    326    saved FPU registers, lowest number first, always 64 bit mode
    327    *** frame pointer points here ***
    328    local variables
    329    alloca storage if any.  */
    330 void
    331 pdp11_expand_prologue (void)
    332 {
    333   HOST_WIDE_INT fsize = get_frame_size ();
    334   unsigned regno;
    335   rtx x, via_ac = NULL;
    336 
    337   /* If we are outputting code for main, the switch FPU to the
    338      right mode if TARGET_FPU.  */
    339   if (MAIN_NAME_P (DECL_NAME (current_function_decl)) && TARGET_FPU)
    340     {
    341       emit_insn (gen_setd ());
    342       emit_insn (gen_seti ());
    343     }
    344 
    345   /* Save CPU registers.  */
    346   for (regno = R0_REGNUM; regno <= PC_REGNUM; regno++)
    347     if (pdp11_saved_regno (regno))
    348       {
    349 	x = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx);
    350 	x = gen_frame_mem (Pmode, x);
    351 	emit_move_insn (x, gen_rtx_REG (Pmode, regno));
    352       }
    353 
    354   /* Save FPU registers.  */
    355   for (regno = AC0_REGNUM; regno <= AC3_REGNUM; regno++)
    356     if (pdp11_saved_regno (regno))
    357       {
    358 	x = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx);
    359 	x = gen_frame_mem (DFmode, x);
    360 	via_ac = gen_rtx_REG (DFmode, regno);
    361 	emit_move_insn (x, via_ac);
    362       }
    363 
    364   /* ??? Maybe make ac4, ac5 call used regs?? */
    365   for (regno = AC4_REGNUM; regno <= AC5_REGNUM; regno++)
    366     if (pdp11_saved_regno (regno))
    367       {
    368 	gcc_assert (via_ac != NULL);
    369 	emit_move_insn (via_ac, gen_rtx_REG (DFmode, regno));
    370 
    371 	x = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx);
    372 	x = gen_frame_mem (DFmode, x);
    373 	emit_move_insn (x, via_ac);
    374       }
    375 
    376   if (frame_pointer_needed)
    377     emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
    378 
    379   /* Make local variable space.  */
    380   if (fsize)
    381     emit_insn (gen_addhi3 (stack_pointer_rtx, stack_pointer_rtx,
    382 			   GEN_INT (-fsize)));
    383 }
    384 
    385 /* Generate epilogue.  This uses the frame pointer to pop the local
    386    variables and any alloca data off the stack.  If there is no alloca
    387    and frame pointer elimination hasn't been disabled, there is no
    388    frame pointer and the local variables are popped by adjusting the
    389    stack pointer instead.  */
    390 
    391 void
    392 pdp11_expand_epilogue (void)
    393 {
    394   HOST_WIDE_INT fsize = get_frame_size ();
    395   unsigned regno;
    396   rtx x, reg, via_ac = NULL;
    397 
    398   /* Deallocate the local variables.  */
    399   if (fsize)
    400     {
    401       if (frame_pointer_needed)
    402 	{
    403 	  /* We can deallocate the frame with a single move.  */
    404 	  emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
    405 	}
    406       else
    407 	emit_insn (gen_addhi3 (stack_pointer_rtx, stack_pointer_rtx,
    408 			       GEN_INT (fsize)));
    409     }
    410 
    411   /* Restore the FPU registers.  */
    412   if (pdp11_saved_regno (AC4_REGNUM) || pdp11_saved_regno (AC5_REGNUM))
    413     {
    414       /* Find a temporary with which to restore AC4/5.  */
    415       for (regno = AC0_REGNUM; regno <= AC3_REGNUM; regno++)
    416 	if (pdp11_saved_regno (regno))
    417 	  {
    418 	    via_ac = gen_rtx_REG (DFmode, regno);
    419 	    break;
    420 	  }
    421     }
    422 
    423   /* Restore registers via pops.  */
    424 
    425   for (regno = AC5_REGNUM; regno >= AC0_REGNUM; regno--)
    426     if (pdp11_saved_regno (regno))
    427       {
    428 	x = gen_rtx_POST_INC (Pmode, stack_pointer_rtx);
    429 	x = gen_frame_mem (DFmode, x);
    430 	reg = gen_rtx_REG (DFmode, regno);
    431 
    432 	if (LOAD_FPU_REG_P (regno))
    433 	  emit_move_insn (reg, x);
    434 	else
    435 	  {
    436 	    emit_move_insn (via_ac, x);
    437 	    emit_move_insn (reg, via_ac);
    438 	  }
    439       }
    440 
    441   for (regno = PC_REGNUM; regno >= R0_REGNUM + 2; regno--)
    442     if (pdp11_saved_regno (regno))
    443       {
    444 	x = gen_rtx_POST_INC (Pmode, stack_pointer_rtx);
    445 	x = gen_frame_mem (Pmode, x);
    446 	emit_move_insn (gen_rtx_REG (Pmode, regno), x);
    447       }
    448 
    449   emit_jump_insn (gen_rtspc ());
    450 }
    451 
    452 /* Return the best assembler insn template
    453    for moving operands[1] into operands[0] as a fullword.  */
    454 static const char *
    455 singlemove_string (rtx *operands)
    456 {
    457   if (operands[1] != const0_rtx)
    458     return "mov\t%1,%0";
    459 
    460   return "clr\t%0";
    461 }
    462 
    463 
    464 /* Expand multi-word operands (SImode or DImode) into the 2 or 4
    466    corresponding HImode operands.  The number of operands is given as
    467    the third argument, the word count for the mode as the fourth
    468    argument, and the required order of parts as the sixth argument.
    469    The word count is explicit because sometimes we're asked to compare
    470    two constants, both of which have mode VOIDmode, so we can't always
    471    rely on the input operand mode to imply the operand size.  */
    472 bool
    473 pdp11_expand_operands (rtx *operands, rtx exops[][2],
    474 		       int opcount, int words,
    475 		       pdp11_action *action, pdp11_partorder order)
    476 {
    477   int op, w, i, sh;
    478   pdp11_partorder useorder;
    479   bool sameoff = false;
    480   enum { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype;
    481   long sval[2];
    482 
    483   /* If either piece order is accepted and one is pre-decrement
    484      while the other is post-increment, set order to be high order
    485      word first.  That will force the pre-decrement to be turned
    486      into a pointer adjust, then offset addressing.
    487      Otherwise, if either operand uses pre-decrement, that means
    488      the order is low order first.
    489      Otherwise, if both operands are registers and destination is
    490      higher than source and they overlap, do low order word (highest
    491      register number) first.  */
    492   useorder = either;
    493   if (opcount == 2)
    494     {
    495       if (GET_CODE (operands[0]) == MEM &&
    496 	  GET_CODE (operands[1]) == MEM &&
    497 	  ((GET_CODE (XEXP (operands[0], 0)) == POST_INC &&
    498 	    GET_CODE (XEXP (operands[1], 0)) == PRE_DEC) ||
    499 	   (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC &&
    500 	    GET_CODE (XEXP (operands[1], 0)) == POST_INC)))
    501 	    useorder = big;
    502       else if ((GET_CODE (operands[0]) == MEM &&
    503 		GET_CODE (XEXP (operands[0], 0)) == PRE_DEC) ||
    504 	       (GET_CODE (operands[1]) == MEM &&
    505 		GET_CODE (XEXP (operands[1], 0)) == PRE_DEC))
    506 	useorder = little;
    507       else if (REG_P (operands[0]) && REG_P (operands[1]) &&
    508 	       REGNO (operands[0]) > REGNO (operands[1]) &&
    509 	       REGNO (operands[0]) < REGNO (operands[1]) + words)
    510 	    useorder = little;
    511 
    512       /* Check for source == offset from register and dest == push of
    513 	 the same register.  In that case, we have to use the same
    514 	 offset (the one for the low order word) for all words, because
    515 	 the push increases the offset to each source word.
    516 	 In theory there are other cases like this, for example dest == pop,
    517 	 but those don't occur in real life so ignore those.  */
    518       if (GET_CODE (operands[0]) ==  MEM
    519 	  && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
    520 	  && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
    521 	  && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
    522 	sameoff = true;
    523     }
    524 
    525   /* If the caller didn't specify order, use the one we computed,
    526      or high word first if we don't care either.  If the caller did
    527      specify, verify we don't have a problem with that order.
    528      (If it matters to the caller, constraints need to be used to
    529      ensure this case doesn't occur).  */
    530   if (order == either)
    531     order = (useorder == either) ? big : useorder;
    532   else
    533     gcc_assert (useorder == either || useorder == order);
    534 
    535 
    536   for (op = 0; op < opcount; op++)
    537     {
    538       /* First classify the operand.  */
    539       if (REG_P (operands[op]))
    540 	optype = REGOP;
    541       else if (CONST_INT_P (operands[op])
    542 	       || GET_CODE (operands[op]) == CONST_DOUBLE)
    543 	optype = CNSTOP;
    544       else if (GET_CODE (XEXP (operands[op], 0)) == POST_INC)
    545 	optype = POPOP;
    546       else if (GET_CODE (XEXP (operands[op], 0)) == PRE_DEC)
    547 	optype = PUSHOP;
    548       else if (!reload_in_progress || offsettable_memref_p (operands[op]))
    549 	optype = OFFSOP;
    550       else if (GET_CODE (operands[op]) == MEM)
    551 	optype = MEMOP;
    552       else
    553 	optype = RNDOP;
    554 
    555       /* Check for the cases that the operand constraints are not
    556 	 supposed to allow to happen. Return failure for such cases.  */
    557       if (optype == RNDOP)
    558 	return false;
    559 
    560       if (action != NULL)
    561 	action[op] = no_action;
    562 
    563       /* If the operand uses pre-decrement addressing but we
    564 	 want to get the parts high order first,
    565 	 decrement the former register explicitly
    566 	 and change the operand into ordinary indexing.  */
    567       if (optype == PUSHOP && order == big)
    568 	{
    569 	  gcc_assert (action != NULL);
    570 	  action[op] = dec_before;
    571 	  operands[op] = gen_rtx_MEM (GET_MODE (operands[op]),
    572 				      XEXP (XEXP (operands[op], 0), 0));
    573 	  optype = OFFSOP;
    574 	}
    575       /* If the operand uses post-increment mode but we want
    576 	 to get the parts low order first, change the operand
    577 	 into ordinary indexing and remember to increment
    578 	 the register explicitly when we're done.  */
    579       else if (optype == POPOP && order == little)
    580 	{
    581 	  gcc_assert (action != NULL);
    582 	  action[op] = inc_after;
    583 	  operands[op] = gen_rtx_MEM (GET_MODE (operands[op]),
    584 				      XEXP (XEXP (operands[op], 0), 0));
    585 	  optype = OFFSOP;
    586 	}
    587 
    588       if (GET_CODE (operands[op]) == CONST_DOUBLE)
    589 	{
    590 	  gcc_assert (GET_MODE (operands[op]) != VOIDmode);
    591 	  REAL_VALUE_TO_TARGET_DOUBLE
    592 	    (*CONST_DOUBLE_REAL_VALUE (operands[op]), sval);
    593 	}
    594 
    595       for (i = 0; i < words; i++)
    596 	{
    597 	  if (order == big)
    598 	    w = i;
    599 	  else if (sameoff)
    600 	    w = words - 1;
    601 	  else
    602 	    w = words - 1 - i;
    603 
    604 	  /* Set the output operand to be word "w" of the input.  */
    605 	  if (optype == REGOP)
    606 	    exops[i][op] = gen_rtx_REG (HImode, REGNO (operands[op]) + w);
    607 	  else if (optype == OFFSOP)
    608 	    exops[i][op] = adjust_address (operands[op], HImode, w * 2);
    609 	  else if (optype == CNSTOP)
    610 	    {
    611 	      if (GET_CODE (operands[op]) == CONST_DOUBLE)
    612 		{
    613 		  sh = 16 - (w & 1) * 16;
    614 		  exops[i][op] = gen_rtx_CONST_INT (HImode, (sval[w / 2] >> sh) & 0xffff);
    615 		}
    616 	      else
    617 		{
    618 		  sh = ((words - 1 - w) * 16);
    619 		  exops[i][op] = gen_rtx_CONST_INT (HImode, trunc_int_for_mode (INTVAL(operands[op]) >> sh, HImode));
    620 		}
    621 	    }
    622 	  else
    623 	    exops[i][op] = operands[op];
    624 	}
    625     }
    626   return true;
    627 }
    628 
    629 /* Output assembler code to perform a multiple-word move insn
    630    with operands OPERANDS.  This moves 2 or 4 words depending
    631    on the machine mode of the operands.  */
    632 
    633 const char *
    634 output_move_multiple (rtx *operands)
    635 {
    636   rtx inops[2];
    637   rtx exops[4][2];
    638   rtx adjops[2];
    639 
    640   pdp11_action action[2];
    641   int i, words;
    642 
    643   words = GET_MODE_BITSIZE (GET_MODE (operands[0])) / 16;
    644   adjops[1] = gen_rtx_CONST_INT (HImode, words * 2);
    645 
    646   inops[0] = operands[0];
    647   inops[1] = operands[1];
    648 
    649   pdp11_expand_operands (inops, exops, 2, words, action, either);
    650 
    651   /* Check for explicit decrement before.  */
    652   if (action[0] == dec_before)
    653     {
    654       adjops[0] = XEXP (XEXP (operands[0], 0), 0);
    655       output_asm_insn ("sub\t%1,%0", adjops);
    656     }
    657   if (action[1] == dec_before)
    658     {
    659       adjops[0] = XEXP (XEXP (operands[1], 0), 0);
    660       output_asm_insn ("sub\t%1,%0", adjops);
    661     }
    662 
    663   /* Do the words.  */
    664   for (i = 0; i < words; i++)
    665     output_asm_insn (singlemove_string (exops[i]), exops[i]);
    666 
    667   /* Check for increment after.  */
    668   if (action[0] == inc_after)
    669     {
    670       adjops[0] = XEXP (XEXP (operands[0], 0), 0);
    671       output_asm_insn ("add\t%1,%0", adjops);
    672     }
    673   if (action[1] == inc_after)
    674     {
    675       adjops[0] = XEXP (XEXP (operands[1], 0), 0);
    676       output_asm_insn ("add\t%1,%0", adjops);
    677     }
    678 
    679   return "";
    680 }
    681 
    682 /* Build an internal label.  */
    684 void
    685 pdp11_gen_int_label (char *label, const char *prefix, int num)
    686 {
    687   if (TARGET_DEC_ASM)
    688     /* +1 because GCC numbers labels starting at zero.  */
    689     sprintf (label, "*%u$", num + 1);
    690   else
    691     sprintf (label, "*%s_%u", prefix, num);
    692 }
    693 
    694 /* Output an ascii string.  */
    695 void
    696 output_ascii (FILE *file, const char *p, int size)
    697 {
    698   int i, c;
    699   const char *pseudo = "\t.ascii\t";
    700   bool delim = false;
    701 
    702   if (TARGET_DEC_ASM)
    703     {
    704       if (p[size - 1] == '\0')
    705 	{
    706 	  pseudo = "\t.asciz\t";
    707 	  size--;
    708 	}
    709       fputs (pseudo, file);
    710       for (i = 0; i < size; i++)
    711 	{
    712 	  c = *p++ & 0xff;
    713 	  if (c < 32 || c == '"' || c > 126)
    714 	    {
    715 	      if (delim)
    716 		putc ('"', file);
    717 	      fprintf (file, "<%o>", c);
    718 	      delim = false;
    719 	    }
    720 	  else
    721 	    {
    722 	      if (!delim)
    723 		putc ('"', file);
    724 	      delim = true;
    725 	      putc (c, file);
    726 	    }
    727 	}
    728       if (delim)
    729 	putc ('"', file);
    730       putc ('\n', file);
    731     }
    732   else
    733     {
    734       fprintf (file, "\t.byte ");
    735 
    736       for (i = 0; i < size; i++)
    737 	{
    738 	  fprintf (file, "%#o", *p++ & 0xff);
    739 	  if (i < size - 1)
    740 	    putc (',', file);
    741 	}
    742       putc ('\n', file);
    743     }
    744 }
    745 
    746 void
    747 pdp11_asm_output_var (FILE *file, const char *name, int size,
    748 		      int align, bool global)
    749 {
    750   switch_to_section (data_section);
    751   if (align > 8)
    752     fprintf (file, "\t.even\n");
    753   if (TARGET_DEC_ASM)
    754     {
    755       assemble_name (file, name);
    756       if (global)
    757 	fputs ("::", file);
    758       else
    759 	fputs (":", file);
    760       if (align > 8)
    761 	fprintf (file, "\t.blkw\t%o\n", (size & 0xffff) / 2);
    762       else
    763 	fprintf (file, "\t.blkb\t%o\n", size & 0xffff);
    764     }
    765   else
    766     {
    767       if (global)
    768 	{
    769 	  fprintf (file, ".globl ");
    770 	  assemble_name (file, name);
    771 	  fprintf (file, "\n");
    772 	}
    773       assemble_name (file, name);
    774       fputs (":", file);
    775       ASM_OUTPUT_SKIP (file, size);
    776     }
    777 }
    778 
    779 /* Special format operators handled here:
    780    # -- output the correct immediate operand marker for the assembler
    781         dialect.
    782    @ -- output the correct indirect marker for the assembler dialect.
    783    o -- emit a constant value as a number (not an immediate operand)
    784         in octal.  */
    785 static void
    786 pdp11_asm_print_operand (FILE *file, rtx x, int code)
    787 {
    788   long sval[2];
    789 
    790   if (code == '#')
    791     {
    792       if (TARGET_DEC_ASM)
    793 	putc ('#', file);
    794       else
    795 	putc ('$', file);
    796     }
    797   else if (code == '@')
    798     {
    799       if (TARGET_UNIX_ASM)
    800 	fprintf (file, "*");
    801       else
    802 	fprintf (file, "@");
    803     }
    804   else if (GET_CODE (x) == REG)
    805     fprintf (file, "%s", reg_names[REGNO (x)]);
    806   else if (GET_CODE (x) == MEM)
    807     output_address (GET_MODE (x), XEXP (x, 0));
    808   else if (GET_CODE (x) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (x)))
    809     {
    810       REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x), sval);
    811       if (TARGET_DEC_ASM)
    812 	fprintf (file, "#%lo", (sval[0] >> 16) & 0xffff);
    813       else
    814 	fprintf (file, "$%#lo", (sval[0] >> 16) & 0xffff);
    815     }
    816   else
    817     {
    818       if (code != 'o')
    819 	{
    820 	  if (TARGET_DEC_ASM)
    821 	    putc ('#', file);
    822 	  else
    823 	    putc ('$', file);
    824 	}
    825       output_addr_const_pdp11 (file, x);
    826     }
    827 }
    828 
    829 static bool
    830 pdp11_asm_print_operand_punct_valid_p (unsigned char c)
    831 {
    832   return (c == '#' || c == '@');
    833 }
    834 
    835 void
    836 print_operand_address (FILE *file, rtx addr)
    837 {
    838   rtx breg;
    839   rtx offset;
    840   int again = 0;
    841 
    842  retry:
    843 
    844   switch (GET_CODE (addr))
    845     {
    846     case MEM:
    847       if (TARGET_UNIX_ASM)
    848 	fprintf (file, "*");
    849       else
    850 	fprintf (file, "@");
    851       addr = XEXP (addr, 0);
    852       again = 1;
    853       goto retry;
    854 
    855     case REG:
    856       fprintf (file, "(%s)", reg_names[REGNO (addr)]);
    857       break;
    858 
    859     case PRE_MODIFY:
    860     case PRE_DEC:
    861       fprintf (file, "-(%s)", reg_names[REGNO (XEXP (addr, 0))]);
    862       break;
    863 
    864     case POST_MODIFY:
    865     case POST_INC:
    866       fprintf (file, "(%s)+", reg_names[REGNO (XEXP (addr, 0))]);
    867       break;
    868 
    869     case PLUS:
    870       breg = 0;
    871       offset = 0;
    872       if (CONSTANT_ADDRESS_P (XEXP (addr, 0))
    873 	  || GET_CODE (XEXP (addr, 0)) == MEM)
    874 	{
    875 	  offset = XEXP (addr, 0);
    876 	  addr = XEXP (addr, 1);
    877 	}
    878       else if (CONSTANT_ADDRESS_P (XEXP (addr, 1))
    879 	       || GET_CODE (XEXP (addr, 1)) == MEM)
    880 	{
    881 	  offset = XEXP (addr, 1);
    882 	  addr = XEXP (addr, 0);
    883 	}
    884       if (GET_CODE (addr) != PLUS)
    885 	;
    886       else if (GET_CODE (XEXP (addr, 0)) == REG)
    887 	{
    888 	  breg = XEXP (addr, 0);
    889 	  addr = XEXP (addr, 1);
    890 	}
    891       else if (GET_CODE (XEXP (addr, 1)) == REG)
    892 	{
    893 	  breg = XEXP (addr, 1);
    894 	  addr = XEXP (addr, 0);
    895 	}
    896       if (GET_CODE (addr) == REG)
    897 	{
    898 	  gcc_assert (breg == 0);
    899 	  breg = addr;
    900 	  addr = 0;
    901 	}
    902       if (offset != 0)
    903 	{
    904 	  gcc_assert (addr == 0);
    905 	  addr = offset;
    906 	}
    907       if (addr != 0)
    908 	output_addr_const_pdp11 (file, addr);
    909       if (breg != 0)
    910 	{
    911 	  gcc_assert (GET_CODE (breg) == REG);
    912 	  fprintf (file, "(%s)", reg_names[REGNO (breg)]);
    913 	}
    914       break;
    915 
    916     default:
    917       if (!again && GET_CODE (addr) == CONST_INT)
    918 	{
    919 	  /* Absolute (integer number) address.  */
    920 	  if (TARGET_DEC_ASM)
    921 	    fprintf (file, "@#");
    922 	  else if (!TARGET_UNIX_ASM)
    923 	    fprintf (file, "@$");
    924 	}
    925       output_addr_const_pdp11 (file, addr);
    926     }
    927 }
    928 
    929 /* Target hook to assemble integer objects.  We need to use the
    930    pdp-specific version of output_addr_const.  */
    931 
    932 static bool
    933 pdp11_assemble_integer (rtx x, unsigned int size, int aligned_p)
    934 {
    935   if (aligned_p)
    936     switch (size)
    937       {
    938       case 1:
    939 	fprintf (asm_out_file, "\t.byte\t");
    940 	output_addr_const_pdp11 (asm_out_file, GEN_INT (INTVAL (x) & 0xff));
    941 	fputs ("\n", asm_out_file);
    942 	return true;
    943 
    944       case 2:
    945 	fprintf (asm_out_file, TARGET_UNIX_ASM ? "\t" : "\t.word\t");
    946 	output_addr_const_pdp11 (asm_out_file, x);
    947 	fputs ("\n", asm_out_file);
    948 	return true;
    949       }
    950   return default_assemble_integer (x, size, aligned_p);
    951 }
    952 
    953 
    954 static bool
    955 pdp11_lra_p (void)
    956 {
    957   return TARGET_LRA;
    958 }
    959 
    960 /* Register to register moves are cheap if both are general
    961    registers.  */
    962 static int
    963 pdp11_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED,
    964 			  reg_class_t c1, reg_class_t c2)
    965 {
    966   if (CPU_REG_CLASS (c1) && CPU_REG_CLASS (c2))
    967     return 2;
    968   else if ((c1 >= LOAD_FPU_REGS && c1 <= FPU_REGS && c2 == LOAD_FPU_REGS) ||
    969 	   (c2 >= LOAD_FPU_REGS && c2 <= FPU_REGS && c1 == LOAD_FPU_REGS))
    970     return 2;
    971   else
    972     return 22;
    973 }
    974 
    975 /* This tries to approximate what pdp11_insn_cost would do, but
    976    without visibility into the actual instruction being generated it's
    977    inevitably a rough approximation.  */
    978 static bool
    979 pdp11_rtx_costs (rtx x, machine_mode mode, int outer_code,
    980 		 int opno ATTRIBUTE_UNUSED, int *total, bool speed)
    981 {
    982   const int code = GET_CODE (x);
    983   const int asize = (mode == QImode) ? 2 : GET_MODE_SIZE (mode);
    984   rtx src, dest;
    985   const char *fmt;
    986 
    987   switch (code)
    988     {
    989     case CONST_INT:
    990       /* Treat -1, 0, 1 as things that are optimized as clr or dec
    991 	 etc. though that doesn't apply to every case.  */
    992       if (INTVAL (x) >= -1 && INTVAL (x) <= 1)
    993 	{
    994 	  *total = 0;
    995 	  return true;
    996 	}
    997       /* FALL THROUGH.  */
    998     case REG:
    999     case MEM:
   1000     case CONST:
   1001     case LABEL_REF:
   1002     case SYMBOL_REF:
   1003     case CONST_DOUBLE:
   1004       *total = pdp11_addr_cost (x, mode, ADDR_SPACE_GENERIC, speed);
   1005       return true;
   1006     }
   1007   if (GET_RTX_LENGTH (code) == 0)
   1008     {
   1009       if (speed)
   1010 	*total = 0;
   1011       else
   1012 	*total = 2;
   1013       return true;
   1014     }
   1015 
   1016   /* Pick up source and dest.  We don't necessarily use the standard
   1017      recursion in rtx_costs to figure the cost, because that would
   1018      count the destination operand twice for three-operand insns.
   1019      Also, this way we can catch special cases like move of zero, or
   1020      add one.  */
   1021   fmt = GET_RTX_FORMAT (code);
   1022   if (fmt[0] != 'e' || (GET_RTX_LENGTH (code) > 1 && fmt[1] != 'e'))
   1023     {
   1024       if (speed)
   1025 	*total = 0;
   1026       else
   1027 	*total = 2;
   1028       return true;
   1029     }
   1030   if (GET_RTX_LENGTH (code) > 1)
   1031     src = XEXP (x, 1);
   1032   dest = XEXP (x, 0);
   1033 
   1034   /* If optimizing for size, claim everything costs 2 per word, plus
   1035      whatever the operands require.  */
   1036   if (!speed)
   1037     *total = asize;
   1038   else
   1039     {
   1040       if (FLOAT_MODE_P (mode))
   1041 	{
   1042 	  switch (code)
   1043 	    {
   1044 	    case MULT:
   1045 	    case DIV:
   1046 	    case MOD:
   1047 	      *total = 20;
   1048 	      break;
   1049 
   1050 	    case COMPARE:
   1051 	      *total = 4;
   1052 	      break;
   1053 
   1054 	    case PLUS:
   1055 	    case MINUS:
   1056 	      *total = 6;
   1057 	      break;
   1058 
   1059 	    default:
   1060 	      *total = 2;
   1061 	      break;
   1062 	    }
   1063 	}
   1064       else
   1065 	{
   1066 	  /* Integer operations are scaled for SI and DI modes, though the
   1067 	     scaling is not exactly accurate.  */
   1068 	  switch (code)
   1069 	    {
   1070 	    case MULT:
   1071 	      *total = 5 * asize * asize;
   1072 	      break;
   1073 
   1074 	    case DIV:
   1075 	      *total = 10 * asize * asize;
   1076 	      break;
   1077 
   1078 	    case MOD:
   1079 	      /* Fake value because it's accounted for under DIV, since we
   1080 		 use a divmod pattern.  */
   1081 	      total = 0;
   1082 	      break;
   1083 
   1084 	    case ASHIFT:
   1085 	    case ASHIFTRT:
   1086 	    case LSHIFTRT:
   1087 	      /* This is a bit problematic because the cost depends on the
   1088 		 shift amount.  Make it <asize> for now, which is for the
   1089 		 case of a one bit shift.  */
   1090 	      *total = asize;
   1091 	      break;
   1092 
   1093 	    default:
   1094 	      *total = asize;
   1095 	      break;
   1096 	    }
   1097 	}
   1098     }
   1099 
   1100   /* Now see if we're looking at a SET.  If yes, then look at the
   1101      source to see if this is a move or an arithmetic operation, and
   1102      continue accordingly to handle the operands.  */
   1103   if (code == SET)
   1104     {
   1105       switch (GET_CODE (src))
   1106 	{
   1107 	case REG:
   1108 	case MEM:
   1109 	case CONST_INT:
   1110 	case CONST:
   1111 	case LABEL_REF:
   1112 	case SYMBOL_REF:
   1113 	case CONST_DOUBLE:
   1114 	  /* It's a move.  */
   1115 	  *total += pdp11_addr_cost (dest, mode, ADDR_SPACE_GENERIC, speed);
   1116 	  if (src != const0_rtx)
   1117 	    *total += pdp11_addr_cost (src, mode, ADDR_SPACE_GENERIC, speed);
   1118 	  return true;
   1119 	default:
   1120 	  /* Not a move.  Get the cost of the source operand and add
   1121 	     that in, but not the destination operand since we're
   1122 	     dealing with read/modify/write operands.  */
   1123 	  *total += rtx_cost (src, mode, (enum rtx_code) outer_code, 1, speed);
   1124 	  return true;
   1125 	}
   1126     }
   1127   else if (code == PLUS || code == MINUS)
   1128     {
   1129       if (GET_CODE (src) == CONST_INT &&
   1130 	  (INTVAL (src) == 1 || INTVAL (src) == -1))
   1131 	{
   1132 	  *total += rtx_cost (dest, mode, (enum rtx_code) outer_code, 0, speed);
   1133 	  return true;
   1134 	}
   1135     }
   1136   return false;
   1137 }
   1138 
   1139 /* Return cost of accessing the supplied operand.  Registers are free.
   1140    Anything else starts with a cost of two.  Add to that for memory
   1141    references the memory accesses of the addressing mode (if any) plus
   1142    the data reference; for other operands just the memory access (if
   1143    any) for the mode.  */
   1144 static int
   1145 pdp11_addr_cost (rtx addr, machine_mode mode, addr_space_t as ATTRIBUTE_UNUSED,
   1146 		 bool speed)
   1147 {
   1148   int cost = 0;
   1149 
   1150   if (GET_CODE (addr) != REG)
   1151     {
   1152       if (!simple_memory_operand (addr, mode))
   1153 	cost = 2;
   1154 
   1155       /* If optimizing for speed, account for the memory reference if
   1156 	 any.  */
   1157       if (speed && !CONSTANT_P (addr))
   1158 	cost += (mode == QImode) ? 2 : GET_MODE_SIZE (mode);
   1159     }
   1160   return cost;
   1161 }
   1162 
   1163 
   1164 static int
   1165 pdp11_insn_cost (rtx_insn *insn, bool speed)
   1166 {
   1167   int base_cost;
   1168   rtx pat, set, dest, src, src2;
   1169   machine_mode mode;
   1170   enum rtx_code op;
   1171 
   1172   if (recog_memoized (insn) < 0)
   1173     return 0;
   1174 
   1175   /* If optimizing for size, we want the insn size.  */
   1176   if (!speed)
   1177     return get_attr_length (insn);
   1178   else
   1179     {
   1180       /* Optimizing for speed.  Get the base cost of the insn, then
   1181 	 adjust for the cost of accessing operands.  Zero means use
   1182 	 the length as the cost even when optimizing for speed.  */
   1183       base_cost = get_attr_base_cost (insn);
   1184       if (base_cost <= 0)
   1185 	base_cost = get_attr_length (insn);
   1186     }
   1187   /* Look for the operands.  Often we have a PARALLEL that's either
   1188      the actual operation plus a clobber, or the implicit compare plus
   1189      the actual operation.  Find the actual operation.  */
   1190   pat = PATTERN (insn);
   1191 
   1192   if (GET_CODE (pat) == PARALLEL)
   1193     {
   1194       set = XVECEXP (pat, 0, 0);
   1195       if (GET_CODE (set) != SET || GET_CODE (XEXP (set, 1)) == COMPARE)
   1196 	set = XVECEXP (pat, 0, 1);
   1197       if (GET_CODE (set) != SET || GET_CODE (XEXP (set, 1)) == COMPARE)
   1198 	return 0;
   1199     }
   1200   else
   1201     {
   1202       set = pat;
   1203       if (GET_CODE (set) != SET)
   1204 	return 0;
   1205     }
   1206 
   1207   /* Pick up the SET source and destination RTL.  */
   1208   dest = XEXP (set, 0);
   1209   src = XEXP (set, 1);
   1210   mode = GET_MODE (dest);
   1211 
   1212   /* See if we have a move, or some arithmetic operation.  If a move,
   1213      account for source and destination operand costs.  Otherwise,
   1214      account for the destination and for the second operand of the
   1215      operation -- the first is also destination and we don't want to
   1216      double-count it.  */
   1217   base_cost += pdp11_addr_cost (dest, mode, ADDR_SPACE_GENERIC, speed);
   1218   op = GET_CODE (src);
   1219   switch (op)
   1220     {
   1221     case REG:
   1222     case MEM:
   1223     case CONST_INT:
   1224     case CONST:
   1225     case LABEL_REF:
   1226     case SYMBOL_REF:
   1227     case CONST_DOUBLE:
   1228       /* It's a move.  */
   1229       if (src != const0_rtx)
   1230 	base_cost += pdp11_addr_cost (src, mode, ADDR_SPACE_GENERIC, speed);
   1231       return base_cost;
   1232     default:
   1233       break;
   1234     }
   1235   /* There are some other cases where souce and dest are distinct.  */
   1236   if (FLOAT_MODE_P (mode) &&
   1237       (op == FLOAT_TRUNCATE || op == FLOAT_EXTEND || op == FIX || op == FLOAT))
   1238     {
   1239       src2 = XEXP (src, 0);
   1240       base_cost += pdp11_addr_cost (src2, mode, ADDR_SPACE_GENERIC, speed);
   1241     }
   1242   /* Otherwise, pick up the second operand of the arithmetic
   1243      operation, if it has two operands.  */
   1244   else if (op != SUBREG && op != UNSPEC && GET_RTX_LENGTH (op) > 1)
   1245     {
   1246       src2 = XEXP (src, 1);
   1247       base_cost += pdp11_addr_cost (src2, mode, ADDR_SPACE_GENERIC, speed);
   1248     }
   1249 
   1250   return base_cost;
   1251 }
   1252 
   1253 const char *
   1254 output_jump (rtx *operands, int ccnz, int length)
   1255 {
   1256   rtx tmpop[1];
   1257   static char buf[100];
   1258   const char *pos, *neg;
   1259   enum rtx_code code = GET_CODE (operands[0]);
   1260 
   1261   if (ccnz)
   1262     {
   1263       /* These are the branches valid for CCNZmode, i.e., a comparison
   1264 	 with zero where the V bit is not set to zero.  These cases
   1265 	 occur when CC or FCC are set as a side effect of some data
   1266 	 manipulation, such as the ADD instruction.  */
   1267       switch (code)
   1268 	{
   1269 	case EQ: pos = "beq", neg = "bne"; break;
   1270 	case NE: pos = "bne", neg = "beq"; break;
   1271 	case LT: pos = "bmi", neg = "bpl"; break;
   1272 	case GE: pos = "bpl", neg = "bmi"; break;
   1273 	default: gcc_unreachable ();
   1274 	}
   1275     }
   1276   else
   1277     {
   1278       switch (code)
   1279 	{
   1280 	case EQ: pos = "beq", neg = "bne"; break;
   1281 	case NE: pos = "bne", neg = "beq"; break;
   1282 	case GT: pos = "bgt", neg = "ble"; break;
   1283 	case GTU: pos = "bhi", neg = "blos"; break;
   1284 	case LT: pos = "blt", neg = "bge"; break;
   1285 	case LTU: pos = "blo", neg = "bhis"; break;
   1286 	case GE: pos = "bge", neg = "blt"; break;
   1287 	case GEU: pos = "bhis", neg = "blo"; break;
   1288 	case LE: pos = "ble", neg = "bgt"; break;
   1289 	case LEU: pos = "blos", neg = "bhi"; break;
   1290 	default: gcc_unreachable ();
   1291 	}
   1292     }
   1293   switch (length)
   1294     {
   1295     case 2:
   1296       sprintf (buf, "%s\t%%l1", pos);
   1297       return buf;
   1298     case 6:
   1299       tmpop[0] = gen_label_rtx ();
   1300       sprintf (buf, "%s\t%%l0", neg);
   1301       output_asm_insn (buf, tmpop);
   1302       output_asm_insn ("jmp\t%l1", operands);
   1303       output_asm_label (tmpop[0]);
   1304       fputs (":\n", asm_out_file);
   1305       return "";
   1306     default:
   1307       gcc_unreachable ();
   1308     }
   1309 }
   1310 
   1311 /* Select the CC mode to be used for the side effect compare with
   1312    zero, given the compare operation code in op and the compare
   1313    operands in x in and y.  */
   1314 machine_mode
   1315 pdp11_cc_mode (enum rtx_code op ATTRIBUTE_UNUSED, rtx x, rtx y ATTRIBUTE_UNUSED)
   1316 {
   1317   if (FLOAT_MODE_P (GET_MODE (x)))
   1318     {
   1319       switch (GET_CODE (x))
   1320 	{
   1321 	case ABS:
   1322 	case NEG:
   1323 	case REG:
   1324 	case MEM:
   1325 	  return CCmode;
   1326 	default:
   1327 	  return CCNZmode;
   1328 	}
   1329     }
   1330   else
   1331     {
   1332       switch (GET_CODE (x))
   1333 	{
   1334 	case XOR:
   1335 	case AND:
   1336 	case IOR:
   1337 	case MULT:
   1338 	case NOT:
   1339 	case REG:
   1340 	case MEM:
   1341 	  return CCmode;
   1342 	default:
   1343 	  return CCNZmode;
   1344 	}
   1345     }
   1346 }
   1347 
   1348 
   1349 int
   1350 simple_memory_operand(rtx op, machine_mode mode ATTRIBUTE_UNUSED)
   1351 {
   1352   rtx addr;
   1353 
   1354   /* Eliminate non-memory operations */
   1355   if (GET_CODE (op) != MEM)
   1356     return FALSE;
   1357 
   1358   /* Decode the address now.  */
   1359 
   1360  indirection:
   1361 
   1362   addr = XEXP (op, 0);
   1363 
   1364   switch (GET_CODE (addr))
   1365     {
   1366     case REG:
   1367       /* (R0) - no extra cost */
   1368       return 1;
   1369 
   1370     case PRE_DEC:
   1371     case POST_INC:
   1372     case PRE_MODIFY:
   1373     case POST_MODIFY:
   1374       /* -(R0), (R0)+ - cheap! */
   1375       return 1;
   1376 
   1377     case MEM:
   1378       /* cheap - is encoded in addressing mode info!
   1379 
   1380 	 -- except for @(R0), which has to be @0(R0) !!! */
   1381 
   1382       if (GET_CODE (XEXP (addr, 0)) == REG)
   1383 	return 0;
   1384 
   1385       op=addr;
   1386       goto indirection;
   1387 
   1388     case CONST_INT:
   1389     case LABEL_REF:
   1390     case CONST:
   1391     case SYMBOL_REF:
   1392       /* @#address - extra cost */
   1393       return 0;
   1394 
   1395     case PLUS:
   1396       /* X(R0) - extra cost */
   1397       return 0;
   1398 
   1399     default:
   1400       break;
   1401     }
   1402 
   1403   return FALSE;
   1404 }
   1405 
   1406 /* Similar to simple_memory_operand but doesn't match push/pop.  */
   1407 int
   1408 no_side_effect_operand(rtx op, machine_mode mode ATTRIBUTE_UNUSED)
   1409 {
   1410   rtx addr;
   1411 
   1412   /* Eliminate non-memory operations */
   1413   if (GET_CODE (op) != MEM)
   1414     return FALSE;
   1415 
   1416   /* Decode the address now.  */
   1417 
   1418  indirection:
   1419 
   1420   addr = XEXP (op, 0);
   1421 
   1422   switch (GET_CODE (addr))
   1423     {
   1424     case REG:
   1425       /* (R0) - no extra cost */
   1426       return 1;
   1427 
   1428     case PRE_DEC:
   1429     case POST_INC:
   1430     case PRE_MODIFY:
   1431     case POST_MODIFY:
   1432       return 0;
   1433 
   1434     case MEM:
   1435       /* cheap - is encoded in addressing mode info!
   1436 
   1437 	 -- except for @(R0), which has to be @0(R0) !!! */
   1438 
   1439       if (GET_CODE (XEXP (addr, 0)) == REG)
   1440 	return 0;
   1441 
   1442       op=addr;
   1443       goto indirection;
   1444 
   1445     case CONST_INT:
   1446     case LABEL_REF:
   1447     case CONST:
   1448     case SYMBOL_REF:
   1449       /* @#address - extra cost */
   1450       return 0;
   1451 
   1452     case PLUS:
   1453       /* X(R0) - extra cost */
   1454       return 0;
   1455 
   1456     default:
   1457       break;
   1458     }
   1459 
   1460   return FALSE;
   1461 }
   1462 
   1463 /* Return TRUE if op is a push or pop using the register "regno".  */
   1464 bool
   1465 pushpop_regeq (rtx op, int regno)
   1466 {
   1467   rtx addr;
   1468 
   1469   /* False if not memory reference.  */
   1470   if (GET_CODE (op) != MEM)
   1471     return FALSE;
   1472 
   1473   /* Get the address of the memory reference.  */
   1474   addr = XEXP (op, 0);
   1475 
   1476   if (GET_CODE (addr) == MEM)
   1477     addr = XEXP (addr, 0);
   1478 
   1479   switch (GET_CODE (addr))
   1480     {
   1481     case PRE_DEC:
   1482     case POST_INC:
   1483     case PRE_MODIFY:
   1484     case POST_MODIFY:
   1485       return REGNO (XEXP (addr, 0)) == (unsigned) regno;
   1486     default:
   1487       return FALSE;
   1488     }
   1489 }
   1490 
   1491 /* This function checks whether a real value can be encoded as
   1492    a literal, i.e., addressing mode 27.  In that mode, real values
   1493    are one word values, so the remaining 48 bits have to be zero.  */
   1494 int
   1495 legitimate_const_double_p (rtx address)
   1496 {
   1497   long sval[2];
   1498 
   1499   /* If it's too big for HOST_WIDE_INT, it's definitely to big here.  */
   1500   if (GET_MODE (address) == VOIDmode)
   1501     return 0;
   1502   REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (address), sval);
   1503 
   1504   if ((sval[0] & 0xffff) == 0 && sval[1] == 0)
   1505     return 1;
   1506   return 0;
   1507 }
   1508 
   1509 /* Implement TARGET_CAN_CHANGE_MODE_CLASS.  */
   1510 static bool
   1511 pdp11_can_change_mode_class (machine_mode from,
   1512 			     machine_mode to,
   1513 			     reg_class_t rclass)
   1514 {
   1515   /* Also, FPU registers contain a whole float value and the parts of
   1516      it are not separately accessible.
   1517 
   1518      So we disallow all mode changes involving FPRs.  */
   1519   if (FLOAT_MODE_P (from) != FLOAT_MODE_P (to))
   1520     return false;
   1521 
   1522   return !reg_classes_intersect_p (FPU_REGS, rclass);
   1523 }
   1524 
   1525 /* Implement TARGET_CXX_GUARD_TYPE */
   1526 static tree
   1527 pdp11_guard_type (void)
   1528 {
   1529   return short_integer_type_node;
   1530 }
   1531 
   1532 /* TARGET_PREFERRED_RELOAD_CLASS
   1533 
   1534    Given an rtx X being reloaded into a reg required to be
   1535    in class CLASS, return the class of reg to actually use.
   1536    In general this is just CLASS; but on some machines
   1537    in some cases it is preferable to use a more restrictive class.
   1538 
   1539 loading is easier into LOAD_FPU_REGS than FPU_REGS! */
   1540 
   1541 static reg_class_t
   1542 pdp11_preferred_reload_class (rtx x, reg_class_t rclass)
   1543 {
   1544   if (rclass == FPU_REGS)
   1545     return LOAD_FPU_REGS;
   1546   if (rclass == ALL_REGS)
   1547     {
   1548       if (FLOAT_MODE_P (GET_MODE (x)))
   1549 	return LOAD_FPU_REGS;
   1550       else
   1551 	return GENERAL_REGS;
   1552     }
   1553   return rclass;
   1554 }
   1555 
   1556 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
   1557 
   1558    Given an rtx X being reloaded into a reg required to be
   1559    in class CLASS, return the class of reg to actually use.
   1560    In general this is just CLASS; but on some machines
   1561    in some cases it is preferable to use a more restrictive class.
   1562 
   1563 loading is easier into LOAD_FPU_REGS than FPU_REGS! */
   1564 
   1565 static reg_class_t
   1566 pdp11_preferred_output_reload_class (rtx x, reg_class_t rclass)
   1567 {
   1568   if (rclass == FPU_REGS)
   1569     return LOAD_FPU_REGS;
   1570   if (rclass == ALL_REGS)
   1571     {
   1572       if (FLOAT_MODE_P (GET_MODE (x)))
   1573 	return LOAD_FPU_REGS;
   1574       else
   1575 	return GENERAL_REGS;
   1576     }
   1577   return rclass;
   1578 }
   1579 
   1580 
   1581 /* TARGET_SECONDARY_RELOAD.
   1582 
   1583    FPU registers AC4 and AC5 (class NO_LOAD_FPU_REGS) require an
   1584    intermediate register (AC0-AC3: LOAD_FPU_REGS).  Everything else
   1585    can be loaded/stored directly.  */
   1586 static reg_class_t
   1587 pdp11_secondary_reload (bool in_p ATTRIBUTE_UNUSED,
   1588 			rtx x,
   1589 			reg_class_t reload_class,
   1590 			machine_mode reload_mode ATTRIBUTE_UNUSED,
   1591 			secondary_reload_info *sri ATTRIBUTE_UNUSED)
   1592 {
   1593   if (reload_class != NO_LOAD_FPU_REGS || GET_CODE (x) != REG ||
   1594       REGNO_REG_CLASS (REGNO (x)) == LOAD_FPU_REGS)
   1595     return NO_REGS;
   1596 
   1597   return LOAD_FPU_REGS;
   1598 }
   1599 
   1600 /* Implement TARGET_SECONDARY_MEMORY_NEEDED.
   1601 
   1602    The answer is yes if we're going between general register and FPU
   1603    registers.  The mode doesn't matter in making this check.  */
   1604 static bool
   1605 pdp11_secondary_memory_needed (machine_mode, reg_class_t c1, reg_class_t c2)
   1606 {
   1607   int fromfloat = (c1 == LOAD_FPU_REGS || c1 == NO_LOAD_FPU_REGS ||
   1608 		   c1 == FPU_REGS);
   1609   int tofloat = (c2 == LOAD_FPU_REGS || c2 == NO_LOAD_FPU_REGS ||
   1610 		 c2 == FPU_REGS);
   1611 
   1612   return (fromfloat != tofloat);
   1613 }
   1614 
   1615 /* TARGET_LEGITIMATE_ADDRESS_P recognizes an RTL expression
   1616    that is a valid memory address for an instruction.
   1617    The MODE argument is the machine mode for the MEM expression
   1618    that wants to use this address.
   1619 
   1620 */
   1621 
   1622 static bool
   1623 pdp11_legitimate_address_p (machine_mode mode,
   1624 			    rtx operand, bool strict)
   1625 {
   1626     rtx xfoob;
   1627 
   1628     /* accept @#address */
   1629     if (CONSTANT_ADDRESS_P (operand))
   1630       return true;
   1631 
   1632     switch (GET_CODE (operand))
   1633       {
   1634       case REG:
   1635 	/* accept (R0) */
   1636 	return !strict || REGNO_OK_FOR_BASE_P (REGNO (operand));
   1637 
   1638       case PLUS:
   1639 	/* accept X(R0) */
   1640 	return GET_CODE (XEXP (operand, 0)) == REG
   1641 	  && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (operand, 0))))
   1642 	  && CONSTANT_ADDRESS_P (XEXP (operand, 1));
   1643 
   1644       case PRE_DEC:
   1645 	/* accept -(R0) */
   1646 	return GET_CODE (XEXP (operand, 0)) == REG
   1647 	  && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (operand, 0))));
   1648 
   1649       case POST_INC:
   1650 	/* accept (R0)+ */
   1651 	return GET_CODE (XEXP (operand, 0)) == REG
   1652 	  && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (operand, 0))));
   1653 
   1654       case PRE_MODIFY:
   1655 	/* accept -(SP) -- which uses PRE_MODIFY for byte mode */
   1656 	return GET_CODE (XEXP (operand, 0)) == REG
   1657 	  && REGNO (XEXP (operand, 0)) == STACK_POINTER_REGNUM
   1658 	  && GET_CODE ((xfoob = XEXP (operand, 1))) == PLUS
   1659 	  && GET_CODE (XEXP (xfoob, 0)) == REG
   1660 	  && REGNO (XEXP (xfoob, 0)) == STACK_POINTER_REGNUM
   1661 	  && CONST_INT_P (XEXP (xfoob, 1))
   1662 	  && INTVAL (XEXP (xfoob,1)) == -2;
   1663 
   1664       case POST_MODIFY:
   1665 	/* accept (SP)+ -- which uses POST_MODIFY for byte mode */
   1666 	return GET_CODE (XEXP (operand, 0)) == REG
   1667 	  && REGNO (XEXP (operand, 0)) == STACK_POINTER_REGNUM
   1668 	  && GET_CODE ((xfoob = XEXP (operand, 1))) == PLUS
   1669 	  && GET_CODE (XEXP (xfoob, 0)) == REG
   1670 	  && REGNO (XEXP (xfoob, 0)) == STACK_POINTER_REGNUM
   1671 	  && CONST_INT_P (XEXP (xfoob, 1))
   1672 	  && INTVAL (XEXP (xfoob,1)) == 2;
   1673 
   1674       case MEM:
   1675 	/* handle another level of indirection ! */
   1676 	xfoob = XEXP (operand, 0);
   1677 
   1678 	/* (MEM:xx (MEM:xx ())) is not valid for SI, DI and currently
   1679 	   also forbidden for float, because we have to handle this
   1680 	   in output_move_double and/or output_move_quad() - we could
   1681 	   do it, but currently it's not worth it!!!
   1682 	   now that DFmode cannot go into CPU register file,
   1683 	   maybe I should allow float ...
   1684 	   but then I have to handle memory-to-memory moves in movdf ??  */
   1685 	if (GET_MODE_BITSIZE(mode) > 16)
   1686 	  return false;
   1687 
   1688 	/* accept @address */
   1689 	if (CONSTANT_ADDRESS_P (xfoob))
   1690 	  return true;
   1691 
   1692 	switch (GET_CODE (xfoob))
   1693 	  {
   1694 	  case REG:
   1695 	    /* accept @(R0) - which is @0(R0) */
   1696 	    return !strict || REGNO_OK_FOR_BASE_P(REGNO (xfoob));
   1697 
   1698 	  case PLUS:
   1699 	    /* accept @X(R0) */
   1700 	    return GET_CODE (XEXP (xfoob, 0)) == REG
   1701 	      && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (xfoob, 0))))
   1702 	      && CONSTANT_ADDRESS_P (XEXP (xfoob, 1));
   1703 
   1704 	  case PRE_DEC:
   1705 	    /* accept @-(R0) */
   1706 	    return GET_CODE (XEXP (xfoob, 0)) == REG
   1707 	      && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (xfoob, 0))));
   1708 
   1709 	  case POST_INC:
   1710 	    /* accept @(R0)+ */
   1711 	    return GET_CODE (XEXP (xfoob, 0)) == REG
   1712 	      && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (xfoob, 0))));
   1713 
   1714 	  default:
   1715 	    /* anything else is invalid */
   1716 	    return false;
   1717 	  }
   1718 
   1719       default:
   1720 	/* anything else is invalid */
   1721 	return false;
   1722       }
   1723 }
   1724 
   1725 /* Return the class number of the smallest class containing
   1726    reg number REGNO.  */
   1727 enum reg_class
   1728 pdp11_regno_reg_class (int regno)
   1729 {
   1730   if (regno == ARG_POINTER_REGNUM)
   1731     return NOTSP_REG;
   1732   else if (regno == CC_REGNUM || regno == FCC_REGNUM)
   1733     return CC_REGS;
   1734   else if (regno > AC3_REGNUM)
   1735     return NO_LOAD_FPU_REGS;
   1736   else if (regno >= AC0_REGNUM)
   1737     return LOAD_FPU_REGS;
   1738   else if (regno == 6)
   1739     return NOTR0_REG;
   1740   else if (regno < 6)
   1741     return NOTSP_REG;
   1742   else
   1743     return GENERAL_REGS;
   1744 }
   1745 
   1746 /* Return the regnums of the CC registers.  */
   1747 bool
   1748 pdp11_fixed_cc_regs (unsigned int *p1, unsigned int *p2)
   1749 {
   1750   *p1 = CC_REGNUM;
   1751   *p2 = FCC_REGNUM;
   1752   return true;
   1753 }
   1754 
   1755 static int
   1756 pdp11_reg_save_size (void)
   1757 {
   1758   int offset = 0, regno;
   1759 
   1760   for (regno = 0; regno <= PC_REGNUM; regno++)
   1761     if (pdp11_saved_regno (regno))
   1762       offset += 2;
   1763   for (regno = AC0_REGNUM; regno <= AC5_REGNUM; regno++)
   1764     if (pdp11_saved_regno (regno))
   1765       offset += 8;
   1766 
   1767   return offset;
   1768 }
   1769 
   1770 /* Return the offset between two registers, one to be eliminated, and the other
   1771    its replacement, at the start of a routine.  */
   1772 
   1773 int
   1774 pdp11_initial_elimination_offset (int from, int to)
   1775 {
   1776   /* Get the size of the register save area.  */
   1777 
   1778   if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
   1779     return get_frame_size ();
   1780   else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
   1781     return pdp11_reg_save_size () + 2;
   1782   else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
   1783     return pdp11_reg_save_size () + 2 + get_frame_size ();
   1784   else
   1785     gcc_assert (0);
   1786 }
   1787 
   1788 /* A copy of output_addr_const modified for pdp11 expression syntax.
   1789    output_addr_const also gets called for %cDIGIT and %nDIGIT, which we don't
   1790    use, and for debugging output, which we don't support with this port either.
   1791    So this copy should get called whenever needed.
   1792 */
   1793 void
   1794 output_addr_const_pdp11 (FILE *file, rtx x)
   1795 {
   1796   char buf[256];
   1797   int i;
   1798 
   1799  restart:
   1800   switch (GET_CODE (x))
   1801     {
   1802     case PC:
   1803       gcc_assert (flag_pic);
   1804       putc ('.', file);
   1805       break;
   1806 
   1807     case SYMBOL_REF:
   1808       assemble_name (file, XSTR (x, 0));
   1809       break;
   1810 
   1811     case LABEL_REF:
   1812       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
   1813       assemble_name (file, buf);
   1814       break;
   1815 
   1816     case CODE_LABEL:
   1817       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
   1818       assemble_name (file, buf);
   1819       break;
   1820 
   1821     case CONST_INT:
   1822       i = INTVAL (x);
   1823       if (i < 0)
   1824 	{
   1825 	  i = -i;
   1826 	  fprintf (file, "-");
   1827 	}
   1828       if (TARGET_DEC_ASM)
   1829 	fprintf (file, "%o", i & 0xffff);
   1830       else
   1831 	fprintf (file, "%#o", i & 0xffff);
   1832       break;
   1833 
   1834     case CONST:
   1835       output_addr_const_pdp11 (file, XEXP (x, 0));
   1836       break;
   1837 
   1838     case PLUS:
   1839       /* Some assemblers need integer constants to appear last (e.g. masm).  */
   1840       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
   1841 	{
   1842 	  output_addr_const_pdp11 (file, XEXP (x, 1));
   1843 	  if (INTVAL (XEXP (x, 0)) >= 0)
   1844 	    fprintf (file, "+");
   1845 	  output_addr_const_pdp11 (file, XEXP (x, 0));
   1846 	}
   1847       else
   1848 	{
   1849 	  output_addr_const_pdp11 (file, XEXP (x, 0));
   1850 	  if (INTVAL (XEXP (x, 1)) >= 0)
   1851 	    fprintf (file, "+");
   1852 	  output_addr_const_pdp11 (file, XEXP (x, 1));
   1853 	}
   1854       break;
   1855 
   1856     case MINUS:
   1857       /* Avoid outputting things like x-x or x+5-x,
   1858 	 since some assemblers can't handle that.  */
   1859       x = simplify_subtraction (x);
   1860       if (GET_CODE (x) != MINUS)
   1861 	goto restart;
   1862 
   1863       output_addr_const_pdp11 (file, XEXP (x, 0));
   1864       if (GET_CODE (XEXP (x, 1)) != CONST_INT
   1865 	  || INTVAL (XEXP (x, 1)) >= 0)
   1866 	fprintf (file, "-");
   1867       output_addr_const_pdp11 (file, XEXP (x, 1));
   1868       break;
   1869 
   1870     case ZERO_EXTEND:
   1871     case SIGN_EXTEND:
   1872       output_addr_const_pdp11 (file, XEXP (x, 0));
   1873       break;
   1874 
   1875     default:
   1876       output_operand_lossage ("invalid expression as operand");
   1877     }
   1878 }
   1879 
   1880 /* Worker function for TARGET_RETURN_IN_MEMORY.  */
   1881 
   1882 static bool
   1883 pdp11_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
   1884 {
   1885   /* Integers 32 bits and under, and scalar floats (if FPU), are returned
   1886      in registers.  The rest go into memory.  */
   1887   return (TYPE_MODE (type) == DImode
   1888 	  || (FLOAT_MODE_P (TYPE_MODE (type)) && ! TARGET_AC0)
   1889 	  || TREE_CODE (type) == VECTOR_TYPE
   1890 	  || COMPLEX_MODE_P (TYPE_MODE (type)));
   1891 }
   1892 
   1893 /* Worker function for TARGET_FUNCTION_VALUE.
   1894 
   1895    On the pdp11 the value is found in R0 (or ac0??? not without FPU!!!! )  */
   1896 
   1897 static rtx
   1898 pdp11_function_value (const_tree valtype,
   1899  		      const_tree fntype_or_decl ATTRIBUTE_UNUSED,
   1900  		      bool outgoing ATTRIBUTE_UNUSED)
   1901 {
   1902   return gen_rtx_REG (TYPE_MODE (valtype),
   1903 		      BASE_RETURN_VALUE_REG(TYPE_MODE(valtype)));
   1904 }
   1905 
   1906 /* Worker function for TARGET_LIBCALL_VALUE.  */
   1907 
   1908 static rtx
   1909 pdp11_libcall_value (machine_mode mode,
   1910                      const_rtx fun ATTRIBUTE_UNUSED)
   1911 {
   1912   return  gen_rtx_REG (mode, BASE_RETURN_VALUE_REG(mode));
   1913 }
   1914 
   1915 /* Worker function for TARGET_FUNCTION_VALUE_REGNO_P.
   1916 
   1917    On the pdp, the first "output" reg is the only register thus used.
   1918 
   1919    maybe ac0 ? - as option someday!  */
   1920 
   1921 static bool
   1922 pdp11_function_value_regno_p (const unsigned int regno)
   1923 {
   1924   return (regno == RETVAL_REGNUM) || (TARGET_AC0 && (regno == AC0_REGNUM));
   1925 }
   1926 
   1927 /* Used for O constraint, matches if shift count is "small".  */
   1928 bool
   1929 pdp11_small_shift (int n)
   1930 {
   1931   return (unsigned) n < 4;
   1932 }
   1933 
   1934 /* Expand a shift insn.  Returns true if the expansion was done,
   1935    false if it needs to be handled by the caller.  */
   1936 bool
   1937 pdp11_expand_shift (rtx *operands, rtx (*shift_sc) (rtx, rtx, rtx),
   1938 		    rtx (*shift_base) (rtx, rtx, rtx))
   1939 {
   1940   rtx r, test;
   1941   rtx_code_label *lb;
   1942 
   1943   if (CONST_INT_P (operands[2]) && pdp11_small_shift (INTVAL (operands[2])))
   1944     emit_insn ((*shift_sc) (operands[0], operands[1], operands[2]));
   1945   else if (TARGET_40_PLUS)
   1946     return false;
   1947   else
   1948     {
   1949       lb = gen_label_rtx ();
   1950       r = gen_reg_rtx (HImode);
   1951       emit_move_insn (operands[0], operands[1]);
   1952       emit_move_insn (r, operands[2]);
   1953       if (!CONST_INT_P (operands[2]))
   1954 	{
   1955 	  test = gen_rtx_LE (HImode, r, const0_rtx);
   1956 	  emit_jump_insn (gen_cbranchhi4 (test, r, const0_rtx, lb));
   1957 	}
   1958       /* It would be nice to expand the loop here, but that's not
   1959 	 possible because shifts may be generated by the loop unroll
   1960 	 optimizer and it doesn't appreciate flow changes happening
   1961 	 while it's doing things.  */
   1962       emit_insn ((*shift_base) (operands[0], operands[1], r));
   1963       if (!CONST_INT_P (operands[2]))
   1964 	{
   1965 	  emit_label (lb);
   1966 
   1967 	  /* Allow REG_NOTES to be set on last insn (labels don't have enough
   1968 	     fields, and can't be used for REG_NOTES anyway).  */
   1969 	  emit_use (stack_pointer_rtx);
   1970 	}
   1971     }
   1972   return true;
   1973 }
   1974 
   1975 /* Emit the instructions needed to produce a shift by a small constant
   1976    amount (unrolled), or a shift made from a loop for the base machine
   1977    case.  */
   1978 const char *
   1979 pdp11_assemble_shift (rtx *operands, machine_mode m, int code)
   1980 {
   1981   int i, n;
   1982   rtx inops[2];
   1983   rtx exops[2][2];
   1984   rtx lb[1];
   1985   pdp11_action action[2];
   1986   const bool small = CONST_INT_P (operands[2]) && pdp11_small_shift (INTVAL (operands[2]));
   1987 
   1988   gcc_assert (small || !TARGET_40_PLUS);
   1989 
   1990   if (m == E_SImode)
   1991     {
   1992       inops[0] = operands[0];
   1993       pdp11_expand_operands (inops, exops, 1, 2, action, either);
   1994     }
   1995 
   1996   if (!small)
   1997     {
   1998       /* Loop case, generate the top of loop label.  */
   1999       lb[0] = gen_label_rtx ();
   2000       output_asm_label (lb[0]);
   2001       fputs (":\n", asm_out_file);
   2002       n = 1;
   2003     }
   2004   else
   2005     n = INTVAL (operands[2]);
   2006   if (code == LSHIFTRT)
   2007     {
   2008       output_asm_insn ("clc", NULL);
   2009       switch (m)
   2010 	{
   2011 	case E_QImode:
   2012 	  output_asm_insn ("rorb\t%0", operands);
   2013 	  break;
   2014 	case E_HImode:
   2015 	  output_asm_insn ("ror\t%0", operands);
   2016 	  break;
   2017 	case E_SImode:
   2018 	  output_asm_insn ("ror\t%0", exops[0]);
   2019 	  output_asm_insn ("ror\t%0", exops[1]);
   2020 	  break;
   2021 	default:
   2022 	  gcc_unreachable ();
   2023 	}
   2024       n--;
   2025     }
   2026   for (i = 0; i < n; i++)
   2027     {
   2028       switch (code)
   2029 	{
   2030 	case LSHIFTRT:
   2031 	case ASHIFTRT:
   2032 	  switch (m)
   2033 	    {
   2034 	    case E_QImode:
   2035 	      output_asm_insn ("asrb\t%0", operands);
   2036 	      break;
   2037 	    case E_HImode:
   2038 	      output_asm_insn ("asr\t%0", operands);
   2039 	      break;
   2040 	    case E_SImode:
   2041 	      output_asm_insn ("asr\t%0", exops[0]);
   2042 	      output_asm_insn ("ror\t%0", exops[1]);
   2043 	      break;
   2044 	    default:
   2045 	      gcc_unreachable ();
   2046 	    }
   2047 	  break;
   2048 	case ASHIFT:
   2049 	  switch (m)
   2050 	    {
   2051 	    case E_QImode:
   2052 	      output_asm_insn ("aslb\t%0", operands);
   2053 	      break;
   2054 	    case E_HImode:
   2055 	      output_asm_insn ("asl\t%0", operands);
   2056 	      break;
   2057 	    case E_SImode:
   2058 	      output_asm_insn ("asl\t%0", exops[1]);
   2059 	      output_asm_insn ("rol\t%0", exops[0]);
   2060 	      break;
   2061 	    default:
   2062 	      gcc_unreachable ();
   2063 	    }
   2064 	  break;
   2065 	}
   2066     }
   2067   if (!small)
   2068     {
   2069       /* Loop case, emit the count-down and branch if not done.  */
   2070       output_asm_insn ("dec\t%2", operands);
   2071       output_asm_insn ("bne\t%l0", lb);
   2072     }
   2073   return "";
   2074 }
   2075 
   2076 /* Figure out the length of the instructions that will be produced for
   2077    the given operands by pdp11_assemble_shift above.  */
   2078 int
   2079 pdp11_shift_length (rtx *operands, machine_mode m, int code, bool simple_operand_p)
   2080 {
   2081   int shift_size;
   2082 
   2083   /* Shift by 1 is 2 bytes if simple operand, 4 bytes if 2-word addressing mode.  */
   2084   shift_size = simple_operand_p ? 2 : 4;
   2085 
   2086   /* In SImode, two shifts are needed per data item.  */
   2087   if (m == E_SImode)
   2088     shift_size *= 2;
   2089 
   2090   /* If shifting by a small constant, the loop is unrolled by the
   2091      shift count.  Otherwise, account for the size of the decrement
   2092      and branch.  */
   2093   if (CONST_INT_P (operands[2]) && pdp11_small_shift (INTVAL (operands[2])))
   2094     shift_size *= INTVAL (operands[2]);
   2095   else
   2096     shift_size += 4;
   2097 
   2098   /* Logical right shift takes one more instruction (CLC).  */
   2099   if (code == LSHIFTRT)
   2100     shift_size += 2;
   2101 
   2102   return shift_size;
   2103 }
   2104 
   2105 /* Return the length of 2 or 4 word integer compares.  */
   2106 int
   2107 pdp11_cmp_length (rtx *operands, int words)
   2108 {
   2109   rtx inops[2];
   2110   rtx exops[4][2];
   2111   int i, len = 0;
   2112 
   2113   if (!reload_completed)
   2114     return 2;
   2115 
   2116   inops[0] = operands[0];
   2117   inops[1] = operands[1];
   2118 
   2119   pdp11_expand_operands (inops, exops, 2, words, NULL, big);
   2120 
   2121   for (i = 0; i < words; i++)
   2122     {
   2123       len += 4;    /* cmp instruction word and branch that follows.  */
   2124       if (!REG_P (exops[i][0]) &&
   2125 	  !simple_memory_operand (exops[i][0], HImode))
   2126 	len += 2;  /* first operand extra word.  */
   2127       if (!REG_P (exops[i][1]) &&
   2128 	  !simple_memory_operand (exops[i][1], HImode) &&
   2129 	  !(CONST_INT_P (exops[i][1]) && INTVAL (exops[i][1]) == 0))
   2130 	len += 2;  /* second operand extra word.  */
   2131     }
   2132 
   2133   /* Deduct one word because there is no branch at the end.  */
   2134   return len - 2;
   2135 }
   2136 
   2137 /* Prepend to CLOBBERS hard registers that are automatically clobbered
   2138    for an asm We do this for CC_REGNUM and FCC_REGNUM (on FPU target)
   2139    to maintain source compatibility with the original cc0-based
   2140    compiler.  */
   2141 
   2142 static rtx_insn *
   2143 pdp11_md_asm_adjust (vec<rtx> & /*outputs*/, vec<rtx> & /*inputs*/,
   2144 		     vec<machine_mode> & /*input_modes*/,
   2145 		     vec<const char *> & /*constraints*/, vec<rtx> &clobbers,
   2146 		     HARD_REG_SET &clobbered_regs, location_t /*loc*/)
   2147 {
   2148   clobbers.safe_push (gen_rtx_REG (CCmode, CC_REGNUM));
   2149   SET_HARD_REG_BIT (clobbered_regs, CC_REGNUM);
   2150   if (TARGET_FPU)
   2151     {
   2152       clobbers.safe_push (gen_rtx_REG (CCmode, FCC_REGNUM));
   2153       SET_HARD_REG_BIT (clobbered_regs, FCC_REGNUM);
   2154     }
   2155   return NULL;
   2156 }
   2157 
   2158 /* Worker function for TARGET_TRAMPOLINE_INIT.
   2159 
   2160    trampoline - how should i do it in separate i+d ?
   2161    have some allocate_trampoline magic???
   2162 
   2163    the following should work for shared I/D:
   2164 
   2165    MOV	#STATIC, $4	01270Y	0x0000 <- STATIC; Y = STATIC_CHAIN_REGNUM
   2166    JMP	@#FUNCTION	000137  0x0000 <- FUNCTION
   2167 */
   2168 static void
   2169 pdp11_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
   2170 {
   2171   rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
   2172   rtx mem;
   2173 
   2174   gcc_assert (!TARGET_SPLIT);
   2175 
   2176   mem = adjust_address (m_tramp, HImode, 0);
   2177   emit_move_insn (mem, GEN_INT (012700+STATIC_CHAIN_REGNUM));
   2178   mem = adjust_address (m_tramp, HImode, 2);
   2179   emit_move_insn (mem, chain_value);
   2180   mem = adjust_address (m_tramp, HImode, 4);
   2181   emit_move_insn (mem, GEN_INT (000137));
   2182   emit_move_insn (mem, fnaddr);
   2183 }
   2184 
   2185 /* Worker function for TARGET_FUNCTION_ARG.  */
   2186 
   2187 static rtx
   2188 pdp11_function_arg (cumulative_args_t, const function_arg_info &)
   2189 {
   2190   return NULL_RTX;
   2191 }
   2192 
   2193 /* Worker function for TARGET_FUNCTION_ARG_ADVANCE.
   2194 
   2195    Update the data in CUM to advance over argument ARG.  */
   2196 
   2197 static void
   2198 pdp11_function_arg_advance (cumulative_args_t cum_v,
   2199 			    const function_arg_info &arg)
   2200 {
   2201   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
   2202 
   2203   *cum += arg.promoted_size_in_bytes ();
   2204 }
   2205 
   2206 /* Make sure everything's fine if we *don't* have an FPU.
   2207    This assumes that putting a register in fixed_regs will keep the
   2208    compiler's mitts completely off it.  We don't bother to zero it out
   2209    of register classes.  Also fix incompatible register naming with
   2210    the UNIX assembler.  */
   2211 
   2212 static void
   2213 pdp11_conditional_register_usage (void)
   2214 {
   2215   int i;
   2216   HARD_REG_SET x;
   2217   if (!TARGET_FPU)
   2218     {
   2219       x = reg_class_contents[FPU_REGS];
   2220       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++ )
   2221        if (TEST_HARD_REG_BIT (x, i))
   2222 	fixed_regs[i] = call_used_regs[i] = 1;
   2223     }
   2224 
   2225   if (TARGET_AC0)
   2226       call_used_regs[AC0_REGNUM] = 1;
   2227   if (TARGET_UNIX_ASM)
   2228     {
   2229       /* Change names of FPU registers for the UNIX assembler.  */
   2230       reg_names[8] = "fr0";
   2231       reg_names[9] = "fr1";
   2232       reg_names[10] = "fr2";
   2233       reg_names[11] = "fr3";
   2234       reg_names[12] = "fr4";
   2235       reg_names[13] = "fr5";
   2236     }
   2237 }
   2238 
   2239 static section *
   2240 pdp11_function_section (tree decl ATTRIBUTE_UNUSED,
   2241 			enum node_frequency freq ATTRIBUTE_UNUSED,
   2242 			bool startup ATTRIBUTE_UNUSED,
   2243 			bool exit ATTRIBUTE_UNUSED)
   2244 {
   2245   return NULL;
   2246 }
   2247 
   2248 /* Support #ident for DEC assembler, but don't process the
   2249    auto-generated ident string that names the compiler (since its
   2250    syntax is not correct for DEC .ident).  */
   2251 static void pdp11_output_ident (const char *ident)
   2252 {
   2253   if (TARGET_DEC_ASM)
   2254     {
   2255       if (!startswith (ident, "GCC:"))
   2256 	fprintf (asm_out_file, "\t.ident\t\"%s\"\n", ident);
   2257     }
   2258 
   2259 }
   2260 
   2261 /* This emits a (user) label, which gets a "_" prefix except for DEC
   2262    assembler output.  */
   2263 void
   2264 pdp11_output_labelref (FILE *file, const char *name)
   2265 {
   2266   if (!TARGET_DEC_ASM)
   2267     fputs (USER_LABEL_PREFIX, file);
   2268   fputs (name, file);
   2269 }
   2270 
   2271 /* This equates name with value.  */
   2272 void
   2273 pdp11_output_def (FILE *file, const char *label1, const char *label2)
   2274 {
   2275   if (TARGET_DEC_ASM)
   2276     {
   2277       assemble_name (file, label1);
   2278       putc ('=', file);
   2279       assemble_name (file, label2);
   2280     }
   2281   else
   2282     {
   2283       fputs ("\t.set\t", file);
   2284       assemble_name (file, label1);
   2285       putc (',', file);
   2286       assemble_name (file, label2);
   2287     }
   2288   putc ('\n', file);
   2289 }
   2290 
   2291 void
   2292 pdp11_output_addr_vec_elt (FILE *file, int value)
   2293 {
   2294   char buf[256];
   2295 
   2296   pdp11_gen_int_label (buf, "L", value);
   2297   if (!TARGET_UNIX_ASM)
   2298     fprintf (file, "\t.word");
   2299   fprintf (file, "\t%s\n", buf + 1);
   2300 }
   2301 
   2302 /* This overrides some target hooks that are initializer elements so
   2303    they can't be variables in the #define.  */
   2304 static void
   2305 pdp11_option_override (void)
   2306 {
   2307   if (TARGET_DEC_ASM)
   2308     {
   2309       targetm.asm_out.open_paren  = "<";
   2310       targetm.asm_out.close_paren = ">";
   2311     }
   2312 }
   2313 
   2314 static void
   2315 pdp11_asm_named_section (const char *name, unsigned int flags,
   2316 			 tree decl ATTRIBUTE_UNUSED)
   2317 {
   2318   const char *rwro = (flags & SECTION_WRITE) ? "rw" : "ro";
   2319   const char *insdat = (flags & SECTION_CODE) ? "i" : "d";
   2320 
   2321   gcc_assert (TARGET_DEC_ASM);
   2322   fprintf (asm_out_file, "\t.psect\t%s,con,%s,%s\n", name, insdat, rwro);
   2323 }
   2324 
   2325 static void
   2326 pdp11_asm_init_sections (void)
   2327 {
   2328   if (TARGET_DEC_ASM)
   2329     {
   2330       bss_section = data_section;
   2331     }
   2332   else if (TARGET_GNU_ASM)
   2333     {
   2334       bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
   2335 					 output_section_asm_op,
   2336 					 ".bss");
   2337     }
   2338 }
   2339 
   2340 static void
   2341 pdp11_file_start (void)
   2342 {
   2343   default_file_start ();
   2344 
   2345   if (TARGET_DEC_ASM)
   2346     fprintf (asm_out_file, "\t.enabl\tlsb,reg\n\n");
   2347 }
   2348 
   2349 static void
   2350 pdp11_file_end (void)
   2351 {
   2352   if (TARGET_DEC_ASM)
   2353     fprintf (asm_out_file, "\t.end\n");
   2354 }
   2355 
   2356 /* Implement TARGET_LEGITIMATE_CONSTANT_P.  */
   2357 
   2358 static bool
   2359 pdp11_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
   2360 {
   2361   return GET_CODE (x) != CONST_DOUBLE || legitimate_const_double_p (x);
   2362 }
   2363 
   2364 /* Implement TARGET_SCALAR_MODE_SUPPORTED_P.  */
   2365 
   2366 static bool
   2367 pdp11_scalar_mode_supported_p (scalar_mode mode)
   2368 {
   2369   /* Support SFmode even with -mfloat64.  */
   2370   if (mode == SFmode)
   2371     return true;
   2372   return default_scalar_mode_supported_p (mode);
   2373 }
   2374 
   2375 /* Implement TARGET_HARD_REGNO_NREGS.  */
   2376 
   2377 static unsigned int
   2378 pdp11_hard_regno_nregs (unsigned int regno, machine_mode mode)
   2379 {
   2380   if (regno <= PC_REGNUM)
   2381     return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD);
   2382   return 1;
   2383 }
   2384 
   2385 /* Implement TARGET_HARD_REGNO_MODE_OK.  On the pdp, the cpu registers
   2386    can hold any mode other than float (because otherwise we may end up
   2387    being asked to move from CPU to FPU register, which isn't a valid
   2388    operation on the PDP11).  For CPU registers, check alignment.
   2389 
   2390    FPU accepts SF and DF but actually holds a DF - simplifies life!  */
   2391 
   2392 static bool
   2393 pdp11_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
   2394 {
   2395   if (regno <= PC_REGNUM)
   2396     return (GET_MODE_BITSIZE (mode) <= 16
   2397 	    || (GET_MODE_BITSIZE (mode) >= 32
   2398 		&& !(regno & 1)
   2399 		&& !FLOAT_MODE_P (mode)));
   2400 
   2401   return FLOAT_MODE_P (mode);
   2402 }
   2403 
   2404 /* Implement TARGET_MODES_TIEABLE_P.  */
   2405 
   2406 static bool
   2407 pdp11_modes_tieable_p (machine_mode mode1, machine_mode mode2)
   2408 {
   2409   return mode1 == HImode && mode2 == QImode;
   2410 }
   2411 
   2412 /* Implement PUSH_ROUNDING.  On the pdp11, the stack is on an even
   2413    boundary.  */
   2414 
   2415 poly_int64
   2416 pdp11_push_rounding (poly_int64 bytes)
   2417 {
   2418   return (bytes + 1) & ~1;
   2419 }
   2420 
   2421 struct gcc_target targetm = TARGET_INITIALIZER;
   2422