rust/src/librustc_trans
bors f50fd075c2 Auto merge of #45225 - eddyb:trans-abi, r=arielb1
Refactor type memory layouts and ABIs, to be more general and easier to optimize.

To combat combinatorial explosion, type layouts are now described through 3 orthogonal properties:
* `Variants` describes the plurality of sum types (where applicable)
  * `Single` is for one inhabited/active variant, including all C `struct`s and `union`s
  * `Tagged` has its variants discriminated by an integer tag, including C `enum`s
  * `NicheFilling` uses otherwise-invalid values ("niches") for all but one of its inhabited variants
* `FieldPlacement` describes the number and memory offsets of fields (if any)
  * `Union` has all its fields at offset `0`
  * `Array` has offsets that are a multiple of its `stride`; guarantees all fields have one type
  * `Arbitrary` records all the field offsets, which can be out-of-order
* `Abi` describes how values of the type should be passed around, including for FFI
  * `Uninhabited` corresponds to no values, associated with unreachable control-flow
  * `Scalar` is ABI-identical to its only integer/floating-point/pointer "scalar component"
  * `ScalarPair` has two "scalar components", but only applies to the Rust ABI
  * `Vector` is for SIMD vectors, typically `#[repr(simd)]` `struct`s in Rust
  * `Aggregate` has arbitrary contents, including all non-transparent C `struct`s and `union`s

Size optimizations implemented so far:
* ignoring uninhabited variants (i.e. containing uninhabited fields), e.g.:
  * `Option<!>` is 0 bytes
  * `Result<T, !>` has the same size as `T`
* using arbitrary niches, not just `0`, to represent a data-less variant, e.g.:
  * `Option<bool>`, `Option<Option<bool>>`, `Option<Ordering>` are all 1 byte
  * `Option<char>` is 4 bytes
* using a range of niches to represent *multiple* data-less variants, e.g.:
  * `enum E { A(bool), B, C, D }` is 1 byte

Code generation now takes advantage of `Scalar` and `ScalarPair` to, in more cases, pass around scalar components as immediates instead of indirectly, through pointers into temporary memory, while avoiding LLVM's "first-class aggregates", and there's more untapped potential here.

Closes #44426, fixes #5977, fixes #14540, fixes #43278.
2017-11-19 22:12:22 +00:00
..
back Auto merge of #46009 - kennytm:fix-38878-again, r=alexcrichton 2017-11-18 15:00:13 +00:00
debuginfo rustc: extend the niche-filling enum optimization past 2 variants. 2017-11-19 02:43:56 +02:00
mir rustc_trans: remove primitive_align optimization. 2017-11-19 20:33:46 +02:00
abi.rs rustc_trans: remove primitive_align optimization. 2017-11-19 20:33:46 +02:00
allocator.rs
asm.rs rustc_trans: query LLVM types from a layout instead of a Ty. 2017-11-19 02:14:32 +02:00
assert_module_sources.rs
attributes.rs rustc_trans: support scalar pairs directly in the Rust ABI. 2017-11-19 02:43:55 +02:00
base.rs rustc: unpack scalar pair newtype layout ABIs. 2017-11-19 02:43:55 +02:00
build.rs
builder.rs rustc_trans: remove primitive_align optimization. 2017-11-19 20:33:46 +02:00
cabi_aarch64.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_arm.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_asmjs.rs rustc_trans: support scalar pairs directly in the Rust ABI. 2017-11-19 02:43:55 +02:00
cabi_hexagon.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_mips64.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_mips.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_msp430.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_nvptx64.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_nvptx.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_powerpc64.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_powerpc.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_s390x.rs rustc: track validity ranges for layout::Abi::Scalar values. 2017-11-19 02:14:33 +02:00
cabi_sparc64.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_sparc.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
cabi_x86_64.rs rustc_trans: support scalar pairs directly in the Rust ABI. 2017-11-19 02:43:55 +02:00
cabi_x86_win64.rs rustc: encode scalar pairs in layout ABI. 2017-11-19 02:43:32 +02:00
cabi_x86.rs rustc_trans: support scalar pairs directly in the Rust ABI. 2017-11-19 02:43:55 +02:00
callee.rs rustc_trans: query LLVM types from a layout instead of a Ty. 2017-11-19 02:14:32 +02:00
Cargo.toml
common.rs rustc_trans: remove type_is_fat_ptr and its uses. 2017-11-19 02:43:56 +02:00
consts.rs rustc_trans: query LLVM types from a layout instead of a Ty. 2017-11-19 02:14:32 +02:00
context.rs rustc: encode scalar pairs in layout ABI. 2017-11-19 02:43:32 +02:00
declare.rs
diagnostics.rs
glue.rs rustc: move size, align & primitive_align from Abi::Aggregate to layout. 2017-11-19 02:14:32 +02:00
intrinsic.rs rustc_trans: remove primitive_align optimization. 2017-11-19 20:33:46 +02:00
lib.rs rustc: track validity ranges for layout::Abi::Scalar values. 2017-11-19 02:14:33 +02:00
llvm_util.rs rustc: Add some more compatibility with AVX-512 2017-11-10 01:43:20 -08:00
metadata.rs
meth.rs rustc: support u128 discriminant ranges. 2017-11-19 02:14:32 +02:00
partitioning.rs
README.md
symbol_names_test.rs
time_graph.rs
trans_item.rs rustc_trans: query LLVM types from a layout instead of a Ty. 2017-11-19 02:14:32 +02:00
type_.rs rustc_trans: generate LLVM pointee types based on alignment. 2017-11-19 02:14:33 +02:00
type_of.rs rustc_trans: remove primitive_align optimization. 2017-11-19 20:33:46 +02:00
value.rs

NB: This crate is part of the Rust compiler. For an overview of the compiler as a whole, see the README.md file found in librustc.

The trans crate contains the code to convert from MIR into LLVM IR, and then from LLVM IR into machine code. In general it contains code that runs towards the end of the compilation process.