cen64.git
6 months agocompiler: Optimize renaming in SSA a little more. master
Tyler J. Stachecki [Sun, 23 Apr 2017 14:20:24 +0000 (10:20 -0400)]
compiler: Optimize renaming in SSA a little more.

Some of the variable cloning logic was duplicated (as it
was mostly transcribed from literature). We can leverage
the fact that our stores and phis are almost identical.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler: Optimize renaming in SSA a little more.
Tyler J. Stachecki [Sun, 23 Apr 2017 14:03:10 +0000 (10:03 -0400)]
compiler: Optimize renaming in SSA a little more.

When populating phi nodes in immediate successors, we can
break out of the loop when scanning for our predecessor
index early (the compiler can't do this for us, as it does
not know that we're the only basic block in the list).

Also, augment the stack_top method so that it returns a
value if the stack does not currently have any items. In
most cases, this would be NULL... however, we can save a
conditional branch in mosts cases if it's not.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler: Reserve BB#0 for "null" comparison.
Tyler J. Stachecki [Sun, 23 Apr 2017 13:20:56 +0000 (09:20 -0400)]
compiler: Reserve BB#0 for "null" comparison.

Since we're using integers to represent our basic block
numbers, reserve the first basic block (BB#0) and use it
as a "null" value.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler: Attempt to hoist a load in set.
Tyler J. Stachecki [Sun, 23 Apr 2017 13:19:18 +0000 (09:19 -0400)]
compiler: Attempt to hoist a load in set.

Not sure if this will make a difference or not, but try
to coerce the compiler into hoisting the load for the tree
traversal before doing the check while doing set inserts.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler: Optimize renaming in SSA conversion.
Tyler J. Stachecki [Sun, 23 Apr 2017 12:29:53 +0000 (08:29 -0400)]
compiler: Optimize renaming in SSA conversion.

Instead of pushing N entries onto the variable stack, one
for each renamed instance within a basic block, only push
one per variable per block (and update the top of the
stack as needed when there is more than 1 entry).

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler: Add Briggs-Cooper-Harvey-Simpson.
Tyler J. Stachecki [Sun, 23 Apr 2017 02:24:52 +0000 (22:24 -0400)]
compiler: Add Briggs-Cooper-Harvey-Simpson.

This paper contains a lot of the algorithms used to
convert the CFG into minimal SSA form.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler: Rename variables during SSA conversion.
Tyler J. Stachecki [Sat, 22 Apr 2017 22:50:18 +0000 (18:50 -0400)]
compiler: Rename variables during SSA conversion.

Rename variables so that the graph adheres to single
static assignment form.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler: Add a stack data structure.
Tyler J. Stachecki [Sat, 22 Apr 2017 18:12:22 +0000 (14:12 -0400)]
compiler: Add a stack data structure.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler: Add some pure attributes to variable_ht.
Tyler J. Stachecki [Sat, 22 Apr 2017 17:55:50 +0000 (13:55 -0400)]
compiler: Add some pure attributes to variable_ht.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler: Place phi nodes in stores during SSA.
Tyler J. Stachecki [Sat, 22 Apr 2017 16:34:51 +0000 (12:34 -0400)]
compiler: Place phi nodes in stores during SSA.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler: Optimize dominator tree construction.
Tyler J. Stachecki [Sat, 22 Apr 2017 15:47:02 +0000 (11:47 -0400)]
compiler: Optimize dominator tree construction.

Instead of doing two passes on the list of basic blocks in
order to constructor the dominator tree, only perform one
pass (by making use of the bb_flag_list and by constructing
our immediate dominator's tree early if needed).

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 months agocompiler/lexer: optimizations from izy.
Tyler J. Stachecki [Sat, 22 Apr 2017 14:29:56 +0000 (10:29 -0400)]
compiler/lexer: optimizations from izy.

izy sent some optimizations for the lexer that remove
duplicate code and turn some messy if/else chain into a
series of ifs that may result in better generated code.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Rename variables during SSA.
Tyler J. Stachecki [Sun, 9 Apr 2017 23:36:30 +0000 (19:36 -0400)]
compiler: Rename variables during SSA.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Place phi nodes into CFG during SSA.
Tyler J. Stachecki [Fri, 7 Apr 2017 23:51:10 +0000 (19:51 -0400)]
compiler: Place phi nodes into CFG during SSA.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Remove an unused function.
Tyler J. Stachecki [Fri, 7 Apr 2017 19:04:50 +0000 (15:04 -0400)]
compiler: Remove an unused function.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Fix an issue with scoping rules.
Tyler J. Stachecki [Fri, 7 Apr 2017 18:57:51 +0000 (14:57 -0400)]
compiler: Fix an issue with scoping rules.

The compiler's IR has no concept of scope. Thus, you could
previously write horrible code such as the following:

```
if (condition) (
  devar magic as i32
) else (
  devar magic as i32
)

assign value to magic
```

and the semantic analyzer would be unable to detect any
problems. This commit adds the minimal amount of scope
information to conditional branches in order to be able
to detect this sort of thing and disallow it.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agoos: Fix a comment.
Tyler J. Stachecki [Sun, 26 Mar 2017 21:25:26 +0000 (17:25 -0400)]
os: Fix a comment.

If malloc returns non-NULL pointers on failures, there
would probably be some issues arising as a result.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agogcc: Drop dependency on setjmp/longjmp.
Tyler J. Stachecki [Sun, 26 Mar 2017 17:43:11 +0000 (13:43 -0400)]
gcc: Drop dependency on setjmp/longjmp.

If compiling with GCC (and I mean just that - not clang or
ICC), then use __builtin_setjmp and __builtin_longjmp in
leiu of libc's. This will help break dependence on MSVCRT
when targeting Windows.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agoos: Add support for private/OS-specific heaps.
Tyler J. Stachecki [Sun, 26 Mar 2017 16:28:39 +0000 (12:28 -0400)]
os: Add support for private/OS-specific heaps.

Leverage heaps other than what is provided by the cstdlib
where possible. This commit mostly helps to drop a runtime
dependency on malloc/free for Windows builds.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agoos: Add support for native file access.
Tyler J. Stachecki [Sun, 26 Mar 2017 14:34:18 +0000 (10:34 -0400)]
os: Add support for native file access.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Fix another allocator bug.
Tyler J. Stachecki [Sun, 26 Mar 2017 12:39:26 +0000 (08:39 -0400)]
compiler: Fix another allocator bug.

The set allocator was not expanding correctly: it would
allocate an entire new subblock page each time it needed
to allocate a new set node (and subsequently lose track of
the newly allocated subblock).

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Use sets instead of bblists.
Tyler J. Stachecki [Sun, 26 Mar 2017 02:16:01 +0000 (22:16 -0400)]
compiler: Use sets instead of bblists.

Most of the SSA algorithms implemented so far expect to be
working with sets (not lists). Use sets throughout the SSA
pass where necessary.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Fix another allocator bug.
Tyler J. Stachecki [Sun, 26 Mar 2017 01:33:27 +0000 (21:33 -0400)]
compiler: Fix another allocator bug.

The allocator is expected to perform like calloc (i.e.,
all memory allocated shall be zeroed upon return from any
allocator function).

When cen64_arena_free_slack_and_unlock interface was added,
the used memory region was not begin zeroed out after it
was returned and causing problems with allocations further
down the line (which were expecting that the memory would
be wiped, but it was not).

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Allow sets to "self allocate" themselves.
Tyler J. Stachecki [Sat, 25 Mar 2017 23:19:20 +0000 (19:19 -0400)]
compiler: Allow sets to "self allocate" themselves.

Set objects are generally about the same size as the nodes
which they contain. Thus, when allocating a set, allocate
the set on top of its own subblock allocator. This saves
the caller the hassle of having to find space themselves
at little to no cost of performance.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Fix an allocator bug.
Tyler J. Stachecki [Sat, 25 Mar 2017 20:42:56 +0000 (16:42 -0400)]
compiler: Fix an allocator bug.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Minor allocator optimizations.
Tyler J. Stachecki [Sat, 25 Mar 2017 19:30:15 +0000 (15:30 -0400)]
compiler: Minor allocator optimizations.

Blocks should already have their memory zeroed out before
we dish out memory, so setting some fields to NULL is not
necessary.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Add an (ordered) set data structure.
Tyler J. Stachecki [Sat, 25 Mar 2017 17:02:14 +0000 (13:02 -0400)]
compiler: Add an (ordered) set data structure.

CEN64's arena allocator is very inflexible and not well-
suited to hash tables (as they really require variable-
sized buckets to correct the distribution of items once
the load factor starts getting out of hand).

For that reason, add a tree (set) data structure, which
can be used to track countless numbers of items without
having to sacrifice the simplicity of CEN64's allocator).

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Compute dominance frontier during SSA.
Tyler J. Stachecki [Sat, 25 Mar 2017 14:01:41 +0000 (10:01 -0400)]
compiler: Compute dominance frontier during SSA.

Compute the dominance frontier for each node and cache the
result in a bblist (along with the idom). The dominance
frontier will be used shortly to insert phi nodes into the
control flow graph where necessary.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
7 months agocompiler: Fix a parser bug.
Tyler J. Stachecki [Sat, 25 Mar 2017 12:37:02 +0000 (08:37 -0400)]
compiler: Fix a parser bug.

When the parser inserts a new basic block for the
invariant, it must also insert a branch from the previous
basic block.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Fix a memory allocation bug in bblist.
Tyler J. Stachecki [Sun, 19 Mar 2017 22:06:13 +0000 (18:06 -0400)]
compiler: Fix a memory allocation bug in bblist.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Optimize Lengauer-Tarjan allocation.
Tyler J. Stachecki [Sun, 19 Mar 2017 17:30:59 +0000 (13:30 -0400)]
compiler: Optimize Lengauer-Tarjan allocation.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Allow clients to use the arena's slack
Tyler J. Stachecki [Sun, 19 Mar 2017 16:51:30 +0000 (12:51 -0400)]
compiler: Allow clients to use the arena's slack

The compiler will need to allocate large, dynamic slices of
memory (i.e,. arrays). In some cases, the unused portion,
or "slack", in the arena allocator's head block can be used
to service such allocations. This commit provides clients
of the arena with a means for doing so.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Compute dominators for SSA conversion
Tyler J. Stachecki [Sun, 19 Mar 2017 14:50:45 +0000 (10:50 -0400)]
compiler: Compute dominators for SSA conversion

Implement Lengauer and Tarjan's algorithm for quickly
finding immediate dominators in the flow graph.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocmake: Add toolchain files for osxcross (x86_64).
Tyler J. Stachecki [Sun, 19 Mar 2017 00:54:08 +0000 (00:54 +0000)]
cmake: Add toolchain files for osxcross (x86_64).

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agodriver: Fix a small bug in argument check.
Tyler J. Stachecki [Thu, 16 Mar 2017 02:35:52 +0000 (22:35 -0400)]
driver: Fix a small bug in argument check.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agoos: Fix build issues with mingw-w64.
Tyler J. Stachecki [Mon, 13 Mar 2017 00:32:52 +0000 (00:32 +0000)]
os: Fix build issues with mingw-w64.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Fill error_message on parser failures.
Tyler J. Stachecki [Sun, 12 Mar 2017 23:46:49 +0000 (19:46 -0400)]
compiler: Fill error_message on parser failures.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agoos/alloc: Don't mmap on top of /dev/null.
Tyler J. Stachecki [Sun, 12 Mar 2017 22:40:55 +0000 (18:40 -0400)]
os/alloc: Don't mmap on top of /dev/null.

This didn't really provide any benefit and it's not
portable. Macs, in particular, will bork on this.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocmake: Define _DARWIN_C_SOURCE if needed.
Tyler J. Stachecki [Sun, 12 Mar 2017 21:12:44 +0000 (17:12 -0400)]
cmake: Define _DARWIN_C_SOURCE if needed.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler/x86_64: Fix gcc build issue.
Tyler J. Stachecki [Sun, 12 Mar 2017 13:20:17 +0000 (09:20 -0400)]
compiler/x86_64: Fix gcc build issue.

gcc was complaining about the fact that a variable on the
stack could get clobbered in the event of a longjmp. While
it is technically correct, the fact that something could
be clobbered doesn't matter here since the variable could
not be referenced if a longjmp is performed anyways (since
it's out of scope at that point).

The warning (-Wclobbered) has actually saved me in a few
instances... so instead of disabling the error, put a lame
patch in the code so that gcc shuts up.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocmake: Allow clang to build with -Werror cleanly.
Tyler J. Stachecki [Sun, 12 Mar 2017 04:15:56 +0000 (23:15 -0500)]
cmake: Allow clang to build with -Werror cleanly.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Small readability change to bblist.
Tyler J. Stachecki [Sat, 11 Mar 2017 01:10:31 +0000 (20:10 -0500)]
compiler: Small readability change to bblist.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Populate basic block pred/succ lists.
Tyler J. Stachecki [Sun, 26 Feb 2017 17:40:45 +0000 (12:40 -0500)]
compiler: Populate basic block pred/succ lists.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Add a basic block list data structure.
Tyler J. Stachecki [Sun, 26 Feb 2017 00:14:37 +0000 (19:14 -0500)]
compiler: Add a basic block list data structure.

Add a data structure that can effectively track lists of
basic blocks (really, compiler nodes, but in practice it
will be used to track basic blocks).

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Enhance the basic block nodes.
Tyler J. Stachecki [Sat, 25 Feb 2017 22:45:54 +0000 (17:45 -0500)]
compiler: Enhance the basic block nodes.

Pull the basic block ID out of the basic block structure,
and re-purpose the otherwise unused line_number field of
compiler nodes to hold the ID for basic blocks instead.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Kill the existing SSA conversion pass.
Tyler J. Stachecki [Sat, 25 Feb 2017 20:39:04 +0000 (15:39 -0500)]
compiler: Kill the existing SSA conversion pass.

It did not really work and needs to be rewritten properly
anyways. Instead of killing all the lines in the commit(s)
which implement the correct functionality, do it all here.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Add a BB-related data structure.
Tyler J. Stachecki [Sat, 25 Feb 2017 20:33:10 +0000 (15:33 -0500)]
compiler: Add a BB-related data structure.

A lot of passes will need to mark and sweep BBs as they
are visited. Instead of reallocing memory and freeing it
every time this kind of design pattern is used, provide
an array that lives across all passes which can be used
instead.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler/x86_64: Simplify backend.
Tyler J. Stachecki [Sat, 25 Feb 2017 20:04:18 +0000 (15:04 -0500)]
compiler/x86_64: Simplify backend.

Move all machine code generation into cen64_lower_and_gen.
Furthermore, allow the entrypoint to be anywhere in the
generated memory segment (as opposed to just the start of
it) to potentially allow the backend to better place code
segments in the resulting image.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler/x86_64: Fix a minor bug in the backend.
Tyler J. Stachecki [Sat, 25 Feb 2017 19:40:06 +0000 (14:40 -0500)]
compiler/x86_64: Fix a minor bug in the backend.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Fix a minor bug in the lexer.
Tyler J. Stachecki [Sat, 25 Feb 2017 19:39:54 +0000 (14:39 -0500)]
compiler: Fix a minor bug in the lexer.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Restore backend functionality.
Tyler J. Stachecki [Sat, 25 Feb 2017 18:46:05 +0000 (13:46 -0500)]
compiler: Restore backend functionality.

The backend broke after the introduction of the basic
block architecture. Fix outstanding issues that prevented
it from working.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Rename identifier allocator to dynsize.
Tyler J. Stachecki [Sat, 25 Feb 2017 17:56:13 +0000 (12:56 -0500)]
compiler: Rename identifier allocator to dynsize.

Currently, though even more so in the future, the allocator
that was previously being used to allocate dynamically-
sized strings will be used to allocate several types of
small objects. Thus, it's more aptly named the dynamic-
size allocator (or dynsize).

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Add support for while loops.
Tyler J. Stachecki [Sat, 25 Feb 2017 17:22:16 +0000 (12:22 -0500)]
compiler: Add support for while loops.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Add support for return statements.
Tyler J. Stachecki [Sat, 25 Feb 2017 02:35:19 +0000 (21:35 -0500)]
compiler: Add support for return statements.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
8 months agocompiler: Small parser simplification.
Tyler J. Stachecki [Sat, 25 Feb 2017 01:42:15 +0000 (20:42 -0500)]
compiler: Small parser simplification.

The parser is always writing to the last basic block in
the scope, so just assign the "last basic block" marker
just before leaving the scope.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
9 months agocompiler: Use basic blocks to organize the graph.
Tyler J. Stachecki [Sun, 12 Feb 2017 15:55:37 +0000 (10:55 -0500)]
compiler: Use basic blocks to organize the graph.

I was hoping that it wouldn't be necessary to use basic
blocks and follow "traditional" compiler methodologies as
far as the graph layout goes, but trying to implement
algorithms without them turned out to be quite difficult.

This should introduce basic blocks and bring the compiler
on feature parity with the previous non-basic block
oriented version. Hopefully I didn't introduce any bugs in
the process.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
9 months agoos: Fix a typo in a comment.
Tyler J. Stachecki [Fri, 10 Feb 2017 02:03:55 +0000 (21:03 -0500)]
os: Fix a typo in a comment.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
12 months agocompiler: Start implementing the SSA conversion.
Tyler J. Stachecki [Sat, 22 Oct 2016 21:13:22 +0000 (17:13 -0400)]
compiler: Start implementing the SSA conversion.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
12 months agocompiler: Make use of compiler node's prev field.
Tyler J. Stachecki [Sat, 22 Oct 2016 17:46:42 +0000 (13:46 -0400)]
compiler: Make use of compiler node's prev field.

In the parser, assign the value of node->prev accordingly
when building the graph. In the printer, assert that the
value of of prev points to the expected node when debugging
is enabled.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
12 months agocompiler: Pack namespace and type/name together.
Tyler J. Stachecki [Fri, 21 Oct 2016 12:59:04 +0000 (08:59 -0400)]
compiler: Pack namespace and type/name together.

In compiler node, namespace and type/name pairs were taking
8b/16b. By packing them together in a structure and pointing
to only the type/name structure, we half that size.

Take advantage of the packed size to add a prev field to the
compiler node structure (not yet implemented; always NULL).

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
12 months agocompiler: Improve semantic analysis type checking.
Tyler J. Stachecki [Sun, 25 Sep 2016 19:29:05 +0000 (15:29 -0400)]
compiler: Improve semantic analysis type checking.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
13 months agocompiler: Minor optimizations.
Tyler J. Stachecki [Sat, 24 Sep 2016 15:43:16 +0000 (11:43 -0400)]
compiler: Minor optimizations.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
13 months agocompiler: Fix object analysis bugs, qualifier issues.
Tyler J. Stachecki [Sat, 24 Sep 2016 01:06:39 +0000 (21:06 -0400)]
compiler: Fix object analysis bugs, qualifier issues.

Object analysis was failing in two cases (one in which the
object members were not being aligned correctly in some
instances, and another in which objects were being visited
for analysis more than once).

Furthermore, don't use an enum to store qualifiers since
doing bitwise operations since we want to pack qualifiers
into a single field (and doing bitwise operations on with
enums is a bad idea).

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
14 months agocompiler: nit: Remove old comment.
Tyler J. Stachecki [Thu, 15 Sep 2016 23:27:49 +0000 (19:27 -0400)]
compiler: nit: Remove old comment.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
14 months agocompiler: Fold object analysis into the list builder.
Tyler J. Stachecki [Thu, 15 Sep 2016 22:46:20 +0000 (18:46 -0400)]
compiler: Fold object analysis into the list builder.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
14 months agocompiler: Reduce and fix size of a compiler node.
Tyler J. Stachecki [Tue, 13 Sep 2016 14:04:58 +0000 (10:04 -0400)]
compiler: Reduce and fix size of a compiler node.

Cut down on the size of cen64_compiler_node so it fits into
a cache line on x86(_64) builds (64 bytes). This improves
performance and increases the amount of compiler nodes we
can fit into a single page.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
14 months agocompiler: Make parser longjmp-safe.
Tyler J. Stachecki [Thu, 1 Sep 2016 19:19:20 +0000 (15:19 -0400)]
compiler: Make parser longjmp-safe.

Non-volatile-qualified objects shouldn't be accessed after
a longjmp unless they were qualified as volatile. Make sure
that the parser pointer and any necessary members are
qualified as volatile so they are destructed safely.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
14 months agocompiler: Use a W^X policy for the JIT.
Tyler J. Stachecki [Thu, 1 Sep 2016 18:34:51 +0000 (14:34 -0400)]
compiler: Use a W^X policy for the JIT.

Compiler/JIT-allocated pages should either be readable/
writable or execute, but not both, at any given time.

Instead of specifying the policy of the memory pages when
they are allocated, they are initially not executable and
can be changed on-the-fly using a pair of new functions:
cen64_os_alloc_make_exec and cen64_os_alloc_make_rw.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
14 months agocompiler: Silence a warning produced by GCC.
Tyler J. Stachecki [Thu, 1 Sep 2016 16:54:19 +0000 (12:54 -0400)]
compiler: Silence a warning produced by GCC.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Add a SSA conversion pass.
Tyler J. Stachecki [Sat, 13 Aug 2016 14:01:38 +0000 (10:01 -0400)]
compiler: Add a SSA conversion pass.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Start hashing out semantic analysis.
Tyler J. Stachecki [Fri, 12 Aug 2016 19:22:28 +0000 (15:22 -0400)]
compiler: Start hashing out semantic analysis.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agoos/posix: Fix a derpy buffer-related bug.
Tyler J. Stachecki [Tue, 9 Aug 2016 20:29:03 +0000 (16:29 -0400)]
os/posix: Fix a derpy buffer-related bug.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agoos/winapi: Fix large page allocation.
Tyler J. Stachecki [Sun, 7 Aug 2016 19:23:46 +0000 (15:23 -0400)]
os/winapi: Fix large page allocation.

Fallback to regular-sized page allocation when large page
allocation fails. Most users will not be able to allocate
using large pages due to the fact that it requires a very
specific user account privilege.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agoos/winapi: Fix MSVC build errors and warnings.
Tyler J. Stachecki [Sun, 7 Aug 2016 18:10:09 +0000 (14:10 -0400)]
os/winapi: Fix MSVC build errors and warnings.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocen64: Add support for building with ICC.
Tyler J. Stachecki [Sun, 7 Aug 2016 17:31:47 +0000 (13:31 -0400)]
cen64: Add support for building with ICC.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agoos/posix: Fix issue preventing inlining from occurring.
Tyler J. Stachecki [Sat, 6 Aug 2016 00:20:29 +0000 (20:20 -0400)]
os/posix: Fix issue preventing inlining from occurring.

Due to using an obnoxiously large buffer size, GCC was not
inlining a function used in the allocator. Trim down the
buffer size to something more reasonable.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocmake: Strip symbols from shared objects.
Tyler J. Stachecki [Sat, 6 Aug 2016 00:19:14 +0000 (20:19 -0400)]
cmake: Strip symbols from shared objects.

If the build is a release build of some form, symbols
should be stripped from shared objects, just as they are
for executables.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agoos: Coerce compiler into inlining thread functions.
Tyler J. Stachecki [Fri, 5 Aug 2016 23:11:35 +0000 (19:11 -0400)]
os: Coerce compiler into inlining thread functions.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Prefix some external symbols with cen64_.
Tyler J. Stachecki [Fri, 5 Aug 2016 22:44:00 +0000 (18:44 -0400)]
compiler: Prefix some external symbols with cen64_.

Upon inspection, some symbols were being exported without
a cen64_ prefix. We want to be consistent, so add prefixes
accordingly.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agolibretro: Hide non-retro_* symbols in the core.
Tyler J. Stachecki [Thu, 4 Aug 2016 21:59:59 +0000 (17:59 -0400)]
libretro: Hide non-retro_* symbols in the core.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocen64: Modularize a bit of functionality.
Tyler J. Stachecki [Thu, 4 Aug 2016 21:23:00 +0000 (17:23 -0400)]
cen64: Modularize a bit of functionality.

Modularizing functionality in the manner that this commit
does not only reduces the amount of code duplication across
multiple targets, but also facilitates the Libretro port.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agolibretro: Begin adding Libretro support.
Tyler J. Stachecki [Thu, 4 Aug 2016 20:50:32 +0000 (16:50 -0400)]
libretro: Begin adding Libretro support.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Remove an unneeded #include. No code change.
Tyler J. Stachecki [Thu, 4 Aug 2016 19:45:58 +0000 (15:45 -0400)]
compiler: Remove an unneeded #include. No code change.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Unflag suballocator initialization as cold.
Tyler J. Stachecki [Thu, 4 Aug 2016 16:57:28 +0000 (12:57 -0400)]
compiler: Unflag suballocator initialization as cold.

We re-initialize the suballocators each time we compile
something; these are no longer infrequent operations!

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocmake: Use aggressive optimization options where available.
Tyler J. Stachecki [Thu, 4 Aug 2016 16:53:34 +0000 (12:53 -0400)]
cmake: Use aggressive optimization options where available.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler/parser: Fix error message bug.
Tyler J. Stachecki [Thu, 4 Aug 2016 16:39:42 +0000 (12:39 -0400)]
compiler/parser: Fix error message bug.

Error messages were not being displayed correctly in some
cases due to the parallel table of lexemes -> error strings
not being updated after the addition of else/elseif.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Unflag parser creation/destruction as cold.
Tyler J. Stachecki [Thu, 4 Aug 2016 16:19:03 +0000 (12:19 -0400)]
compiler: Unflag parser creation/destruction as cold.

We create a lexer and parser each time we compile something
from source; these are no longer infrequent operations!

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Fix small #include issue, no code change.
Tyler J. Stachecki [Thu, 4 Aug 2016 16:11:01 +0000 (12:11 -0400)]
compiler: Fix small #include issue, no code change.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Remove parser from the driver object.
Tyler J. Stachecki [Thu, 4 Aug 2016 16:05:39 +0000 (12:05 -0400)]
compiler: Remove parser from the driver object.

The parser reference should only be accessible from within
the compiler itself. Nobody else should be touching it.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler/x86_64: Optimize SIMD code emission.
Tyler J. Stachecki [Thu, 4 Aug 2016 15:43:57 +0000 (11:43 -0400)]
compiler/x86_64: Optimize SIMD code emission.

De-duplicate some methods that emitted x86_64 native code.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Change function parameter -> variable.
Tyler J. Stachecki [Wed, 3 Aug 2016 23:45:00 +0000 (19:45 -0400)]
compiler: Change function parameter -> variable.

Really, function parameters are just 'input variables',
which we bind values to whenever we call a function. The
function parameter node had all the same fields that a
variable node did. So this commit merges the two nodes.

Semantic analysis was also changed so that we can detect
when a function parameter shadows another parameter, or
when a variable in a function shadows a parameter.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocmake: Fix ignored build type issue.
Tyler J. Stachecki [Wed, 3 Aug 2016 17:08:19 +0000 (13:08 -0400)]
cmake: Fix ignored build type issue.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Add a variable hash table data structure.
Tyler J. Stachecki [Wed, 3 Aug 2016 16:56:36 +0000 (12:56 -0400)]
compiler: Add a variable hash table data structure.

Allow us to reference variables via a hash table for fast
resolution. Hash tables are allocated using the existing
arena allocator. Collisions are handled via an intrusive
linked list.

When I introduced this into the compiler, it became clear
that accessing a variable that is a member of another
namespace would result in additional overhead, as both the
variable name and namespace must be checked. Seeing as the
parser provided no means for defining a variable in another
namespace anyways, I altered the grammar such that it is no
longer possible to reference a variable from another
namespace.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agodriver: Return a non-zero exit status on failure.
Tyler J. Stachecki [Wed, 3 Aug 2016 14:50:53 +0000 (10:50 -0400)]
driver: Return a non-zero exit status on failure.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Minor fixes. No code change.
Tyler J. Stachecki [Sat, 30 Jul 2016 20:01:40 +0000 (16:01 -0400)]
compiler: Minor fixes. No code change.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Don't destroy the allocator prematurely.
Tyler J. Stachecki [Sat, 30 Jul 2016 19:46:27 +0000 (15:46 -0400)]
compiler: Don't destroy the allocator prematurely.

We shouldn't destroy the allocator when a compilation fails
because of a syntax error or something. We probably want to
try and see if we can handle the error gracefully or try to
compile something else.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Reduce # of allocations for small blobs.
Tyler J. Stachecki [Sat, 30 Jul 2016 19:11:34 +0000 (15:11 -0400)]
compiler: Reduce # of allocations for small blobs.

Place the suballocator 'head' metadata on the stack, but
leave the allocation data itself on the arena. This way, we
don't waste a subblock of data for each suballocator type.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Reduce memset overhead slightly.
Tyler J. Stachecki [Sat, 30 Jul 2016 18:59:11 +0000 (14:59 -0400)]
compiler: Reduce memset overhead slightly.

Use the arena for the instruction allocator. Move all
memset code out of suballocators and into the arena proper.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler/lexer: Small performance optimization.
Tyler J. Stachecki [Sat, 30 Jul 2016 18:44:46 +0000 (14:44 -0400)]
compiler/lexer: Small performance optimization.

Reduce the number of calls to libc feof when the buffer
starts becoming empty, or in the event we don't get a
short read.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
15 months agocompiler: Ensure arena memory is wiped before use.
Tyler J. Stachecki [Sat, 30 Jul 2016 17:53:36 +0000 (13:53 -0400)]
compiler: Ensure arena memory is wiped before use.

Ensure that all memory provided by the arena and any
suballocators is wiped before it is dished out. There is
some overhead that we incur as a result of doing this, but
it helps lint for bugs quickly and since we are doing the
compilation in a second thread, it does not cost much.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>