From 6df3c625b0f8501b2ed2ecc61e29d104f28f84b8 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 11 Jan 2013 19:15:59 +0100 Subject: [PATCH] Added a flag to both ast and ir which enforces the generation of a globaldef for a value --- ast.c | 14 ++++++++++++++ ast.h | 1 + ir.c | 2 ++ ir.h | 2 ++ 4 files changed, 19 insertions(+) diff --git a/ast.c b/ast.c index 2b4a456..995ba09 100644 --- a/ast.c +++ b/ast.c @@ -1164,6 +1164,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) self->constval.vfunc->ir_func = func; self->ir_v = func->value; + if (self->expression.flags & AST_FLAG_INCLUDE_DEF) + self->ir_v->flags |= IR_FLAG_INCLUDE_DEF; /* The function is filled later on ast_function_codegen... */ return true; } @@ -1206,6 +1208,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) v->unique_life = true; v->locked = true; array->ir_v = self->ir_v = v; + if (self->expression.flags & AST_FLAG_INCLUDE_DEF) + self->ir_v->flags |= IR_FLAG_INCLUDE_DEF; namelen = strlen(self->name); name = (char*)mem_a(namelen + 16); @@ -1224,6 +1228,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) array->ir_values[ai]->context = ast_ctx(self); array->ir_values[ai]->unique_life = true; array->ir_values[ai]->locked = true; + if (self->expression.flags & AST_FLAG_INCLUDE_DEF) + self->ir_values[ai]->flags |= IR_FLAG_INCLUDE_DEF; } mem_d(name); } @@ -1234,6 +1240,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) return false; v->context = ast_ctx(self); self->ir_v = v; + if (self->expression.flags & AST_FLAG_INCLUDE_DEF) + self->ir_v->flags |= IR_FLAG_INCLUDE_DEF; } return true; } @@ -1258,6 +1266,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) v->context = ast_ctx(self); v->unique_life = true; v->locked = true; + if (self->expression.flags & AST_FLAG_INCLUDE_DEF) + v->flags |= IR_FLAG_INCLUDE_DEF; namelen = strlen(self->name); name = (char*)mem_a(namelen + 16); @@ -1276,6 +1286,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) self->ir_values[ai]->context = ast_ctx(self); self->ir_values[ai]->unique_life = true; self->ir_values[ai]->locked = true; + if (self->expression.flags & AST_FLAG_INCLUDE_DEF) + self->ir_values[ai]->flags |= IR_FLAG_INCLUDE_DEF; } mem_d(name); } @@ -1338,6 +1350,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) /* link us to the ir_value */ v->cvq = self->cvq; self->ir_v = v; + if (self->expression.flags & AST_FLAG_INCLUDE_DEF) + self->ir_v->flags |= IR_FLAG_INCLUDE_DEF; return true; error: /* clean up */ diff --git a/ast.h b/ast.h index ce69810..37bbf02 100644 --- a/ast.h +++ b/ast.h @@ -145,6 +145,7 @@ typedef struct #define AST_FLAG_INLINE (1<<2) #define AST_FLAG_INITIALIZED (1<<3) #define AST_FLAG_DEPRECATED (1<<4) +#define AST_FLAG_INCLUDE_DEF (1<<5) #define AST_FLAG_TYPE_MASK (AST_FLAG_VARIADIC | AST_FLAG_NORETURN) /* Value diff --git a/ir.c b/ir.c index 420ef93..5461b44 100644 --- a/ir.c +++ b/ir.c @@ -1018,6 +1018,7 @@ ir_value* ir_value_var(const char *name, int storetype, int vtype) self->fieldtype = TYPE_VOID; self->outtype = TYPE_VOID; self->store = storetype; + self->flags = 0; self->reads = NULL; self->writes = NULL; @@ -3323,6 +3324,7 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool isloc pushdef = true; if (OPTS_OPTIMIZATION(OPTIM_STRIP_CONSTANT_NAMES) && + !(global->flags & IR_FLAG_INCLUDE_DEF) && (global->name[0] == '#' || global->cvq == CV_CONST)) { pushdef = false; diff --git a/ir.h b/ir.h index a241ad5..9a953a6 100644 --- a/ir.h +++ b/ir.h @@ -44,6 +44,7 @@ typedef struct ir_value_s { int outtype; /* 'const' vs 'var' qualifier */ int cvq; + uint32_t flags; struct ir_instr_s **reads; struct ir_instr_s **writes; @@ -276,6 +277,7 @@ typedef struct ir_function_s #define IR_FLAG_HAS_ARRAYS (1<<1) #define IR_FLAG_HAS_UNINITIALIZED (1<<2) #define IR_FLAG_HAS_GOTO (1<<3) +#define IR_FLAG_INCLUDE_DEF (1<<4) #define IR_FLAG_MASK_NO_OVERLAP (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED) ir_function* ir_function_new(struct ir_builder_s *owner, int returntype); -- 2.39.2