about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/llvm
AgeCommit message (Collapse)AuthorLines
2024-03-03Auto merge of #121665 - erikdesjardins:ptradd, r=nikicbors-7/+0
Always generate GEP i8 / ptradd for struct offsets This implements #98615, and goes a bit further to remove `struct_gep` entirely. Upstream LLVM is in the beginning stages of [migrating to `ptradd`](https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699). LLVM 19 will [canonicalize](https://github.com/llvm/llvm-project/pull/68882) all constant-offset GEPs to i8, which has roughly the same effect as this change. Fixes #121719. Split out from #121577. r? `@nikic`
2024-03-01Add initial support for DataFlowSanitizerRamon de C Valle-0/+3
Adds initial support for DataFlowSanitizer to the Rust compiler. It currently supports `-Zsanitizer-dataflow-abilist`. Additional options for it can be passed to LLVM command line argument processor via LLVM arguments using `llvm-args` codegen option (e.g., `-Cllvm-args=-dfsan-combine-pointer-labels-on-load=false`).
2024-02-28Add `f16` and `f128` to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`Trevor Gross-0/+2
Make changes necessary to support these types in the compiler.
2024-02-26remove struct_gep, use manual layout calculations for va_argErik Desjardins-7/+0
2024-02-26Rollup merge of #121389 - klensy:llvm-warn-fix, r=nikicMatthias Krüger-3/+3
llvm-wrapper: fix few warnings Two fixes: first one is simple unsigned -> uint64_t, but how second one is more subtile, see commit description.
2024-02-21make simd_reduce_{mul,add}_unordered use only the 'reassoc' flag, not all ↵Ralf Jung-0/+1
fast-math flags
2024-02-21llvm-wrapper: fix warning C4244klensy-3/+3
llvm-wrapper/RustWrapper.cpp(1234): warning C4244: '=': conversion from 'uint64_t' to 'unsigned int', possible loss of data nice consistency: uint64_t https://github.com/llvm/llvm-project/blob/6009708b4367171ccdbf4b5905cb6a803753fe18/llvm/include/llvm/IR/DiagnosticInfo.h#L172 but unsigned https://github.com/llvm/llvm-project/blob/6009708b4367171ccdbf4b5905cb6a803753fe18/llvm/include/llvm/IR/DiagnosticInfo.h#L1091
2024-02-20Add "algebraic" versions of the fast-math intrinsicsBen Kimock-0/+1
2024-02-06Rollup merge of #120502 - clubby789:remove-ffi-returns-twice, r=compiler-errorsMatthias Krüger-1/+0
Remove `ffi_returns_twice` feature The [tracking issue](https://github.com/rust-lang/rust/issues/58314) and [RFC](https://github.com/rust-lang/rfcs/pull/2633) have been closed for a couple of years. There is also an attribute gate in R-A which should be removed if this lands.
2024-01-30Remove `ffi_returns_twice` featureclubby789-1/+0
2024-01-30Remove the `abi_amdgpu_kernel` featureclubby789-1/+0
2024-01-12Revert "Auto merge of #113923 - DianQK:restore-no-builtins-lto, r=pnkfelix"DianQK-1/+7
This reverts commit 8c2b57721728233e074db69d93517614de338055, reversing changes made to 9cf18e98f82d85fa41141391d54485b8747da46f.
2023-12-30Update to bitflags 2 in the compilerNilstrieb-2/+2
This involves lots of breaking changes. There are two big changes that force changes. The first is that the bitflag types now don't automatically implement normal derive traits, so we need to derive them manually. Additionally, bitflags now have a hidden inner type by default, which breaks our custom derives. The bitflags docs recommend using the impl form in these cases, which I did.
2023-12-11fix: stop emitting `.debug_pubnames` and `.debug_pubtypes`Weihang Lo-1/+11
`.debug_pubnames` and `.debug_pubtypes` are poorly designed and people seldom use them. However, they take a considerable portion of size in the final binary. This tells LLVM stop emitting those sections on DWARFv4 or lower. DWARFv5 use `.debug_names` which is more concise in size and performant for name lookup.
2023-12-07Add emulated TLS supportquininer-1/+1
Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls.
2023-12-01Auto merge of #113923 - DianQK:restore-no-builtins-lto, r=pnkfelixbors-7/+1
Restore `#![no_builtins]` crates participation in LTO. After #113716, we can make `#![no_builtins]` crates participate in LTO again. `#![no_builtins]` with LTO does not result in undefined references to the error. I believe this type of issue won't happen again. Fixes #72140. Fixes #112245. Fixes #110606. Fixes #105734. Fixes #96486. Fixes #108853. Fixes #108893. Fixes #78744. Fixes #91158. Fixes https://github.com/rust-lang/cargo/issues/10118. Fixes https://github.com/rust-lang/compiler-builtins/issues/347. The `nightly-2023-07-20` version does not always reproduce problems due to changes in compiler-builtins, core, and user code. That's why this issue recurs and disappears. Some issues were not tested due to the difficulty of reproducing them. r? pnkfelix cc `@bjorn3` `@japaric` `@alexcrichton` `@Amanieu`
2023-11-30Add `-Zfunction-return={keep,thunk-extern}` optionMiguel Ojeda-0/+1
This is intended to be used for Linux kernel RETHUNK builds. With this commit (optionally backported to Rust 1.73.0), plus a patched Linux kernel to pass the flag, I get a RETHUNK build with Rust enabled that is `objtool`-warning-free and is able to boot in QEMU and load a sample Rust kernel module. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-11-23remove unused pub fnklensy-7/+0
2023-11-21Tighten up linkage settings for LLVM bindingsBen Kimock-173/+199
2023-11-03consts: remove dead code around `i1` constant valuesAugie Fackler-1/+0
`LLVMConstZext` recently got deleted, and it turns out (thanks to @nikic for knowing!) that this is dead code. Tests all pass for me without this logic, and per nikic: > We always generate constants in "relocatable bag of bytes" > representation, so you're never going to get a plain bool. So this should be a safe thing to do. r? @nikic @rustbot label: +llvm-main
2023-10-15Removes the useless DisableSimplifyLibCalls parameter.DianQK-7/+1
After applying no_builtins to the function attributes, we can remove the DisableSimplifyLibCalls parameter.
2023-09-25Pass name of object file to LLVM so it can correctly emit S_OBJNAMEFlorian Schmiderer-0/+1
2023-09-24Add OwnedTargetMachine to manage llvm:TargetMachine. Uses pointersFlorian Schmiderer-2/+4
instead of &'static mut and provides safe interface to create/dispose it.
2023-09-08debuginfo: add compiler option to allow compressed debuginfo sectionsAugie Fackler-0/+5
LLVM already supports emitting compressed debuginfo. In debuginfo=full builds, the debug section is often a large amount of data, and it typically compresses very well (3x is not unreasonable.) We add a new knob to allow debuginfo to be compressed when the matching LLVM functionality is present. Like clang, if a known-but-disabled compression mechanism is requested, we disable compression and emit uncompressed debuginfo sections. The API is different enough on older LLVMs we just pretend the support is missing on LLVM older than 16.
2023-09-08lto: load bitcode sections by nameAugie Fackler-0/+6
Upstream change llvm/llvm-project@6b539f5eb8ef1d3a3c87873caa2dbd5147e1adbd changed `isSectionBitcode` works and it now only respects `.llvm.lto` sections instead of also `.llvmbc`, which it says was never intended to be used for LTO. We instead load sections by name, and sniff for raw bitcode by hand. r? @nikic @rustbot label: +llvm-main
2023-09-08Add missing Debuginfo to PDB debug file on windows.Florian Schmiderer-0/+3
Set Arg0 and CommandLineArgs in MCTargetoptions so LLVM outputs correct CL and CMD in LF_DEBUGINFO instead of empty/invalid values.
2023-08-26Use `preserve_mostcc` for `extern "rust-cold"`Scott McMurray-0/+5
As experimentation in 115242 has shown looks better than `coldcc`. And *don't* use a different convention for cold on Windows, because that actually ends up making things worse. cc tracking issue 97544
2023-08-10Auto merge of #114005 - Zalathar:no-cstr, r=jackh726bors-1/+7
coverage: Don't convert filename/symbol strings to `CString` for FFI LLVM APIs are usually perfectly happy to accept pointer/length strings, as long as we supply a suitable length value when creating a `StringRef` or `std::string`. This lets us avoid quite a few intermediate `CString` copies during coverage codegen. It also lets us use an `IndexSet<Symbol>` (instead of an `IndexSet<CString>`) when building the deduplicated filename table.
2023-08-08Rollup merge of #113593 - rcvalle:rust-cfi-fix-90546, r=wesleywiserMatthias Krüger-0/+4
CFI: Fix error compiling core with LLVM CFI enabled Fix #90546 by filtering out global value function pointer types from the type tests, and adding the LowerTypeTests pass to the rustc LTO optimization pipelines.
2023-08-08Only enable hotness information when PGO is availableJakub Beránek-0/+1
2023-08-07CFI: Fix error compiling core with LLVM CFI enabledRamon de C Valle-0/+4
Fix #90546 by filtering out global value function pointer types from the type tests, and adding the LowerTypeTests pass to the rustc LTO optimization pipelines.
2023-08-04coverage: Don't convert symbol names to `CString` for FFIZalathar-1/+5
2023-08-04coverage: Don't convert filenames to `CString` for FFIZalathar-0/+2
2023-08-02coverage: Consolidate FFI types into one moduleZalathar-202/+2
Coverage FFI types were historically split across two modules, because some of them were needed by code in `rustc_codegen_ssa`. Now that all of the coverage codegen code has been moved into `rustc_codegen_llvm` (#113355), it's possible to move all of the FFI types into a single module, making it easier to see all of them at once.
2023-08-01Auto merge of #113339 - lqd:respect-filters, r=tmiaskobors-1/+1
Filter out short-lived LLVM diagnostics before they reach the rustc handler During profiling I saw remark passes being unconditionally enabled: for example `Machine Optimization Remark Emitter`. The diagnostic remarks enabled by default are [from missed optimizations and opt analyses](https://github.com/rust-lang/rust/pull/113339#discussion_r1259480303). They are created by LLVM, passed to the diagnostic handler on the C++ side, emitted to rust, where they are unpacked, C++ strings are converted to rust, etc. Then they are discarded in the vast majority of the time (i.e. unless some kind of `-Cremark` has enabled some of these passes' output to be printed). These unneeded allocations are very short-lived, basically only lasting between the LLVM pass emitting them and the rust handler where they are discarded. So it doesn't hugely impact max-rss, and is only a slight reduction in instruction count (cachegrind reports a reduction between 0.3% and 0.5%) _on linux_. It's possible that targets without `jemalloc` or with a worse allocator, may optimize these less. It is however significant in the aggregate, looking at the total number of allocated bytes: - it's the biggest source of allocations according to dhat, on the benchmarks I've tried e.g. `syn` or `cargo` - allocations on `syn` are reduced by 440MB, 17% (from 2440722647 bytes total, to 2030461328 bytes) - allocations on `cargo` are reduced by 6.6GB, 19% (from 35371886402 bytes total, to 28723987743 bytes) Some of these diagnostics objects [are allocated in LLVM](https://github.com/rust-lang/rust/pull/113339#discussion_r1252387484) *before* they're emitted to our diagnostic handler, where they'll be filtered out. So we could remove those in the future, but that will require changing a few LLVM call-sites upstream, so I left a FIXME.
2023-07-29cg_llvm: remove pointee types and pointercast/bitcast-of-ptrErik Desjardins-1/+1
2023-07-21Rollup merge of #113780 - dtolnay:printkindpath, r=b-naberMatthias Krüger-1/+6
Support `--print KIND=PATH` command line syntax As is already done for `--emit KIND=PATH` and `-L KIND=PATH`. In the discussion of #110785, it was pointed out that `--print KIND=PATH` is nicer than trying to apply the single global `-o` path to `--print`'s output, because in general there can be multiple print requests within a single rustc invocation, and anyway `-o` would already be used for a different meaning in the case of `link-args` and `native-static-libs`. I am interested in using `--print cfg=PATH` in Buck2. Currently Buck2 works around the lack of support for `--print KIND=PATH` by [indirecting through a Python wrapper script](https://github.com/facebook/buck2/blob/d43cf3a51a31f00be2c2248e78271b0fef0452b4/prelude/rust/tools/get_rustc_cfg.py) to redirect rustc's stdout into the location dictated by the build system. From skimming Cargo's usages of `--print`, it definitely seems like it would benefit from `--print KIND=PATH` too. Currently it is working around the lack of this by inserting `--crate-name=___ --print=crate-name` so that it can look for a line containing `___` as a delimiter between the 2 other `--print` informations it actually cares about. This is commented as a "HACK" and "abuse". https://github.com/rust-lang/cargo/blob/31eda6f7c360d9911f853b3014e057db61238f3e/src/cargo/core/compiler/build_context/target_info.rs#L242 (FYI `@weihanglo` as you dealt with this recently in https://github.com/rust-lang/cargo/pull/11633.) Mentioning reviewers active in #110785: `@fee1-dead` `@jyn514` `@bjorn3`
2023-07-20Implement printing to file in PassWrapperDavid Tolnay-1/+6
2023-07-20address feedback from nikic and oli-obk ↵khei4-2/+2
https://github.com/rust-lang/rust/pull/113723/files use slice memcpy rather than strcpy and write it on stdout use println on failure Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2023-07-17print on rustc_codegen_llvm and rename malloc and cpy c_charkhei4-2/+2
2023-07-16rustc_llvm: Add a `-Z print-llvm-stats` option to expose LLVM statistics.Patrick Walton-0/+3
LLVM has a neat [statistics] feature that tracks how often optimizations kick in. It's very handy for optimization work. Since we expose the LLVM pass timings, I thought it made sense to expose the LLVM statistics too. [statistics]: https://llvm.org/docs/ProgrammersManual.html#the-statistic-class-stats-option
2023-07-14make opt diagnostic kinds printableRémy Rakic-1/+1
2023-07-13Remove `LLVMRustCoverageHashCString`Zalathar-1/+0
Coverage has two FFI functions for computing the hash of a byte string. One takes a ptr/len pair, and the other takes a NUL-terminated C string. But on closer inspection, the C string version is unnecessary. The calling-side code converts a Rust `&str` into a C string, and the C++ code then immediately turns it back into a ptr/len string before actually hashing it.
2023-07-10Reuse LLVMConstInBoundsGEP2Jubilee Young-1/+1
We have had LLVM 14 as our minimum for a bit now.
2023-07-06Rollup merge of #112791 - WaffleLapkin:wag_the_llvm, r=cuviperfee1-dead-0/+11
llvm ffi: Expose `CallInst->setTailCallKind` This is needed for the explicit tail calls experiment.
2023-07-05Move `coverageinfo::ffi` and `coverageinfo::map` out of SSAZalathar-1/+1
2023-07-02Auto merge of #113040 - Kobzol:llvm-remark-streamer, r=tmiaskobors-0/+1
Add `-Zremark-dir` unstable flag to write LLVM optimization remarks to YAML This PR adds an option for `rustc` to emit LLVM optimization remarks to a set of YAML files, which can then be digested by existing tools, like https://github.com/OfekShilon/optview2. When `-Cremark-dir` is passed, and remarks are enabled (`-Cremark=all`), the remarks will be now written to the specified directory, **instead** of being printed to standard error output. The files are named based on the CGU from which they are being generated. Currently, the remarks are written using the LLVM streaming machinery, directly in the diagnostics handler. It seemed easier than going back to Rust and then form there back to C++ to use the streamer from the diagnostics handler. But there are many ways to implement this, of course, so I'm open to suggestions :) I included some comments with questions into the code. Also, I'm not sure how to test this. r? `@tmiasko`
2023-07-02Add `rustc` option to output LLVM optimization remarks to YAML filesJakub Beránek-0/+1
2023-06-30llvm ffi: Expose `CallInst->setTailCallKind`Maybe Waffle-0/+11
2023-06-30Auto merge of #113162 - matthiaskrgr:rollup-fct3wj7, r=matthiaskrgrbors-0/+1
Rollup of 7 pull requests Successful merges: - #111322 (Support for native WASM exceptions) - #112086 (resolve: Remove artificial import ambiguity errors) - #112234 (refactor `tool_doc!`) - #112300 (Convert `run-make/coverage-reports` tests to use a custom compiletest mode) - #112795 (Migrate some rustc_builtin_macros to SessionDiagnostic) - #113144 (Make the `Elaboratable` trait take clauses) - #113161 (Fix type privacy lints error message) r? `@ghost` `@rustbot` modify labels: rollup