verify: implement P_Array_Append_One
[ajla.git] / stdlib / compiler / optimize / defs.ajla
blob33527f1ba49b13461d7b86f62d0b4531a1284800
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         block_name : bytes;
59         post_cut_nodes : int;
60         pre_cut_nodes : bool;
61         added_claims : list(bytes);
64 fn new_basic_block : basic_block
66         return basic_block.[
67                 active : true,
68                 instrs : empty(int),
69                 pred_list : empty(int),
70                 pred_position : empty(int),
71                 post_list : empty(int),
73                 dom : -1,
74                 dominates : -1,
75                 idom : -1,
76                 is_idom_of : -1,
77                 df : -1,
78                 uninitialized : -1,
79                 live_top : -1,
80                 live_bottom : -1,
82                 block_name : "",
83                 post_cut_nodes : 0,
84                 pre_cut_nodes : false,
85                 added_claims : empty(bytes),
86         ];
89 record variable [
90         type_index : int;
91         runtime_type : int;
92         local_type : int;
93         must_be_flat : bool;
94         must_be_data : bool;
95         name : bytes;
97         //reading_instrs : instr_set;
98         writing_instrs : instr_set;
99         reaching_def : int;
100         defining_block : int;
101         defining_instr : int;
103         color : int;
104         needed : bool;
106         ra_priority : int;
108         is_option_type : bool;
109         always_flat_option : bool;
111         verifier_name : list(bytes);
112         type_name : bytes;
115 fn new_variable : variable
117         return variable.[
118                 type_index : -1,
119                 runtime_type : -1,
120                 local_type : -1,
121                 must_be_flat : false,
122                 must_be_data : false,
123                 name : "",
124                 writing_instrs : -1,
125                 reaching_def : -1,
126                 defining_block : -1,
127                 defining_instr : -1,
128                 color : -1,
129                 needed : false,
130                 ra_priority : 0,
131                 is_option_type : false,
132                 always_flat_option : false,
133                 verifier_name : infinite(""),
134                 type_name : "",
135         ];
138 record function [
139         path_idx : int;
140         un : bytes;
141         program : bool;
142         fn_idx : list(int);
145 record local_type_flat_record [
146         non_flat_record : int;
147         flat_types : list(int);
150 record local_type_flat_array [
151         flat_type : int;
152         number_of_elements : int;
155 option local_type [
156         rec : function;
157         flat_rec : local_type_flat_record;
158         flat_array : local_type_flat_array;
161 type conflict_map := list(var_set);
163 record context [
164         local_types : list(local_type);
165         instrs : list(instruction);
166         blocks : list(basic_block);
167         variables : list(variable);
168         label_to_block : list(int);
169         var_map : list(int);
170         cm : conflict_map;
171         should_retry : bool;
172         name : bytes;
173         return_ins : instruction;