Commit graph

119 commits

Author SHA1 Message Date
Bill Currie
c4ba294433 Fix the icky fixme :) 2012-11-27 20:32:52 +09:00
Bill Currie
31b07bcbbf Rewrite expr_alias().
Modifying the existing alias chain proved to be a bad idea (in retrospect,
I should have known better:P). Instead, just walk down any existing alias
chain to the root operand and build a new alias from that.
2012-11-27 18:33:41 +09:00
Bill Currie
d6b38dd0ee Add an option to control expr tree dumping.
About bloody time :P
2012-11-26 21:00:28 +09:00
Bill Currie
8e225cd726 Fix a missing label use count decrement.
if statements in dead code weren't being removed due to the label.
2012-11-26 16:13:59 +09:00
Bill Currie
578ad07487 Fix yet another empty block issue.
I think I need to rework all the code in there, but this will do for now.
2012-11-25 15:01:36 +09:00
Bill Currie
4f8b3b5692 More empty block checks. 2012-11-24 19:06:10 +09:00
Bill Currie
6e7aaac1b9 Fix the wording of a comment. 2012-11-24 19:06:01 +09:00
Bill Currie
7f229b7682 Remove execessive html quoting.
Heh, I must have put that in long before I did the quoting functions.
2012-11-24 15:42:21 +09:00
Bill Currie
f4604d9db5 Remove gotos that go to the following statement.
eg:
	goto foo:
foo:
	//some code
2012-11-24 15:08:48 +09:00
Bill Currie
0dea564cb4 Be more careful of empty sblocks.
Accessing the final statement of an sblock via tail doesn't work in an
empty sblock because tail points to sblock->statements and thus the cast is
invalid. This bug has be lurking for a long time, but for some reason the
cse stuff tickled it (thankfully!!!).
2012-11-19 16:11:07 +09:00
Bill Currie
d1252813ce Use low_level_type instead of extract_type.
extract_type doesn't understand enums (by design?). qwaq's types.r now
compiles.
2012-11-19 13:49:34 +09:00
Bill Currie
f2cc82469a Use the correct field when dechaining aliases.
op_type and type always confuse me :P
2012-11-19 12:53:08 +09:00
Bill Currie
e70b59b925 Don't null the def pointer when freeing a temp.
It makes debugging more difficult.
2012-11-19 11:02:31 +09:00
Bill Currie
0c3aeb30aa Reuse tempary variables.
Now that I've got nice code, it was worth doing. Unfortunatly, bsearch
style switch statements have problems.
switch.r:14: BUG: temp users went negative: <tmp 0x21b6840:-1>
switch.r:14: BUG: temp users went negative: <tmp 0x21b6840:-2>
switch.r:14: BUG: temp users went negative: <tmp 0x21b6840:-3>
switch.r:14: BUG: temp users went negative: <tmp 0x21b67d0:-1>
2012-11-18 19:10:18 +09:00
Bill Currie
1100efba54 Nuke find_operands in favor of flow_analyze_statement.
flow_analyze_statement uses the statement type to quickly determin which
operands are inputs and which are outputs. It takes (optional) sets for
used variables, defined variables and killed variables (only partially
working, but I don't actually use kill sets yet). It also takes an optional
array for storing the operands: index 0 is the output, 1-3 are the inputs.
flow_analyze_statement clears any given sets on entry.

Live variable analysis now uses the sets rather than individual vars. Much
cleaner code :).

Dags are completely broken.
2012-11-16 19:33:37 +09:00
Bill Currie
001e1ac059 Classify statements into broad types.
The types are expression, assignment, pointer assignment (ie, write to a
dereferenced pointer), move (special case of pointer assignment), state,
function call/return, and flow control. With this classification, it will
be easier (less code:) to determine which operands are inputs and which are
outputs.
2012-11-16 16:16:06 +09:00
Bill Currie
b8b626ee81 Change the int<->float conversion opcode string.
Using "=" was rather confusing, so changing it to "<CONV>" seems to be a
good idea. As the string is used only for selecting opcodes at compile
time, only qfcc is affected.
2012-11-16 14:45:11 +09:00
Bill Currie
c1a5c1a7b2 Create alias_operand (). 2012-11-15 15:52:30 +09:00
Bill Currie
095210893f Ensure alias operands are never nested.
No more than one level of aliasing is ever needed, so strip off any
intervening aliases that show up.
2012-11-15 15:18:00 +09:00
Bill Currie
1c32ac8ce6 Expose new_statement, too. 2012-11-15 13:44:09 +09:00
Bill Currie
802e1981bb Expose some statements functions needed for code gen. 2012-11-15 13:44:09 +09:00
Bill Currie
c43a8331cf Expose dump_dot_sblock. 2012-11-15 13:44:09 +09:00
Bill Currie
c358a0e77e Create a function to generalize dot dumping.
Now, any time a graph is wanted, the file can be consistently named without
a lot of messy code.
2012-11-15 13:44:08 +09:00
Bill Currie
5051c922a5 Ensure alias operands are properly freed. 2012-11-15 13:44:08 +09:00
Bill Currie
3298e4d67e Ensure find_operands sets the operands to known values.
This fixes the last of the bogus live variables.
2012-11-15 13:44:08 +09:00
Bill Currie
c00e666668 Expose find_operands.
It has proven to be a generally useful function, not just for dags.
2012-11-15 13:44:08 +09:00
Bill Currie
7404aacab7 Resurrect dags building and printing.
However, this time it's done after the statement recording (so the
statement numbers are set).
2012-11-15 13:44:08 +09:00
Bill Currie
8844ac61a2 Rename dump_flow to dump_sblock and move to dot_sblock.c 2012-11-15 13:44:07 +09:00
Bill Currie
8b374305d2 Rename dot_flow.c and print_flow.
They're now dot_sblock.c and print_sblock. The new names both better
reflect their purpose and free up "flow" for outputting the real flow
analysis graphs.
2012-11-15 13:44:07 +09:00
Bill Currie
7853bf1859 Calculate a node's successors and predecessors.
The dot graphs are a little odd (arrow heads on the wrong end of the
predecessor edges), but things seem to be correct.
2012-11-15 13:44:06 +09:00
Bill Currie
a22260030a Use value for pointer operands.
This allows daglabels on pointer operands without a redundant daglabel
pointer.
2012-11-15 13:44:06 +09:00
Bill Currie
28ce35f1c1 Make values independent objects.
values are now uniquely allocated (for the current object file). With
this, constants in dags will work.
2012-11-15 13:44:06 +09:00
Bill Currie
dbf1aa8f72 Attach dags to statement blocks.
Now, if a dag is attached to a statement block, it will be included in the
flowgraph with that statement block.
2012-11-15 13:44:06 +09:00
Bill Currie
9bc65ffedb Start actually trying to build dags.
Temporary variables aren't being handled correctly (treated as constants),
but it looks like a good start.
2012-11-15 13:44:05 +09:00
Bill Currie
6ff2644ab5 Fix simple pointer dereferences.
It turns out no code was being generated for x = *y. Ouch. I suspect I need
to take a better look at expr_deref at some time in the not too distant
future.

Conflicts:
	tools/qfcc/source/statements.c
2012-11-09 12:32:35 +09:00
Bill Currie
9095e1eabc Rework build_switch to use initialize_def.
This required support for label reference expressions, whose purpose is to
represent the address of a label.
2012-11-09 12:22:34 +09:00
Bill Currie
61ef901254 Tweak some FIXMEs. 2012-11-08 17:03:02 +09:00
Bill Currie
5c79953a7e Put quotes around strings for statement operands.
This makes reading output a bit easier (especially if the string is empty
or just whitespace).
2012-10-30 12:31:28 +09:00
Bill Currie
034139b806 Move some code around so it's more accessible. 2012-10-27 11:43:29 +09:00
Bill Currie
56410ddc58 Prevent merged if/goto losing its way.
When mering if/goto (ie, if skipping a goto), the rest of the dead code
remover is used to delete the goto. That part of the code unuses the goto's
label. The if was getting the goto's label without the lable's used count
being incremented (the usaged temporarily increases by one). I have no idea
why the problem showed up randomly, but this seems to fix it (it fixes /a/
bug, anyway).
2012-05-04 22:35:20 +09:00
Bill Currie
953e789db2 Handle movement of the final block.
Moving a final block caused segfaults and weird flow graph corruptions.
2012-05-04 19:48:32 +09:00
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