Commit Graph

9071 Commits

Author SHA1 Message Date
Bill Currie 43d77900d5 Rewrite dag_gencode to use statement/node types.
It now seems to generate correct code for each node. However, node order is
still incorrect in places (foo++ is being generated as ++foo). quattest.r
actually executes and produces the right output :)
2012-11-16 22:09:49 +09:00
Bill Currie 872b13616d Ensure return's operand gets set properly.
Yay for coding and designing at the same time, not :P
2012-11-16 21:50:27 +09:00
Bill Currie bd5a790456 Support statement labels in dags.
While the code is broken in places, switch.r generates code again.
2012-11-16 20:12:13 +09:00
Bill Currie 4c6381d035 Mostly fix dag_create to work with flow_analyze_statement.
Label operands aren't handled properly, but dags are getting generated
again (better than before: return and goto are in).
2012-11-16 20:03:30 +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 c1776fc2ad Make the dags in flow graphs a little easier to read. 2012-11-16 12:42:57 +09:00
Bill Currie db605fa998 Improve the type accuracy of dag_gencode.
Surprisingly, I don't yet have to "throw one out", but things are still
problematic: rcall1 is getting two arguments, goto and return get lost,
rcall2 got an old temp rather than the value it was supposed to, but
progress :)
2012-11-15 17:58:33 +09:00
Bill Currie 3bfa89ca8b Clean up the operand type fixing.
It doesn't help any yet, but it will make things easier later on.
2012-11-15 17:15:34 +09:00
Bill Currie 012a521dc5 Strip aliases off daglabel operands.
However, the original type of the operand, as seen by the statement, is
kept. Mostly works, but has some problems with plistmenu.r
2012-11-15 15:53:51 +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 6621a42da9 Better handling of progs.dat and line numbers.
Not enough testing :P
2012-11-15 14:53:09 +09:00
Bill Currie 1c32ac8ce6 Expose new_statement, too. 2012-11-15 13:44:09 +09:00
Bill Currie 69543cf85b Fix an uninitialized variable.
It was never a propblem until an attempt to dump empty sblocks was made.
2012-11-15 13:44:09 +09:00
Bill Currie d76e2a8423 Make a start on regenerating code from dags.
Some parts are a lot messier than I thought, so the actual codegen in the
dags code is just a minimal stub for now.
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 88b8bebe3c Detach dead temporary variables from dag nodes.
This allows temporary variables that are used in multiple nodes to remain
in the dag, but also will allow more freedom when generating code from the
dag.
2012-11-15 13:44:08 +09:00
Bill Currie fe13f21d9d Fix a segfault causing c&p error.
Found when I tried to skip attaching temporary vars to dag nodes (which
proved to be a bad move in the end, but exposing bugs is good).
2012-11-15 13:44:08 +09:00
Bill Currie 2b2ea5c9b3 Compute dags as part of data flow analysis.
I want to use the live variable information when building the dags.
2012-11-15 13:44:08 +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 9f409b1ac4 Rename make_dag to dag_create. 2012-11-15 13:44:08 +09:00
Bill Currie 16410332af Create the dags list in execution order.
The root nodes of the dag need to be evaluated in execution order as some
roots may depend on the results of earlier roots (but then, this might also
be related to the problem of function calls not specifying all of their
parameters to the dag).
2012-11-15 13:44:08 +09:00
Bill Currie e77d3b9e54 Fix a missed colspan in sblock dumps. 2012-11-15 13:44:08 +09:00
Bill Currie 783b4082a1 Produce tidier dag dumps. 2012-11-15 13:44:08 +09:00
Bill Currie 04a8e19481 Move the flow-var use/define calcs to a better place.
dags.c really isn't the right place. The only reason it wasn't in flow.c in
the first place is find_operands was in the wrong place.
2012-11-15 13:44:08 +09:00
Bill Currie c4d4174ebc Make some minor improvements to flow graph dumps. 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 e3a49df0a8 Set def after setting use.
An instruction that both reads and writes the same variable will read the
variable before writing to it, so the instruction uses the variable rather
than defines it (for live-variable purposes).
2012-11-15 13:44:08 +09:00
Bill Currie 58cb73d6aa Remember to union the node's use with (out - def)
Oops.
2012-11-15 13:44:08 +09:00
Bill Currie cd224c00d4 Add live variable info to flow graph dumps.
Things are a little bogus, but at least the bogosity is visible :)
2012-11-15 13:44:08 +09:00
Bill Currie 8817c4a1c2 Re-enable the flow graph dumping.
It's still in a bogus place, but it's necessary.
2012-11-15 13:44:08 +09:00
Bill Currie 3c79f07705 Fix an out-by-one error in the set operators.
I have no idea why I added that - 1.
2012-11-15 13:44:08 +09:00
Bill Currie 4b64912793 Begin doing some data flow analysis.
In te beginning, 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 0a2ce6d381 Fix some doxygen comments. 2012-11-15 13:44:08 +09:00
Bill Currie 5514c8db3c Print the statement number in the sblock output. 2012-11-15 13:44:08 +09:00
Bill Currie 0b49bd343c Collect information on statements that set or use vars.
First, it turns out using daglabels wasn't such a workable plan (due to
labels being flushed every sblock). Instead, flowvars are used. Each actual
variable (whether normal or temp) has a pointer to the flowvar attached to
that variable.

For each variable, the statements that use or define the variable are
recorded in the appropriate set attached to each (flow)variable.
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 acedc65de1 Make an array of statements for the function.
With this, sets can be used to represent statements.
2012-11-15 13:44:07 +09:00
Bill Currie 98245f6d00 Bury a dead field. 2012-11-15 13:44:07 +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 d6d03a63b4 Print the depth-first order of the flow graph nodes. 2012-11-15 13:44:07 +09:00
Bill Currie acc3beb6ab Make flow_find_dominators a little more robust.
While a non-initial node not having predecessors is really an internal
error, segfaulting because of it is not nice.
2012-11-15 13:44:07 +09:00
Bill Currie acde6ca0a0 Handle jumpb statements in dot_sblock and flow graphs. 2012-11-15 13:44:07 +09:00
Bill Currie ffa08a99c2 Store the initializer expression in the def.
Initially, this will be used for collecting the targets of a jumpb
instruction.
2012-11-15 13:44:07 +09:00
Bill Currie d7177a78e9 Rewrite the flow graph code.
The flow graph nodes are now properly separated from the graph, and edge
information is stored in the graph struct. This actually made for much
cleaner code (partly thanks to the use of sets and set iterators).

Flow graph reduction has been (temporarily) ripped out as the entire
approach was wrong. There was also a bug in that I didn't really understand
the dragon book about selecting nodes and thus messed things up. The
depth-first search tree "fixed" the problem, but was really the wrong
solution (sledge hammer :P).

Also, now that I understand that dot's directed graphs must be acyclic, I
now have much better control over the graphs (back edges need to be
flipped).
2012-11-15 13:44:07 +09:00