Commit Graph

515 Commits

Author SHA1 Message Date
Irina Popa
b63d7e2b1c Rename trans to codegen everywhere. 2018-05-17 15:08:30 +03:00
Anthony Ramine
5701779b8e Reenable the MergeFunctions pass
The crash that happened in #23566 doesn't happen anymore with the LLVM mergefunc
pass enabled and it hugely reduces code size (for example it shaves off 10% of the
final Servo executable). This patch reenables it.
2018-05-15 21:10:40 +02:00
Nikita Popov
a70ef4cb49 Set PrepareForThinLTO flag when using ThinLTO
The LLVM PassManager has a PrepareForThinLTO flag, which is intended
when compilation occurs in conjunction with linking by ThinLTO. The
flag has two effects:

 * The NameAnonGlobal pass is run after all other passes, which
   ensures that all globals have a name.
 * In optimized builds, a number of late passes (mainly related to
   vectorization and unrolling) are disabled, on the rationale that
   these a) will increase codesize of the intermediate artifacts
   and b) will be run by ThinLTO again anyway.

This patch enables the use of PrepareForThinLTO if Thin or ThinLocal
linking is used.

The background for this change is the CI failure in #49479, which
we assume to be caused by the NameAnonGlobal pass not being run.
As this changes which passes LLVM runs, this might have performance
(or other) impact, so we want to land this separately.
2018-05-12 14:07:20 +02:00
Simon Sapin
86753ce1cc Use the GlobalAlloc trait for #[global_allocator] 2018-04-12 22:53:12 +02:00
Josh Stone
a93a4d259a Enable target_feature on any LLVM 6+
In `LLVMRustHasFeature()`, rather than using `MCInfo->getFeatureTable()`
that is specific to Rust's LLVM fork, we can use this in LLVM 6:

    /// Check whether the subtarget features are enabled/disabled as per
    /// the provided string, ignoring all other features.
    bool checkFeatures(StringRef FS) const;

Now rustc using external LLVM can also have `target_feature`.
2018-03-27 12:27:45 -07:00
bors
31ae4f9fde Auto merge of #49249 - gnzlbg:simd_minmax, r=alexcrichton
implement minmax intrinsics

This adds the `simd_{fmin,fmax}` intrinsics, which do a vertical (lane-wise) `min`/`max` for floating point vectors that's equivalent to Rust's `min`/`max` for `f32`/`f64`.

It might make sense to make `{f32,f64}::{min,max}` use the `minnum` and `minmax` intrinsics as well.

---

~~HELP: I need some help with these. Either I should go to sleep or there must be something that I must be missing. AFAICT I am calling the `maxnum` builder correctly, yet rustc/LLVM seem to insert a call to `llvm.minnum` there instead...~~ EDIT: Rust's LLVM version is too old :/
2018-03-27 04:46:32 +00:00
bors
13a86f4d85 Auto merge of #48346 - emilio:pgo, r=alexcrichton
Add basic PGO support.

This PR adds two mutually exclusive options for profile usage and generation using LLVM's instruction profile generation (the same as clang uses), `-C pgo-use` and `-C pgo-gen`.

See each commit for details.
2018-03-26 13:00:18 +00:00
gnzlbg
066c2ec9ba require llvm 6 2018-03-26 10:20:41 +02:00
gnzlbg
7d5343a670 implement minmax intrinsics 2018-03-26 10:20:41 +02:00
Scott McMurray
02b5851258 Polyfill LLVMBuildExactUDiv
It was added 32 days after LLVM 3.9 shipped.
2018-03-24 19:15:12 -07:00
Emilio Cobos Álvarez
e155ecdc97
try to fix the build on older LLVM versions. 2018-03-25 03:30:06 +02:00
Emilio Cobos Álvarez
a95c8c66a7
librustc_llvm: Show PGO diagnostics properly.
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
2018-03-25 03:30:05 +02:00
Emilio Cobos Álvarez
324ca7acd5
rustc_llvm: rustc_trans: Thread the PGO config down to the pass manager builder.
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
2018-03-25 03:30:04 +02:00
gnzlbg
19b81f6114 error via bug! instead of stderr+terminate 2018-03-15 16:51:58 +01:00
gnzlbg
3125a30759 error on vector reduction usage if LLVM version is < 5.0 2018-03-15 10:08:22 +01:00
gnzlbg
c990fa0d88 add dummy symbols for LLVM<6 2018-03-14 22:12:38 +01:00
gnzlbg
07ce659dd0 expose ordered/unordered/nanless intirnsics 2018-03-14 17:22:40 +01:00
gnzlbg
01cc5b3e19 add intrinsics for portable packed simd vector reductions 2018-03-13 16:47:48 +01:00
varkor
108c56660a Merge LLVM fix for undefined bss globals
This fixes #41315.
2018-03-10 12:38:41 +00:00
Alex Crichton
04eaefb25f rustc: Update LLVM
This pulls in the rest of LLVM's `release_60` branch (the actual 6.0.0 release)
and also pulls in a cherry-pick to...

Closes #48226
2018-03-06 08:45:12 -08:00
Alex Crichton
43e8ac27d9 rustc: Persist LLVM's Linker in Fat LTO
This commit updates our Fat LTO logic to tweak our custom wrapper around LLVM's
"link modules" functionality. Previously whenever the
`LLVMRustLinkInExternalBitcode` function was called it would call LLVM's
`Linker::linkModules` wrapper. Internally this would crate an instance of a
`Linker` which internally creates an instance of an `IRMover`. Unfortunately for
us the creation of `IRMover` is somewhat O(n) with the input module. This means
that every time we linked a module it was O(n) with respect to the entire module
we had built up!

Now the modules we build up during LTO are quite large, so this quickly started
creating an O(n^2) problem for us! Discovered in #48025 it turns out this has
always been a problem and we just haven't noticed it. It became particularly
worse recently though due to most libraries having 16x more object files than
they previously did (1 -> 16).

This commit fixes this performance issue by preserving the `Linker` instance
across all links into the main LLVM module. This means we only create one
`IRMover` and allows LTO to progress much speedier.

From the `cargo-cache` project in #48025 a **full build** locally when from
5m15s to 2m24s. Looking at the timing logs each object file was linked in in
single-digit millisecond rather than hundreds, clearly being a nice improvement!

Closes #48025
2018-02-12 09:11:06 -08:00
Alex Crichton
6b7b6b63a9 rustc: Upgrade to LLVM 6
The following submodules have been updated for a new version of LLVM:

- `src/llvm`
- `src/libcompiler_builtins` - transitively contains compiler-rt
- `src/dlmalloc`

This also updates the docker container for dist-i686-freebsd as the old 16.04
container is no longer capable of building LLVM. The
compiler-rt/compiler-builtins and dlmalloc updates are pretty routine without
much interesting happening, but the LLVM update here is of particular note.
Unlike previous updates I haven't cherry-picked all existing patches we had on
top of our LLVM branch as we have a [huge amount][patches4] and have at this
point forgotten what most of them are for. Instead I started from the current
`release_60` branch in LLVM and only applied patches that were necessary to get
our tests working and building.

The current set of custom rustc-specific patches included in this LLVM update are:

* rust-lang/llvm@1187443 - this is how we actually implement
  `cfg(target_feature)` for now and continues to not be upstreamed. While a
  hazard for SIMD stabilization this commit is otherwise keeping the status
  quo of a small rustc-specific feature.
* rust-lang/llvm@013f2ec - this is a rustc-specific optimization that we haven't
  upstreamed, notably teaching LLVM about our allocation-related routines (which
  aren't malloc/free). Once we stabilize the global allocator routines we will
  likely want to upstream this patch, but for now it seems reasonable to keep it
  on our fork.
* rust-lang/llvm@a65bbfd - I found this necessary to fix compilation of LLVM in
  our 32-bit linux container. I'm not really sure why it's necessary but my
  guess is that it's because of the absolutely ancient glibc that we're using.
  In any case it's only updating pieces we're not actually using in LLVM so I'm
  hoping it'll turn out alright. This doesn't seem like something we'll want to
  upstream.c
* rust-lang/llvm@77ab1f0 - this is what's actually enabling LLVM to build in our
  i686-freebsd container, I'm not really sure what's going on but we for sure
  probably don't want to upstream this and otherwise it seems not too bad for
  now at least.
* rust-lang/llvm@9eb9267 - we currently suffer on MSVC from an [upstream bug]
  which although diagnosed to a particular revision isn't currently fixed
  upstream (and the bug itself doesn't seem too active). This commit is a
  partial revert of the suspected cause of this regression (found via a
  bisection). I'm sort of hoping that this eventually gets fixed upstream with a
  similar fix (which we can replace in our branch), but for now I'm also hoping
  it's a relatively harmless change to have.

After applying these patches (plus one [backport] which should be [backported
upstream][llvm-back]) I believe we should have all tests working on all
platforms in our current test suite. I'm like 99% sure that we'll need some more
backports as issues are reported for LLVM 6 when this propagates through
nightlies, but that's sort of just par for the course nowadays!

In any case though some extra scrutiny of the patches here would definitely be
welcome, along with scrutiny of the "missing patches" like a [change to pass
manager order](rust-lang/llvm@2717444753), [another change to pass manager
order](rust-lang/llvm@c782febb7b), some [compile fixes for
sparc](rust-lang/llvm@1a83de63c4), and some [fixes for
solaris](rust-lang/llvm@c2bfe0abb).

[patches4]: https://github.com/rust-lang/llvm/compare/5401fdf23...rust-llvm-release-4-0-1
[backport]: https://github.com/rust-lang/llvm/commit/5c54c252db
[llvm-back]: https://bugs.llvm.org/show_bug.cgi?id=36114
[upstream bug]: https://bugs.llvm.org/show_bug.cgi?id=36096

---

The update to LLVM 6 is desirable for a number of reasons, notably:

* This'll allow us to keep up with the upstream wasm backend, picking up new
  features as they start landing.
* Upstream LLVM has fixed a number of SIMD-related compilation errors,
  especially around AVX-512 and such.
* There's a few assorted known bugs which are fixed in LLVM 5 and aren't fixed
  in the LLVM 4 branch we're using.
* Overall it's not a great idea to stagnate with our codegen backend!

This update is mostly powered by #47730 which is allowing us to update LLVM
*independent* of the version of LLVM that Emscripten is locked to. This means
that when compiling code for Emscripten we'll still be using the old LLVM 4
backend, but when compiling code for any other target we'll be using the new
LLVM 6 target. Once Emscripten updates we may no longer need this distinction,
but we're not sure when that will happen!

Closes #43370
Closes #43418
Closes #47015
Closes #47683
Closes rust-lang-nursery/stdsimd#157
Closes rust-lang-nursery/rust-wasm#3
2018-02-09 17:13:14 -08:00
Alex Crichton
d492fe0a00 rustc: Add some defines for LLVM 7 compat
I was testing out the tip support to see what's going on with wasm, and this was
I believe the only issue encountered with LLVM 7 support so far.
2018-01-30 12:11:31 -08:00
Alex Crichton
c915e3a10a Merge branch 'mlsm' of https://github.com/dotdash/rust into rollup 2018-01-26 06:53:18 -08:00
Björn Steinbrink
aca88e185a Upgrade LLVM to incorporate a fix for #47364
Fixes #47364
2018-01-26 09:57:34 +01:00
Alex Crichton
8a9381db01 Rollup merge of #47710 - alexcrichton:llvm-6-compat, r=nikomatsakis
First round of LLVM 6.0.0 compatibility

This includes a number of commits for the first round of upgrading to LLVM 6. There are still [lingering bugs](https://github.com/rust-lang/rust/issues/47683) but I believe all of this will nonetheless be necessary!
2018-01-25 13:49:54 -08:00
Alex Crichton
4856f07bb5 Rollup merge of #47618 - mrhota:dw_at_noreturn, r=michaelwoerister
Teach rustc about DW_AT_noreturn and a few more DIFlags

We achieve two small things with this PR:
1. We provide definitions for a few additional llvm debuginfo flags
1. We _use_ one of these new flags, `FlagNoReturn`, and add it to debuginfo for functions with the never return type (`!`).
2018-01-25 13:49:46 -08:00
Alex Crichton
caedb36f08 llvm6: Different return value for writeArchive
Updated in llvm-mirror/llvm@203c90ba this function now just returns an `Error`,
so this updates the C++ bindings accordingly
2018-01-24 07:18:02 -08:00
Alex Crichton
b6fe1127e4 llvm6: Remove MIPS64 archive variant
It looks like LLVM also removed it in llvm-mirror/llvm@f45adc29d in favor of the
name "GNU64". This was added in the thought that we'd need such a variant when
adding mips64 support but we ended up not needing it! For now let's just
removing the various support on the Rust side of things.
2018-01-24 07:18:02 -08:00
Alex Crichton
9eeecd2ada llvm6: Tweak fast math intrinsics
Looks like they did some refactoring of flags in the backend and this should
catch us up! The "unsafe algebra" boolean has been split into a number of
boolean flags for various operations, and this updates to use the `setFast`
function which should hopefully have the same behavior as before.

This was updated in llvm-mirror/llvm@00e900afd
2018-01-24 07:18:02 -08:00
Alex Crichton
2a7ed74d96 llvm6: Missing include for LLVM 6 in PassWrapper.cpp
Just bog-standard compile error fixed by adding some new header files
2018-01-24 07:18:01 -08:00
Alex Crichton
03f86ae982 llvm6: CodeModel::{JIT,}Default no longer exists
LLVM has since removed the `CodeModel::Default` enum value in favor of an
`Optional` implementationg throughout LLVM. Let's mirror the same change in Rust
and update the various bindings we call accordingly.

Removed in llvm-mirror/llvm@9aafb854c
2018-01-24 07:18:01 -08:00
A.J. Gardner
e0f9b26899 Ensure test doesn't run with llvm 3.9 2018-01-21 12:36:25 -06:00
A.J. Gardner
7188706c4f Teach rustc about DW_AT_noreturn and a few more DIFlags 2018-01-20 18:34:53 -06:00
Josh Stone
e2f6b280ea Update DW_OP_plus to DW_OP_plus_uconst
LLVM <= 4.0 used a non-standard interpretation of `DW_OP_plus`.  In the
DWARF standard, this adds two items on the expressions stack.  LLVM's
behavior was more like DWARF's `DW_OP_plus_uconst` -- adding a constant
that follows the op.  The patch series starting with [D33892] switched
to the standard DWARF interpretation, so we need to follow.

[D33892]: https://reviews.llvm.org/D33892
2018-01-19 21:43:53 -08:00
Eduard-Mihai Burtescu
7b3ac21427 rustc_trans: remove unused TargetDataRef accessor. 2018-01-14 08:52:16 +02:00
Björn Steinbrink
907855fe88 Remove unused LLVMRustJITMemoryManagerRef typedef 2018-01-07 04:39:58 +01:00
Björn Steinbrink
ebc85077df Remove dead function rustc_llvm::debug_loc_to_string()
Refs #46437 as it also removes LLVMRustWriteDebugLocToString()
2018-01-07 04:39:58 +01:00
Björn Steinbrink
4be1d5c37b Remove dead function LLVMRustLinkInParsedExternalBitcode()
Refs #46437
2018-01-07 04:39:58 +01:00
Björn Steinbrink
92189bc521 Remove redundant -Zdebug-llvm option
The same effect can be achieved using -Cllvm-args=-debug

Refs #46437 as it removes LLVMRustSetDebug()
2018-01-07 04:39:58 +01:00
kennytm
f6125846b6 Rollup merge of #47220 - nagisa:nonamellvm, r=rkruppe
Use name-discarding LLVM context

This is only applicable when neither of --emit=llvm-ir or --emit=llvm-bc are not
requested.

In case either of these outputs are wanted, but the benefits of such context are
desired as well, -Zfewer_names option provides the same functionality regardless
of the outputs requested.

Should be a viable fix for https://github.com/rust-lang/rust/issues/46449
2018-01-07 02:36:06 +08:00
Guillaume Gomez
21b9822390 Rollup merge of #47173 - dotdash:cleanup, r=michaelwoerister
Remove some outdated LLVM-related code

Ticks two boxes on #46437
2018-01-06 02:13:34 +01:00
Simonas Kazlauskas
b719578f48 Use name-discarding LLVM context
This is only applicable when neither of --emit=llvm-ir or --emit=llvm-bc are not
requested.

In case either of these outputs are wanted, but the benefits of such context are
desired as well, -Zfewer_names option provides the same functionality regardless
of the outputs requested.
2018-01-05 19:08:44 +02:00
bors
5e66887fed Auto merge of #46739 - arielb1:simple-loops, r=nikomatsakis
[needs perf run] Try to improve LLVM pass ordering

Fixes #45466
2018-01-05 02:31:19 +00:00
Björn Steinbrink
7e522b2f0e Simplify LLVMRustModuleCost() 2018-01-04 08:57:14 +01:00
Björn Steinbrink
493c29d35a Remove unused function LLVMRustGetValueContext()
Refs #46437
2018-01-04 08:57:14 +01:00
Björn Steinbrink
d7bbd3042c Remove outdated LLVMRustBuildLandingPad() wrapper
The function was added as a wrapper to handle compatibility with older
LLVM versions that we no longer support, so it can be removed.

Refs #46437
2018-01-04 08:57:14 +01:00
Alex Crichton
b5361d0d41 rustc: Set release mode cgus to 16 by default
This commit is the next attempt to enable multiple codegen units by default in
release mode, getting some of those sweet, sweet parallelism wins by running
codegen in parallel. Performance should not be lost due to ThinLTO being on by
default as well.

Closes #45320
2017-12-23 16:04:15 -08:00
Alex Crichton
e0ab5d5feb rustc: Work around DICompileUnit bugs in LLVM
This commit implements a workaround for #46346 which basically just
avoids triggering the situation that LLVM's bug
https://bugs.llvm.org/show_bug.cgi?id=35562 arises. More details can be
found in the code itself but this commit is also intended to ...

Closes #46346
2017-12-18 11:44:00 -08:00
Steve Klabnik
6e95629812 Rollup merge of #46652 - ishitatsuyuki:thinlto-backport, r=alexcrichton
ThinLTO: updates for LLVM 5

refs:

ccb80b9c0f
e611018a3f
2017-12-15 09:26:57 -05:00