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-05-17 17:28:44 -05:00
|
|
|
|
2012-12-13 15:05:22 -06:00
|
|
|
use lib::llvm::llvm;
|
2013-03-26 15:38:07 -05:00
|
|
|
use lib::llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect};
|
2013-07-21 08:33:40 -05:00
|
|
|
use lib::llvm::{Opcode, IntPredicate, RealPredicate};
|
|
|
|
use lib::llvm::{ValueRef, BasicBlockRef};
|
2013-03-01 12:44:43 -06:00
|
|
|
use lib;
|
2012-12-13 15:05:22 -06:00
|
|
|
use middle::trans::common::*;
|
2013-08-31 11:13:04 -05:00
|
|
|
use syntax::codemap::Span;
|
2012-12-13 15:05:22 -06:00
|
|
|
|
2013-07-21 08:33:40 -05:00
|
|
|
use middle::trans::builder::Builder;
|
2013-06-16 05:52:44 -05:00
|
|
|
use middle::trans::type_::Type;
|
|
|
|
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::cast;
|
|
|
|
use std::libc::{c_uint, c_ulonglong, c_char};
|
2011-08-24 07:54:55 -05:00
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn terminate(cx: @mut Block, _: &str) {
|
2013-04-09 01:07:50 -05:00
|
|
|
cx.terminated = true;
|
2013-01-11 23:01:42 -06:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn check_not_terminated(cx: @mut Block) {
|
2013-01-11 23:01:42 -06:00
|
|
|
if cx.terminated {
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("already terminated!");
|
2013-01-11 23:01:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn B(cx: @mut Block) -> Builder {
|
2013-07-21 08:33:40 -05:00
|
|
|
let b = cx.fcx.ccx.builder();
|
|
|
|
b.position_at_end(cx.llbb);
|
|
|
|
b
|
2012-03-22 15:44:20 -05:00
|
|
|
}
|
|
|
|
|
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-07-17 05:12:08 -05:00
|
|
|
pub fn RetVoid(cx: @mut Block) {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "RetVoid");
|
|
|
|
B(cx).ret_void();
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Ret(cx: @mut Block, V: ValueRef) {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "Ret");
|
|
|
|
B(cx).ret(V);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn AggregateRet(cx: @mut 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");
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).aggregate_ret(RetVals);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Br(cx: @mut Block, Dest: BasicBlockRef) {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "Br");
|
|
|
|
B(cx).br(Dest);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn CondBr(cx: @mut Block, If: ValueRef, Then: BasicBlockRef,
|
2013-01-30 13:46:19 -06:00
|
|
|
Else: BasicBlockRef) {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "CondBr");
|
|
|
|
B(cx).cond_br(If, Then, Else);
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Switch(cx: @mut Block, V: ValueRef, Else: BasicBlockRef, NumCases: uint)
|
2011-09-21 05:40:27 -05:00
|
|
|
-> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "Switch");
|
|
|
|
B(cx).switch(V, Else, NumCases)
|
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-07-17 05:12:08 -05:00
|
|
|
pub fn IndirectBr(cx: @mut Block, Addr: ValueRef, NumDests: uint) {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "IndirectBr");
|
|
|
|
B(cx).indirect_br(Addr, NumDests);
|
2011-09-21 10:46:11 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Invoke(cx: @mut Block,
|
2013-04-18 17:53:29 -05:00
|
|
|
Fn: ValueRef,
|
|
|
|
Args: &[ValueRef],
|
|
|
|
Then: BasicBlockRef,
|
2013-09-16 17:30:59 -05:00
|
|
|
Catch: BasicBlockRef,
|
|
|
|
attributes: &[(uint, lib::llvm::Attribute)])
|
2013-04-18 17:53:29 -05:00
|
|
|
-> ValueRef {
|
|
|
|
if cx.unreachable {
|
2013-06-15 09:29:52 -05:00
|
|
|
return C_null(Type::i8());
|
2013-04-18 17:53:29 -05:00
|
|
|
}
|
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))",
|
2013-06-14 22:16:03 -05:00
|
|
|
cx.val_to_str(Fn),
|
|
|
|
Args.map(|a| cx.val_to_str(*a)).connect(", "));
|
2013-09-16 17:30:59 -05:00
|
|
|
B(cx).invoke(Fn, Args, Then, Catch, attributes)
|
2011-09-07 13:46:53 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Unreachable(cx: @mut Block) {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
cx.unreachable = true;
|
|
|
|
if !cx.terminated {
|
|
|
|
B(cx).unreachable();
|
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 {
|
2013-06-16 05:52:44 -05:00
|
|
|
return llvm::LLVMGetUndef(val_ty(val).to_ref());
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Arithmetic */
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Add(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).add(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn NSWAdd(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).nswadd(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn NUWAdd(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).nuwadd(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FAdd(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).fadd(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Sub(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).sub(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn NSWSub(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).nswsub(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn NUWSub(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).nuwsub(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FSub(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).fsub(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Mul(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).mul(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn NSWMul(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).nswmul(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn NUWMul(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).nuwmul(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FMul(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).fmul(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn UDiv(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).udiv(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn SDiv(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).sdiv(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn ExactSDiv(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).exactsdiv(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FDiv(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).fdiv(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn URem(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).urem(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn SRem(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).srem(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FRem(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).frem(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Shl(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).shl(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn LShr(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).lshr(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn AShr(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).ashr(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn And(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).and(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Or(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).or(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Xor(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).xor(LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn BinOp(cx: @mut Block, Op: Opcode, LHS: ValueRef, RHS: ValueRef)
|
2013-01-30 13:46:19 -06:00
|
|
|
-> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(LHS); }
|
|
|
|
B(cx).binop(Op, LHS, RHS)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Neg(cx: @mut Block, V: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
B(cx).neg(V)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn NSWNeg(cx: @mut Block, V: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
B(cx).nswneg(V)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn NUWNeg(cx: @mut Block, V: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
B(cx).nuwneg(V)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FNeg(cx: @mut Block, V: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
B(cx).fneg(V)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
2011-08-26 17:36:18 -05:00
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Not(cx: @mut Block, V: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(V); }
|
|
|
|
B(cx).not(V)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Memory */
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Malloc(cx: @mut Block, Ty: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::i8p().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).malloc(Ty)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn ArrayMalloc(cx: @mut Block, Ty: Type, Val: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::i8p().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).array_malloc(Ty, Val)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Alloca(cx: @mut Block, Ty: Type, name: &str) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-16 05:52:44 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Ty.ptr_to().to_ref()); }
|
2013-07-21 09:19:34 -05:00
|
|
|
let b = cx.fcx.ccx.builder();
|
2013-08-03 18:59:24 -05:00
|
|
|
b.position_before(cx.fcx.alloca_insert_pt.unwrap());
|
2013-07-21 09:19:34 -05:00
|
|
|
b.alloca(Ty, name)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn ArrayAlloca(cx: @mut Block, Ty: Type, Val: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-16 05:52:44 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Ty.ptr_to().to_ref()); }
|
2013-07-21 09:19:34 -05:00
|
|
|
let b = cx.fcx.ccx.builder();
|
2013-08-03 18:59:24 -05:00
|
|
|
b.position_before(cx.fcx.alloca_insert_pt.unwrap());
|
2013-07-21 09:19:34 -05:00
|
|
|
b.array_alloca(Ty, Val)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Free(cx: @mut Block, PointerVal: ValueRef) {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
B(cx).free(PointerVal)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Load(cx: @mut 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);
|
2013-06-16 05:52:44 -05:00
|
|
|
let eltty = if ty.kind() == lib::llvm::Array {
|
|
|
|
ty.element_type()
|
|
|
|
} else {
|
|
|
|
ccx.int_type
|
|
|
|
};
|
|
|
|
return llvm::LLVMGetUndef(eltty.to_ref());
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).load(PointerVal)
|
2011-09-21 05:40:27 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn AtomicLoad(cx: @mut Block, PointerVal: ValueRef, order: AtomicOrdering) -> ValueRef {
|
2013-05-12 14:22:20 -05:00
|
|
|
unsafe {
|
|
|
|
let ccx = cx.fcx.ccx;
|
|
|
|
if cx.unreachable {
|
2013-06-16 05:52:44 -05:00
|
|
|
return llvm::LLVMGetUndef(ccx.int_type.to_ref());
|
2013-05-12 14:22:20 -05:00
|
|
|
}
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).atomic_load(PointerVal, order)
|
2013-05-12 14:22:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn LoadRangeAssert(cx: @mut Block, PointerVal: ValueRef, lo: c_ulonglong,
|
2013-02-19 13:55:40 -06:00
|
|
|
hi: c_ulonglong, signed: lib::llvm::Bool) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable {
|
|
|
|
let ccx = cx.fcx.ccx;
|
|
|
|
let ty = val_ty(PointerVal);
|
|
|
|
let eltty = if ty.kind() == lib::llvm::Array {
|
|
|
|
ty.element_type()
|
|
|
|
} else {
|
|
|
|
ccx.int_type
|
|
|
|
};
|
2013-07-17 03:13:23 -05:00
|
|
|
unsafe {
|
2013-07-21 08:33:40 -05:00
|
|
|
llvm::LLVMGetUndef(eltty.to_ref())
|
2013-02-19 13:55:40 -06:00
|
|
|
}
|
2013-07-21 08:33:40 -05:00
|
|
|
} else {
|
|
|
|
B(cx).load_range_assert(PointerVal, lo, hi, signed)
|
2013-02-19 13:55:40 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Store(cx: @mut Block, Val: ValueRef, Ptr: ValueRef) {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
B(cx).store(Val, Ptr)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn AtomicStore(cx: @mut Block, Val: ValueRef, Ptr: ValueRef, order: AtomicOrdering) {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
B(cx).atomic_store(Val, Ptr, order)
|
2013-05-12 14:22:20 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn GEP(cx: @mut Block, Pointer: ValueRef, Indices: &[ValueRef]) -> ValueRef {
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).gep(Pointer, Indices)
|
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()
|
2013-06-07 21:59:32 -05:00
|
|
|
#[inline]
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn GEPi(cx: @mut Block, base: ValueRef, ixs: &[uint]) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref()); }
|
|
|
|
B(cx).gepi(base, ixs)
|
2013-06-07 21:59:32 -05:00
|
|
|
}
|
2011-10-26 00:23:28 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn InBoundsGEP(cx: @mut Block, Pointer: ValueRef, Indices: &[ValueRef]) -> ValueRef {
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).inbounds_gep(Pointer, Indices)
|
2011-10-07 14:05:38 -05:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn StructGEP(cx: @mut Block, Pointer: ValueRef, Idx: uint) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).struct_gep(Pointer, Idx)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn GlobalString(cx: @mut Block, _Str: *c_char) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-16 05:52:44 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::i8p().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).global_string(_Str)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn GlobalStringPtr(cx: @mut Block, _Str: *c_char) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-16 05:52:44 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::i8p().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).global_string_ptr(_Str)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Casts */
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Trunc(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).trunc(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn ZExt(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).zext(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn SExt(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).sext(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FPToUI(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).fptoui(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FPToSI(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).fptosi(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn UIToFP(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).uitofp(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn SIToFP(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).sitofp(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FPTrunc(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).fptrunc(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FPExt(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).fpext(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn PtrToInt(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).ptrtoint(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn IntToPtr(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).inttoptr(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn BitCast(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).bitcast(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn ZExtOrBitCast(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).zext_or_bitcast(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn SExtOrBitCast(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).sext_or_bitcast(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn TruncOrBitCast(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).trunc_or_bitcast(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Cast(cx: @mut Block, Op: Opcode, Val: ValueRef, DestTy: Type, _: *u8)
|
2013-01-10 23:23:07 -06:00
|
|
|
-> ValueRef {
|
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).cast(Op, Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn PointerCast(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).pointercast(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn IntCast(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).intcast(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FPCast(cx: @mut Block, Val: ValueRef, DestTy: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(DestTy.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).fpcast(Val, DestTy)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Comparisons */
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn ICmp(cx: @mut Block, Op: IntPredicate, LHS: ValueRef, RHS: ValueRef)
|
2013-01-10 23:23:07 -06:00
|
|
|
-> ValueRef {
|
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::i1().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).icmp(Op, LHS, RHS)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn FCmp(cx: @mut Block, Op: RealPredicate, LHS: ValueRef, RHS: ValueRef)
|
2013-01-10 23:23:07 -06:00
|
|
|
-> ValueRef {
|
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::i1().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).fcmp(Op, LHS, RHS)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Miscellaneous instructions */
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn EmptyPhi(cx: @mut Block, Ty: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Ty.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).empty_phi(Ty)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-09-23 14:13:50 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Phi(cx: @mut Block, Ty: Type, vals: &[ValueRef], bbs: &[BasicBlockRef]) -> ValueRef {
|
2011-10-07 14:05:38 -05:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Ty.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).phi(Ty, vals, bbs)
|
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; }
|
2013-04-22 16:27:30 -05:00
|
|
|
let valptr = cast::transmute(&val);
|
|
|
|
let bbptr = cast::transmute(&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-07-17 05:12:08 -05:00
|
|
|
pub fn _UndefReturn(cx: @mut Block, Fn: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
let ccx = cx.fcx.ccx;
|
|
|
|
let ty = val_ty(Fn);
|
2013-06-16 05:52:44 -05:00
|
|
|
let retty = if ty.kind() == lib::llvm::Integer {
|
|
|
|
ty.return_type()
|
|
|
|
} else {
|
|
|
|
ccx.int_type
|
|
|
|
};
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).count_insn("ret_undef");
|
|
|
|
llvm::LLVMGetUndef(retty.to_ref())
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-09-21 05:40:27 -05:00
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
pub fn add_span_comment(cx: @mut Block, sp: Span, text: &str) {
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).add_span_comment(sp, text)
|
2011-11-14 16:03:20 -06:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn add_comment(cx: @mut Block, text: &str) {
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).add_comment(text)
|
2011-11-14 16:03:20 -06:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn InlineAsmCall(cx: @mut Block, asm: *c_char, cons: *c_char,
|
2013-06-15 09:29:52 -05:00
|
|
|
inputs: &[ValueRef], output: Type,
|
2013-03-12 03:02:58 -05:00
|
|
|
volatile: bool, alignstack: bool,
|
|
|
|
dia: AsmDialect) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).inline_asm_call(asm, cons, inputs, output, volatile, alignstack, dia)
|
2013-03-10 00:37:50 -06:00
|
|
|
}
|
|
|
|
|
2013-09-12 23:14:17 -05:00
|
|
|
pub fn Call(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef],
|
|
|
|
attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
|
2012-08-01 19:30:05 -05:00
|
|
|
if cx.unreachable { return _UndefReturn(cx, Fn); }
|
2013-09-12 23:14:17 -05:00
|
|
|
B(cx).call(Fn, Args, attributes)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-09-12 23:14:17 -05:00
|
|
|
pub fn CallWithConv(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef], Conv: CallConv,
|
|
|
|
attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
|
2012-08-01 19:30:05 -05:00
|
|
|
if cx.unreachable { return _UndefReturn(cx, Fn); }
|
2013-09-12 23:14:17 -05:00
|
|
|
B(cx).call_with_conv(Fn, Args, Conv, attributes)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-28 02:48:16 -05:00
|
|
|
pub fn AtomicFence(cx: @mut Block, order: AtomicOrdering) {
|
|
|
|
if cx.unreachable { return; }
|
|
|
|
B(cx).atomic_fence(order)
|
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Select(cx: @mut Block, If: ValueRef, Then: ValueRef, Else: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return _Undef(Then); }
|
|
|
|
B(cx).select(If, Then, Else)
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn VAArg(cx: @mut Block, list: ValueRef, Ty: Type) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Ty.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).va_arg(list, Ty)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn ExtractElement(cx: @mut Block, VecVal: ValueRef, Index: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).extract_element(VecVal, Index)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn InsertElement(cx: @mut Block, VecVal: ValueRef, EltVal: ValueRef,
|
2013-05-02 02:59:26 -05:00
|
|
|
Index: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).insert_element(VecVal, EltVal, Index)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn ShuffleVector(cx: @mut Block, V1: ValueRef, V2: ValueRef,
|
2013-05-02 02:59:26 -05:00
|
|
|
Mask: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).shuffle_vector(V1, V2, Mask)
|
2013-05-02 02:59:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn VectorSplat(cx: @mut Block, NumElts: uint, EltVal: ValueRef) -> ValueRef {
|
2013-05-02 02:59:26 -05:00
|
|
|
unsafe {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
|
|
|
|
B(cx).vector_splat(NumElts, EltVal)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn ExtractValue(cx: @mut Block, AggVal: ValueRef, Index: uint) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).extract_value(AggVal, Index)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn InsertValue(cx: @mut Block, AggVal: ValueRef, EltVal: ValueRef, Index: uint) -> ValueRef {
|
|
|
|
unsafe {
|
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
|
|
|
|
B(cx).insert_value(AggVal, EltVal, Index)
|
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn IsNull(cx: @mut Block, Val: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::i1().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).is_null(Val)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn IsNotNull(cx: @mut Block, Val: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
2013-06-15 09:29:52 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(Type::i1().to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).is_not_null(Val)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn PtrDiff(cx: @mut Block, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
|
2013-01-10 23:23:07 -06:00
|
|
|
unsafe {
|
|
|
|
let ccx = cx.fcx.ccx;
|
2013-06-16 05:52:44 -05:00
|
|
|
if cx.unreachable { return llvm::LLVMGetUndef(ccx.int_type.to_ref()); }
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).ptrdiff(LHS, RHS)
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Trap(cx: @mut Block) {
|
2013-07-21 08:33:40 -05:00
|
|
|
if cx.unreachable { return; }
|
|
|
|
B(cx).trap();
|
2011-08-24 07:54:55 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn LandingPad(cx: @mut Block, Ty: Type, PersFn: ValueRef,
|
2013-01-30 13:46:19 -06:00
|
|
|
NumClauses: uint) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
check_not_terminated(cx);
|
|
|
|
assert!(!cx.unreachable);
|
|
|
|
B(cx).landing_pad(Ty, PersFn, NumClauses)
|
2011-09-07 13:58:49 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn SetCleanup(cx: @mut Block, LandingPad: ValueRef) {
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).set_cleanup(LandingPad)
|
2011-09-07 13:58:49 -05:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn Resume(cx: @mut Block, Exn: ValueRef) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
check_not_terminated(cx);
|
|
|
|
terminate(cx, "Resume");
|
|
|
|
B(cx).resume(Exn)
|
2011-09-07 16:28:02 -05:00
|
|
|
}
|
|
|
|
|
2012-06-21 17:01:32 -05:00
|
|
|
// Atomic Operations
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn AtomicCmpXchg(cx: @mut Block, dst: ValueRef,
|
2013-01-30 13:46:19 -06:00
|
|
|
cmp: ValueRef, src: ValueRef,
|
|
|
|
order: AtomicOrdering) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).atomic_cmpxchg(dst, cmp, src, order)
|
2012-10-21 21:23:50 -05:00
|
|
|
}
|
2013-07-17 05:12:08 -05:00
|
|
|
pub fn AtomicRMW(cx: @mut Block, op: AtomicBinOp,
|
2013-01-30 13:46:19 -06:00
|
|
|
dst: ValueRef, src: ValueRef,
|
|
|
|
order: AtomicOrdering) -> ValueRef {
|
2013-07-21 08:33:40 -05:00
|
|
|
B(cx).atomic_rmw(op, dst, src, order)
|
2012-06-21 17:01:32 -05:00
|
|
|
}
|