summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/llvm
AgeCommit message (Collapse)AuthorLines
2024-11-12Rollup merge of #132702 - 1c3t3a:issue-132615, r=rcvalleMatthias Krüger-0/+1
CFI: Append debug location to CFI blocks Currently we're not appending debug locations to the inserted CFI blocks. This shows up in #132615 and #100783. This change fixes that by passing down the debug location to the CFI type-test generation and appending it to the blocks. Credits also belong to `@jakos-sec` who worked with me on this.
2024-11-11CFI: Append debug location to CFI blocksBastian Kersting-0/+1
2024-11-09Add discriminators to DILocations when multiple functions are inlined into a ↵Kyle Huey-0/+4
single point. LLVM does not expect to ever see multiple dbg_declares for the same variable at the same location with different values. proc-macros make it possible for arbitrary code, including multiple calls that get inlined, to happen at any given location in the source code. Add discriminators when that happens so these locations are different to LLVM. This may interfere with the AddDiscriminators pass in LLVM, which is added by the unstable flag -Zdebug-info-for-profiling. Fixes #131944
2024-11-09Auto merge of #132584 - Zalathar:includes, r=cuviperbors-1/+1
Trim and tidy includes in `rustc_llvm` These includes tend to accumulate over time, and are usually only removed when something breaks in a new LLVM version, so it's nice to clean them up manually once in a while. General strategy used for this PR: - Remove all includes from `LLVMWrapper.h` that aren't needed by the header itself, transplanting them to individual source files as necessary. - For each source file, temporarily remove each include if doing so doesn't cause a compile error. - If a “required” include looks like it shouldn't be needed, try replacing it with its sub-includes, then trim that list. - After doing all of the above, go back and re-add any removed include if the file does actually use things defined in that header, even if the header happens to also be included by something else.
2024-11-09Make `RustString` an extern type to avoid `improper_ctypes` warningsZalathar-24/+2
2024-11-08Rollup merge of #132590 - Zalathar:z-timings-stats, r=jieyouxuStuart Cook-4/+6
Simplify FFI calls for `-Ztime-llvm-passes` and `-Zprint-codegen-stats` The existing code for these unstable LLVM-infodump flags was jumping through hoops to pass an allocated C string across the FFI boundary, when it's much simpler to just write to a `&RustString` instead.
2024-11-05coverage: Tidy up coverage-specific FFI functionsZalathar-12/+12
2024-11-04Simplify FFI calls for `-Ztime-llvm-passes` and `-Zprint-codegen-stats`Zalathar-4/+6
2024-11-04Move `LLVMRustAttribute[Kind]` out of `LLVMWrapper.h`Zalathar-1/+1
2024-11-03compiler: Directly use rustc_abi in codegenJubilee Young-1/+1
2024-11-02Port most of `LLVMRustPrintTargetCPUs` to RustZalathar-6/+2
2024-11-02Use a dedicated safe wrapper for `LLVMRustGetHostCPUName`Zalathar-1/+1
2024-10-31Remove support for `-Zprofile` (gcov-style coverage instrumentation)Zalathar-1/+0
2024-10-30Rollup merge of #132342 - Zalathar:operand-bundle, r=workingjubileeMatthias Krüger-55/+74
cg_llvm: Clean up FFI calls for operand bundles All of these FFI functions have equivalents in the stable LLVM-C API, though `LLVMBuildCallBr` requires a temporary polyfill on LLVM 18. This PR also creates a clear split between `OperandBundleOwned` and `OperandBundle`, and updates the internals of the owner to be a little less terrifying.
2024-10-30Clean up FFI calls for operand bundlesZalathar-55/+74
2024-10-30Consistently use safe wrapper function `set_section`Zalathar-0/+1
2024-10-29Rollup merge of #132319 - Zalathar:add-module-flag, r=jieyouxuMatthias Krüger-11/+44
cg_llvm: Clean up FFI calls for setting module flags This is a combination of several inter-related changes to how module flags are set: - Remove some unnecessary code for setting an `"LTOPostLink"` flag, which has been obsolete since LLVM 17. - Define our own enum instead of relying on enum values defined by LLVM's unstable C++ API. - Use safe wrapper functions to set module flags, instead of direct `unsafe` calls. - Consistently pass pointer/length strings instead of C strings. - Remove or shrink some `unsafe` blocks.
2024-10-29Clean up FFI calls for setting module flagsZalathar-9/+44
- Don't rely on enum values defined by LLVM's C++ API - Use safe wrapper functions instead of direct `unsafe` calls - Consistently pass pointer/length strings instead of C strings
2024-10-29Don't set unnecessary module flag "LTOPostLink"Zalathar-2/+0
This module flag was an internal detail of LLVM's optimization passes, and all code involving it was removed in LLVM 17. <https://github.com/llvm/llvm-project/commit/200cc952a28a73687ba24d5334415df6332f2d5b>
2024-10-29Rollup merge of #132216 - klensy:c_uint, r=cuviperJubilee-2/+2
correct LLVMRustCreateThinLTOData arg types `LLVMRustCreateThinLTOData` defined in rust as ```rust pub fn LLVMRustCreateThinLTOData( Modules: *const ThinLTOModule, NumModules: c_uint, PreservedSymbols: *const *const c_char, PreservedSymbolsLen: c_uint, ) -> Option<&'static mut ThinLTOData>; ``` but in cpp as ```cpp extern "C" LLVMRustThinLTOData * LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules, int num_modules, const char **preserved_symbols, int num_symbols) { ``` (note `c_unit` vs `int` types). Let it be actually `size_t`. Also fixes return type of `LLVMRustDIBuilderCreateOpLLVMFragment` to uint64_t as other similar functions around, which should be correct, i assume.
2024-10-29correct LLVMRustCreateThinLTOData arg typesklensy-2/+2
2024-10-28Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`Zalathar-6/+6
2024-10-27Use LLVM-C APIs for getting/setting visibilityZalathar-6/+6
2024-10-26Use LLVM-C APIs for getting/setting linkageZalathar-13/+24
2024-10-26Add a wrapper type for raw enum values returned by LLVMZalathar-0/+25
2024-10-26Use safe wrappers `get_visibility` and `set_visibility`Zalathar-0/+4
2024-10-26Use safe wrappers `get_linkage` and `set_linkage`Zalathar-0/+4
2024-10-25coverage: Emit MC/DC intrinsics using the normal helper methodZalathar-3/+0
2024-10-25coverage: Emit `llvm.instrprof.increment` using the normal helper methodZalathar-1/+0
2024-10-24Rollup merge of #131956 - Zalathar:llvm-counters, r=compiler-errors,SwatinemStuart Cook-10/+16
coverage: Pass coverage mappings to LLVM as separate structs Instead of trying to cram *N* different kinds of coverage mapping data into a single list for FFI, pass *N* different lists of simpler structs. This avoids the need to fill unused fields with dummy values, and avoids the need to tag structs with their underlying kind. It also lets us call the dedicated LLVM constructors for each different mapping type, instead of having to go through the complex general-purpose constructor. Even though this adds multiple new structs to the FFI surface area, the resulting C++ code is simpler and shorter. --- I've structured this mostly as a single atomic patch, rather than a series of incremental changes, because that avoids the need to make fiddly fixes to code that is about to be deleted anyway.
2024-10-20Make `llvm::set_section` take a `&CStr`Zalathar-3/+2
2024-10-20Pass coverage mappings to LLVM as separate structsZalathar-2/+8
2024-10-20Reduce visibility of coverage FFI functions/typesZalathar-8/+8
2024-10-19cg_llvm: Reuse LLVM-C Comdat supportJubilee Young-7/+15
Migrate `llvm::set_comdat` and `llvm::SetUniqueComdat` to LLVM-C FFI. Note, now we can call `llvm::set_comdat` only when the target actually supports adding comdat. As this has no convenient LLVM-C API, we implement this as `TargetOptions::supports_comdat`. Co-authored-by: Stuart Cook <Zalathar@users.noreply.github.com>
2024-10-18cg_llvm: Switch `llvm::add_global` to `&CStr`Jubilee Young-2/+1
2024-10-08coverage. Adapt to mcdc mapping formats introduced by llvm 19zhuyunxing-1/+0
2024-10-01Replace -Z default-hidden-visibility with -Z default-visibilityDavid Lattimore-0/+11
MCP: https://github.com/rust-lang/compiler-team/issues/782 Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2024-09-24Auto merge of #130389 - Luv-Ray:LLVMMDNodeInContext2, r=nikicbors-10/+0
llvm: replace some deprecated functions `LLVMMDStringInContext` and `LLVMMDNodeInContext` are deprecated, replace them with `LLVMMDStringInContext2` and `LLVMMDNodeInContext2`. Also replace `Value` with `Metadata` in some function signatures for better consistency.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-09-19Reformat some comments.Nicholas Nethercote-1/+2
So they are less than 100 chars.
2024-09-19Merge adjacent `unsafe extern "C"` blocks.Nicholas Nethercote-26/+2
2024-09-19Avoid heavy repetition in `llvm/ffi.rs`.Nicholas Nethercote-70/+67
Through judicious use of `use` and `Self`.
2024-09-19replace some deprecated functionsLuv-Ray-10/+0
2024-09-06Don't leave debug locations for constants sitting on the builder indefinitely.Kyle Huey-1/+1
Because constants are currently emitted *before* the prologue, leaving the debug location on the IRBuilder spills onto other instructions in the prologue and messes up both line numbers as well as the point LLVM chooses to be the prologue end. Example LLVM IR (irrelevant IR elided): Before: define internal { i64, i64 } @_ZN3tmp3Foo18var_return_opt_try17he02116165b0fc08cE(ptr align 8 %self) !dbg !347 { start: %self.dbg.spill = alloca [8 x i8], align 8 %_0 = alloca [16 x i8], align 8 %residual.dbg.spill = alloca [0 x i8], align 1 #dbg_declare(ptr %residual.dbg.spill, !353, !DIExpression(), !357) store ptr %self, ptr %self.dbg.spill, align 8, !dbg !357 #dbg_declare(ptr %self.dbg.spill, !350, !DIExpression(), !358) After: define internal { i64, i64 } @_ZN3tmp3Foo18var_return_opt_try17h00b17d08874ddd90E(ptr align 8 %self) !dbg !347 { start: %self.dbg.spill = alloca [8 x i8], align 8 %_0 = alloca [16 x i8], align 8 %residual.dbg.spill = alloca [0 x i8], align 1 #dbg_declare(ptr %residual.dbg.spill, !353, !DIExpression(), !357) store ptr %self, ptr %self.dbg.spill, align 8 #dbg_declare(ptr %self.dbg.spill, !350, !DIExpression(), !358) Note in particular how !357 from %residual.dbg.spill's dbg_declare no longer falls through onto the store to %self.dbg.spill. This fixes argument values at entry when the constant is a ZST (e.g. <Option as Try>::Residual). This fixes #130003 (but note that it does *not* fix issues with argument values and non-ZST constants, which emit their own stores that have debug info on them, like #128945).
2024-09-05Rollup merge of #128820 - LYF1999:yf/dev, r=nikicMatthias Krüger-0/+1
fix: get llvm type of global val using `LLVMTypeOf` on a global var always return ptr. so create a new function to access the value type of a global
2024-08-29Rollup merge of #128970 - DianQK:lint-llvm-ir, r=nikicGuillaume Gomez-0/+1
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-0/+1
2024-08-27Rollup merge of #129635 - compiler-errors:unsafe-blocks, r=spastorinoMatthias Krüger-21/+21
Use unsafe extern blocks throughout the compiler Making this change in preparation for edition 2024. r? spastorino
2024-08-27Rollup merge of #126985 - Mrmaxmeier:dwarf-embed-source, r=davidtwcoTrevor Gross-0/+2
Implement `-Z embed-source` (DWARFv5 source code embedding extension) Implement https://github.com/rust-lang/compiler-team/issues/764 MCP which adds an unstable flag that exposes LLVM's [DWARFv5 source code embedding](https://dwarfstd.org/issues/180201.1.html) support.
2024-08-26Use unsafe extern blocks throughout the compilerMichael Goulet-21/+21