use rustc_hash::FxHashSet;
use crate::{
llir_nodes::{Call, Node},
opt::{
global_opt::Commands,
optimize_commands::{OptimizeCommand, OptimizeCommandKind},
},
};
pub fn optimize_call_chain(commands: &mut Commands) {
let mut encountered_functions = FxHashSet::default();
encountered_functions.reserve(commands.optimizer.functions.len());
for id in commands
.stats
.call_graph
.iter_dfs(commands.optimizer.runtime.root_blocks())
{
let function = commands.optimizer.get_function(id);
if let Some(Node::Call(Call { id: other_function })) = function.nodes().last() {
if other_function != &id && !encountered_functions.contains(&id) {
let idx = function.nodes.len() - 1;
commands.commands.push(OptimizeCommand::new(
(id, idx),
OptimizeCommandKind::InlineFunction,
));
encountered_functions.insert(*other_function);
}
}
}
}