Author: kjs
Date: Fri Dec 12 06:37:49 2008
New Revision: 33830
Modified:
trunk/compilers/pirc/new/main.c
trunk/compilers/pirc/new/pircompiler.c
trunk/compilers/pirc/new/pircompunit.c
trunk/compilers/pirc/new/pirregalloc.c
trunk/compilers/pirc/new/pirregalloc.h
Log:
[pirc] some refactoring of the reg.allocator. Reg.allocator is now run after
each sub, instead of after the parse.
+ this can improve memory usage
+ it should be slightly faster I think
+ it allows to update the actual register usage in the current_sub, which is
needed.
Modified: trunk/compilers/pirc/new/main.c
==============================================================================
--- trunk/compilers/pirc/new/main.c (original)
+++ trunk/compilers/pirc/new/main.c Fri Dec 12 06:37:49 2008
@@ -181,10 +181,6 @@
lexer->outfile = stdout;
}
- /* if register allocation was requested, do that now */
- if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC))
- linear_scan_register_allocation(lexer->lsr);
-
if (TEST_FLAG(lexer->flags, LEXER_FLAG_NOOUTPUT)) /* handy for testing
the compiler */
fprintf(stdout, "ok\n");
else if (TEST_FLAG(lexer->flags, LEXER_FLAG_PREPROCESS))
Modified: trunk/compilers/pirc/new/pircompiler.c
==============================================================================
--- trunk/compilers/pirc/new/pircompiler.c (original)
+++ trunk/compilers/pirc/new/pircompiler.c Fri Dec 12 06:37:49 2008
@@ -182,7 +182,7 @@
lexer->macro_size = INIT_MACRO_SIZE;
/* create a new linear scan register allocator */
- lexer->lsr = new_linear_scan_register_allocator();
+ lexer->lsr = new_linear_scan_register_allocator(lexer);
return lexer;
}
Modified: trunk/compilers/pirc/new/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.c (original)
+++ trunk/compilers/pirc/new/pircompunit.c Fri Dec 12 06:37:49 2008
@@ -2388,6 +2388,10 @@
/* store end offset in bytecode of this subroutine */
CURRENT_SUB(lexer)->endoffset = lexer->codesize;
+
+ /* if register allocation was requested, do that now */
+ if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC))
+ linear_scan_register_allocation(lexer->lsr);
}
Modified: trunk/compilers/pirc/new/pirregalloc.c
==============================================================================
--- trunk/compilers/pirc/new/pirregalloc.c (original)
+++ trunk/compilers/pirc/new/pirregalloc.c Fri Dec 12 06:37:49 2008
@@ -37,7 +37,7 @@
*/
lsr_allocator *
-new_linear_scan_register_allocator(void) {
+new_linear_scan_register_allocator(struct lexer_state *lexer) {
lsr_allocator *lsr = (lsr_allocator *)mem_sys_allocate_zeroed(sizeof
(lsr_allocator));
int i;
@@ -51,6 +51,8 @@
for (i = 0; i < 4; ++i)
lsr->r[i] = 1;
+ lsr->lexer = lexer;
+
return lsr;
}
@@ -428,9 +430,11 @@
live_interval * i;
pir_type type = 0; /* types run from 0 to 4; see pircompunit.h */
-
for (type = 0; type < 4; ++type) { /* handle each of the 4 parrot types
separately. */
+ /* intialize active intervals list to NULL */
+ lsr->active[type] = NULL;
+
/* fprintf(stderr, "Lin.scan.reg.alloc.: %u variables to be mapped\n",
lengthi(lsr->intervals[type]));
*/
@@ -449,7 +453,11 @@
add_interval_to_active(lsr, i, type);
}
+ /* clear list of intervals */
+ lsr->intervals[type] = NULL;
}
+
+
}
Modified: trunk/compilers/pirc/new/pirregalloc.h
==============================================================================
--- trunk/compilers/pirc/new/pirregalloc.h (original)
+++ trunk/compilers/pirc/new/pirregalloc.h Fri Dec 12 06:37:49 2008
@@ -56,7 +56,8 @@
} free_reg;
-
+/* forward declaration */
+struct lexer_state;
typedef struct linear_scan_register_allocator {
unsigned r[4];
@@ -70,9 +71,11 @@
/* list of free_reg objects that we can re-use, to save memory
allocations. */
free_reg *cached_regs;
+ struct lexer_state *lexer;
+
} lsr_allocator;
-lsr_allocator *new_linear_scan_register_allocator(void);
+lsr_allocator *new_linear_scan_register_allocator(struct lexer_state *lexer);
void destroy_linear_scan_regiser_allocator(lsr_allocator *lsr);