1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! General transformation passes.

use super::Pass;
use crate::mlir_sys::{
    mlirCreateTransformsCSE, mlirCreateTransformsCanonicalizer, mlirCreateTransformsInliner,
    mlirCreateTransformsPrintOpStats, mlirCreateTransformsSCCP, mlirCreateTransformsStripDebugInfo,
    mlirCreateTransformsSymbolDCE, mlirCreateTransformsSymbolPrivatize,
    mlirRegisterConversionReconcileUnrealizedCasts, mlirRegisterTransformsCSE,
    mlirRegisterTransformsCanonicalizer, mlirRegisterTransformsInliner,
    mlirRegisterTransformsPrintOpStats, mlirRegisterTransformsSCCP,
    mlirRegisterTransformsStripDebugInfo, mlirRegisterTransformsSymbolDCE,
    mlirRegisterTransformsSymbolPrivatize,
};

/// Creates a pass to canonicalize IR.
pub fn canonicalizer() -> Pass {
    Pass::from_raw_fn(mlirCreateTransformsCanonicalizer)
}

/// Registers a pass to canonicalize IR.
pub fn register_canonicalizer() {
    unsafe { mlirRegisterTransformsCanonicalizer() }
}

/// Creates a pass to eliminate common sub-expressions.
pub fn cse() -> Pass {
    Pass::from_raw_fn(mlirCreateTransformsCSE)
}

/// Registers a pass to print operation stats.
pub fn register_cse() {
    unsafe { mlirRegisterTransformsCSE() }
}

/// Creates a pass to inline function calls.
pub fn inliner() -> Pass {
    Pass::from_raw_fn(mlirCreateTransformsInliner)
}

/// Registers a pass to inline function calls.
pub fn register_inliner() {
    unsafe { mlirRegisterTransformsInliner() }
}

/// Creates a pass to propagate constants.
pub fn sccp() -> Pass {
    Pass::from_raw_fn(mlirCreateTransformsSCCP)
}

/// Registers a pass to propagate constants.
pub fn register_sccp() {
    unsafe { mlirRegisterTransformsSCCP() }
}

/// Creates a pass to strip debug information.
pub fn strip_debug_info() -> Pass {
    Pass::from_raw_fn(mlirCreateTransformsStripDebugInfo)
}

/// Registers a pass to strip debug information.
pub fn register_strip_debug_info() {
    unsafe { mlirRegisterTransformsStripDebugInfo() }
}

/// Creates a pass to eliminate dead symbols.
pub fn symbol_dce() -> Pass {
    Pass::from_raw_fn(mlirCreateTransformsSymbolDCE)
}

/// Registers a pass to eliminate dead symbols.
pub fn register_symbol_dce() {
    unsafe { mlirRegisterTransformsSymbolDCE() }
}

/// Creates a pass to mark all top-level symbols private.
pub fn symbol_privatize() -> Pass {
    Pass::from_raw_fn(mlirCreateTransformsSymbolPrivatize)
}

/// Registers a pass to mark all top-level symbols private.
pub fn register_symbol_privatize() {
    unsafe { mlirRegisterTransformsSymbolPrivatize() }
}

/// Creates a pass to print operation statistics.
pub fn print_operation_stats() -> Pass {
    Pass::from_raw_fn(mlirCreateTransformsPrintOpStats)
}

/// Registers a pass to print operation stats.
pub fn register_print_operation_stats() {
    unsafe { mlirRegisterTransformsPrintOpStats() }
}

pub fn register_reconcile_casts() {
    unsafe { mlirRegisterConversionReconcileUnrealizedCasts() }
}