Skip to content

Commit 09ae1c9

Browse files
committed
Add support for inline attribute
1 parent 17cbb61 commit 09ae1c9

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

Cargo.lock

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

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

src/attributes.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#[cfg(feature="master")]
22
use gccjit::FnAttribute;
33
use gccjit::Function;
4-
use rustc_attr::InstructionSetAttr;
4+
use rustc_attr::{InlineAttr, InstructionSetAttr};
55
use rustc_codegen_ssa::target_features::tied_target_features;
66
use rustc_data_structures::fx::FxHashMap;
77
use rustc_middle::ty;
8+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
89
use rustc_session::Session;
910
use rustc_span::symbol::sym;
1011
use smallvec::{smallvec, SmallVec};
@@ -67,6 +68,23 @@ fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> {
6768
}
6869
}
6970

71+
/// Get GCC attribute for the provided inline heuristic.
72+
#[inline]
73+
fn inline_attr<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, inline: InlineAttr) -> Option<FnAttribute<'gcc>> {
74+
match inline {
75+
InlineAttr::Hint => Some(FnAttribute::Inline),
76+
InlineAttr::Always => Some(FnAttribute::AlwaysInline),
77+
InlineAttr::Never => {
78+
if cx.sess().target.arch != "amdgpu" {
79+
Some(FnAttribute::NoInline)
80+
} else {
81+
None
82+
}
83+
}
84+
InlineAttr::None => None,
85+
}
86+
}
87+
7088
/// Composite function which sets GCC attributes for function depending on its AST (`#[attribute]`)
7189
/// attributes.
7290
pub fn from_fn_attrs<'gcc, 'tcx>(
@@ -77,6 +95,21 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
7795
) {
7896
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
7997

98+
// TODO: disable for libgccjit12?
99+
let inline =
100+
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
101+
InlineAttr::Never
102+
}
103+
else if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
104+
InlineAttr::Hint
105+
}
106+
else {
107+
codegen_fn_attrs.inline
108+
};
109+
if let Some(attr) = inline_attr(cx, inline) {
110+
func.add_attribute(attr);
111+
}
112+
80113
let function_features =
81114
codegen_fn_attrs.target_features.iter().map(|features| features.as_str()).collect::<Vec<&str>>();
82115

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)