138fd1498Szrj /* Definitions for code generation pass of GNU compiler.
238fd1498Szrj Copyright (C) 1987-2018 Free Software Foundation, Inc.
338fd1498Szrj
438fd1498Szrj This file is part of GCC.
538fd1498Szrj
638fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
738fd1498Szrj the terms of the GNU General Public License as published by the Free
838fd1498Szrj Software Foundation; either version 3, or (at your option) any later
938fd1498Szrj version.
1038fd1498Szrj
1138fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1238fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
1338fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1438fd1498Szrj for more details.
1538fd1498Szrj
1638fd1498Szrj You should have received a copy of the GNU General Public License
1738fd1498Szrj along with GCC; see the file COPYING3. If not see
1838fd1498Szrj <http://www.gnu.org/licenses/>. */
1938fd1498Szrj
2038fd1498Szrj #ifndef GCC_EXPR_H
2138fd1498Szrj #define GCC_EXPR_H
2238fd1498Szrj
2338fd1498Szrj /* This is the 4th arg to `expand_expr'.
2438fd1498Szrj EXPAND_STACK_PARM means we are possibly expanding a call param onto
2538fd1498Szrj the stack.
2638fd1498Szrj EXPAND_SUM means it is ok to return a PLUS rtx or MULT rtx.
2738fd1498Szrj EXPAND_INITIALIZER is similar but also record any labels on forced_labels.
2838fd1498Szrj EXPAND_CONST_ADDRESS means it is ok to return a MEM whose address
2938fd1498Szrj is a constant that is not a legitimate address.
3038fd1498Szrj EXPAND_WRITE means we are only going to write to the resulting rtx.
3138fd1498Szrj EXPAND_MEMORY means we are interested in a memory result, even if
3238fd1498Szrj the memory is constant and we could have propagated a constant value,
3338fd1498Szrj or the memory is unaligned on a STRICT_ALIGNMENT target. */
3438fd1498Szrj enum expand_modifier {EXPAND_NORMAL = 0, EXPAND_STACK_PARM, EXPAND_SUM,
3538fd1498Szrj EXPAND_CONST_ADDRESS, EXPAND_INITIALIZER, EXPAND_WRITE,
3638fd1498Szrj EXPAND_MEMORY};
3738fd1498Szrj
3838fd1498Szrj /* Prevent the compiler from deferring stack pops. See
3938fd1498Szrj inhibit_defer_pop for more information. */
4038fd1498Szrj #define NO_DEFER_POP (inhibit_defer_pop += 1)
4138fd1498Szrj
4238fd1498Szrj /* Allow the compiler to defer stack pops. See inhibit_defer_pop for
4338fd1498Szrj more information. */
4438fd1498Szrj #define OK_DEFER_POP (inhibit_defer_pop -= 1)
4538fd1498Szrj
4638fd1498Szrj /* This structure is used to pass around information about exploded
4738fd1498Szrj unary, binary and trinary expressions between expand_expr_real_1 and
4838fd1498Szrj friends. */
4938fd1498Szrj typedef struct separate_ops
5038fd1498Szrj {
5138fd1498Szrj enum tree_code code;
5238fd1498Szrj location_t location;
5338fd1498Szrj tree type;
5438fd1498Szrj tree op0, op1, op2;
5538fd1498Szrj } *sepops;
5638fd1498Szrj
5738fd1498Szrj /* This is run during target initialization to set up which modes can be
5838fd1498Szrj used directly in memory and to initialize the block move optab. */
5938fd1498Szrj extern void init_expr_target (void);
6038fd1498Szrj
6138fd1498Szrj /* This is run at the start of compiling a function. */
6238fd1498Szrj extern void init_expr (void);
6338fd1498Szrj
6438fd1498Szrj /* Emit some rtl insns to move data between rtx's, converting machine modes.
6538fd1498Szrj Both modes must be floating or both fixed. */
6638fd1498Szrj extern void convert_move (rtx, rtx, int);
6738fd1498Szrj
6838fd1498Szrj /* Convert an rtx to specified machine mode and return the result. */
6938fd1498Szrj extern rtx convert_to_mode (machine_mode, rtx, int);
7038fd1498Szrj
7138fd1498Szrj /* Convert an rtx to MODE from OLDMODE and return the result. */
7238fd1498Szrj extern rtx convert_modes (machine_mode, machine_mode, rtx, int);
7338fd1498Szrj
7438fd1498Szrj /* Expand a call to memcpy or memmove or memcmp, and return the result. */
7538fd1498Szrj extern rtx emit_block_op_via_libcall (enum built_in_function, rtx, rtx, rtx,
7638fd1498Szrj bool);
7738fd1498Szrj
7838fd1498Szrj static inline rtx
7938fd1498Szrj emit_block_copy_via_libcall (rtx dst, rtx src, rtx size, bool tailcall = false)
8038fd1498Szrj {
8138fd1498Szrj return emit_block_op_via_libcall (BUILT_IN_MEMCPY, dst, src, size, tailcall);
8238fd1498Szrj }
8338fd1498Szrj
8438fd1498Szrj static inline rtx
8538fd1498Szrj emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall = false)
8638fd1498Szrj {
8738fd1498Szrj return emit_block_op_via_libcall (BUILT_IN_MEMMOVE, dst, src, size, tailcall);
8838fd1498Szrj }
8938fd1498Szrj
9038fd1498Szrj static inline rtx
9138fd1498Szrj emit_block_comp_via_libcall (rtx dst, rtx src, rtx size, bool tailcall = false)
9238fd1498Szrj {
9338fd1498Szrj return emit_block_op_via_libcall (BUILT_IN_MEMCMP, dst, src, size, tailcall);
9438fd1498Szrj }
9538fd1498Szrj
9638fd1498Szrj /* Emit code to move a block Y to a block X. */
9738fd1498Szrj enum block_op_methods
9838fd1498Szrj {
9938fd1498Szrj BLOCK_OP_NORMAL,
10038fd1498Szrj BLOCK_OP_NO_LIBCALL,
10138fd1498Szrj BLOCK_OP_CALL_PARM,
10238fd1498Szrj /* Like BLOCK_OP_NORMAL, but the libcall can be tail call optimized. */
10338fd1498Szrj BLOCK_OP_TAILCALL,
10438fd1498Szrj /* Like BLOCK_OP_NO_LIBCALL, but instead of emitting a libcall return
10538fd1498Szrj pc_rtx to indicate nothing has been emitted and let the caller handle
10638fd1498Szrj it. */
10738fd1498Szrj BLOCK_OP_NO_LIBCALL_RET
10838fd1498Szrj };
10938fd1498Szrj
11038fd1498Szrj typedef rtx (*by_pieces_constfn) (void *, HOST_WIDE_INT, scalar_int_mode);
11138fd1498Szrj
11238fd1498Szrj extern rtx emit_block_move (rtx, rtx, rtx, enum block_op_methods);
11338fd1498Szrj extern rtx emit_block_move_hints (rtx, rtx, rtx, enum block_op_methods,
11438fd1498Szrj unsigned int, HOST_WIDE_INT,
11538fd1498Szrj unsigned HOST_WIDE_INT,
11638fd1498Szrj unsigned HOST_WIDE_INT,
11738fd1498Szrj unsigned HOST_WIDE_INT);
11838fd1498Szrj extern rtx emit_block_cmp_hints (rtx, rtx, rtx, tree, rtx, bool,
11938fd1498Szrj by_pieces_constfn, void *);
12038fd1498Szrj extern bool emit_storent_insn (rtx to, rtx from);
12138fd1498Szrj
12238fd1498Szrj /* Copy all or part of a value X into registers starting at REGNO.
12338fd1498Szrj The number of registers to be filled is NREGS. */
12438fd1498Szrj extern void move_block_to_reg (int, rtx, int, machine_mode);
12538fd1498Szrj
12638fd1498Szrj /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
12738fd1498Szrj The number of registers to be filled is NREGS. */
12838fd1498Szrj extern void move_block_from_reg (int, rtx, int);
12938fd1498Szrj
13038fd1498Szrj /* Generate a non-consecutive group of registers represented by a PARALLEL. */
13138fd1498Szrj extern rtx gen_group_rtx (rtx);
13238fd1498Szrj
13338fd1498Szrj /* Load a BLKmode value into non-consecutive registers represented by a
13438fd1498Szrj PARALLEL. */
13538fd1498Szrj extern void emit_group_load (rtx, rtx, tree, poly_int64);
13638fd1498Szrj
13738fd1498Szrj /* Similarly, but load into new temporaries. */
13838fd1498Szrj extern rtx emit_group_load_into_temps (rtx, rtx, tree, poly_int64);
13938fd1498Szrj
14038fd1498Szrj /* Move a non-consecutive group of registers represented by a PARALLEL into
14138fd1498Szrj a non-consecutive group of registers represented by a PARALLEL. */
14238fd1498Szrj extern void emit_group_move (rtx, rtx);
14338fd1498Szrj
14438fd1498Szrj /* Move a group of registers represented by a PARALLEL into pseudos. */
14538fd1498Szrj extern rtx emit_group_move_into_temps (rtx);
14638fd1498Szrj
14738fd1498Szrj /* Store a BLKmode value from non-consecutive registers represented by a
14838fd1498Szrj PARALLEL. */
14938fd1498Szrj extern void emit_group_store (rtx, rtx, tree, poly_int64);
15038fd1498Szrj
15138fd1498Szrj extern rtx maybe_emit_group_store (rtx, tree);
15238fd1498Szrj
15338fd1498Szrj /* Mark REG as holding a parameter for the next CALL_INSN.
15438fd1498Szrj Mode is TYPE_MODE of the non-promoted parameter, or VOIDmode. */
15538fd1498Szrj extern void use_reg_mode (rtx *, rtx, machine_mode);
15638fd1498Szrj extern void clobber_reg_mode (rtx *, rtx, machine_mode);
15738fd1498Szrj
15838fd1498Szrj extern rtx copy_blkmode_to_reg (machine_mode, tree);
15938fd1498Szrj
16038fd1498Szrj /* Mark REG as holding a parameter for the next CALL_INSN. */
16138fd1498Szrj static inline void
use_reg(rtx * fusage,rtx reg)16238fd1498Szrj use_reg (rtx *fusage, rtx reg)
16338fd1498Szrj {
16438fd1498Szrj use_reg_mode (fusage, reg, VOIDmode);
16538fd1498Szrj }
16638fd1498Szrj
16738fd1498Szrj /* Mark REG as clobbered by the call with FUSAGE as CALL_INSN_FUNCTION_USAGE. */
16838fd1498Szrj static inline void
clobber_reg(rtx * fusage,rtx reg)16938fd1498Szrj clobber_reg (rtx *fusage, rtx reg)
17038fd1498Szrj {
17138fd1498Szrj clobber_reg_mode (fusage, reg, VOIDmode);
17238fd1498Szrj }
17338fd1498Szrj
17438fd1498Szrj /* Mark NREGS consecutive regs, starting at REGNO, as holding parameters
17538fd1498Szrj for the next CALL_INSN. */
17638fd1498Szrj extern void use_regs (rtx *, int, int);
17738fd1498Szrj
17838fd1498Szrj /* Mark a PARALLEL as holding a parameter for the next CALL_INSN. */
17938fd1498Szrj extern void use_group_regs (rtx *, rtx);
18038fd1498Szrj
18138fd1498Szrj #ifdef GCC_INSN_CODES_H
18238fd1498Szrj extern rtx expand_cmpstrn_or_cmpmem (insn_code, rtx, rtx, rtx, tree, rtx,
18338fd1498Szrj HOST_WIDE_INT);
18438fd1498Szrj #endif
18538fd1498Szrj
18638fd1498Szrj /* Write zeros through the storage of OBJECT.
18738fd1498Szrj If OBJECT has BLKmode, SIZE is its length in bytes. */
18838fd1498Szrj extern rtx clear_storage (rtx, rtx, enum block_op_methods);
18938fd1498Szrj extern rtx clear_storage_hints (rtx, rtx, enum block_op_methods,
19038fd1498Szrj unsigned int, HOST_WIDE_INT,
19138fd1498Szrj unsigned HOST_WIDE_INT,
19238fd1498Szrj unsigned HOST_WIDE_INT,
19338fd1498Szrj unsigned HOST_WIDE_INT);
19438fd1498Szrj /* The same, but always output an library call. */
19538fd1498Szrj extern rtx set_storage_via_libcall (rtx, rtx, rtx, bool = false);
19638fd1498Szrj
19738fd1498Szrj /* Expand a setmem pattern; return true if successful. */
19838fd1498Szrj extern bool set_storage_via_setmem (rtx, rtx, rtx, unsigned int,
19938fd1498Szrj unsigned int, HOST_WIDE_INT,
20038fd1498Szrj unsigned HOST_WIDE_INT,
20138fd1498Szrj unsigned HOST_WIDE_INT,
20238fd1498Szrj unsigned HOST_WIDE_INT);
20338fd1498Szrj
20438fd1498Szrj /* Return nonzero if it is desirable to store LEN bytes generated by
20538fd1498Szrj CONSTFUN with several move instructions by store_by_pieces
20638fd1498Szrj function. CONSTFUNDATA is a pointer which will be passed as argument
20738fd1498Szrj in every CONSTFUN call.
20838fd1498Szrj ALIGN is maximum alignment we can assume.
20938fd1498Szrj MEMSETP is true if this is a real memset/bzero, not a copy
21038fd1498Szrj of a const string. */
21138fd1498Szrj extern int can_store_by_pieces (unsigned HOST_WIDE_INT,
21238fd1498Szrj by_pieces_constfn,
21338fd1498Szrj void *, unsigned int, bool);
21438fd1498Szrj
21538fd1498Szrj /* Generate several move instructions to store LEN bytes generated by
21638fd1498Szrj CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
21738fd1498Szrj pointer which will be passed as argument in every CONSTFUN call.
21838fd1498Szrj ALIGN is maximum alignment we can assume.
21938fd1498Szrj MEMSETP is true if this is a real memset/bzero, not a copy.
22038fd1498Szrj Returns TO + LEN. */
22138fd1498Szrj extern rtx store_by_pieces (rtx, unsigned HOST_WIDE_INT, by_pieces_constfn,
22238fd1498Szrj void *, unsigned int, bool, int);
22338fd1498Szrj
22438fd1498Szrj /* Emit insns to set X from Y. */
22538fd1498Szrj extern rtx_insn *emit_move_insn (rtx, rtx);
22638fd1498Szrj extern rtx_insn *gen_move_insn (rtx, rtx);
22738fd1498Szrj
22838fd1498Szrj /* Emit insns to set X from Y, with no frills. */
22938fd1498Szrj extern rtx_insn *emit_move_insn_1 (rtx, rtx);
23038fd1498Szrj
23138fd1498Szrj extern rtx_insn *emit_move_complex_push (machine_mode, rtx, rtx);
23238fd1498Szrj extern rtx_insn *emit_move_complex_parts (rtx, rtx);
23338fd1498Szrj extern rtx read_complex_part (rtx, bool);
23438fd1498Szrj extern void write_complex_part (rtx, rtx, bool);
23538fd1498Szrj extern rtx read_complex_part (rtx, bool);
23638fd1498Szrj extern rtx emit_move_resolve_push (machine_mode, rtx);
23738fd1498Szrj
23838fd1498Szrj /* Push a block of length SIZE (perhaps variable)
23938fd1498Szrj and return an rtx to address the beginning of the block. */
24038fd1498Szrj extern rtx push_block (rtx, poly_int64, int);
24138fd1498Szrj
24238fd1498Szrj /* Generate code to push something onto the stack, given its mode and type. */
24338fd1498Szrj extern bool emit_push_insn (rtx, machine_mode, tree, rtx, unsigned int,
24438fd1498Szrj int, rtx, poly_int64, rtx, rtx, int, rtx, bool);
24538fd1498Szrj
24638fd1498Szrj /* Extract the accessible bit-range from a COMPONENT_REF. */
24738fd1498Szrj extern void get_bit_range (poly_uint64_pod *, poly_uint64_pod *, tree,
24838fd1498Szrj poly_int64_pod *, tree *);
24938fd1498Szrj
25038fd1498Szrj /* Expand an assignment that stores the value of FROM into TO. */
25138fd1498Szrj extern void expand_assignment (tree, tree, bool);
25238fd1498Szrj
25338fd1498Szrj /* Generate code for computing expression EXP,
25438fd1498Szrj and storing the value into TARGET.
25538fd1498Szrj If SUGGEST_REG is nonzero, copy the value through a register
25638fd1498Szrj and return that register, if that is possible. */
25738fd1498Szrj extern rtx store_expr_with_bounds (tree, rtx, int, bool, bool, tree);
25838fd1498Szrj extern rtx store_expr (tree, rtx, int, bool, bool);
25938fd1498Szrj
26038fd1498Szrj /* Given an rtx that may include add and multiply operations,
26138fd1498Szrj generate them as insns and return a pseudo-reg containing the value.
26238fd1498Szrj Useful after calling expand_expr with 1 as sum_ok. */
26338fd1498Szrj extern rtx force_operand (rtx, rtx);
26438fd1498Szrj
26538fd1498Szrj /* Work horses for expand_expr. */
26638fd1498Szrj extern rtx expand_expr_real (tree, rtx, machine_mode,
26738fd1498Szrj enum expand_modifier, rtx *, bool);
26838fd1498Szrj extern rtx expand_expr_real_1 (tree, rtx, machine_mode,
26938fd1498Szrj enum expand_modifier, rtx *, bool);
27038fd1498Szrj extern rtx expand_expr_real_2 (sepops, rtx, machine_mode,
27138fd1498Szrj enum expand_modifier);
27238fd1498Szrj
27338fd1498Szrj /* Generate code for computing expression EXP.
27438fd1498Szrj An rtx for the computed value is returned. The value is never null.
27538fd1498Szrj In the case of a void EXP, const0_rtx is returned. */
27638fd1498Szrj static inline rtx
expand_expr(tree exp,rtx target,machine_mode mode,enum expand_modifier modifier)27738fd1498Szrj expand_expr (tree exp, rtx target, machine_mode mode,
27838fd1498Szrj enum expand_modifier modifier)
27938fd1498Szrj {
28038fd1498Szrj return expand_expr_real (exp, target, mode, modifier, NULL, false);
28138fd1498Szrj }
28238fd1498Szrj
28338fd1498Szrj static inline rtx
expand_normal(tree exp)28438fd1498Szrj expand_normal (tree exp)
28538fd1498Szrj {
28638fd1498Szrj return expand_expr_real (exp, NULL_RTX, VOIDmode, EXPAND_NORMAL, NULL, false);
28738fd1498Szrj }
28838fd1498Szrj
28938fd1498Szrj
29038fd1498Szrj /* Return the tree node and offset if a given argument corresponds to
29138fd1498Szrj a string constant. */
29238fd1498Szrj extern tree string_constant (tree, tree *);
29338fd1498Szrj
29438fd1498Szrj /* Two different ways of generating switch statements. */
29538fd1498Szrj extern int try_casesi (tree, tree, tree, tree, rtx, rtx, rtx, profile_probability);
29638fd1498Szrj extern int try_tablejump (tree, tree, tree, tree, rtx, rtx, profile_probability);
29738fd1498Szrj
29838fd1498Szrj extern int safe_from_p (const_rtx, tree, int);
29938fd1498Szrj
30038fd1498Szrj /* Get the personality libfunc for a function decl. */
30138fd1498Szrj rtx get_personality_function (tree);
30238fd1498Szrj
30338fd1498Szrj /* Determine whether the LEN bytes can be moved by using several move
30438fd1498Szrj instructions. Return nonzero if a call to move_by_pieces should
30538fd1498Szrj succeed. */
30638fd1498Szrj extern bool can_move_by_pieces (unsigned HOST_WIDE_INT, unsigned int);
30738fd1498Szrj
30838fd1498Szrj extern unsigned HOST_WIDE_INT highest_pow2_factor (const_tree);
30938fd1498Szrj
31038fd1498Szrj extern bool categorize_ctor_elements (const_tree, HOST_WIDE_INT *,
311*58e805e6Szrj HOST_WIDE_INT *, HOST_WIDE_INT *,
312*58e805e6Szrj bool *);
31338fd1498Szrj
31438fd1498Szrj extern void expand_operands (tree, tree, rtx, rtx*, rtx*,
31538fd1498Szrj enum expand_modifier);
31638fd1498Szrj
31738fd1498Szrj /* rtl.h and tree.h were included. */
31838fd1498Szrj /* Return an rtx for the size in bytes of the value of an expr. */
31938fd1498Szrj extern rtx expr_size (tree);
32038fd1498Szrj
32138fd1498Szrj #endif /* GCC_EXPR_H */
322