about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
AgeCommit message (Collapse)AuthorLines
2024-03-15Install the bad-alloc handler before fatal errorsJosh Stone-1/+1
The bad-alloc installer was incorrectly asserting that the other handler isn't set yet, instead of checking its own, but we can avoid that by changing the order we install them. Ref: https://github.com/llvm/llvm-project/issues/83040
2024-03-15Aggressively ignore write errors during bad-allocJosh Stone-3/+3
2024-03-15Register LLVM handlers for bad-alloc / OOMJosh Stone-1/+24
LLVM's default bad-alloc handler may throw if exceptions are enabled, and `operator new` isn't hooked at all by default. Now we register our own handler that prints a message similar to fatal errors, then aborts. We also call the function that registers the C++ `std::new_handler`.
2024-03-12llvm-wrapper: adapt for LLVM API changesKrasimir Georgiev-2/+7
Adapts rust for https://github.com/llvm/llvm-project/commit/9997e0397156ff7e01aecbd17bdeb7bfe5fb15b0.
2024-03-10Fix 32-bit overflows in LLVM composite constantserer1243-8/+34
2024-03-08Rollup merge of #119365 - nbdd0121:asm-goto, r=AmanieuMatthias Krüger-0/+25
Add asm goto support to `asm!` Tracking issue: #119364 This PR implements asm-goto support, using the syntax described in "future possibilities" section of [RFC2873](https://rust-lang.github.io/rfcs/2873-inline-asm.html#asm-goto). Currently I have only implemented the `label` part, not the `fallthrough` part (i.e. fallthrough is implicit). This doesn't reduce the expressive though, since you can use label-break to get arbitrary control flow or simply set a value and rely on jump threading optimisation to get the desired control flow. I can add that later if deemed necessary. r? ``@Amanieu`` cc ``@ojeda``
2024-03-07Rollup merge of #122062 - workingjubilee:initialize-my-fist, r=cuviperMatthias Krüger-20/+20
Explicitly assign constructed C++ classes 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-05Explicitly assign constructed C++ classesJubilee Young-20/+20
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-05Clarify FatalErrorHandlerJubilee Young-2/+12
Clarify the FatalErrorHandler API that we use: - Identify rustc's LLVM ERRORs by prefixing them - Comment heavily on its interior, while we are here
2024-02-26Rollup merge of #121389 - klensy:llvm-warn-fix, r=nikicMatthias Krüger-1/+1
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-24Add callbr support to LLVM wrapperGary Guo-0/+25
2024-02-21remove simd_reduce_{min,max}_nanlessRalf Jung-7/+6
2024-02-21make simd_reduce_{mul,add}_unordered use only the 'reassoc' flag, not all ↵Ralf Jung-0/+15
fast-math flags
2024-02-21llvm-wrapper: fix warning C4244klensy-1/+1
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-1/+24
2024-02-12llvm-wrapper: adapt for LLVM API change: Add support for EXPORTAS name typesHans Wennborg-0/+3
Adapt for llvm/llvm-project@8f23464.
2024-01-30Remove `ffi_returns_twice` featureclubby789-2/+0
2023-12-11fix: stop emitting `.debug_pubnames` and `.debug_pubtypes`Weihang Lo-2/+23
`.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-11-30Add `-Zfunction-return={keep,thunk-extern}` optionMiguel Ojeda-0/+2
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-21Update the minimum external LLVM to 16.Dario Nieuwenhuis-50/+1
2023-11-16Auto merge of #117948 - aeubanks:dibuilder, r=durin42bors-0/+3
llvm-wrapper: Pass newly added param to DIBuilder::createStaticMemberType() This was added in https://github.com/llvm/llvm-project/pull/72234. DW_TAG_member was the implicit default before. The LLVM change is quite sinister since due to weakly typed ints and default params, this was still successfully compiling against LLVM but was passing the wrong parameters.
2023-11-15llvm-wrapper: Pass newly added param to DIBuilder::createEnumerationType()Arthur Eubanks-1/+5
Added in LLVM in https://github.com/llvm/llvm-project/pull/72011.
2023-11-1517 -> 18Arthur Eubanks-1/+1
2023-11-15[llvm-wrapper] Pass newly added param to DIBuilder::createStaticMemberType()Arthur Eubanks-0/+3
This was added in https://github.com/llvm/llvm-project/pull/72234. DW_TAG_member was the implicit default before.
2023-09-08debuginfo: add compiler option to allow compressed debuginfo sectionsAugie Fackler-0/+16
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-08-08Rollup merge of #113593 - rcvalle:rust-cfi-fix-90546, r=wesleywiserMatthias Krüger-0/+11
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-3/+6
2023-08-07CFI: Fix error compiling core with LLVM CFI enabledRamon de C Valle-0/+11
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-04Add hotness data to LLVM remarksJakub Beránek-0/+3
This makes sure that if PGO is used, remarks generated using `-Zremark-dir` will include the `Hotness` attribute.
2023-08-01Auto merge of #113339 - lqd:respect-filters, r=tmiaskobors-3/+10
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-08-01filter LLVM diagnostics before crossing the rust bridgeRémy Rakic-3/+10
this will eliminate many short-lived allocations (e.g. 20% of the memory used building cargo) when unpacking the diagnostic and converting its various C++ strings into rust strings, just to be filtered out most of the time.
2023-07-27Update the minimum external LLVM to 15Josh Stone-41/+0
2023-07-20address feedback from nikic and oli-obk ↵khei4-6/+8
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-8/+18
2023-07-16rustc_llvm: Add a `-Z print-llvm-stats` option to expose LLVM statistics.Patrick Walton-0/+6
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-10Reuse LLVMConstInBoundsGEP2Jubilee Young-11/+0
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/+26
llvm ffi: Expose `CallInst->setTailCallKind` This is needed for the explicit tail calls experiment.
2023-07-02Add `rustc` option to output LLVM optimization remarks to YAML filesJakub Beránek-7/+83
2023-06-30llvm ffi: Expose `CallInst->setTailCallKind`Maybe Waffle-0/+26
2023-05-26Add SafeStack support to rustcWesley Wiser-0/+2
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-03debuginfo: split method declaration and definitionJosh Stone-0/+22
When we're adding a method to a type DIE, we only want a DW_AT_declaration there, because LLVM LTO can't unify type definitions when a child DIE is a full subprogram definition. Now the subprogram definition gets added at the CU level with a specification link back to the abstract declaration.
2023-04-08Auto merge of #109862 - klensy:llvm-dd, r=nikicbors-74/+3
llvm: replace some deprecated functions, add fixmes Replace some deprecated llvm functions, add FIXME's (for simpler future work), replace some rust custom functions with llvm ones.
2023-04-05reviewklensy-1/+1
2023-04-04replaceklensy-12/+1
LLVMRustBuildIntCast -> LLVMBuildIntCast2 LLVMRustAddHandler -> LLVMAddHandler
2023-04-04Use existing llvm methods, instead of rust wrappers for:klensy-49/+0
LLVMRustBuildCleanupPad -> LLVMBuildCleanupPad LLVMRustBuildCleanupRet -> LLVMBuildCleanupRet LLVMRustBuildCatchPad -> LLVMBuildCatchPad LLVMRustBuildCatchRet -> LLVMBuildCatchRet LLVMRustBuildCatchSwitch -> LLVMBuildCatchSwitch
2023-04-04replace LLVMRustAppendModuleInlineAsm with LLVMAppendModuleInlineAsm, ↵klensy-9/+0
LLVMRustMetadataTypeInContext with LLVMMetadataTypeInContext
2023-04-04replace LLVMRustMetadataAsValue with LLVMMetadataAsValueklensy-4/+0
2023-04-04add bunch of fixmes: currently there exist some functions that accept ↵klensy-0/+2
LLVMValueRef, some that accept LLVMMetadataRef, and replacing one with another not always possible without explicit convertion
2023-03-31Preserve, clarify, and extend debug informationJulia Tatz-0/+3
`-Cdebuginfo=1` was never line tables only and can't be due to backwards compatibility issues. This was clarified and an option for line tables only was added. Additionally an option for line info directives only was added, which is well needed for some targets. The debug info options should now behave the same as clang's debug info options.
2023-02-25record llvm cgu instruction statscsmoe-0/+13