Skip to content

Commit

Permalink
Auto merge of #58846 - bjorn3:misc_cg_ssa_refactor, r=eddyb
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Mar 29, 2019
2 parents e782d79 + 35705de commit 2671421
Show file tree
Hide file tree
Showing 26 changed files with 693 additions and 759 deletions.
4 changes: 4 additions & 0 deletions src/librustc_codegen_llvm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,4 +859,8 @@ impl AbiBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
) {
ty.apply_attrs_callsite(self, callsite)
}

fn get_param(&self, index: usize) -> Self::Value {
llvm::get_param(self.llfn(), index as c_uint)
}
}
48 changes: 46 additions & 2 deletions src/librustc_codegen_llvm/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::mir::operand::OperandValue;

use std::ffi::CString;
use std::ffi::{CStr, CString};
use libc::{c_uint, c_char};


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

let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap();
let constraint_cstr = CString::new(all_constraints).unwrap();
let r = self.inline_asm_call(
let r = inline_asm_call(
self,
&asm,
&constraint_cstr,
&inputs,
Expand Down Expand Up @@ -119,3 +120,46 @@ impl AsmMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}
}

fn inline_asm_call(
bx: &mut Builder<'a, 'll, 'tcx>,
asm: &CStr,
cons: &CStr,
inputs: &[&'ll Value],
output: &'ll llvm::Type,
volatile: bool,
alignstack: bool,
dia: ::syntax::ast::AsmDialect,
) -> Option<&'ll Value> {
let volatile = if volatile { llvm::True }
else { llvm::False };
let alignstack = if alignstack { llvm::True }
else { llvm::False };

let argtys = inputs.iter().map(|v| {
debug!("Asm Input Type: {:?}", *v);
bx.cx.val_ty(*v)
}).collect::<Vec<_>>();

debug!("Asm Output Type: {:?}", output);
let fty = bx.cx.type_func(&argtys[..], output);
unsafe {
// Ask LLVM to verify that the constraints are well-formed.
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr());
debug!("Constraint verification result: {:?}", constraints_ok);
if constraints_ok {
let v = llvm::LLVMRustInlineAsm(
fty,
asm.as_ptr(),
cons.as_ptr(),
volatile,
alignstack,
llvm::AsmDialect::from_generic(dia),
);
Some(bx.call(v, inputs, None))
} else {
// LLVM has detected an issue with our constraints, bail out
None
}
}
}

0 comments on commit 2671421

Please sign in to comment.