warn when inline(never) is not respected

This commit is contained in:
molikto 2022-05-17 10:53:51 +08:00 committed by Eduard-Mihai Burtescu
parent a435c93317
commit cdbf4dec1d
2 changed files with 26 additions and 0 deletions

View File

@ -35,8 +35,12 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
// Drop all the functions we'll be inlining. (This also means we won't waste time processing
// inlines in functions that will get inlined)
let mut dropped_ids = FxHashSet::default();
let mut inlined_dont_inlines = Vec::new();
module.functions.retain(|f| {
if should_inline(&disallowed_argument_types, &disallowed_return_types, f) {
if has_dont_inline(f) {
inlined_dont_inlines.push(f.def_id().unwrap());
}
// TODO: We should insert all defined IDs in this function.
dropped_ids.insert(f.def_id().unwrap());
false
@ -44,6 +48,16 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
true
}
});
if !inlined_dont_inlines.is_empty() {
let names = get_names(module);
for f in inlined_dont_inlines {
sess.warn(&format!(
"function `{}` has `dont_inline` attribute, but need to be inlined because it has illegal argument or return types",
get_name(&names, f)
));
}
}
// Drop OpName etc. for inlined functions
module.debug_names.retain(|inst| {
!inst.operands.iter().any(|op| {
@ -204,6 +218,12 @@ fn compute_disallowed_argument_and_return_types(
(disallowed_argument_types, disallowed_return_types)
}
fn has_dont_inline(function: &Function) -> bool {
let def = function.def.as_ref().unwrap();
let control = def.operands[0].unwrap_function_control();
control.contains(FunctionControl::DONT_INLINE)
}
fn should_inline(
disallowed_argument_types: &FxHashSet<Word>,
disallowed_return_types: &FxHashSet<Word>,

View File

@ -0,0 +1,6 @@
warning: function `nested_ref::deep_load` has `dont_inline` attribute, but need to be inlined because it has illegal argument or return types
warning: function `nested_ref::deep_transpose` has `dont_inline` attribute, but need to be inlined because it has illegal argument or return types
warning: 2 warnings emitted