Commit Graph

136 Commits

Author SHA1 Message Date
Alex Crichton 7f23e6e8d7
rustc: Link LLVM directly into rustc again
This commit builds on #65501 continue to simplify the build system and
compiler now that we no longer have multiple LLVM backends to ship by
default. Here this switches the compiler back to what it once was long
long ago, which is linking LLVM directly to the compiler rather than
dynamically loading it at runtime. The `codegen-backends` directory of
the sysroot no longer exists and all relevant support in the build
system is removed. Note that `rustc` still supports a dynamically loaded
codegen backend as it did previously, it just no longer supports
dynamically loaded codegen backends in its own sysroot.

Additionally as part of this the `librustc_codegen_llvm` crate now once
again explicitly depends on all of its crates instead of implicitly
loading them through the sysroot. This involved filling out its
`Cargo.toml` and deleting all the now-unnecessary `extern crate`
annotations in the header of the crate. (this in turn required adding a
number of imports for names of macros too).

The end results of this change are:

* Rustbuild's build process for the compiler as all the "oh don't forget
  the codegen backend" checks can be easily removed.
* Building `rustc_codegen_llvm` is much simpler since it's simply
  another compiler crate.
* Managing the dependencies of `rustc_codegen_llvm` is much simpler since
  it's "just another `Cargo.toml` to edit"
* The build process should be a smidge faster because there's more
  parallelism in the main rustc build step rather than splitting
  `librustc_codegen_llvm` out to its own step.
* The compiler is expected to be slightly faster by default because the
  codegen backend does not need to be dynamically loaded.
* Disabling LLVM as part of rustbuild is still supported, supporting
  multiple codegen backends is still supported, and dynamic loading of a
  codegen backend is still supported.
2019-12-11 09:50:11 -05:00
Simon Sapin cba479f75c Add `{f32,f64}::approx_unchecked_to<Int>` unsafe methods
As discussed in https://github.com/rust-lang/rust/issues/10184

Currently, casting a floating point number to an integer with `as` is Undefined Behavior if the value is out of range. `-Z saturating-float-casts` fixes this soundness hole by making `as` “saturate” to the maximum or minimum value of the integer type (or zero for `NaN`), but has measurable negative performance impact in some benchmarks. There is some consensus in that thread for enabling saturation by default anyway, but provide an `unsafe fn` alternative for users who know through some other mean that their values are in range.
2019-12-06 14:01:05 +01:00
bors 5f1d6c4403 Auto merge of #65947 - eddyb:fn-abi, r=oli-obk,nagisa
rustc: split FnAbi's into definitions/direct calls ("of_instance") and indirect calls ("of_fn_ptr").

After this PR:
* `InstanceDef::Virtual` is only used for "direct" virtual calls, and shims around those calls use `InstanceDef::ReifyShim` (i.e. for `<dyn Trait as Trait>::f as fn(_)`)
  * this could easily be done for intrinsics as well, to allow their reification, but I didn't do it
* `FnAbi::of_instance` is **always** used for declaring/defining an `fn`, and for direct calls to an `fn`
  * this is great for e.g. https://github.com/rust-lang/rust/pull/65881 (`#[track_caller]`), which can introduce the "caller location" argument into "codegen signatures" by only changing `FnAbi::of_instance`, after this PR
* `FnAbi::of_fn_ptr` is used primarily for indirect calls, i.e. to `fn` pointers
  * *not* virtual calls (which use `FnAbi::of_instance` with `InstanceDef::Virtual`)
  * there's also a couple uses where the `rustc_codegen_llvm` needs to declare (i.e. FFI-import) an LLVM function that has no Rust declaration available at all
    * at least one of them could probably be a "weak lang item" instead

As there are many steps, this PR is best reviewed commit by commit - some of which arguably should be in their own PRs, I may have gotten carried away a bit.

cc @nagisa @rkruppe @oli-obk @anp
2019-12-04 08:22:05 +00:00
Eduard-Mihai Burtescu 902433b5bf rustc: take a PolyFnSig instead of an FnSig in FnAbi::of_fn_ptr. 2019-12-03 15:55:14 +02:00
Eduard-Mihai Burtescu 2b921d51d7 rustc: rename FnAbi::new to FnAbi::of_fn_ptr. 2019-12-03 15:41:56 +02:00
Eduard-Mihai Burtescu 95b944210f rustc_codegen_ssa: take a FnAbi instead of a FnSig in declare_fn. 2019-12-03 15:28:18 +02:00
Eduard-Mihai Burtescu db477af9ad rustc_codegen_ssa: remove define_fn and define_internal_fn. 2019-12-03 15:28:18 +02:00
Josh Stone 2304c25f31 Update the minimum external LLVM to 7
LLVM 7 is over a year old, which should be plenty for compatibility. The
last LLVM 6 holdout was llvm-emscripten, which went away in #65501.

I've also included a fix for LLVM 8 lacking `MemorySanitizerOptions`,
which was broken by #66522.
2019-12-02 11:36:21 -08:00
Mark Rousskov 66dce1114d Store ptr_width as u32 on Config
This removes the dependency on IntTy, UintTy from Session.
2019-11-24 16:32:07 -05:00
Alexander Regueiro 51cb60cd3f Aggregation of drive-by cosmetic changes. 2019-11-21 18:50:38 +00:00
Ralf Jung 5e115a25ca avoid some casts 2019-11-16 16:09:45 +01:00
Ralf Jung 09180d71fd make simd_size return a u64 2019-11-16 13:31:09 +01:00
Camille GILLOT ed640c6a27 Merge hir::Mutability into ast::Mutability. 2019-11-10 12:21:05 +01:00
Eduard-Mihai Burtescu ccde510c95 rustc_target: inline abi::FloatTy into abi::Primitive. 2019-11-07 16:54:25 +02:00
Mazdak Farrokhzad 55f76cdb2f syntax: use distinct FloatTy from rustc_target.
We also sever syntax's dependency on rustc_target as a result.
This should slightly improve pipe-lining.

Moreover, some cleanup is done in related code.
2019-11-07 05:25:31 +01:00
bors 2e4da3caad Auto merge of #65938 - eddyb:fn-abi-rename, r=oli-obk
rustc_target: rename {Fn,Arg}Type to {Fn,Arg}Abi.

I was trying to tweak the API of `FnType` (now `FnAbi`) and the name kept bothering me.

`FnAbi` is to a function signature a bit like a layout is to a type, so the name still isn't perfect yet, but at least it doesn't have the misleading `Type` in it anymore.

If this can't land I think I can continue my original refactor without it, so I'm not strongly attached to it.

r? @nagisa cc @oli-obk
2019-11-05 05:47:31 +00:00
Amanieu d'Antras 76660fde81 Make Emscripten unwinding use a valid type_info
This allows catch_panic to ignore C++ exceptions.
2019-11-03 14:04:15 +00:00
Amanieu d'Antras ad61c88e72 Make SEH exceptions use a rust_panic type instead of unsigned __int64* 2019-11-03 14:03:21 +00:00
Eduard-Mihai Burtescu 6567154ede rustc_target: rename {Fn,Arg}Type to {Fn,Arg}Abi. 2019-11-03 09:23:43 +02:00
bors 6c1b220fd7 Auto merge of #63810 - oli-obk:const_offset_from, r=RalfJung,nikic
Make <*const/mut T>::offset_from `const fn`

This reenables offset_of cc @mjbshaw 	after https://github.com/rust-lang/rust/pull/63075 broke it
2019-11-02 22:26:54 +00:00
Oliver Scherer 4a51801c39
Use dedicated method for getting the type size
Co-Authored-By: Nikita Popov <nikita.ppv@googlemail.com>
2019-10-18 12:21:09 +02:00
bjorn3 5f6ddb94a6 Move span_invalid_monomorphization_error from cg_llvm to cg_ssa
The associated long diagnostic didn't get registered before
2019-10-13 14:35:14 +02:00
Oliver Scherer 88b5e945e0 Make <*const/mut T>::offset_from `const fn` 2019-10-11 10:40:49 +02:00
Xiang Fan e9acfa306f Generate llvm.sideeffect at function entry instead of call 2019-09-28 07:14:21 +08:00
Xiang Fan 10c668190c Gate llvm.sideeffect under -Z insert-sideeffect 2019-09-28 07:13:53 +08:00
Xiang Fan f71e0daa29 Add llvm.sideeffect to potential infinite loops and recursions
LLVM assumes that a thread will eventually cause side effect. This is
not true in Rust if a loop or recursion does nothing in its body,
causing undefined behavior even in common cases like `loop {}`.
Inserting llvm.sideeffect fixes the undefined behavior.

As a micro-optimization, only insert llvm.sideeffect when jumping back
in blocks or calling a function.

A patch for LLVM is expected to allow empty non-terminate code by
default and fix this issue from LLVM side.

https://github.com/rust-lang/rust/issues/28728
2019-09-28 04:45:08 +08:00
varkor e2e0f9af85 Rename `sty` to `kind` 2019-09-25 15:50:04 +01:00
Oliver Scherer 0de9485038 Get rid of special const intrinsic query in favour of `const_eval` 2019-09-17 16:31:55 +02:00
Eduard-Mihai Burtescu e9214a147b codegen: be more explicit about setting giving names to allocas. 2019-09-12 19:04:30 +03:00
Dante-Broggi 8657fb1140 `new_sized` is mostly used without align
so rename it `new_sized_aligned`.
6/11 use `align` = `layout.align.abi`.
`from_const_alloc` uses `alloc.align`, but that is `assert_eq!` to `layout.align.abi`.
only 4/11 use something interesting for `align`.
2019-08-29 14:24:50 -04:00
Eduard-Mihai Burtescu 0f1da639d4 Rename overflowing_{add,sub,mul} intrinsics to wrapping_{add,sub,mul}. 2019-08-16 20:04:21 +03:00
Tatsuyuki Ishi 2358e3eff6 Revert "Rollup merge of #62150 - alex:mem-uninit-refactor, r=RalfJung"
This reverts commit 1d45156866, reversing
changes made to 0f92eb8a4a.
2019-08-10 22:16:35 +09:00
Vadim Petrochenkov 434152157f Remove lint annotations in specific crates that are already enforced by rustbuild
Remove some random unnecessary lint `allow`s
2019-07-28 18:46:24 +03:00
Nikita Popov 6fae7db65d Remove vector fadd/fmul reduction workarounds
The bugs that this was working around have been fixed in LLVM 9.
2019-07-20 18:49:50 +02:00
Nikita Popov 5c95f5fa6b Fix float add/mul reduction codegen
The accumulator is now respected for unordered reductions.
2019-07-09 21:55:29 +02:00
Alex Gaynor e4f250e405 Implement mem::{zeroed,uninitialized} in terms of MaybeUninit.
Refs #62061
2019-07-04 09:33:15 -04:00
Andrei Homescu b9ea653aee Expose `VaListImpl` as the Rust equivalent of `__va_list_tag` and implement Clone for it. 2019-06-17 16:04:49 -07:00
Eduard-Mihai Burtescu 4c98cb6f75 rustc_codegen_llvm: `deny(internal)`. 2019-06-12 16:06:35 +03:00
varkor 0e5edc9f16 Add intrinsics for floating-point min and max 2019-06-06 21:27:23 +01:00
Alexander Regueiro 35585c499f Aggregation of drive-by cosmetic changes. 2019-06-05 21:09:26 +01:00
bors e22b7a3eef Auto merge of #59148 - lcnr:unchecked_maths, r=eddyb
add support for unchecked math

add compiler support for
```rust
/// Returns the result of an unchecked addition, resulting in
/// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
pub fn unchecked_add<T>(x: T, y: T) -> T;

/// Returns the result of an unchecked substraction, resulting in
/// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
pub fn unchecked_sub<T>(x: T, y: T) -> T;

/// Returns the result of an unchecked multiplication, resulting in
/// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
pub fn unchecked_mul<T>(x: T, y: T) -> T;
```

cc https://github.com/rust-lang/rfcs/issues/2508
2019-06-03 22:05:55 +00:00
lcnr/Bastian Kauschke 4e7319cd3f add unchecked math intrinsics 2019-06-03 12:59:48 +02:00
Mark Mansi 0f822d775f query-fy type_name 2019-06-02 23:20:36 -05:00
Oliver Scherer 5b9848912a Make the `type_name` intrinsic's output deterministic 2019-05-30 11:19:22 +02:00
Nicholas Nethercote c06cdbeac5 Introduce `LocalInternedString::intern`.
`LocalInternedString::intern(x)` is preferable to
`Symbol::intern(x).as_str()`, because the former involves one call to
`with_interner` while the latter involves two.
2019-05-20 09:17:02 +10:00
Eduard-Mihai Burtescu eb525b0916 rustc: tie the 'tcx between Print and PrintCx in ty::print. 2019-03-15 09:26:13 +02:00
Eduard-Mihai Burtescu 01fa283d6f rustc: remove fmt::{Debug,Display} from ty::TyKind. 2019-03-15 09:26:13 +02:00
Dan Robertson 58147d486b
Support defining C compatible variadic functions
Add support for defining C compatible variadic functions in unsafe rust
with extern "C".
2019-02-27 10:21:35 -05:00
Mazdak Farrokhzad 9661a81968 librustc_codegen_llvm: deny(elided_lifetimes_in_paths) 2019-02-25 08:40:18 +01:00
bors 7cb3ee453b Auto merge of #58304 - gnzlbg:simd_saturated, r=nagisa
Add generic simd saturated add/sub intrinsics

r? @eddyb
2019-02-24 04:16:12 +00:00