Skip to content

Support using const pointers in asm const operand #138618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

nbdd0121
Copy link
Contributor

@nbdd0121 nbdd0121 commented Mar 17, 2025

Implements #128464

This adds support of const pointers for asm const in addition to plain integers.

The inline asm! support is implemented using i constraint, and the global_asm! and naked_asm! support is implemented by inserting symbol + offset and make symbol compiler-used. For unnamed consts, it will create additional internal & hidden symbols so that they can be referenced by global_asm.

The feature is also implemented for GCC backend but it's untested.

This is used for string interpolation currently, so rename it as so.
The name `Const` will be used to denote a general CTFE constant that
can either be integer or pointer.
This is intended for supporting passing arbitrary CTFE const into inline
assembly.
`global_asm!` themselves don't need symbol names; they currently only have
a symbol name during mono collecion to identify them to partitioning
algorithm.

However it will have shims generated under it which will need unique symbol
names. The name themselves ultimately doesn't matter, so they're generated
like other shim instances.
This is currently a no-op, but will be useful when const in `global_asm!`
can be pointers.
@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2025

r? @fmease

rustbot has assigned @fmease.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 17, 2025
@fmease
Copy link
Member

fmease commented Mar 17, 2025

r? codegen

@rustbot rustbot assigned workingjubilee and unassigned fmease Mar 17, 2025
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

r? compiler-errors

@nbdd0121 nbdd0121 marked this pull request as ready for review April 10, 2025 14:59
@rustbot
Copy link
Collaborator

rustbot commented Apr 10, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@@ -25,9 +26,12 @@ pub enum InlineAsmOperandRef<'tcx, B: BackendTypes + ?Sized> {
in_value: OperandRef<'tcx, B::Value>,
out_place: Option<PlaceRef<'tcx, B::Value>>,
},
Const {
Interpolate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more doc comment explaining the significance of the difference between Interpolate and Const for backends. It begs the question for why we ever turn const operands into strings, for example.

Comment on lines +52 to +54
value: mir::interpret::Pointer,
/// Instance that instantiates this const operand.
instance: Instance<'tcx>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need both a value and an instance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants