Skip to content

Commit 0947c84

Browse files
committed
Add InlineAsmOperandRef::Const
This is intended for supporting passing arbitrary CTFE const into inline assembly.
1 parent 1447b1d commit 0947c84

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
@@ -298,6 +298,14 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
298298
constants_len += string.len() + att_dialect as usize;
299299
}
300300

301+
InlineAsmOperandRef::Const { value } => {
302+
inputs.push(AsmInOperand {
303+
constraint: Cow::Borrowed("i"),
304+
rust_idx,
305+
val: value.immediate(),
306+
});
307+
}
308+
301309
InlineAsmOperandRef::SymFn { instance } => {
302310
// TODO(@Amanieu): Additional mangling is needed on
303311
// some targets to add a leading underscore (Mach-O)
@@ -413,6 +421,10 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
413421
// processed in the previous pass
414422
}
415423

424+
InlineAsmOperandRef::Const { .. } => {
425+
// processed in the previous pass
426+
}
427+
416428
InlineAsmOperandRef::Label { .. } => {
417429
// processed in the previous pass
418430
}
@@ -486,6 +498,15 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
486498
push_to_template(modifier, gcc_index);
487499
}
488500

501+
InlineAsmOperandRef::Const { .. } => {
502+
let in_gcc_index = inputs
503+
.iter()
504+
.position(|op| operand_idx == op.rust_idx)
505+
.expect("wrong rust index");
506+
let gcc_index = in_gcc_index + outputs.len();
507+
push_to_template(None, gcc_index);
508+
}
509+
489510
InlineAsmOperandRef::SymFn { instance } => {
490511
// TODO(@Amanieu): Additional mangling is needed on
491512
// 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)