Skip to content

Commit 607ae1f

Browse files
committed
---
yaml --- r: 63299 b: refs/heads/snap-stage3 c: 1a3edec h: refs/heads/master i: 63297: 9d7859d 63295: 7a59a88 v: v3
1 parent 5c5e0cc commit 607ae1f

File tree

12 files changed

+131
-114
lines changed

12 files changed

+131
-114
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 7755018074a7802e47ae61f69f5e2b5364a12eb8
4+
refs/heads/snap-stage3: 1a3edecbf21eef7f39bbf3a7bf38fb72fdc6af61
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/lib/llvm.rs

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -239,23 +239,21 @@ pub mod llvm {
239239
#[fast_ffi]
240240
pub unsafe fn LLVMContextCreate() -> ContextRef;
241241
#[fast_ffi]
242-
pub unsafe fn LLVMGetGlobalContext() -> ContextRef;
243-
#[fast_ffi]
244242
pub unsafe fn LLVMContextDispose(C: ContextRef);
245243
#[fast_ffi]
246244
pub unsafe fn LLVMGetMDKindIDInContext(C: ContextRef,
247245
Name: *c_char,
248246
SLen: c_uint)
249247
-> c_uint;
250-
#[fast_ffi]
251-
pub unsafe fn LLVMGetMDKindID(Name: *c_char, SLen: c_uint) -> c_uint;
252248

253249
/* Create and destroy modules. */
254250
#[fast_ffi]
255251
pub unsafe fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
256252
C: ContextRef)
257253
-> ModuleRef;
258254
#[fast_ffi]
255+
pub unsafe fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
256+
#[fast_ffi]
259257
pub unsafe fn LLVMDisposeModule(M: ModuleRef);
260258

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

303-
#[fast_ffi]
304-
pub unsafe fn LLVMInt1Type() -> TypeRef;
305-
#[fast_ffi]
306-
pub unsafe fn LLVMInt8Type() -> TypeRef;
307-
#[fast_ffi]
308-
pub unsafe fn LLVMInt16Type() -> TypeRef;
309-
#[fast_ffi]
310-
pub unsafe fn LLVMInt32Type() -> TypeRef;
311-
#[fast_ffi]
312-
pub unsafe fn LLVMInt64Type() -> TypeRef;
313-
#[fast_ffi]
314-
pub unsafe fn LLVMIntType(NumBits: c_uint) -> TypeRef;
315301
#[fast_ffi]
316302
pub unsafe fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
317303

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

330-
#[fast_ffi]
331-
pub unsafe fn LLVMFloatType() -> TypeRef;
332-
#[fast_ffi]
333-
pub unsafe fn LLVMDoubleType() -> TypeRef;
334-
#[fast_ffi]
335-
pub unsafe fn LLVMX86FP80Type() -> TypeRef;
336-
#[fast_ffi]
337-
pub unsafe fn LLVMFP128Type() -> TypeRef;
338-
#[fast_ffi]
339-
pub unsafe fn LLVMPPCFP128Type() -> TypeRef;
340-
341316
/* Operations on function types */
342317
#[fast_ffi]
343318
pub unsafe fn LLVMFunctionType(ReturnType: TypeRef,
@@ -361,11 +336,6 @@ pub mod llvm {
361336
ElementCount: c_uint,
362337
Packed: Bool) -> TypeRef;
363338
#[fast_ffi]
364-
pub unsafe fn LLVMStructType(ElementTypes: *TypeRef,
365-
ElementCount: c_uint,
366-
Packed: Bool)
367-
-> TypeRef;
368-
#[fast_ffi]
369339
pub unsafe fn LLVMCountStructElementTypes(StructTy: TypeRef)
370340
-> c_uint;
371341
#[fast_ffi]
@@ -403,13 +373,6 @@ pub mod llvm {
403373
#[fast_ffi]
404374
pub unsafe fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
405375

406-
#[fast_ffi]
407-
pub unsafe fn LLVMVoidType() -> TypeRef;
408-
#[fast_ffi]
409-
pub unsafe fn LLVMLabelType() -> TypeRef;
410-
#[fast_ffi]
411-
pub unsafe fn LLVMMetadataType() -> TypeRef;
412-
413376
/* Operations on all values */
414377
#[fast_ffi]
415378
pub unsafe fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
@@ -482,15 +445,11 @@ pub mod llvm {
482445
SLen: c_uint)
483446
-> ValueRef;
484447
#[fast_ffi]
485-
pub unsafe fn LLVMMDString(Str: *c_char, SLen: c_uint) -> ValueRef;
486-
#[fast_ffi]
487448
pub unsafe fn LLVMMDNodeInContext(C: ContextRef,
488449
Vals: *ValueRef,
489450
Count: c_uint)
490451
-> ValueRef;
491452
#[fast_ffi]
492-
pub unsafe fn LLVMMDNode(Vals: *ValueRef, Count: c_uint) -> ValueRef;
493-
#[fast_ffi]
494453
pub unsafe fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
495454
Val: ValueRef);
496455

@@ -544,20 +503,11 @@ pub mod llvm {
544503
Packed: Bool) -> ValueRef;
545504

546505
#[fast_ffi]
547-
pub unsafe fn LLVMConstString(Str: *c_char,
548-
Length: c_uint,
549-
DontNullTerminate: Bool)
550-
-> ValueRef;
551-
#[fast_ffi]
552506
pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
553507
ConstantVals: *ValueRef,
554508
Length: c_uint)
555509
-> ValueRef;
556510
#[fast_ffi]
557-
pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef,
558-
Count: c_uint,
559-
Packed: Bool) -> ValueRef;
560-
#[fast_ffi]
561511
pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
562512
Size: c_uint) -> ValueRef;
563513

@@ -970,15 +920,6 @@ pub mod llvm {
970920
BB: BasicBlockRef,
971921
Name: *c_char)
972922
-> BasicBlockRef;
973-
974-
#[fast_ffi]
975-
pub unsafe fn LLVMAppendBasicBlock(Fn: ValueRef,
976-
Name: *c_char)
977-
-> BasicBlockRef;
978-
#[fast_ffi]
979-
pub unsafe fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef,
980-
Name: *c_char)
981-
-> BasicBlockRef;
982923
#[fast_ffi]
983924
pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
984925

@@ -1039,8 +980,6 @@ pub mod llvm {
1039980
#[fast_ffi]
1040981
pub unsafe fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1041982
#[fast_ffi]
1042-
pub unsafe fn LLVMCreateBuilder() -> BuilderRef;
1043-
#[fast_ffi]
1044983
pub unsafe fn LLVMPositionBuilder(Builder: BuilderRef,
1045984
Block: BasicBlockRef,
1046985
Instr: ValueRef);
@@ -1893,7 +1832,8 @@ pub mod llvm {
18931832

18941833
/** Parses LLVM asm in the given file */
18951834
#[fast_ffi]
1896-
pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char)
1835+
pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char,
1836+
C: ContextRef)
18971837
-> ModuleRef;
18981838

18991839
#[fast_ffi]
@@ -1909,6 +1849,9 @@ pub mod llvm {
19091849
#[fast_ffi]
19101850
pub unsafe fn LLVMRustPrintPassTimings();
19111851

1852+
#[fast_ffi]
1853+
pub unsafe fn LLVMRustStartMultithreading() -> bool;
1854+
19121855
#[fast_ffi]
19131856
pub unsafe fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char)
19141857
-> TypeRef;

branches/snap-stage3/src/librustc/middle/trans/base.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use back::link::{mangle_exported_name};
2929
use back::{link, abi, upcall};
3030
use driver::session;
3131
use driver::session::Session;
32-
use lib::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef};
32+
use lib::llvm::{ContextRef, ModuleRef, ValueRef, TypeRef, BasicBlockRef};
3333
use lib::llvm::{True, False};
3434
use lib::llvm::{llvm, mk_target_data, mk_type_names};
3535
use lib;
@@ -73,6 +73,7 @@ use core::libc::c_uint;
7373
use core::str;
7474
use core::uint;
7575
use core::vec;
76+
use core::local_data;
7677
use extra::time;
7778
use syntax::ast::ident;
7879
use syntax::ast_map::{path, path_elt_to_str, path_name};
@@ -1187,7 +1188,7 @@ pub fn new_block(cx: fn_ctxt, parent: Option<block>, kind: block_kind,
11871188
};
11881189
unsafe {
11891190
let llbb = str::as_c_str(cx.ccx.sess.str_of(s), |buf| {
1190-
llvm::LLVMAppendBasicBlock(cx.llfn, buf)
1191+
llvm::LLVMAppendBasicBlockInContext(cx.ccx.llcx, cx.llfn, buf)
11911192
});
11921193
let bcx = mk_block(llbb,
11931194
parent,
@@ -1554,11 +1555,12 @@ pub struct BasicBlocks {
15541555
// Creates the standard set of basic blocks for a function
15551556
pub fn mk_standard_basic_blocks(llfn: ValueRef) -> BasicBlocks {
15561557
unsafe {
1558+
let cx = task_llcx();
15571559
BasicBlocks {
15581560
sa: str::as_c_str("static_allocas",
1559-
|buf| llvm::LLVMAppendBasicBlock(llfn, buf)),
1561+
|buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)),
15601562
rt: str::as_c_str("return",
1561-
|buf| llvm::LLVMAppendBasicBlock(llfn, buf))
1563+
|buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf))
15621564
}
15631565
}
15641566
}
@@ -2341,7 +2343,7 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
23412343
};
23422344
let llbb = str::as_c_str("top", |buf| {
23432345
unsafe {
2344-
llvm::LLVMAppendBasicBlock(llfn, buf)
2346+
llvm::LLVMAppendBasicBlockInContext(ccx.llcx, llfn, buf)
23452347
}
23462348
});
23472349
let bld = ccx.builder.B;
@@ -2659,10 +2661,10 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {
26592661
T_void()));
26602662
let memcpy32 =
26612663
decl_cdecl_fn(llmod, "llvm.memcpy.p0i8.p0i8.i32",
2662-
T_fn(copy T_memcpy32_args, T_void()));
2664+
T_fn(T_memcpy32_args, T_void()));
26632665
let memcpy64 =
26642666
decl_cdecl_fn(llmod, "llvm.memcpy.p0i8.p0i8.i64",
2665-
T_fn(copy T_memcpy64_args, T_void()));
2667+
T_fn(T_memcpy64_args, T_void()));
26662668
let memmove32 =
26672669
decl_cdecl_fn(llmod, "llvm.memmove.p0i8.p0i8.i32",
26682670
T_fn(T_memcpy32_args, T_void()));
@@ -3038,9 +3040,13 @@ pub fn trans_crate(sess: session::Session,
30383040
let llmod_id = link_meta.name.to_owned() + ".rc";
30393041
30403042
unsafe {
3043+
if !llvm::LLVMRustStartMultithreading() {
3044+
sess.bug("couldn't enable multi-threaded LLVM");
3045+
}
3046+
let llcx = llvm::LLVMContextCreate();
3047+
set_task_llcx(llcx);
30413048
let llmod = str::as_c_str(llmod_id, |buf| {
3042-
llvm::LLVMModuleCreateWithNameInContext
3043-
(buf, llvm::LLVMGetGlobalContext())
3049+
llvm::LLVMModuleCreateWithNameInContext(buf, llcx)
30443050
});
30453051
let data_layout: &str = sess.targ_cfg.target_strs.data_layout;
30463052
let targ_triple: &str = sess.targ_cfg.target_strs.target_triple;
@@ -3071,6 +3077,7 @@ pub fn trans_crate(sess: session::Session,
30713077
let ccx = @CrateContext {
30723078
sess: sess,
30733079
llmod: llmod,
3080+
llcx: llcx,
30743081
td: td,
30753082
tn: tn,
30763083
externs: @mut HashMap::new(),
@@ -3124,7 +3131,9 @@ pub fn trans_crate(sess: session::Session,
31243131
int_type: int_type,
31253132
float_type: float_type,
31263133
opaque_vec_type: T_opaque_vec(targ_cfg),
3127-
builder: BuilderRef_res(unsafe { llvm::LLVMCreateBuilder() }),
3134+
builder: BuilderRef_res(unsafe {
3135+
llvm::LLVMCreateBuilderInContext(llcx)
3136+
}),
31283137
shape_cx: mk_ctxt(llmod),
31293138
crate_map: crate_map,
31303139
uses_gc: @mut false,
@@ -3172,3 +3181,16 @@ pub fn trans_crate(sess: session::Session,
31723181
return (llmod, link_meta);
31733182
}
31743183
}
3184+
3185+
fn task_local_llcx_key(_v: @ContextRef) {}
3186+
3187+
pub fn task_llcx() -> ContextRef {
3188+
let opt = unsafe { local_data::local_data_get(task_local_llcx_key) };
3189+
*opt.expect("task-local LLVMContextRef wasn't ever set!")
3190+
}
3191+
3192+
fn set_task_llcx(c: ContextRef) {
3193+
unsafe {
3194+
local_data::local_data_set(task_local_llcx_key, @c);
3195+
}
3196+
}

branches/snap-stage3/src/librustc/middle/trans/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ pub fn LoadRangeAssert(cx: block, PointerVal: ValueRef, lo: c_ulonglong,
564564

565565
do vec::as_imm_buf([min, max]) |ptr, len| {
566566
llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint,
567-
llvm::LLVMMDNode(ptr, len as c_uint));
567+
llvm::LLVMMDNodeInContext(cx.fcx.ccx.llcx,
568+
ptr, len as c_uint));
568569
}
569570
}
570571

branches/snap-stage3/src/librustc/middle/trans/cabi_mips.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use lib::llvm::{llvm, TypeRef, Integer, Pointer, Float, Double};
1919
use lib::llvm::{Struct, Array, Attribute};
2020
use lib::llvm::{StructRetAttribute};
2121
use lib::llvm::True;
22+
use middle::trans::base::task_llcx;
2223
use middle::trans::common::*;
2324
use middle::trans::cabi::*;
2425

@@ -166,7 +167,7 @@ fn coerce_to_int(size: uint) -> ~[TypeRef] {
166167
let r = size % 32;
167168
if r > 0 {
168169
unsafe {
169-
args.push(llvm::LLVMIntType(r as c_uint))
170+
args.push(llvm::LLVMIntTypeInContext(task_llcx(), r as c_uint))
170171
}
171172
}
172173

branches/snap-stage3/src/librustc/middle/trans/closure.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ pub fn load_environment(fcx: fn_ctxt,
327327
str::as_c_str("load_env",
328328
|buf|
329329
unsafe {
330-
llvm::LLVMAppendBasicBlock(fcx.llfn, buf)
330+
llvm::LLVMAppendBasicBlockInContext(fcx.ccx.llcx,
331+
fcx.llfn,
332+
buf)
331333
});
332334
fcx.llloadenv = Some(ll);
333335
ll

0 commit comments

Comments
 (0)