Skip to content

Commit b2e6194

Browse files
committed
Remove inline_asm_call from cg_ssa
`count_insn` is no longer called for inline asm, because it is private to builder.rs
1 parent b71c429 commit b2e6194

File tree

3 files changed

+47
-57
lines changed

3 files changed

+47
-57
lines changed

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+
}

src/librustc_codegen_llvm/builder.rs

+1-41
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::llvm::{AtomicRmwBinOp, AtomicOrdering, SynchronizationScope, AsmDialect};
1+
use crate::llvm::{AtomicRmwBinOp, AtomicOrdering, SynchronizationScope};
22
use crate::llvm::{self, False, BasicBlock};
33
use crate::common::Funclet;
44
use crate::context::CodegenCx;
@@ -19,7 +19,6 @@ use rustc_codegen_ssa::base::to_immediate;
1919
use rustc_codegen_ssa::mir::operand::{OperandValue, OperandRef};
2020
use rustc_codegen_ssa::mir::place::PlaceRef;
2121
use std::borrow::Cow;
22-
use std::ffi::CStr;
2322
use std::ops::{Deref, Range};
2423
use std::ptr;
2524

@@ -903,45 +902,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
903902
}
904903

905904
/* Miscellaneous instructions */
906-
fn inline_asm_call(&mut self, asm: &CStr, cons: &CStr,
907-
inputs: &[&'ll Value], output: &'ll Type,
908-
volatile: bool, alignstack: bool,
909-
dia: syntax::ast::AsmDialect) -> Option<&'ll Value> {
910-
self.count_insn("inlineasm");
911-
912-
let volatile = if volatile { llvm::True }
913-
else { llvm::False };
914-
let alignstack = if alignstack { llvm::True }
915-
else { llvm::False };
916-
917-
let argtys = inputs.iter().map(|v| {
918-
debug!("Asm Input Type: {:?}", *v);
919-
self.cx.val_ty(*v)
920-
}).collect::<Vec<_>>();
921-
922-
debug!("Asm Output Type: {:?}", output);
923-
let fty = self.type_func(&argtys[..], output);
924-
unsafe {
925-
// Ask LLVM to verify that the constraints are well-formed.
926-
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr());
927-
debug!("Constraint verification result: {:?}", constraints_ok);
928-
if constraints_ok {
929-
let v = llvm::LLVMRustInlineAsm(
930-
fty,
931-
asm.as_ptr(),
932-
cons.as_ptr(),
933-
volatile,
934-
alignstack,
935-
AsmDialect::from_generic(dia),
936-
);
937-
Some(self.call(v, inputs, None))
938-
} else {
939-
// LLVM has detected an issue with our constraints, bail out
940-
None
941-
}
942-
}
943-
}
944-
945905
fn memcpy(&mut self, dst: &'ll Value, dst_align: Align,
946906
src: &'ll Value, src_align: Align,
947907
size: &'ll Value, flags: MemFlags) {

src/librustc_codegen_ssa/traits/builder.rs

-14
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ use crate::mir::place::PlaceRef;
1111
use crate::MemFlags;
1212
use rustc::ty::Ty;
1313
use rustc::ty::layout::{Align, Size};
14-
use std::ffi::CStr;
15-
1614
use std::ops::Range;
17-
use syntax::ast::AsmDialect;
1815

1916
#[derive(Copy, Clone)]
2017
pub enum OverflowOp {
@@ -164,17 +161,6 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
164161
fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
165162
fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
166163

167-
fn inline_asm_call(
168-
&mut self,
169-
asm: &CStr,
170-
cons: &CStr,
171-
inputs: &[Self::Value],
172-
output: Self::Type,
173-
volatile: bool,
174-
alignstack: bool,
175-
dia: AsmDialect,
176-
) -> Option<Self::Value>;
177-
178164
fn memcpy(
179165
&mut self,
180166
dst: Self::Value,

0 commit comments

Comments
 (0)