2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-01-07 16:16:52 -06:00
|
|
|
|
2012-09-04 13:54:36 -05:00
|
|
|
use codemap::span;
|
2012-12-13 15:05:22 -06:00
|
|
|
use lib::llvm::llvm;
|
|
|
|
use lib::llvm::{CallConv, TypeKind, AtomicBinOp, AtomicOrdering};
|
|
|
|
use lib::llvm::{Opcode, IntPredicate, RealPredicate, True, False};
|
2012-09-04 13:54:36 -05:00
|
|
|
use lib::llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, ModuleRef};
|
2012-12-13 15:05:22 -06:00
|
|
|
use libc::{c_uint, c_int};
|
|
|
|
use middle::trans::common::*;
|
|
|
|
|
2013-01-11 23:01:42 -06:00
|
|
|
use core::cast::transmute;
|
2012-12-23 16:41:37 -06:00
|
|
|
use core::cast;
|
|
|
|
use core::libc;
|
|
|
|
use core::str;
|
|
|
|
use core::vec;
|
2012-12-13 15:05:22 -06:00
|
|
|
use std::map::HashMap;
|
|
|
|
use syntax::codemap;
|
2011-08-24 07:54:55 -05:00
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn terminate(cx: block, _: &str) {
|
2013-01-11 23:01:42 -06:00
|
|
|
unsafe {
|
|
|
|
cx.terminated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn check_not_terminated(cx: block) {
|
2013-01-11 23:01:42 -06:00
|
|
|
if cx.terminated {
|
2013-01-31 19:51:01 -06:00
|
|
|
die!(~"already terminated!");
|
2013-01-11 23:01:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn B(cx: block) -> BuilderRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
let b = cx.fcx.ccx.builder.B;
|
|
|
|
llvm::LLVMPositionBuilderAtEnd(b, cx.llbb);
|
|
|
|
return b;
|
|
|
|
}
|
2011-08-30 07:02:20 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn count_insn(cx: block, category: &str) {
|
2012-05-17 23:53:49 -05:00
|
|
|
if cx.ccx().sess.count_llvm_insns() {
|
2012-03-22 15:44:20 -05:00
|
|
|
|
|
|
|
let h = cx.ccx().stats.llvm_insns;
|
2012-04-26 18:02:01 -05:00
|
|
|
let v = cx.ccx().stats.llvm_insn_ctxt;
|
2012-03-22 15:44:20 -05:00
|
|
|
|
|
|
|
// Build version of path with cycles removed.
|
|
|
|
|
|
|
|
// Pass 1: scan table mapping str -> rightmost pos.
|
2012-09-19 17:13:04 -05:00
|
|
|
let mm = HashMap();
|
2012-03-22 15:44:20 -05:00
|
|
|
let len = vec::len(*v);
|
|
|
|
let mut i = 0u;
|
|
|
|
while i < len {
|
|
|
|
mm.insert(copy v[i], i);
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Pass 2: concat strings for each elt, skipping
|
|
|
|
// forwards over any cycles by advancing to rightmost
|
|
|
|
// occurrence of each element in path.
|
2012-07-14 00:57:48 -05:00
|
|
|
let mut s = ~".";
|
2012-03-22 15:44:20 -05:00
|
|
|
i = 0u;
|
|
|
|
while i < len {
|
2013-01-07 16:16:52 -06:00
|
|
|
let e = /*bad*/copy v[i];
|
|
|
|
i = mm.get(/*bad*/ copy e);
|
2012-07-14 00:57:48 -05:00
|
|
|
s += ~"/";
|
2012-03-22 15:44:20 -05:00
|
|
|
s += e;
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
s += ~"/";
|
2012-03-22 15:44:20 -05:00
|
|
|
s += category;
|
|
|
|
|
2013-01-10 12:59:58 -06:00
|
|
|
let n = match h.find(/*bad*/ copy s) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(n) => n,
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => 0u
|
|
|
|
};
|
2012-03-22 15:44:20 -05:00
|
|
|
h.insert(s, n+1u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-21 05:40:27 -05:00
|
|
|
// The difference between a block being unreachable and being terminated is
|
|
|
|
// somewhat obscure, and has to do with error checking. When a block is
|
|
|
|
// terminated, we're saying that trying to add any further statements in the
|
|
|
|
// block is an error. On the other hand, if something is unreachable, that
|
|
|
|
// means that the block was terminated in some way that we don't want to check
|
2012-08-01 19:30:05 -05:00
|
|
|
// for (fail/break/return statements, call to diverging functions, etc), and
|
2011-09-21 05:40:27 -05:00
|
|
|
// further instructions to the block should simply be ignored.
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn RetVoid(cx: block) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "RetVoid");
|
2013-01-10 23:23:07 -06:00
|
|
|
count_insn(cx, "retvoid");
|
|
|
|
llvm::LLVMBuildRetVoid(B(cx));
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Ret(cx: block, V: ValueRef) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "Ret");
|
2013-01-10 23:23:07 -06:00
|
|
|
count_insn(cx, "ret");
|
|
|
|
llvm::LLVMBuildRet(B(cx), V);
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn AggregateRet(cx: block, RetVals: ~[ValueRef]) {
|
2012-08-01 19:30:05 -05:00
|
|
|
if cx.unreachable { return; }
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "AggregateRet");
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2012-09-12 19:45:23 -05:00
|
|
|
llvm::LLVMBuildAggregateRet(B(cx), vec::raw::to_ptr(RetVals),
|
2012-02-14 02:10:47 -06:00
|
|
|
RetVals.len() as c_uint);
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Br(cx: block, Dest: BasicBlockRef) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "Br");
|
2013-01-10 23:23:07 -06:00
|
|
|
count_insn(cx, "br");
|
|
|
|
llvm::LLVMBuildBr(B(cx), Dest);
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn CondBr(cx: block, If: ValueRef, Then: BasicBlockRef,
|
|
|
|
Else: BasicBlockRef) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "CondBr");
|
2013-01-10 23:23:07 -06:00
|
|
|
count_insn(cx, "condbr");
|
|
|
|
llvm::LLVMBuildCondBr(B(cx), If, Then, Else);
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Switch(cx: block, V: ValueRef, Else: BasicBlockRef, NumCases: uint)
|
2011-09-21 05:40:27 -05:00
|
|
|
-> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(V); }
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "Switch");
|
2013-01-10 23:23:07 -06:00
|
|
|
return llvm::LLVMBuildSwitch(B(cx), V, Else, NumCases as c_uint);
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn AddCase(S: ValueRef, OnVal: ValueRef, Dest: BasicBlockRef) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if llvm::LLVMIsUndef(S) == lib::llvm::True { return; }
|
|
|
|
llvm::LLVMAddCase(S, OnVal, Dest);
|
|
|
|
}
|
2011-09-21 05:40:27 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn IndirectBr(cx: block, Addr: ValueRef, NumDests: uint) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "IndirectBr");
|
2013-01-10 23:23:07 -06:00
|
|
|
count_insn(cx, "indirectbr");
|
|
|
|
llvm::LLVMBuildIndirectBr(B(cx), Addr, NumDests as c_uint);
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2011-09-21 10:46:11 -05:00
|
|
|
// This is a really awful way to get a zero-length c-string, but better (and a
|
2012-03-14 17:10:34 -05:00
|
|
|
// lot more efficient) than doing str::as_c_str("", ...) every time.
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn noname() -> *libc::c_char {
|
2013-01-23 13:43:58 -06:00
|
|
|
unsafe {
|
|
|
|
const cnull: uint = 0u;
|
|
|
|
return cast::reinterpret_cast(&ptr::addr_of(&cnull));
|
|
|
|
}
|
2011-09-21 10:46:11 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Invoke(cx: block, Fn: ValueRef, Args: ~[ValueRef],
|
|
|
|
Then: BasicBlockRef, Catch: BasicBlockRef) {
|
2012-08-01 19:30:05 -05:00
|
|
|
if cx.unreachable { return; }
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "Invoke");
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("Invoke(%s with arguments (%s))",
|
2012-02-21 07:20:18 -06:00
|
|
|
val_str(cx.ccx().tn, Fn),
|
2013-01-18 16:30:29 -06:00
|
|
|
str::connect(vec::map(Args, |a| val_str(cx.ccx().tn,
|
|
|
|
*a).to_owned()),
|
2012-08-22 19:24:52 -05:00
|
|
|
~", "));
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2012-08-14 18:45:43 -05:00
|
|
|
count_insn(cx, "invoke");
|
2012-09-12 19:45:23 -05:00
|
|
|
llvm::LLVMBuildInvoke(B(cx), Fn, vec::raw::to_ptr(Args),
|
2012-02-14 02:10:47 -06:00
|
|
|
Args.len() as c_uint, Then, Catch,
|
2012-01-10 15:26:21 -06:00
|
|
|
noname());
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FastInvoke(cx: block, Fn: ValueRef, Args: ~[ValueRef],
|
|
|
|
Then: BasicBlockRef, Catch: BasicBlockRef) {
|
2012-08-01 19:30:05 -05:00
|
|
|
if cx.unreachable { return; }
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "FastInvoke");
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2012-08-14 18:45:43 -05:00
|
|
|
count_insn(cx, "fastinvoke");
|
2012-09-12 19:45:23 -05:00
|
|
|
let v = llvm::LLVMBuildInvoke(B(cx), Fn, vec::raw::to_ptr(Args),
|
2012-02-14 02:10:47 -06:00
|
|
|
Args.len() as c_uint,
|
2012-01-16 04:21:01 -06:00
|
|
|
Then, Catch, noname());
|
2012-02-01 04:04:56 -06:00
|
|
|
lib::llvm::SetInstructionCallConv(v, lib::llvm::FastCallConv);
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-09-07 13:46:53 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Unreachable(cx: block) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
|
|
|
cx.unreachable = true;
|
|
|
|
if !cx.terminated {
|
|
|
|
count_insn(cx, "unreachable");
|
|
|
|
llvm::LLVMBuildUnreachable(B(cx));
|
|
|
|
}
|
2012-03-22 15:44:20 -05:00
|
|
|
}
|
2011-09-21 05:40:27 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn _Undef(val: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
return llvm::LLVMGetUndef(val_ty(val));
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Arithmetic */
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Add(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "add");
|
|
|
|
return llvm::LLVMBuildAdd(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn NSWAdd(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "nswadd");
|
|
|
|
return llvm::LLVMBuildNSWAdd(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn NUWAdd(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "nuwadd");
|
|
|
|
return llvm::LLVMBuildNUWAdd(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FAdd(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "fadd");
|
|
|
|
return llvm::LLVMBuildFAdd(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Sub(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "sub");
|
|
|
|
return llvm::LLVMBuildSub(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn NSWSub(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "nwsub");
|
|
|
|
return llvm::LLVMBuildNSWSub(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn NUWSub(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "nuwsub");
|
|
|
|
return llvm::LLVMBuildNUWSub(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FSub(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "sub");
|
|
|
|
return llvm::LLVMBuildFSub(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Mul(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "mul");
|
|
|
|
return llvm::LLVMBuildMul(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn NSWMul(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "nswmul");
|
|
|
|
return llvm::LLVMBuildNSWMul(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn NUWMul(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "nuwmul");
|
|
|
|
return llvm::LLVMBuildNUWMul(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FMul(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "fmul");
|
|
|
|
return llvm::LLVMBuildFMul(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn UDiv(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "udiv");
|
|
|
|
return llvm::LLVMBuildUDiv(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn SDiv(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "sdiv");
|
|
|
|
return llvm::LLVMBuildSDiv(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn ExactSDiv(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "extractsdiv");
|
|
|
|
return llvm::LLVMBuildExactSDiv(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FDiv(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "fdiv");
|
|
|
|
return llvm::LLVMBuildFDiv(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn URem(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "urem");
|
|
|
|
return llvm::LLVMBuildURem(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn SRem(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "srem");
|
|
|
|
return llvm::LLVMBuildSRem(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FRem(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "frem");
|
|
|
|
return llvm::LLVMBuildFRem(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Shl(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "shl");
|
|
|
|
return llvm::LLVMBuildShl(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn LShr(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "lshr");
|
|
|
|
return llvm::LLVMBuildLShr(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn AShr(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "ashr");
|
|
|
|
return llvm::LLVMBuildAShr(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn And(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "and");
|
|
|
|
return llvm::LLVMBuildAnd(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Or(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "or");
|
|
|
|
return llvm::LLVMBuildOr(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Xor(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "xor");
|
|
|
|
return llvm::LLVMBuildXor(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn BinOp(cx: block, Op: Opcode, LHS: ValueRef, RHS: ValueRef)
|
|
|
|
-> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
count_insn(cx, "binop");
|
|
|
|
return llvm::LLVMBuildBinOp(B(cx), Op, LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Neg(cx: block, V: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
count_insn(cx, "neg");
|
|
|
|
return llvm::LLVMBuildNeg(B(cx), V, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn NSWNeg(cx: block, V: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
count_insn(cx, "nswneg");
|
|
|
|
return llvm::LLVMBuildNSWNeg(B(cx), V, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn NUWNeg(cx: block, V: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
count_insn(cx, "nuwneg");
|
|
|
|
return llvm::LLVMBuildNUWNeg(B(cx), V, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FNeg(cx: block, V: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
count_insn(cx, "fneg");
|
|
|
|
return llvm::LLVMBuildFNeg(B(cx), V, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
2011-08-26 17:36:18 -05:00
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Not(cx: block, V: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
count_insn(cx, "not");
|
|
|
|
return llvm::LLVMBuildNot(B(cx), V, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Memory */
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Malloc(cx: block, Ty: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(T_i8())); }
|
|
|
|
count_insn(cx, "malloc");
|
|
|
|
return llvm::LLVMBuildMalloc(B(cx), Ty, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn ArrayMalloc(cx: block, Ty: TypeRef, Val: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(T_i8())); }
|
|
|
|
count_insn(cx, "arraymalloc");
|
|
|
|
return llvm::LLVMBuildArrayMalloc(B(cx), Ty, Val, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Alloca(cx: block, Ty: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(Ty)); }
|
|
|
|
count_insn(cx, "alloca");
|
|
|
|
return llvm::LLVMBuildAlloca(B(cx), Ty, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn ArrayAlloca(cx: block, Ty: TypeRef, Val: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(Ty)); }
|
|
|
|
count_insn(cx, "arrayalloca");
|
|
|
|
return llvm::LLVMBuildArrayAlloca(B(cx), Ty, Val, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Free(cx: block, PointerVal: ValueRef) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
|
|
|
count_insn(cx, "free");
|
|
|
|
llvm::LLVMBuildFree(B(cx), PointerVal);
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Load(cx: block, PointerVal: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
let ccx = cx.fcx.ccx;
|
|
|
|
if cx.unreachable {
|
|
|
|
let ty = val_ty(PointerVal);
|
|
|
|
let eltty = if llvm::LLVMGetTypeKind(ty) == lib::llvm::Array {
|
|
|
|
llvm::LLVMGetElementType(ty) } else { ccx.int_type };
|
|
|
|
return llvm::LLVMGetUndef(eltty);
|
|
|
|
}
|
|
|
|
count_insn(cx, "load");
|
|
|
|
return llvm::LLVMBuildLoad(B(cx), PointerVal, noname());
|
2011-09-21 05:40:27 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Store(cx: block, Val: ValueRef, Ptr: ValueRef) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
|
|
|
debug!("Store %s -> %s",
|
|
|
|
val_str(cx.ccx().tn, Val),
|
|
|
|
val_str(cx.ccx().tn, Ptr));
|
|
|
|
count_insn(cx, "store");
|
|
|
|
llvm::LLVMBuildStore(B(cx), Val, Ptr);
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn GEP(cx: block, Pointer: ValueRef, Indices: ~[ValueRef]) -> ValueRef {
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2013-01-10 23:23:07 -06:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(T_nil())); }
|
|
|
|
count_insn(cx, "gep");
|
|
|
|
return llvm::LLVMBuildGEP(B(cx), Pointer, vec::raw::to_ptr(Indices),
|
|
|
|
Indices.len() as c_uint, noname());
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2011-10-26 00:23:28 -05:00
|
|
|
// Simple wrapper around GEP that takes an array of ints and wraps them
|
|
|
|
// in C_i32()
|
2012-08-27 14:16:37 -05:00
|
|
|
//
|
|
|
|
// XXX: Use a small-vector optimization to avoid allocations here.
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn GEPi(cx: block, base: ValueRef, ixs: &[uint]) -> ValueRef {
|
2012-10-18 10:03:04 -05:00
|
|
|
let v = do vec::map(ixs) |i| { C_i32(*i as i32) };
|
2012-08-14 18:45:43 -05:00
|
|
|
count_insn(cx, "gepi");
|
2012-08-01 19:30:05 -05:00
|
|
|
return InBoundsGEP(cx, base, v);
|
2011-10-26 00:23:28 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn InBoundsGEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) ->
|
2011-09-02 17:34:58 -05:00
|
|
|
ValueRef {
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2013-01-10 23:23:07 -06:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(T_nil())); }
|
|
|
|
unsafe {
|
|
|
|
count_insn(cx, "inboundsgep");
|
|
|
|
return llvm::LLVMBuildInBoundsGEP(B(cx), Pointer,
|
|
|
|
vec::raw::to_ptr(Indices),
|
|
|
|
Indices.len() as c_uint,
|
|
|
|
noname());
|
|
|
|
}
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn StructGEP(cx: block, Pointer: ValueRef, Idx: uint) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(T_nil())); }
|
|
|
|
count_insn(cx, "structgep");
|
|
|
|
return llvm::LLVMBuildStructGEP(B(cx),
|
|
|
|
Pointer,
|
|
|
|
Idx as c_uint,
|
|
|
|
noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn GlobalString(cx: block, _Str: *libc::c_char) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(T_i8())); }
|
|
|
|
count_insn(cx, "globalstring");
|
|
|
|
return llvm::LLVMBuildGlobalString(B(cx), _Str, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn GlobalStringPtr(cx: block, _Str: *libc::c_char) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(T_i8())); }
|
|
|
|
count_insn(cx, "globalstringptr");
|
|
|
|
return llvm::LLVMBuildGlobalStringPtr(B(cx), _Str, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Casts */
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Trunc(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "trunc");
|
|
|
|
return llvm::LLVMBuildTrunc(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn ZExt(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "zext");
|
|
|
|
return llvm::LLVMBuildZExt(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn SExt(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "sext");
|
|
|
|
return llvm::LLVMBuildSExt(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FPToUI(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "fptoui");
|
|
|
|
return llvm::LLVMBuildFPToUI(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FPToSI(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "fptosi");
|
|
|
|
return llvm::LLVMBuildFPToSI(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn UIToFP(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "uitofp");
|
|
|
|
return llvm::LLVMBuildUIToFP(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn SIToFP(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "sitofp");
|
|
|
|
return llvm::LLVMBuildSIToFP(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FPTrunc(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "fptrunc");
|
|
|
|
return llvm::LLVMBuildFPTrunc(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FPExt(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "fpext");
|
|
|
|
return llvm::LLVMBuildFPExt(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn PtrToInt(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "ptrtoint");
|
|
|
|
return llvm::LLVMBuildPtrToInt(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn IntToPtr(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "inttoptr");
|
|
|
|
return llvm::LLVMBuildIntToPtr(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn BitCast(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "bitcast");
|
|
|
|
return llvm::LLVMBuildBitCast(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn ZExtOrBitCast(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "zextorbitcast");
|
|
|
|
return llvm::LLVMBuildZExtOrBitCast(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn SExtOrBitCast(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "sextorbitcast");
|
|
|
|
return llvm::LLVMBuildSExtOrBitCast(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn TruncOrBitCast(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "truncorbitcast");
|
|
|
|
return llvm::LLVMBuildTruncOrBitCast(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Cast(cx: block, Op: Opcode, Val: ValueRef, DestTy: TypeRef, _: *u8)
|
2013-01-10 23:23:07 -06:00
|
|
|
-> ValueRef {
|
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "cast");
|
|
|
|
return llvm::LLVMBuildCast(B(cx), Op, Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn PointerCast(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "pointercast");
|
|
|
|
return llvm::LLVMBuildPointerCast(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn IntCast(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "intcast");
|
|
|
|
return llvm::LLVMBuildIntCast(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FPCast(cx: block, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy); }
|
|
|
|
count_insn(cx, "fpcast");
|
|
|
|
return llvm::LLVMBuildFPCast(B(cx), Val, DestTy, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Comparisons */
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn ICmp(cx: block, Op: IntPredicate, LHS: ValueRef, RHS: ValueRef)
|
2013-01-10 23:23:07 -06:00
|
|
|
-> ValueRef {
|
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_i1()); }
|
|
|
|
count_insn(cx, "icmp");
|
|
|
|
return llvm::LLVMBuildICmp(B(cx), Op as c_uint, LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FCmp(cx: block, Op: RealPredicate, LHS: ValueRef, RHS: ValueRef)
|
2013-01-10 23:23:07 -06:00
|
|
|
-> ValueRef {
|
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_i1()); }
|
|
|
|
count_insn(cx, "fcmp");
|
|
|
|
return llvm::LLVMBuildFCmp(B(cx), Op as c_uint, LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Miscellaneous instructions */
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn EmptyPhi(cx: block, Ty: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Ty); }
|
|
|
|
count_insn(cx, "emptyphi");
|
|
|
|
return llvm::LLVMBuildPhi(B(cx), Ty, noname());
|
|
|
|
}
|
2011-09-23 14:13:50 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Phi(cx: block, Ty: TypeRef, vals: ~[ValueRef], bbs: ~[BasicBlockRef])
|
2013-01-10 23:23:07 -06:00
|
|
|
-> ValueRef {
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2013-01-10 23:23:07 -06:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Ty); }
|
|
|
|
assert vals.len() == bbs.len();
|
|
|
|
let phi = EmptyPhi(cx, Ty);
|
2012-08-14 18:45:43 -05:00
|
|
|
count_insn(cx, "addincoming");
|
2012-09-12 19:45:23 -05:00
|
|
|
llvm::LLVMAddIncoming(phi, vec::raw::to_ptr(vals),
|
|
|
|
vec::raw::to_ptr(bbs),
|
2012-02-14 02:10:47 -06:00
|
|
|
vals.len() as c_uint);
|
2012-08-01 19:30:05 -05:00
|
|
|
return phi;
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
|
2011-10-28 16:19:17 -05:00
|
|
|
unsafe {
|
2013-01-10 23:23:07 -06:00
|
|
|
if llvm::LLVMIsUndef(phi) == lib::llvm::True { return; }
|
2012-10-01 14:47:02 -05:00
|
|
|
let valptr = cast::reinterpret_cast(&ptr::addr_of(&val));
|
|
|
|
let bbptr = cast::reinterpret_cast(&ptr::addr_of(&bb));
|
2012-01-18 05:29:37 -06:00
|
|
|
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint);
|
2011-10-28 16:19:17 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn _UndefReturn(cx: block, Fn: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
let ccx = cx.fcx.ccx;
|
|
|
|
let ty = val_ty(Fn);
|
|
|
|
let retty = if llvm::LLVMGetTypeKind(ty) == lib::llvm::Integer {
|
|
|
|
llvm::LLVMGetReturnType(ty) } else { ccx.int_type };
|
|
|
|
count_insn(cx, ~"");
|
|
|
|
return llvm::LLVMGetUndef(retty);
|
|
|
|
}
|
2011-09-21 05:40:27 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn add_span_comment(bcx: block, sp: span, text: ~str) {
|
2012-02-21 07:20:18 -06:00
|
|
|
let ccx = bcx.ccx();
|
2012-05-17 23:53:49 -05:00
|
|
|
if !ccx.sess.no_asm_comments() {
|
2012-11-12 20:24:56 -06:00
|
|
|
let s = text + ~" (" + ccx.sess.codemap.span_to_str(sp)
|
2012-07-14 00:57:48 -05:00
|
|
|
+ ~")";
|
2013-01-07 16:16:52 -06:00
|
|
|
log(debug, copy s);
|
2011-12-18 22:32:38 -06:00
|
|
|
add_comment(bcx, s);
|
2011-11-14 16:03:20 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn add_comment(bcx: block, text: ~str) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
let ccx = bcx.ccx();
|
|
|
|
if !ccx.sess.no_asm_comments() {
|
|
|
|
let sanitized = str::replace(text, ~"$", ~"");
|
|
|
|
let comment_text = ~"# " +
|
|
|
|
str::replace(sanitized, ~"\n", ~"\n\t# ");
|
|
|
|
let asm = str::as_c_str(comment_text, |c| {
|
|
|
|
str::as_c_str(~"", |e| {
|
|
|
|
count_insn(bcx, ~"inlineasm");
|
|
|
|
llvm::LLVMConstInlineAsm(T_fn(~[], T_void()), c, e,
|
|
|
|
False, False)
|
|
|
|
})
|
|
|
|
});
|
|
|
|
Call(bcx, asm, ~[]);
|
|
|
|
}
|
2011-11-14 16:03:20 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Call(cx: block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
|
2012-08-01 19:30:05 -05:00
|
|
|
if cx.unreachable { return _UndefReturn(cx, Fn); }
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2012-08-14 18:45:43 -05:00
|
|
|
count_insn(cx, "call");
|
2012-05-18 21:02:39 -05:00
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("Call(Fn=%s, Args=%?)",
|
2012-05-18 21:02:39 -05:00
|
|
|
val_str(cx.ccx().tn, Fn),
|
2012-09-21 20:43:30 -05:00
|
|
|
Args.map(|arg| val_str(cx.ccx().tn, *arg)));
|
2012-05-18 21:02:39 -05:00
|
|
|
|
2012-09-13 13:46:10 -05:00
|
|
|
do vec::as_imm_buf(Args) |ptr, len| {
|
2012-08-28 17:54:45 -05:00
|
|
|
llvm::LLVMBuildCall(B(cx), Fn, ptr, len as c_uint, noname())
|
|
|
|
}
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn FastCall(cx: block, Fn: ValueRef, Args: ~[ValueRef]) -> ValueRef {
|
2012-08-01 19:30:05 -05:00
|
|
|
if cx.unreachable { return _UndefReturn(cx, Fn); }
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2012-08-14 18:45:43 -05:00
|
|
|
count_insn(cx, "fastcall");
|
2012-09-12 19:45:23 -05:00
|
|
|
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::raw::to_ptr(Args),
|
2012-02-14 02:10:47 -06:00
|
|
|
Args.len() as c_uint, noname());
|
2012-02-01 04:04:56 -06:00
|
|
|
lib::llvm::SetInstructionCallConv(v, lib::llvm::FastCallConv);
|
2012-08-01 19:30:05 -05:00
|
|
|
return v;
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn CallWithConv(cx: block, Fn: ValueRef, Args: ~[ValueRef],
|
|
|
|
Conv: CallConv) -> ValueRef {
|
2012-08-01 19:30:05 -05:00
|
|
|
if cx.unreachable { return _UndefReturn(cx, Fn); }
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2012-08-14 18:45:43 -05:00
|
|
|
count_insn(cx, "callwithconv");
|
2012-09-12 19:45:23 -05:00
|
|
|
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::raw::to_ptr(Args),
|
2012-02-14 02:10:47 -06:00
|
|
|
Args.len() as c_uint, noname());
|
2012-02-01 04:04:56 -06:00
|
|
|
lib::llvm::SetInstructionCallConv(v, Conv);
|
2012-08-01 19:30:05 -05:00
|
|
|
return v;
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Select(cx: block, If: ValueRef, Then: ValueRef, Else: ValueRef) ->
|
2011-09-02 17:34:58 -05:00
|
|
|
ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return _Undef(Then); }
|
|
|
|
count_insn(cx, "select");
|
|
|
|
return llvm::LLVMBuildSelect(B(cx), If, Then, Else, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn VAArg(cx: block, list: ValueRef, Ty: TypeRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Ty); }
|
|
|
|
count_insn(cx, "vaarg");
|
|
|
|
return llvm::LLVMBuildVAArg(B(cx), list, Ty, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn ExtractElement(cx: block, VecVal: ValueRef, Index: ValueRef) ->
|
2011-09-02 17:34:58 -05:00
|
|
|
ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_nil()); }
|
|
|
|
count_insn(cx, "extractelement");
|
|
|
|
return llvm::LLVMBuildExtractElement(B(cx), VecVal, Index, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn InsertElement(cx: block, VecVal: ValueRef, EltVal: ValueRef,
|
2011-09-21 05:40:27 -05:00
|
|
|
Index: ValueRef) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
|
|
|
count_insn(cx, "insertelement");
|
|
|
|
llvm::LLVMBuildInsertElement(B(cx), VecVal, EltVal, Index, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn ShuffleVector(cx: block, V1: ValueRef, V2: ValueRef,
|
|
|
|
Mask: ValueRef) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
|
|
|
count_insn(cx, "shufflevector");
|
|
|
|
llvm::LLVMBuildShuffleVector(B(cx), V1, V2, Mask, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn ExtractValue(cx: block, AggVal: ValueRef, Index: uint) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_nil()); }
|
|
|
|
count_insn(cx, "extractvalue");
|
|
|
|
return llvm::LLVMBuildExtractValue(
|
|
|
|
B(cx), AggVal, Index as c_uint, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn InsertValue(cx: block, AggVal: ValueRef, EltVal: ValueRef,
|
|
|
|
Index: uint) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return; }
|
|
|
|
count_insn(cx, "insertvalue");
|
|
|
|
llvm::LLVMBuildInsertValue(B(cx), AggVal, EltVal, Index as c_uint,
|
|
|
|
noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn IsNull(cx: block, Val: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_i1()); }
|
|
|
|
count_insn(cx, "isnull");
|
|
|
|
return llvm::LLVMBuildIsNull(B(cx), Val, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn IsNotNull(cx: block, Val: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(T_i1()); }
|
|
|
|
count_insn(cx, "isnotnull");
|
|
|
|
return llvm::LLVMBuildIsNotNull(B(cx), Val, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn PtrDiff(cx: block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
let ccx = cx.fcx.ccx;
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(ccx.int_type); }
|
|
|
|
count_insn(cx, "ptrdiff");
|
|
|
|
return llvm::LLVMBuildPtrDiff(B(cx), LHS, RHS, noname());
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Trap(cx: block) {
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2013-01-10 23:23:07 -06:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
let b = B(cx);
|
|
|
|
let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(b);
|
|
|
|
let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB);
|
|
|
|
let M: ModuleRef = llvm::LLVMGetGlobalParent(FN);
|
|
|
|
let T: ValueRef = str::as_c_str(~"llvm.trap", |buf| {
|
|
|
|
llvm::LLVMGetNamedFunction(M, buf)
|
|
|
|
});
|
|
|
|
assert (T as int != 0);
|
|
|
|
let Args: ~[ValueRef] = ~[];
|
|
|
|
unsafe {
|
|
|
|
count_insn(cx, "trap");
|
|
|
|
llvm::LLVMBuildCall(b, T, vec::raw::to_ptr(Args),
|
|
|
|
Args.len() as c_uint, noname());
|
|
|
|
}
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn LandingPad(cx: block, Ty: TypeRef, PersFn: ValueRef,
|
|
|
|
NumClauses: uint) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
assert !cx.unreachable;
|
2013-01-10 23:23:07 -06:00
|
|
|
count_insn(cx, "landingpad");
|
|
|
|
return llvm::LLVMBuildLandingPad(B(cx), Ty, PersFn,
|
|
|
|
NumClauses as c_uint, noname());
|
|
|
|
}
|
2011-09-07 13:58:49 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn SetCleanup(cx: block, LandingPad: ValueRef) {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
count_insn(cx, "setcleanup");
|
|
|
|
llvm::LLVMSetCleanup(LandingPad, lib::llvm::True);
|
|
|
|
}
|
2011-09-07 13:58:49 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn Resume(cx: block, Exn: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-01-11 23:01:42 -06:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "Resume");
|
2013-01-10 23:23:07 -06:00
|
|
|
count_insn(cx, "resume");
|
|
|
|
return llvm::LLVMBuildResume(B(cx), Exn);
|
|
|
|
}
|
2011-09-07 16:28:02 -05:00
|
|
|
}
|
|
|
|
|
2012-06-21 17:01:32 -05:00
|
|
|
// Atomic Operations
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn AtomicCmpXchg(cx: block, dst: ValueRef,
|
|
|
|
cmp: ValueRef, src: ValueRef,
|
|
|
|
order: AtomicOrdering) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
llvm::LLVMBuildAtomicCmpXchg(B(cx), dst, cmp, src, order)
|
|
|
|
}
|
2012-10-21 21:23:50 -05:00
|
|
|
}
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn AtomicRMW(cx: block, op: AtomicBinOp,
|
|
|
|
dst: ValueRef, src: ValueRef,
|
|
|
|
order: AtomicOrdering) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
llvm::LLVMBuildAtomicRMW(B(cx), op, dst, src, order)
|
|
|
|
}
|
2012-06-21 17:01:32 -05:00
|
|
|
}
|
|
|
|
|
2011-08-24 07:54:55 -05:00
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|
|
|
|
//
|