about summary refs log tree commit diff
path: root/compiler/stable_mir/src/mir
AgeCommit message (Collapse)AuthorLines
2024-04-09Rollup merge of #123655 - celinval:smir-fix-binop-ty, r=compiler-errorsMatthias Krüger-36/+2
Remove unimplemented!() from BinOp::ty() function To reduce redundancy, we now internalize the BinOp instead of duplicating the `ty()` function body.
2024-04-08Add support to intrinsics fallback bodyCelina G. Val-1/+10
Before this fix, the call to `body()` would crash, since `has_body()` would return true, but we would try to retrieve the body of an intrinsic which is not allowed. Instead, the `Instance::body()` function will now convert an Intrinsic into an Item before retrieving its body.
2024-04-08Remove unimplemented!() from BinOp::ty() functionCelina G. Val-36/+2
To reduce redundancy, we now internalize the BinOp instead of duplicating the `ty()` function body.
2024-04-06Put checks that detect UB under their own flag below debug_assertionsBen Kimock-1/+1
2024-04-03rename `expose_addr` to `expose_provenance`joboet-0/+1
2024-04-02Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=AmanieuJacob Pratt-1/+1
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066). The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".) The new name nicely matches `ptr::without_provenance`.
2024-04-02Auto merge of #118310 - scottmcm:three-way-compare, r=davidtwcobors-0/+4
Add `Ord::cmp` for primitives as a `BinOp` in MIR Update: most of this OP was written months ago. See https://github.com/rust-lang/rust/pull/118310#issuecomment-2016940014 below for where we got to recently that made it ready for review. --- There are dozens of reasonable ways to implement `Ord::cmp` for integers using comparison, bit-ops, and branches. Those differences are irrelevant at the rust level, however, so we can make things better by adding `BinOp::Cmp` at the MIR level: 1. Exactly how to implement it is left up to the backends, so LLVM can use whatever pattern its optimizer best recognizes and cranelift can use whichever pattern codegens the fastest. 2. By not inlining those details for every use of `cmp`, we drastically reduce the amount of MIR generated for `derive`d `PartialOrd`, while also making it more amenable to MIR-level optimizations. Having extremely careful `if` ordering to μoptimize resource usage on broadwell (#63767) is great, but it really feels to me like libcore is the wrong place to put that logic. Similarly, using subtraction [tricks](https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign) (#105840) is arguably even nicer, but depends on the optimizer understanding it (https://github.com/llvm/llvm-project/issues/73417) to be practical. Or maybe [bitor is better than add](https://discourse.llvm.org/t/representing-in-ir/67369/2?u=scottmcm)? But maybe only on a future version that [has `or disjoint` support](https://discourse.llvm.org/t/rfc-add-or-disjoint-flag/75036?u=scottmcm)? And just because one of those forms happens to be good for LLVM, there's no guarantee that it'd be the same form that GCC or Cranelift would rather see -- especially given their very different optimizers. Not to mention that if LLVM gets a spaceship intrinsic -- [which it should](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Suboptimal.20inlining.20in.20std.20function.20.60binary_search.60/near/404250586) -- we'll need at least a rustc intrinsic to be able to call it. As for simplifying it in Rust, we now regularly inline `{integer}::partial_cmp`, but it's quite a large amount of IR. The best way to see that is with https://github.com/rust-lang/rust/commit/8811efa88b25b5e41d63850e6047e8257c677858#diff-d134c32d028fbe2bf835fef2df9aca9d13332dd82284ff21ee7ebf717bfa4765R113 -- I added a new pre-codegen MIR test for a simple 3-tuple struct, and this PR change it from 36 locals and 26 basic blocks down to 24 locals and 8 basic blocks. Even better, as soon as the construct-`Some`-then-match-it-in-same-BB noise is cleaned up, this'll expose the `Cmp == 0` branches clearly in MIR, so that an InstCombine (#105808) can simplify that to just a `BinOp::Eq` and thus fix some of our generated code perf issues. (Tracking that through today's `if a < b { Less } else if a == b { Equal } else { Greater }` would be *much* harder.) --- r? `@ghost` But first I should check that perf is ok with this ~~...and my true nemesis, tidy.~~
2024-03-23Add+Use `mir::BinOp::Cmp`Scott McMurray-0/+4
2024-03-23Rollup merge of #122762 - RoboSchmied:RoboSchmied-typo, r=workingjubileeJubilee-2/+2
fix typo of endianness fix typo endianess -> endianness
2024-03-23refactor check_{lang,library}_ub: use a single intrinsic, put policy into ↵Ralf Jung-8/+2
library
2024-03-23rename MIR int2ptr casts to match library nameRalf Jung-1/+1
2024-03-21Rollup merge of #122801 - celinval:smir-pretty, r=compiler-errorsMatthias Krüger-335/+222
Fix misc printing issues in emit=stable_mir Trying to continue the work that ````@ouz-a```` started here: https://github.com/rust-lang/rust/pull/118364 Few modifications beyond fixes: 1. I made the `pretty_*` functions private. 2. I added a function to print the instance body 3. Changed a bunch of signatures to write to the writer directly. 4. Added a function to translate the place to its internal representation, so we could use the internal debug implementation. 5. Also removed `pretty_ty`, replaced by Display implementation of Ty which uses the internal display.
2024-03-20s/place_debug/place_pretty in SMIRCelina G. Val-1/+1
2024-03-20Enable users to dump the body of an instanceCelina G. Val-1/+8
2024-03-20Improve emit stable mir bodyCelina G. Val-335/+215
2024-03-20Update target.rs alloc.rs event.rs simd.rsRoboSchmied-2/+2
fix typos
2024-03-20resolve clippy errorsonur-ozkan-4/+4
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-03-13Rollup merge of #122203 - adpaco-aws:smir-intrinsic-name, r=celinvalMatthias Krüger-0/+11
Add `intrinsic_name` to get plain intrinsic name Add an `intrinsic_name` API to retrieve the plain intrinsic name. The plain name does not include type arguments (as `trimmed_name` does), which is more convenient to match with intrinsic symbols.
2024-03-12Add `intrinsic_name` to get plain intrinsic nameAdrian Palacios-0/+11
2024-03-08Distinguish between library and lang UB in assert_unsafe_preconditionBen Kimock-2/+8
2024-02-12Dejargnonize substShoyu Vanilla-1/+1
2024-02-08Add a new debug_assertions instrinsic (compiler)Ben Kimock-0/+3
And in clippy
2024-01-11Add more information to `visit_projection_elem`Celina G. Val-19/+38
Without the starting place, it's hard to retrieve any useful information from visiting a projection.
2023-12-28Restore movability to SMIRMichael Goulet-4/+8
2023-12-28Remove movability from TyKind::CoroutineMichael Goulet-7/+4
2023-12-25Only regular coroutines have movabilityMichael Goulet-3/+3
2023-12-22Split coroutine desugaring kind from sourceMichael Goulet-21/+34
2023-12-20Add method to get instance instantiation argumentsCelina G. Val-0/+6
2023-12-20Rollup merge of #119094 - celinval:smir-layout, r=compiler-errorsMatthias Krüger-0/+6
Add function ABI and type layout to StableMIR This change introduces a new module to StableMIR named `abi` with information from `rustc_target::abi` and `rustc_abi`, that allow users to retrieve more low level information required to perform bit-precise analysis. The layout of a type can be retrieved via `Ty::layout`, and the instance ABI can be retrieved via `Instance::fn_abi()`. To properly handle errors while retrieve layout information, we had to implement a few layout related traits. r? ```@compiler-errors```
2023-12-18Add the function body span to StableMIRCelina G. Val-2/+8
2023-12-18Add function ABI and type layout to StableMIRCelina G. Val-0/+6
This change introduces a new module to StableMIR named `abi` with information from `rustc_target::abi` and `rustc_abi`, that allow users to retrieve more low level information required to perform bit-precise analysis. The layout of a type can be retrieved via `Ty::layout`, and the instance ABI can be retrieved via `Instance::fn_abi()`. To properly handle errors while retrieve layout information, we had to implement a few layout related traits.
2023-12-15Rollup merge of #118927 - celinval:smir-missing-info, r=compiler-errorsAli MJ Al-Nasrawy-13/+74
Erase late bound regions from `Instance::fn_sig()` and add a few more details to StableMIR APIs The Instance `fn_sig()` still included a late bound regions which needed a new compiler function in order to be erased. I've also bundled the following small fixes in this PR, let me know if you want me to isolate any of them. - Add missing `CoroutineKind::AsyncGen`. - Add optional spread argument to function body which is needed to properly analyze compiler shims. - Add a utility method to iterate over all locals together with their declaration. - Add a method to get the description of `AssertMessage`*. * For the last one, we could consider eventually calling the internal `AssertKind::description()` to avoid code duplication. However, we still don't have ways to convert `AssertMessage`, `Operand`, `Place` and others, in order to use that. The other downside of using the internal method is that it will panic for some of the variants. r ? `@ouz-a`
2023-12-14Revert signature change for AssertMessage descriptionCelina G. Val-34/+21
2023-12-14Address PR commentsCelina G. Val-27/+35
- Remove `fn_sig()` from Instance. - Change return value of `AssertMessage::description` to `Cow<>`. - Add assert to instance `ty()`. - Generalize uint / int type creation.
2023-12-14add stable_mir output testouz-a-13/+30
2023-12-13Add spread arg and missing CoroutineKindCelina G. Val-7/+73
2023-12-13Erase late bound regions from instance `fn_sig()`Celina G. Val-1/+1
Late bound regions were still part of the signature.
2023-12-11Remove scalar fn and tighten the BiOp Ty assertionsCelina G. Val-5/+11
2023-12-11Fix BinOp ty assertion and `fn_sig` for closuresCelina G. Val-10/+12
Also added a few more util methods to TyKind to check for specific types.
2023-12-07Add tests to allocation methods and fix is_null()Celina G. Val-1/+19
2023-12-07Fix conversion to StaticDef and add testCelina G. Val-1/+1
2023-12-07Add instance evaluation and methods to read allocCelina G. Val-3/+43
The instance evaluation is needed to handle intrinsics such as `type_id` and `type_name`. Since we now use Allocation to represent all evaluated constants, provide a few methods to help process the data inside an allocation.
2023-12-07Rollup merge of #118688 - celinval:smir-rvalue-ty, r=compiler-errorsMatthias Krüger-2/+118
Add method to get type of an Rvalue in StableMIR Provide a method to StableMIR users to retrieve the type of an Rvalue operation. There were two possible implementation: 1. Create the logic inside stable_mir to process the type according to the Rvalue semantics, which duplicates the logic of `rustc_middle::mir::Rvalue::ty()`. 2. Implement the Rvalue translation from StableMIR back to internal representation, invoke the `rustc_middle::mir::Rvalue::ty()`, and translate the return value to StableMIR. I chose the first one for now since the duplication was fairly small, and the option 2 would require way more work to translate everything back to rustc internal representation. If we eventually add those translations, we could easily swap to the option 2. ```@compiler-errors``` / ```@ouz-a``` Please let me know if you have any strong opinion here. r? ```@compiler-errors```
2023-12-06Add sanity check to `BinOp::ty()`Celina G. Val-8/+14
2023-12-06Update compiler/stable_mir/src/mir/body.rsCelina G. Val-1/+1
Co-authored-by: Michael Goulet <michael@errs.io>
2023-12-06Simplify StaticDef to Instance conversionCelina G. Val-3/+4
2023-12-06Add method to get type of an Rvalue in StableMIRCelina G. Val-0/+109
2023-12-06Rollup merge of #118681 - celinval:fix-foreign-item, r=ouz-aMatthias Krüger-2/+9
Fix is_foreign_item for StableMIR instance Change the implementation of `Instance::is_foreign_item` to directly query the compiler for the instance `def_id` instead of incorrectly relying on the conversion to `CrateItem`. I also added a method to check if the instance has body, since the function already existed and it just wasn't exposed via public APIs. This makes it much cheaper for the user to check if the instance has body. ## Background: - In pull https://github.com/rust-lang/rust/pull/118524, I fixed the conversion from Instance to CrateItem to avoid the conversion if the instance didn't have a body available. This broke the `is_foreign_item`. r? `@ouz-a`
2023-12-06Also add an API to check if an instance has bodyCelina G. Val-0/+8
This is much cheaper than building a body just for the purpose of checking if the body exists.
2023-12-06Fix `is_foreign_item` for StableMIR instanceCelina G. Val-2/+1
Change the implementation of `Instance::is_foreign_item` to directly query the compiler for the instance `def_id` instead of incorrectly relying on the conversion to `CrateItem`. Background: - In pull https://github.com/rust-lang/rust/pull/118524, I fixed the conversion from Instance to CrateItem to avoid the conversion if the instance didn't have a body available. This broke the `is_foreign_item`.