Commit Graph

167 Commits

Author SHA1 Message Date
root
9f50f84ef1 break long line for formatting 2020-06-16 18:14:32 +00:00
root
4506a358ca add header for rust specific feature 2020-06-16 17:36:04 +00:00
asrar
e32db84584
Add rust features to print target features
`crt-static` is a rust specific target feature that's absent from llvm feature table, adding it there.
2020-06-14 21:44:11 +05:30
Jake Goulding
690bb8af51 [AVR] Add AVR platform support 2020-06-09 17:34:07 +12:00
Vadim Petrochenkov
d0a48d19f5 rustllvm: Fix warnings about unused function parameters 2020-05-21 22:05:19 +03:00
bors
5f472813df Auto merge of #72248 - petrochenkov:codemodel, r=Amanieu
Cleanup and document `-C code-model`

r? @Amanieu
2020-05-17 21:22:48 +00:00
Vadim Petrochenkov
55a94bdc38 rustc_target: Stop using "string typing" for code models
Introduce `enum CodeModel` instead.
2020-05-16 12:02:11 +03:00
Tomasz Miąsko
bbb63d4554 Consistently use LLVM lifetime markers during codegen
Ensure that inliner inserts lifetime markers if they have been emitted during
codegen. Otherwise if allocas from inlined functions are merged together,
lifetime markers from one function might invalidate load & stores performed
by the other one.
2020-05-14 15:23:24 +02:00
Ralf Jung
ce05553c62
Rollup merge of #71234 - maurer:init-array, r=cuviper
rustllvm: Use .init_array rather than .ctors

LLVM TargetMachines default to using the (now-legacy) .ctors
representation of init functions. Mixing .ctors and .init_array
representations can cause issues when linking with lld.

This happens in practice for:

* Our profiling runtime which is currently implicitly built with
  .init_array since it is built by clang, which sets this field.
* External C/C++ code that may be linked into the same process.

Fixes: #71233
2020-05-09 13:36:32 +02:00
bors
1357af3a55 Auto merge of #71528 - alexcrichton:no-more-bitcode, r=nnethercote
Store LLVM bitcode in object files, not compressed

This commit is an attempted resurrection of #70458 where LLVM bitcode
emitted by rustc into rlibs is stored into object file sections rather
than in a separate file. The main rationale for doing this is that when
rustc emits bitcode it will no longer use a custom compression scheme
which makes it both easier to interoperate with existing tools and also
cuts down on compile time since this compression isn't happening.

The blocker for this in #70458 turned out to be that native linkers
didn't handle the new sections well, causing the sections to either
trigger bugs in the linker or actually end up in the final linked
artifact. This commit attempts to address these issues by ensuring that
native linkers ignore the new sections by inserting custom flags with
module-level inline assembly.

Note that this does not currently change the API of the compiler at all.
The pre-existing `-C bitcode-in-rlib` flag is co-opted to indicate
whether the bitcode should be present in the object file or not.

Finally, note that an important consequence of this commit, which is also
one of its primary purposes, is to enable rustc's `-Clto` bitcode
loading to load rlibs produced with `-Clinker-plugin-lto`. The goal here
is that when you're building with LTO Cargo will tell rustc to skip
codegen of all intermediate crates and only generate LLVM IR. Today
rustc will generate both object code and LLVM IR, but the object code is
later simply thrown away, wastefully.
2020-04-29 23:47:27 +00:00
Matthew Maurer
0e7d5be4b8 Use .init_array rather than .ctors
LLVM TargetMachines default to using the (now-legacy) .ctors
representation of init functions. Mixing .ctors and .init_array
representations can cause issues when linking with lld.

This happens in practice for:

* Our profiling runtime which is currently implicitly built with
  .init_array since it is built by clang, which sets this field.
* External C/C++ code that may be linked into the same process.

To support legacy systems which may use .ctors, targets may now specify
that they use .ctors via the use_ctors attribute which defaults to
false.

For debugging and manual control, -Z use-ctors-section=yes/no will allow
manual override.

Fixes: #71233
2020-04-29 13:38:59 -07:00
Alex Crichton
ef89cc8f04 Store LLVM bitcode in object files, not compressed
This commit is an attempted resurrection of #70458 where LLVM bitcode
emitted by rustc into rlibs is stored into object file sections rather
than in a separate file. The main rationale for doing this is that when
rustc emits bitcode it will no longer use a custom compression scheme
which makes it both easier to interoperate with existing tools and also
cuts down on compile time since this compression isn't happening.

The blocker for this in #70458 turned out to be that native linkers
didn't handle the new sections well, causing the sections to either
trigger bugs in the linker or actually end up in the final linked
artifact. This commit attempts to address these issues by ensuring that
native linkers ignore the new sections by inserting custom flags with
module-level inline assembly.

Note that this does not currently change the API of the compiler at all.
The pre-existing `-C bitcode-in-rlib` flag is co-opted to indicate
whether the bitcode should be present in the object file or not.

Finally, note that an important consequence of this commit, which is also
one of its primary purposes, is to enable rustc's `-Clto` bitcode
loading to load rlibs produced with `-Clinker-plugin-lto`. The goal here
is that when you're building with LTO Cargo will tell rustc to skip
codegen of all intermediate crates and only generate LLVM IR. Today
rustc will generate both object code and LLVM IR, but the object code is
later simply thrown away, wastefully.
2020-04-29 11:57:26 -07:00
Vadim Petrochenkov
0452725583 codegen_llvm: RelocMode -> RelocModel 2020-04-26 11:18:48 +03:00
Vadim Petrochenkov
fb91e5ed2f rustc_target: Stop using "string typing" for relocation models
Introduce `enum RelocModel` instead.
2020-04-26 11:18:47 +03:00
Josh Stone
8506bb0060 Update the minimum external LLVM to 8
LLVM 8 was released on March 20, 2019, over a year ago.
2020-04-14 12:44:41 -07:00
Nikita Popov
a94fa896cc Fix timeTraceProfilerInitialize for LLVM 10 2020-03-19 20:09:57 +01:00
Tomasz Miąsko
a61e13423e Invoke OptimizerLastEPCallbacks in PreLinkThinLTO
The default ThinLTO pre-link pipeline does not include optimizer last
extension points. Thus, when using the new LLVM pass manager & ThinLTO
& sanitizers on any opt-level different from zero, the sanitizer
function passes would be omitted from the pipeline.

Add optimizer last extensions points manually to the pipeline, but guard
registration with stage check in the case this behaviour changes in the
future.
2020-03-03 08:37:44 +01:00
bors
10104085e4 Auto merge of #69144 - Dylan-DPC:rollup-apt6zjj, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #68728 (parse: merge `fn` syntax + cleanup item parsing)
 - #68938 (fix lifetime shadowing check in GATs)
 - #69057 (expand: misc cleanups and simplifications)
 - #69108 (Use HirId in TraitCandidate.)
 - #69125 (Add comment to SGX entry code)
 - #69126 (miri: fix exact_div)
 - #69127 (Enable use after scope detection in the new LLVM pass manager)
 - #69135 (Spelling error "represening" to "representing")
 - #69141 (Don't error on network failures)

Failed merges:

r? @ghost
2020-02-13 22:20:58 +00:00
Andreas Jonson
cec0ed0219 add selfprofiling for new llvm passmanager 2020-02-13 08:02:18 +01:00
Tomasz Miąsko
91b4a24219 Enable use after scope detection in the new LLVM pass manager
Implementation of 08a1c566a7 for the new
LLVM pass manager, support for which landed in the meantime.
2020-02-13 00:00:00 +00:00
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