Skip to content

Commit 7f91e77

Browse files
committed
Fix LLVM compilation issues and use the new attrs
This implements #[no_split_stack] and also changes #[fast_ffi] to using the new "fixedstacksegment" string attribute instead of integer attribute.
1 parent d1e4815 commit 7f91e77

File tree

6 files changed

+34
-36
lines changed

6 files changed

+34
-36
lines changed

src/librustc/back/passes.rs

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

src/librustc/lib/llvm.rs

+4-23
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ pub enum Attribute {
8585
ReturnsTwiceAttribute = 1 << 29,
8686
UWTableAttribute = 1 << 30,
8787
NonLazyBindAttribute = 1 << 31,
88-
89-
// Not added to LLVM yet, so may need to stay updated if LLVM changes.
90-
// FIXME(#8199): if this changes, be sure to change the relevant constant
91-
// down below
92-
// FixedStackSegment = 1 << 41,
9388
}
9489

9590
// enum for the LLVM IntPredicate type
@@ -843,7 +838,9 @@ pub mod llvm {
843838
#[fast_ffi]
844839
pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
845840
#[fast_ffi]
846-
pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint, HighPA: c_uint);
841+
pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
842+
#[fast_ffi]
843+
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
847844
#[fast_ffi]
848845
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
849846
#[fast_ffi]
@@ -2112,23 +2109,7 @@ pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
21122109

21132110
pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) {
21142111
unsafe {
2115-
let attr = attr as u64;
2116-
let lower = attr & 0xffffffff;
2117-
let upper = (attr >> 32) & 0xffffffff;
2118-
llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint);
2119-
}
2120-
}
2121-
2122-
// FIXME(#8199): this shouldn't require this hackery. On i686
2123-
// (FixedStackSegment as u64) will return 0 instead of 1 << 41.
2124-
// Furthermore, if we use a match of any sort then an LLVM
2125-
// assertion is generated!
2126-
pub fn SetFixedStackSegmentAttribute(Fn: ValueRef) {
2127-
unsafe {
2128-
let attr = 1u64 << 41;
2129-
let lower = attr & 0xffffffff;
2130-
let upper = (attr >> 32) & 0xffffffff;
2131-
llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint);
2112+
llvm::LLVMAddFunctionAttr(Fn, attr as c_uint)
21322113
}
21332114
}
21342115
/* Memory-managed object interface to type handles. */

src/librustc/middle/trans/base.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -440,23 +440,36 @@ pub fn set_inline_hint(f: ValueRef) {
440440
lib::llvm::SetFunctionAttribute(f, lib::llvm::InlineHintAttribute)
441441
}
442442

443-
pub fn set_inline_hint_if_appr(attrs: &[ast::Attribute],
444-
llfn: ValueRef) {
443+
pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) {
445444
use syntax::attr::*;
445+
// Set the inline hint if there is one
446446
match find_inline_attr(attrs) {
447447
InlineHint => set_inline_hint(llfn),
448448
InlineAlways => set_always_inline(llfn),
449449
InlineNever => set_no_inline(llfn),
450450
InlineNone => { /* fallthrough */ }
451451
}
452+
453+
// Add the no-split-stack attribute if requested
454+
if contains_name(attrs, "no_split_stack") {
455+
set_no_split_stack(llfn);
456+
}
452457
}
453458

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

458463
pub fn set_fixed_stack_segment(f: ValueRef) {
459-
lib::llvm::SetFixedStackSegmentAttribute(f);
464+
do "fixed-stack-segment".to_c_str().with_ref |buf| {
465+
unsafe { llvm::LLVMAddFunctionAttrString(f, buf); }
466+
}
467+
}
468+
469+
pub fn set_no_split_stack(f: ValueRef) {
470+
do "no-split-stack".to_c_str().with_ref |buf| {
471+
unsafe { llvm::LLVMAddFunctionAttrString(f, buf); }
472+
}
460473
}
461474

462475
pub fn set_glue_inlining(f: ValueRef, t: ty::t) {
@@ -2444,7 +2457,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
24442457
} else {
24452458
foreign::register_foreign_fn(ccx, i.span, sym, i.id)
24462459
};
2447-
set_inline_hint_if_appr(i.attrs, llfn);
2460+
set_llvm_fn_attrs(i.attrs, llfn);
24482461
llfn
24492462
}
24502463

@@ -2579,7 +2592,7 @@ pub fn register_method(ccx: @mut CrateContext,
25792592
let sym = exported_name(ccx, path, mty, m.attrs);
25802593

25812594
let llfn = register_fn(ccx, m.span, sym, id, mty);
2582-
set_inline_hint_if_appr(m.attrs, llfn);
2595+
set_llvm_fn_attrs(m.attrs, llfn);
25832596
llfn
25842597
}
25852598

src/librustc/middle/trans/monomorphize.rs

+4-4
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/rustllvm/RustWrapper.cpp

+7-3
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));
@@ -412,7 +412,7 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
412412
bool NoVerify = false;
413413
std::string ErrorInfo;
414414
raw_fd_ostream OS(path, ErrorInfo,
415-
raw_fd_ostream::F_Binary);
415+
sys::fs::F_Binary);
416416
if (ErrorInfo != "") {
417417
LLVMRustError = ErrorInfo.c_str();
418418
return false;
@@ -481,6 +481,10 @@ extern "C" LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C) {
481481
return wrap(Type::getMetadataTy(*unwrap(C)));
482482
}
483483

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

src/rustllvm/rustllvm.def.in

+1
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)