regmove, regfill, and regspill have immediates which aren't value
operands, so they aren't in the set of things that can be described by
the existing constraint system. Consequently, constraints saying that
the non-REX encodings only support registers that don't need REX
prefixes don't work. Fow now, just remove the non-REX encodings, so
that they don't get selected when they aren't valid.
This fixes the last known issue with instruction shrinking, so it can
be re-enabled.
Add a calling-convention setting to the `Flags` used as part of the
`TargetIsa`. This allows Cretonne code that generates calls to use the
correct convention, such as when emitting libcalls during legalization
or when the wasm frontend is decoding functions. This setting can be
overridden per-function.
This also adds "fast", "cold", and "fastcall" conventions, with "fast"
as the new default. Note that "fast" and "cold" are not intended to be
ABI-compatible across Cretonne versions.
This will also ensure Windows users will get an `unimplemented!` rather
than silent calling-convention mismatches, which reflects the fact that
Windows calling conventions are not yet implemented.
This also renames SpiderWASM, which isn't camel-case, to Baldrdash,
which is, and which is also a more relevant name.
When an instruction has multiple valid encodings, such as with and
without a REX prefix on x86-64, Cretonne typically picks the encoding
which gives the register allocator the most flexibility, which is
typically the longest encoding. This patch adds a pass that runs after
register allocation that picks the smallest encoding, working within the
constraints of the register allocator's choices. The result is smaller
and easier to read encodings.
In the future, we may want to merge this pass into the relaxation pass,
or possibly fold it into the final encoding step, however for now, a
discrete pass will suffice.
Choosing smaller instruction encodings on eg. x86 is an optimization,
rather than a useful discrete setting.
Use "is_compressed" only for ISAs that have an explicit compression feature
that users of the output may to be aware of, such as RISC-V's RVC or
ARM's Thumb-2.
It turns out that "cargo test --release" doesn't use
`[profile.release]`; it uses `[profile.bench]` instead; see
[here](https://doc.rust-lang.org/cargo/reference/manifest.html) for details.
So the plan to run the tests in optimized mode but with debug-assertions
enabled didn't actually work, and we had an actual failing unit test that
was hidden because assertions were disabled.
So, this makes test-all.sh just run the unit tests in debug mode, as is
the norm for Rust packages, and fixes the buggy test.
This also removes the `[profile.release]` override from the top-level
Cargo.toml file too. We don't need it now that we're not running tests
in release mode, and it had confused multiple people because it made
Cretonne's in-tree builds different from how Cretonne is built when used as
a dependency in other projects.
* Mark emit_to_memory as unsafe, and provide a safe compile_and_emit.
Mark `Context::emit_to_memory` and `MemoryCodeSink::new` as unsafe, as
`MemoryCodeSink` does not perform bounds checking when writing to
memory.
Add a `Context::compile_and_emit` function which provides a convenient
interface for doing `compile` and `emit_to_memory` in one step, and
which can also provide a safe interface, since it allocates memory of
the needed size itself.
* Mention that `MemoryCodeSink` can't guarantee that the pointer is valid.
* Initial skeleton.
* Add basic faerie support.
This adds enough functionality to enable simple .o file writing through
faerie. This included adding the functionality to Module to support
RelocSink implementations.
* Add basic SimpleJIT support.
This adds enough functionality to enable a simple program to be jitted
and executed.
* Make declare_func_in_func take a Function instead of a Context.
It only needs the Function, and sometimes it's useful to call it from
places that don't have a full Context.
* Temporarily disable local and exported global variables in the Faerie backend.
Faerie assumes these variables use pc-relative offset instructions, and
Cretonne is not yet emitting those instructions.
* FaerieBackend depends on PIC.
Faerie itself only supports PIC objects for now, so add an assert to
Cretonne to check that it's using a PIC target flag.
* SimpleJIT support for data objects.
* Preliminary faerie support for data objects.
* Support for data objects in faerie using the new colocated flag.
* Unit tests for DataContext and friends.
* Add a Module::consume() function.
This consumes the Module and returns the contained Backend, so that
users can call Backend-specific functions with it. For example, the
Faerie backend has functions to write an object file.
* Update the new crates to version 0.4.4.
* Make FaerieBackend own its TargetIsa.
This simplifies its interface, as it eliminates a lifetime parameter.
While we may eventually want to look into allowing multiple clients to
share a TargetIsa, it isn't worth the complexity for FaerieBackend
right now.
* Don't try to protect faerie from multiple declarations.
Let faerie decide for itself whether it wants to consider two
declarations to be compatible.
* Use debug_assert_eq rather than debug_assert with ==.
* Fix FaerieRelocSink's reloc_external to handle data object names.
* Relax the asserts in get_function_definition and get_data_definition.
These functions don't require definable symbols, but they do require
that definable symbols be defined. This is needed for the simplejit
backend.
* Add a function to the faerie backend to retrieve the artifact name.
* Sync up with cretonne changes.
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.
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.
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.
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.
* 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.
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.
* 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.
* 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.
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.
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.