Commit Graph

101 Commits

Author SHA1 Message Date
Bill Currie c40f4194e9 Use tempop_visit_all for flow and dags
Fixes t3 of vecexpr, but t2 is broken (lost first assignment).
2019-06-16 16:56:39 +09:00
Bill Currie fa69aeef0f Improve handling of temp aliases
This makes all tests pass when not optimizing. More work needs to be
done in dags.
2019-06-12 00:37:02 +09:00
Bill Currie 78e0a8dc52 Support assigning non-constant vector expressions. 2018-10-12 22:05:17 +09:00
Bill Currie 34bcf7faab Do a pure/const/noreturn/format attribute pass.
I always wanted these, but as gcc now provides warnings for functions that
could do with such attributes, finding all the functions is much easier.
2018-10-09 12:42:21 +09:00
Bill Currie 59e85b7d5e Fix a pile of dead assignments.
Some were actual bugs!
2018-09-08 22:23:57 +09:00
Bill Currie 8fd5be0ee0 Fix a pile of sizeof goofs.
While scan-build wasn't what I was looking for, it has proven useful
anyway: many of the sizeof errors were just noise, but a few were actual
bugs (allocating too much or too little memory).
2018-09-07 20:00:57 +09:00
Bill Currie 0f279cd3f0 Add a comment about fake statement numbers.
I had forgotten how they worked (not surprising after 6 years).
2018-08-21 15:57:51 +09:00
Bill Currie 1b84ea747c Dump statements during flow analysis. 2018-08-21 15:56:39 +09:00
Bill Currie 5ba13d759b Fix a FIXME.
Set of everything got added shortly after that FIXME was added, but I
forgot to fix it.
2018-08-21 15:56:03 +09:00
Bill Currie 2329fb1885 Fix some warnings and bitrot. 2016-10-25 00:10:30 +09:00
Bill Currie ca0b03687f Change the naming of ALLOC's free-list.
Rather than prefixing free_ to the supplied name, suffix _freelist to the
supplied name. The biggest advantage of this is it allows the free-list to
be a structure member. It also cleans up the name-space a little.
2013-03-08 22:16:31 +09:00
Bill Currie 9d418379bf Use the correct type when allocating flow node edges.
sizeof (struct) vs sizeof (struct *). Ouch.
2013-01-30 18:08:59 +09:00
Bill Currie 0186ca993d Allow the uninitialized variable warning to be suppressed. 2013-01-18 16:28:08 +09:00
Bill Currie c5179c9e99 Add MOVEP's opc to the use set.
MOVEP's opc itself is always known and used, whether it's a constant
pointer or variable doesn't matter. This fixes the lost pointer calculation
for va_list.list[j] = object_from_plist (item);
2012-12-26 11:53:06 +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 92fffb3c7e Check for a flow var for temp aliases. 2012-12-25 13:22:31 +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 a51ca44b05 Record MOVEP's destination pointer only when variable.
If MOVEP's destination is variable, then the actual destination isn't (at
this stage) knowable, so it can't be attached to the dagnode and thus must
be a child.
2012-12-20 19:08:50 +09:00
Bill Currie 4d587eaa25 Use flow_analyze_statement to get statement operands.
Getting the operands directly from the statement was missing the
destination operand of movep when movep's op_c was a constant pointer and
thus the flowvar wasn't being counted/created early enough. This led to a
segfault in the set code when attempting to add -1 to the set.
2012-12-20 19:02:55 +09:00
Bill Currie 21b5ea8075 Remove unreachable nodes.
Any nodes still marked as unreachable (dfn < 0) need to be removed so
graph->dfo is valid (only one node 0).
2012-12-19 17:08:48 +09:00
Bill Currie 3270bb3f5e Make node numbering int rather than unsigned.
(unsigned) -1 is not what I wanted :P
2012-12-19 16:50:06 +09:00
Bill Currie 927335a29c Break out the successors and edges code.
This will make for nicer code when everything is looped for unreachable
node removal.
2012-12-19 16:23:08 +09:00
Bill Currie c7ae58d7a3 Allow flownodes and sblocks to be numbered independently.
The numbering will need to be independent when unreachable nodes are
removed.
2012-12-19 16:22:15 +09:00
Bill Currie 9d35ca607f Mark all nodes as unreachable.
flow_build_dfst() marks a reacable node as such by setting the node's dfn
to a value >= 0.
2012-12-19 16:00:58 +09:00
Bill Currie 32556b7210 Initialize the graph's depth first order array.
Unreachable nodes will cause the first elements of the array to remain
unwritten by df_search. This fixes the segfaults caused by unreachable
nodes (the reason they were an internal error before).
2012-12-19 15:55:29 +09:00
Bill Currie a7e9defebd Remove the non-initial parentless node check.
Its purpose was to catch when the old dead block remover failed to remove
unreachable blocks, but that code is now gone.
2012-12-19 15:31:32 +09:00
Bill Currie 503154257c Fix an uninitialized variable.
Yay valgrind, boo taniwha.
2012-12-13 13:58:30 +09:00
Bill Currie 5681e0fd42 Treat certain move instructions as assignments.
MOVE (static move) and MOVEP to a pointer constant know exactly where their
data is going, so treat them similarly to assignments: save their
distination operands (the addressed def for MOVEP) and mark them as
defined.
2012-12-13 12:50:00 +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 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 50b0bd0b95 Use define from temp aliases as well to kill uninit defines.
Finally, the uninitialized temp warnings are fixed.
2012-12-11 13:04:06 +09:00
Bill Currie 5083679fcc Don't mask out the dummy defines from temp kills. 2012-12-11 12:58:16 +09:00
Bill Currie 28c37b367d Fix the dummy definitions of temp vars.
I forgot to add func->num_statements :P. Fixes the weirdness where only
some alias temps were being (bogusly) detected as uninitialized. Now they
all are.
2012-12-11 12:27:23 +09:00
Bill Currie 8582e9de63 Make it possible to dump statement blocks in a flow graph.
Much nicer looking with proper back edges :). Not actually enabled, though.
2012-12-11 11:31:55 +09:00
Bill Currie 3aa3a0945a Scan the statements in a node with suspect var usage.
When the naive uninitialized variable detection finds a node with possible
uses of uninitialized variables, the statements in the node are scanned one
at a time checking each usage and removing uninitialized definitions as
appropriate. vectest.r now compiles without warnings. As an added bonus,
accurate line number information is reported for uninitialized variables.

Unfortunately, there is still a problem with uninitialized temps in
switch.r, but that might just be poor handling of temp op aliases.
2012-12-10 20:49:08 +09:00
Bill Currie 426363cd0d Don't kill aliased definitions in the entry dummy block.
Only definitions for the def used in the current statement (whether an
alias or not) are suitable for killing. Doing otherwise defeats the purpose
of this work :P

Fixes the false negatives found in a modified quattest.r (commented out the
"tq.s = 0;" line).
2012-12-10 19:42:31 +09:00
Bill Currie aa97979d98 Rewrite flow_uninitialized() to use reaching defs.
Nicely, the use sets from live_variable analysis can be used too, though
there are some problems with the naive implementation. For:

vector foo (float x, float y, float z)
{
	vector v;
	v.x = x;
	v.y = y;
	v.z = z;
	return v;
}

qfcc thinks v is uninitialized, but if "if (x) return nil;" (or any other
basic-block splitter) is put just before the return v; qfcc correctly
detects that v is initialized. The reason is that the inits are in the same
basic block as the return, and thus aren't affecting the reaching
definitions, which are stored per-block.

The naive implementation should be good for a fast-cull before doing a
per-statement check.
2012-12-10 15:58:51 +09:00
Bill Currie c47cb697de Create dummy uses for global variables
The exit dummy block is setup to provide dummy uses of global variables to
the live variable analysis doesn't miss global variables. Much cleaner than
the previous code :) There may be some issues with aliases, though.
2012-12-10 15:27:07 +09:00
Bill Currie 2e105f17f2 Enable live var flow dumps. 2012-12-10 15:27:07 +09:00
Bill Currie d2f2fdc28e Create dummy definitions for local variables.
The entry dummy block is setup to provide dummy definitions of local
variables so the reaching definitions analysis can be used to detect
uninitialized variables (not implemented yet). Fake statement numbers
(func->num_statements + X) are used to represent the definitions. Local
variables (ie, not temp ops) use their offsets (ie, the offset range they
cover) for X. Temp ops use their flowvar number + the size of the
function's defspace for X. flow_kill_aliases() should take care of temp op
aliasing, while the use of the actual offsets spanned by the variable's def
should take care of any wild aliasing so structures and unions should
become a non-issue.
2012-12-10 15:26:47 +09:00
Bill Currie d717a0b3f2 Add dummy nodes at the beginning and end of the graph.
The dummy nodes are for detectining uninitialized variables (entry dummy)
and making globals live at function exit (exit dummy). The reaching defs
and live vars code currently seg because neither node has had its sets
initialized.
2012-12-10 13:56:26 +09:00
Bill Currie f30741c875 Add fixed aliases to a statement's kill set.
Fixed aliases are those that will never change through the life of the
code. They are generated from structure accesses and thus what they alias
is always known.
2012-12-10 13:25:06 +09:00
Bill Currie fa45ab842f Make the reaching defs dot dump optional. 2012-12-10 12:17:20 +09:00
Bill Currie e4dd86c36b Calculate reaching defs. 2012-12-09 22:37:59 +09:00
Bill Currie f3adb70ee4 Move the var def/use calculation into flow_build_vars(). 2012-12-09 21:22:57 +09:00
Bill Currie 2bc3a36126 Split out the statement array building. 2012-12-09 21:12:53 +09:00
Bill Currie 17a2f86a22 Correct some comments. 2012-12-09 21:12:33 +09:00
Bill Currie 1c99cf50da Clean up the flow api a little. 2012-12-09 20:50:53 +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