Commit Graph

554 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
07f459fb93 Add a legalize_signature method to TargetIsa.
This entry point will be used for controlling ABI conventions when
legalizing.

Provide an empty implementation for RISC-V and let the other ISAs crash
in legalization.

This is just the scaffolding. We still need to:

- Rewrite the entry block arguments to match the legalized signature.
- Rewrite call and return instructions.
- Implement the legalize_signature() function for all ISAs.
- Add shared generic types to help with the legalize_signature()
  functions.
2017-03-03 11:00:26 -08:00
Jakob Stoklund Olesen
cae4368a8a Use ISA information to display function signatures.
The argument locations contains register unit references that we want to
display with their correct names.
2017-03-03 10:58:45 -08:00
Jakob Stoklund Olesen
99c7e18fbf Add {ValueLoc,ArgumentLoc}::display().
These functions return an object containing the necessary ISA info to
print a ValueLoc or ArgumentLoc correctly.
2017-03-03 10:56:32 -08:00
Jakob Stoklund Olesen
c01ff670ed Fixed for mypy 0.501.
The List and Dict types are no longer implicitly available. They must be
imported from typing.

Type annotations must appear before the doc comment in a function. Also
fix type errors in these functions that weren't detected before.
2017-03-03 09:08:28 -08:00
Davide Italiano
5170219125 [EntityList] Fix typo. No functional change. 2017-02-28 12:43:53 -08:00
Jakob Stoklund Olesen
1f76521580 Require a current Rust version.
Rust 1.12 did work at one point, but Travis is testing against the
current stable and beta releases, so that is the only versions we can
claim to support.

Fixes #51.
2017-02-27 15:03:06 -08:00
rep-nop
0bc27fca9a Fixes error on propagating a Result<()> with the ? operator 2017-02-26 07:50:55 -08:00
rep-nop
9f00a40b52 Ran rustfmt 2017-02-26 07:50:55 -08:00
rep-nop
af3f4703b9 Fixes formatting for settings.rs 2017-02-26 07:50:55 -08:00
rep-nop
b23f1fb347 Converts all try! macros to ? syntax.
Fixes #46
2017-02-26 07:50:55 -08:00
Jakob Stoklund Olesen
cf5701b137 Add ABI annotations to function signatures.
Specify the location of arguments as well as the size of stack argument
array needed. The ABI annotations are optional, just like the value
locations.

Remove the Eq implementation for Signature which was only used by a
single parser test.
2017-02-24 13:53:46 -08:00
Jakob Stoklund Olesen
cf7a729dc1 Add an ArgumentLoc data type.
This will be used to amend function signatures with ABI lowering
information.
2017-02-24 12:09:24 -08:00
Jakob Stoklund Olesen
aa7e349134 Add a section about implementation limits.
Fix a few other minor issues with the documentation.
2017-02-24 11:08:15 -08:00
Jakob Stoklund Olesen
db9e4ea979 Convert try! to ? in extfunc.rs 2017-02-24 10:33:08 -08:00
Angus Holder
65efefff38 Shortened comment to pass lint. 2017-02-23 09:22:16 -08:00
Angus Holder
54a53b7ab7 Added tests, some fixes. 2017-02-23 09:22:16 -08:00
Angus Holder
a08e177595 Lexer can now scan names, hex sequences, brackets and minus signs. 2017-02-23 09:22:16 -08:00
Jakob Stoklund Olesen
04bddd73ba Add a 'regalloc' filetest command.
Run functions through the register allocator, and then filecheck.
2017-02-22 11:53:01 -08:00
Jakob Stoklund Olesen
247be57042 Also write out register assignments in write_instruction.
The value locations appear after the encodings:

> [R#0c,%x2]              v0 = iadd vx0, vx1
> [Iret#19]               return_reg v0
2017-02-22 11:53:01 -08:00
Jakob Stoklund Olesen
bf9cf09622 Add a register allocation context module.
Collect the data structures that hang around between function
compilations.

Provide a main entry point to the register allocator passes.
2017-02-22 11:53:01 -08:00
Jakob Stoklund Olesen
8e421d666d SSA register coloring pass.
This is a bare-bones outline of the SSA coloring pass. Many features are
missing, including:

- Handling instruction operand constraints beyond simple register
  classes.
- Handling ABI requirements for function arguments and return values.
- Generating shuffle code for EBB arguments.
2017-02-22 11:53:01 -08:00
Angus Holder
1e4096b8b8 Removed unnecessary documentation. 2017-02-22 10:22:08 -08:00
Angus Holder
b2a3b34022 Add assertion that the NonZero optimization works on Option<Opcode>. 2017-02-22 10:22:08 -08:00
Angus Holder
41ca00df8d Fix test case that I missed before. 2017-02-22 10:22:08 -08:00
Angus Holder
e002011602 Removed the Opcode::NotAnOpcode variant, replaced its uses with Option<Opcode>, and used the NonZero optimization to maintain the small 1-byte size of an optional Opcode. 2017-02-22 10:22:08 -08:00
Angus Holder
855c429d31 Documentation fix for what appears to be a minor copy-paste mistake. 2017-02-22 09:33:17 -08:00
Jakob Stoklund Olesen
377550b835 Add return_reg encodings for RISC-V. 2017-02-21 16:29:23 -08:00
Jakob Stoklund Olesen
608d452f0c Compute the controlling type variable accurately.
Some polymorphic instructions don't return the controlling type
variable, so it has to be computed from the designated operand instead.

- Add a requires_typevar_operand() method to the operand constraints
  which indicates that.
- Add a ctrl_typevar(dfg) method to InstructionData which computes the
  controlling type variable correctly, and returns VOID for monomorphic
  instructions.
- Use ctrl_typevar(dfg) to drive the level-1 encoding table lookups.
2017-02-21 16:26:19 -08:00
Jakob Stoklund Olesen
b6fa40d6a3 Add a return_reg instruction to the base instruction set.
Register-style return is used by all RISC architectures, so it is
natural to have a shared instruction representation.
2017-02-21 13:05:17 -08:00
Jakob Stoklund Olesen
22bc33fa05 Create live ranges for dead defs.
When the liveness pass implements dead code elimination, missing live
ranges can be used to indicate unused values that it may be possible to
remove. But even then, we may have to keep dead defs around if the
instruction has side effects or other live defs.
2017-02-21 12:24:39 -08:00
Jakob Stoklund Olesen
a20afbefe0 Improve assertion text for missing live ranges. 2017-02-21 12:24:37 -08:00
Jakob Stoklund Olesen
85fa68023c Make the DominatorTree reusable.
Add a compute() method which can recompute a dominator tree for
different functions.

Add a dominator tree data to the cretonne::Context.
2017-02-17 13:09:41 -08:00
Jakob Stoklund Olesen
77a7ad88f4 Make the ControlFlowGraph reusable.
Move the flow graph computation into a compute method which can be
called with multiple functions.

This allows us to reuse the ControlFlowGraph memory and keep an instance
in the Context.
2017-02-17 12:20:33 -08:00
Jakob Stoklund Olesen
f3fa0fb4e9 Return slices instead of &Vec references.
We Don't need to expose the internal control flow graph representation.
2017-02-17 12:05:27 -08:00
Jakob Stoklund Olesen
1992890f85 Add a compilation context struct.
This will provide main entry points for compiling functions, and it
serves as a place for keeping data structures that should be preserved
between function compilations to reduce allocator thrashing.

So far, Context is just basic scaffolding. More to be added.
2017-02-17 12:04:53 -08:00
Jakob Stoklund Olesen
e60d7f179c Give register classes a name.
This is just for better error messages etc.
2017-02-16 13:57:28 -08:00
Jakob Stoklund Olesen
b1769ac7e4 Cache the affinity in LiveValue.
Most of the register allocator algorithms will only have to look at the
currently live values as presented by LiveValueTracker. Many also need
the value's affinity which is stored in the LiveRange associated with
the value.

Save the extra table lookup by caching the affinity value inside
LiveValue.
2017-02-15 13:53:01 -08:00
Jakob Stoklund Olesen
1fa3ddf018 Return RegInfo by value from TargetIsa::register_info().
The struct is just a pair of static references, and we don't need the
double indirection.
2017-02-14 16:05:54 -08:00
Jakob Stoklund Olesen
408dc4e72e Add a contains_key method to SparseMap. 2017-02-14 16:05:54 -08:00
Jakob Stoklund Olesen
96e0a3273c Return slices of live-ins and arguments from ebb_top().
The coloring algorithm needs to process these two types of live values
differently, so we may as well provide the needed info.
2017-02-14 16:05:54 -08:00
Jakob Stoklund Olesen
2317142c75 Add a Layout::next_ebb() method.
This lets us iterate over the blocks in a function without holding a
reference to the layout.
2017-02-14 15:52:44 -08:00
Jakob Stoklund Olesen
2c31041640 Live Value Tracker.
Keep track of which values are live and dead as we move through the
instructions in an EBB.
2017-02-14 10:17:24 -08:00
Jakob Stoklund Olesen
5579e9b4a5 Add a partition_slice function.
Partition the elements in a mutable slice according to a predicate.
2017-02-14 10:17:24 -08:00
Mikko Perttunen
5a1d9561a7 Coalesce live range intervals in adjacent EBBs
LiveRanges represent the live-in range of a value as a sorted
list of intervals. Each interval starts at an EBB and continues
to an instruction. Before this commit, the LiveRange would store
an interval for each EBB. This commit changes the representation
such that intervals continuing from one EBB to another are coalesced
into one.

Fixes #37.
2017-02-14 08:06:38 -08:00
Jakob Stoklund Olesen
f6391c57e8 Compute register affinities during liveness analysis.
Each live range has an affinity hint containing the preferred register
class (or stack slot). Compute the affinity by merging the constraints
of the def and all uses.
2017-02-03 15:06:05 -08:00
Jakob Stoklund Olesen
f8e4d4e839 Speling. 2017-02-03 12:49:40 -08:00
Jakob Stoklund Olesen
933dfc70c1 Fix a dead code warning from the new Rust compiler.
On ISAs with no instruction predicates, just emit an unimplemented!()
stub for the check_instp() function. It is unlikely that a finished ISA
will not have any instruction predicates.
2017-02-03 11:28:59 -08:00
Jakob Stoklund Olesen
dab96d8ea2 Add entity lists.
Like a vector, but with a tiny footprint, and allocated from a pool so
all memory can be released very quickly.
2017-01-31 15:04:26 -08:00
Jakob Stoklund Olesen
16f4b4c7d5 Implement value affinities for register allocation.
An SSA value is usually biased towards a specific register class or a
stack slot, depending on the constraints of the instructions using it.

Represent this bias as an Affinity enum, and implement a merging
algorithm for updating an affinity to satisfy a new constraint.

Affinities will be computed as part of the liveness analysis. This is
not implemented yet.
2017-01-27 10:22:50 -08:00
Andrea Canciani
fd3cd153ed Fix some typos in the documentation
These were found by the spellchecker.
2017-01-27 09:51:22 -08:00