Commit Graph

267 Commits

Author SHA1 Message Date
Rui Ueyama ea2f4b8bde
Update README.md 2019-11-05 12:32:24 +09:00
Rui Ueyama 882e4b2dd8 Promote int variables to register values.
In this patch, we promote all non-address-taken integer variables
to registers, so that we use as many registers as we have.
2018-09-01 09:34:13 +00:00
Rui Ueyama 12c65a4259 Fix register allocator. 2018-09-01 09:03:16 +00:00
Rui Ueyama 5e5d76ff55 Implement linear scan register allocator. 2018-09-01 06:01:03 +00:00
Rui Ueyama d56cb7cc4e Use r2 instead of r0 for IR_RETURN.
r0 is a destination register. If an instruction takes only
a source register, it should use r2 instead of r0.
2018-09-01 04:13:03 +00:00
Rui Ueyama 6f7c3f25a2 Branch instructions must be at end of basic blocks. 2018-09-01 03:59:24 +00:00
Rui Ueyama d8cc52f870 Simplify. 2018-09-01 03:15:48 +00:00
Rui Ueyama 04df768a1f Assign offsets to local variables in gen_x86 instead of in gen_ir.
In SSA, we will promote local variables in memory to register values,
so that they are allocated to physical registers rather than the stack
if there are enough number of registers available. Therefore,
computing function's stack size in gen_ir is too early.
2018-09-01 02:58:06 +00:00
Rui Ueyama 443b0b554c Remove kill(). 2018-09-01 00:36:26 +00:00
Rui Ueyama b2d2459dc0 Make IR SSA.
There's no Phi node in our IR. Instead, basic blocks take parameters.
I borrowed the idea from Swift Intermediate Language.
2018-09-01 00:36:26 +00:00
Rui Ueyama ac74d2ed4c Make the IR three-address form.
This is a preparation for introducing SSA so that we can apply
modern compiler optimization techniques to 9cc.
2018-08-31 12:36:15 +00:00
Rui Ueyama 1adfc8545f Define a new struct to represent a register. 2018-08-31 12:08:52 +00:00
Rui Ueyama 3235d3fa5c Rename registers to prepare for the three-address form. 2018-08-30 22:43:57 +00:00
Rui Ueyama 742be85d9e Remove IRInfo. 2018-08-30 22:04:10 +00:00
Rui Ueyama 9ec612f626 Simplify. 2018-08-30 20:12:28 +00:00
Rui Ueyama b93ef13283 Refactor. 2018-08-30 12:43:30 +00:00
Rui Ueyama 316525a1c7 Rename. 2018-08-30 12:31:28 +00:00
Rui Ueyama 3a06a615c0 Fix out-of-bound access. 2018-08-30 12:27:16 +00:00
Rui Ueyama d97091b48a Remove dead code. 2018-08-30 12:25:16 +00:00
Rui Ueyama 1c7927a7df Rename. 2018-08-30 00:11:30 +00:00
Rui Ueyama fbf9223bda Introduce basic block.
Basic block is a straight-line code sequence with no branches in
except to the entry and no branches out except at the exit.
This change alone shouldn't make things better, but it allows us
to add optimization passes in later patches.
2018-08-30 00:11:30 +00:00
Rui Ueyama 11318ddc1a Simplify visit() in regalloc.c. 2018-08-29 23:59:57 +00:00
Rui Ueyama 4442c4cfc5 Split emit_code(). Code move only. 2018-08-29 23:59:57 +00:00
Rui Ueyama 124e5268b3 Improve stringize().
Print out a space between tokens only when there is at least
one space between them in the source file.
2018-08-29 23:59:57 +00:00
Rui Ueyama e81e567b35 Move tokenize() to token.c. 2018-08-29 11:45:25 +00:00
Rui Ueyama c54ffad436 Remove IR_KILL as an independent insn.
This is a preparation for introducing a three-address code so that
we can apply modern optimization techniques.
2018-08-29 00:25:02 +00:00
Rui Ueyama 372391cb70 Add vec_last(). 2018-08-28 23:23:54 +00:00
Rui Ueyama b8d34c626f Simplify. 2018-08-28 23:12:35 +00:00
Rui Ueyama d1e19c5730 Add comments. 2018-08-28 23:00:00 +00:00
Rui Ueyama 0208ac2968 Add switch-case. 2018-08-28 22:45:49 +00:00
Rui Ueyama b60fdbcc16 Simplify. 2018-08-28 22:04:50 +00:00
Rui Ueyama 4e7d6752e2 Interpret `x++` as `({ T *y = &x; *y = *y + 1; *y - 1; })`.
This change simplifies AST at the cost of decreased runtime performance.
That performance degradation should be recovered in a future optimization
pass, so that is okay for now.
2018-08-28 14:00:47 +00:00
Rui Ueyama e936b1a2e9 Fix error message output. 2018-08-28 13:34:24 +00:00
Rui Ueyama 05672ee720 Remove AST types for compound assignments. 2018-08-28 02:40:09 +00:00
Rui Ueyama 9826b21c36 Rename functions. 2018-08-28 01:59:39 +00:00
Rui Ueyama 49caa8e044 Remove IR insns that take immediate operands for simplicity. 2018-08-28 01:58:24 +00:00
Rui Ueyama cdf534efd6 Store negative (real) offsets from RBP.
Because that's logically more accurate.
2018-08-28 01:44:44 +00:00
Rui Ueyama 83020d6a2a Move local variable offset calculation from sema to gen_ir.
Local variable offsets are not significant in semantics.
It logically belongs to gen_ir.
2018-08-28 01:38:04 +00:00
Rui Ueyama 0973c8330a Simplify. 2018-08-28 00:55:54 +00:00
Rui Ueyama cbe5868763 Simplify. 2018-08-28 00:37:46 +00:00
Rui Ueyama 4e2c1fb92f Remove extern varaibles from gvars. 2018-08-28 00:25:06 +00:00
Rui Ueyama 6a622ded26 Simplify. 2018-08-28 00:20:45 +00:00
Rui Ueyama 29124303ae Simplify. 2018-08-28 00:06:34 +00:00
Rui Ueyama 74abebad81 Simplify. 2018-08-28 00:01:08 +00:00
Rui Ueyama 7f3b1ee486 Simplify. 2018-08-27 23:51:18 +00:00
Rui Ueyama 40d8e06cb1 Simplify. 2018-08-27 23:43:40 +00:00
Rui Ueyama df650363fa Rename. 2018-08-27 23:09:34 +00:00
Rui Ueyama 4209ff2273 Eliminate ND_VARDEF before passing AST to Sema. 2018-08-27 23:09:01 +00:00
Rui Ueyama db4021b9ae Simplify struct member lookup. 2018-08-27 22:48:15 +00:00
Rui Ueyama 1e1c548b8d Rewrite `T var = init` `T var; var = init` in the parser. 2018-08-27 22:18:28 +00:00