summaryrefslogtreecommitdiff
path: root/offsets.c
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2012-06-16 17:35:24 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2012-06-16 17:35:24 -0400
commite327fd94f3be22d9129b252102e73b5bfb3b3276 (patch)
tree4e2f178bd467fda1ffce236e40bb112db94dd133 /offsets.c
parent15e96a558baf007966f80d565f50f18cd2ecd75d (diff)
Remove redundant loads
Do breadth first of the entire program when marking variables used/unused Don't optimize away unused function parameters
Diffstat (limited to 'offsets.c')
-rw-r--r--offsets.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/offsets.c b/offsets.c
index 32f3614..0504d7f 100644
--- a/offsets.c
+++ b/offsets.c
@@ -59,18 +59,21 @@ assign_offsets (symbol_table_t *symbols, int offset, int *max)
{
ast_definition_t *definition = definitions->pdata[i];
- if (definition->common.type == AST_VARIABLE_DEFINITION &&
- definition->variable.used)
+ if (definition->common.type == AST_VARIABLE_DEFINITION)
{
- int size = ast_type_spec_get_size (definition->variable.type_spec);
-
- /* Align to size */
- if (offset % size != 0)
- offset += (size - offset % size);
-
- definition->variable.offset = offset;
-
- offset += size;
+ ast_variable_definition_t *variable = &definition->variable;
+
+ if (variable->used || variable->parameter)
+ {
+ int size = ast_type_spec_get_size (variable->type_spec);
+
+ /* Align to size */
+ if (offset % size != 0)
+ offset += (size - offset % size);
+
+ variable->offset = offset;
+ offset += size;
+ }
}
}
@@ -145,8 +148,7 @@ do_offsets (ast_t *ast, int offset, int *max)
gboolean
offsets (ast_t *ast)
{
- node_breadth_first (ast->program.enter, mark_used, NULL);
-
+ program_breadth_first (&ast->program, mark_used, NULL);
do_offsets (ast, 0, NULL);
/* The offsets pass can never fail */