Skip to content

Commit 6a92455

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 dd50999 commit 6a92455

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.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

@@ -1126,45 +1125,6 @@ impl UnwindBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
11261125

11271126
impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11281127
/* Miscellaneous instructions */
1129-
fn inline_asm_call(&mut self, asm: &CStr, cons: &CStr,
1130-
inputs: &[&'ll Value], output: &'ll Type,
1131-
volatile: bool, alignstack: bool,
1132-
dia: syntax::ast::AsmDialect) -> Option<&'ll Value> {
1133-
self.count_insn("inlineasm");
1134-
1135-
let volatile = if volatile { llvm::True }
1136-
else { llvm::False };
1137-
let alignstack = if alignstack { llvm::True }
1138-
else { llvm::False };
1139-
1140-
let argtys = inputs.iter().map(|v| {
1141-
debug!("Asm Input Type: {:?}", *v);
1142-
self.cx.val_ty(*v)
1143-
}).collect::<Vec<_>>();
1144-
1145-
debug!("Asm Output Type: {:?}", output);
1146-
let fty = self.type_func(&argtys[..], output);
1147-
unsafe {
1148-
// Ask LLVM to verify that the constraints are well-formed.
1149-
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr());
1150-
debug!("Constraint verification result: {:?}", constraints_ok);
1151-
if constraints_ok {
1152-
let v = llvm::LLVMRustInlineAsm(
1153-
fty,
1154-
asm.as_ptr(),
1155-
cons.as_ptr(),
1156-
volatile,
1157-
alignstack,
1158-
AsmDialect::from_generic(dia),
1159-
);
1160-
Some(self.call(v, inputs, None))
1161-
} else {
1162-
// LLVM has detected an issue with our constraints, bail out
1163-
None
1164-
}
1165-
}
1166-
}
1167-
11681128
fn select(
11691129
&mut self, cond: &'ll Value,
11701130
then_val: &'ll Value,

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 {
@@ -258,17 +255,6 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
258255
+ NumBuilderMethods<'tcx>
259256
+ UnwindBuilderMethods<'tcx>
260257
{
261-
fn inline_asm_call(
262-
&mut self,
263-
asm: &CStr,
264-
cons: &CStr,
265-
inputs: &[Self::Value],
266-
output: Self::Type,
267-
volatile: bool,
268-
alignstack: bool,
269-
dia: AsmDialect,
270-
) -> Option<Self::Value>;
271-
272258
fn select(
273259
&mut self,
274260
cond: Self::Value,

0 commit comments

Comments
 (0)