Skip to content

Un-revert rusti, fix rusti issues, serialize rustpkg tests #7125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Revert "Revert "Remove all usage of the global LLVMContextRef""
This reverts commit 541c657.
  • Loading branch information
alexcrichton committed Jun 14, 2013
commit 1a3edecbf21eef7f39bbf3a7bf38fb72fdc6af61
71 changes: 7 additions & 64 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,23 +239,21 @@ pub mod llvm {
#[fast_ffi]
pub unsafe fn LLVMContextCreate() -> ContextRef;
#[fast_ffi]
pub unsafe fn LLVMGetGlobalContext() -> ContextRef;
#[fast_ffi]
pub unsafe fn LLVMContextDispose(C: ContextRef);
#[fast_ffi]
pub unsafe fn LLVMGetMDKindIDInContext(C: ContextRef,
Name: *c_char,
SLen: c_uint)
-> c_uint;
#[fast_ffi]
pub unsafe fn LLVMGetMDKindID(Name: *c_char, SLen: c_uint) -> c_uint;

/* Create and destroy modules. */
#[fast_ffi]
pub unsafe fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
C: ContextRef)
-> ModuleRef;
#[fast_ffi]
pub unsafe fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
#[fast_ffi]
pub unsafe fn LLVMDisposeModule(M: ModuleRef);

/** Data layout. See Module::getDataLayout. */
Expand Down Expand Up @@ -300,18 +298,6 @@ pub mod llvm {
pub unsafe fn LLVMIntTypeInContext(C: ContextRef,
NumBits: c_uint) -> TypeRef;

#[fast_ffi]
pub unsafe fn LLVMInt1Type() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMInt8Type() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMInt16Type() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMInt32Type() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMInt64Type() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMIntType(NumBits: c_uint) -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;

Expand All @@ -327,17 +313,6 @@ pub mod llvm {
#[fast_ffi]
pub unsafe fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;

#[fast_ffi]
pub unsafe fn LLVMFloatType() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMDoubleType() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMX86FP80Type() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMFP128Type() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMPPCFP128Type() -> TypeRef;

/* Operations on function types */
#[fast_ffi]
pub unsafe fn LLVMFunctionType(ReturnType: TypeRef,
Expand All @@ -361,11 +336,6 @@ pub mod llvm {
ElementCount: c_uint,
Packed: Bool) -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMStructType(ElementTypes: *TypeRef,
ElementCount: c_uint,
Packed: Bool)
-> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMCountStructElementTypes(StructTy: TypeRef)
-> c_uint;
#[fast_ffi]
Expand Down Expand Up @@ -403,13 +373,6 @@ pub mod llvm {
#[fast_ffi]
pub unsafe fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;

#[fast_ffi]
pub unsafe fn LLVMVoidType() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMLabelType() -> TypeRef;
#[fast_ffi]
pub unsafe fn LLVMMetadataType() -> TypeRef;

/* Operations on all values */
#[fast_ffi]
pub unsafe fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
Expand Down Expand Up @@ -482,15 +445,11 @@ pub mod llvm {
SLen: c_uint)
-> ValueRef;
#[fast_ffi]
pub unsafe fn LLVMMDString(Str: *c_char, SLen: c_uint) -> ValueRef;
#[fast_ffi]
pub unsafe fn LLVMMDNodeInContext(C: ContextRef,
Vals: *ValueRef,
Count: c_uint)
-> ValueRef;
#[fast_ffi]
pub unsafe fn LLVMMDNode(Vals: *ValueRef, Count: c_uint) -> ValueRef;
#[fast_ffi]
pub unsafe fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
Val: ValueRef);

Expand Down Expand Up @@ -544,20 +503,11 @@ pub mod llvm {
Packed: Bool) -> ValueRef;

#[fast_ffi]
pub unsafe fn LLVMConstString(Str: *c_char,
Length: c_uint,
DontNullTerminate: Bool)
-> ValueRef;
#[fast_ffi]
pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
ConstantVals: *ValueRef,
Length: c_uint)
-> ValueRef;
#[fast_ffi]
pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef,
Count: c_uint,
Packed: Bool) -> ValueRef;
#[fast_ffi]
pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
Size: c_uint) -> ValueRef;

Expand Down Expand Up @@ -970,15 +920,6 @@ pub mod llvm {
BB: BasicBlockRef,
Name: *c_char)
-> BasicBlockRef;

#[fast_ffi]
pub unsafe fn LLVMAppendBasicBlock(Fn: ValueRef,
Name: *c_char)
-> BasicBlockRef;
#[fast_ffi]
pub unsafe fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef,
Name: *c_char)
-> BasicBlockRef;
#[fast_ffi]
pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);

Expand Down Expand Up @@ -1039,8 +980,6 @@ pub mod llvm {
#[fast_ffi]
pub unsafe fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
#[fast_ffi]
pub unsafe fn LLVMCreateBuilder() -> BuilderRef;
#[fast_ffi]
pub unsafe fn LLVMPositionBuilder(Builder: BuilderRef,
Block: BasicBlockRef,
Instr: ValueRef);
Expand Down Expand Up @@ -1893,7 +1832,8 @@ pub mod llvm {

/** Parses LLVM asm in the given file */
#[fast_ffi]
pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char)
pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char,
C: ContextRef)
-> ModuleRef;

#[fast_ffi]
Expand All @@ -1909,6 +1849,9 @@ pub mod llvm {
#[fast_ffi]
pub unsafe fn LLVMRustPrintPassTimings();

#[fast_ffi]
pub unsafe fn LLVMRustStartMultithreading() -> bool;

#[fast_ffi]
pub unsafe fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char)
-> TypeRef;
Expand Down
42 changes: 32 additions & 10 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use back::link::{mangle_exported_name};
use back::{link, abi, upcall};
use driver::session;
use driver::session::Session;
use lib::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef};
use lib::llvm::{ContextRef, ModuleRef, ValueRef, TypeRef, BasicBlockRef};
use lib::llvm::{True, False};
use lib::llvm::{llvm, mk_target_data, mk_type_names};
use lib;
Expand Down Expand Up @@ -73,6 +73,7 @@ use core::libc::c_uint;
use core::str;
use core::uint;
use core::vec;
use core::local_data;
use extra::time;
use syntax::ast::ident;
use syntax::ast_map::{path, path_elt_to_str, path_name};
Expand Down Expand Up @@ -1187,7 +1188,7 @@ pub fn new_block(cx: fn_ctxt, parent: Option<block>, kind: block_kind,
};
unsafe {
let llbb = str::as_c_str(cx.ccx.sess.str_of(s), |buf| {
llvm::LLVMAppendBasicBlock(cx.llfn, buf)
llvm::LLVMAppendBasicBlockInContext(cx.ccx.llcx, cx.llfn, buf)
});
let bcx = mk_block(llbb,
parent,
Expand Down Expand Up @@ -1554,11 +1555,12 @@ pub struct BasicBlocks {
// Creates the standard set of basic blocks for a function
pub fn mk_standard_basic_blocks(llfn: ValueRef) -> BasicBlocks {
unsafe {
let cx = task_llcx();
BasicBlocks {
sa: str::as_c_str("static_allocas",
|buf| llvm::LLVMAppendBasicBlock(llfn, buf)),
|buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)),
rt: str::as_c_str("return",
|buf| llvm::LLVMAppendBasicBlock(llfn, buf))
|buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf))
}
}
}
Expand Down Expand Up @@ -2341,7 +2343,7 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
};
let llbb = str::as_c_str("top", |buf| {
unsafe {
llvm::LLVMAppendBasicBlock(llfn, buf)
llvm::LLVMAppendBasicBlockInContext(ccx.llcx, llfn, buf)
}
});
let bld = ccx.builder.B;
Expand Down Expand Up @@ -2659,10 +2661,10 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {
T_void()));
let memcpy32 =
decl_cdecl_fn(llmod, "llvm.memcpy.p0i8.p0i8.i32",
T_fn(copy T_memcpy32_args, T_void()));
T_fn(T_memcpy32_args, T_void()));
let memcpy64 =
decl_cdecl_fn(llmod, "llvm.memcpy.p0i8.p0i8.i64",
T_fn(copy T_memcpy64_args, T_void()));
T_fn(T_memcpy64_args, T_void()));
let memmove32 =
decl_cdecl_fn(llmod, "llvm.memmove.p0i8.p0i8.i32",
T_fn(T_memcpy32_args, T_void()));
Expand Down Expand Up @@ -3038,9 +3040,13 @@ pub fn trans_crate(sess: session::Session,
let llmod_id = link_meta.name.to_owned() + ".rc";

unsafe {
if !llvm::LLVMRustStartMultithreading() {
sess.bug("couldn't enable multi-threaded LLVM");
}
let llcx = llvm::LLVMContextCreate();
set_task_llcx(llcx);
let llmod = str::as_c_str(llmod_id, |buf| {
llvm::LLVMModuleCreateWithNameInContext
(buf, llvm::LLVMGetGlobalContext())
llvm::LLVMModuleCreateWithNameInContext(buf, llcx)
});
let data_layout: &str = sess.targ_cfg.target_strs.data_layout;
let targ_triple: &str = sess.targ_cfg.target_strs.target_triple;
Expand Down Expand Up @@ -3071,6 +3077,7 @@ pub fn trans_crate(sess: session::Session,
let ccx = @CrateContext {
sess: sess,
llmod: llmod,
llcx: llcx,
td: td,
tn: tn,
externs: @mut HashMap::new(),
Expand Down Expand Up @@ -3124,7 +3131,9 @@ pub fn trans_crate(sess: session::Session,
int_type: int_type,
float_type: float_type,
opaque_vec_type: T_opaque_vec(targ_cfg),
builder: BuilderRef_res(unsafe { llvm::LLVMCreateBuilder() }),
builder: BuilderRef_res(unsafe {
llvm::LLVMCreateBuilderInContext(llcx)
}),
shape_cx: mk_ctxt(llmod),
crate_map: crate_map,
uses_gc: @mut false,
Expand Down Expand Up @@ -3172,3 +3181,16 @@ pub fn trans_crate(sess: session::Session,
return (llmod, link_meta);
}
}

fn task_local_llcx_key(_v: @ContextRef) {}

pub fn task_llcx() -> ContextRef {
let opt = unsafe { local_data::local_data_get(task_local_llcx_key) };
*opt.expect("task-local LLVMContextRef wasn't ever set!")
}

fn set_task_llcx(c: ContextRef) {
unsafe {
local_data::local_data_set(task_local_llcx_key, @c);
}
}
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ pub fn LoadRangeAssert(cx: block, PointerVal: ValueRef, lo: c_ulonglong,

do vec::as_imm_buf([min, max]) |ptr, len| {
llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint,
llvm::LLVMMDNode(ptr, len as c_uint));
llvm::LLVMMDNodeInContext(cx.fcx.ccx.llcx,
ptr, len as c_uint));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/cabi_mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use lib::llvm::{llvm, TypeRef, Integer, Pointer, Float, Double};
use lib::llvm::{Struct, Array, Attribute};
use lib::llvm::{StructRetAttribute};
use lib::llvm::True;
use middle::trans::base::task_llcx;
use middle::trans::common::*;
use middle::trans::cabi::*;

Expand Down Expand Up @@ -166,7 +167,7 @@ fn coerce_to_int(size: uint) -> ~[TypeRef] {
let r = size % 32;
if r > 0 {
unsafe {
args.push(llvm::LLVMIntType(r as c_uint))
args.push(llvm::LLVMIntTypeInContext(task_llcx(), r as c_uint))
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ pub fn load_environment(fcx: fn_ctxt,
str::as_c_str("load_env",
|buf|
unsafe {
llvm::LLVMAppendBasicBlock(fcx.llfn, buf)
llvm::LLVMAppendBasicBlockInContext(fcx.ccx.llcx,
fcx.llfn,
buf)
});
fcx.llloadenv = Some(ll);
ll
Expand Down
Loading