rework the verifier to prepare for loop cutting
[ajla.git] / newlib / compiler / optimize / defs.ajla
blob569b606e63c67fed7ec973aa00591c9ee42e884d
1 {*
2  * Copyright (C) 2024, 2025 Mikulas Patocka
3  *
4  * This file is part of Ajla.
5  *
6  * Ajla is free software: you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation, either version 3 of the License, or (at your option) any later
9  * version.
10  *
11  * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13  * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * Ajla. If not, see <https://www.gnu.org/licenses/>.
17  *}
19 private unit compiler.optimize.defs;
21 uses pcode;
23 const check : bool := false;
25 type node_set := int128;
26 type var_set := int128;
27 type instr_set := int128;
28 type param_set := int;
30 record instruction [
31         opcode : pcode_t;
32         params : list(pcode_t);
33         read_set : param_set;
34         write_set : param_set;
35         free_set : param_set;
36         lt_set : param_set;
37         conflict_1 : param_set;
38         conflict_2 : param_set;
39         borrow : int;
40         bb : int;
43 record basic_block [
44         active : bool;
45         instrs : list(int);
46         pred_list : list(int);
47         pred_position : list(int);
48         post_list : list(int);
49         dom : node_set;
50         dominates : node_set;
51         idom : int;
52         is_idom_of : node_set;
53         df : node_set;
54         uninitialized : var_set;
55         live_top : var_set;
56         live_bottom : var_set;
58         verifier_name : bytes;
61 fn new_basic_block : basic_block
63         return basic_block.[
64                 active : true,
65                 instrs : empty(int),
66                 pred_list : empty(int),
67                 pred_position : empty(int),
68                 post_list : empty(int),
70                 dom : -1,
71                 dominates : -1,
72                 idom : -1,
73                 is_idom_of : -1,
74                 df : -1,
75                 uninitialized : -1,
76                 live_top : -1,
77                 live_bottom : -1,
79                 verifier_name : "",
80         ];
83 record variable [
84         type_index : int;
85         runtime_type : int;
86         local_type : int;
87         must_be_flat : bool;
88         must_be_data : bool;
89         name : bytes;
91         //reading_instrs : instr_set;
92         writing_instrs : instr_set;
93         reaching_def : int;
94         defining_block : int;
95         defining_instr : int;
97         color : int;
98         needed : bool;
100         ra_priority : int;
102         is_option_type : bool;
103         always_flat_option : bool;
105         verifier_name : bytes;
106         verifier_valid : bytes;
109 fn new_variable : variable
111         return variable.[
112                 type_index : -1,
113                 runtime_type : -1,
114                 local_type : -1,
115                 must_be_flat : false,
116                 must_be_data : false,
117                 name : "",
118                 writing_instrs : -1,
119                 reaching_def : -1,
120                 defining_block : -1,
121                 defining_instr : -1,
122                 color : -1,
123                 needed : false,
124                 ra_priority : 0,
125                 is_option_type : false,
126                 always_flat_option : false,
127                 verifier_name : "",
128                 verifier_valid : "",
129         ];
132 record function [
133         path_idx : int;
134         un : bytes;
135         program : bool;
136         fn_idx : list(int);
139 record local_type_flat_record [
140         non_flat_record : int;
141         flat_types : list(int);
144 record local_type_flat_array [
145         flat_type : int;
146         number_of_elements : int;
149 option local_type [
150         rec : function;
151         flat_rec : local_type_flat_record;
152         flat_array : local_type_flat_array;
155 type conflict_map := list(var_set);
157 record context [
158         local_types : list(local_type);
159         instrs : list(instruction);
160         blocks : list(basic_block);
161         variables : list(variable);
162         label_to_block : list(int);
163         var_map : list(int);
164         cm : conflict_map;
165         should_retry : bool;
166         name : bytes;
167         return_ins : instruction;