Commit Graph

721 Commits

Author SHA1 Message Date
Dan Gohman
2b6502ac6e Fix handling of CFG triangles in compute_postorder.
For example, in `loops_one`, ebb3 is the bottom of a triangle, so
postorder should order it after the rest of the triangle.
2017-11-07 16:57:22 -08:00
Dan Gohman
5dda19035d Implement Hash for ExternalName.
This allows users to have HashMaps etc. with ExternalNames as keys.
2017-11-06 11:34:09 -08:00
Dan Gohman
4091688cc0 Avoid unnecessary name qualification. 2017-11-06 11:10:03 -08:00
Dan Gohman
d9743290ea Elide elidable lifetime parameters. 2017-11-06 11:09:56 -08:00
Dan Gohman
8501cb798e Minor comment cleanups. 2017-11-03 16:43:29 -07:00
Dan Gohman
acc6d941a3 Combine redundant match arm bodies. 2017-11-03 16:40:51 -07:00
Dan Gohman
5f8b1b9f04 Fix a flake8 lint. 2017-10-31 13:05:26 -07:00
Dan Gohman
871bf95acf Change reloc_ebb to pass a CodeOffset rather than an Ebb index. 2017-10-31 12:26:38 -07:00
Dan Gohman
5d063eb8bc Merge reloc_func and reloc_globalsym into reloc_external. 2017-10-31 12:26:33 -07:00
Dan Gohman
b60b2ce135 Change parse_multiline to follow PEP 257.
The main change is that it avoids creating blank lines when processing
docstrings.

This also adds blank lines in various places to make the generated code
prettier.
2017-10-31 12:21:23 -07:00
Dan Gohman
149a41a684 Clean up copypasta. 2017-10-31 12:21:14 -07:00
Dan Gohman
9c54c3fff0 Introduce globalsym_addr.
This is an instruction used in legalization of GlobalVarData::Sym global
variables.
2017-10-30 13:26:56 -07:00
Dan Gohman
cb805f704d Put BaldrMonkey-specific behavior under a setting.
BaldrMonkey will need to enable allones_funcaddrs.
2017-10-30 13:26:56 -07:00
Dan Gohman
6fc45b070a Add a new kind of GlobalVar for symbolic addresses.
These addresses will allow referencing C/C++/Rust-style global variables
by name directly.
2017-10-30 13:26:56 -07:00
Dan Gohman
c2665385b1 Rename FunctionName to ExternalName. 2017-10-30 13:26:56 -07:00
Dan Gohman
fae5ffb556 Make generated code more consistent with current rustfmt. 2017-10-30 10:06:23 -07:00
Jakob Stoklund Olesen
d37126565e Also consider fixed outputs for replace_global_defines.
Fixes #178.

When an instruction with a fixed output operand defines a globally live
SSA value, we need to check if the fixed register is available in the
`regs.global` set of registers that can be used across EBB boundaries.

If the fixed output register is not available in regs.global, set the
replace_global_defines flag so the output operands are rewritten as
local values.
2017-10-25 14:28:30 -07:00
Jakob Stoklund Olesen
1b71285b34 Return bools in GPR registers.
Boolean types are returned in %rax, so regclass_for_abi_type() should
return GPR.

Fixes #179.
2017-10-25 13:34:55 -07:00
Jakob Stoklund Olesen
02e81dd1d7 Fix build after flake8 update.
There's a new version of flake8 out which doesn't like variables names
i, l, I.

No functional change intended.
2017-10-25 11:40:37 -07:00
Jakob Stoklund Olesen
e8ecf1f809 Add a FixedTied constraint kind for operand constraints.
Fixes #175.

The Intel division instructions have fixed input operands that are
clobbered by fixed output operands, so the value passed as an input will
be clobbered just like a tied operand.

The FixedTied operand constraint is used to indicate a fixed input
operand that has a corresponding output operand with the same fixed
register.

Teach the spiller to teach a FixedTied operand the same as a Tied
operand constraint and make sure that the input value is killed by the
instruction.
2017-10-25 11:22:20 -07:00
Dan Gohman
fc0671a0cf Avoid dangling references to block params when sealing an unreachable block. 2017-10-25 10:04:18 -07:00
Dan Gohman
bbdce7e3e0 Update the comment for 'notrap()'. 2017-10-24 10:39:01 -07:00
Jakob Stoklund Olesen
8e9ac361bd Remove the CFG entry_block member.
It was not used.
2017-10-20 09:40:28 -07:00
Jakob Stoklund Olesen
b3fb41087e Use the term "Function parameter" instead of "argument".
Rename the ArgumentType type to AbiParam since it describes the ABI
characteristics of a parameter or return value, not just the value type.

In Signature, rename members argument_types and return_types to "params"
and "returns". Again, they are not just types.

Fix a couple lingering references to "EBB arguments".
2017-10-19 17:39:23 -07:00
Jakob Stoklund Olesen
921bcc6c25 Use the term "EBB parameter" everywhere.
Add EBB parameter and EBB argument to the langref glossary to clarify
the distinction between formal EBB parameter values and arguments passed
to branches.

- Replace "ebb_arg" with "ebb_param" in function names that deal with
  EBB parameters.
- Rename the ValueDef variants to Result and Param.
- A bunch of other small langref fixes.

No functional changes intended.
2017-10-19 16:17:09 -07:00
Jakob Stoklund Olesen
ea68a69f8b Fix a flake8 lint.
Also don't infer writes_cpu_flags if it is specified explicitly.
2017-10-19 16:17:09 -07:00
Dan Gohman
7c9b9e3d27 Mark spill and fill as can_store and can_load.
This allows GVN to avoid hoisting them. These will be to coarse for
things that want more precise dependence information, however we can
work that out when we build such things.
2017-10-19 13:11:33 -07:00
Dan Gohman
cc0bb70c5d Make GVN aware of instructions that write to CPU flags. 2017-10-19 12:59:10 -07:00
Dan Gohman
3ccee371a7 Remove the todo for smod.
It's not present in either WebAssembly or Rust, for example. We can
still add smod in the future if future use cases need it.
2017-10-19 12:59:10 -07:00
Jakob Stoklund Olesen
57b81a179e Move the CursorBase trait into the cursor module.
Also move the CursorPosition type into the cursor module.

Move layout::cursor into the tests module as LayoutCursor and remove its
ability to insert instructions via the dfg.ins() method. This cursor
type is only used in the layout unit tests now.

The FuncCursor and EncCursor types are the commonly used cursors now.
2017-10-19 12:15:43 -07:00
Dan Gohman
55bc368bf8 Remove minnum/maxnum. 2017-10-18 15:44:17 -07:00
Jakob Stoklund Olesen
b948de1693 Add a verifier pass for CPU flags.
Only one CPU flags value can be live at a time, and some instructions
clobber the flags.
2017-10-18 15:07:19 -07:00
Jakob Stoklund Olesen
c3446ee472 Add CPU flags value types to the language reference manual.
Clean up a few other things in the value types section too.
2017-10-18 15:07:19 -07:00
Dan Gohman
35989f4069 Tidy up unneeded references. 2017-10-17 11:48:57 -07:00
Dan Gohman
e6c6f09e41 Tidy some formatting in the generated legalizer.rs. 2017-10-17 11:48:57 -07:00
Jakob Stoklund Olesen
620eb7effe Add a "clobbers_flags" flag to encoding recipes.
On some ISAs like Intel's, all arithmetic instructions set all or some
of the CPU flags, so flag values can't be live across these
instructions. On ISAs like ARM's Aarch32, flags are clobbered by compact
16-bit encodings but not necessarily by 32-bit encodings of the same
instruction.

The "clobbers_flags" bit on the encoding recipe is used to indicate if
CPU flag values can be live across an instruction, or conversely whether
the encoding can be used where flag values are live.
2017-10-16 14:40:28 -07:00
Jakob Stoklund Olesen
5d065c4d8f Add encodings for CPU flags instructions.
Branch on flags: brif, brff,
Compare integers to flags: ifcmp
Compare floats to flags: ffcmp
Convert flags to b1: trueif, trueff
2017-10-16 13:07:23 -07:00
Jakob Stoklund Olesen
0f4f663584 Add register banks for CPU flags to Intel and ARM ISAs.
The arm32 ISA technically has separate floating point and integer flags,
but the only useful thing you can do with the floating point flags is to
copy them ti the integer flags, so there is not need to model them.

The arm64 ISA fixes this and the fcmp instruction writes the integer
nzcv flags directly.

RISC-V does not have CPU flags.
2017-10-13 14:02:09 -07:00
Jakob Stoklund Olesen
1dbc55dadf Add a pressure_tracking flag to register banks.
This makes it possible to define register banks that opt out of register
pressure tracking. This will be used to define banks for special-purpose
registers like the CPU flags.

The pressure tracker does not need to use resources for a top-level
register class in a non-tracked bank. The constant MAX_TOPRCS is renamed
to MAX_TRACKED_TOPRCS to indicate that there may be top-level register
classes with higher numbers, but they won't require pressure tracking.

We won't be tracking register pressure for CPU flags since only one
value is allowed to be live at a time.
2017-10-13 13:46:16 -07:00
Jakob Stoklund Olesen
1f98fc491c Add instructions using CPU flags.
Add integer and floating comparison instructions that return CPU flags:
ifcmp, ifcmp_imm, and ffcmp.

Add conditional branch instructions that check CPU flags: brif, brff

Add instructions that check a condition in the CPU flags and return a
b1: trueif, trueff.
2017-10-12 19:12:28 -07:00
Jakob Stoklund Olesen
15461c1e4b Add two new value types: iflags and fflags.
These two value types represent the state of CPU flags after an integer
comparison and a floating point comparison respectively.

Instructions using these types TBD.
2017-10-12 19:05:24 -07:00
Jakob Stoklund Olesen
dbaa919ca9 Make room for SpecialType in the value type numbering.
The value types are now classified into three groups:

1. Lane types are scalar types that can also be used to form vectors.
2. Vector types 2-256 copies of a lane type.
3. Special types. This is where the CPU flag types will go.

The special types can't be used to form vectors.

Change the numbering scheme for value types to make room for the special
types and add `is_lane()` and `is_special()` classification methods.

The VOID type still has number 0, but it can no longer appear as a
vector lane. It classifies as special now.
2017-10-12 12:48:55 -07:00
Jakob Stoklund Olesen
89a24b2f13 Rename ScalarType to LaneType.
The word "scalar" is a bit vague and tends to mean "non-vector". Since
we are about to add new CPU flag value types that can't appear as vector
lanes, make the distinction clear: LaneType represents value types that
can appear as a vector lane.

Also replace the Type::is_scalar() method with an is_vector() method.
2017-10-12 10:39:12 -07:00
Jakob Stoklund Olesen
994af598f5 Avoid interference on CFG edges.
Track allocatable registers both locally and globally: Add a second
AllocatableSet which tracks registers allocated to global values without
accounting for register diversions. Since diversions are only local to
an EBB, global values must be assigned un-diverted locations that don't
interfere.

Handle the third "global" interference domain in the constraint solver in
addition to the existing "input" and "output" domains.

Extend the solver error code to indicate when a global define just can't
be allocated because there are not enough available global registers.
Resolve this problem by replacing the instruction's global defines with
local defines that are copied into their global destinations
afterwards.
2017-10-11 15:38:30 -07:00
Jakob Stoklund Olesen
ba52a38597 Add a t8jccd_long encoding recipe for brz.b1 and brnz.b1 in 32-bit mode.
The register allocator can't handle branches with constrained register
operands, and the brz.b1/brnz.b1 instructions only have the t8jccd_abcd
in 32-bit mode where no REX prefixes are possible.

This adds a worst case encoding for those cases where a b1 value lives
in a non-ABCD register.
2017-10-11 14:20:43 -07:00
Jakob Stoklund Olesen
ece09f2df2 Add encodings for spill.b1, fill.b1 etc.
These spills and fills use 32-bit writes, knowing that the spill slot is
minimum 4 bytes which makes it safe.

Also simplify the definition of load/store encodings a bit by
introducing loops.
2017-10-11 14:20:43 -07:00
Jakob Stoklund Olesen
699cb9895e Enforce a 4-byte minimum spill slot size.
This is primarily for the benefit of 32-bit x86 code which can't spill
1-byte types from arbitrary registers. This makes it possible to use
32-bit writes to spill types like b1 and i8.

These small types are expected to be very rare since WebAssembly doesn't
have then, and we tend to push integer arithmetic to at least i32. The
effect of frame sizes should be minimal.
2017-10-11 14:20:43 -07:00
Jakob Stoklund Olesen
1a04c4260f Remove an unused import to silence a compiler warning. 2017-10-11 14:20:43 -07:00
Dan Gohman
3f30171b79 Actually disable simple_gvn and licm by default.
See

https://github.com/stoklund/cretonne/pull/164#discussion_r142449999

for details.
2017-10-10 16:28:29 -07:00
Jakob Stoklund Olesen
90ed698e83 Add an unreachable code elimination pass.
The register allocator doesn't even try to compile unreachable EBBs, so
any values defined in such blocks won't be assigned registers.

Since the dominator tree already has determined which EBBs are
reachable, we should just eliminate any unreachable blocks instead o
trying to do something with the dead code.

Not that this is not a "dead code elimination" pass which would also
remove individual instructions whose results are not used.
2017-10-09 15:26:27 -07:00