Skip to content

Commit a8c3fe4

Browse files
committed
auto merge of #8328 : alexcrichton/rust/llvm-head, r=brson
The first commit message is pretty good, but whomever reviews this should probably also at least glance at the changes I made in LLVM. I basically reorganized our pending patch queue to be a bit more organized and clearer in what needs to go where. After this, our queue would be: * Add the `no-split-stack` attribute * Add the `fixedstacksegment` attribute * Add split-stacks for arm android * Add split-stacks for arm linux * Add split stacks for mips Then there's a patch which I added to get rust to build at all on LLVM-head, and I'm not quite sure why it's there, but nothing seems to be crashing for now! (famous last words). Otherwise, I just updated code to reflect the changes I made in LLVM with the only major change being the advent of the new `no_split_stack` attribute. This is work towards #1226, but someone more familiar with the code should probably actually assign the attribute to the appropriate functions. Also as a bonus, I've verified that this closes #5774
2 parents 67c954e + 7f91e77 commit a8c3fe4

File tree

8 files changed

+36
-38
lines changed

8 files changed

+36
-38
lines changed

src/librustc/back/passes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ pub static transform_passes : &'static [(&'static str, &'static str)] = &'static
293293
("scalarrepl", "Scalar Replacement of Aggregates (DT)"),
294294
("scalarrepl-ssa", "Scalar Replacement of Aggregates (SSAUp)"),
295295
("sccp", "Sparse Conditional Constant Propagation"),
296-
("simplify-libcalls", "Simplify well-known library calls"),
297296
("simplifycfg", "Simplify the CFG"),
298297
("sink", "Code sinking"),
299298
("strip", "Strip all symbols from a module"),

src/librustc/lib/llvm.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ pub enum Attribute {
8989
ReturnsTwiceAttribute = 1 << 29,
9090
UWTableAttribute = 1 << 30,
9191
NonLazyBindAttribute = 1 << 31,
92-
93-
// Not added to LLVM yet, so may need to stay updated if LLVM changes.
94-
// FIXME(#8199): if this changes, be sure to change the relevant constant
95-
// down below
96-
// FixedStackSegment = 1 << 41,
9792
}
9893

9994
// enum for the LLVM IntPredicate type
@@ -847,7 +842,9 @@ pub mod llvm {
847842
#[fast_ffi]
848843
pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
849844
#[fast_ffi]
850-
pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint, HighPA: c_uint);
845+
pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
846+
#[fast_ffi]
847+
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
851848
#[fast_ffi]
852849
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
853850
#[fast_ffi]
@@ -2138,23 +2135,7 @@ pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
21382135

21392136
pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) {
21402137
unsafe {
2141-
let attr = attr as u64;
2142-
let lower = attr & 0xffffffff;
2143-
let upper = (attr >> 32) & 0xffffffff;
2144-
llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint);
2145-
}
2146-
}
2147-
2148-
// FIXME(#8199): this shouldn't require this hackery. On i686
2149-
// (FixedStackSegment as u64) will return 0 instead of 1 << 41.
2150-
// Furthermore, if we use a match of any sort then an LLVM
2151-
// assertion is generated!
2152-
pub fn SetFixedStackSegmentAttribute(Fn: ValueRef) {
2153-
unsafe {
2154-
let attr = 1u64 << 41;
2155-
let lower = attr & 0xffffffff;
2156-
let upper = (attr >> 32) & 0xffffffff;
2157-
llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint);
2138+
llvm::LLVMAddFunctionAttr(Fn, attr as c_uint)
21582139
}
21592140
}
21602141
/* Memory-managed object interface to type handles. */

src/librustc/middle/trans/base.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,23 +442,36 @@ pub fn set_inline_hint(f: ValueRef) {
442442
lib::llvm::SetFunctionAttribute(f, lib::llvm::InlineHintAttribute)
443443
}
444444

445-
pub fn set_inline_hint_if_appr(attrs: &[ast::Attribute],
446-
llfn: ValueRef) {
445+
pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) {
447446
use syntax::attr::*;
447+
// Set the inline hint if there is one
448448
match find_inline_attr(attrs) {
449449
InlineHint => set_inline_hint(llfn),
450450
InlineAlways => set_always_inline(llfn),
451451
InlineNever => set_no_inline(llfn),
452452
InlineNone => { /* fallthrough */ }
453453
}
454+
455+
// Add the no-split-stack attribute if requested
456+
if contains_name(attrs, "no_split_stack") {
457+
set_no_split_stack(llfn);
458+
}
454459
}
455460

456461
pub fn set_always_inline(f: ValueRef) {
457462
lib::llvm::SetFunctionAttribute(f, lib::llvm::AlwaysInlineAttribute)
458463
}
459464

460465
pub fn set_fixed_stack_segment(f: ValueRef) {
461-
lib::llvm::SetFixedStackSegmentAttribute(f);
466+
do "fixed-stack-segment".to_c_str().with_ref |buf| {
467+
unsafe { llvm::LLVMAddFunctionAttrString(f, buf); }
468+
}
469+
}
470+
471+
pub fn set_no_split_stack(f: ValueRef) {
472+
do "no-split-stack".to_c_str().with_ref |buf| {
473+
unsafe { llvm::LLVMAddFunctionAttrString(f, buf); }
474+
}
462475
}
463476

464477
pub fn set_glue_inlining(f: ValueRef, t: ty::t) {
@@ -2472,7 +2485,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
24722485
sym,
24732486
i.id)
24742487
};
2475-
set_inline_hint_if_appr(i.attrs, llfn);
2488+
set_llvm_fn_attrs(i.attrs, llfn);
24762489
llfn
24772490
}
24782491

@@ -2605,7 +2618,7 @@ pub fn register_method(ccx: @mut CrateContext,
26052618
let sym = exported_name(ccx, path, mty, m.attrs);
26062619

26072620
let llfn = register_fn(ccx, m.span, sym, id, mty);
2608-
set_inline_hint_if_appr(m.attrs, llfn);
2621+
set_llvm_fn_attrs(m.attrs, llfn);
26092622
llfn
26102623
}
26112624

src/librustc/middle/trans/monomorphize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use back::link::mangle_exported_name;
1313
use driver::session;
1414
use lib::llvm::ValueRef;
15-
use middle::trans::base::{set_inline_hint_if_appr, set_inline_hint};
15+
use middle::trans::base::{set_llvm_fn_attrs, set_inline_hint};
1616
use middle::trans::base::{trans_enum_variant,push_ctxt};
1717
use middle::trans::base::{trans_fn, decl_internal_cdecl_fn};
1818
use middle::trans::base::{get_item_val, no_self};
@@ -222,7 +222,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
222222
_
223223
}, _) => {
224224
let d = mk_lldecl();
225-
set_inline_hint_if_appr(i.attrs, d);
225+
set_llvm_fn_attrs(i.attrs, d);
226226
trans_fn(ccx,
227227
pt,
228228
decl,
@@ -266,13 +266,13 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
266266
ast_map::node_method(mth, _, _) => {
267267
// XXX: What should the self type be here?
268268
let d = mk_lldecl();
269-
set_inline_hint_if_appr(mth.attrs.clone(), d);
269+
set_llvm_fn_attrs(mth.attrs, d);
270270
meth::trans_method(ccx, pt, mth, Some(psubsts), d);
271271
d
272272
}
273273
ast_map::node_trait_method(@ast::provided(mth), _, pt) => {
274274
let d = mk_lldecl();
275-
set_inline_hint_if_appr(mth.attrs.clone(), d);
275+
set_llvm_fn_attrs(mth.attrs, d);
276276
meth::trans_method(ccx, (*pt).clone(), mth, Some(psubsts), d);
277277
d
278278
}

src/llvm

Submodule llvm updated 5382 files

src/rustllvm/RustWrapper.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern "C" void LLVMRustAddPrintModulePass(LLVMPassManagerRef PMR,
4343
const char* path) {
4444
PassManager *PM = unwrap<PassManager>(PMR);
4545
std::string ErrorInfo;
46-
raw_fd_ostream OS(path, ErrorInfo, raw_fd_ostream::F_Binary);
46+
raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_Binary);
4747
formatted_raw_ostream FOS(OS);
4848
PM->add(createPrintModulePass(&FOS));
4949
PM->run(*unwrap(M));
@@ -413,7 +413,7 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
413413
bool NoVerify = false;
414414
std::string ErrorInfo;
415415
raw_fd_ostream OS(path, ErrorInfo,
416-
raw_fd_ostream::F_Binary);
416+
sys::fs::F_Binary);
417417
if (ErrorInfo != "") {
418418
LLVMRustError = ErrorInfo.c_str();
419419
return false;
@@ -482,6 +482,10 @@ extern "C" LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C) {
482482
return wrap(Type::getMetadataTy(*unwrap(C)));
483483
}
484484

485+
extern "C" void LLVMAddFunctionAttrString(LLVMValueRef fn, const char *Name) {
486+
unwrap<Function>(fn)->addFnAttr(Name);
487+
}
488+
485489
extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,
486490
LLVMValueRef source,
487491
const char* Name,
@@ -625,7 +629,7 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateFunction(
625629
return wrap(Builder->createFunction(
626630
unwrapDI<DIScope>(Scope), Name, LinkageName,
627631
unwrapDI<DIFile>(File), LineNo,
628-
unwrapDI<DIType>(Ty), isLocalToUnit, isDefinition, ScopeLine,
632+
unwrapDI<DICompositeType>(Ty), isLocalToUnit, isDefinition, ScopeLine,
629633
Flags, isOptimized,
630634
unwrap<Function>(Fn),
631635
unwrapDI<MDNode*>(TParam),

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-
2013-07-04
4+
2013-08-20

src/rustllvm/rustllvm.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ LLVMAddDestination
4242
LLVMAddEarlyCSEPass
4343
LLVMAddFunction
4444
LLVMAddFunctionAttr
45+
LLVMAddFunctionAttrString
4546
LLVMAddFunctionAttrsPass
4647
LLVMAddFunctionInliningPass
4748
LLVMAddGVNPass

0 commit comments

Comments
 (0)