about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm/llvm
AgeCommit message (Collapse)AuthorLines
2020-04-29Auto merge of #71528 - alexcrichton:no-more-bitcode, r=nnethercotebors-0/+5
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-29Store LLVM bitcode in object files, not compressedAlex Crichton-0/+5
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-26codegen_llvm: `RelocMode` -> `RelocModel`Vadim Petrochenkov-2/+2
2020-04-26rustc_target: Stop using "string typing" for relocation modelsVadim Petrochenkov-1/+0
Introduce `enum RelocModel` instead.
2020-04-02Add hash of source files in debug infoArlo Siemsen-0/+12
* Adds either an MD5 or SHA1 hash to the debug info. * Adds new unstable option `-Z src-hash-algorithm` to control the hashing algorithm.
2020-03-26Rename asm! to llvm_asm!Amanieu d'Antras-3/+3
asm! is left as a wrapper around llvm_asm! to maintain compatibility.
2020-03-23Rollup merge of #69940 - tmiasko:llvm-api, r=hanna-kruppeMazdak Farrokhzad-5/+13
librustc_codegen_llvm: Replace deprecated API usage
2020-03-20remove redundant returns (clippy::needless_return)Matthias Krüger-2/+2
2020-03-16use direct imports for `rustc::{lint, session}`.Mazdak Farrokhzad-2/+2
2020-03-12remove lifetimes that can be elided (clippy::needless_lifetimes)Matthias Krüger-3/+3
2020-03-11librustc_codegen_llvm: Replace deprecated API usageTomasz Miąsko-5/+13
2020-03-11librustc_codegen_llvm: Use slices instead of 0-terminated stringsTomasz Miąsko-4/+14
Changed functions: * LLVMRustGetOrInsertFunction * LLVMRustGetNamedValue * LLVMRustBuildCall (removed unused name argument) * LLVMRustInlineAsm * LLVMRustInlineAsmVerify * LLVMRustAppendModuleInlineAsm
2020-03-09Use slices in preference to 0-terminated stringsTomasz Miąsko-2/+24
Additionally whenever possible match C API provided by the LLVM.
2020-03-05Change DIBuilderCreateEnumerator signature to match LLVM 9Tomasz Miąsko-1/+3
No functional changes intended.
2020-02-29Rename `syntax` to `rustc_ast` in source codeVadim Petrochenkov-3/+3
2020-02-13add selfprofiling for new llvm passmanagerAndreas Jonson-0/+7
2020-02-12Rollup merge of #67954 - nikic:new-pm, r=nagisaDylan DPC-0/+57
Support new LLVM pass manager Add support for the new LLVM pass manager behind a `-Z new-llvm-pass-manager=on` option. Both the pre-link optimization and LTO pipelines use the new pass manager. There's some bits that are not supported yet: * `-C passes`. NewPM requires an entirely different way of specifying custom pass pipelines. We should probably expose that functionality, but it doesn't directly map to what `-C passes` does. * NewPM has no support for custom inline parameters right now. We'd have to add upstream support for that first. * NewPM does not support PGO at O0 in LLVM 9 (which is why those tests fail with NewPM enabled). This is supported in LLVM 10. * NewPM does not support MergeFunctions in LLVM 9. I've landed this upstream just before the cut, so we'll be able to re-enable that with LLVM 10. Closes #64289. r? @ghost
2020-02-12Add support for new pass managerNikita Popov-0/+49
The new pass manager can be enabled using -Z new-llvm-pass-manager=on.
2020-02-12Use IRBuilder to create memsetNikita Popov-0/+8
To avoid creating memsets with outdated signature. For some reason SROA chokes on this when using NewPM.
2020-02-12Properly use the darwin archive format on Apple targetsAnthony Ramine-0/+2
See https://github.com/servo/servo/issues/25550.
2020-02-08rustc_codegen_ssa: remove unnecessary source_locations_enabled.Eduard-Mihai Burtescu-1/+1
2020-02-08rustc_codegen_llvm: remove InternalDebugLocation and simplify dbg_var_addr.Eduard-Mihai Burtescu-2/+0
2020-02-01Add support for enabling the LLVM time-trace featureWesley Wiser-0/+4
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
2019-12-22Format the worldMark Rousskov-966/+1106
2019-12-12Fix weird implicit dependency between rustllvm and rustc_codegen_llvmAaron Hill-17/+2
rustllvm relies on the `LLVMRustStringWriteImpl` symbol existing, but this symbol was previously defined in a *downstream* crate (rustc_codegen_llvm, which depends on rustc_llvm. While this somehow worked under the old 'separate bootstrap step for codegen' scheme, it meant that rustc_llvm could not actually be built by itself, since it relied linking to the downstream rustc_codegen_llvm crate. Now that librustc_codegen_llvm is just a normal crate, we actually try to build a standalone rustc_llvm when we run tests. This commit moves `LLVMRustStringWriteImpl` into rustc_llvm (technically the rustllvm directory, which has its contents built by rustc_llvm). This ensures that we can build each crate in the graph by itself, without requiring that any downstream crates be linked in as well.
2019-12-11rustc: Link LLVM directly into rustc againAlex Crichton-0/+1
This commit builds on #65501 continue to simplify the build system and compiler now that we no longer have multiple LLVM backends to ship by default. Here this switches the compiler back to what it once was long long ago, which is linking LLVM directly to the compiler rather than dynamically loading it at runtime. The `codegen-backends` directory of the sysroot no longer exists and all relevant support in the build system is removed. Note that `rustc` still supports a dynamically loaded codegen backend as it did previously, it just no longer supports dynamically loaded codegen backends in its own sysroot. Additionally as part of this the `librustc_codegen_llvm` crate now once again explicitly depends on all of its crates instead of implicitly loading them through the sysroot. This involved filling out its `Cargo.toml` and deleting all the now-unnecessary `extern crate` annotations in the header of the crate. (this in turn required adding a number of imports for names of macros too). The end results of this change are: * Rustbuild's build process for the compiler as all the "oh don't forget the codegen backend" checks can be easily removed. * Building `rustc_codegen_llvm` is much simpler since it's simply another compiler crate. * Managing the dependencies of `rustc_codegen_llvm` is much simpler since it's "just another `Cargo.toml` to edit" * The build process should be a smidge faster because there's more parallelism in the main rustc build step rather than splitting `librustc_codegen_llvm` out to its own step. * The compiler is expected to be slightly faster by default because the codegen backend does not need to be dynamically loaded. * Disabling LLVM as part of rustbuild is still supported, supporting multiple codegen backends is still supported, and dynamic loading of a codegen backend is still supported.
2019-12-07Rollup merge of #67033 - cuviper:ValueName2, r=rkruppeYuki Okushi-5/+24
Migrate to LLVM{Get,Set}ValueName2 The deprecated `LLVM{Get,Set}ValueName` only work with NUL-terminated strings, but the `2` variants use explicit lengths, which fits better with Rust strings and slices. We now use these in new helper functions `llvm::{get,set}_value_name` that convert to/from `&[u8]`. Closes #64223. r? @rkruppe
2019-12-05Auto merge of #66952 - 0dvictor:print, r=rkruppebors-2/+1
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-04Migrate to LLVM{Get,Set}ValueName2Josh Stone-5/+24
The deprecated `LLVM{Get,Set}ValueName` only work with NUL-terminated strings, but the `2` variants use explicit lengths, which fits better with Rust strings and slices. We now use these in new helper functions `llvm::{get,set}_value_name` that convert to/from `&[u8]`.
2019-12-03Change linker for x86_64-fortanix-unknown-sgx to rust-lldParth Sane-1/+2
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-02Use Module::print() instead of a PrintModulePassVictor Ding-2/+1
llvm::Module has a print() method. It is unnecessary to create a pass just for the purpose of printing LLVM IR.
2019-11-29Use LLVMAddAnalysisPasses instead of Rust's wrapperVictor Ding-1/+2
LLVM exposes a C API `LLVMAddAnalysisPasses` and hence Rust's own wrapper `LLVMRustAddAnalysisPasses` is not needed anymore.
2019-11-22Move sanitizer passes creation from ssa to llvmTomasz Miąsko-0/+5
2019-11-13Revert "Auto merge of #65134 - ↵Robin Kruppe-1/+0
davidtwco:issue-19834-improper-ctypes-in-extern-C-fn, r=rkruppe" This reverts commit 3f0e16473de5ec010f44290a8c3ea1d90e0ad7a2, reversing changes made to 61a551b4939ec1d5596e585351038b8fbd0124ba.
2019-11-06Auto merge of #65134 - davidtwco:issue-19834-improper-ctypes-in-extern-C-fn, ↵bors-0/+1
r=rkruppe improper_ctypes: `extern "C"` fns cc #19834. Fixes #65867. This pull request implements the change [described in this comment](https://github.com/rust-lang/rust/issues/19834#issuecomment-466671572). cc @rkruppe @varkor @shepmaster
2019-11-06Rollup merge of #66062 - smaeul:patch/pic-level, r=estebankMazdak Farrokhzad-0/+1
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-05Rollup merge of #65953 - keystone-enclave:llvm_abiname, r=alexcrichtonPietro Albini-0/+1
Allow specifying LLVM's MCTargetOptions::ABIName in target specification files This addresses #65024, as it allows RISC-V target specification files to set `"llvm-abiname": "lp64d"`. Other languages (read: C) usually expose this codegen parameter under a compiler argument like `-mabi=<XYZ>`.
2019-11-05improper_ctypes: `extern "C"` fnsDavid Wood-0/+1
2019-11-05Rollup merge of #65720 - icefoxen:LLVMgetInstructionCount, r=rkruppePietro Albini-0/+1
Add FFI bindings for LLVM's Module::getInstructionCount() Just to make it usable for profiling and such inside rustc itself. It was vaguely useful in https://wiki.alopex.li/WhereRustcSpendsItsTime and I figured I might as well upstream it; I may or may not ever get around to doing more with it (hopefully I will), but it may be useful for others.
2019-11-03Configure LLVM module PIC levelSamuel Holland-0/+1
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-02Add FFI bindings for Module::getInstructionCount()Simon Heath-0/+1
Just to make it useable for profiling and such inside rustc itself. It was vaguely useful in https://wiki.alopex.li/WhereRustcSpendsItsTime and I figured I might as well upstream it; I may or may not ever get around to doing more with it (hopefully I will), but it may be useful for others.
2019-10-29Allow specifying key "llvm-abiname" in target specificationGui Andrade-0/+1
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-21Remove many unnecessary trait derivations.Nicholas Nethercote-2/+1
2019-10-13Improve type safetybjorn3-3/+4
2019-09-06rustc_codegen_llvm: give names to non-alloca variable values.Eduard-Mihai Burtescu-0/+2
2019-08-01Use Rust integer types instead of libc's fixed-width typesgnzlbg-2/+2
2019-07-28Remove lint annotations in specific crates that are already enforced by ↵Vadim Petrochenkov-3/+3
rustbuild Remove some random unnecessary lint `allow`s
2019-07-20Remove vector fadd/fmul reduction workaroundsNikita Popov-2/+0
The bugs that this was working around have been fixed in LLVM 9.
2019-07-15Don't add extra passes into the function pass managerNikita Popov-0/+3
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-10Rollup merge of #62474 - nikic:update-llvm, r=alexcrichtonMazdak Farrokhzad-0/+3
Prepare for LLVM 9 update Main changes: * In preparation for opaque pointer types, the `byval` attribute now takes a type. As such, the argument type needs to be threaded through to the function/callsite attribute application logic. * On ARM the `+fp-only-sp` and `+d16` features have become `-fp64` and `-d32`. I've switched the target definitions to use the new names, but also added bidirectional emulation so either can be used on any LLVM version for backwards compatibility. * The datalayout can now specify function pointer alignment. In particular on ARM `Fi8` is specified, which means that function pointer alignment is independent of function alignment. I've added this to our datalayouts to match LLVM (which is something we check) and strip the fnptr alignment for older LLVM versions. * The fmul/fadd reductions now always respect the accumulator (including for unordered reductions), so we should pass the identity instead of undef. Open issues: * https://reviews.llvm.org/D62106 causes linker errors with ld.bdf due to https://sourceware.org/bugzilla/show_bug.cgi?id=24784. To avoid this I've enabled `RelaxELFRelocations`, which results in a GOTPCRELX relocation for `__tls_get_addr` and avoids the issue. However, this is likely not acceptable because relax relocations are not supported by older linker versions. We may need an LLVM option to keep using PLT for `__tls_get_addr` despite `RtLibUseGOT`. The corresponding llvm-project PR is https://github.com/rust-lang/llvm-project/pull/19. r? @ghost