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