1 /* 2 * Copyright © Microsoft Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24 #ifndef DXIL_INTERNAL_H 25 #define DXIL_INTERNAL_H 26 27 #include "dxil_module.h" 28 29 #include "util/list.h" 30 31 #include <stdint.h> 32 33 // Malloc.h defines a macro for alloca. Let's at least make sure that all includers 34 // of this header have the same definition of alloca. 35 #include <malloc.h> 36 37 struct dxil_type_list { 38 struct dxil_type **types; 39 size_t num_types; 40 }; 41 42 struct dxil_type { 43 enum type_type { 44 TYPE_VOID, 45 TYPE_INTEGER, 46 TYPE_FLOAT, 47 TYPE_POINTER, 48 TYPE_STRUCT, 49 TYPE_ARRAY, 50 TYPE_VECTOR, 51 TYPE_FUNCTION 52 } type; 53 54 union { 55 unsigned int_bits; 56 unsigned float_bits; 57 const struct dxil_type *ptr_target_type; 58 struct { 59 const char *name; 60 struct dxil_type_list elem; 61 } struct_def; 62 struct { 63 const struct dxil_type *ret_type; 64 struct dxil_type_list args; 65 } function_def; 66 struct { 67 const struct dxil_type *elem_type; 68 size_t num_elems; 69 } array_or_vector_def; 70 }; 71 72 struct list_head head; 73 unsigned id; 74 }; 75 76 struct dxil_value { 77 int id; 78 const struct dxil_type *type; 79 }; 80 81 struct dxil_gvar { 82 const char *name; 83 const struct dxil_type *type; 84 bool constant; 85 enum dxil_address_space as; 86 int align; 87 88 const struct dxil_value *initializer; 89 struct dxil_value value; 90 struct list_head head; 91 }; 92 93 struct dxil_func { 94 char *name; 95 const struct dxil_type *type; 96 bool decl; 97 unsigned attr_set; 98 99 struct dxil_value value; 100 struct list_head head; 101 }; 102 103 struct dxil_attrib { 104 enum { 105 DXIL_ATTR_ENUM, 106 DXIL_ATTR_ENUM_VALUE, 107 DXIL_ATTR_STRING = 3, 108 DXIL_ATTR_STRING_VALUE, 109 } type; 110 111 union { 112 enum dxil_attr_kind kind; 113 const char *str; 114 } key; 115 union { 116 uint64_t integer; 117 const char *str; 118 } value; 119 }; 120 121 struct attrib_set { 122 struct dxil_attrib attrs[2]; 123 unsigned num_attrs; 124 struct list_head head; 125 }; 126 127 struct dxil_instr_binop { 128 enum dxil_bin_opcode opcode; 129 const struct dxil_value *operands[2]; 130 enum dxil_opt_flags flags; 131 }; 132 133 struct dxil_instr_cmp { 134 enum dxil_cmp_pred pred; 135 const struct dxil_value *operands[2]; 136 }; 137 138 struct dxil_instr_select { 139 const struct dxil_value *operands[3]; 140 }; 141 142 struct dxil_instr_cast { 143 enum dxil_cast_opcode opcode; 144 const struct dxil_type *type; 145 const struct dxil_value *value; 146 }; 147 148 struct dxil_instr_call { 149 const struct dxil_func *func; 150 struct dxil_value **args; 151 size_t num_args; 152 }; 153 154 struct dxil_instr_ret { 155 struct dxil_value *value; 156 }; 157 158 struct dxil_instr_extractval { 159 const struct dxil_value *src; 160 const struct dxil_type *type; 161 unsigned int idx; 162 }; 163 164 struct dxil_instr_br { 165 const struct dxil_value *cond; 166 unsigned succ[2]; 167 }; 168 169 struct dxil_instr_phi { 170 const struct dxil_type *type; 171 struct dxil_phi_src { 172 const struct dxil_value *value; 173 unsigned block; 174 } *incoming; 175 size_t num_incoming; 176 }; 177 178 struct dxil_instr_alloca { 179 const struct dxil_type *alloc_type; 180 const struct dxil_type *size_type; 181 const struct dxil_value *size; 182 unsigned align; 183 }; 184 185 struct dxil_instr_gep { 186 bool inbounds; 187 const struct dxil_type *source_elem_type; 188 struct dxil_value **operands; 189 size_t num_operands; 190 }; 191 192 struct dxil_instr_load { 193 const struct dxil_value *ptr; 194 const struct dxil_type *type; 195 unsigned align; 196 bool is_volatile; 197 }; 198 199 struct dxil_instr_store { 200 const struct dxil_value *value, *ptr; 201 unsigned align; 202 bool is_volatile; 203 }; 204 205 struct dxil_instr_atomicrmw { 206 const struct dxil_value *value, *ptr; 207 enum dxil_rmw_op op; 208 bool is_volatile; 209 enum dxil_atomic_ordering ordering; 210 enum dxil_sync_scope syncscope; 211 }; 212 213 struct dxil_instr_cmpxchg { 214 const struct dxil_value *cmpval, *newval, *ptr; 215 bool is_volatile; 216 enum dxil_atomic_ordering ordering; 217 enum dxil_sync_scope syncscope; 218 }; 219 220 struct dxil_instr { 221 enum instr_type { 222 INSTR_BINOP, 223 INSTR_CMP, 224 INSTR_SELECT, 225 INSTR_CAST, 226 INSTR_BR, 227 INSTR_PHI, 228 INSTR_CALL, 229 INSTR_RET, 230 INSTR_EXTRACTVAL, 231 INSTR_ALLOCA, 232 INSTR_GEP, 233 INSTR_LOAD, 234 INSTR_STORE, 235 INSTR_ATOMICRMW, 236 INSTR_CMPXCHG, 237 } type; 238 239 union { 240 struct dxil_instr_binop binop; 241 struct dxil_instr_cmp cmp; 242 struct dxil_instr_select select; 243 struct dxil_instr_cast cast; 244 struct dxil_instr_call call; 245 struct dxil_instr_ret ret; 246 struct dxil_instr_extractval extractval; 247 struct dxil_instr_phi phi; 248 struct dxil_instr_br br; 249 struct dxil_instr_alloca alloca; 250 struct dxil_instr_gep gep; 251 struct dxil_instr_load load; 252 struct dxil_instr_store store; 253 struct dxil_instr_atomicrmw atomicrmw; 254 struct dxil_instr_cmpxchg cmpxchg; 255 }; 256 257 bool has_value; 258 struct dxil_value value; 259 260 struct list_head head; 261 }; 262 263 struct dxil_const { 264 struct dxil_value value; 265 266 bool undef; 267 union { 268 intmax_t int_value; 269 double float_value; 270 const struct dxil_value **array_values; 271 const struct dxil_value **struct_values; 272 const struct dxil_value **vector_values; 273 }; 274 275 struct list_head head; 276 }; 277 278 struct dxil_mdnode { 279 enum mdnode_type { 280 MD_STRING, 281 MD_VALUE, 282 MD_NODE 283 } type; 284 285 union { 286 char *string; 287 288 struct { 289 const struct dxil_type *type; 290 const struct dxil_value *value; 291 } value; 292 293 struct { 294 const struct dxil_mdnode **subnodes; 295 size_t num_subnodes; 296 } node; 297 }; 298 299 struct list_head head; 300 unsigned id; 301 }; 302 303 struct dxil_named_node { 304 char *name; 305 const struct dxil_mdnode **subnodes; 306 size_t num_subnodes; 307 struct list_head head; 308 }; 309 310 #endif // DXIL_INTERNAL_H 311