Skip to content

Commit 30ff17f

Browse files
committed
Upgrade LLVM
This comes with a number of fixes to be compatible with upstream LLVM: * Previously all monomorphizations of "mem::size_of()" would receive the same symbol. In the past LLVM would silently rename duplicated symbols, but it appears to now be dropping the duplicate symbols and functions now. The symbol names of monomorphized functions are now no longer solely based on the type of the function, but rather the type and the unique hash for the monomorphization. * Split stacks are no longer a global feature controlled by a flag in LLVM. Instead, they are opt-in on a per-function basis through a function attribute. The rust #[no_split_stack] attribute will disable this, otherwise all functions have #[split_stack] attached to them. * The compare and swap instruction now takes two atomic orderings, one for the successful case and one for the failure case. LLVM internally has an implementation of calculating the appropriate failure ordering given a particular success ordering (previously only a success ordering was specified), and I copied that into the intrinsic translation so the failure ordering isn't supplied on a source level for now. * Minor tweaks to LLVM's API in terms of debuginfo, naming, c++11 conventions, etc.
1 parent 903fbd2 commit 30ff17f

File tree

13 files changed

+89
-35
lines changed

13 files changed

+89
-35
lines changed

configure

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -921,10 +921,6 @@ do
921921
LLVM_OPTS="$LLVM_OPTS --disable-terminfo"
922922
# Try to have LLVM pull in as few dependencies as possible (#9397)
923923
LLVM_OPTS="$LLVM_OPTS --disable-zlib --disable-libffi"
924-
# LLVM says it needs a "new" clang/gcc, but we seem to get by ok with
925-
# older versions on the bots. Get by for a little longer by asking it to
926-
# not do version detection
927-
LLVM_OPTS="$LLVM_OPTS --disable-compiler-version-checks"
928924

929925
# Use win32 native thread/lock apis instead of pthread wrapper.
930926
# (llvm's configure tries to find pthread first, so we have to disable it explicitly.)

src/librustc/lib/llvm.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,8 @@ pub mod llvm {
12611261
LHS: ValueRef,
12621262
CMP: ValueRef,
12631263
RHS: ValueRef,
1264-
Order: AtomicOrdering)
1264+
Order: AtomicOrdering,
1265+
FailureOrder: AtomicOrdering)
12651266
-> ValueRef;
12661267
pub fn LLVMBuildAtomicRMW(B: BuilderRef,
12671268
Op: AtomicBinOp,
@@ -1586,7 +1587,8 @@ pub mod llvm {
15861587
Scope: DIDescriptor,
15871588
File: DIFile,
15881589
Line: c_uint,
1589-
Col: c_uint)
1590+
Col: c_uint,
1591+
Discriminator: c_uint)
15901592
-> DILexicalBlock;
15911593

15921594
pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,

src/librustc/middle/trans/base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) {
445445
}
446446

447447
// Add the no-split-stack attribute if requested
448-
if contains_name(attrs, "no_split_stack") {
449-
set_no_split_stack(llfn);
448+
if !contains_name(attrs, "no_split_stack") {
449+
set_split_stack(llfn);
450450
}
451451

452452
if contains_name(attrs, "cold") {
@@ -458,8 +458,8 @@ pub fn set_always_inline(f: ValueRef) {
458458
lib::llvm::SetFunctionAttribute(f, lib::llvm::AlwaysInlineAttribute)
459459
}
460460

461-
pub fn set_no_split_stack(f: ValueRef) {
462-
"no-split-stack".with_c_str(|buf| {
461+
pub fn set_split_stack(f: ValueRef) {
462+
"split-stack".with_c_str(|buf| {
463463
unsafe { llvm::LLVMAddFunctionAttrString(f, buf); }
464464
})
465465
}

src/librustc/middle/trans/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,9 @@ pub fn Resume(cx: &Block, exn: ValueRef) -> ValueRef {
814814
// Atomic Operations
815815
pub fn AtomicCmpXchg(cx: &Block, dst: ValueRef,
816816
cmp: ValueRef, src: ValueRef,
817-
order: AtomicOrdering) -> ValueRef {
818-
B(cx).atomic_cmpxchg(dst, cmp, src, order)
817+
order: AtomicOrdering,
818+
failure_order: AtomicOrdering) -> ValueRef {
819+
B(cx).atomic_cmpxchg(dst, cmp, src, order, failure_order)
819820
}
820821
pub fn AtomicRMW(cx: &Block, op: AtomicBinOp,
821822
dst: ValueRef, src: ValueRef,

src/librustc/middle/trans/builder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,11 @@ impl<'a> Builder<'a> {
949949
// Atomic Operations
950950
pub fn atomic_cmpxchg(&self, dst: ValueRef,
951951
cmp: ValueRef, src: ValueRef,
952-
order: AtomicOrdering) -> ValueRef {
952+
order: AtomicOrdering,
953+
failure_order: AtomicOrdering) -> ValueRef {
953954
unsafe {
954-
llvm::LLVMBuildAtomicCmpXchg(self.llbuilder, dst, cmp, src, order)
955+
llvm::LLVMBuildAtomicCmpXchg(self.llbuilder, dst, cmp, src,
956+
order, failure_order)
955957
}
956958
}
957959
pub fn atomic_rmw(&self, op: AtomicBinOp,

src/librustc/middle/trans/debuginfo.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,7 +2422,8 @@ fn populate_scope_map(cx: &CrateContext,
24222422
parent_scope,
24232423
file_metadata,
24242424
loc.line as c_uint,
2425-
loc.col.to_uint() as c_uint)
2425+
loc.col.to_uint() as c_uint,
2426+
0)
24262427
};
24272428

24282429
scope_stack.push(ScopeStackEntry { scope_metadata: scope_metadata, ident: None });
@@ -2539,7 +2540,8 @@ fn populate_scope_map(cx: &CrateContext,
25392540
parent_scope,
25402541
file_metadata,
25412542
loc.line as c_uint,
2542-
loc.col.to_uint() as c_uint)
2543+
loc.col.to_uint() as c_uint,
2544+
0)
25432545
};
25442546

25452547
scope_stack.push(ScopeStackEntry {

src/librustc/middle/trans/intrinsic.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,23 @@ pub fn trans_intrinsic(ccx: &CrateContext,
223223

224224
match *split.get(1) {
225225
"cxchg" => {
226+
// See include/llvm/IR/Instructions.h for their implementation
227+
// of this, I assume that it's good enough for us to use for
228+
// now.
229+
let strongest_failure_ordering = match order {
230+
lib::llvm::NotAtomic | lib::llvm::Unordered =>
231+
ccx.sess().fatal("cmpxchg must be atomic"),
232+
lib::llvm::Monotonic | lib::llvm::Release =>
233+
lib::llvm::Monotonic,
234+
lib::llvm::Acquire | lib::llvm::AcquireRelease =>
235+
lib::llvm::Acquire,
236+
lib::llvm::SequentiallyConsistent =>
237+
lib::llvm::SequentiallyConsistent,
238+
};
226239
let old = AtomicCmpXchg(bcx, get_param(decl, first_real_arg),
227240
get_param(decl, first_real_arg + 1u),
228241
get_param(decl, first_real_arg + 2u),
229-
order);
242+
order, strongest_failure_ordering);
230243
Ret(bcx, old);
231244
}
232245
"load" => {

src/librustc/middle/trans/monomorphize.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
12-
use back::link::mangle_exported_name;
11+
use back::link::exported_name;
1312
use driver::session;
1413
use lib::llvm::ValueRef;
1514
use middle::trans::base::{set_llvm_fn_attrs, set_inline_hint};
@@ -27,6 +26,7 @@ use syntax::abi;
2726
use syntax::ast;
2827
use syntax::ast_map;
2928
use syntax::ast_util::local_def;
29+
use std::hash::sip;
3030

3131
pub fn monomorphic_fn(ccx: &CrateContext,
3232
fn_id: ast::DefId,
@@ -178,7 +178,8 @@ pub fn monomorphic_fn(ccx: &CrateContext,
178178
}
179179

180180
let s = ccx.tcx.map.with_path(fn_id.node, |path| {
181-
mangle_exported_name(ccx, path, mono_ty, fn_id.node)
181+
exported_name(path, format!("h{}", sip::hash(&(hash_id, mono_ty))),
182+
ccx.link_meta.crateid.version_or_default())
182183
});
183184
debug!("monomorphize_fn mangled to {}", s);
184185

src/llvm

Submodule llvm updated 3201 files

src/rustllvm/PassWrapper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ LLVMRustCreateTargetMachine(const char *triple,
8181

8282
TargetOptions Options;
8383
Options.NoFramePointerElim = NoFramePointerElim;
84+
#if LLVM_VERSION_MINOR < 5
8485
Options.EnableSegmentedStacks = EnableSegmentedStacks;
86+
#endif
8587
Options.FloatABIType = FloatABI::Default;
8688
Options.UseSoftFloat = UseSoftFloat;
8789
if (UseSoftFloat) {
@@ -111,7 +113,11 @@ LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
111113
LLVMPassManagerRef PMR,
112114
LLVMModuleRef M) {
113115
PassManagerBase *PM = unwrap(PMR);
116+
#if LLVM_VERSION_MINOR >= 5
117+
PM->add(new DataLayoutPass(unwrap(M)));
118+
#else
114119
PM->add(new DataLayout(unwrap(M)));
120+
#endif
115121
unwrap(TM)->addAnalysisPasses(*PM);
116122
}
117123

0 commit comments

Comments
 (0)