about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/builder.rs
AgeCommit message (Collapse)AuthorLines
2024-11-03compiler: Directly use rustc_abi in codegenJubilee Young-1/+1
2024-10-30Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errorsJubilee-2/+2
Rename `rustc_abi::Abi` to `BackendRepr` Remove the confabulation of `rustc_abi::Abi` with what "ABI" actually means by renaming it to `BackendRepr`, and rename `Abi::Aggregate` to `BackendRepr::Memory`. The type never actually represented how things are passed, as that has to have `PassMode` considered, at minimum, but rather it just is how we represented some things to the backend. This conflation arose because LLVM, the primary backend at the time, would lower certain IR forms using certain ABIs. Even that only somewhat was true, as it broke down when one ventured significantly afield of what is described by the System V AMD64 ABI either by using different architectures, ABI-modifying IR annotations, the same architecture **with different ISA extensions enabled**, or other... unexpected delights. Unfortunately both names are still somewhat of a misnomer right now, as people have written code for years based on this misunderstanding. Still, their original names are even moreso, and for better or worse, this backend code hasn't received as much maintenance as the rest of the compiler, lately. Actually arriving at a correct end-state will simply require us to disentangle a lot of code in order to fix, much of it pointlessly repeated in several places. Thus this is not an "actual fix", just a way to deflect further misunderstandings.
2024-10-30Clean up FFI calls for operand bundlesZalathar-14/+9
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-2/+2
The initial naming of "Abi" was an awful mistake, conveying wrong ideas about how psABIs worked and even more about what the enum meant. It was only meant to represent the way the value would be described to a codegen backend as it was lowered to that intermediate representation. It was never meant to mean anything about the actual psABI handling! The conflation is because LLVM typically will associate a certain form with a certain ABI, but even that does not hold when the special cases that actually exist arise, plus the IR annotations that modify the ABI. Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename `BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to the persistent misunderstandings, this too is now incorrect: - Scattered ABI-relevant code is entangled with BackendRepr - We do not always pre-compute a correct BackendRepr that reflects how we "actually" want this value to be handled, so we leave the backend interface to also inject various special-cases here - In some cases `BackendRepr::Memory` is a "real" aggregate, but in others it is in fact using memory, and in some cases it is a scalar! Our rustc-to-backend lowering code handles this sort of thing right now. That will eventually be addressed by lifting duplicated lowering code to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-25coverage: SSA doesn't need to know about `instrprof_increment`Zalathar-11/+12
2024-10-25coverage: Emit MC/DC intrinsics using the normal helper methodZalathar-46/+9
2024-10-25coverage: Emit `llvm.instrprof.increment` using the normal helper methodZalathar-24/+2
2024-10-08compiler: Factor rustc_target::abi out of cg_llvmJubilee Young-4/+5
2024-10-08coverage. Adapt to mcdc mapping formats introduced by llvm 19zhuyunxing-50/+13
2024-10-08coverage. Disable supporting mcdc on llvm-18zhuyunxing-0/+13
2024-09-24Auto merge of #130389 - Luv-Ray:LLVMMDNodeInContext2, r=nikicbors-39/+20
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-19MetadataType type castLuv-Ray-8/+7
2024-09-19wrap `LLVMSetMetadata`Luv-Ray-19/+12
2024-09-19Reformat some comments.Nicholas Nethercote-5/+5
So they are less than 100 chars.
2024-09-19Use a macro to factor out some repetitive code.Nicholas Nethercote-80/+27
Similar to the existing macro just above.
2024-09-19replace some deprecated functionsLuv-Ray-36/+25
2024-09-18Update the minimum external LLVM to 18Josh Stone-14/+4
2024-09-17Use associative type defaults in `{Layout,FnAbi}OfHelpers`.Nicholas Nethercote-4/+0
This avoids some repetitive boilerplate code.
2024-09-17Merge `HasCodegen` into `BuilderMethods`.Nicholas Nethercote-4/+2
It has `Backend` and `Deref` boudns, plus an associated type `CodegenCx`, and it has a single use. This commit "inlines" it into `BuilderMethods`, which makes the complicated backend trait situation a little simpler.
2024-08-16Add `warn(unreachable_pub)` to `rustc_codegen_llvm`.Nicholas Nethercote-23/+35
2024-08-12Rollup merge of #128149 - RalfJung:nontemporal_store, r=jieyouxu,Amanieu,JubileeGuillaume Gomez-7/+26
nontemporal_store: make sure that the intrinsic is truly just a hint The `!nontemporal` flag for stores in LLVM *sounds* like it is just a hint, but actually, it is not -- at least on x86, non-temporal stores need very special treatment by the programmer or else the Rust memory model breaks down. LLVM still treats these stores as-if they were normal stores for optimizations, which is [highly dubious](https://github.com/llvm/llvm-project/issues/64521). Let's avoid all that dubiousness by making our own non-temporal stores be truly just a hint, which is possible on some targets (e.g. ARM). On all other targets, non-temporal stores become regular stores. ~~Blocked on https://github.com/rust-lang/stdarch/pull/1541 propagating to the rustc repo, to make sure the `_mm_stream` intrinsics are unaffected by this change.~~ Fixes https://github.com/rust-lang/rust/issues/114582 Cc `@Amanieu` `@workingjubilee`
2024-08-12make the codegen test also cover an ill-behaved arch, and add linksRalf Jung-0/+2
2024-08-08Rename struct_tail_erasing_lifetimes to struct_tail_for_codegenMichael Goulet-1/+1
2024-08-08Do normalize when computing struct tails in codegenMichael Goulet-2/+3
2024-08-05RISC-V also has sane nontemporal storesRalf Jung-1/+2
2024-08-05nontemporal_store: make sure that the intrinsic is truly just a hintRalf Jung-7/+23
2024-07-30Auto merge of #128250 - Amanieu:select_unpredictable, r=nikicbors-0/+10
Add `select_unpredictable` to force LLVM to use CMOV Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs into branches if it comes from a `select` marked with an `unpredictable` metadata attribute. This PR introduces `core::intrinsics::select_unpredictable` which emits such a `select` and uses it in the implementation of `binary_search_by`.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-15/+17
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28Force LLVM to use CMOV for binary searchAmanieu d'Antras-0/+10
Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs into branches if it comes from a `select` marked with an `unpredictable` metadata attribute. This PR introduces `core::intrinsics::select_unpredictable` which emits such a `select` and uses it in the implementation of `binary_search_by`.
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_codegen_llvm`.Nicholas Nethercote-0/+1
2024-05-10Auto merge of #124972 - matthiaskrgr:rollup-3fablim, r=matthiaskrgrbors-1/+1
Rollup of 5 pull requests Successful merges: - #124615 (coverage: Further simplify extraction of mapping info from MIR) - #124778 (Fix parse error message for meta items) - #124797 (Refactor float `Primitive`s to a separate `Float` type) - #124888 (Migrate `run-make/rustdoc-output-path` to rmake) - #124957 (Make `Ty::builtin_deref` just return a `Ty`) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-09codegen: memmove/memset cannot be non-temporalRalf Jung-0/+1
2024-05-06Refactor float `Primitive`s to a separate `Float` typebeetrees-1/+1
2024-05-01coverage: Set up MC/DC bitmaps without additional unsafe codeZalathar-24/+12
Because this now always takes place at the start of the function, we can just use the normal `alloca` method and then initialize each bitmap immediately. This patch also moves bitmap setup out of the `mcdc_parameters` method, because there is no longer any particular reason for it to be there.
2024-04-29Auto merge of #124255 - RenjiSann:renji/mcdc-nested-expressions, r=Zalatharbors-11/+20
MCDC coverage: support nested decision coverage #123409 provided the initial MCDC coverage implementation. As referenced in #124144, it does not currently support "nested" decisions, like the following example : ```rust fn nested_if_in_condition(a: bool, b: bool, c: bool) { if a && if b || c { true } else { false } { say("yes"); } else { say("no"); } } ``` Note that there is an if-expression (`if b || c ...`) embedded inside a boolean expression in the decision of an outer if-expression. This PR proposes a workaround for this cases, by introducing a Decision context stack, and by handing several `temporary condition bitmaps` instead of just one. When instrumenting boolean expressions, if the current node is a leaf condition (i.e. not a `||`/`&&` logical operator nor a `!` not operator), we insert a new decision context, such that if there are more boolean expressions inside the condition, they are handled as separate expressions. On the codegen LLVM side, we allocate as many `temp_cond_bitmap`s as necessary to handle the maximum encountered decision depth.
2024-04-29mcdc-coverage: Add possibility for codegen llvm to handle several condition ↵Dorian Péron-11/+20
bitmaps
2024-04-24Auto merge of #122053 - erikdesjardins:alloca, r=nikicbors-3/+4
Stop using LLVM struct types for alloca The alloca type has no semantic meaning, only the size (and alignment, but we specify it explicitly) matter. Using `[N x i8]` is a more direct way to specify that we want `N` bytes, and avoids relying on LLVM's struct layout. It is likely that a future LLVM version will change to an untyped alloca representation. Split out from #121577. r? `@ghost`
2024-04-20coverage. Lowering MC/DC statements to llvm-irzhuyunxing-1/+125
2024-04-15Auto merge of #122917 - saethlin:atomicptr-to-int, r=nikicbors-4/+8
Add the missing inttoptr when we ptrtoint in ptr atomics Ralf noticed this here: https://github.com/rust-lang/rust/pull/122220#discussion_r1535172094 Our previous codegen forgot to add the cast back to integer type. The code compiles anyway, because of course all locals are in-memory to start with, so previous codegen would do the integer atomic, store the integer to a local, then load a pointer from that local. Which is definitely _not_ what we wanted: That's an integer-to-pointer transmute, so all pointers returned by these `AtomicPtr` methods didn't have provenance. Yikes. Here's the IR for `AtomicPtr::fetch_byte_add` on 1.76: https://godbolt.org/z/8qTEjeraY ```llvm define noundef ptr `@atomicptr_fetch_byte_add(ptr` noundef nonnull align 8 %a, i64 noundef %v) unnamed_addr #0 !dbg !7 { start: %0 = alloca ptr, align 8, !dbg !12 %val = inttoptr i64 %v to ptr, !dbg !12 call void `@llvm.lifetime.start.p0(i64` 8, ptr %0), !dbg !28 %1 = ptrtoint ptr %val to i64, !dbg !28 %2 = atomicrmw add ptr %a, i64 %1 monotonic, align 8, !dbg !28 store i64 %2, ptr %0, align 8, !dbg !28 %self = load ptr, ptr %0, align 8, !dbg !28 call void `@llvm.lifetime.end.p0(i64` 8, ptr %0), !dbg !28 ret ptr %self, !dbg !33 } ``` r? `@RalfJung` cc `@nikic`
2024-04-11use [N x i8] for alloca typesErik Desjardins-3/+4
2024-04-11Put `PlaceValue` into `OperandValue::Ref`, rather than 3 tuple fieldsScott McMurray-3/+4
2024-04-11Make `PlaceRef` hold a `PlaceValue` for the non-layout fields (like ↵Scott McMurray-10/+10
`OperandRef` does)
2024-04-08sanitizers: Create the rustc_sanitizers crateRamon de C Valle-14/+11
Create the rustc_sanitizers crate and move the source code for the CFI and KCFI sanitizers to it. Co-authored-by: David Wood <agile.lion3441@fuligin.ink>
2024-03-26Auto merge of #122849 - clubby789:no-metadata, r=petrochenkovbors-0/+11
Don't emit load metadata in debug mode r? `@ghost`
2024-03-25Don't emit load metadata in debug modeclubby789-0/+11
2024-03-25Instance is CopyMichael Goulet-2/+2
2024-03-23CFI: Use Instance at callsitesMatthew Maurer-12/+29
We already use `Instance` at declaration sites when available to glean additional information about possible abstractions of the type in use. This does the same when possible at callsites as well. The primary purpose of this change is to allow CFI to alter how it generates type information for indirect calls through `Virtual` instances.
2024-03-23Add the missing inttoptr when we ptrtoint in ptr atomicsBen Kimock-4/+8
2024-03-09Sink ptrtoint for RMW ops on pointers to cg_llvmBen Kimock-1/+7