Bill Currie
5df25133b3
Implement code movement for unconditional jumps.
...
That is, when the destination of the jump is reachable via only the jump.
2012-05-04 18:00:05 +09:00
Bill Currie
33bfac0508
Process all basic blocks for jump threading.
...
I'd copied the for loop from the dead block removal code, but jump
threading doesn't need to look at the following block...
2012-05-04 14:10:30 +09:00
Bill Currie
f169a7732d
Factor out label unuse.
...
I expect to need this more often in the future.
2012-05-04 14:01:39 +09:00
Bill Currie
75aa28cfac
Mark all subsequent blocks as reachable after if/goto merge.
...
If an if/goto merge is done in the first dead block pass, no blocks after
the merge have their rechable flag set because they've never been tested.
2012-05-04 10:58:18 +09:00
Bill Currie
8ddd58f951
Fix the dropping of the block after the merged if/goto.
...
The naive implementation of the if/goto merging was letting the old target
of the if get dropped because the block would lose its label and thus be
judged unreachable because the preceeding goto block was still in the list.
Instead, when the if/goto are "merged", mark the goto block as unreachable,
the following block as reachable, and break out of the analysis loop to
force the removal of the goto block. Since the dead block removal function
loops until no action is taken, all other dead blocks will be removed.
2012-05-04 10:07:55 +09:00
Bill Currie
e866619de6
Output basic block flow diagrams to files.
...
The output can be controlled via --block-dot (not yet documented). The
files a named <sourcefile>.<function>.<stage>.dot. Currently, stage will be
one of "initial" (after expression to statement conversion), "thread"
(after jump threading), "dead" (after dead block removal), "final" (final
state before actual code emission).
2012-05-04 09:45:51 +09:00
Bill Currie
3da44ace52
Merge if and goto blocks when if only skips over the goto.
2012-05-03 22:21:32 +09:00
Bill Currie
6afdfb5fac
Unuse label expressions that are no longer necessary.
2012-05-03 22:20:00 +09:00
Bill Currie
402a578bf8
Add some more helper functions.
...
Things were getting messy with the strcmps.
2012-05-03 22:17:23 +09:00
Bill Currie
88bed3644e
Rename some helper functions.
2012-05-03 22:11:52 +09:00
Bill Currie
6900907129
Remove dead labels when jump threading.
...
This lets the dead block removal do a better job.
2012-05-03 19:32:44 +09:00
Bill Currie
ab73a267cd
Do not unconditionally remove labels from blocks.
...
Labels can be shared between multiple flow-control instructions, so use the
label's used counter to determine when to remove the label. This was
causing problems with the jump threading.
2012-05-03 19:22:57 +09:00
Bill Currie
43b5edf46b
Implement jump threading.
...
First real optimization :)
2012-05-03 17:42:58 +09:00
Bill Currie
bc1b483525
Nuke the rcsid stuff.
...
It's pretty useless in git.
2012-04-22 10:56:32 +09:00
Bill Currie
c7612dcd99
Make statement dumps a little more informative.
2011-04-10 09:08:46 +09:00
Bill Currie
55cc0f9206
Bring back the unsigned type (PROGS version bump)
...
This is only low-level support (the unsigned keyword still does not work),
but sufficient to make switch statements using jump tables work.
2011-04-09 10:07:47 +09:00
Bill Currie
237f11c472
Fix cast expressions.
...
Casting between ints and floats needs special treatment to get the
conversion operator, but other casts need to be aliases.
2011-04-08 13:55:26 +09:00
Bill Currie
8d3508cf20
Allocate space for temp defs using size rather than type.
...
Statement operands throw away the high level type information, so store
type size in the operand and use this size for allocating space for temps
rather than using the low-level type.
2011-03-23 21:32:14 +09:00
Bill Currie
5aa0b34570
Add the cast statement to the statement block.
...
*sob*
2011-03-10 20:43:53 +09:00
Bill Currie
2129eaaf20
Dereference moves need movepi rather than movei.
2011-03-10 19:29:23 +09:00
Bill Currie
39278ba8cc
Explicitly select between direct and indirect moves.
2011-03-09 10:30:57 +09:00
Bill Currie
5a78758781
Support return in void functions in v6 code.
2011-03-07 13:52:28 +09:00
Bill Currie
17a9dff769
Avoid freeing an operand twice.
...
Due to the way operands are used, they can be freed twice in dead-statement
removal. Detect the double-free and ignore it.
2011-03-06 11:19:09 +09:00
Bill Currie
ee9045c377
Emit code for jump tables.
...
With this, the entirety of the ruamoko tree builds (though the progs will
be broken in various ways: mostly unrelocated references).
2011-03-03 19:09:00 +09:00
Bill Currie
4324486ae6
Give - unary expressions special treatment.
...
The progs engine has no neg instruction, so need to implement -val as
nil - val
2011-03-03 18:13:30 +09:00
Bill Currie
f9e177efd6
Obtain the label to be removed from the correct place.
...
This fixes the undetected dead block after "if return else return".
2011-03-03 17:50:46 +09:00
Bill Currie
ed901bd48f
Drop unused labels rather than adding them to the statement block.
...
However, even unused labels create a new statement block if necessary.
2011-03-03 17:35:06 +09:00
Bill Currie
c5ecc170b6
Give labels a usage count to detect unused labels.
2011-03-03 15:28:49 +09:00
Bill Currie
d937172243
Create and use alias operands for alias expressions.
...
This avoids the alias expression modifying the operand used in other
expressions.
2011-03-03 13:46:07 +09:00
Bill Currie
022fde666f
Implement unary expression statements.
2011-03-03 13:10:07 +09:00
Bill Currie
45de7327dc
Implement alias expressions (finally).
...
Alias expressions are like cast expressions, but never do any conversions.
2011-03-03 11:06:10 +09:00
Bill Currie
497db3ac81
Fix the return symbol extraction when appending a return statement.
...
The code is still icky, though :P
2011-02-22 09:20:52 +09:00
Bill Currie
bcaf3687c5
Fix loading structs into params via an offset pointer.
...
For certain values of "fix" :/. The code is ugly, but it does the right
thing: calculate the effect address and use the resulting pointer in a
move instruction.
2011-02-14 23:10:45 +09:00
Bill Currie
179c1f7058
Support move statements (structure copy).
2011-02-11 22:29:57 +09:00
Bill Currie
370f0b97ed
Produce cleaner output for a = b op c.
2011-02-11 22:29:57 +09:00
Bill Currie
d93d8d7d46
Remove the dirty hack used for accessing params and the return value.
...
Instead of using the equivalent of *(float*)&.return, now use the
equivalent of (float).return. No conversion is done in the "cast".
NOTE: this sort of cast should be separated from normal casts.
2011-02-11 22:29:38 +09:00
Bill Currie
7d2a95ee40
Mark a few problem spots.
2011-02-11 22:29:37 +09:00
Bill Currie
6f625e426f
Use the correct type when deferencing an offset pointer.
2011-02-10 14:26:12 +09:00
Bill Currie
006c16807d
Add the statement for based loads.
...
Oops :P
2011-02-09 22:40:16 +09:00
Bill Currie
0d5ab6600d
Store the source expression in a statement.
...
This makes problem reporting more informative.
2011-02-08 18:18:34 +09:00
Bill Currie
3c849b970b
Handle union access now that they're detected properly.
2011-02-08 14:45:48 +09:00
Bill Currie
3b080fcbb0
Fix an uninitialized variable.
2011-02-08 13:27:37 +09:00
Bill Currie
65a07ada1c
Implement offset dereferences.
2011-02-07 14:56:29 +09:00
Bill Currie
d2b464053c
Fix assignment sub-expressions.
2011-02-07 14:43:07 +09:00
Bill Currie
ef2ad46f7a
Convert complex types to a suitable low-level type.
...
This takes care of moving structures etc around.
2011-02-07 10:55:09 +09:00
Bill Currie
b629c12b31
Do not change the type of the return operand.
...
Doing so made a mess of returning expressions. It was probably a holdover
from before getting instructions with void operand types working.
2011-02-07 10:21:54 +09:00
Bill Currie
e4ac92b5f2
Auto-cast between enums and the default type.
2011-02-06 20:08:16 +09:00
Bill Currie
c53001800a
Create a struct for representing specifiers.
...
The specifiers are yet to come (next few commits), but this will be
necessary when they do.
2011-02-01 21:15:51 +09:00
Bill Currie
e7424e1496
Don't segfault on bare return statements.
...
I will probably need to do something about the required operand for v6
progs, but this will do for now.
2011-01-30 21:43:56 +09:00
Bill Currie
834417b8c8
Add "debug" diagnotic printing, and use it.
...
Debug diagnostics are silent for verbosity levels less than 1.
2011-01-28 13:28:45 +09:00