Skip to content

Commit 0cbf2b9

Browse files
authored
Merge pull request #267 from rust-lang/inline-attribute
Add support for inline attribute
2 parents 17cbb61 + b93041a commit 0cbf2b9

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

Diff for: Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ master = ["gccjit/master"]
2525
gccjit = { git = "https://github.com/antoyo/gccjit.rs" }
2626

2727
# Local copy.
28-
#gccjit = { path = "../gccjit.rs" }
28+
# gccjit = { path = "../gccjit.rs" }
2929

3030
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
3131

Diff for: src/attributes.rs

+39
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
use gccjit::FnAttribute;
33
use gccjit::Function;
44
use rustc_attr::InstructionSetAttr;
5+
#[cfg(feature="master")]
6+
use rustc_attr::InlineAttr;
57
use rustc_codegen_ssa::target_features::tied_target_features;
68
use rustc_data_structures::fx::FxHashMap;
79
use rustc_middle::ty;
10+
#[cfg(feature="master")]
11+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
812
use rustc_session::Session;
913
use rustc_span::symbol::sym;
1014
use smallvec::{smallvec, SmallVec};
@@ -67,6 +71,24 @@ fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> {
6771
}
6872
}
6973

74+
/// Get GCC attribute for the provided inline heuristic.
75+
#[cfg(feature="master")]
76+
#[inline]
77+
fn inline_attr<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, inline: InlineAttr) -> Option<FnAttribute<'gcc>> {
78+
match inline {
79+
InlineAttr::Hint => Some(FnAttribute::Inline),
80+
InlineAttr::Always => Some(FnAttribute::AlwaysInline),
81+
InlineAttr::Never => {
82+
if cx.sess().target.arch != "amdgpu" {
83+
Some(FnAttribute::NoInline)
84+
} else {
85+
None
86+
}
87+
}
88+
InlineAttr::None => None,
89+
}
90+
}
91+
7092
/// Composite function which sets GCC attributes for function depending on its AST (`#[attribute]`)
7193
/// attributes.
7294
pub fn from_fn_attrs<'gcc, 'tcx>(
@@ -77,6 +99,23 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
7799
) {
78100
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
79101

102+
#[cfg(feature="master")]
103+
{
104+
let inline =
105+
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
106+
InlineAttr::Never
107+
}
108+
else if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
109+
InlineAttr::Hint
110+
}
111+
else {
112+
codegen_fn_attrs.inline
113+
};
114+
if let Some(attr) = inline_attr(cx, inline) {
115+
func.add_attribute(attr);
116+
}
117+
}
118+
80119
let function_features =
81120
codegen_fn_attrs.target_features.iter().map(|features| features.as_str()).collect::<Vec<&str>>();
82121

Diff for: src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ impl CodegenBackend for GccCodegenBackend {
110110
}
111111

112112
fn init(&self, sess: &Session) {
113+
#[cfg(feature="master")]
114+
gccjit::set_global_personality_function_name(b"rust_eh_personality\0");
113115
if sess.lto() != Lto::No {
114116
sess.emit_warning(LTONotSupported {});
115117
}

0 commit comments

Comments
 (0)