From 9ae0658fd0bf7552cc9a302d00fa9f94c7fc44de Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 21 May 2013 16:34:41 -0700 Subject: [PATCH 1/6] Try to fix a periodic windows build failure due to broken rwildcard macro --- mk/llvm.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mk/llvm.mk b/mk/llvm.mk index 77b6b4d96f362..12ccc55d4fae1 100644 --- a/mk/llvm.mk +++ b/mk/llvm.mk @@ -14,7 +14,9 @@ LLVM_DEPS := $(S)/.gitmodules else # This is just a rough approximation of LLVM deps -LLVM_DEPS=$(call rwildcard,$(CFG_LLVM_SRC_DIR),*cpp *hpp) +LLVM_DEPS_SRC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)/lib,*cpp *hpp) +LLVM_DEPS_INC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)/include,*cpp *hpp) +LLVM_DEPS=$(LLVM_DEPS_SRC) $(LLVM_DEPS_INC) endif define DEF_LLVM_RULES From 1d06aaae647bd76b9d94b784866a21cf6214224a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 24 May 2013 00:43:59 -0500 Subject: [PATCH 2/6] Update LLVM --- .gitmodules | 2 +- src/llvm | 2 +- src/rustllvm/llvm-auto-clean-trigger | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index c84426161796d..88ead6e608d5c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "src/llvm"] path = src/llvm - url = https://github.com/brson/llvm.git + url = https://github.com/alexcrichton/llvm.git branch = master [submodule "src/libuv"] path = src/libuv diff --git a/src/llvm b/src/llvm index 2e9f0d21fe321..e3abef3eedc8d 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit 2e9f0d21fe321849a4759a01fc28eae82ef196d6 +Subproject commit e3abef3eedc8d5bad3420c7e29bf2fe80585316a diff --git a/src/rustllvm/llvm-auto-clean-trigger b/src/rustllvm/llvm-auto-clean-trigger index 9b8f0e3a46214..670eebbed1327 100644 --- a/src/rustllvm/llvm-auto-clean-trigger +++ b/src/rustllvm/llvm-auto-clean-trigger @@ -1,4 +1,4 @@ # If this file is modified, then llvm will be forcibly cleaned and then rebuilt. # The actual contents of this file do not matter, but to trigger a change on the # build bots then the contents should be changed so git updates the mtime. -2013-07-03 +2013-07-04 From 8d2936765052f7267a16da5717d403dfe300d180 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 25 May 2013 17:23:12 -0500 Subject: [PATCH 3/6] Fix build issues once LLVM has been upgraded * LLVM now has a C interface to LLVMBuildAtomicRMW * The exception handling support for the JIT seems to have been dropped * Various interfaces have been added or headers have changed --- src/librustc/back/passes.rs | 1 - src/librustc/lib/llvm.rs | 3 ++- src/librustc/middle/trans/builder.rs | 2 +- src/rustllvm/RustWrapper.cpp | 11 +---------- src/rustllvm/rustllvm.h | 2 ++ 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/librustc/back/passes.rs b/src/librustc/back/passes.rs index 714e7d666ac38..b77ed10c21ba4 100644 --- a/src/librustc/back/passes.rs +++ b/src/librustc/back/passes.rs @@ -97,7 +97,6 @@ pub fn create_standard_passes(level: OptLevel) -> ~[~str] { passes.push(~"sroa"); passes.push(~"domtree"); passes.push(~"early-cse"); - passes.push(~"simplify-libcalls"); passes.push(~"lazy-value-info"); passes.push(~"jump-threading"); passes.push(~"correlated-propagation"); diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 6c631a104aa9f..842746f8209ee 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -1541,7 +1541,8 @@ pub mod llvm { Op: AtomicBinOp, LHS: ValueRef, RHS: ValueRef, - Order: AtomicOrdering) + Order: AtomicOrdering, + SingleThreaded: Bool) -> ValueRef; pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering); diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index d876b4d0b1673..1d821e5af94bd 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -940,7 +940,7 @@ impl Builder { dst: ValueRef, src: ValueRef, order: AtomicOrdering) -> ValueRef { unsafe { - llvm::LLVMBuildAtomicRMW(self.llbuilder, op, dst, src, order) + llvm::LLVMBuildAtomicRMW(self.llbuilder, op, dst, src, order, False) } } diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index beaa7e1daef9c..04c062072d6cb 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -113,6 +113,7 @@ class RustMCJITMemoryManager : public JITMemoryManager { virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, bool isReadOnly); + bool finalizeMemory(std::string *ErrMsg) { return false; } virtual bool applyPermissions(std::string *Str); @@ -340,7 +341,6 @@ LLVMRustBuildJIT(void* mem, std::string Err; TargetOptions Options; - Options.JITExceptionHandling = true; Options.JITEmitDebugInfo = true; Options.NoFramePointerElim = true; Options.EnableSegmentedStacks = EnableSegmentedStacks; @@ -516,15 +516,6 @@ extern "C" LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, extern "C" LLVMValueRef LLVMBuildAtomicFence(LLVMBuilderRef B, AtomicOrdering order) { return wrap(unwrap(B)->CreateFence(order)); } -extern "C" LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, - AtomicRMWInst::BinOp op, - LLVMValueRef target, - LLVMValueRef source, - AtomicOrdering order) { - return wrap(unwrap(B)->CreateAtomicRMW(op, - unwrap(target), unwrap(source), - order)); -} extern "C" void LLVMSetDebug(int Enabled) { #ifndef NDEBUG diff --git a/src/rustllvm/rustllvm.h b/src/rustllvm/rustllvm.h index d4202abd2854e..eeefb19883eb3 100644 --- a/src/rustllvm/rustllvm.h +++ b/src/rustllvm/rustllvm.h @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#include "llvm/IR/IRBuilder.h" #include "llvm/IR/InlineAsm.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/Linker.h" #include "llvm/PassManager.h" #include "llvm/IR/InlineAsm.h" From 4ace3b74348d5bc20b22c9d94959dd828b100fc4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 25 May 2013 21:26:08 -0500 Subject: [PATCH 4/6] Fix setting the fixed stack segment attribute on LLVM functions At the same time create a more robust wrapper to try to prevent this type of issue from cropping up in the future. --- src/librustc/lib/llvm.rs | 67 ++++++++++++++++++------------- src/librustc/middle/trans/base.rs | 41 ++++--------------- 2 files changed, 45 insertions(+), 63 deletions(-) diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 842746f8209ee..5ec439ce386c5 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -59,35 +59,35 @@ pub enum Linkage { #[deriving(Clone)] pub enum Attribute { - ZExtAttribute = 1, - SExtAttribute = 2, - NoReturnAttribute = 4, - InRegAttribute = 8, - StructRetAttribute = 16, - NoUnwindAttribute = 32, - NoAliasAttribute = 64, - ByValAttribute = 128, - NestAttribute = 256, - ReadNoneAttribute = 512, - ReadOnlyAttribute = 1024, - NoInlineAttribute = 2048, - AlwaysInlineAttribute = 4096, - OptimizeForSizeAttribute = 8192, - StackProtectAttribute = 16384, - StackProtectReqAttribute = 32768, - // 31 << 16 - AlignmentAttribute = 2031616, - NoCaptureAttribute = 2097152, - NoRedZoneAttribute = 4194304, - NoImplicitFloatAttribute = 8388608, - NakedAttribute = 16777216, - InlineHintAttribute = 33554432, - // 7 << 26 - StackAttribute = 469762048, - ReturnsTwiceAttribute = 536870912, - // 1 << 30 - UWTableAttribute = 1073741824, - NonLazyBindAttribute = 2147483648, + ZExtAttribute = 1 << 0, + SExtAttribute = 1 << 1, + NoReturnAttribute = 1 << 2, + InRegAttribute = 1 << 3, + StructRetAttribute = 1 << 4, + NoUnwindAttribute = 1 << 5, + NoAliasAttribute = 1 << 6, + ByValAttribute = 1 << 7, + NestAttribute = 1 << 8, + ReadNoneAttribute = 1 << 9, + ReadOnlyAttribute = 1 << 10, + NoInlineAttribute = 1 << 11, + AlwaysInlineAttribute = 1 << 12, + OptimizeForSizeAttribute = 1 << 13, + StackProtectAttribute = 1 << 14, + StackProtectReqAttribute = 1 << 15, + AlignmentAttribute = 31 << 16, + NoCaptureAttribute = 1 << 21, + NoRedZoneAttribute = 1 << 22, + NoImplicitFloatAttribute = 1 << 23, + NakedAttribute = 1 << 24, + InlineHintAttribute = 1 << 25, + StackAttribute = 7 << 26, + ReturnsTwiceAttribute = 1 << 29, + UWTableAttribute = 1 << 30, + NonLazyBindAttribute = 1 << 31, + + // Not added to LLVM yet, so may need to stay updated if LLVM changes. + FixedStackSegment = 1 << 41, } // enum for the LLVM IntPredicate type @@ -2107,6 +2107,15 @@ pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef { llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2) } } + +pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) { + unsafe { + let attr = attr as u64; + let lower = attr & 0xffffffff; + let upper = (attr >> 32) & 0xffffffff; + llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint); + } +} /* Memory-managed object interface to type handles. */ pub struct TypeNames { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 5070d678c9fab..e727907f88e74 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -419,46 +419,25 @@ pub fn get_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info { } pub fn set_optimize_for_size(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::OptimizeForSizeAttribute - as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::OptimizeForSizeAttribute) } pub fn set_no_inline(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::NoInlineAttribute as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::NoInlineAttribute) } pub fn set_no_unwind(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::NoUnwindAttribute as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::NoUnwindAttribute) } // Tell LLVM to emit the information necessary to unwind the stack for the // function f. pub fn set_uwtable(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::UWTableAttribute as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::UWTableAttribute) } pub fn set_inline_hint(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::InlineHintAttribute as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::InlineHintAttribute) } pub fn set_inline_hint_if_appr(attrs: &[ast::Attribute], @@ -473,17 +452,11 @@ pub fn set_inline_hint_if_appr(attrs: &[ast::Attribute], } pub fn set_always_inline(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::AlwaysInlineAttribute as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::AlwaysInlineAttribute) } pub fn set_fixed_stack_segment(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, 0, 1 << (39 - 32)); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::FixedStackSegment) } pub fn set_glue_inlining(f: ValueRef, t: ty::t) { From bb9393057557967ad88e9772f793531eb3f918f4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 1 Aug 2013 15:47:09 -0700 Subject: [PATCH 5/6] Add a workaround for 8199 for now --- src/librustc/lib/llvm.rs | 13 +++++++++++++ src/librustc/middle/trans/base.rs | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 5ec439ce386c5..40fe9bd5fc6a1 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -87,6 +87,8 @@ pub enum Attribute { NonLazyBindAttribute = 1 << 31, // Not added to LLVM yet, so may need to stay updated if LLVM changes. + // FIXME(#8199): if this changes, be sure to change the relevant constant + // down below FixedStackSegment = 1 << 41, } @@ -2116,6 +2118,17 @@ pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) { llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint); } } + +// FIXME(#8199): this shouldn't require this hackery. On i686 +// (FixedStackSegment as u64) will return 0 instead of 1 << 41. +// Furthermore, if we use a match of any sort then an LLVM +// assertion is generated! +pub fn SetFixedStackSegmentAttribute(Fn: ValueRef) { + let attr = 1u64 << 41; + let lower = attr & 0xffffffff; + let upper = (attr >> 32) & 0xffffffff; + llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint); +} /* Memory-managed object interface to type handles. */ pub struct TypeNames { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index e727907f88e74..fc39af095b79c 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -456,7 +456,7 @@ pub fn set_always_inline(f: ValueRef) { } pub fn set_fixed_stack_segment(f: ValueRef) { - lib::llvm::SetFunctionAttribute(f, lib::llvm::FixedStackSegment) + lib::llvm::SetFixedStackSegmentAttribute(f); } pub fn set_glue_inlining(f: ValueRef, t: ty::t) { From 60e9507086dd0329fc4e96897d4d89c7d6b271f6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 2 Aug 2013 00:55:49 -0700 Subject: [PATCH 6/6] Integrate new arm patch and fix an LLVM bug Thanks @luqama! --- src/librustc/lib/llvm.rs | 4 +++- src/llvm | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 40fe9bd5fc6a1..356cdaf754eeb 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -89,7 +89,7 @@ pub enum Attribute { // Not added to LLVM yet, so may need to stay updated if LLVM changes. // FIXME(#8199): if this changes, be sure to change the relevant constant // down below - FixedStackSegment = 1 << 41, + // FixedStackSegment = 1 << 41, } // enum for the LLVM IntPredicate type @@ -2124,10 +2124,12 @@ pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) { // Furthermore, if we use a match of any sort then an LLVM // assertion is generated! pub fn SetFixedStackSegmentAttribute(Fn: ValueRef) { + unsafe { let attr = 1u64 << 41; let lower = attr & 0xffffffff; let upper = (attr >> 32) & 0xffffffff; llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint); + } } /* Memory-managed object interface to type handles. */ diff --git a/src/llvm b/src/llvm index e3abef3eedc8d..f67442eee27d3 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit e3abef3eedc8d5bad3420c7e29bf2fe80585316a +Subproject commit f67442eee27d3d075a65cf7f9a70f7ec6649ffd1