Commit Graph

1293 Commits

Author SHA1 Message Date
Dan Gohman
85662fbca9 Add an "umbrella" crate, which seeks to provide a convenient interface.
This currently pulls in cretonne-codegen and cretonne-frontend and
provides a simple prelude interface.

This fixes #287.
2018-04-17 09:47:13 -07:00
Dan Gohman
f43b6aca1a Use lower-case letters for github URLs.
This makes it a little more consistent; now, "cretonne" is never capitalized
in identifier, path, or URL contexts. It is capitalized in natural
language contexts when referring to the project.
2018-04-17 09:47:11 -07:00
Dan Gohman
24fa169e1f Rename the 'cretonne' crate to 'cretonne-codegen'.
This fixes the next part of #287.
2018-04-17 09:46:56 -07:00
Dan Gohman
7767186dd0 Rename 'cton_*' library names to match the 'cretonne_*' crate names.
This renames `cton_frontend` to `cretonne_frontend` and so on.

This fixes the first part of #287.
2018-04-17 07:55:59 -07:00
Dan Gohman
f552c8768e Bump version to 0.4.4 2018-04-16 16:37:00 -07:00
Dan Gohman
56f11e76b4 Use PC-relative encodings for colocated functions on non-PIC.
Colocated functions are expected to be defined within the PC-relative
immediate range on x86-64, so allow this addressing for non-PIC as well
as PIC.
2018-04-16 16:27:27 -07:00
Dan Gohman
5977f2e45e Update packaging metadata for cretonne-entity. 2018-04-16 14:50:41 -07:00
Dan Gohman
a4523cf0b8 Bump version to 0.4.3 2018-04-16 14:48:11 -07:00
Dan Gohman
0e57f3d0ea Add a "colocated" flag to symbol references. (#298)
This adds a "colocated" flag to function and symbolic global variables which
indicates that they are defined along with the current function, so they can
use PC-relative addressing.

This also changes the function decl syntax; the name now always precedes the
signature, and the "function" keyword is no longer included.
2018-04-13 15:00:09 -07:00
Dan Gohman
645fa3e858 Minor code cleanup. 2018-04-13 13:50:26 -07:00
Dan Gohman
04746270b3 Rename X86Abs4/X86Abs8 to Abs4/Abs8.
These relocation codes are for simple absolute addresses and aren't
architecture-specific.
2018-04-13 09:11:14 -07:00
Dan Gohman
1c760ab179 Rename intel to x86.
x86 is the more accurate name, as there are non-Intel x86 implementations.

Fixes #263.
2018-04-12 10:02:16 -07:00
Amanieu d'Antras
9e17e62d68 Move entity into a separate crate (#297) 2018-04-10 11:06:49 -07:00
Dan Gohman
18b2f12150 Save/restore callee-saved registers used in regmove/regfill.
The regmove and regfill instructions temporarily divert a value's
location, and these temporary diversions are not reflected in
`func.locations`. For now, make an extra scan through the instructions
of the function to find any regmove or regfill instructions in order to
find all used callee-saved registers.

This fixes #296.
2018-04-09 22:33:54 -07:00
Dan Gohman
eab57c0a40 Use large-model addressing for calls when in non-PIC mode.
The main use for non-PIC code at present is JIT code, and JIT code can
live anywhere in memory and reference other symbols defined anywhere in
memory, so it needs to use the "large" code model.

func_addr and globalsym_addr instructions were already using `movabs`
to support arbitrary 64-bit addresses, so this just makes calls be
legalized to support arbitrary 64-bit addresses also.
2018-04-08 22:37:35 -07:00
Dan Gohman
2703b8ce6f The current x86-32 encodings for symbolic addresses are non-PIC. 2018-04-08 22:30:55 -07:00
Dan Gohman
b0d414731c The addend for a PCRel4 reloc should be -4 too. 2018-04-07 06:15:33 -07:00
Dan Gohman
781d3ee3ff Bump version to 0.4.2 2018-04-03 16:04:54 -07:00
Dan Gohman
e2681a6303 Tidy up an unneeded mut. 2018-04-03 15:48:14 -07:00
Tyler McMullen
775c674b38 Only save callee-saved registers that are used (#293)
* Only save callee-saved registers that are actually being used.

* Rename AllocatableSet to RegisterSet

* Style cleanup and small renames for readability.

* Adjust x86 prologue-epilogue test to account for callee-saved register optimization.

* Add more tests for prologue-epilogue optimizations.
2018-04-03 14:44:12 -07:00
Dan Gohman
e107793b68 Pre-opt: Use the correct operand in the irsub_imm pattern. 2018-03-30 21:02:26 -07:00
Dan Gohman
07693048f0 Merge remote-tracking branch 'origin/master' into no_std 2018-03-30 15:18:29 -07:00
Dan Gohman
b523b69c16 Make bash function syntax consistent with other scripts in the repo. 2018-03-30 13:38:30 -07:00
Dan Gohman
c50675deb8 Format with nightly rustfmt-preview, then with rustfmt-0.9 again. 2018-03-30 13:23:47 -07:00
Dan Gohman
8d5fecd324 Format with stable rustfmt-preview, then with rustfmt-0.9 again. 2018-03-30 13:17:15 -07:00
Dan Gohman
d7c66a8ec1 Don't run the DCE pass when optimization is disabled.
The main purpose of the DCE pass is to clean up dead code left behind by
the optimizer, so it's not valuable to run it when the optimizer isn't
being run.
2018-03-30 12:46:03 -07:00
Dan Gohman
72b7a4b3ef Add iter() and values() functions to PrimaryMap and EntityMap.
`iter()` iterates over both keys and values, while `values()` iterates over
just values. Also add `_mut()` versions.

These replace the otherwise common idiom of iterating with `keys()` and using
indexing to get the values, allowing for simpler code.
2018-03-30 12:45:52 -07:00
Dan Gohman
9e4ab7dc86 Rename CallConv::Native to CallConv::SystemV. (#291)
To keep cross-compiling straightforward, Cretonne shouldn't have any
behavior that depends on the host. This renames the "Native" calling
convention to "SystemV", which has a defined meaning for each target,
so that it's clear that the calling convention doesn't change
depending on what host Cretonne is running on.
2018-03-30 12:32:14 -07:00
Dan Gohman
6606b88136 Optimize immediates and compare and branch sequences (#286)
* Add a pre-opt optimization to change constants into immediates.

This converts 'iadd' + 'iconst' into 'iadd_imm', and so on.

* Optimize away redundant `bint` instructions.

Cretonne has a concept of "Testable" values, which can be either boolean
or integer. When the an instruction needing a "Testable" value receives
the result of a `bint`, converting boolean to integer, eliminate the
`bint`, as it's redundant.

* Postopt: Optimize using CPU flags.

This introduces a post-legalization optimization pass which converts
compare+branch sequences to use flags values on CPUs which support it.

* Define a form of x86's `urm` that doesn't clobber FLAGS.

movzbl/movsbl/etc. don't clobber FLAGS; define a form of the `urm`
recipe that represents this.

* Implement a DCE pass.

This pass deletes instructions with no side effects and no results that
are used.

* Clarify ambiguity about "32-bit" and "64-bit" in comments.

* Add x86 encodings for icmp_imm.

* Add a testcase for postopt CPU flags optimization.

This covers the basic functionality of transforming compare+branch
sequences to use CPU flags.

* Pattern-match irsub_imm in preopt.
2018-03-30 12:30:07 -07:00
Dan Gohman
5377092e5b Use #[cold] rather than #[inline(never)].
This gives optimizers more information about likely branch
probabilities.
2018-03-28 22:48:30 -07:00
Dan Gohman
4af95e37a6 Convert regular comments to documentation comments. 2018-03-28 22:48:30 -07:00
Dan Gohman
68b2040ba2 Document that opcodes.rs contains InstructionData. 2018-03-28 22:48:30 -07:00
Tyler McMullen
951ff11f85 [WIP] Add a Trap sink to code generation (#279)
* First draft of TrapSink implementation.

* Add trap sink calls to 'trapif' and 'trapff' recipes.

* Add SourceLoc to trap sink calls, and add trap sink calls to all loads and stores.

* Add IntegerDivisionByZero trap to div recipe.

* Only emit load/store traps if 'notrap' flag is not set on the instruction.

* Update filetest machinery to add new trap sink functionality.

* Update filetests to include traps in output.

* Add a few more trap outputs to filetests.

* Add trap output to CLI tool.
2018-03-28 22:48:03 -07:00
Dan Gohman
d566faa8fb Disable preopt at opt_level=fastest. 2018-03-28 22:13:13 -07:00
Dan Gohman
57cd69d8b4 Say "IR" instead of "IL".
While the specifics of these terms are debatable, "IR" generally
isn't incorrect in this context, and is the more widely recognized
term at this time.

See also the discussion in #267.

Fixes #267.
2018-03-28 22:07:26 -07:00
Dan Gohman
a297465c25 Tidy up comment formatting.
Convert several normal comments to documentation comments, and make
separator comments consistent with other files.
2018-03-28 22:07:23 -07:00
Dan Gohman
592db1de7a Tighten up the parser's verification of value aliases.
This prevents uses of undefined values from passsing through
unnoticed, and ensures that all aliases are ultimately resolved,
regardless of where they are defined.
2018-03-28 22:07:08 -07:00
Dan Gohman
e5ec7242cc Fix handling of value aliases, and re-enable LICM.
Value aliases aren't instructions, so they don't have a location in the
CFG, so it's not meaningful to query whether a value alias is defined
within a loop.
2018-03-28 22:06:52 -07:00
Dan Gohman
db2be8ee01 Verifier: Diagnose an instruction using its own result values. 2018-03-28 21:27:05 -07:00
Dan Gohman
23ab07b54e Support legalizing bconst instructions on x86. 2018-03-28 14:11:16 -07:00
Dan Gohman
c3f044ff46 Note that the "widen" legalization group is not yet implemented. 2018-03-28 13:44:54 -07:00
Dan Gohman
8d560cf8ba Fix Rust syntax in generated code.
This code is not currently emitted, though it will be when there
are more legalization rules.
2018-03-28 12:58:31 -07:00
Dan Gohman
7b51edd285 Fix spelling in a comment to be consistent with the code. 2018-03-28 08:58:58 -07:00
Dan Gohman
0b5bb313cb Mark CondCode's functions #[must_use].
It's easy to forget whether they mutate the value in place or return a
new value. Marking them #[must_use] will catch cases where they are used
incorrectly.
2018-03-27 14:16:55 -07:00
Dan Gohman
79f02e42dd Use movss/movsd rather than movd/movq for floating-point loads and stores.
While there may be CPUs that have a domain crossing penalty here,
this also helps the generated code look more like the code produced
by other compilers.
2018-03-27 11:53:59 -07:00
Dan Gohman
3b0a9b9ecf Remove an unused argument. 2018-03-27 11:53:10 -07:00
Dan Gohman
a661a8a9bb Factor out common ways to call encode from a dfg or func. 2018-03-27 11:53:03 -07:00
Dan Gohman
ffe89cdc0a Rename %eflags to %rflags.
EFLAGS is a subregister of RFLAGS. For consistency with GPRs where we
use the 64-bit names to refer to the registers, use the 64-bit name for
RFLAGS as well.
2018-03-27 11:52:57 -07:00
Dan Gohman
14faef7374 Derive Debug for LiveValue. 2018-03-26 21:21:54 -07:00
Dan Gohman
685cde98a4 Mark loads from globals aligned and notrap.
Mark loads from globals generated by cton_wasm or by legalization as
`aligned` and `notrap`, since memory for these globals should be
allocated by the runtime environment for that purpose. This reduces
the number of potentially trapping instructions, which can reduce
the amount of metadata required by embedding environments.
2018-03-26 21:21:54 -07:00