Skip to content
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

Refactor rustc_codegen_ssa (part 2) #56636

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c324b4e
Don't use c_uint in cg_ssa
bjorn3 Dec 2, 2018
86104b4
`eval_mir_constant` doesn't need a builder param
bjorn3 Dec 2, 2018
cec0cf5
Use Builder instead of CodegenCx for OperandRef and LocalRef
bjorn3 Dec 2, 2018
17ef249
Use implicit deref instead of BuilderMethods::cx() at more places
bjorn3 Dec 2, 2018
7d72269
Misc
bjorn3 Dec 2, 2018
fbd969b
Remove const_{fat_ptr,array,vector,bytes} from cg_ssa
bjorn3 Dec 2, 2018
48c3baa
Remove const_{cstr,str_slice,get_elt,get_real} and is_const_real meth…
bjorn3 Dec 2, 2018
86f0603
Remove param_substs from FunctionCx
bjorn3 Dec 2, 2018
84c5b52
Remove internal mutability from source_locations_enabled
bjorn3 Dec 2, 2018
18e59b7
[WIP] Make some debug info methods take &mut FunctionDebugContext
bjorn3 Dec 2, 2018
231ff37
Remove a lot of methods from BuilderMethods
bjorn3 Dec 2, 2018
d24125e
Rebase fallout
bjorn3 Dec 4, 2018
13d5c03
Split memory related methods out of BuilderMethods and move get_param…
bjorn3 Dec 6, 2018
7319287
Move mem{cpy,move,set} to MemoryBuilderMethods
bjorn3 Dec 6, 2018
1e0e3b0
Introduce NumBuilderMethods and move some more methods to MemoryBuild…
bjorn3 Dec 7, 2018
5f33467
Remove scalar_lltypes from cg_ssa
bjorn3 Dec 7, 2018
d163582
Remove a lot of methods from *TypeMethods
bjorn3 Dec 7, 2018
e19c4b9
Remove type_variadic_func and typ_array from cg_ssa
bjorn3 Dec 8, 2018
a0713cc
Relax some trait constraints
bjorn3 Dec 8, 2018
14c3492
Move the loop of Rvalue::Repeat codegen out of cg_ssa
bjorn3 Dec 8, 2018
97e43a4
Move unwinding related methods to UnwindBuilderMethods
bjorn3 Dec 8, 2018
dd50999
Split control flow related methods out to ControlFlowBuilderMethods
bjorn3 Dec 8, 2018
6a92455
Remove inline_asm_call from cg_ssa
bjorn3 Dec 8, 2018
c45a9b9
Remove va_arg from cg_ssa
bjorn3 Dec 8, 2018
d7a528c
Relax some more constraints
bjorn3 Dec 8, 2018
018747b
Add a method for emiting a switch.
bjorn3 Dec 8, 2018
ef3358b
Fix tidy
bjorn3 Dec 9, 2018
270540b
Remove duplicate va_arg
bjorn3 Jan 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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
}
}
}
Loading