| 1 |
/* Definitions for microarchitecture-related data structures. |
| 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 |
#ifndef LOONGARCH_TUNE_H |
| 22 |
#define LOONGARCH_TUNE_H |
| 23 |
|
| 24 |
#include "loongarch-def-array.h" |
| 25 |
|
| 26 |
/* RTX costs of various operations on the different architectures. */ |
| 27 |
struct loongarch_rtx_cost_data |
| 28 |
{ |
| 29 |
unsigned short fp_add; |
| 30 |
unsigned short fp_mult_sf; |
| 31 |
unsigned short fp_mult_df; |
| 32 |
unsigned short fp_div_sf; |
| 33 |
unsigned short fp_div_df; |
| 34 |
unsigned short int_mult_si; |
| 35 |
unsigned short int_mult_di; |
| 36 |
unsigned short int_div_si; |
| 37 |
unsigned short int_div_di; |
| 38 |
unsigned short movcf2gr; |
| 39 |
unsigned short movgr2cf; |
| 40 |
unsigned short branch_cost; |
| 41 |
unsigned short addr_reg_reg_cost; |
| 42 |
unsigned short memory_latency; |
| 43 |
|
| 44 |
/* Default RTX cost initializer, implemented in loongarch-def.cc. */ |
| 45 |
loongarch_rtx_cost_data (); |
| 46 |
|
| 47 |
loongarch_rtx_cost_data fp_add_ (unsigned short _fp_add) |
| 48 |
{ |
| 49 |
fp_add = _fp_add; |
| 50 |
return *this; |
| 51 |
} |
| 52 |
|
| 53 |
loongarch_rtx_cost_data fp_mult_sf_ (unsigned short _fp_mult_sf) |
| 54 |
{ |
| 55 |
fp_mult_sf = _fp_mult_sf; |
| 56 |
return *this; |
| 57 |
} |
| 58 |
|
| 59 |
loongarch_rtx_cost_data fp_mult_df_ (unsigned short _fp_mult_df) |
| 60 |
{ |
| 61 |
fp_mult_df = _fp_mult_df; |
| 62 |
return *this; |
| 63 |
} |
| 64 |
|
| 65 |
loongarch_rtx_cost_data fp_div_sf_ (unsigned short _fp_div_sf) |
| 66 |
{ |
| 67 |
fp_div_sf = _fp_div_sf; |
| 68 |
return *this; |
| 69 |
} |
| 70 |
|
| 71 |
loongarch_rtx_cost_data fp_div_df_ (unsigned short _fp_div_df) |
| 72 |
{ |
| 73 |
fp_div_df = _fp_div_df; |
| 74 |
return *this; |
| 75 |
} |
| 76 |
|
| 77 |
loongarch_rtx_cost_data int_mult_si_ (unsigned short _int_mult_si) |
| 78 |
{ |
| 79 |
int_mult_si = _int_mult_si; |
| 80 |
return *this; |
| 81 |
} |
| 82 |
|
| 83 |
loongarch_rtx_cost_data int_mult_di_ (unsigned short _int_mult_di) |
| 84 |
{ |
| 85 |
int_mult_di = _int_mult_di; |
| 86 |
return *this; |
| 87 |
} |
| 88 |
|
| 89 |
loongarch_rtx_cost_data int_div_si_ (unsigned short _int_div_si) |
| 90 |
{ |
| 91 |
int_div_si = _int_div_si; |
| 92 |
return *this; |
| 93 |
} |
| 94 |
|
| 95 |
loongarch_rtx_cost_data int_div_di_ (unsigned short _int_div_di) |
| 96 |
{ |
| 97 |
int_div_di = _int_div_di; |
| 98 |
return *this; |
| 99 |
} |
| 100 |
|
| 101 |
loongarch_rtx_cost_data movcf2gr_ (unsigned short _movcf2gr) |
| 102 |
{ |
| 103 |
movcf2gr = _movcf2gr; |
| 104 |
return *this; |
| 105 |
} |
| 106 |
|
| 107 |
loongarch_rtx_cost_data movgr2cf_ (unsigned short _movgr2cf) |
| 108 |
{ |
| 109 |
movgr2cf = _movgr2cf; |
| 110 |
return *this; |
| 111 |
} |
| 112 |
|
| 113 |
loongarch_rtx_cost_data branch_cost_ (unsigned short _branch_cost) |
| 114 |
{ |
| 115 |
branch_cost = _branch_cost; |
| 116 |
return *this; |
| 117 |
} |
| 118 |
|
| 119 |
loongarch_rtx_cost_data addr_reg_reg_cost_ (unsigned short _addr_reg_reg_cost) |
| 120 |
{ |
| 121 |
addr_reg_reg_cost = _addr_reg_reg_cost; |
| 122 |
return *this; |
| 123 |
} |
| 124 |
|
| 125 |
loongarch_rtx_cost_data memory_latency_ (unsigned short _memory_latency) |
| 126 |
{ |
| 127 |
memory_latency = _memory_latency; |
| 128 |
return *this; |
| 129 |
} |
| 130 |
}; |
| 131 |
|
| 132 |
/* Costs to use when optimizing for size. */ |
| 133 |
extern const struct loongarch_rtx_cost_data loongarch_rtx_cost_optimize_size; |
| 134 |
|
| 135 |
/* Cache size record of known processor models. */ |
| 136 |
struct loongarch_cache { |
| 137 |
int l1d_line_size; /* bytes */ |
| 138 |
int l1d_size; /* KiB */ |
| 139 |
int l2d_size; /* kiB */ |
| 140 |
int simultaneous_prefetches; /* number of parallel prefetch */ |
| 141 |
|
| 142 |
loongarch_cache () : l1d_line_size (0), |
| 143 |
l1d_size (0), |
| 144 |
l2d_size (0), |
| 145 |
simultaneous_prefetches (0) {} |
| 146 |
|
| 147 |
loongarch_cache l1d_line_size_ (int _l1d_line_size) |
| 148 |
{ |
| 149 |
l1d_line_size = _l1d_line_size; |
| 150 |
return *this; |
| 151 |
} |
| 152 |
|
| 153 |
loongarch_cache l1d_size_ (int _l1d_size) |
| 154 |
{ |
| 155 |
l1d_size = _l1d_size; |
| 156 |
return *this; |
| 157 |
} |
| 158 |
|
| 159 |
loongarch_cache l2d_size_ (int _l2d_size) |
| 160 |
{ |
| 161 |
l2d_size = _l2d_size; |
| 162 |
return *this; |
| 163 |
} |
| 164 |
|
| 165 |
loongarch_cache simultaneous_prefetches_ (int _simultaneous_prefetches) |
| 166 |
{ |
| 167 |
simultaneous_prefetches = _simultaneous_prefetches; |
| 168 |
return *this; |
| 169 |
} |
| 170 |
}; |
| 171 |
|
| 172 |
/* Alignment for functions loops and jumps for best performance. For new |
| 173 |
uarchs the value should be measured via benchmarking. See the |
| 174 |
documentation for -falign-functions, -falign-loops, and -falign-jumps in |
| 175 |
invoke.texi for the format. */ |
| 176 |
struct loongarch_align { |
| 177 |
const char *function; /* default value for -falign-functions */ |
| 178 |
const char *loop; /* default value for -falign-loops */ |
| 179 |
const char *jump; /* default value for -falign-jumps */ |
| 180 |
const char *label; /* default value for -falign-labels */ |
| 181 |
|
| 182 |
loongarch_align () : function (nullptr), loop (nullptr), jump (nullptr), label (nullptr) {} |
| 183 |
|
| 184 |
loongarch_align function_ (const char *_function) |
| 185 |
{ |
| 186 |
function = _function; |
| 187 |
return *this; |
| 188 |
} |
| 189 |
|
| 190 |
loongarch_align loop_ (const char *_loop) |
| 191 |
{ |
| 192 |
loop = _loop; |
| 193 |
return *this; |
| 194 |
} |
| 195 |
|
| 196 |
loongarch_align jump_ (const char *_jump) |
| 197 |
{ |
| 198 |
jump = _jump; |
| 199 |
return *this; |
| 200 |
} |
| 201 |
|
| 202 |
loongarch_align label_ (const char *_label) |
| 203 |
{ |
| 204 |
label = _label; |
| 205 |
return *this; |
| 206 |
} |
| 207 |
}; |
| 208 |
|
| 209 |
#endif /* LOONGARCH_TUNE_H */ |