Commit Graph

147 Commits

Author SHA1 Message Date
Nikita Popov
c6b0803202 Add support for new pass manager
The new pass manager can be enabled using
-Z new-llvm-pass-manager=on.
2020-02-12 15:34:16 +01:00
Wesley Wiser
f5f86be1d4 Add support for enabling the LLVM time-trace feature
I found this helpful while investigating an LLVM performance issue.
Passing `-Z llvm-time-trace` causes a `llvm_timings.json` file to be
created. This file can be inspected in either the Chrome Profiler tools
or with any other compatible tool like SpeedScope.

More information on the LLVM feature:

- https://aras-p.info/blog/2019/01/16/time-trace-timeline-flame-chart-profiler-for-Clang/

- https://reviews.llvm.org/rL357340
2020-02-01 14:19:17 -05:00
Tomasz Miąsko
08a1c566a7 Detect use-after-scope bugs with AddressSanitizer
Enable use-after-scope checks by default when using AddressSanitizer.
They allow to detect incorrect use of stack objects after their scope
have already ended. The detection is based on LLVM lifetime intrinsics.

To facilitate the use of this functionality, the lifetime intrinsics are
now emitted regardless of optimization level if enabled sanitizer makes
use of them.
2020-01-27 16:56:25 +01:00
Nikita Popov
8010f4037a Update thinLTOInternalizeAndPromoteInIndex() usage 2020-01-07 21:28:22 +01:00
Nikita Popov
30ec68a545 Handle removal of llvm::make_unique() 2020-01-07 21:28:22 +01:00
Nikita Popov
3ec3aa72d4 CodeGenFileType moved outside TargetMachine 2020-01-07 21:28:21 +01:00
Nikita Popov
2fd4e76d88 Explicitly include InitializePasses.h 2020-01-07 21:28:21 +01:00
bors
1e2a73867d Auto merge of #66952 - 0dvictor:print, r=rkruppe
Use Module::print() instead of a PrintModulePass

llvm::Module has a print() method. It is unnecessary to create a pass just for the purpose of printing LLVM IR.
2019-12-05 11:23:26 +00:00
Mazdak Farrokhzad
8dcb5326dd
Rollup merge of #66973 - cuviper:min-llvm7, r=alexcrichton
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-03 19:41:57 +01:00
Parth Sane
54b206034f Change linker for x86_64-fortanix-unknown-sgx to rust-lld
For SGX, the relocation using the relocation table is done by
the code in rust/src/libstd/sys/sgx/abi/reloc.rs and this code
should not require relocation. Setting RelaxELFRelocations flag
if allows this to happen, hence adding a Target Option for it.
2019-12-03 14:44:14 +05:30
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
Victor Ding
85df207ecc Use Module::print() instead of a PrintModulePass
llvm::Module has a print() method. It is unnecessary to create a
pass just for the purpose of printing LLVM IR.
2019-12-02 21:04:44 +11:00
Victor Ding
b41b1d3407 Use LLVMAddAnalysisPasses instead of Rust's wrapper
LLVM exposes a C API `LLVMAddAnalysisPasses` and hence Rust's own
wrapper `LLVMRustAddAnalysisPasses` is not needed anymore.
2019-11-29 14:31:09 +11:00
Tyler Mandry
b05f14cc40
Rollup merge of #66761 - yuyoyuppe:rust_llvm_minor_fix, r=alexcrichton
Use LLVMDisposePassManager instead of raw delete in rustllvm

LLVM has a dedicated API call which wraps the destructor invocation for the PassManager.
Rust invokes it [otherwhere](d63b24ffcc/src/librustc_codegen_llvm/back/write.rs (L446-L447)), but not in the `LLVMRustWriteOutputFile`.

Since `LLVMDisposePassManager` might be extended to perform additional cleanup actions in the future, this change replaces raw destructor invocation with that API call.
2019-11-27 15:28:45 -06:00
yuyoyuppe
e846ea1112
Use LLVMDisposePassManager instead of raw delete in rustllvm 2019-11-25 23:52:10 +03:00
Tomasz Miąsko
5141aa36f6 Retain compatibility with LLVM 6, 7, 8 and 9 2019-11-22 19:32:45 +01:00
Tomasz Miąsko
317f68ab10 Move sanitizer passes creation from ssa to llvm 2019-11-22 19:31:43 +01:00
Mazdak Farrokhzad
98cbe17903
Rollup merge of #66062 - smaeul:patch/pic-level, r=estebank
Configure LLVM module PIC level

As of LLVM 9, this is required for 32-bit PowerPC to properly generate
PLT references. Previously, only BigPIC was supported; now LLVM supports
both BigPIC and SmallPIC, and there is no default value provided.
2019-11-06 07:03:06 +01:00
Samuel Holland
1943079361 Configure LLVM module PIC level
As of LLVM 9, this is required for 32-bit PowerPC to properly generate
PLT references. Previously, only BigPIC was supported; now LLVM supports
both BigPIC and SmallPIC, and there is no default value provided.
2019-11-03 10:52:00 -06:00
Gui Andrade
539de439ad Allow specifying key "llvm-abiname" in target specification
This addresses #65024, as it allows RISC-V target specification
files to set "llvm-abiname": "lp64d". In general, it is useful
for the programmer to be able to set this codegen parameter,
which other languages usually expose under a compiler argument
like "-mabi=<XYZ>".
2019-10-29 21:12:05 -07:00
Nikita Popov
b9784b18c2 Don't link mcjit/interpreter LLVM components 2019-07-20 17:17:48 +02:00
Nikita Popov
a5c3956a75 Don't add extra passes into the function pass manager
Exception for specific cases like linting, additional passes should
be going into the module pass manager (even if they are function
passes). The separate function pass manager is only used for very
early optimization passes.

Rather than apparending passes to the MPM, use the OptimizerLast
and EnabledOnOptLevel0 pass manager builder extension hooks, which
allow adding passes directly before finalization (alias
canonicalization and name-anon-globals).

The main effect and purpose of this change is to add sanitizer
passes at the end of the pipeline, which is where they belong.
In LLVM 9 the address sanitizer can't be used as a pass in the
early function pass manager, because it has a dependence on a
module-level analysis pass.
2019-07-15 09:45:14 +02:00
Nikita Popov
d6c818e8d7 Update CPU printing for SubtargetSubTypeKV
CPUs now use SubtargetSubTypeKV rather than SubtargetFeatureKV and
no longer have a description.
2019-07-13 00:16:40 +02:00
Nikita Popov
04304fcd16 Pass GUIDPreservedSymbols to thinLTOResolvePrevailingInIndex() 2019-07-09 21:55:29 +02:00
Josh Stone
b4131e297e Limit internalization in LLVM 8 ThinLTO 2019-04-26 08:58:14 -07:00
Josh Stone
aafe2c6da9 Show better errors for LLVM IR output
I was trying to output LLVM IR directly to the console:

    $ rustc hello.rs --emit=llvm-ir -o /dev/stdout
    LLVM ERROR: IO failure on output stream: Bad file descriptor

Now `LLVMRustPrintModule` returns an error, and we print:

    error: failed to write LLVM IR to /dev/stdout.hello.7rcbfp3g-cgu.0.rcgu.ll: Permission denied

... which is more informative.
2019-04-05 17:48:23 -07:00
Alex Crichton
e983b4f64e rustc: Implement incremental "fat" LTO
Currently the compiler will produce an error if both incremental
compilation and full fat LTO is requested. With recent changes and the
advent of incremental ThinLTO, however, all the hard work is already
done for us and it's actually not too bad to remove this error!

This commit updates the codegen backend to allow incremental full fat
LTO. The semantics are that the input modules to LTO are all produce
incrementally, but the final LTO step is always done unconditionally
regardless of whether the inputs changed or not. The only real
incremental win we could have here is if zero of the input modules
changed, but that's so rare it's unlikely to be worthwhile to implement
such a code path.

cc #57968
cc rust-lang/cargo#6643
2019-02-12 04:58:31 -08:00
Josh Stone
df0466d0bb Rebase to the llvm-project monorepo
The new git submodule src/llvm-project is a monorepo replacing src/llvm
and src/tools/{clang,lld,lldb}.  This also serves as a rebase for these
projects to the new 8.x branch from trunk.

The src/llvm-emscripten fork is unchanged for now.
2019-01-25 15:39:54 -08:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Nikita Popov
706e67b0a0 Bump minimum required LLVM version to 6.0 2018-12-09 12:05:40 +01:00
Nikita Popov
cbf748993f Enable -mergefunc-use-aliases
If the Rust LLVM fork is used, enable the -mergefunc-use-aliases
flag, which will create aliases for merged functions, rather than
inserting a call from one to the other.

A number of codegen tests needed to be adjusted, because functions
that previously fell below the thunk limit are now being merged.
Merging is prevented either using -C no-prepopulate-passes, or by
making the functions non-identical.

I expect that this is going to break something, somewhere, because
it isn't able to deal with aliases properly, but we won't find out
until we try :)

This fixes #52651.
2018-11-30 00:52:16 +01:00
Alex Crichton
ae5b350d77 Handle some renamed ThinLTO functions 2018-11-25 20:27:18 -08:00
bors
775eab5883 Auto merge of #55698 - nikic:remove-llvm-4-support, r=alexcrichton
Remove support for building against LLVM 4

With emscripten removed in #55626, we no longer need to support building against LLVM 4.
2018-11-11 22:38:54 +00:00
bors
06118eac4c Auto merge of #55626 - nikic:update-emscripten, r=alexcrichton
Update emscripten

This updates emscripten to 1.38.15, which is based on LLVM 6.0.1 and would allow us to drop code for handling LLVM 4.

The main issue I ran into is that exporting statics through `EXPORTED_FUNCTIONS` no longer works. As far as I understand exporting non-functions doesn't really make sense under emscripten anyway, so I've modified the symbol export code to not even try.

Closes #52323.
2018-11-10 01:16:02 +00:00
Nikita Popov
3cc8b17451 Remove support for building against LLVM 4
With emscripten removed in #55626, we no longer need to support
building against LLVM 4.
2018-11-05 15:04:26 +01:00
Nikita Popov
9eb19273a3 Update llvm-emscripten
This updates emscripten to version 1.38.15, which is based on
LLVM 6.0.1.
2018-11-04 18:50:57 +01:00
Nikita Popov
d794597698 Remove checks for LLVM < 4.0
While we still have to support LLVM 4.0 for Emscripten, we can
drop checks for LLVM >= 4.0 and < 4.0.
2018-11-01 21:09:02 +01:00
Jorge Aparicio
3c0907ce51 add -Z emit-stack-sizes 2018-09-26 15:21:26 +02:00
Michael Woerister
2e587df6e2 Provide a way of accessing the ThinLTO module import map in rustc. 2018-08-31 15:22:52 +02:00
Alex Crichton
1fd45a13de Fix warnings about the native target-cpu
This fixes a regression from #53031 where specifying `-C target-cpu=native` is
printing a lot of warnings from LLVM about `native` being an unknown CPU. It
turns out that `native` is indeed an unknown CPU and we have to perform a
mapping to an actual CPU name, but this mapping is only performed in one
location rather than all locations we inform LLVM about the target CPU.

This commit centralizes the mapping of `native` to LLVM's value of the native
CPU, ensuring that all locations we inform LLVM about the `target-cpu` it's
never `native`.

Closes #53322
2018-08-28 13:32:11 -07:00
Alex Crichton
9d54bf8df2 Buffer LLVM's object output stream
In some profiling on OSX I saw the `write` syscall as quite high up on
the profiling graph, which is definitely not good! It looks like we're
setting the output stream of an object file as directly to a file
descriptor which means that we run the risk of doing lots of little
writes rather than a few large writes.

This commit fixes this issue by adding a buffered stream on the output,
causing the `write` syscall to disappear from the profiles on OSX.
2018-08-19 23:46:32 -07:00
whitequark
66fd1ebfae Make LLVM emit assembly comments with -Z asm-comments.
Fixes #35741.
2018-08-12 17:59:33 +00:00
David Craven
2d5f62fb48
[RISCV] Enable LLVM backend. 2018-08-01 15:32:22 +02:00
Pietro Albini
61b9a516d3
Rollup merge of #52824 - varkor:fix-llvm-ret-move-warnings, r=rkruppe
Fix -Wpessimizing-move warnings in rustllvm/PassWrapper

These are producing warnings when building rustc (`warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]`).
2018-08-01 10:12:45 +02:00
Irina Popa
ebec156abf rustc_codegen_llvm: remove more unused functions. 2018-07-30 20:10:25 +03:00
varkor
9ccd7eef1e Fix -Wpessimizing-move warnings in rustllvm/PassWrapper 2018-07-29 12:20:06 +01:00
bors
5665a2d367 Auto merge of #52506 - alexcrichton:dont-duplicate-wasm-sections, r=michaelwoerister
rustc: Work around an upstream wasm ThinLTO bug

This commit implements a workaround for an [upstream LLVM bug][1] where custom
sections were accidentally duplicated amongst codegen units when ThinLTO passes
were performed. This is due to the fact that custom sections for wasm are stored
as metadata nodes which are automatically imported into modules when ThinLTO
happens. The fix here is to forcibly delete the metadata node from imported
modules before LLVM has a chance to try to copy it over.

[1]: https://bugs.llvm.org/show_bug.cgi?id=38184
2018-07-23 13:42:23 +00:00
Alex Crichton
e08fcbbd8d rustc: Work around an upstream wasm ThinLTO bug
This commit implements a workaround for an [upstream LLVM bug][1] where custom
sections were accidentally duplicated amongst codegen units when ThinLTO passes
were performed. This is due to the fact that custom sections for wasm are stored
as metadata nodes which are automatically imported into modules when ThinLTO
happens. The fix here is to forcibly delete the metadata node from imported
modules before LLVM has a chance to try to copy it over.

[1]: https://bugs.llvm.org/show_bug.cgi?id=38184
2018-07-18 12:12:53 -07:00
Alex Crichton
829bc268a9 rustc: Remove a workaroudn in ThinLTO fixed upstream
This commit removes a hack in our ThinLTO passes which removes available
externally functions manually. The [upstream bug][1] has long since been fixed,
so we should be able to rely on LLVM natively for this now!

[1]: https://bugs.llvm.org/show_bug.cgi?id=35736
2018-07-18 11:37:56 -07:00
Michael Woerister
d992090a70 Revert "Provide a way of accessing the ThinLTO module import map in rustc."
This reverts commit 9df56ca0ee.
2018-07-16 08:59:10 +02:00