rust/compiler/rustc_codegen_ssa/src/traits
bors 3b022d8cee Auto merge of #133852 - x17jiri:cold_path, r=saethlin
improve cold_path()

#120370 added a new instrinsic `cold_path()` and used it to fix `likely` and `unlikely`

However, in order to limit scope, the information about cold code paths is only used in 2-target switch instructions. This is sufficient for `likely` and `unlikely`, but limits usefulness of `cold_path` for idiomatic rust. For example, code like this:

```
if let Some(x) = y { ... }
```

may generate 3-target switch:

```
switch y.discriminator:
0 => true branch
1 = > false branch
_ => unreachable
```

and therefore marking a branch as cold will have no effect.

This PR improves `cold_path()` to work with arbitrary switch instructions.

Note that for 2-target switches, we can use `llvm.expect`, but for multiple targets we need to manually emit branch weights. I checked Clang and it also emits weights in this situation. The Clang's weight calculation is more complex that this PR, which I believe is mainly because `switch` in `C/C++` can have multiple cases going to the same target.
2025-02-18 07:49:09 +00:00
..
abi.rs Merge apply_attrs_callsite into call and invoke 2022-10-01 17:01:31 +00:00
asm.rs codegen #[naked] functions using global_asm! 2024-12-10 21:41:03 +01:00
backend.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
builder.rs Auto merge of #133852 - x17jiri:cold_path, r=saethlin 2025-02-18 07:49:09 +00:00
consts.rs compiler: remove rustc_target::abi entirely 2025-02-07 11:23:12 -08:00
coverageinfo.rs Remove BackendTypes constraint from traits that don't need it. 2024-09-17 10:24:43 +10:00
debuginfo.rs Use ExistentialTraitRef throughout codegen 2025-01-30 15:34:00 +00:00
declare.rs Rename supertraits of CodegenMethods. 2024-09-17 10:24:43 +10:00
intrinsic.rs compiler: Directly use rustc_abi in codegen 2024-11-03 12:30:32 -08:00
misc.rs Use ExistentialTraitRef throughout codegen 2025-01-30 15:34:00 +00:00
mod.rs compiler: Directly use rustc_abi in codegen 2024-11-03 12:30:32 -08:00
statics.rs compiler: Directly use rustc_abi in codegen 2024-11-03 12:30:32 -08:00
type_.rs compiler: remove reexports from rustc_target::callconv 2025-02-07 11:25:18 -08:00
write.rs Make CodegenCx and Builder generic 2025-01-24 16:05:26 -05:00