Skip to content

Commit

Permalink
Rollup merge of #58308 - gnzlbg:context_insert_intr, r=eddyb
Browse files Browse the repository at this point in the history
Extract block to insert an intrinsic into its own function

r? @eddyb
  • Loading branch information
Centril authored Feb 14, 2019
2 parents fab0f9b + 7d6bfc5 commit a0767d6
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,33 +465,38 @@ impl CodegenCx<'b, 'tcx> {
self.declare_intrinsic(key).unwrap_or_else(|| bug!("unknown intrinsic '{}'", key))
}

fn insert_intrinsic(
&self, name: &'static str, args: Option<&[&'b llvm::Type]>, ret: &'b llvm::Type
) -> &'b llvm::Value {
let fn_ty = if let Some(args) = args {
self.type_func(args, ret)
} else {
self.type_variadic_func(&[], ret)
};
let f = self.declare_cfn(name, fn_ty);
llvm::SetUnnamedAddr(f, false);
self.intrinsics.borrow_mut().insert(name, f.clone());
f
}

fn declare_intrinsic(
&self,
key: &str
) -> Option<&'b Value> {
macro_rules! ifn {
($name:expr, fn() -> $ret:expr) => (
if key == $name {
let f = self.declare_cfn($name, self.type_func(&[], $ret));
llvm::SetUnnamedAddr(f, false);
self.intrinsics.borrow_mut().insert($name, f.clone());
return Some(f);
return Some(self.insert_intrinsic($name, Some(&[]), $ret));
}
);
($name:expr, fn(...) -> $ret:expr) => (
if key == $name {
let f = self.declare_cfn($name, self.type_variadic_func(&[], $ret));
llvm::SetUnnamedAddr(f, false);
self.intrinsics.borrow_mut().insert($name, f.clone());
return Some(f);
return Some(self.insert_intrinsic($name, None, $ret));
}
);
($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
if key == $name {
let f = self.declare_cfn($name, self.type_func(&[$($arg),*], $ret));
llvm::SetUnnamedAddr(f, false);
self.intrinsics.borrow_mut().insert($name, f.clone());
return Some(f);
return Some(self.insert_intrinsic($name, Some(&[$($arg),*]), $ret));
}
);
}
Expand Down

0 comments on commit a0767d6

Please sign in to comment.