X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ir.h;h=6dcbd5a905044bbdcb58c5fc5ca49da0bb9c26f4;hp=5b948358fdee732766bf818a66653350460c823a;hb=380fb3d44fac96a0bef0962c7e6e526683501e86;hpb=4ff68e07e8cc5980c3f4be880d0e81f0bdba5e7c diff --git a/ir.h b/ir.h index 5b94835..6dcbd5a 100644 --- a/ir.h +++ b/ir.h @@ -1,25 +1,3 @@ -/* - * Copyright (C) 2012, 2013, 2014 - * Wolfgang Bumiller - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ #ifndef GMQCC_IR_HDR #define GMQCC_IR_HDR #include "gmqcc.h" @@ -30,76 +8,75 @@ */ typedef uint8_t ir_flag_t; -typedef struct ir_value_s ir_value; -typedef struct ir_instr_s ir_instr; -typedef struct ir_block_s ir_block; -typedef struct ir_function_s ir_function; -typedef struct ir_builder_s ir_builder; +struct ir_value; +struct ir_instr; +struct ir_block; +struct ir_function; +struct ir_builder; -typedef struct { +struct ir_life_entry_t { /* both inclusive */ size_t start; size_t end; -} ir_life_entry_t; +}; enum { - IR_FLAG_HAS_ARRAYS = 1 << 0, - IR_FLAG_HAS_UNINITIALIZED = 1 << 1, - IR_FLAG_HAS_GOTO = 1 << 2, - IR_FLAG_INCLUDE_DEF = 1 << 3, - IR_FLAG_ERASEABLE = 1 << 4, - IR_FLAG_BLOCK_COVERAGE = 1 << 5, + IR_FLAG_HAS_ARRAYS = 1 << 0, + IR_FLAG_HAS_UNINITIALIZED = 1 << 1, + IR_FLAG_HAS_GOTO = 1 << 2, + IR_FLAG_INCLUDE_DEF = 1 << 3, + IR_FLAG_ERASABLE = 1 << 4, + IR_FLAG_BLOCK_COVERAGE = 1 << 5, + + IR_FLAG_SPLIT_VECTOR = 1 << 6, IR_FLAG_LAST, IR_FLAG_MASK_NO_OVERLAP = (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED), IR_FLAG_MASK_NO_LOCAL_TEMPS = (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED) }; -struct ir_value_s { - char *name; - int vtype; - int store; - lex_ctx_t context; - - - int fieldtype; /* even the IR knows the subtype of a field */ - int outtype; /* and the output type of a function */ - int cvq; /* 'const' vs 'var' qualifier */ +struct ir_value { + char *name; + int vtype; + int store; + lex_ctx_t context; + int fieldtype; // even the IR knows the subtype of a field + int outtype; // and the output type of a function + int cvq; // 'const' vs 'var' qualifier ir_flag_t flags; - ir_instr **reads; - ir_instr **writes; + std::vector reads; + std::vector writes; - /* constantvalues */ + // constant values bool hasvalue; union { - qcfloat_t vfloat; - int vint; - vec3_t vvec; - int32_t ivec[3]; - char *vstring; - ir_value *vpointer; + qcfloat_t vfloat; + int vint; + vec3_t vvec; + int32_t ivec[3]; + char *vstring; + ir_value *vpointer; ir_function *vfunc; } constval; struct { int32_t globaladdr; int32_t name; - int32_t local; /* filled by the local-allocator */ - int32_t addroffset; /* added for members */ - int32_t fieldaddr; /* to generate field-addresses early */ + int32_t local; // filled by the local-allocator + int32_t addroffset; // added for members + int32_t fieldaddr; // to generate field-addresses early } code; - /* for acessing vectors */ + // for accessing vectors ir_value *members[3]; ir_value *memberof; - - bool unique_life; /* arrays will never overlap with temps */ - bool locked; /* temps living during a CALL must be locked */ + bool unique_life; // arrays will never overlap with temps + bool locked; // temps living during a CALL must be locked bool callparam; - ir_life_entry_t *life; /* For the temp allocator */ + ir_life_entry_t *life; // For the temp allocator }; /* @@ -118,49 +95,49 @@ bool ir_value_lives(ir_value*, size_t); void ir_value_dump_life(const ir_value *self, int (*oprintf)(const char*,...)); /* PHI data */ -typedef struct ir_phi_entry_s { +struct ir_phi_entry_t { ir_value *value; ir_block *from; -} ir_phi_entry_t; +}; /* instruction */ -struct ir_instr_s { - int opcode; - lex_ctx_t context; - ir_value* (_ops[3]); - ir_block* (bops[2]); +struct ir_instr { + int opcode; + lex_ctx_t context; + ir_value *(_ops[3]); + ir_block *(bops[2]); - ir_phi_entry_t *phi; - ir_value **params; + std::vector phi; + std::vector params; - /* For the temp-allocation */ + // For the temp-allocation size_t eid; - /* For IFs */ - bool likely; + // For IFs + bool likely; ir_block *owner; }; /* block */ -struct ir_block_s { - char *label; - lex_ctx_t context; - bool final; /* once a jump is added we're done */ +struct ir_block { + char *label; + lex_ctx_t context; + bool final; /* once a jump is added we're done */ ir_instr **instr; ir_block **entries; ir_block **exits; - ir_value **living; + std::vector living; /* For the temp-allocation */ size_t entry_id; size_t eid; - bool is_return; + bool is_return; ir_function *owner; - bool generated; + bool generated; size_t code_start; }; @@ -170,6 +147,7 @@ bool GMQCC_WARN ir_block_create_store_op(ir_block*, lex_ctx_t, int op, ir_value bool GMQCC_WARN ir_block_create_storep(ir_block*, lex_ctx_t, ir_value *target, ir_value *what); ir_value* ir_block_create_load_from_ent(ir_block*, lex_ctx_t, const char *label, ir_value *ent, ir_value *field, int outype); ir_value* ir_block_create_fieldaddress(ir_block*, lex_ctx_t, const char *label, ir_value *entity, ir_value *field); +bool GMQCC_WARN ir_block_create_state_op(ir_block*, lex_ctx_t, ir_value *frame, ir_value *think); /* This is to create an instruction of the form * %label := opcode a, b @@ -196,7 +174,7 @@ bool GMQCC_WARN ir_block_create_jump(ir_block*, lex_ctx_t, ir_block *to); bool GMQCC_WARN ir_block_create_goto(ir_block*, lex_ctx_t, ir_block *to); /* function */ -struct ir_function_s { +struct ir_function { char *name; int outtype; int *params; @@ -248,11 +226,12 @@ ir_block* ir_function_create_block(lex_ctx_t ctx, ir_function*, const char #define IR_HT_SIZE 1024 #define IR_MAX_VINSTR_TEMPS 1 -struct ir_builder_s { +struct ir_builder { char *name; ir_function **functions; ir_value **globals; ir_value **fields; + ir_value **const_floats; /* for reusing them in vector-splits, TODO: sort this or use a radix-tree */ ht htfunctions; ht htglobals;