| 1 |
/* LoongArch static properties. |
| 2 |
Copyright (C) 2021-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Loongson Ltd. |
| 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 |
#include "config.h" |
| 22 |
#include "system.h" |
| 23 |
#include "coretypes.h" |
| 24 |
#include "tm.h" |
| 25 |
#include "rtl.h" |
| 26 |
|
| 27 |
#include "loongarch-def.h" |
| 28 |
#include "loongarch-str.h" |
| 29 |
|
| 30 |
template <class T, int N> |
| 31 |
using array = loongarch_def_array<T, N>; |
| 32 |
|
| 33 |
template <class T> |
| 34 |
using array_arch = array<T, N_ARCH_TYPES>; |
| 35 |
|
| 36 |
template <class T> |
| 37 |
using array_tune = array<T, N_TUNE_TYPES>; |
| 38 |
|
| 39 |
array_arch<const char *> loongarch_arch_strings = array_arch<const char *> () |
| 40 |
.set (ARCH_NATIVE, STR_CPU_NATIVE) |
| 41 |
.set (ARCH_ABI_DEFAULT, STR_ARCH_ABI_DEFAULT) |
| 42 |
.set (ARCH_LOONGARCH64, STR_CPU_LOONGARCH64) |
| 43 |
.set (ARCH_LA464, STR_CPU_LA464) |
| 44 |
.set (ARCH_LA664, STR_CPU_LA664) |
| 45 |
.set (ARCH_LA64V1_0, STR_ARCH_LA64V1_0) |
| 46 |
.set (ARCH_LA64V1_1, STR_ARCH_LA64V1_1); |
| 47 |
|
| 48 |
array_tune<const char *> loongarch_tune_strings = array_tune<const char *> () |
| 49 |
.set (TUNE_NATIVE, STR_CPU_NATIVE) |
| 50 |
.set (TUNE_GENERIC, STR_TUNE_GENERIC) |
| 51 |
.set (TUNE_LOONGARCH64, STR_CPU_LOONGARCH64) |
| 52 |
.set (TUNE_LA464, STR_CPU_LA464) |
| 53 |
.set (TUNE_LA664, STR_CPU_LA664); |
| 54 |
|
| 55 |
array_arch<loongarch_isa> loongarch_cpu_default_isa = |
| 56 |
array_arch<loongarch_isa> () |
| 57 |
.set (ARCH_LOONGARCH64, |
| 58 |
loongarch_isa () |
| 59 |
.base_ (ISA_BASE_LA64) |
| 60 |
.fpu_ (ISA_EXT_FPU64)) |
| 61 |
|
| 62 |
.set (ARCH_LA464, |
| 63 |
loongarch_isa () |
| 64 |
.base_ (ISA_BASE_LA64) |
| 65 |
.fpu_ (ISA_EXT_FPU64) |
| 66 |
.simd_ (ISA_EXT_SIMD_LASX)) |
| 67 |
|
| 68 |
.set (ARCH_LA664, |
| 69 |
loongarch_isa () |
| 70 |
.base_ (ISA_BASE_LA64) |
| 71 |
.fpu_ (ISA_EXT_FPU64) |
| 72 |
.simd_ (ISA_EXT_SIMD_LASX) |
| 73 |
.evolution_ (OPTION_MASK_ISA_DIV32 | OPTION_MASK_ISA_LD_SEQ_SA |
| 74 |
| OPTION_MASK_ISA_LAM_BH | OPTION_MASK_ISA_LAMCAS |
| 75 |
| OPTION_MASK_ISA_FRECIPE)) |
| 76 |
.set (ARCH_LA64V1_0, |
| 77 |
loongarch_isa () |
| 78 |
.base_ (ISA_BASE_LA64) |
| 79 |
.fpu_ (ISA_EXT_FPU64) |
| 80 |
.simd_ (ISA_EXT_SIMD_LSX)) |
| 81 |
|
| 82 |
.set (ARCH_LA64V1_1, |
| 83 |
loongarch_isa () |
| 84 |
.base_ (ISA_BASE_LA64) |
| 85 |
.fpu_ (ISA_EXT_FPU64) |
| 86 |
.simd_ (ISA_EXT_SIMD_LSX) |
| 87 |
.evolution_ (OPTION_MASK_ISA_DIV32 | OPTION_MASK_ISA_LD_SEQ_SA |
| 88 |
| OPTION_MASK_ISA_LAM_BH | OPTION_MASK_ISA_LAMCAS |
| 89 |
| OPTION_MASK_ISA_FRECIPE)); |
| 90 |
|
| 91 |
|
| 92 |
static inline loongarch_cache la464_cache () |
| 93 |
{ |
| 94 |
return loongarch_cache () |
| 95 |
.l1d_line_size_ (64) |
| 96 |
.l1d_size_ (64) |
| 97 |
.l2d_size_ (256) |
| 98 |
.simultaneous_prefetches_ (4); |
| 99 |
} |
| 100 |
|
| 101 |
array_tune<loongarch_cache> loongarch_cpu_cache = |
| 102 |
array_tune<loongarch_cache> () |
| 103 |
.set (TUNE_GENERIC, la464_cache ()) |
| 104 |
.set (TUNE_LOONGARCH64, la464_cache ()) |
| 105 |
.set (TUNE_LA464, la464_cache ()) |
| 106 |
.set (TUNE_LA664, la464_cache ()); |
| 107 |
|
| 108 |
static inline loongarch_align la464_align () |
| 109 |
{ |
| 110 |
return loongarch_align ().function_ ("32").loop_ ("8").jump_ ("32").label_ ("8"); |
| 111 |
} |
| 112 |
|
| 113 |
static inline loongarch_align la664_align () |
| 114 |
{ |
| 115 |
return loongarch_align ().function_ ("16").loop_ ("16").jump_ ("32").label_ ("8"); |
| 116 |
} |
| 117 |
|
| 118 |
array_tune<loongarch_align> loongarch_cpu_align = |
| 119 |
array_tune<loongarch_align> () |
| 120 |
.set (TUNE_GENERIC, la664_align ()) |
| 121 |
.set (TUNE_LOONGARCH64, la664_align ()) |
| 122 |
.set (TUNE_LA464, la464_align ()) |
| 123 |
.set (TUNE_LA664, la664_align ()); |
| 124 |
|
| 125 |
/* Default RTX cost initializer. */ |
| 126 |
loongarch_rtx_cost_data::loongarch_rtx_cost_data () |
| 127 |
: fp_add (COSTS_N_INSNS (5)), |
| 128 |
fp_mult_sf (COSTS_N_INSNS (5)), |
| 129 |
fp_mult_df (COSTS_N_INSNS (5)), |
| 130 |
fp_div_sf (COSTS_N_INSNS (8)), |
| 131 |
fp_div_df (COSTS_N_INSNS (8)), |
| 132 |
int_mult_si (COSTS_N_INSNS (4)), |
| 133 |
int_mult_di (COSTS_N_INSNS (4)), |
| 134 |
int_div_si (COSTS_N_INSNS (5)), |
| 135 |
int_div_di (COSTS_N_INSNS (5)), |
| 136 |
movcf2gr (COSTS_N_INSNS (7)), |
| 137 |
movgr2cf (COSTS_N_INSNS (15)), |
| 138 |
branch_cost (6), |
| 139 |
addr_reg_reg_cost (3), |
| 140 |
memory_latency (4) {} |
| 141 |
|
| 142 |
/* The following properties cannot be looked up directly using "cpucfg". |
| 143 |
So it is necessary to provide a default value for "unknown native" |
| 144 |
tune targets (i.e. -mtune=native while PRID does not correspond to |
| 145 |
any known "-mtune" type). */ |
| 146 |
array_tune<loongarch_rtx_cost_data> loongarch_cpu_rtx_cost_data = |
| 147 |
array_tune<loongarch_rtx_cost_data> () |
| 148 |
.set (TUNE_LA664, |
| 149 |
loongarch_rtx_cost_data () |
| 150 |
.movcf2gr_ (COSTS_N_INSNS (1)) |
| 151 |
.movgr2cf_ (COSTS_N_INSNS (1))); |
| 152 |
|
| 153 |
/* RTX costs to use when optimizing for size. |
| 154 |
We use a value slightly larger than COSTS_N_INSNS (1) for all of them |
| 155 |
because they are slower than simple instructions. */ |
| 156 |
#define COST_COMPLEX_INSN (COSTS_N_INSNS (1) + 1) |
| 157 |
const loongarch_rtx_cost_data loongarch_rtx_cost_optimize_size = |
| 158 |
loongarch_rtx_cost_data () |
| 159 |
.fp_add_ (COST_COMPLEX_INSN) |
| 160 |
.fp_mult_sf_ (COST_COMPLEX_INSN) |
| 161 |
.fp_mult_df_ (COST_COMPLEX_INSN) |
| 162 |
.fp_div_sf_ (COST_COMPLEX_INSN) |
| 163 |
.fp_div_df_ (COST_COMPLEX_INSN) |
| 164 |
.int_mult_si_ (COST_COMPLEX_INSN) |
| 165 |
.int_mult_di_ (COST_COMPLEX_INSN) |
| 166 |
.int_div_si_ (COST_COMPLEX_INSN) |
| 167 |
.int_div_di_ (COST_COMPLEX_INSN) |
| 168 |
.movcf2gr_ (COST_COMPLEX_INSN); |
| 169 |
|
| 170 |
array_tune<int> loongarch_cpu_issue_rate = array_tune<int> () |
| 171 |
.set (TUNE_NATIVE, 4) |
| 172 |
.set (TUNE_GENERIC, 4) |
| 173 |
.set (TUNE_LOONGARCH64, 4) |
| 174 |
.set (TUNE_LA464, 4) |
| 175 |
.set (TUNE_LA664, 6); |
| 176 |
|
| 177 |
array_tune<int> loongarch_cpu_multipass_dfa_lookahead = array_tune<int> () |
| 178 |
.set (TUNE_NATIVE, 4) |
| 179 |
.set (TUNE_GENERIC, 4) |
| 180 |
.set (TUNE_LOONGARCH64, 4) |
| 181 |
.set (TUNE_LA464, 4) |
| 182 |
.set (TUNE_LA664, 6); |
| 183 |
|
| 184 |
/* Wiring string definitions from loongarch-str.h to global arrays |
| 185 |
with standard index values from loongarch-opts.h, so we can |
| 186 |
print config-related messages and do ABI self-spec filtering |
| 187 |
from the driver in a self-consistent manner. */ |
| 188 |
|
| 189 |
array<const char *, N_ISA_BASE_TYPES> loongarch_isa_base_strings = |
| 190 |
array<const char *, N_ISA_BASE_TYPES> () |
| 191 |
.set (ISA_BASE_LA64, STR_ISA_BASE_LA64); |
| 192 |
|
| 193 |
array<const char *, N_ISA_EXT_TYPES> loongarch_isa_ext_strings = |
| 194 |
array<const char *, N_ISA_EXT_TYPES> () |
| 195 |
.set (ISA_EXT_NONE, STR_NONE) |
| 196 |
.set (ISA_EXT_FPU32, STR_ISA_EXT_FPU32) |
| 197 |
.set (ISA_EXT_FPU64, STR_ISA_EXT_FPU64) |
| 198 |
.set (ISA_EXT_SIMD_LSX, STR_ISA_EXT_LSX) |
| 199 |
.set (ISA_EXT_SIMD_LASX, STR_ISA_EXT_LASX); |
| 200 |
|
| 201 |
array<const char *, N_ABI_BASE_TYPES> loongarch_abi_base_strings = |
| 202 |
array<const char *, N_ABI_BASE_TYPES> () |
| 203 |
.set (ABI_BASE_LP64D, STR_ABI_BASE_LP64D) |
| 204 |
.set (ABI_BASE_LP64F, STR_ABI_BASE_LP64F) |
| 205 |
.set (ABI_BASE_LP64S, STR_ABI_BASE_LP64S); |
| 206 |
|
| 207 |
array<const char *, N_ABI_EXT_TYPES> loongarch_abi_ext_strings = |
| 208 |
array<const char *, N_ABI_EXT_TYPES> () |
| 209 |
.set (ABI_EXT_BASE, STR_ABI_EXT_BASE); |
| 210 |
|
| 211 |
array<const char *, N_CMODEL_TYPES> loongarch_cmodel_strings = |
| 212 |
array<const char *, N_CMODEL_TYPES> () |
| 213 |
.set (CMODEL_NORMAL, STR_CMODEL_NORMAL) |
| 214 |
.set (CMODEL_TINY, STR_CMODEL_TINY) |
| 215 |
.set (CMODEL_TINY_STATIC, STR_CMODEL_TS) |
| 216 |
.set (CMODEL_MEDIUM, STR_CMODEL_MEDIUM) |
| 217 |
.set (CMODEL_LARGE, STR_CMODEL_LARGE) |
| 218 |
.set (CMODEL_EXTREME, STR_CMODEL_EXTREME); |
| 219 |
|
| 220 |
array<array<loongarch_isa, N_ABI_EXT_TYPES>, N_ABI_BASE_TYPES> |
| 221 |
abi_minimal_isa = array<array<loongarch_isa, N_ABI_EXT_TYPES>, |
| 222 |
N_ABI_BASE_TYPES> () |
| 223 |
.set (ABI_BASE_LP64D, |
| 224 |
array<loongarch_isa, N_ABI_EXT_TYPES> () |
| 225 |
.set (ABI_EXT_BASE, |
| 226 |
loongarch_isa () |
| 227 |
.base_ (ISA_BASE_LA64) |
| 228 |
.fpu_ (ISA_EXT_FPU64))) |
| 229 |
.set (ABI_BASE_LP64F, |
| 230 |
array<loongarch_isa, N_ABI_EXT_TYPES> () |
| 231 |
.set (ABI_EXT_BASE, |
| 232 |
loongarch_isa () |
| 233 |
.base_ (ISA_BASE_LA64) |
| 234 |
.fpu_ (ISA_EXT_FPU32))) |
| 235 |
.set (ABI_BASE_LP64S, |
| 236 |
array<loongarch_isa, N_ABI_EXT_TYPES> () |
| 237 |
.set (ABI_EXT_BASE, |
| 238 |
loongarch_isa ().base_ (ISA_BASE_LA64))); |