about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
AgeCommit message (Collapse)AuthorLines
2024-08-29Rollup merge of #128970 - DianQK:lint-llvm-ir, r=nikicGuillaume Gomez-1/+8
Add `-Zlint-llvm-ir` This flag is similar to `-Zverify-llvm-ir` and allows us to lint the generated IR. r? compiler
2024-08-29Add `-Zlint-llvm-ir`DianQK-1/+8
2024-08-21llvm-wrapper: adapt for LLVM 20 API changesKrasimir Georgiev-0/+11
No functional changes intended. Adapts llvm-wrapper for the LLVM commits https://github.com/llvm/llvm-project/commit/0f22d47a7a1f70ec77ea8ccdf08a6487827937db and https://github.com/llvm/llvm-project/commit/d6d8243dcd4ea768549904036ed31b8e59e14c73.
2024-07-02Rename the `asm-comments` compiler flag to `verbose-asm`Trevor Gross-2/+2
Since this codegen flag now only controls LLVM-generated comments rather than all assembly comments, make the name more accurate (and also match Clang).
2024-07-02Always preserve user-written comments in assemblyTrevor Gross-1/+2
2024-06-26Format C++ files in `llvm-wrapper`DianQK-243/+227
2024-05-29Teach rustc about the Xtensa arch.Scott Mabin-0/+7
2024-05-23thinlto: only build summary file if neededAugie Fackler-2/+5
If we don't do this, some versions of LLVM (at least 17, experimentally) will double-emit some error messages, which is how I noticed this. Given that it seems to be costing some extra work, let's only request the summary bitcode production if we'll actually bother writing it down, otherwise skip it.
2024-05-22rustc_codegen_llvm: add support for writing summary bitcodeAugie Fackler-1/+13
Typical uses of ThinLTO don't have any use for this as a standalone file, but distributed ThinLTO uses this to make the linker phase more efficient. With clang you'd do something like `clang -flto=thin -fthin-link-bitcode=foo.indexing.o -c foo.c` and then get both foo.o (full of bitcode) and foo.indexing.o (just the summary or index part of the bitcode). That's then usable by a two-stage linking process that's more friendly to distributed build systems like bazel, which is why I'm working on this area. I talked some to @teresajohnson about naming in this area, as things seem to be a little confused between various blog posts and build systems. "bitcode index" and "bitcode summary" tend to be a little too ambiguous, and she tends to use "thin link bitcode" and "minimized bitcode" (which matches the descriptions in LLVM). Since the clang option is thin-link-bitcode, I went with that to try and not add a new spelling in the world. Per @dtolnay, you can work around the lack of this by using `lld --thinlto-index-only` to do the indexing on regular .o files of bitcode, but that is a bit wasteful on actions when we already have all the information in rustc and could just write out the matching minimized bitcode. I didn't test that at all in our infrastructure, because by the time I learned that I already had this patch largely written.
2024-03-17Update the minimum external LLVM to 17Josh Stone-36/+4
2024-03-07PassWrapper: update for llvm/llvm-project@a3319371970bAugie Fackler-0/+16
@rustbot label: +llvm-main
2024-03-05Explicitly assign constructed C++ classesJubilee Young-21/+21
C++ style guides I am aware of recommend specifically preferring = syntax for any classes with fairly obvious constructors[^0] that do not perform any complicated logic in their constructor. I contend that all constructors that the `rustc_llvm` code uses qualify. This has only become more common since C++ 17 guaranteed many cases of copy initialization elision. The other detail is that I tried to ask another contributor with infinitely more C++ experience than me (i.e. any) what this constructor syntax was, and they thought it was a macro. I know of no other language that has adopted this same syntax. As the rustc codebase features many contributors experienced in many other languages, using a less... unique... style has many other benefits in making this code more lucid and maintainable, which is something it direly needs. [^0]: e.g. https://abseil.io/tips/88
2024-03-01Add initial support for DataFlowSanitizerRamon de C Valle-0/+16
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-13Auto merge of #120055 - nikic:llvm-18, r=cuviperbors-4/+4
Update to LLVM 18 LLVM 18 final is planned to be released on Mar 5th. Rust 1.78 is planned to be released on May 2nd. Tested images: dist-x86_64-linux, dist-s390x-linux, dist-aarch64-linux, dist-riscv64-linux, dist-loongarch64-linux, dist-x86_64-freebsd, dist-x86_64-illumos, dist-x86_64-musl, x86_64-linux-integration, test-various, armhf-gnu, i686-msvc, x86_64-msvc, i686-mingw, x86_64-mingw, x86_64-apple-1, x86_64-apple-2, dist-aarch64-apple r? `@ghost`
2024-02-13Use MCSubtargetInfo::getAllProcessorFeatures()Nikita Popov-4/+4
This method is now available in upstream LLVM \o/
2024-02-12PassWrapper: adapt for ↵Augie Fackler-0/+15
llvm/llvm-project@93cdd1b5cfa3735c599949b77e24dbfbe570441a Should be no functional change. @rustbot label: +llvm-main
2024-02-06reviewklensy-6/+2
2024-02-06llvm-wrapper: remove llvm 12 hackklensy-6/+1
effectively reverts https://github.com/rust-lang/rust/commit/9a8acea78355b604dbeb29bc38bd4dbf7bfce95f
2024-01-12Revert "Auto merge of #113923 - DianQK:restore-no-builtins-lto, r=pnkfelix"DianQK-2/+7
This reverts commit 8c2b57721728233e074db69d93517614de338055, reversing changes made to 9cf18e98f82d85fa41141391d54485b8747da46f.
2024-01-05Pass LLVM error message back to pass wrapper.Ao Li-1/+3
2023-12-16Auto merge of #110494 - majaha:noTrapAfterNoreturn, r=nikicbors-0/+8
Use the LLVM option NoTrapAfterNoreturn Use this LLVM option: https://llvm.org/doxygen/classllvm_1_1TargetOptions.html#acd83fce25de1ac9f6c975135a8235c22 when TrapUnreachable is enabled. This prevents codegenning unnecessary double-traps in some situations. See further discussion here: https://github.com/rust-lang/compiler-team/issues/618
2023-12-12llvm-wrapper: adapt for LLVM API changeKrasimir Georgiev-1/+3
LLVM commit https://github.com/llvm/llvm-project/commit/f09cf34d00625e57dea5317a3ac0412c07292148 moved some functions to a different header: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/24416#018c5de6-b9c9-4b22-9473-6070d99dcfa7/233-537
2023-12-11llvm-wrapper: adapt for LLVM API changeKrasimir Georgiev-0/+4
LLVM commit https://github.com/llvm/llvm-project/commit/1d608fc755a3e15d0020f61c9535c9b730ab9dec renamed the pass.
2023-12-07Add emulated TLS supportquininer-7/+3
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/+2
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-27Auto merge of #117947 - Dirbaio:drop-llvm-15, r=cuviperbors-27/+0
Update the minimum external LLVM to 16. With this change, we'll have stable support for LLVM 16 and 17. For reference, the previous increase to LLVM 15 was #114148 [Relevant zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/riscv.20forced-atomics)
2023-11-23remove unused pub fnklensy-26/+0
2023-11-21Update the minimum external LLVM to 16.Dario Nieuwenhuis-27/+0
2023-11-21Tighten up linkage settings for LLVM bindingsBen Kimock-3/+3
2023-11-03Use the LLVM option NoTrapAfterNoreturnMatt Harding-0/+8
Use the LLVM option NoTrapAfterNoreturn: https://llvm.org/doxygen/classllvm_1_1TargetOptions.html#acd83fce25de1ac9f6c975135a8235c22 when TrapUnreachable is enabled. This prevents codegenning unnecessary double-traps in some situations. Also, ensure NoTrapAfterNoreturn is set to false when targeting WebAssembly, as it is known to cause bugs.
2023-10-21Treat extern in compiler-builtins as `used`DianQK-103/+1
We have to preserve the symbols of the built-in functions during LTO.
2023-10-16Add `PreservedSymbols` from LLVM to LTO.DianQK-1/+103
When building with LTO, builtin functions that are defined but whose calls have not been inserted yet, get internalized. We need to prevent these symbols from being internalized at LTO time. Refer to https://reviews.llvm.org/D49434.
2023-10-15Removes the useless DisableSimplifyLibCalls parameter.DianQK-7/+2
After applying no_builtins to the function attributes, we can remove the DisableSimplifyLibCalls parameter.
2023-10-06fix to register analysis pass from llvm pluginEmanuele Vannacci-14/+14
2023-09-25Pass name of object file to LLVM so it can correctly emit S_OBJNAMEFlorian Schmiderer-0/+4
2023-09-15llvm-wrapper: adapt for LLVM API changesKrasimir Georgiev-5/+19
No functional changes intended. Adapts the wrapper for https://github.com/llvm/llvm-project/commit/0a1aa6cda2758b0926a95f87d39ffefb1cb90200. Found by our experimental rust + llvm @ head CI: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/22301#018a9926-a810-4e56-8ac2-e6f30b78f433/253-551
2023-09-09Rollup merge of #115358 - durin42:compress-debuginfo, r=oli-obkMatthias Krüger-0/+11
debuginfo: add compiler option to allow compressed debuginfo sections 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-08Auto merge of #115641 - durin42:llvm-18-fatlto-take-2, r=nikicbors-0/+33
lto: load bitcode sections by name 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. This is an alternative approach to #115136, where we tried the same thing using the `object` crate, but it got too fraught to continue. r? `@nikic` `@rustbot` label: +llvm-main
2023-09-08debuginfo: add compiler option to allow compressed debuginfo sectionsAugie Fackler-0/+11
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/+33
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-08Rollup merge of #115638 - ldm0:ldm/llvm-args-fix, r=nikicGuillaume Gomez-1/+4
`-Cllvm-args` usability improvement fixes: #26338 fixes: #115564 Two problems were found during playing with `-Cllvm-args` 1. When `llvm.link-shared` is set to `false` in `config.toml`, output of `rustc -C llvm-args='--help-list-hidden'` doesn't contain `--emit-dwarf-unwind` and `--emulated-tls`. When it is set to `true`, `rustc -C llvm-args='--help-list-hidden'` emits `--emit-dwarf-unwind`, but `--emulated-tls` is still missing. 2. Setting `-Cllvm-args=--emit-dwarf-unwind=always` doesn't take any effect, but `-Cllvm-args=-machine-outliner-reruns=3` does work. ### 1 Adding `RegisterCodeGenFlags` to register codegen flags fixed the first problem. `rustc -C llvm-args='--help-list-hidden'` emits full codegen flags including `--emit-dwarf-unwind` and `--emulated-tls`. ### 2 Constructing `TargetOptions` from `InitTargetOptionsFromCodeGenFlags` in `LLVMRustCreateTargetMachine` fixed the second problem. The `LLVMRustSetLLVMOptions` calls `ParseCommandLineOptions` which parses given `llvm-args`. For options like `machine-outliner-reruns`, it just works, since the codegen logic directly consumes the parsing result: [machine-outliner-reruns register](https://github.com/rust-lang/llvm-project/blob/0537f6354cffe546cbf47f6dc9c7f82e49e86cfb/llvm/lib/CodeGen/MachineOutliner.cpp#L114) [machine-outliner-reruns consumption](https://github.com/rust-lang/llvm-project/blob/0537f6354cffe546cbf47f6dc9c7f82e49e86cfb/llvm/lib/CodeGen/MachineOutliner.cpp#L1138) But for flags defined in `TargetOptions` and `MCTargetOptions` to take effect, constructing them with `InitTargetOptionsFromCodeGenFlags` is essential, or the parsing result is just not consumed. Similar patterns can be observed in [lli](https://github.com/rust-lang/llvm-project/blob/0537f6354cffe546cbf47f6dc9c7f82e49e86cfb/llvm/tools/llc/llc.cpp#L494), [llc](https://github.com/rust-lang/llvm-project/blob/0537f6354cffe546cbf47f6dc9c7f82e49e86cfb/llvm/tools/lli/lli.cpp#L517), etc.
2023-09-08Auto merge of #113492 - nebulark:pr_96475, r=petrochenkovbors-1/+38
Add CL and CMD into to pdb debug info Partial fix for https://github.com/rust-lang/rust/issues/96475 The Arg0 and CommandLineArgs of the MCTargetOptions cpp class are not set within https://github.com/rust-lang/rust/blob/bb548f964572f7fe652716f5897d9050a31c936e/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp#L378 This causes LLVM to not neither output any compiler path (cl) nor the arguments that were used when invoking it (cmd) in the PDB file. This fix adds the missing information to the target machine so LLVM can use it.
2023-09-08Add missing Debuginfo to PDB debug file on windows.Florian Schmiderer-1/+38
Set Arg0 and CommandLineArgs in MCTargetoptions so LLVM outputs correct CL and CMD in LF_DEBUGINFO instead of empty/invalid values.
2023-09-07lto: load bitcode sections by nameAugie Fackler-0/+33
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-07Using parsed codegen flagsLiu Dingming-1/+1
2023-09-07Add `RegisterCodeGenFlags` to get full codegen flags listLiu Dingming-0/+3
2023-09-06Auto merge of #114946 - anforowicz:generic-fix-for-asan-lto, r=tmiaskobors-0/+7
Preserve ASAN-related symbols during LTO. Fixes https://github.com/rust-lang/rust/issues/113404
2023-09-05llvm-wrapper: adapt for LLVM API changeKrasimir Georgiev-0/+4
No functional changes intended. Adapts the wrapper for https://github.com/llvm/llvm-project/commit/bbe8cd13335300958b04db5318c31ff52714f96f. Found by our experimental rust + llvm @ HEAD CI: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/22055#018a6495-8dd9-41df-9381-5e7b0009ce0a/274-575
2023-08-29Preserve `___asan_globals_registered` symbol during LTO.Lukasz Anforowicz-0/+7
Fixes https://github.com/rust-lang/rust/issues/113404
2023-08-21Move a local to the `#if` block where it is usedJosh Stone-1/+1
For other cases (LLVM < 17), this was complaining under `-Wall`: ``` warning: llvm-wrapper/PassWrapper.cpp: In function ‘void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef, const char*)’: warning: llvm-wrapper/PassWrapper.cpp:311:26: warning: unused variable ‘MCInfo’ [-Wunused-variable] warning: 311 | const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo(); warning: | ^~~~~~ ```