Added a flag to both ast and ir which enforces the generation of a globaldef for a value

This commit is contained in:
Wolfgang Bumiller 2013-01-11 19:15:59 +01:00
parent 5ea710e317
commit 6df3c625b0
4 changed files with 19 additions and 0 deletions

14
ast.c
View file

@ -1164,6 +1164,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
self->constval.vfunc->ir_func = func; self->constval.vfunc->ir_func = func;
self->ir_v = func->value; 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... */ /* The function is filled later on ast_function_codegen... */
return true; return true;
} }
@ -1206,6 +1208,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
v->unique_life = true; v->unique_life = true;
v->locked = true; v->locked = true;
array->ir_v = self->ir_v = v; 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); namelen = strlen(self->name);
name = (char*)mem_a(namelen + 16); 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]->context = ast_ctx(self);
array->ir_values[ai]->unique_life = true; array->ir_values[ai]->unique_life = true;
array->ir_values[ai]->locked = 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); mem_d(name);
} }
@ -1234,6 +1240,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
return false; return false;
v->context = ast_ctx(self); v->context = ast_ctx(self);
self->ir_v = v; self->ir_v = v;
if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
} }
return true; return true;
} }
@ -1258,6 +1266,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
v->context = ast_ctx(self); v->context = ast_ctx(self);
v->unique_life = true; v->unique_life = true;
v->locked = true; v->locked = true;
if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
v->flags |= IR_FLAG_INCLUDE_DEF;
namelen = strlen(self->name); namelen = strlen(self->name);
name = (char*)mem_a(namelen + 16); 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]->context = ast_ctx(self);
self->ir_values[ai]->unique_life = true; self->ir_values[ai]->unique_life = true;
self->ir_values[ai]->locked = 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); 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 */ /* link us to the ir_value */
v->cvq = self->cvq; v->cvq = self->cvq;
self->ir_v = v; self->ir_v = v;
if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
return true; return true;
error: /* clean up */ error: /* clean up */

1
ast.h
View file

@ -145,6 +145,7 @@ typedef struct
#define AST_FLAG_INLINE (1<<2) #define AST_FLAG_INLINE (1<<2)
#define AST_FLAG_INITIALIZED (1<<3) #define AST_FLAG_INITIALIZED (1<<3)
#define AST_FLAG_DEPRECATED (1<<4) #define AST_FLAG_DEPRECATED (1<<4)
#define AST_FLAG_INCLUDE_DEF (1<<5)
#define AST_FLAG_TYPE_MASK (AST_FLAG_VARIADIC | AST_FLAG_NORETURN) #define AST_FLAG_TYPE_MASK (AST_FLAG_VARIADIC | AST_FLAG_NORETURN)
/* Value /* Value

2
ir.c
View file

@ -1018,6 +1018,7 @@ ir_value* ir_value_var(const char *name, int storetype, int vtype)
self->fieldtype = TYPE_VOID; self->fieldtype = TYPE_VOID;
self->outtype = TYPE_VOID; self->outtype = TYPE_VOID;
self->store = storetype; self->store = storetype;
self->flags = 0;
self->reads = NULL; self->reads = NULL;
self->writes = NULL; self->writes = NULL;
@ -3323,6 +3324,7 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool isloc
pushdef = true; pushdef = true;
if (OPTS_OPTIMIZATION(OPTIM_STRIP_CONSTANT_NAMES) && if (OPTS_OPTIMIZATION(OPTIM_STRIP_CONSTANT_NAMES) &&
!(global->flags & IR_FLAG_INCLUDE_DEF) &&
(global->name[0] == '#' || global->cvq == CV_CONST)) (global->name[0] == '#' || global->cvq == CV_CONST))
{ {
pushdef = false; pushdef = false;

2
ir.h
View file

@ -44,6 +44,7 @@ typedef struct ir_value_s {
int outtype; int outtype;
/* 'const' vs 'var' qualifier */ /* 'const' vs 'var' qualifier */
int cvq; int cvq;
uint32_t flags;
struct ir_instr_s **reads; struct ir_instr_s **reads;
struct ir_instr_s **writes; 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_ARRAYS (1<<1)
#define IR_FLAG_HAS_UNINITIALIZED (1<<2) #define IR_FLAG_HAS_UNINITIALIZED (1<<2)
#define IR_FLAG_HAS_GOTO (1<<3) #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) #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); ir_function* ir_function_new(struct ir_builder_s *owner, int returntype);