Skip to content

Commit 541c657

Browse files
committed
Revert "Remove all usage of the global LLVMContextRef"
This reverts commit 779191c. Conflicts: src/librustc/middle/trans/base.rs src/librustc/middle/trans/common.rs
1 parent 19adece commit 541c657

File tree

11 files changed

+113
-130
lines changed

11 files changed

+113
-130
lines changed

src/librustc/lib/llvm.rs

+64-7
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,23 @@ pub mod llvm {
239239
#[fast_ffi]
240240
pub unsafe fn LLVMContextCreate() -> ContextRef;
241241
#[fast_ffi]
242+
pub unsafe fn LLVMGetGlobalContext() -> ContextRef;
243+
#[fast_ffi]
242244
pub unsafe fn LLVMContextDispose(C: ContextRef);
243245
#[fast_ffi]
244246
pub unsafe fn LLVMGetMDKindIDInContext(C: ContextRef,
245247
Name: *c_char,
246248
SLen: c_uint)
247249
-> c_uint;
250+
#[fast_ffi]
251+
pub unsafe fn LLVMGetMDKindID(Name: *c_char, SLen: c_uint) -> c_uint;
248252

249253
/* Create and destroy modules. */
250254
#[fast_ffi]
251255
pub unsafe fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
252256
C: ContextRef)
253257
-> ModuleRef;
254258
#[fast_ffi]
255-
pub unsafe fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
256-
#[fast_ffi]
257259
pub unsafe fn LLVMDisposeModule(M: ModuleRef);
258260

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

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;
301315
#[fast_ffi]
302316
pub unsafe fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
303317

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

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+
316341
/* Operations on function types */
317342
#[fast_ffi]
318343
pub unsafe fn LLVMFunctionType(ReturnType: TypeRef,
@@ -336,6 +361,11 @@ pub mod llvm {
336361
ElementCount: c_uint,
337362
Packed: Bool) -> TypeRef;
338363
#[fast_ffi]
364+
pub unsafe fn LLVMStructType(ElementTypes: *TypeRef,
365+
ElementCount: c_uint,
366+
Packed: Bool)
367+
-> TypeRef;
368+
#[fast_ffi]
339369
pub unsafe fn LLVMCountStructElementTypes(StructTy: TypeRef)
340370
-> c_uint;
341371
#[fast_ffi]
@@ -373,6 +403,13 @@ pub mod llvm {
373403
#[fast_ffi]
374404
pub unsafe fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
375405

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+
376413
/* Operations on all values */
377414
#[fast_ffi]
378415
pub unsafe fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
@@ -445,11 +482,15 @@ pub mod llvm {
445482
SLen: c_uint)
446483
-> ValueRef;
447484
#[fast_ffi]
485+
pub unsafe fn LLVMMDString(Str: *c_char, SLen: c_uint) -> ValueRef;
486+
#[fast_ffi]
448487
pub unsafe fn LLVMMDNodeInContext(C: ContextRef,
449488
Vals: *ValueRef,
450489
Count: c_uint)
451490
-> ValueRef;
452491
#[fast_ffi]
492+
pub unsafe fn LLVMMDNode(Vals: *ValueRef, Count: c_uint) -> ValueRef;
493+
#[fast_ffi]
453494
pub unsafe fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
454495
Val: ValueRef);
455496

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

505546
#[fast_ffi]
547+
pub unsafe fn LLVMConstString(Str: *c_char,
548+
Length: c_uint,
549+
DontNullTerminate: Bool)
550+
-> ValueRef;
551+
#[fast_ffi]
506552
pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
507553
ConstantVals: *ValueRef,
508554
Length: c_uint)
509555
-> ValueRef;
510556
#[fast_ffi]
557+
pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef,
558+
Count: c_uint,
559+
Packed: Bool) -> ValueRef;
560+
#[fast_ffi]
511561
pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
512562
Size: c_uint) -> ValueRef;
513563

@@ -920,6 +970,15 @@ pub mod llvm {
920970
BB: BasicBlockRef,
921971
Name: *c_char)
922972
-> 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;
923982
#[fast_ffi]
924983
pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
925984

@@ -980,6 +1039,8 @@ pub mod llvm {
9801039
#[fast_ffi]
9811040
pub unsafe fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
9821041
#[fast_ffi]
1042+
pub unsafe fn LLVMCreateBuilder() -> BuilderRef;
1043+
#[fast_ffi]
9831044
pub unsafe fn LLVMPositionBuilder(Builder: BuilderRef,
9841045
Block: BasicBlockRef,
9851046
Instr: ValueRef);
@@ -1832,8 +1893,7 @@ pub mod llvm {
18321893

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

18391899
#[fast_ffi]
@@ -1849,9 +1909,6 @@ pub mod llvm {
18491909
#[fast_ffi]
18501910
pub unsafe fn LLVMRustPrintPassTimings();
18511911

1852-
#[fast_ffi]
1853-
pub unsafe fn LLVMRustStartMultithreading() -> bool;
1854-
18551912
#[fast_ffi]
18561913
pub unsafe fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char)
18571914
-> TypeRef;

src/librustc/middle/trans/base.rs

+10-32
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::{ContextRef, ModuleRef, ValueRef, TypeRef, BasicBlockRef};
32+
use lib::llvm::{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,7 +73,6 @@ use core::libc::c_uint;
7373
use core::str;
7474
use core::uint;
7575
use core::vec;
76-
use core::local_data;
7776
use extra::time;
7877
use syntax::ast::ident;
7978
use syntax::ast_map::{path, path_elt_to_str, path_name};
@@ -1188,7 +1187,7 @@ pub fn new_block(cx: fn_ctxt, parent: Option<block>, kind: block_kind,
11881187
};
11891188
unsafe {
11901189
let llbb = str::as_c_str(cx.ccx.sess.str_of(s), |buf| {
1191-
llvm::LLVMAppendBasicBlockInContext(cx.ccx.llcx, cx.llfn, buf)
1190+
llvm::LLVMAppendBasicBlock(cx.llfn, buf)
11921191
});
11931192
let bcx = mk_block(llbb,
11941193
parent,
@@ -1555,12 +1554,11 @@ pub struct BasicBlocks {
15551554
// Creates the standard set of basic blocks for a function
15561555
pub fn mk_standard_basic_blocks(llfn: ValueRef) -> BasicBlocks {
15571556
unsafe {
1558-
let cx = task_llcx();
15591557
BasicBlocks {
15601558
sa: str::as_c_str("static_allocas",
1561-
|buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)),
1559+
|buf| llvm::LLVMAppendBasicBlock(llfn, buf)),
15621560
rt: str::as_c_str("return",
1563-
|buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf))
1561+
|buf| llvm::LLVMAppendBasicBlock(llfn, buf))
15641562
}
15651563
}
15661564
}
@@ -2343,7 +2341,7 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
23432341
};
23442342
let llbb = str::as_c_str("top", |buf| {
23452343
unsafe {
2346-
llvm::LLVMAppendBasicBlockInContext(ccx.llcx, llfn, buf)
2344+
llvm::LLVMAppendBasicBlock(llfn, buf)
23472345
}
23482346
});
23492347
let bld = ccx.builder.B;
@@ -2661,10 +2659,10 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {
26612659
T_void()));
26622660
let memcpy32 =
26632661
decl_cdecl_fn(llmod, "llvm.memcpy.p0i8.p0i8.i32",
2664-
T_fn(T_memcpy32_args, T_void()));
2662+
T_fn(copy T_memcpy32_args, T_void()));
26652663
let memcpy64 =
26662664
decl_cdecl_fn(llmod, "llvm.memcpy.p0i8.p0i8.i64",
2667-
T_fn(T_memcpy64_args, T_void()));
2665+
T_fn(copy T_memcpy64_args, T_void()));
26682666
let memmove32 =
26692667
decl_cdecl_fn(llmod, "llvm.memmove.p0i8.p0i8.i32",
26702668
T_fn(T_memcpy32_args, T_void()));
@@ -3040,13 +3038,9 @@ pub fn trans_crate(sess: session::Session,
30403038
let llmod_id = link_meta.name.to_owned() + ".rc";
30413039
30423040
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);
30483041
let llmod = str::as_c_str(llmod_id, |buf| {
3049-
llvm::LLVMModuleCreateWithNameInContext(buf, llcx)
3042+
llvm::LLVMModuleCreateWithNameInContext
3043+
(buf, llvm::LLVMGetGlobalContext())
30503044
});
30513045
let data_layout: &str = sess.targ_cfg.target_strs.data_layout;
30523046
let targ_triple: &str = sess.targ_cfg.target_strs.target_triple;
@@ -3077,7 +3071,6 @@ pub fn trans_crate(sess: session::Session,
30773071
let ccx = @CrateContext {
30783072
sess: sess,
30793073
llmod: llmod,
3080-
llcx: llcx,
30813074
td: td,
30823075
tn: tn,
30833076
externs: @mut HashMap::new(),
@@ -3131,9 +3124,7 @@ pub fn trans_crate(sess: session::Session,
31313124
int_type: int_type,
31323125
float_type: float_type,
31333126
opaque_vec_type: T_opaque_vec(targ_cfg),
3134-
builder: BuilderRef_res(unsafe {
3135-
llvm::LLVMCreateBuilderInContext(llcx)
3136-
}),
3127+
builder: BuilderRef_res(unsafe { llvm::LLVMCreateBuilder() }),
31373128
shape_cx: mk_ctxt(llmod),
31383129
crate_map: crate_map,
31393130
uses_gc: @mut false,
@@ -3181,16 +3172,3 @@ pub fn trans_crate(sess: session::Session,
31813172
return (llmod, link_meta);
31823173
}
31833174
}
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-
}

src/librustc/middle/trans/build.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,7 @@ 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::LLVMMDNodeInContext(cx.fcx.ccx.llcx,
568-
ptr, len as c_uint));
567+
llvm::LLVMMDNode(ptr, len as c_uint));
569568
}
570569
}
571570

src/librustc/middle/trans/cabi_mips.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ 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;
2322
use middle::trans::common::*;
2423
use middle::trans::cabi::*;
2524

@@ -167,7 +166,7 @@ fn coerce_to_int(size: uint) -> ~[TypeRef] {
167166
let r = size % 32;
168167
if r > 0 {
169168
unsafe {
170-
args.push(llvm::LLVMIntTypeInContext(task_llcx(), r as c_uint))
169+
args.push(llvm::LLVMIntType(r as c_uint))
171170
}
172171
}
173172

src/librustc/middle/trans/closure.rs

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

0 commit comments

Comments
 (0)