cubecl_core/post_processing/
mod.rs1pub mod analysis_helper;
2pub mod checked_io;
3pub mod dead_code;
4pub mod disaggregate;
5pub mod expression_merge;
6pub mod predicate;
7pub mod saturating;
8pub mod unroll;
9pub mod util;
10
11pub mod constant_prop;
13
14pub mod visitor;
15
16use cubecl_ir::Scope;
17
18use crate::post_processing::{
19 analysis_helper::{BufferVisibility, GlobalAnalyses},
20 constant_prop::{ConstEval, ConstOperandSimplify},
21 dead_code::EliminateUnusedExpressions,
22 expression_merge::InlineAssignments,
23 util::AtomicCounter,
24 visitor::InstructionVisitor,
25};
26
27pub fn optimize_scope(scope: &Scope) -> BufferVisibility {
28 let analyses = GlobalAnalyses::default();
29 analyses.recalculate_pointer_source(scope);
30
31 let changes = AtomicCounter::new(1);
32 while changes.get_and_reset() != 0 {
33 ConstOperandSimplify.visit_scope(scope, &analyses, &changes);
34 ConstEval.visit_scope(scope, &analyses, &changes);
35 ConstEval.visit_scope(scope, &analyses, &changes);
36 InlineAssignments::default().visit_scope(scope, &analyses, &changes);
37
38 analyses.recalculate_used_values(scope);
39 EliminateUnusedExpressions.visit_scope(scope, &analyses, &changes);
40 }
41
42 BufferVisibility::new(scope, &analyses)
43}