Commit graph

155 commits

Author SHA1 Message Date
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
Luqman Aden
90eeb92e10 Update to LLVM head and mark various ptrs as nonnull. 2014-05-22 21:06:24 -04:00
klutzy
9f7caed202 rustllvm: Add LLVMRustArrayType
LLVM internally uses `uint64_t` for array size, but the corresponding
C API (`LLVMArrayType`) uses `unsigned int` so ths value is truncated.
Therefore rustc generates wrong type for fixed-sized large vector e.g.
`[0 x i8]` for `[0u8, ..(1 << 32)]`.

This patch adds `LLVMRustArrayType` function for `uint64_t` support.
2014-05-13 17:24:08 -07:00
Alex Crichton
de7845ac72 rustc: Fix passing errors from LLVM to rustc
Many of the instances of setting a global error variable ended up leaving a
dangling pointer into free'd memory. This changes the method of error
transmission to strdup any error and "relinquish ownership" to rustc when it
gets an error. The corresponding Rust code will then free the error as
necessary.

Closes #12865
2014-04-23 10:04:29 -07:00
Alex Crichton
50fb57bb10 rustc: Ensure closures are "split-stack"
In upgrading LLVM, only rust functions had the "split-stack" attribute added.
This commit changes the addition of LLVM's "split-stack" attribute to *always*
occur and then we remove it sometimes if the "no_split_stack" rust attribute is
present.

Closes #13625
2014-04-19 10:33:46 -07:00
Alex Crichton
30ff17f809 Upgrade LLVM
This comes with a number of fixes to be compatible with upstream LLVM:

* Previously all monomorphizations of "mem::size_of()" would receive the same
  symbol. In the past LLVM would silently rename duplicated symbols, but it
  appears to now be dropping the duplicate symbols and functions now. The symbol
  names of monomorphized functions are now no longer solely based on the type of
  the function, but rather the type and the unique hash for the
  monomorphization.

* Split stacks are no longer a global feature controlled by a flag in LLVM.
  Instead, they are opt-in on a per-function basis through a function attribute.
  The rust #[no_split_stack] attribute will disable this, otherwise all
  functions have #[split_stack] attached to them.

* The compare and swap instruction now takes two atomic orderings, one for the
  successful case and one for the failure case. LLVM internally has an
  implementation of calculating the appropriate failure ordering given a
  particular success ordering (previously only a success ordering was
  specified), and I copied that into the intrinsic translation so the failure
  ordering isn't supplied on a source level for now.

* Minor tweaks to LLVM's API in terms of debuginfo, naming, c++11 conventions,
  etc.
2014-04-17 11:11:39 -07:00
Alex Crichton
15e6e8cf3e rustc: Stop using LLVMGetSectionName
The recent pull request to remove libc from libstd has hit a wall in compiling
on windows, and I've been trying to investigate on the try bots as to why (it
compiles locally just fine). To the best of my knowledge, the LLVM section
iterator is behaving badly when iterating over the sections of the libc DLL.

Upon investigating the LLVMGetSectionName function in LLVM, I discovered that
this function doesn't always return a null-terminated string. It returns the
data pointer of a StringRef instance (LLVM's equivalent of &str essentially),
but it has no method of returning the length of the name of the section.

This commit modifies the section iteration when loading libraries to invoke a
custom LLVMRustGetSectionName which will correctly return both the length and
the data pointer.

I have not yet verified that this will fix landing liblibc, as it will require a
snapshot before doing a full test. Regardless, this is a worrisome situation
regarding the LLVM API, and should likely be fixed anyway.
2014-04-03 10:49:35 -07:00
gentlefolk
f4518cdba7 Initial support for emitting DWARF for static vars.
Only supports crate level statics. No debug info is generated for
function level statics. Closes #9227.
2014-03-27 21:03:44 -04:00
Alex Crichton
9396452592 rustc: Fix support for LLVM 3.3
The llvm.copysign and llvm.round intrinsics weren't added until LLVM 3.4, so if
we're on LLVM 3.3 we lower these to calls in libm instead of LLVM intrinsics.

This should fix our travis failures.
2014-03-05 18:05:05 -08:00
Alex Crichton
1ac5e84e91 rustc: Get rustc compiling with LLVM 3.{3,4} again
The travis builds have been breaking recently because LLVM 3.5 upstream is
changing. This looks like it's likely to continue, so it would be more useful
for us if we could lock ourselves to a system LLVM version that is not changing.

This commit has the support to bring our C++ glue to LLVM back in line with what
was possible back in LLVM 3.{3,4}. I don't think we're going to be able to
reasonably protect against regressions in the future, but this kind of code is a
good sign that we can continue to use the system LLVM for simple-ish things.
Codegen for ARM won't work and it won't have some of the perf improvements we
have, but using the system LLVM should work well enough for development.
2014-02-26 15:01:15 -08:00
bors
e3b1f3c443 auto merge of #11853 : alexcrichton/rust/up-llvm, r=brson
This upgrade brings commit by @eddyb to help optimizations of virtual calls in
a few places (https://github.com/llvm-mirror/llvm/commit/6d2bd95) as well as a
commit by @c-a to *greatly* improve the runtime of the optimization passes
(https://github.com/rust-lang/llvm/pull/3).

Nice work to these guys!
2014-01-29 23:46:26 -08:00
Alex Crichton
8cd935f52a Upgrade LLVM
This upgrade brings commit by @eddyb to help optimizations of virtual calls in
a few places (https://github.com/llvm-mirror/llvm/commit/6d2bd95) as well as a
commit by @c-a to *greatly* improve the runtime of the optimization passes
(https://github.com/rust-lang/llvm/pull/3).

Nice work to these guys!
2014-01-29 23:43:39 -08:00
comex
ea7b20d8f2 Add appropriate LLVM module flags for debug info.
Set "Dwarf Version" to 2 on OS X to avoid toolchain incompatibility, and
set "Debug Info Version" to prevent debug info from being stripped from
bitcode.

Fixes #11352.
2014-01-28 00:05:33 -05:00
Niko Matsakis
419ac4a1b8 Issue #3511 - Rationalize temporary lifetimes.
Major changes:

- Define temporary scopes in a syntax-based way that basically defaults
  to the innermost statement or conditional block, except for in
  a `let` initializer, where we default to the innermost block. Rules
  are documented in the code, but not in the manual (yet).
  See new test run-pass/cleanup-value-scopes.rs for examples.
- Refactors Datum to better define cleanup roles.
- Refactor cleanup scopes to not be tied to basic blocks, permitting
  us to have a very large number of scopes (one per AST node).
- Introduce nascent documentation in trans/doc.rs covering datums and
  cleanup in a more comprehensive way.
2014-01-15 18:34:38 -05:00
bors
3249de8c4f auto merge of #11274 : michaelwoerister/rust/issue11083, r=pcwalton
This pull request fixes #11083. The problem was that recursive type definitions were not properly handled for enum types, leading to problems with LLVM's metadata "uniquing". This bug has already been fixed for struct types some time ago (#9658) but I seem to have forgotten about enums back then. I added the offending code from issue #11083 as a test case.
2014-01-02 09:02:01 -08:00
Michael Woerister
6d20876c3f debuginfo: Fix issue #11083 and some minor clean up. 2014-01-02 15:20:43 +01:00
Alex Crichton
c22fed9424 Convert relevant static mutexes to Once 2013-12-31 20:15:03 -08:00
Alex Crichton
64faafba19 rustc: Optimize reading metadata by 4x
We were previously reading metadata via `ar p`, but as learned from rustdoc
awhile back, spawning a process to do something is pretty slow. Turns out LLVM
has an Archive class to read archives, but it cannot write archives.

This commits adds bindings to the read-only version of the LLVM archive class
(with a new type that only has a read() method), and then it uses this class
when reading the metadata out of rlibs. When you put this in tandem of not
compressing the metadata, reading the metadata is 4x faster than it used to be
The timings I got for reading metadata from the respective libraries was:

    libstd-04ff901e-0.9-pre.dylib    => 100ms
    libstd-04ff901e-0.9-pre.rlib     => 23ms
    librustuv-7945354c-0.9-pre.dylib => 4ms
    librustuv-7945354c-0.9-pre.rlib  => 1ms
    librustc-5b94a16f-0.9-pre.dylib  => 87ms
    librustc-5b94a16f-0.9-pre.rlib   => 35ms
    libextra-a6ebb16f-0.9-pre.dylib  => 63ms
    libextra-a6ebb16f-0.9-pre.rlib   => 15ms
    libsyntax-2e4c0458-0.9-pre.dylib => 86ms
    libsyntax-2e4c0458-0.9-pre.rlib  => 22ms

In order to always take advantage of these faster metadata read-times, I sort
the files in filesearch based on whether they have an rlib extension or not
(prefer all rlib files first).

Overall, this halved the compile time for a `fn main() {}` crate from 0.185s to
0.095s on my system (when preferring dynamic linking). Reading metadata is still
the slowest pass of the compiler at 0.035s, but it's getting pretty close to
linking at 0.021s! The next best optimization is to just not copy the metadata
from LLVM because that's the most expensive part of reading metadata right now.
2013-12-19 23:34:32 -08:00
Alex Crichton
fce4a174b9 Implement LTO
This commit implements LTO for rust leveraging LLVM's passes. What this means
is:

* When compiling an rlib, in addition to insdering foo.o into the archive, also
  insert foo.bc (the LLVM bytecode) of the optimized module.

* When the compiler detects the -Z lto option, it will attempt to perform LTO on
  a staticlib or binary output. The compiler will emit an error if a dylib or
  rlib output is being generated.

* The actual act of performing LTO is as follows:

    1. Force all upstream libraries to have an rlib version available.
    2. Load the bytecode of each upstream library from the rlib.
    3. Link all this bytecode into the current LLVM module (just using llvm
       apis)
    4. Run an internalization pass which internalizes all symbols except those
       found reachable for the local crate of compilation.
    5. Run the LLVM LTO pass manager over this entire module

    6a. If assembling an archive, then add all upstream rlibs into the output
        archive. This ignores all of the object/bitcode/metadata files rust
        generated and placed inside the rlibs.
    6b. If linking a binary, create copies of all upstream rlibs, remove the
        rust-generated object-file, and then link everything as usual.

As I have explained in #10741, this process is excruciatingly slow, so this is
*not* turned on by default, and it is also why I have decided to hide it behind
a -Z flag for now. The good news is that the binary sizes are about as small as
they can be as a result of LTO, so it's definitely working.

Closes #10741
Closes #10740
2013-12-09 14:41:49 -08:00
Alex Crichton
6b34ba242d Update LLVM and jettison jit support
LLVM's JIT has been updated numerous times, and we haven't been tracking it at
all. The existing LLVM glue code no longer compiles, and the JIT isn't used for
anything currently.

This also rebases out the FixedStackSegment support which we have added to LLVM.
None of this is still in use by the compiler, and there's no need to keep this
functionality around inside of LLVM.

This is needed to unblock #10708 (where we're tripping an LLVM assertion).
2013-12-05 09:15:54 -08:00
Daniel Micay
541e5f84d7 add support for the cold function attribute
This allows a function to marked as infrequently called, resulting in
any branch calling it to be considered colder.
2013-10-28 15:34:50 -04:00
Daniel Micay
7bad416765 have LLVM print type strings for us
Example:

    void ({ i64, %tydesc*, i8*, i8*, i8 }*, i64*, %"struct.std::fmt::Formatter[#1]"*)*

Before, we would print 20 levels deep due to recursion in the type
definition.
2013-10-11 20:26:08 -04:00
Michael Woerister
85deeeab59 debuginfo: Unified namespace generation approach for crate-local and external items. Fixed bug related to LLVM metadata uniquing. 2013-10-08 10:35:24 +02:00
Michael Woerister
ccb721a58d debuginfo: Added description of algorithm for handling recursive types.
Also fixed nasty bug caused by calling LLVMDIBuilderCreateStructType() with a null pointer where an empty array was expected (which would trigger an unintelligable assertion somewhere down the line).
2013-09-15 12:28:25 +02:00
Michael Woerister
f85da506a8 debuginfo: Support for recursive types. 2013-09-15 12:28:25 +02:00
Michael Woerister
382cb500be debuginfo: Wrapped namespace facilities of llvm::DIBuilder 2013-09-10 16:25:19 +02:00
Daniel Micay
889e1b9731 add noalias attribute to ~ return values 2013-09-09 13:48:54 -04:00
Michael Woerister
b81ea86530 debuginfo: Support for variables captured in closures and closure type descriptions. 2013-09-04 18:38:46 +02:00
Brian Anderson
3801534d10 Revert "auto merge of #8695 : thestinger/rust/build, r=pcwalton"
This reverts commit 2c0f9bd354, reversing
changes made to f8c4f0ea9c.

Conflicts:
	src/rustllvm/RustWrapper.cpp
2013-08-28 19:59:52 -07:00