Commit graph

2112 commits

Author SHA1 Message Date
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
b5a72320bb Make alias defs and temps more obvious in dumps. 2012-12-11 12:26:48 +09:00
Bill Currie
f358364ef2 Fix assignment of nil to a structure.
constfold.c seems to be getting a little long in the tooth :P
2012-12-11 11:53:01 +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
aeed16109f Add vecinit.r to the test-suite.
Ugh, I really need to take time out to do compile tests properly.
2012-12-10 21:09:53 +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
8f274f5b1d Add convenience functions for getting a def's offset and size. 2012-12-10 14:40:43 +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
4f70b48370 Add a function to check if two defs overlap.
Very useful for alias handling :)
2012-12-10 13:23:45 +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
054d902d3a Document alias defs.
The diagram showing the basics of how alias defs work is in a spearate file
because it created to much clutter in the header file.
2012-12-09 19:43:12 +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
b28ac6672b Add support for set of everything, and a lot of docs.
Set of everything is implemented by inverting the meaning of bits in the
bitmap: 1 becomes non-member, 0 member. This means that set_size and
set_first/set_next become inverted and represent non-members as counting
members becomes impossible :)
2012-12-06 19:32:31 +09:00
Bill Currie
b6ae9867c2 Fully connect temps and their aliases. 2012-12-06 09:40:16 +09:00
Bill Currie
34e3ac1468 Fix jumpb's operand types.
Aliasing the jump table to an integer broke statement_get_targetlist with
the new alias def handling, and was really wrong anyway. I probably did
that due to being fed up with things and wanting to get qfcc working again
rather than spending time getting jumpb right.
2012-12-05 22:20:55 +09:00
Bill Currie
c06cd8fcc0 Cast constants at compile time.
This takes care of the internal error due to aliasing values.
2012-12-05 22:19:22 +09:00
Bill Currie
f7e174f3ba Be more clear about integral expression types.
Is that 7 a short? int? unsigned?
2012-12-05 22:18:13 +09:00
Bill Currie
7071a46936 Make convert_value create a new value.
It operating in-place proved to be troublesome.
2012-12-05 22:16:08 +09:00
Bill Currie
a099847026 Do a little bit of const correctness for type.[ch]
It's only the beginning :/
2012-12-05 22:15:19 +09:00
Bill Currie
fea806c155 Be more careful with boolean expressions.
Either true_list or false_list may be null.
2012-12-05 20:12:57 +09:00
Bill Currie
08b27efe33 Nuke the return type flow calculations.
They've proven to be unnecessary with the recent symbol/def changes.
2012-12-05 19:56:10 +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
3bb8b1b9d2 Make it easy to print symbol types. 2012-12-05 19:45:16 +09:00
Bill Currie
2904c619c1 Don't bother creating an alias for a def of the same type. 2012-12-05 19:43:27 +09:00
Bill Currie
cc88202f8c Fix function.h's doxgygen grouping. 2012-12-05 16:01:28 +09:00
Bill Currie
7ccfd7b9e0 Fix the wrong space for static vars.
Turns out there was only one place to fix (for qc, anyway: I don't have
tests for qp yet). func-static now passes :)

Hmm, how to test for static var naming... (not implemented yet)
2012-12-04 14:25:06 +09:00
Bill Currie
6074a6648f Do some sanity checking on storage class and defspace type.
Params and locals in virtual spaces, static vars in backed. Otherwise,
whatever (for now). Now func-static.r aborts :)
2012-12-04 14:18:17 +09:00
Bill Currie
0585471723 Make defspaces typed.
Simply "backed" and "virutal". Backed spaces have memory allocated to them
while virtual spaces do not. Virtual spaces are intended for local
variables and entity fields.
2012-12-04 14:16:52 +09:00
Bill Currie
c7b2996798 Use the correct algorithm for the new defspace size.
While the result was correct, space->size >= space->size is always true and
thus grow_space would unconditionally increase the defspace's size.
2012-12-04 14:06:36 +09:00
Bill Currie
d340aac2eb Fix the bugs marked in defspace.h
Now size is checked properly for defspace_free_loc and defspace_alloc_loc,
and defspace_alloc_loc check's grow()'s return value.
2012-12-04 13:40:00 +09:00
Bill Currie
f7bf05034f Remove func-static from XFAIL_TESTS.
I realized that's not the way it's meant to be used, and it /is/ I bug I
want fixed before release, so... :)
2012-12-04 13:27:39 +09:00
Bill Currie
98a0afa38f Add and use FREE() to complement ALLOC().
Now it will be easy to test memory access with valgrind (just compile with
DEBUG_QFCC_MEMORY defined).
2012-12-04 13:23:31 +09:00
Bill Currie
0872961269 Do a little bit of cleanup. 2012-12-04 12:48:52 +09:00
Bill Currie
1eb3349510 Add a test for function local static variables.
It turns out they're not getting allocated properly (they're put in the
function's locals defspace rather than near data), but fixing it proved a
little more problematic than expected, so the test is marked as XFAIL for
now to remind me to fix it.
2012-12-03 16:27:31 +09:00
Bill Currie
7412a45c65 Attach alias defs to their base def.
With this, alias defs become singletons based on the def they alias and the
type and offset of the alias. Thus, the removal of the free_def call in
emit.c.
2012-12-03 12:40:00 +09:00
Bill Currie
919ea8192a Make alias_def take an offset.
alias_def now always creates an offset def (though the usual case has an
offset of 0). The if the alias escapes the bounds of the base def, an
internal error will be generated.
2012-12-03 11:50:26 +09:00
Bill Currie
9d0332ae30 Make alaising a def to a larger type an internal error.
It really doesn't seem wise to allow the compiler to do so as it would
overwrite unrelated defs. The only time such a thing is valid is the return
statement (silly vm design), and that's read-only.
2012-12-03 11:38:55 +09:00
Bill Currie
9ca5a9e86c Make aliasing an alias def an internal error.
I haven't seen the bug message show up, so it seems safe, and is probably a
good idea with what I have in mind.
2012-12-03 11:36:14 +09:00
Bill Currie
cd64c0ad9b Document defspace.h 2012-12-02 22:04:54 +09:00
Bill Currie
3ecb7e8805 Mised some st_->sc_ changes.
Hiding in a comment in a header, sneaky rats ;)
2012-12-02 22:00:07 +09:00
Bill Currie
79c1a8f37a Use internal_error instead of error/exit(1).
Heh, an abort hiding in disguise :)
2012-12-02 20:15:18 +09:00
Bill Currie
e3bf64262f Remove the "data" defspace from pr_info_t.
It's only usage would have caused a segfault if it had been hit. I suspect
it's a holdover from before the rewrite of 2011.
2012-12-02 20:09:54 +09:00
Bill Currie
72108ba0b5 Document def.h.
Also remove the extern for current_storage as it belongs in shared.h.

I'm not satisfied with the documentation for initialize_def, but it will do
for now. I probably have to rewrite the thing as it's a bit of a beast.
2012-12-02 19:54:20 +09:00
Bill Currie
fd765f5e62 Fix an ownership problem with line numbers in qfos. 2012-12-02 18:59:35 +09:00
Bill Currie
5725c5124c Rename the storage_class_t enum values.
With the intoduction of the statement type enum came a prefix clash. As
"st" makes sense for "statement type", I decided that "storage class"
should be "sc". Although there haven't been any problems as of yet, I
decided it would be a good idea to clean up the clash now. It also helps
avoid confusion (I was a bit surprised after working with st_assign etc to
be reminded of st_extern etc).
2012-12-02 10:11:30 +09:00
Bill Currie
4c65d9f2a4 Fix up the definitely lost memory blocks.
qfcc isn't meant to be long running, so I'm not super worried about memory
usage, but definitely lost memory blocks when compiling just a single
function seems a tad sloppy.
2012-12-01 20:53:58 +09:00
Bill Currie
b0c08bf24b Build the tests with optimization.
Egad, the whole point of the tests was to make sure the optimizations work.
2012-12-01 16:40:37 +09:00
Bill Currie
54289da416 Fix the line number info for else.
It has bugged me for a while that the goto for else would display the if's
source line.
2012-12-01 16:37:38 +09:00
Bill Currie
7e4ec4cee4 Update qfcc's TODO
Remove old completed items, complete a couple, etc.
2012-12-01 15:41:30 +09:00
Bill Currie
d47fa0fc89 Make the new optimizations optional.
The usual -O :) (no numbers yet, though). Alternatively, -C [no-]optimize
may be used.
2012-12-01 11:13:45 +09:00
Bill Currie
848493379d Support calls through function temps.
I had forgotten function vars stored in ents and objects would use a temp
when calling the function.
2012-12-01 11:10:47 +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
df66669a87 Handle back edges in return type flow.
Turns out the flow loop needs to be repeated until there are no changes.
2012-11-30 18:25:47 +09:00
Bill Currie
9e4fb3d3e7 Fix the return type flow.
Uninitialized variable :P
So far, basic tests seem to be good.
2012-11-30 17:24:39 +09:00
Bill Currie
554b2e4710 Add flow analysis to determin the type of .return.
It doesn't quite work yet, but...

It has proven necessary to know what type .return has at any point in the
function. The segfault in ctf is caused by the return statement added to
the end of the void function messing with the expr pointer stored in the
daglabel for .return. While this is actually by design (though the
statement really should have a valid expr pointer rather than), it actually
highlights a bigger problem: there's no stable knowledge of the current
type of .return. This is not a problem in expression statements as the
dagnodes for expression statements store the desired types of all operands.
However, when assigning from .return to attached variables in a leaf node,
the type of .return is not stored anywhere but the expression last
accessing .return.
2012-11-30 17:15:05 +09:00
Bill Currie
388247791d Re-enable the dags specific flow graph dump. 2012-11-30 16:56:25 +09:00
Bill Currie
71d1804e22 Clean up flow diagrams.
Now information like dags or live variables are dumped separately, and the
live variable information replaces the flow node in the diagram (like dags
have recently).
2012-11-30 16:52:22 +09:00
Bill Currie
93f53605ed Move and rename statement related flow_is_* and flow_get_*
They really should have been in statements.[ch] in the first place
(actually, they sort of were: is_goto etc, so some redundant code has been
removed, too).
2012-11-30 14:06:52 +09:00
Bill Currie
086fd0f3c3 Correct a comment. 2012-11-30 13:57:08 +09:00
Bill Currie
e97193faf6 Add error to stub.c.
It turns out libc has an "error" function too, but the android libc does
not, thus qfprogs wouldn't link when building for droid.
2012-11-29 10:26:19 +09:00
Bill Currie
c4ba294433 Fix the icky fixme :) 2012-11-27 20:32:52 +09:00
Bill Currie
a91f4cedeb Add the @nil keyword.
@nil is exactly the same as nil, but it is always available.
2012-11-27 18:33:42 +09:00
Bill Currie
edeffd64e9 Fix a missed obj_module_s/_t from the class cleanup.
Doesn't seem to have caused any problems, but still :)
2012-11-27 18:33:42 +09:00
Bill Currie
026a992179 Add a test case for the alias chain mangling.
I think I need to rework the tests to better handle compile-only tests.
2012-11-27 18:33:41 +09:00
Bill Currie
31b07bcbbf Rewrite expr_alias().
Modifying the existing alias chain proved to be a bad idea (in retrospect,
I should have known better:P). Instead, just walk down any existing alias
chain to the root operand and build a new alias from that.
2012-11-27 18:33:41 +09:00
Bill Currie
215ff61216 Add a test for the dead boolean expression.
This tests the zombie label problem found via ctf.
2012-11-26 21:05:24 +09:00
Bill Currie
d6b38dd0ee Add an option to control expr tree dumping.
About bloody time :P
2012-11-26 21:00:28 +09:00
Bill Currie
e28aa0a5fb Fix some errors in the set code.
I really need to write some unit tests for the set code, but with this (and
an uncommitted dags patch (still thinking about it)) ctf compiles.
2012-11-26 17:19:02 +09:00
Bill Currie
8e225cd726 Fix a missing label use count decrement.
if statements in dead code weren't being removed due to the label.
2012-11-26 16:13:59 +09:00
Bill Currie
24847857ef Fix some whitespace. 2012-11-26 16:13:40 +09:00
Bill Currie
128547b885 Resurrect the "next" pointers for labels and conditionals. 2012-11-26 16:09:53 +09:00
Bill Currie
f7417345ba Rewrite print_bool to be more informative. 2012-11-26 15:47:10 +09:00
Bill Currie
147d00d41f Rewrite print_block making it more informative. 2012-11-26 15:04:33 +09:00
Bill Currie
ce1d89ba50 Replace some of the quotes around node names.
Null expression pointers can show up unexpectedly, and printf's (null)
messes up dot.
2012-11-26 14:18:23 +09:00
Bill Currie
578ad07487 Fix yet another empty block issue.
I think I need to rework all the code in there, but this will do for now.
2012-11-25 15:01:36 +09:00
Bill Currie
f6e5428382 Don't create default_expr unless needed.
The goto for the default expression is the source of the mis-counted label
users: the label was being counted by the goto, but the goto was never
being inserted into the code (only v6 progs or "difficult" types insert the
goto).
2012-11-24 21:53:00 +09:00
Bill Currie
d0e56c91cc Detect non-initial nodes with no predecessors.
Such nodes are unreachable code (ie, dead blocks), but the dead block
removal code failed to remove them (current known cause: miscounted label
userrs). As such blocks cause problems for data flow analysis, ignoring
them is not a good idea. Thus make them an internal error.
2012-11-24 21:39:02 +09:00
Bill Currie
4f8b3b5692 More empty block checks. 2012-11-24 19:06:10 +09:00
Bill Currie
6e7aaac1b9 Fix the wording of a comment. 2012-11-24 19:06:01 +09:00
Bill Currie
b68401e552 Produce a debug print when using jump tables. 2012-11-24 17:55:57 +09:00
Bill Currie
4c1dc568e0 Cop out on uninitialized large variables.
vectors, quaternions and structs are a little tricky. I need to think about
how to get them working, but I also want qfcc to get through as much code
as possible.
2012-11-24 16:49:46 +09:00
Bill Currie
40c97f9570 Tread immediate move statements similarly to assignments.
They're used for structure assignment in near data space. This fixes the
bogus uninitialized warnings on fully initialized structs.
2012-11-24 16:47:44 +09:00
Bill Currie
7f229b7682 Remove execessive html quoting.
Heh, I must have put that in long before I did the quoting functions.
2012-11-24 15:42:21 +09:00
Bill Currie
dbbca47a3b Mark initialized struct/array defs as initalized.
Also, use the initialized flag for setting up the initalized var set in
flow_uninitialized().
2012-11-24 15:26:27 +09:00
Bill Currie
f4604d9db5 Remove gotos that go to the following statement.
eg:
	goto foo:
foo:
	//some code
2012-11-24 15:08:48 +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
2478b053de Add a test for writes to global vars in a loop. 2012-11-24 14:53:45 +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