Commit graph

183 commits

Author SHA1 Message Date
Jake Goulding
e6e117c33a Extend preprocessor LLVM version checks to support LLVM 4.x
This doesn't actually do anything for LLVM 4.x yet, but sets the stage.
2016-09-26 13:40:29 -04:00
Matt Ickstadt
b9a8c1a063 Fix incorrect LLVM Linkage enum
The `Linkage` enum in librustc_llvm got out of sync with the version in LLVM and it caused two variants of the #[linkage=""] attribute to break.

This adds the functions `LLVMRustGetLinkage` and `LLVMRustSetLinkage` which convert between the Rust Linkage enum and the LLVM one, which should stop this from breaking every time LLVM changes it.

Fixes #33992
2016-09-04 16:12:01 -05:00
Vadim Chugunov
cf6461168f Fix debug line info for macro expansions.
Macro expansions produce code tagged with debug locations that are completely different from the surrounding expressions.  This wrecks havoc on debugger's ability the step over source lines.

In order to have a good line stepping behavior in debugger, we overwrite debug locations of macro expansions with that of the outermost expansion site.
2016-08-25 00:40:42 -07:00
Ariel Ben-Yehuda
3041a97b1a finish type-auditing rustllvm 2016-08-03 15:08:47 +03:00
Ariel Ben-Yehuda
d091ef802f begin auditing the C++ types in RustWrapper 2016-08-03 15:08:47 +03:00
Jan-Erik Rediger
7420874a97 [LLVM-3.9] Rename custom methods to Rust-specific ones 2016-07-29 10:29:44 +02:00
Jake Goulding
4f01329e0e Reflect supporting only LLVM 3.7+ in the LLVM wrappers 2016-06-09 15:59:26 -04:00
Björn Steinbrink
22f4587586 Use weak_odr linkage when reusing definitions across codegen units
When reuing a definition across codegen units, we obviously cannot use
internal linkage, but using external linkage means that we can end up
with multiple conflicting definitions of a single symbol across
multiple crates. Since the definitions should all be equal
semantically, we can use weak_odr linkage to resolve the situation.

Fixes #32518
2016-03-29 16:44:54 +02:00
Björn Steinbrink
95697a8395 Fix removal of function attributes on ARM
We use a 64bit integer to pass the set of attributes that is to be
removed, but the called C function expects a 32bit integer. On most
platforms this doesn't cause any problems other than being unable to
unset some attributes, but on  ARM even the lower 32bit aren't handled
correctly because the 64bit value is passed in different registers, so
the C function actually sees random garbage.

So we need to fix the relevant functions to use 32bit integers instead.
Additionally we need an implementation that actually accepts 64bit
integers because some attributes can only be unset that way.

Fixes #32360
2016-03-26 13:02:54 +01:00
Ulrik Sverdrup
e22d6d569f Fix LLVMRustSetHasUnsafeAlgebra to only have effect on instructions 2016-03-19 22:35:28 +01:00
Ulrik Sverdrup
2dbac1fb8e Add intrinsics for float arithmetic with fast flag enabled
`fast` a.k.a UnsafeAlgebra is the flag for enabling all "unsafe"
(according to llvm) float optimizations.

See LangRef for more information http://llvm.org/docs/LangRef.html#fast-math-flags

Providing these operations with less precise associativity rules (for
example) is useful to numerical applications.

For example, the summation loop:

    let sum = 0.;
    for element in data {
        sum += *element;
    }

Using the default floating point semantics, this loop expresses the
floats must be added in a sequence, one after another. This constraint
is usually completely unintended, and it means that no autovectorization
is possible.
2016-03-18 17:31:41 +01:00
Simonas Kazlauskas
ba26efb60c Implement filling drop in MIR
Hopefully the author caught all the cases. For the mir_dynamic_drops_3 test case the ratio of
memsets to other instructions is 12%. On the other hand we actually do not double drop for at least
the test cases provided anymore in MIR.
2016-02-24 21:05:21 +02:00
Amanieu d'Antras
64ddcb33f4 Add intrinsics for compare_exchange and compare_exchange_weak 2016-02-18 19:07:05 +00:00
bors
1096e7ab7a Auto merge of #30962 - Amanieu:non_volatile_atomic, r=alexcrichton
Rust currently emits atomic loads and stores with the LLVM `volatile` qualifier. This is unnecessary and prevents LLVM from performing optimization on these atomic operations.
2016-02-04 02:46:44 +00:00
Alex Crichton
3e9589c0f4 trans: Reimplement unwinding on MSVC
This commit transitions the compiler to using the new exception handling
instructions in LLVM for implementing unwinding for MSVC. This affects both 32
and 64-bit MSVC as they're both now using SEH-based strategies. In terms of
standard library support, lots more details about how SEH unwinding is
implemented can be found in the commits.

In terms of trans, this change necessitated a few modifications:

* Branches were added to detect when the old landingpad instruction is used or
  the new cleanuppad instruction is used to `trans::cleanup`.
* The return value from `cleanuppad` is not stored in an `alloca` (because it
  cannot be).
* Each block in trans now has an `Option<LandingPad>` instead of `is_lpad: bool`
  for indicating whether it's in a landing pad or not. The new exception
  handling intrinsics require that on MSVC each `call` inside of a landing pad
  is annotated with which landing pad that it's in. This change to the basic
  block means that whenever a `call` or `invoke` instruction is generated we
  know whether to annotate it as part of a cleanuppad or not.
* Lots of modifications were made to the instruction builders to construct the
  new instructions as well as pass the tagging information for the call/invoke
  instructions.
* The translation of the `try` intrinsics for MSVC has been overhauled to use
  the new `catchpad` instruction. The filter function is now also a
  rustc-generated function instead of a purely libstd-defined function. The
  libstd definition still exists, it just has a stable ABI across architectures
  and leaves some of the really weird implementation details to the compiler
  (e.g. the `localescape` and `localrecover` intrinsics).
2016-01-29 16:25:20 -08:00
Alex Crichton
d1cace17af trans: Upgrade LLVM
This brings some routine upgrades to the bundled LLVM that we're using, the most
notable of which is a bug fix to the way we handle range asserts when loading
the discriminant of an enum. This fix ended up being very similar to f9d4149c
where we basically can't have a range assert when loading a discriminant due to
filling drop, and appropriate flags were added to communicate this to
`trans::adt`.
2016-01-29 16:25:20 -08:00
Amanieu d'Antras
01112d1ac4 Don't make atomic loads and stores volatile 2016-01-16 20:16:10 +00:00
Seo Sanghyeon
b285f92025 rustllvm: Update to LLVM trunk 2015-10-24 18:42:23 +09:00
Alex Crichton
27dd6dd3db Tweak Travis to use GCE
Travis CI has new infrastructure using the Google Compute Engine which has both
faster CPUs and more memory, and we've been encouraged to switch as it should
help our build times! The only downside currently, however, is that IPv6 is
disabled, causing a number of standard library tests to fail.

Consequently this commit tweaks our travis config in a few ways:

* ccache is disabled as it's not working on GCE just yet
* Docker is used to run tests inside which reportedly will get IPv6 working
* A system LLVM installation is used instead of building LLVM itself. This is
  primarily done to reduce build times, but we want automation for this sort of
  behavior anyway and we can extend this in the future with building from source
  as well if needed.
* gcc-specific logic is removed as the docker image for Ubuntu gives us a
  recent-enough gcc by default.
2015-09-29 16:56:35 -07:00
Alex Crichton
c35b2bd226 trans: Move rust_try into the compiler
This commit moves the IR files in the distribution, rust_try.ll,
rust_try_msvc_64.ll, and rust_try_msvc_32.ll into the compiler from the main
distribution. There's a few reasons for this change:

* LLVM changes its IR syntax from time to time, so it's very difficult to
  have these files build across many LLVM versions simultaneously. We'll likely
  want to retain this ability for quite some time into the future.
* The implementation of these files is closely tied to the compiler and runtime
  itself, so it makes sense to fold it into a location which can do more
  platform-specific checks for various implementation details (such as MSVC 32
  vs 64-bit).
* This removes LLVM as a build-time dependency of the standard library. This may
  end up becoming very useful if we move towards building the standard library
  with Cargo.

In the immediate future, however, this commit should restore compatibility with
LLVM 3.5 and 3.6.
2015-07-21 16:08:11 -07:00
Alex Crichton
7f0e733f1d rustc_trans: Update LLVMBuildLandingPad signature
The C API of this function changed so it no longer takes a personality function.
A shim was introduced to call the right LLVM function (depending on which
version we're compiled against) to set the personality function on the outer
function.

The compiler only ever sets one personality function for all generated
functions, so this should be equivalent.
2015-07-16 20:25:51 -07:00
Alex Crichton
4a824275b9 trans: Use LLVM's writeArchive to modify archives
We have previously always relied upon an external tool, `ar`, to modify archives
that the compiler produces (staticlibs, rlibs, etc). This approach, however, has
a number of downsides:

* Spawning a process is relatively expensive for small compilations
* Encoding arguments across process boundaries often incurs unnecessary overhead
  or lossiness. For example `ar` has a tough time dealing with files that have
  the same name in archives, and the compiler copies many files around to ensure
  they can be passed to `ar` in a reasonable fashion.
* Most `ar` programs found do **not** have the ability to target arbitrary
  platforms, so this is an extra tool which needs to be found/specified when
  cross compiling.

The LLVM project has had a tool called `llvm-ar` for quite some time now, but it
wasn't available in the standard LLVM libraries (it was just a standalone
program). Recently, however, in LLVM 3.7, this functionality has been moved to a
library and is now accessible by consumers of LLVM via the `writeArchive`
function.

This commit migrates our archive bindings to no longer invoke `ar` by default
but instead make a library call to LLVM to do various operations. This solves
all of the downsides listed above:

* Archive management is now much faster, for example creating a "hello world"
  staticlib is now 6x faster (50ms => 8ms). Linking dynamic libraries also
  recently started requiring modification of rlibs, and linking a hello world
  dynamic library is now 2x faster.
* The compiler is now one step closer to "hassle free" cross compilation because
  no external tool is needed for managing archives, LLVM does the right thing!

This commit does not remove support for calling a system `ar` utility currently.
We will continue to maintain compatibility with LLVM 3.5 and 3.6 looking forward
(so the system LLVM can be used wherever possible), and in these cases we must
shell out to a system utility. All nightly builds of Rust, however, will stop
needing a system `ar`.
2015-07-10 09:06:21 -07:00
Alex Crichton
f9d4149c29 rustc: Update LLVM
This commit updates the LLVM submodule in use to the current HEAD of the LLVM
repository. This is primarily being done to start picking up unwinding support
for MSVC, which is currently unimplemented in the revision of LLVM we are using.
Along the way a few changes had to be made:

* As usual, lots of C++ debuginfo bindings in LLVM changed, so there were some
  significant changes to our RustWrapper.cpp
* As usual, some pass management changed in LLVM, so clang was re-scrutinized to
  ensure that we're doing the same thing as clang.
* Some optimization options are now passed directly into the
  `PassManagerBuilder` instead of through CLI switches to LLVM.
* The `NoFramePointerElim` option was removed from LLVM, favoring instead the
  `no-frame-pointer-elim` function attribute instead.

Additionally, LLVM has picked up some new optimizations which required fixing an
existing soundness hole in the IR we generate. It appears that the current LLVM
we use does not expose this hole. When an enum is moved, the previous slot in
memory is overwritten with a bit pattern corresponding to "dropped". When the
drop glue for this slot is run, however, the switch on the discriminant can
often start executing the `unreachable` block of the switch due to the
discriminant now being outside the normal range. This was patched over locally
for now by having the `unreachable` block just change to a `ret void`.
2015-06-16 22:56:42 -07:00
Luca Bruno
ce32f6412e rustc_trans: don't hardcode llvm version for conditional intrinsics
This commit introduce a third parameter for compatible_ifn!, as new
intrinsics are being added in recent LLVM releases and there is no
need to hardcode a specific case.

Signed-off-by: Luca Bruno <lucab@debian.org>
2015-06-07 22:47:00 -04:00
Tamir Duberstein
1be9e6f055 Remove useless const 2015-06-07 22:43:21 -04:00
Alex Crichton
847c8520b1 rustc_llvm: Don't export constants across dlls
For imports of constants across DLLs to work on Windows it *requires* that the
import be marked with `dllimport` (unlike functions where the marker is
optional, but strongly recommended). This currently isn't working for importing
FFI constants across boundaries, however, so the one constant exported from
`rustc_llvm.dll` is now a function to be called instead.
2015-05-19 10:53:07 -07:00
Alex Crichton
40570eb49e rustc_llvm: Expose setting more DLL storage classes
Currently only `dllexport` is used, but more integration will require using
`dllimport` as well.
2015-05-12 14:50:36 -07:00
Peter Marheine
998c10d6b6 Add singlethreaded fence intrinsics.
These new intrinsics are comparable to `atomic_signal_fence` in C++,
ensuring the compiler will not reorder memory accesses across the
barrier, nor will it emit any machine instructions for it.

Closes #24118, implementing RFC 888.
2015-04-25 19:41:21 -06:00
Alex Crichton
d14fb2f0d6 rollup merge of #24635: tamird/llvm-3.5
r? @alexcrichton
2015-04-21 15:23:10 -07:00
Alex Crichton
9ab0475d94 rustc: Handle duplicate names merging archives
When linking an archive statically to an rlib, the compiler will extract all
contents of the archive and add them all to the rlib being generated. The
current method of extraction is to run `ar x`, dumping all files into a
temporary directory. Object archives, however, are allowed to have multiple
entries with the same file name, so there is no method for them to extract their
contents into a directory in a lossless fashion.

This commit adds iterator support to the `ArchiveRO` structure which hooks into
LLVM's support for reading object archives. This iterator is then used to
inspect each object in turn and extract it to a unique location for later
assembly.
2015-04-21 11:08:19 -07:00
Tamir Duberstein
ba276adab5 LLVM < 3.5 is unsupported since bb18a3c 2015-04-21 07:20:48 -07:00
Simonas Kazlauskas
deb097a1d2 Implement LLVMGetOrInsertGlobal wrapper 2015-04-03 15:48:07 +03:00
Simonas Kazlauskas
2198969f89 Wrap LLVM’s Module::getNamedValue 2015-04-03 15:46:09 +03:00
Björn Steinbrink
bb18a3cfe7 Drop support for LLVM < 3.5 and fix compile errors with 3.5
LLVM older that 3.6 has a bug that cause assertions when compiling certain
constructs. For 3.5 there's still a chance that the bug might get fixed
in 3.5.2, so let's keep allowing to compile with it for it for now.
2015-03-14 13:14:04 +01:00
Björn Steinbrink
602e508db0 Update LLVM to rust-llvm-2015-01-30 2015-02-01 20:00:35 +01:00
John Kåre Alsaker
4cfb70026c Better inline assembly errors 2015-01-22 19:43:39 +01:00
Michael Woerister
91a0e18866 debuginfo: Add a rust-gdb shell script that will start GDB with Rust pretty printers enabled. 2014-12-30 17:26:13 +01:00
Luqman Aden
4b22178d32 Update LLVM. 2014-10-04 13:28:57 -04:00
Keegan McAllister
9d60de93e2 Translate inline assembly errors back to source locations
Fixes #17552.
2014-09-27 11:10:37 -07:00
Keegan McAllister
ad9a1daa81 Add -C remark for LLVM optimization remarks
Fixes #17116.
2014-09-12 11:46:38 -07:00
Keegan McAllister
225353d8bb Add a Rust string ostream for LLVM 2014-09-12 11:46:38 -07:00
Björn Steinbrink
f1f67b2848 Fix builds with LLVM < 3.6 2014-08-15 16:36:05 +02:00
Vadim Chugunov
a12b23521f Update LLVM 2014-08-04 17:43:56 -07:00
Luqman Aden
a78c0f1019 rustllvm: Stub out some functions for llvm < 3.5 2014-07-25 19:47:29 -07:00
Luqman Aden
17256197a9 librustc: Use builder for llvm attributes. 2014-07-25 16:06:44 -07:00
Alex Crichton
b29d106b7c rustllvm: Don't require null terminators in files
Apparently the default getFile implementation for a memory buffer in LLVM ends
up requiring a null terminator at the end of the file. This isn't true a good
bit of the time apparently on OSX. There have been a number of failed
nightly/snapshot builds recently with this strange assertion.

This modifies the calls to MemoryBuffer::getFile to explicitly not ask for a
null terminator.
2014-07-24 11:31:28 -07:00
Valerii Hiora
57cade5744 Updated LLVM for iOS
There should be no more problems during SjLj pass
2014-07-24 07:25:55 -07:00
Björn Steinbrink
90a9f65b8d Update LLVM
To fix #8106, we need an LLVM version that contains r211082 aka 0dee6756
which fixes a bug that blocks that issue.

There have been some tiny API changes in LLVM, and cmpxchg changed its
return type. The i1 part of the new return type is only interesting when
using the new weak cmpxchg, which we don't do.
2014-06-21 19:59:58 +02:00
Michael Woerister
c7426cf05a debuginfo: Fix issue with unique type IDs not being passed to LLVM for LLVM 3.4 2014-06-12 18:48:14 +02:00
Luqman Aden
3cae434f5c librustc: Consolidate the attribute handling for tagging function arguments and returns. 2014-05-23 22:32:30 -04:00