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
Bill Currie
b9599a7119
Better set memory management.
...
At the cost of one pointer per set, sets can now be allocated and freed
more efficiently (especially since malloc might round things up).
2012-11-15 13:44:07 +09:00
Bill Currie
2385cf65c2
Rename setstate_t to set_iter_t.
...
After all, it is an iterator :).
2012-11-15 13:44:07 +09:00
Bill Currie
d3d88290b5
Mostly satisfactory output of nested regions.
...
It turns out dot does not like cyclic graphs (thus some of the weird
layouts), but fixing it by flipping back-edges requires proper recording of
edge info (I guess that's what T is for in the dragon book).
2012-11-15 13:44:07 +09:00
Bill Currie
8c5a2b3d11
Implement depth-first searching for flow graphs.
...
This fixes the bogusly irreducible graphs.
2012-11-15 13:44:07 +09:00
Bill Currie
53622dbb99
Perform graph reduction on the function's flow graph.
...
The reduction is performed itteratively until the graph is irreducible, but
such that each reduction wraps the previous graph. Unfortunately, due
depth-first searching not being implemented, graphs that should be reduced
(ie, those with natural loops).
2012-11-15 13:44:07 +09:00
Bill Currie
388b6e6e8f
Add set_size ().
...
Return the number of members in the set.
2012-11-15 13:44:07 +09:00
Bill Currie
8567508963
Rewrite set_first() and add set_next().
...
set_first() now returns a pointer to a setstate_t struct that holds the
state necessary for scanning a set. set_next() will automatically delete
the state block when the end of the set is reached. set_delstate() is also
provided to allow early termination of the scan.
2012-11-15 13:44:07 +09:00
Bill Currie
2da038ce0f
Bring back dot_flow.c.
...
However, it produces simplified flow graphs (ie, just nodes and edges, no
statements, though later on data flow information will be added).
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
c483770121
Rework flow.c with the aim of graph reduction.
...
Much of the data recently added to sblock_t has been moved to flownode_t.
No graph reduction is carried out yet, but the initial (innermost level)
graph has been built.
2012-11-15 13:44:07 +09:00
Bill Currie
da446fd343
Detect natural loops.
...
Non-nested loops that have the same head-node are merged into one loop.
However, loop nesting is not currently detected (next step).
2012-11-15 13:44:07 +09:00
Bill Currie
8fb958603c
Add set_first.
...
It returns the first element of a set. If the set is empty, -1 (unsigned)
is returned.
2012-11-15 13:44:07 +09:00
Bill Currie
4cc8d4a04b
Fix an apparent snafu in set_test.
...
It looks like a bit of case&paste where I forgot to change != to &.
2012-11-15 13:44:07 +09:00
Bill Currie
1fead50f4e
Calculate the dominators of each node in the flow graph.
...
The dominators are represented by sets using the node numbers.
2012-11-15 13:44:07 +09:00
Bill Currie
964ea7f9fe
Add set_as_string for debug output.
2012-11-15 13:44:07 +09:00
Bill Currie
d2fab28d01
Implement set_is_member.
...
Oops, forgot that one.
2012-11-15 13:44:06 +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
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
f30010b367
Add some docs to function.h
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
cdc790d0c8
Add a set type and support code.
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
16869cabd1
Fix a slew of uninitialized data problems.
...
Bah, structs on stacks... good fun :P
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
0cedf0d13a
Fix a bunch of mis-uses of an expressions's value.
...
The value field really should be treated as constant.
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
c57df8b5f3
Print all dag nodes in a dag.
...
Dags can have multiple roots, so only recursing once could miss much of the
dag.
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
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
24553867a4
Use dashed lines for attached identifiers in dags.
2012-11-15 13:44:06 +09:00
Bill Currie
aa72f263ec
Use an extra temp for v6 float modulo.
...
It seems the dag creation algorithm doesn't like "a = a op a", so use
"b = a op a" instead. Since I plan on fixing temp leaks anyway, this won't
be a problem (also, few people even use qfcc's v6 float modulo :P).
2012-11-15 13:44:06 +09:00
Bill Currie
d9354255a3
Avoid double-printing dag nodes.
2012-11-15 13:44:05 +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
b7b6294d87
Fix some dag printing goofs.
...
Typo and no node recursion.
2012-11-15 13:44:05 +09:00
Bill Currie
8015e1b1e9
Put the dags stuff into a qfcc sub-section.
...
Not much point writting docs if they can't be found.
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
60108c688c
Change dags from binary to trinary.
...
I'd forgotten some instructions take three inputs that can benefit from
CSE.
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
Bill Currie
d5c831b6da
Add a little test case for accessing types.
...
Using ruamoko to access ruamoko type encodings is actually quite pleasant
:)
2012-11-15 13:40:11 +09:00
Bill Currie
ee8247ec61
Support using enums as array indices.
2012-11-15 13:39:23 +09:00
Bill Currie
f18a4d3c4a
Support pointer - pointer.
2012-11-15 13:38:57 +09:00
Bill Currie
552142497e
Support progs.dat when dumping type encodings.
...
Knock up a quick and dirty progs-to-qfo "converter" (strings and types
only) to re-use the qfo types dumper.
2012-11-15 11:58:13 +09:00
Bill Currie
9691b50f0f
Make .type_encodings more useful.
...
Rather than just a pointer, it is now a struct with a pointer and size
indicating the extent of the type encodings block.
2012-11-15 11:57:16 +09:00
Bill Currie
74ac4ee142
Fix a misplaced line.
2012-11-15 11:00:51 +09:00
Bill Currie
39c1034afb
Relocate the data in the type encodings space.
...
Because of the way it is used, the data in the type encodings space needs
to always be correct (ie, relocated), even for partially linked object
files.
2012-11-14 20:37:19 +09:00
Bill Currie
453ac11bc3
Correct some comments.
2012-11-14 17:13:14 +09:00
Bill Currie
2685d38059
More paranoia when dumping qfo type encodings.
2012-11-14 16:32:41 +09:00
Bill Currie
3b3e013d4a
Do not demand a defined def is actually global.
...
Rather, only that it is neither external nor local. The idea was to catch
myself swapping the arguments to resolve_external_def, but for some reason
I decided type encoding defs would not be global (save game reasons?).
2012-11-14 15:50:55 +09:00
Bill Currie
acc188d62b
Ressurect the builtin symbol type fixup.
...
I was a little overzealous when gutting process_type_space :P
2012-11-14 15:49:19 +09:00
Bill Currie
9d7b8a4cf2
Add optional arguments to the todo list.
...
Interesting alternative to overloaded functions.
2012-11-14 14:55:36 +09:00
Bill Currie
33eb3f2418
A bit of pointer saftey in add_defs.
...
Directly accessing odef after can be dangerous (probably not here, but
hey), so use the defref instead.
2012-11-14 13:25:30 +09:00
Bill Currie
00c87434bf
A touch of whitespace.
2012-11-14 13:25:03 +09:00
Bill Currie
281e203545
Make process_data_def use the correct def tables.
...
Fixes the bogus redefined errors when entity fields are used.
Also, rename extern_defs and defined_defs to extern_data_defs and
defined_data_defs (more consistent with the other tables).
2012-11-14 13:14:54 +09:00
Bill Currie
e05c12e16d
Make linker_add_def take a pointer for the value.
...
While it looks like I might not use it for the type encodings, it should be
useful in the future.
2012-11-14 13:12:58 +09:00
Bill Currie
51236b0693
Fix the incorrect type space reloc offsets.
...
The problem was caused by add_relocs and process_loose_relocs adjusting the
reloc offset based on the reloc's space's base address. This is fine for
most relocs, but as relocs for the type space have already been adjusted by
process_type_space, those relocs must be left alone by add_relocs and
process_loose_relocs. As a bonus, the duplicate code has been refactored
into a separate function :)
2012-11-14 10:29:45 +09:00
Bill Currie
31739f4dbf
Rewrite the type_space processing.
...
Now each encoding is copied across def by def using memcpy, with the
expectation that any references to other types will be handled via the
reloc system. Unfortunately, it seems there's an off-by-4 (hmm, suspicious
number...) in the reloc offsets, but I'll look into that after I get some
sleep.
2012-11-13 21:55:54 +09:00
Bill Currie
8625964634
Fix some careless inernal_error changes.
...
Back when I did the abort->internal_error change, I wasn't paying attention
and forgot I should use linker_internal_error in linker.c.
2012-11-13 21:51:16 +09:00