Commit Graph

98 Commits

Author SHA1 Message Date
Bill Currie f83cf1748f Allow node() to work for all operand types.
This is a bit of an expermiment to get better dags (more node reuse).
2012-11-20 14:23:43 +09:00
Bill Currie 1472fec7f2 Factor out the live vars magic from dag_create.
The code is messy enough as it is :P
2012-11-20 13:44:36 +09:00
Bill Currie 56103f9a38 Treat global variables as live at the end of a function.
.return and .param_N are not classed as global variables for data flow
analysis. .return is taken care of by return statements, and .param_N by
call statements.

With this, the menus work up to attempting to load the menu plist.
Something is corrupting zmalloc's blocks.
2012-11-19 17:21:35 +09:00
Bill Currie bcde7396a0 Don't let generate_assignments guess the type.
It fails when both source and destination are void, but since the dag node
itself does know the correct type, pass in the type rather than guessing.
2012-11-19 15:21:01 +09:00
Bill Currie 68bf013601 Use a dag-local live vars set.
Function calls need to ensure .param_N actually get assigned, and so the
params must be seen as live by the dead variable removal code. However, it
is undesirable to modify the live vars data of the flow node, so make a
local copy.
2012-11-19 15:18:31 +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 3cffeb7b66 Handle assignment from void defs.
The main void defs are .return and .param_N. If the source operand is void,
use the destination operand's type to alias the source operand rather than
the source operand's type to alias the destination's operand (the usual
case).
2012-11-19 11:00:04 +09:00
Bill Currie 3d1792d2fc Properly count users of a tempory variable.
The dags code isn't the only place that creates temporary variables, so
count them as they go into a statement rather than when they're created.
This fixes the temp underflows.
2012-11-18 20:27:26 +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 c5fa4fe92a Generate code from the dag in topological sort order.
Nicely, the need for dag_gencode to recurse seems to have been removed.

At least for a simple case, correct code is generated :)

	switch.r:49:    case 1:         *to = *from++;
	003b loadbi.i *(from + 0), .tmp10
	003c add.i from, .imm, from
	003d storep.i .tmp10, *to
2012-11-18 13:10:19 +09:00
Bill Currie 1452dcca9a Create dependency edges.
A node that writes to a var must be evaluated after any node that reads
that var, so for any node reading var, add that node to the edges of the
node currently associated with the var (unless the node is a child of the
node reading the var).
2012-11-18 12:56:27 +09:00
Bill Currie d58595660f Treat newly created nodes as root nodes.
When a node is made a child of another node, it is removed from the dag's
set of root nodes.
2012-11-18 10:50:10 +09:00
Bill Currie af4e56bba8 Topologically sort the dag.
It doesn't make any difference yet, but that's because I need to add extra
edges indicating iter-node dependencies. However, the sort does seem to
work for its limited input.
2012-11-18 09:23:01 +09:00
Bill Currie 668871205a Add the child nodes to the node's edges set. 2012-11-17 22:12:03 +09:00
Bill Currie dcc786b16f Remove dead variables after creating the dag.
Not adding them while creating the dag completely broke the dag as
node(deadvar) always returned null. Code quality is back to where it was
before the dags rewrite.
2012-11-17 22:08:46 +09:00
Bill Currie deb5484c7e Move the node/label numbering into the alloc funcs.
I should have done it this way in the first place. much cleaner.
2012-11-17 21:55:59 +09:00
Bill Currie 12133bc02f Rewrite dags to use sets.
While things are quite broken now (very incorrect code is being generated),
the dag is much easier to work with. The dag is now stored in an array of
nodes (the children pointers are still used for dagnode operands), and sets
are used for marking node parents, attached identifiers and (when done,
extra edges).
2012-11-17 21:14:42 +09:00
Bill Currie 0bb2fc1891 Fix the lost line numbers on simple assignments.
Instead of storing the generating statement in the dagnode, the generating
expression is stored in the daglabel. The daglabel's expression pointer is
updated each time the label is attached to a node. Now I know why debugging
optimized code can be... interesting.
2012-11-17 12:07:27 +09:00
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 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 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 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 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 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 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 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 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 739ebc522c Begin working on flow analysis.
For now, variable and flow graph node maps are built.
2012-11-15 13:44:06 +09:00
Bill Currie 5acf474882 Double quote dag labels.
Dot interprets escape sequences in non-html string, and needs the quotes to
be escaped, so quote the result of operand_string. Unfortunately,
operand_string uses quote_string and quote_string returns a static pointer,
so some hoop-jumping is necessary.
2012-11-15 13:44:06 +09:00
Bill Currie 60d03dbdd9 Fix the naive opcode checks.
Confusing . with .=, and < and <= with more <MOVE etc isn't good.
2012-11-15 13:44:06 +09:00
Bill Currie dc9d2a982e Make the returned dag a linked list of root-nodes.
A dag can have mulitple "root" nodes (ie, nodes with no parents).
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 0c58cd9067 Generate only one daglabel for value operands.
As each value is now unique, their labels can also be unique, which will
improve CSE.
2012-11-15 13:44:06 +09:00
Bill Currie 01c8aaae8c Add some error checking for attaching identifiers. 2012-11-15 13:44:06 +09:00
Bill Currie 0ccf4093e4 Handle attached identifier labels correctly.
I'd forgotten I had the prev field. Makes for much cleaner code.
2012-11-15 13:44:06 +09:00
Bill Currie 39506881c0 Fix the completely bogus handling of "x" in dag creation.
That made a complete mashup of attached identifiers :P
2012-11-15 13:44:06 +09:00
Bill Currie 7b2e426545 Support temp operands in dags. 2012-11-15 13:44:05 +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 aa2943709e Start work on building dags from basic blocks.
Doesn't compile and the design is in flux anyway, but I want to get back to
iqm.
2012-11-15 13:44:05 +09:00
Bill Currie 0fefeb73fe Initial support for basic block dags.
Currently, only dumping to dot, but that seems to be a very sensible place
to start: debug support.
2012-11-15 13:44:05 +09:00