Skip to content

Commit 6ce4c5d

Browse files
committed
Add InlineAsmOperandRef::Const
This is intended for supporting passing arbitrary CTFE const into inline assembly.
1 parent ad72e0d commit 6ce4c5d

File tree

3 files changed

+32
-0
lines changed
  • compiler

3 files changed

+32
-0
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
276276
constants_len += string.len() + att_dialect as usize;
277277
}
278278

279+
InlineAsmOperandRef::Const { value } => {
280+
inputs.push(AsmInOperand {
281+
constraint: Cow::Borrowed("i"),
282+
rust_idx,
283+
val: value.immediate(),
284+
});
285+
}
286+
279287
InlineAsmOperandRef::SymFn { instance } => {
280288
// TODO(@Amanieu): Additional mangling is needed on
281289
// some targets to add a leading underscore (Mach-O)
@@ -391,6 +399,10 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
391399
// processed in the previous pass
392400
}
393401

402+
InlineAsmOperandRef::Const { .. } => {
403+
// processed in the previous pass
404+
}
405+
394406
InlineAsmOperandRef::Label { .. } => {
395407
// processed in the previous pass
396408
}
@@ -464,6 +476,15 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
464476
push_to_template(modifier, gcc_index);
465477
}
466478

479+
InlineAsmOperandRef::Const { .. } => {
480+
let in_gcc_index = inputs
481+
.iter()
482+
.position(|op| operand_idx == op.rust_idx)
483+
.expect("wrong rust index");
484+
let gcc_index = in_gcc_index + outputs.len();
485+
push_to_template(None, gcc_index);
486+
}
487+
467488
InlineAsmOperandRef::SymFn { instance } => {
468489
// TODO(@Amanieu): Additional mangling is needed on
469490
// some targets to add a leading underscore (Mach-O)

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
158158
constraints.push(format!("{}", op_idx[&idx]));
159159
}
160160
}
161+
InlineAsmOperandRef::Const { value } => {
162+
inputs.push(value.immediate());
163+
op_idx.insert(idx, constraints.len());
164+
constraints.push("i".to_string());
165+
}
161166
InlineAsmOperandRef::SymFn { instance } => {
162167
inputs.push(self.cx.get_fn(instance));
163168
op_idx.insert(idx, constraints.len());
@@ -205,6 +210,9 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
205210
template_str.push_str(&format!("${{{}}}", op_idx[&operand_idx]));
206211
}
207212
}
213+
InlineAsmOperandRef::Const { .. } => {
214+
template_str.push_str(&format!("${{{}:c}}", op_idx[&operand_idx]));
215+
}
208216
InlineAsmOperandRef::Interpolate { ref string } => {
209217
// Const operands get injected directly into the template
210218
template_str.push_str(string);

compiler/rustc_codegen_ssa/src/traits/asm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub enum InlineAsmOperandRef<'tcx, B: BackendTypes + ?Sized> {
2828
Interpolate {
2929
string: String,
3030
},
31+
Const {
32+
value: OperandRef<'tcx, B::Value>,
33+
},
3134
SymFn {
3235
instance: Instance<'tcx>,
3336
},

0 commit comments

Comments
 (0)