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

src/rustllvm/RustWrapper.cpp

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,14 @@ extern "C" LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B,
129129
LLVMValueRef target,
130130
LLVMValueRef old,
131131
LLVMValueRef source,
132-
AtomicOrdering order) {
132+
AtomicOrdering order,
133+
AtomicOrdering failure_order) {
133134
return wrap(unwrap(B)->CreateAtomicCmpXchg(unwrap(target), unwrap(old),
134-
unwrap(source), order));
135+
unwrap(source), order
136+
#if LLVM_VERSION_MINOR >= 5
137+
, failure_order
138+
#endif
139+
));
135140
}
136141
extern "C" LLVMValueRef LLVMBuildAtomicFence(LLVMBuilderRef B, AtomicOrdering order) {
137142
return wrap(unwrap(B)->CreateFence(order));
@@ -289,10 +294,9 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateStructType(
289294
RunTimeLang,
290295
unwrapDI<DIType>(VTableHolder)
291296
#if LLVM_VERSION_MINOR >= 5
292-
,UniqueId));
293-
#else
294-
));
297+
,UniqueId
295298
#endif
299+
));
296300
}
297301

298302
extern "C" LLVMValueRef LLVMDIBuilderCreateMemberType(
@@ -318,10 +322,15 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateLexicalBlock(
318322
LLVMValueRef Scope,
319323
LLVMValueRef File,
320324
unsigned Line,
321-
unsigned Col) {
325+
unsigned Col,
326+
unsigned Discriminator) {
322327
return wrap(Builder->createLexicalBlock(
323328
unwrapDI<DIDescriptor>(Scope),
324-
unwrapDI<DIFile>(File), Line, Col));
329+
unwrapDI<DIFile>(File), Line, Col
330+
#if LLVM_VERSION_MINOR >= 5
331+
, Discriminator
332+
#endif
333+
));
325334
}
326335

327336
extern "C" LLVMValueRef LLVMDIBuilderCreateStaticVariable(
@@ -477,15 +486,16 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateUnionType(
477486
unwrapDI<DIArray>(Elements),
478487
RunTimeLang
479488
#if LLVM_VERSION_MINOR >= 5
480-
,UniqueId));
481-
#else
482-
));
489+
,UniqueId
483490
#endif
491+
));
484492
}
485493

494+
#if LLVM_VERSION_MINOR < 5
486495
extern "C" void LLVMSetUnnamedAddr(LLVMValueRef Value, LLVMBool Unnamed) {
487496
unwrap<GlobalValue>(Value)->setUnnamedAddr(Unnamed);
488497
}
498+
#endif
489499

490500
extern "C" LLVMValueRef LLVMDIBuilderCreateTemplateTypeParameter(
491501
DIBuilderRef Builder,
@@ -620,6 +630,23 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
620630
}
621631
#endif
622632

633+
#if LLVM_VERSION_MINOR >= 5
634+
extern "C" void*
635+
LLVMRustOpenArchive(char *path) {
636+
std::unique_ptr<MemoryBuffer> buf;
637+
error_code err = MemoryBuffer::getFile(path, buf);
638+
if (err) {
639+
LLVMRustError = err.message().c_str();
640+
return NULL;
641+
}
642+
Archive *ret = new Archive(buf.release(), err);
643+
if (err) {
644+
LLVMRustError = err.message().c_str();
645+
return NULL;
646+
}
647+
return ret;
648+
}
649+
#else
623650
extern "C" void*
624651
LLVMRustOpenArchive(char *path) {
625652
OwningPtr<MemoryBuffer> buf;
@@ -635,6 +662,7 @@ LLVMRustOpenArchive(char *path) {
635662
}
636663
return ret;
637664
}
665+
#endif
638666

639667
extern "C" const char*
640668
LLVMRustArchiveReadSection(Archive *ar, char *name, size_t *size) {

src/rustllvm/llvm-auto-clean-trigger

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# If this file is modified, then llvm will be forcibly cleaned and then rebuilt.
22
# The actual contents of this file do not matter, but to trigger a change on the
33
# build bots then the contents should be changed so git updates the mtime.
4-
2014-02-25
4+
2014-04-14

src/rustllvm/rustllvm.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "llvm/IR/InlineAsm.h"
1313
#include "llvm/IR/LLVMContext.h"
1414
#include "llvm/IR/Module.h"
15-
#include "llvm/Linker.h"
1615
#include "llvm/PassManager.h"
1716
#include "llvm/IR/InlineAsm.h"
1817
#include "llvm/IR/LLVMContext.h"
@@ -43,8 +42,6 @@
4342
#include "llvm/Transforms/IPO.h"
4443
#include "llvm/Transforms/Instrumentation.h"
4544
#include "llvm/Transforms/Vectorize.h"
46-
#include "llvm/DebugInfo.h"
47-
#include "llvm/DIBuilder.h"
4845
#include "llvm/Bitcode/ReaderWriter.h"
4946
#include "llvm-c/Core.h"
5047
#include "llvm-c/BitReader.h"
@@ -53,8 +50,14 @@
5350

5451
#if LLVM_VERSION_MINOR >= 5
5552
#include "llvm/IR/IRPrintingPasses.h"
53+
#include "llvm/IR/DebugInfo.h"
54+
#include "llvm/IR/DIBuilder.h"
55+
#include "llvm/Linker/Linker.h"
5656
#else
5757
#include "llvm/Assembly/PrintModulePass.h"
58+
#include "llvm/DebugInfo.h"
59+
#include "llvm/DIBuilder.h"
60+
#include "llvm/Linker.h"
5861
#endif
5962

6063
// Used by RustMCJITMemoryManager::getPointerToNamedFunction()

0 commit comments

Comments
 (0)