Skip to content

Commit

Permalink
Fix LLVM compilation issues and use the new attrs
Browse files Browse the repository at this point in the history
This implements #[no_split_stack] and also changes #[fast_ffi] to using the new
"fixedstacksegment" string attribute instead of integer attribute.
  • Loading branch information
alexcrichton committed Aug 20, 2013
1 parent d1e4815 commit 7f91e77
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/librustc/back/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ pub static transform_passes : &'static [(&'static str, &'static str)] = &'static
("scalarrepl", "Scalar Replacement of Aggregates (DT)"),
("scalarrepl-ssa", "Scalar Replacement of Aggregates (SSAUp)"),
("sccp", "Sparse Conditional Constant Propagation"),
("simplify-libcalls", "Simplify well-known library calls"),
("simplifycfg", "Simplify the CFG"),
("sink", "Code sinking"),
("strip", "Strip all symbols from a module"),
Expand Down
27 changes: 4 additions & 23 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ pub enum Attribute {
ReturnsTwiceAttribute = 1 << 29,
UWTableAttribute = 1 << 30,
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,
}

// enum for the LLVM IntPredicate type
Expand Down Expand Up @@ -843,7 +838,9 @@ pub mod llvm {
#[fast_ffi]
pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
#[fast_ffi]
pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint, HighPA: c_uint);
pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
#[fast_ffi]
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
#[fast_ffi]
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
#[fast_ffi]
Expand Down Expand Up @@ -2112,23 +2109,7 @@ pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {

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);
}
}

// 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) {
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);
llvm::LLVMAddFunctionAttr(Fn, attr as c_uint)
}
}
/* Memory-managed object interface to type handles. */
Expand Down
23 changes: 18 additions & 5 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,23 +440,36 @@ pub fn set_inline_hint(f: ValueRef) {
lib::llvm::SetFunctionAttribute(f, lib::llvm::InlineHintAttribute)
}

pub fn set_inline_hint_if_appr(attrs: &[ast::Attribute],
llfn: ValueRef) {
pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) {
use syntax::attr::*;
// Set the inline hint if there is one
match find_inline_attr(attrs) {
InlineHint => set_inline_hint(llfn),
InlineAlways => set_always_inline(llfn),
InlineNever => set_no_inline(llfn),
InlineNone => { /* fallthrough */ }
}

// Add the no-split-stack attribute if requested
if contains_name(attrs, "no_split_stack") {
set_no_split_stack(llfn);
}
}

pub fn set_always_inline(f: ValueRef) {
lib::llvm::SetFunctionAttribute(f, lib::llvm::AlwaysInlineAttribute)
}

pub fn set_fixed_stack_segment(f: ValueRef) {
lib::llvm::SetFixedStackSegmentAttribute(f);
do "fixed-stack-segment".to_c_str().with_ref |buf| {
unsafe { llvm::LLVMAddFunctionAttrString(f, buf); }
}
}

pub fn set_no_split_stack(f: ValueRef) {
do "no-split-stack".to_c_str().with_ref |buf| {
unsafe { llvm::LLVMAddFunctionAttrString(f, buf); }
}
}

pub fn set_glue_inlining(f: ValueRef, t: ty::t) {
Expand Down Expand Up @@ -2444,7 +2457,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
} else {
foreign::register_foreign_fn(ccx, i.span, sym, i.id)
};
set_inline_hint_if_appr(i.attrs, llfn);
set_llvm_fn_attrs(i.attrs, llfn);
llfn
}

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

let llfn = register_fn(ccx, m.span, sym, id, mty);
set_inline_hint_if_appr(m.attrs, llfn);
set_llvm_fn_attrs(m.attrs, llfn);
llfn
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use back::link::mangle_exported_name;
use driver::session;
use lib::llvm::ValueRef;
use middle::trans::base::{set_inline_hint_if_appr, set_inline_hint};
use middle::trans::base::{set_llvm_fn_attrs, set_inline_hint};
use middle::trans::base::{trans_enum_variant,push_ctxt};
use middle::trans::base::{trans_fn, decl_internal_cdecl_fn};
use middle::trans::base::{get_item_val, no_self};
Expand Down Expand Up @@ -222,7 +222,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
_
}, _) => {
let d = mk_lldecl();
set_inline_hint_if_appr(i.attrs, d);
set_llvm_fn_attrs(i.attrs, d);
trans_fn(ccx,
pt,
decl,
Expand Down Expand Up @@ -266,13 +266,13 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
ast_map::node_method(mth, _, _) => {
// XXX: What should the self type be here?
let d = mk_lldecl();
set_inline_hint_if_appr(mth.attrs.clone(), d);
set_llvm_fn_attrs(mth.attrs, d);
meth::trans_method(ccx, pt, mth, Some(psubsts), d);
d
}
ast_map::node_trait_method(@ast::provided(mth), _, pt) => {
let d = mk_lldecl();
set_inline_hint_if_appr(mth.attrs.clone(), d);
set_llvm_fn_attrs(mth.attrs, d);
meth::trans_method(ccx, (*pt).clone(), mth, Some(psubsts), d);
d
}
Expand Down
10 changes: 7 additions & 3 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern "C" void LLVMRustAddPrintModulePass(LLVMPassManagerRef PMR,
const char* path) {
PassManager *PM = unwrap<PassManager>(PMR);
std::string ErrorInfo;
raw_fd_ostream OS(path, ErrorInfo, raw_fd_ostream::F_Binary);
raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_Binary);
formatted_raw_ostream FOS(OS);
PM->add(createPrintModulePass(&FOS));
PM->run(*unwrap(M));
Expand Down Expand Up @@ -412,7 +412,7 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
bool NoVerify = false;
std::string ErrorInfo;
raw_fd_ostream OS(path, ErrorInfo,
raw_fd_ostream::F_Binary);
sys::fs::F_Binary);
if (ErrorInfo != "") {
LLVMRustError = ErrorInfo.c_str();
return false;
Expand Down Expand Up @@ -481,6 +481,10 @@ extern "C" LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C) {
return wrap(Type::getMetadataTy(*unwrap(C)));
}

extern "C" void LLVMAddFunctionAttrString(LLVMValueRef fn, const char *Name) {
unwrap<Function>(fn)->addFnAttr(Name);
}

extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,
LLVMValueRef source,
const char* Name,
Expand Down Expand Up @@ -624,7 +628,7 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateFunction(
return wrap(Builder->createFunction(
unwrapDI<DIScope>(Scope), Name, LinkageName,
unwrapDI<DIFile>(File), LineNo,
unwrapDI<DIType>(Ty), isLocalToUnit, isDefinition, ScopeLine,
unwrapDI<DICompositeType>(Ty), isLocalToUnit, isDefinition, ScopeLine,
Flags, isOptimized,
unwrap<Function>(Fn),
unwrapDI<MDNode*>(TParam),
Expand Down
1 change: 1 addition & 0 deletions src/rustllvm/rustllvm.def.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ LLVMAddDestination
LLVMAddEarlyCSEPass
LLVMAddFunction
LLVMAddFunctionAttr
LLVMAddFunctionAttrString
LLVMAddFunctionAttrsPass
LLVMAddFunctionInliningPass
LLVMAddGVNPass
Expand Down

5 comments on commit 7f91e77

@bors
Copy link
Contributor

@bors bors commented on 7f91e77 Aug 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@7f91e77

@bors
Copy link
Contributor

@bors bors commented on 7f91e77 Aug 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/llvm-head = 7f91e77 into auto

@bors
Copy link
Contributor

@bors bors commented on 7f91e77 Aug 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/llvm-head = 7f91e77 merged ok, testing candidate = a8c3fe4

@bors
Copy link
Contributor

@bors bors commented on 7f91e77 Aug 20, 2013

@bors
Copy link
Contributor

@bors bors commented on 7f91e77 Aug 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = a8c3fe4

Please sign in to comment.