Skip to content

Commit 2671421

Browse files
committed
Auto merge of #58846 - bjorn3:misc_cg_ssa_refactor, r=eddyb
Misc refactorings to rustc_codegen_ssa Unlike #56636 this doesn't split `BuilderMethods` into a lot of traits. That makes this PR twice as small and the split turned out to not be very useful anyway. r? @eddyb
2 parents e782d79 + 35705de commit 2671421

26 files changed

+693
-759
lines changed

src/librustc_codegen_llvm/abi.rs

+4
Original file line numberDiff line numberDiff line change
@@ -859,4 +859,8 @@ impl AbiBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
859859
) {
860860
ty.apply_attrs_callsite(self, callsite)
861861
}
862+
863+
fn get_param(&self, index: usize) -> Self::Value {
864+
llvm::get_param(self.llfn(), index as c_uint)
865+
}
862866
}

src/librustc_codegen_llvm/asm.rs

+46-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_codegen_ssa::traits::*;
1010
use rustc_codegen_ssa::mir::place::PlaceRef;
1111
use rustc_codegen_ssa::mir::operand::OperandValue;
1212

13-
use std::ffi::CString;
13+
use std::ffi::{CStr, CString};
1414
use libc::{c_uint, c_char};
1515

1616

@@ -73,7 +73,8 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
7373

7474
let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap();
7575
let constraint_cstr = CString::new(all_constraints).unwrap();
76-
let r = self.inline_asm_call(
76+
let r = inline_asm_call(
77+
self,
7778
&asm,
7879
&constraint_cstr,
7980
&inputs,
@@ -119,3 +120,46 @@ impl AsmMethods<'tcx> for CodegenCx<'ll, 'tcx> {
119120
}
120121
}
121122
}
123+
124+
fn inline_asm_call(
125+
bx: &mut Builder<'a, 'll, 'tcx>,
126+
asm: &CStr,
127+
cons: &CStr,
128+
inputs: &[&'ll Value],
129+
output: &'ll llvm::Type,
130+
volatile: bool,
131+
alignstack: bool,
132+
dia: ::syntax::ast::AsmDialect,
133+
) -> Option<&'ll Value> {
134+
let volatile = if volatile { llvm::True }
135+
else { llvm::False };
136+
let alignstack = if alignstack { llvm::True }
137+
else { llvm::False };
138+
139+
let argtys = inputs.iter().map(|v| {
140+
debug!("Asm Input Type: {:?}", *v);
141+
bx.cx.val_ty(*v)
142+
}).collect::<Vec<_>>();
143+
144+
debug!("Asm Output Type: {:?}", output);
145+
let fty = bx.cx.type_func(&argtys[..], output);
146+
unsafe {
147+
// Ask LLVM to verify that the constraints are well-formed.
148+
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr());
149+
debug!("Constraint verification result: {:?}", constraints_ok);
150+
if constraints_ok {
151+
let v = llvm::LLVMRustInlineAsm(
152+
fty,
153+
asm.as_ptr(),
154+
cons.as_ptr(),
155+
volatile,
156+
alignstack,
157+
llvm::AsmDialect::from_generic(dia),
158+
);
159+
Some(bx.call(v, inputs, None))
160+
} else {
161+
// LLVM has detected an issue with our constraints, bail out
162+
None
163+
}
164+
}
165+
}

0 commit comments

Comments
 (0)