Commit graph

85 commits

Author SHA1 Message Date
Bill Currie
e27d7cbd2d Handle alloca "correctly".
Use AC_FUNC_ALLOCA and the #ifdef mess suggested by the autoconf docs
(hidden in qfalloca.h).
2013-01-22 21:02:50 +09:00
Bill Currie
412fb4aacd Fix a static out of bounds error.
I really must compile with optimizations more often :P
2012-12-26 11:51:40 +09:00
Bill Currie
386a729209 Remove dead nodes from dags.
Dead nodes are those that generate unused values (unassigned leaf nodes,
expressions or destinationless move(p) nodes). The revoval is done by the
flow analysis code (via the dags code) so that any pre and post removal
flow analysis and manipulation may be done (eg, available expressions).
2012-12-25 17:07:58 +09:00
Bill Currie
33bb422849 Force .param_N to be live when adding the edge to its node.
This fixes the segfault/null pointer access in sendv.r. While I wanted to
use the edge setting code to set the live bit, I didn't expect it to be
this easy. def_visit_all is proving to be worth every bit it consumes :)
2012-12-22 14:38:38 +09:00
Bill Currie
84a68b139e Rename set_iter_t's value to element.
Correct terminology and all :)
2012-12-21 14:09:00 +09:00
Bill Currie
6c2d0b04d3 Directly generate MOVEP for variable destination pointers.
When the destination pointer is variable, the MOVEP node will not have any
identifiers attached to it, so generate_moveps must not be used.
2012-12-20 21:28:34 +09:00
Bill Currie
7b1850917d Force RETURN's operand to be live.
This seems to be the final fix to get return-ivar.r working.
2012-12-20 21:18:27 +09:00
Bill Currie
13f09b10d6 Generate MOVEPs for attached identifiers.
The "address operator" has been stripped from the identifer so it needs to
be rebuilt, and the identifier itself is returned as the destination.
2012-12-20 20:58:19 +09:00
Bill Currie
453dacb356 Nuke dag_set_live_vars.
It is no longer needed thanks to the exit dummy node used for making
globals live.
2012-12-20 20:57:11 +09:00
Bill Currie
cc0373cdca Correct a pair of spelling mistakes.
Hopefully, noone would ever see them anyway.
2012-12-20 20:55:25 +09:00
Bill Currie
5ec4598fce Fix a double out-by-one error.
This fixes the aliasing problem brought to light by the recent dead-code
removal work.

* taniwha dons a brown paper bag.
2012-12-20 16:33:01 +09:00
Bill Currie
dc55034708 Mark aliases as live when a label is attached to a leaf node.
This fixes the lost return values in the menus.
2012-12-13 21:20:21 +09:00
Bill Currie
a7b7a114bc Don't kill the node to which an alias is being assigned.
This does not fix the lost return value the menus as that is caused by the
alias not being marked live when it should be.
2012-12-13 21:06:04 +09:00
Bill Currie
decc3845c5 Kill any aliases when assigning to an aliased def.
Temps aren't supported yet :P

The alias defs themselves aren't killed (still want any assignments to
occur) but rather, their nodes are. Also, edges to the alias defs' nodes
are added to the assigning node. Fixes structlive.r :)
2012-12-13 14:43:43 +09:00
Bill Currie
d990a956c0 More label count paranoia.
MOVEP can generate 4 daglabels.
2012-12-13 12:48:07 +09:00
Bill Currie
c295a0473e Add edges from call nodes to their param nodes.
Assinments to .param_N (0-7 for call, 2-7 for rcall) must occur before the
call, or weird things will happen.
2012-12-13 09:55:28 +09:00
Bill Currie
c477191488 Be a little more paranoid about daglabel counts.
I'm still a little worried about the number of labels needed with heavy
alias usage.
2012-12-13 09:50:18 +09:00
Bill Currie
028b19888f Check aliases for liveness when removing dead vars.
The live var flow analysis doesn't check for aliases. Rather than changing
it to check for aliases (which might break uninitialized var analysis, as
it uses "use" from the live var analysis), make dag_remove_dead_vars do the
check. Fixes the misplaced text in the menus.
2012-12-12 23:15:55 +09:00
Bill Currie
48821f379f Set edges/live for addressed variables.
This fixes (again:P) the messup with .super.
2012-12-12 12:55:17 +09:00
Bill Currie
03fdbe9b86 Ensure the def is aliasing before adding edges.
Getting two nodes doubly connected for *to = *from++; was interesting.
2012-12-12 12:52:01 +09:00
Bill Currie
75be251d65 Create and use def_visit_all.
Even though it turned out there were only two copies of the def alias
handling code, I got tired of writing it. The code is easier to read, too
:)
2012-12-12 12:01:31 +09:00
Bill Currie
76c9aa2930 Handle alias defs when building a dag.
When an alais def (or aliased def) is used, any overlapping aliases that
have previously been assigned need to be marked as live, and edges to the
aliases added to the new node. However, when assigned to, live-forcing
needs to be turned off.

This fixes the lost assignments to .super.
2012-12-11 19:57:19 +09:00
Bill Currie
7607c7d649 Resurrect alias operands.
It turns out they are necessary for the code output from dags. This fixes
the ice for *to = *from++;
2012-12-11 15:52:37 +09:00
Bill Currie
8452f69a21 Use only the real temp for daglabels.
This fixes the bogus temps for "*to = *from++;", but qfcc ices due to the
operand types being lost. It seems alias operands need to be resurrected,
if only for code output by dags.
2012-12-11 15:20:52 +09:00
Bill Currie
e0c92b6089 Rename set_iter_t's member to value.
Makes more sense now that the membership of the value depends on the
inversion of the set.
2012-12-06 21:11:38 +09:00
Bill Currie
eb8fd55677 Move set.c into libQFutil.
Also move the ALLOC/FREE macros from qfcc.h to QF/alloc.h (needed to for
set.c).

Both modules are more generally useful than just for qfcc (eg, set
builtins for ruamoko).
2012-12-06 20:52:53 +09:00
Bill Currie
3f3b501c58 Move flowvar/deflabel from symbol_t to def_t.
With the need to handle aliasing in the optimizer, it has become apparent
that having the flow data attached to symbols is not nearly as useful as
having it attached to defs (which are views of the actual variables).

This also involves a bit of a cleanup of operand types: op_pointer and
op_alias are gone (this seems to greatly simplify the optimizer)

There is a bit of a problem with enums in switch statements, but this might
actually be a sign that something is not quite right in the switch code
(other than enums not being recognized as ints for jump table
optimization).
2012-12-05 19:47:22 +09:00
Bill Currie
5e9d7d3567 Don't use the expr type for assignments.
Instead, the type is taken from the source operand (this means the computed
type of .return for that var). ctf now builds :)
2012-11-30 21:06:08 +09:00
Bill Currie
738fc65e0f Treat global vars as always live.
This fixes the infloop.r test.
2012-11-24 14:56:30 +09:00
Bill Currie
bdafdad0d5 Treat flow control statements separately.
I'm not convinced this is the correct fix for while (count--), but it does
work.
2012-11-24 12:53:51 +09:00
Bill Currie
607d7dd45e Simplify the child match in dagnode_match.
I have no idea why I did it that way when all that's needed is to check the
child pointers. Well, that's modulo.r fixed :)
2012-11-22 21:59:01 +09:00
Bill Currie
4b5e00afdf Do a bunch of refactoring.
The dag creation loop was getting too messy.
2012-11-21 18:30:44 +09:00
Bill Currie
2c09464e80 Don't attach a dag label to its own node.
This kills a = a; statements :)
2012-11-21 12:16:10 +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
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