Commit Graph

151 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
b51cf57e39 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
afd42cf9c2 Convert try! to ? in extfunc.rs 2017-02-24 10:33:08 -08:00
Angus Holder
bf26fffc92 Shortened comment to pass lint. 2017-02-23 09:22:16 -08:00
Angus Holder
a35d946bc4 Added tests, some fixes. 2017-02-23 09:22:16 -08:00
Angus Holder
0b310017b7 Lexer can now scan names, hex sequences, brackets and minus signs. 2017-02-23 09:22:16 -08:00
Jakob Stoklund Olesen
ccda0a192c 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
83571028d9 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
329e51ac4f 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
2ec7412a81 Removed unnecessary documentation. 2017-02-22 10:22:08 -08:00
Angus Holder
81a6e343ad Add assertion that the NonZero optimization works on Option<Opcode>. 2017-02-22 10:22:08 -08:00
Angus Holder
75a426a812 Fix test case that I missed before. 2017-02-22 10:22:08 -08:00
Angus Holder
a4e4776087 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
3d0240d244 Documentation fix for what appears to be a minor copy-paste mistake. 2017-02-22 09:33:17 -08:00
Jakob Stoklund Olesen
62334b26b4 Add return_reg encodings for RISC-V. 2017-02-21 16:29:23 -08:00
Jakob Stoklund Olesen
a7d24ab1dc 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
20ff2f0025 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
74eb13c17a 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
706720eba9 Improve assertion text for missing live ranges. 2017-02-21 12:24:37 -08:00
Jakob Stoklund Olesen
fa205d049d 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
0f29fc7a52 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
793b3a140a 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
518d30b379 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
3072728d37 Give register classes a name.
This is just for better error messages etc.
2017-02-16 13:57:28 -08:00
Jakob Stoklund Olesen
e182bfa9ad 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
2361467536 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
8d7756c06b Add a contains_key method to SparseMap. 2017-02-14 16:05:54 -08:00
Jakob Stoklund Olesen
efab6d0214 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
71ec92281c 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
e3480987bd 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
6567eca21e 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
73202bb3dc 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
8ca61b2a24 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
4ae7fd2a37 Speling. 2017-02-03 12:49:40 -08:00
Jakob Stoklund Olesen
4293bed745 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
0ada419fe7 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
3c4d54c4bd 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
Jakob Stoklund Olesen
c132b8c328 Upgrade to rustfmt 0.7.1 2017-01-25 15:17:27 -08:00
Jakob Stoklund Olesen
2932d41f18 Run Python checks from test-all.sh
The Python style enforcements are easy to miss otherwise.
2017-01-25 14:12:36 -08:00
Jakob Stoklund Olesen
672e4abd7e Compute register class intersections.
Ensure that the set of register classes is closed under intersection.

Provide a RegClass::intersect() method which finds the register class
representing the intersection of two classes.

Generate a bit-mask of subclasses for each register class to be used by
the intersect() method.

Ensure that register classes are sorted topologically. This is also used
by the intersect() method.
2017-01-25 13:57:43 -08:00
Jakob Stoklund Olesen
0394f35034 Add operand register constraints.
Every encoding recipe must specify register constraints on input and
output values.

Generate recipe constraint tables along with the other encoding tables.
2017-01-25 13:35:18 -08:00
Jakob Stoklund Olesen
58dedb673a Add an AllocatableSet for registers.
This set of available register units also manages register aliasing in
an efficient way.

Detect if the units in a register straddles mask words. The algorithm
for allocating multi-unit registers expect the whole register to be
inside a single mask word. We could handle this if necessary, but so far
no ISAs need it.
2017-01-23 12:43:32 -08:00
Jakob Stoklund Olesen
ae926157c2 Generate register class descriptors.
Add a mechanism for defining sub-classes of register classes.
2017-01-20 14:23:06 -08:00
Jakob Stoklund Olesen
ac798c1aed Fix flake8 style issue. 2017-01-20 10:33:45 -08:00
Jakob Stoklund Olesen
8f2ca7c471 Remove EntityRef::wrap().
This has been superceded by PackedOption.
2017-01-20 09:35:57 -08:00
Jakob Stoklund Olesen
1221d94272 Remove NO_INST and the Default+Ord impls for Inst.
Clean up comments.

Add an assertion to check that PackedOption is working as designed.
2017-01-19 19:44:16 -08:00
Jakob Stoklund Olesen
4aa5c313ea Use PackedOption<Inst> in the dominator tree.
Also rework the algorithm to be more robust against unreachable blocks.

- Add an is_reachable(ebb) method.
- Change idom(ebb) to just return an instruction.
- Make idom() return None for the entry block as well as unreachable
  blocks.
2017-01-19 19:44:16 -08:00
Jakob Stoklund Olesen
2e6cf219e9 Use PackedOption<Value> instead of NO_VALUE.
- Remove NO_VALUE and ExpandedValue::None.
- Remove the Default implelmentation for Value.
- InstructionData::second_result() returns an Option<Value>.
- InstructionData::second_result() returns a reference to the packed
  option.
2017-01-19 15:55:18 -08:00
Jakob Stoklund Olesen
f2b9f62f24 Avoid using NO_INST in the parser.
This was only used for the comment rewrite mechanism, and we can just
predict the next allocated instruction number instead. See the other
uses of next_key() for gather_comments().
2017-01-19 14:49:55 -08:00
Jakob Stoklund Olesen
3fc0f80223 Use PackedOption<Inst> in the Layout implementation.
This also revealed that the last_inst() method should return an Option.
2017-01-19 14:26:47 -08:00
Jakob Stoklund Olesen
52db486500 Use PackedOption<Ebb> in the Layout implementation.
The doubly linked lists are terminated with None.

Remove NO_EBB and the Default impl for Ebb.
2017-01-19 14:05:32 -08:00