Commit Graph

1936 Commits

Author SHA1 Message Date
Bill Currie a734feacfd Create the .parN variables for varargs functions.
Ouch, 2 years and this is the first test?
2012-11-20 17:14:58 +09:00
Bill Currie 984aa9a4cf Support entity.field = structvar2 = structvar1;
The structvar2 = structvar1 is implemented as a move expresion, which
address_expr didn't like. Return the address of the source. For indirect
move expressions, this is just the source expression itself.
2012-11-20 17:12:16 +09:00
Bill Currie 5cfeb7809f Fix a missing ; 2012-11-20 17:11:39 +09:00
Bill Currie b91bb2e915 Add direct moves to expression dumping. 2012-11-20 16:55:19 +09:00
Bill Currie 793112de9a Add some more tests.
structptr.r is actually usable for automated testing when I get around to
it.
2012-11-20 15:39:00 +09:00
Bill Currie 87121b4cf1 Be slightly picky about which nodes to kill.
Constant/label nodes should never be killed because they can (in theory)
never change. While constants /can/ change in the Quake VM, it's not worth
worrying about as there would be much more important things to worry about
(like 2+2 not giving 4).

Due to the hoops one would have to jump through, it is assumed that a
pointer or an offset from that pointer will never overwrite the pointer.
2012-11-20 15:28:57 +09:00
Bill Currie 22d72f33d2 Match pointer dereferences with pointer assignements.
Having the source operand of a pointer assignment available to later
instrctions can make for more efficient code as the value does not need to
be dereferenced later. For this purpose, pointer dereference dag nodes now
store the source operand as their value, and dagnode_match will match x=a.b
with *(a+b)=y so long as both a and b are the same in both nodes. x and y
are irrelevant to the match. The resulting code will be the equivalent of:
    *(a+b) = y;
    x = y;
2012-11-20 15:22:05 +09:00
Bill Currie 36e359e2ee Correct a typo. 2012-11-20 15:19:32 +09:00
Bill Currie ef0f30935f Kill all dag nodes on pointer assignment.
It's brutal, but it works and is conservatively correct.
2012-11-20 14:30:42 +09:00
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 06a62be1d5 Fix redundant constant values.
I had forgotten to add the new value to the hash table. Oops.
2012-11-20 13:33:57 +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 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 1e72e3eb20 Make the post-optimization sblocks dump optional. 2012-11-19 15:24:09 +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 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 c03511734d Fix a dreaded uninitialized variable.
Sneaky bastard :P (typo)
2012-11-19 12:52:24 +09:00
Bill Currie 674c823547 Set the operand type for op_label.
It was never set before (and thus void), but as it now needs to be
ev_short, set it when getting the fake def used for label operands.
2012-11-19 12:30:23 +09:00
Bill Currie 5018f5147c Use operand types rather than def types to select opcodes.
With temp types changing and temps being reused within the one instruction,
the def type is no longer usable for selecting the opcode. However, the
operand types are stable and more correct.
2012-11-19 12:28:41 +09:00
Bill Currie 60321061d2 Fix dot_expr.c to work with dump_dot(). 2012-11-19 12:14:02 +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 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 158e261a8f Give reusable temps their own linked list.
The next field is used for linking all defs in a space. Oops.
2012-11-19 10:33:03 +09:00
Bill Currie 1af4d5eeed Ensure reused temps have the correct type.
The type of a temp may change through its life as it's really the location
and name that are reused.
2012-11-19 10:31:22 +09:00
Bill Currie 4e8e94a1b2 Detect aliased temopary variables.
This takes care of some temps not being freed.
2012-11-18 20:29:40 +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 3897142038 Add a couple more tests to ptrderef.r 2012-11-18 13:28:46 +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 8fe71f2146 Display a dagnode's extra dependency edges. 2012-11-18 12:55:44 +09:00
Bill Currie d3f010a81b Fix the flow-dag connections in the flow graphs. 2012-11-18 11:34:01 +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 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