From 19bbdfa3c7ae05f4694ce5e434d9855c6f2c3682 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 24 Jun 2023 18:47:05 +0200 Subject: backend: fix regalloc to work with more complex dataflow basically an allocation map at the beginning (in) and end (out) of each block is kept and after the first allocation pass another pass is ran to resolve allocation conflicts between each edge, plus another pass to finish lowering phi functions. also introduced `regset` and plenty of other miscellaneous fixes --- test/fib.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'test/fib.c') diff --git a/test/fib.c b/test/fib.c index 6254a5f..eadce03 100644 --- a/test/fib.c +++ b/test/fib.c @@ -1,6 +1,6 @@ unsigned fib(unsigned x) { unsigned r = 0, q = 1; - while (x--) { + while (x-- > 1) { unsigned s = r + q; r = q; q = s; @@ -8,12 +8,18 @@ unsigned fib(unsigned x) { return q; } +unsigned fibr(unsigned x) { + if (x < 2) return x; + return fibr(x-1) + fibr(x-2); +} + int atoi(const char *); int printf(const char *, ...); int main(int argc, char **argv) { unsigned n = argv[1] ? atoi(argv[1]) : 10; - printf("fib(%u) = %u\n", n, fib(n)); + printf("fib(%u) = %u\n", n, fib(n)); + printf("fibr(%u) = %u\n", n, fibr(n)); } /* vim:set ts=3 sw=3 expandtab: */ -- cgit v1.2.3