about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm
AgeCommit message (Collapse)AuthorLines
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-42/+42
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-8/+15
2023-07-10Reuse LLVMConstInBoundsGEP2Jubilee Young-3/+3
We have had LLVM 14 as our minimum for a bit now.
2023-07-06Auto merge of #113377 - BoxyUwU:move_ty_ctors_to_ty, r=compiler-errorsbors-28/+39
Move `TyCtxt::mk_x` to `Ty::new_x` where applicable Part of rust-lang/compiler-team#616 turns out there's a lot of places we construct `Ty` this is a ridiculously huge PR :S r? `@oli-obk`
2023-07-06Rollup merge of #113334 - fmease:revert-lexing-c-str-lits, r=compiler-errorsfee1-dead-52/+64
Revert the lexing of `c"…"` string literals Fixes \[after beta-backport\] #113235. Further progress is tracked in #113333. This PR *manually* reverts parts of #108801 (since a git-revert would've been too coarse-grained & messy) and git-reverts #111647. CC `@fee1-dead` (#108801) `@klensy` (#111647) r? `@compiler-errors` `@rustbot` label F-c_str_literals beta-nominated
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 `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-28/+39
2023-07-05Revert "use new c literals instead of cstr! macro"León Orell Valerian Liehr-52/+64
This reverts commit a17561ffc90c900cb7d0e96b00c6381244764ef7.
2023-07-05Move `coverageinfo::ffi` and `coverageinfo::map` out of SSAZalathar-3/+442
2023-07-05Remove trait `CoverageInfoMethods`, since non-LLVM backends don't need itZalathar-5/+11
These methods are only ever called from within `rustc_codegen_llvm`, so they can just be declared there as well.
2023-07-05Narrow trait `CoverageInfoBuilderMethods` down to just one methodZalathar-2/+57
This effectively inlines most of `FunctionCx::codegen_coverage` into the LLVM implementation of `CoverageInfoBuilderMethods`.
2023-07-02Auto merge of #113040 - Kobzol:llvm-remark-streamer, r=tmiaskobors-5/+47
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-5/+47
2023-06-30llvm ffi: Expose `CallInst->setTailCallKind`Maybe Waffle-0/+11
2023-06-30Auto merge of #109524 - bzEq:aix-embed-llvmbc, r=nagisabors-2/+19
Support embedding LLVM bitcode on AIX
2023-06-30Auto merge of #113162 - matthiaskrgr:rollup-fct3wj7, r=matthiaskrgrbors-8/+102
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
2023-06-30Auto merge of #113116 - nnethercote:codegen-opts, r=oli-obkbors-17/+25
A mish-mash of micro-optimizations These were aimed at speeding up LLVM codegen, but ended up affecting other places as well. r? `@bjorn3`
2023-06-29Rollup merge of #111322 - mirkootter:master, r=davidtwcoMatthias Krüger-8/+102
Support for native WASM exceptions ### Motivation Currently, rustc does not support native WASM exceptions. It does support JavaScript based exceptions for the wasm32-emscripten-target, but this requires back&forth with javascript for many calls, which is very slow. Native wasm support for exceptions is quite common: Clang+LLVM implemented them years ago, and all major browsers support them by now. They enable zero-cost exceptions, at least with regard to runtime-performance-cost. They may increase startup-time and code size, though. ### Important: This PR does not change default behaviour Exceptions usually add a lot of code in form of unwinding blocks, increasing the binary size. Most users probably do not want that, especially which regard to web development. Therefore, wasm exceptions play a similar role as WASM-threads: rustc should support them, like clang does, but users who want to use it have to use some command-line magic like rustflags to opt in. ### What does this PR do? As stated above, the default behaviour is not changed. It is already possible to opt-in into wasm exceptions using the command line. Unfortunately, the LLVM IR is invalid and the LLVM backend crashes. ``` rustc <sourcefile> --target wasm32-unknown-unknown -C panic=unwind -C llvm-args=-wasm-enable-eh -C target-feature=+exception-handling ``` As it turns out, LLVM is quite picky when it comes to IR for exception handling. If the IR does not look exactly like it should, some LLVM-assertions fail and the code generation crashes. This PR adds the necessary modifications to the code generator to make it work. It also adds `exception-handling` as a wasm target feature. ### What this PR does not / what is missing This PR is not a full fledges solution. It is the first step. A few parts are still missing; however, it is already useable (see next section). Currently missing: * The std library has to be adapted. Currently, only [no_std] crates work * Usually, nested exceptions abort the program (i.e. a panic during the cleanup of another panic). This is currently not done yet. - Currently, code inside cleanup handlers does not unwind - To fix this requires a little more work: The code generator currently maintains a single terminate block per function for this. Unfortunately, WASM requires funclet based exception handling. Therefore, we need to create a terminate block per funclet. This is probably not a big problem, but I want to keep this PR simple. ### How to use the compiler given this PR? This PR does not add any command line flags or features. It uses those which are already there. To compile with exceptions enabled, you need * to set the panic strategy to unwind, i.e. `-C panic=unwind` * to enable the exception-handling target feature, i.e. `-C target-feature=+exception-handling` * to tell LLVM about the exception handling, i.e. `-C llvm-args=-wasm-enable-eh` Since the standard library has not been adapted, you can only use it in [no_std] crates as of now. The intrinsic `core::intrinsics::r#try` works. To throw exceptions, you need the ```@llvm.wasm.throw``` intrinsic. I created a sample application which works for me: https://github.com/mirkootter/rust-wasm-demos This example can be run at https://webassembly.sh
2023-06-29Simplify the `bundles` vectors.Nicholas Nethercote-6/+6
After the last commit, they contain `Option<&OperandBundleDef<'a>>` but the values are always `Some(_)`. This commit removes the needless `Option` wrapper. This also simplifies the type signatures of `LLVMRustBuild{Invoke,Call}`, which were relying on the fact that the represention of `Option<&T>` is the same as `&T` for non-`None` values.
2023-06-29Use `SmallVec` for the `bundles` vectors.Nicholas Nethercote-6/+15
They never have a length of more than two. So this commit changes them to `SmallVec<[_; 2]>`. Also, we possibly push `None` values and then filter those `None` values out again with `retain`. So this commit removes the `retain` and instead only pushes the values if they are `Some(_)`.
2023-06-29Set capacity of the string passed to `push_item_name`.Nicholas Nethercote-2/+2
Other callsites already do this, but these two were missed. This avoids some allocations.
2023-06-29Avoid an unnecessary use of `SmallStr`.Nicholas Nethercote-3/+2
I don't know why `SmallStr` was used here; some ad hoc profiling showed this code is not that hot, the string is usually empty, and when it's not empty it's usually very short. However, the use of a `SmallStr<1024>` does result in 1024 byte `memcpy` call on each execution, which shows up when I do `memcpy` profiling. So using a normal string makes the code both simpler and very slightly faster.
2023-06-29Replace a `lookup_debug_loc` call.Nicholas Nethercote-3/+3
`lookup_debug_loc` finds a file, line, and column, which requires two binary searches. But this call site only needs the file. This commit replaces the call with `lookup_source_file`, which does a single binary search.
2023-06-29Avoid unnecessary line lookup.Nicholas Nethercote-1/+1
`lookup_debug_loc` calls `SourceMap::lookup_line`, which does a binary search over the files, and then a binary search over the lines within the found file. It then calls `SourceFile::line_begin_pos`, which redoes the binary search over the lines within the found file. This commit removes the second binary search over the lines, instead getting the line starting pos directly using the result of the first binary search over the lines. (And likewise for `get_span_loc`, in the cranelift backend.)
2023-06-27Auto merge of #112516 - erikdesjardins:loop, r=davidtwcobors-15/+7
cg_llvm: use index-based loop in write_operand_repeatedly This should be easier for LLVM to analyze. Fixes #111603 This needs a perf run. [cc](https://github.com/rust-lang/rust/issues/111603#issuecomment-1567531178) `@caojoshua`
2023-06-19Store generator field names in GeneratorLayout.Camille GILLOT-9/+5
2023-06-19Make closure_saved_names_of_captured_variables a query.Camille GILLOT-4/+5
2023-06-16Rollup merge of #112474 - ldm0:ldm_enum_debuginfo_128_support, r=compiler-errorsMichael Goulet-8/+6
Support 128-bit enum variant in debuginfo codegen fixes #111600
2023-06-14Introduce a minimum CGU size in non-incremental builds.Nicholas Nethercote-1/+1
Because tiny CGUs make compilation less efficient *and* result in worse generated code. We don't do this when the number of CGUs is explicitly given, because there are times when the requested number is very important, as described in some comments within the commit. So the commit also introduces a `CodegenUnits` type that distinguishes between default values and user-specified values. This change has a roughly neutral effect on walltimes across the rustc-perf benchmarks; there are some speedups and some slowdowns. But it has significant wins for most other metrics on numerous benchmarks, including instruction counts, cycles, binary size, and max-rss. It also reduces parallelism, which is good for reducing jobserver competition when multiple rustc processes are running at the same time. It's smaller benchmarks that benefit the most; larger benchmarks already have CGUs that are all larger than the minimum size. Here are some example before/after CGU sizes for opt builds. - html5ever - CGUs: 16, mean size: 1196.1, sizes: [3908, 2992, 1706, 1652, 1572, 1136, 1045, 948, 946, 938, 579, 471, 443, 327, 286, 189] - CGUs: 4, mean size: 4396.0, sizes: [6706, 3908, 3490, 3480] - libc - CGUs: 12, mean size: 35.3, sizes: [163, 93, 58, 53, 37, 8, 2 (x6)] - CGUs: 1, mean size: 424.0, sizes: [424] - tt-muncher - CGUs: 5, mean size: 1819.4, sizes: [8508, 350, 198, 34, 7] - CGUs: 1, mean size: 9075.0, sizes: [9075] Note that CGUs of size 100,000+ aren't unusual in larger programs.
2023-06-11cg_llvm: use index-based loop in write_operand_repeatedlyErik Desjardins-15/+7
This is easier for LLVM to analyze.
2023-06-10Support 128-bit enum variant in debuginfo codegenDonoughLiu-8/+6
2023-06-08Auto merge of #110040 - ndrewxie:issue-84447-partial-1, r=lcnr,michaelwoeristerbors-2/+2
Removed use of iteration through a HashMap/HashSet in rustc_incremental and replaced with IndexMap/IndexSet This allows for the `#[allow(rustc::potential_query_instability)]` in rustc_incremental to be removed, moving towards fixing #84447 (although a LOT more modules have to be changed to fully resolve it). Only HashMaps/HashSets that are being iterated through have been modified (although many structs and traits outside of rustc_incremental had to be modified as well, as they had fields/methods that involved a HashMap/HashSet that would be iterated through) I'm making a PR for just 1 module changed to test for performance regressions and such, for future changes I'll either edit this PR to reflect additional modules being converted, or batch multiple modules of changes together and make a PR for each group of modules.
2023-06-08Use `c`-prefixed stringKai Luo-6/+6
2023-06-08Support embedding bitcode on AIXKai Luo-2/+19
2023-06-07fix comment (review change)Jan-Mirko Otter-1/+1
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2023-06-07add comment regarding `__gxx_wasm_personality_v0`Jan-Mirko Otter-0/+4
2023-06-07wasm exception handlingJan-Mirko Otter-8/+89
2023-06-07add wasm eh intrinsicsJan-Mirko Otter-0/+9
2023-06-04Removed use of iteration through a HashMap/HashSet in rustc_incremental and ↵Andrew Xie-2/+2
replaced with IndexMap/IndexSet
2023-06-04Use `load`-`store` instead of `memcpy` for short integer arraysScott McMurray-0/+36
2023-06-02Rollup merge of #111647 - klensy:cstr, r=oli-obkMatthias Krüger-60/+48
use c literals in compiler and library Use c literals #108801 in compiler and library currently blocked on: * <strike>rustfmt: don't know how to format c literals</strike> nope, nightly one works. * <strike>bootstrap</strike> r? `@ghost` `@rustbot` blocked
2023-06-01Use translatable diagnostics in `rustc_const_eval`Deadbeef-23/+33
2023-05-31Add a distinct `OperandValue::ZeroSized` variant for ZSTsScott McMurray-3/+2
These tend to have special handling in a bunch of places anyway, so the variant helps remember that. And I think it's easier to grok than non-Scalar Aggregates sometimes being `Immediates` (like I got wrong and caused 109992). As a minor bonus, it means we don't need to generate poison LLVM values for them to pass around in `OperandValue::Immediate`s.
2023-05-31use new c literals instead of cstr! macroklensy-60/+48
2023-05-30Auto merge of #112102 - Nilstrieb:rollup-ivu1hmc, r=Nilstriebbors-1/+1
Rollup of 7 pull requests Successful merges: - #107916 (fix comment on Allocator trait) - #111543 (Uplift `clippy::invalid_utf8_in_unchecked` lint) - #111872 (fix: dedup `static_candidates` before report) - #111955 (bootstrap: Various Step refactors) - #112060 (`EarlyBinder::new` -> `EarlyBinder::bind`) - #112064 (Migrate GUI colors test to original CSS color format) - #112100 (Don't typecheck recovered method call from suggestion) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-30Auto merge of #111768 - oli-obk:pair_const_llvm, r=cjgillotbors-32/+17
Optimize scalar and scalar pair representations loaded from ByRef in llvm in https://github.com/rust-lang/rust/pull/105653 I noticed that we were generating suboptimal LLVM IR if we had a `ConstValue::ByRef` that could be represented by a `ScalarPair`. Before https://github.com/rust-lang/rust/pull/105653 this is probably rare, but after it, every slice will go down this suboptimal code path that requires LLVM to untangle a bunch of indirections and translate static allocations that are only used once to read a scalar pair from.
2023-05-29EarlyBinder::new -> EarlyBinder::bindlcnr-1/+1
2023-05-28Replace EarlyBinder(x) with EarlyBinder::new(x)Kyle Matsuda-1/+1
2023-05-26Add SafeStack support to rustcWesley Wiser-0/+4
Adds support for LLVM [SafeStack] which provides backward edge control flow protection by separating the stack into two parts: data which is only accessed in provable safe ways is allocated on the normal stack (the "safe stack") and all other data is placed in a separate allocation (the "unsafe stack"). SafeStack support is enabled by passing `-Zsanitizer=safestack`. [SafeStack]: https://clang.llvm.org/docs/SafeStack.html
2023-05-26Stop creating intermediate places just to immediate convert them to operandsOli Scherer-32/+17