1;; Predicate description for RISC-V target. 2;; Copyright (C) 2011-2014 Free Software Foundation, Inc. 3;; Contributed by Andrew Waterman (waterman@cs.berkeley.edu) at UC Berkeley. 4;; Based on MIPS target for GNU compiler. 5;; 6;; This file is part of GCC. 7;; 8;; GCC is free software; you can redistribute it and/or modify 9;; it under the terms of the GNU General Public License as published by 10;; the Free Software Foundation; either version 3, or (at your option) 11;; any later version. 12;; 13;; GCC is distributed in the hope that it will be useful, 14;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16;; GNU General Public License for more details. 17;; 18;; You should have received a copy of the GNU General Public License 19;; along with GCC; see the file COPYING3. If not see 20;; <http://www.gnu.org/licenses/>. 21 22(define_predicate "const_arith_operand" 23 (and (match_code "const_int") 24 (match_test "SMALL_OPERAND (INTVAL (op))"))) 25 26(define_predicate "arith_operand" 27 (ior (match_operand 0 "const_arith_operand") 28 (match_operand 0 "register_operand"))) 29 30(define_predicate "sle_operand" 31 (and (match_code "const_int") 32 (match_test "SMALL_OPERAND (INTVAL (op) + 1)"))) 33 34(define_predicate "sleu_operand" 35 (and (match_operand 0 "sle_operand") 36 (match_test "INTVAL (op) + 1 != 0"))) 37 38(define_predicate "const_0_operand" 39 (and (match_code "const_int,const_double,const_vector") 40 (match_test "op == CONST0_RTX (GET_MODE (op))"))) 41 42(define_predicate "reg_or_0_operand" 43 (ior (match_operand 0 "const_0_operand") 44 (match_operand 0 "register_operand"))) 45 46(define_predicate "const_1_operand" 47 (and (match_code "const_int,const_double,const_vector") 48 (match_test "op == CONST1_RTX (GET_MODE (op))"))) 49 50(define_predicate "reg_or_1_operand" 51 (ior (match_operand 0 "const_1_operand") 52 (match_operand 0 "register_operand"))) 53 54;; This is used for indexing into vectors, and hence only accepts const_int. 55(define_predicate "const_0_or_1_operand" 56 (and (match_code "const_int") 57 (ior (match_test "op == CONST0_RTX (GET_MODE (op))") 58 (match_test "op == CONST1_RTX (GET_MODE (op))")))) 59 60(define_special_predicate "pc_or_label_operand" 61 (match_code "pc,label_ref")) 62 63;; A legitimate CONST_INT operand that takes more than one instruction 64;; to load. 65(define_predicate "splittable_const_int_operand" 66 (match_code "const_int") 67{ 68 /* Don't handle multi-word moves this way; we don't want to introduce 69 the individual word-mode moves until after reload. */ 70 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) 71 return false; 72 73 /* Otherwise check whether the constant can be loaded in a single 74 instruction. */ 75 return !LUI_INT (op) && !SMALL_INT (op); 76}) 77 78(define_predicate "move_operand" 79 (match_operand 0 "general_operand") 80{ 81 enum riscv_symbol_type symbol_type; 82 83 /* The thinking here is as follows: 84 85 (1) The move expanders should split complex load sequences into 86 individual instructions. Those individual instructions can 87 then be optimized by all rtl passes. 88 89 (2) The target of pre-reload load sequences should not be used 90 to store temporary results. If the target register is only 91 assigned one value, reload can rematerialize that value 92 on demand, rather than spill it to the stack. 93 94 (3) If we allowed pre-reload passes like combine and cse to recreate 95 complex load sequences, we would want to be able to split the 96 sequences before reload as well, so that the pre-reload scheduler 97 can see the individual instructions. This falls foul of (2); 98 the splitter would be forced to reuse the target register for 99 intermediate results. 100 101 (4) We want to define complex load splitters for combine. These 102 splitters can request a temporary scratch register, which avoids 103 the problem in (2). They allow things like: 104 105 (set (reg T1) (high SYM)) 106 (set (reg T2) (low (reg T1) SYM)) 107 (set (reg X) (plus (reg T2) (const_int OFFSET))) 108 109 to be combined into: 110 111 (set (reg T3) (high SYM+OFFSET)) 112 (set (reg X) (lo_sum (reg T3) SYM+OFFSET)) 113 114 if T2 is only used this once. */ 115 switch (GET_CODE (op)) 116 { 117 case CONST_INT: 118 return !splittable_const_int_operand (op, mode); 119 120 case CONST: 121 case SYMBOL_REF: 122 case LABEL_REF: 123 return (riscv_symbolic_constant_p (op, &symbol_type) 124 && !riscv_hi_relocs[symbol_type]); 125 126 case HIGH: 127 op = XEXP (op, 0); 128 return riscv_symbolic_constant_p (op, &symbol_type); 129 130 default: 131 return true; 132 } 133}) 134 135(define_predicate "consttable_operand" 136 (match_test "CONSTANT_P (op)")) 137 138(define_predicate "symbolic_operand" 139 (match_code "const,symbol_ref,label_ref") 140{ 141 enum riscv_symbol_type type; 142 return riscv_symbolic_constant_p (op, &type); 143}) 144 145(define_predicate "absolute_symbolic_operand" 146 (match_code "const,symbol_ref,label_ref") 147{ 148 enum riscv_symbol_type type; 149 return (riscv_symbolic_constant_p (op, &type) 150 && type == SYMBOL_ABSOLUTE); 151}) 152 153(define_predicate "plt_symbolic_operand" 154 (match_code "const,symbol_ref,label_ref") 155{ 156 enum riscv_symbol_type type; 157 return (riscv_symbolic_constant_p (op, &type) 158 && type == SYMBOL_GOT_DISP && !SYMBOL_REF_WEAK (op) && TARGET_PLT); 159}) 160 161(define_predicate "call_insn_operand" 162 (ior (match_operand 0 "absolute_symbolic_operand") 163 (match_operand 0 "plt_symbolic_operand") 164 (match_operand 0 "register_operand"))) 165 166(define_predicate "symbol_ref_operand" 167 (match_code "symbol_ref")) 168 169(define_predicate "modular_operator" 170 (match_code "plus,minus,mult,ashift")) 171 172(define_predicate "equality_operator" 173 (match_code "eq,ne")) 174 175(define_predicate "order_operator" 176 (match_code "eq,ne,lt,ltu,le,leu,ge,geu,gt,gtu")) 177 178(define_predicate "fp_order_operator" 179 (match_code "eq,lt,le,gt,ge")) 180 181(define_predicate "fp_unorder_operator" 182 (match_code "ordered,unordered")) 183