Commit Graph

512 Commits

Author SHA1 Message Date
lcnr
3c52a3e280 subst -> instantiate 2023-09-26 09:37:55 +02:00
Guillaume Gomez
208f6ed95c
Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obk
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const

Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`.

Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all.

However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish...

``@oli-obk`` any ideas?
2023-09-21 13:25:39 +02:00
Ralf Jung
c94410c145 rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const 2023-09-21 08:12:30 +02:00
Ralf Jung
ea22adbabd adjust constValue::Slice to work for arbitrary slice types 2023-09-19 20:17:43 +02:00
Ralf Jung
5a0a1ff0cd move ConstValue into mir
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-19 11:11:02 +02:00
bors
cebb9cfd4f Auto merge of #115748 - RalfJung:post-mono, r=oli-obk
move required_consts check to general post-mono-check function

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) https://github.com/rust-lang/rust/issues/115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? `@oli-obk`
2023-09-18 19:41:21 +00:00
Ralf Jung
29a4b7b971 fix gcc, cranelift build 2023-09-15 10:43:44 +02:00
Ralf Jung
89139d4c46 clarify PassMode::Indirect as well 2023-09-15 10:43:44 +02:00
Ralf Jung
9ac8b363e3 don't point at const usage site for resolution-time errors
also share the code that emits the actual error
2023-09-14 22:34:05 +02:00
Ralf Jung
89ac57db4d move required_consts check to general post-mono-check function 2023-09-14 22:30:42 +02:00
Ralf Jung
430c386821 make it more clear which functions create fresh AllocId 2023-09-14 07:27:31 +02:00
Ralf Jung
0f8908da27 cleanup op_to_const a bit; rename ConstValue::ByRef → Indirect 2023-09-14 07:27:30 +02:00
Ralf Jung
551f481ffb use AllocId instead of Allocation in ConstValue::ByRef 2023-09-14 07:26:24 +02:00
Matthias Krüger
565b9c2264
Rollup merge of #115798 - RalfJung:non_1zst_field, r=wesleywiser
add helper method for finding the one non-1-ZST field
2023-09-13 18:37:42 +02:00
Matthias Krüger
5dc37c1966
Rollup merge of #115736 - Zoxc:time-cleanup, r=wesleywiser
Remove `verbose_generic_activity_with_arg`

This removes `verbose_generic_activity_with_arg` and changes users to `generic_activity_with_arg`. This keeps the output of `-Z time` readable while these repeated events are still available with the self profiling mechanism.
2023-09-13 18:37:41 +02:00
Ralf Jung
6e4779ab17 make the eval() functions on our const types return the resulting value 2023-09-13 07:29:34 +02:00
Ralf Jung
60091fe924 add helper method for finding the one non-1-ZST field 2023-09-12 20:52:05 +02:00
John Kåre Alsaker
f742d88326 Remove verbose_generic_activity_with_arg 2023-09-10 17:47:16 +02:00
bors
26f4b72724 Auto merge of #115418 - Zoxc:freeze-source, r=oli-obk
Use `Freeze` for `SourceFile`

This uses the `Freeze` type in `SourceFile` to let accessing `external_src` and `lines` be lock-free.

Behavior of `add_external_src` is changed to set `ExternalSourceKind::AbsentErr` on a hash mismatch which matches the documentation. `ExternalSourceKind::Unneeded` was removed as it's unused.

Based on https://github.com/rust-lang/rust/pull/115401.
2023-09-08 17:20:23 +00:00
John Kåre Alsaker
f49382c050 Use Freeze for SourceFile.lines 2023-09-07 13:05:05 +02:00
bors
fece303aeb Auto merge of #115616 - bjorn3:sync_cg_clif-2023-09-06, r=bjorn3
Sync rustc_codegen_cranelift

Not much changed this time. Mostly doing this sync to make it easier to run the entire test suite on the in-tree version.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
2023-09-07 03:56:43 +00:00
bors
b0d45536ac Auto merge of #115580 - eduardosm:stdarch-intrinsics, r=davidtwco,bjorn3
Update stdarch submodule and remove special handling in cranelift codegen for some AVX and SSE2 LLVM intrinsics

https://github.com/rust-lang/stdarch/pull/1463 reimplemented some x86 intrinsics to avoid using some x86-specific LLVM intrinsics:

* Store unaligned (`_mm*_storeu_*`) use `<*mut _>::write_unaligned` instead of `llvm.x86.*.storeu.*`.
* Shift by immediate (`_mm*_s{ll,rl,ra}i_epi*`) use `if` (srl, sll) or `min` (sra) to simulate the behaviour when the RHS is out of range. RHS is constant, so the `if`/`min` will be optimized away.

This PR updates the stdarch submodule to pull these changes and removes special handling for those LLVM intrinsics from cranelift codegen. I left gcc codegen untouched because there are some autogenerated lists.
2023-09-06 22:26:37 +00:00
bjorn3
521ed6e308 Merge commit 'dda103b1e33c4902deca8bccf614991ada781fa6' into sync_cg_clif-2023-09-06 2023-09-06 18:51:03 +00:00
Eduardo Sánchez Muñoz
0b6ee86d37 Remove special handling in codegen for some AVX and SSE2 shift by immediate intrinsics
Those were removed from stdarch in https://github.com/rust-lang/stdarch/pull/1463 (`simd_shl` and `simd_shr` are used instead)
2023-09-05 20:17:01 +02:00
Eduardo Sánchez Muñoz
c3edc57981 Remove special handling in codegen for some SSE2 "storeu" intrinsics
Those were removed from stdarch in https://github.com/rust-lang/stdarch/pull/1463 (`<*mut _>::write_unaligned` is used instead)
2023-09-05 20:06:50 +02:00
Camille GILLOT
258ace613d Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
Matthias Krüger
56d7d93a4b
Rollup merge of #111580 - atsuzaki:layout-ice, r=oli-obk
Don't ICE on layout computation failure

Fixes #111176 regression.

r? `@oli-obk`
2023-08-29 20:49:02 +02:00
Ralf Jung
b2ebf1c23f const_eval and codegen: audit uses of is_zst 2023-08-29 09:03:46 +02:00
Katherine Philip
56b767322b Don't ICE on layout computation failure 2023-08-28 12:40:39 -07:00
Scott McMurray
754f488d46 Use preserve_mostcc for extern "rust-cold"
As experimentation in 115242 has shown looks better than `coldcc`.

And *don't* use a different convention for cold on Windows, because that actually ends up making things worse.

cc tracking issue 97544
2023-08-26 17:42:59 -07:00
Ralf Jung
4c53783f3c when terminating during unwinding, show the reason why 2023-08-24 13:28:26 +02:00
Ralf Jung
818ec8e23a give some unwind-related terminators a more clear name 2023-08-20 15:52:38 +02:00
Michael Goulet
94533d924e
Rollup merge of #114622 - petrochenkov:noplugin, r=oli-obk
rustc: Move `crate_types` and `stable_crate_id` from `Session` to `GlobalCtxt`

Removes two pieces of mutable state.
Follow up to https://github.com/rust-lang/rust/pull/114578.
2023-08-10 21:17:07 -07:00
bors
832db2fcee Auto merge of #114673 - matthiaskrgr:rollup-9kroqpp, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #110435 (rustdoc-json: Add test for field ordering.)
 - #111891 (feat: `riscv-interrupt-{m,s}` calling conventions)
 - #114377 (test_get_dbpath_for_term(): handle non-utf8 paths (fix FIXME))
 - #114469 (Detect method not found on arbitrary self type with different mutability)
 - #114587 (Convert Const to Allocation in smir)
 - #114670 (Don't use `type_of` to determine if item has intrinsic shim)

Failed merges:

 - #114599 (Add impl trait declarations to SMIR)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-09 23:27:46 +00:00
bjorn3
37751893cc Merge commit '8f9ac9c22d6594cf059d8e6c71d414cc5ccd7975' into sync_cg_clif-2023-08-09 2023-08-09 18:20:12 +00:00
Vadim Petrochenkov
0b89aac08d rustc: Move crate_types from Session to GlobalCtxt
Removes a piece of mutable state.
Follow up to #114578.
2023-08-09 14:17:54 +08:00
Seth Pellegrino
897c7bb23b feat: riscv-interrupt-{m,s} calling conventions
Similar to prior support added for the mips430, avr, and x86 targets
this change implements the rough equivalent of clang's
[`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling
e.g.

```rust
static mut CNT: usize = 0;

pub extern "riscv-interrupt-m" fn isr_m() {
    unsafe {
        CNT += 1;
    }
}
```

to produce highly effective assembly like:

```asm
pub extern "riscv-interrupt-m" fn isr_m() {
420003a0:       1141                    addi    sp,sp,-16
    unsafe {
        CNT += 1;
420003a2:       c62a                    sw      a0,12(sp)
420003a4:       c42e                    sw      a1,8(sp)
420003a6:       3fc80537                lui     a0,0x3fc80
420003aa:       63c52583                lw      a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0>
420003ae:       0585                    addi    a1,a1,1
420003b0:       62b52e23                sw      a1,1596(a0)
    }
}
420003b4:       4532                    lw      a0,12(sp)
420003b6:       45a2                    lw      a1,8(sp)
420003b8:       0141                    addi    sp,sp,16
420003ba:       30200073                mret
```

(disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`)

This outcome is superior to hand-coded interrupt routines which, lacking
visibility into any non-assembly body of the interrupt handler, have to
be very conservative and save the [entire CPU state to the stack
frame][full-frame-save]. By instead asking LLVM to only save the
registers that it uses, we defer the decision to the tool with the best
context: it can more accurately account for the cost of spills if it
knows that every additional register used is already at the cost of an
implicit spill.

At the LLVM level, this is apparently [implemented by] marking every
register as "[callee-save]," matching the semantics of an interrupt
handler nicely (it has to leave the CPU state just as it found it after
its `{m|s}ret`).

This approach is not suitable for every interrupt handler, as it makes
no attempt to e.g. save the state in a user-accessible stack frame. For
a full discussion of those challenges and tradeoffs, please refer to
[the interrupt calling conventions RFC][rfc].

Inside rustc, this implementation differs from prior art because LLVM
does not expose the "all-saved" function flavor as a calling convention
directly, instead preferring to use an attribute that allows for
differentiating between "machine-mode" and "superivsor-mode" interrupts.

Finally, some effort has been made to guide those who may not yet be
aware of the differences between machine-mode and supervisor-mode
interrupts as to why no `riscv-interrupt` calling convention is exposed
through rustc, and similarly for why `riscv-interrupt-u` makes no
appearance (as it would complicate future LLVM upgrades).

[clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v
[full-frame-save]: 9281af2ecf/src/lib.rs (L440-L469)
[implemented by]: b7fb2a3fec/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp (L61-L67)
[callee-save]: 973f1fe7a8/llvm/lib/Target/RISCV/RISCVCallingConv.td (L30-L37)
[rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-08-08 18:09:56 -07:00
Matthias Krüger
cbe2522652
Rollup merge of #114382 - scottmcm:compare-bytes-intrinsic, r=cjgillot
Add a new `compare_bytes` intrinsic instead of calling `memcmp` directly

As discussed in #113435, this lets the backends be the place that can have the "don't call the function if n == 0" logic, if it's needed for the target.  (I didn't actually *add* those checks, though, since as I understood it we didn't actually need them on known targets?)

Doing this also let me make it `const` (unstable), which I don't think `extern "C" fn memcmp` can be.

cc `@RalfJung` `@Amanieu`
2023-08-07 05:29:12 +02:00
scottmcm
75277a6606 Apply suggestions from code review
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-06 15:47:40 -07:00
Scott McMurray
502af03445 Add a new compare_bytes intrinsic instead of calling memcmp directly 2023-08-06 15:47:40 -07:00
David Tolnay
704aa56ba0
Generate better function argument names in global_allocator expansion 2023-08-06 07:36:05 -07:00
Matthias Krüger
a0fd747e38
Rollup merge of #114450 - chenyukang:yukang-fix-114435, r=compiler-errors
Fix ICE failed to get layout for ReferencesError

Fixes #114435

r? `@compiler-errors`
2023-08-04 21:31:57 +02:00
yukang
3d25b5c7e8 Fix ICE failed to get layout for ReferencesError 2023-08-05 01:38:14 +08:00
Oli Scherer
4457ef2c6d Forbid old-style simd_shuffleN intrinsics 2023-08-03 09:29:00 +00:00
bjorn3
36708123c1 Merge commit '1eded3619d0e55d57521a259bf27a03906fdfad0' into sync_cg_clif-2023-07-22 2023-07-22 13:32:34 +00:00
chenx97
c6e03cd951 support for mips64r6 as a target_arch value 2023-07-18 18:58:18 +08:00
Nicholas Nethercote
b52f9eb6ca Introduce MonoItemData.
It replaces `(Linkage, Visibility)`, making the code nicer. Plus the
next commit will add another field.
2023-07-17 08:44:48 +10:00
bors
7a17f577b3 Auto merge of #112157 - erikdesjardins:align, r=nikic
Resurrect: rustc_target: Add alignment to indirectly-passed by-value types, correcting the alignment of byval on x86 in the process.

Same as #111551, which I [accidentally closed](https://github.com/rust-lang/rust/pull/111551#issuecomment-1571222612) :/

---

This resurrects PR #103830, which has sat idle for a while.

Beyond #103830, this also:
- fixes byval alignment for types containing vectors on Darwin (see `tests/codegen/align-byval-vector.rs`)
- fixes byval alignment for overaligned types on x86 Windows (see `tests/codegen/align-byval.rs`)
- fixes ABI for types with 128bit requested alignment on ARM64 Linux (see `tests/codegen/aarch64-struct-align-128.rs`)

r? `@nikic`

---

`@pcwalton's` original PR description is reproduced below:

Commit 88e4d2c from five years ago removed
support for alignment on indirectly-passed arguments because of problems with
the `i686-pc-windows-msvc` target. Unfortunately, the `memcpy` optimizations I
recently added to LLVM 16 depend on this to forward `memcpy`s. This commit
attempts to fix the problems with `byval` parameters on that target and now
correctly adds the `align` attribute.

The problem is summarized in [this comment] by `@eddyb.` Briefly, 32-bit x86 has
special alignment rules for `byval` parameters: for the most part, their
alignment is forced to 4. This is not well-documented anywhere but in the Clang
source. I looked at the logic in Clang `TargetInfo.cpp` and tried to replicate
it here. The relevant methods in that file are
`X86_32ABIInfo::getIndirectResult()` and
`X86_32ABIInfo::getTypeStackAlignInBytes()`. The `align` parameter attribute
for `byval` parameters in LLVM must match the platform ABI, or miscompilations
will occur. Note that this doesn't use the approach suggested by eddyb, because
I felt it was overkill to store the alignment in `on_stack` when special
handling is really only needed for 32-bit x86.

As a side effect, this should fix #80127, because it will make the `align`
parameter attribute for `byval` parameters match the platform ABI on LLVM
x86-64.

[this comment]: #80822 (comment)
2023-07-15 15:39:53 +00:00
Mahdi Dibaiee
e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Erik Desjardins
c858d345b3 cg_clif: just ignore all the unused LayoutS fields 2023-07-10 19:19:41 -04:00