cubecl_core/ir/
non_semantic.rs

1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4
5use crate::ir::fmt_vararg;
6
7use super::Variable;
8
9/// Operations that don't change the semantics of the kernel. In other words, operations that do not
10/// perform any computation, if they run at all. i.e. `println`, comments and debug symbols.
11///
12/// Can be safely removed or ignored without changing the kernel result.
13#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
14pub enum NonSemantic {
15    Source {
16        name: String,
17        file_name: String,
18        line: u32,
19        col: u32,
20    },
21    BeginCall {
22        name: String,
23        line: u32,
24        col: u32,
25    },
26    EndCall,
27    Line {
28        line: u32,
29        col: u32,
30    },
31    Print {
32        format_string: String,
33        args: Vec<Variable>,
34    },
35    Comment {
36        content: String,
37    },
38}
39
40impl Display for NonSemantic {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        match self {
43            NonSemantic::Print {
44                format_string,
45                args,
46            } => {
47                write!(f, "print({format_string}, {})", fmt_vararg(args))
48            }
49            NonSemantic::Comment { content } => write!(f, "//{content}"),
50            _ => {
51                // Debug info has no semantic meaning
52                Ok(())
53            }
54        }
55    }
56}