23 Pass(
"IROptimizer", debug)
29 Rule { { LOAD_CONST, LOAD_CONST }, LOAD_CONST_LOAD_CONST },
30 Rule { { LOAD_CONST, STORE }, LOAD_CONST_STORE },
31 Rule { { LOAD_CONST, SET_VAL }, LOAD_CONST_SET_VAL },
32 Rule { { LOAD_FAST, STORE }, STORE_FROM },
33 Rule { { LOAD_FAST_BY_INDEX, STORE }, STORE_FROM_INDEX },
34 Rule { { LOAD_FAST, SET_VAL }, SET_VAL_FROM },
35 Rule { { LOAD_FAST_BY_INDEX, SET_VAL }, SET_VAL_FROM_INDEX },
36 Rule { { STORE, PUSH_RETURN_ADDRESS, LOAD_FAST_BY_INDEX, CALL_BUILTIN },
37 [](
const Entities entities,
const std::size_t start_idx) {
38 return start_idx == 0 && entities[5].inst() == RET;
41 return IR::Entity(CALL_BUILTIN_WITHOUT_RETURN_ADDRESS, e[3].primaryArg(), 1);
43 Rule { { STORE, STORE, PUSH_RETURN_ADDRESS, LOAD_FAST_BY_INDEX, LOAD_FAST_BY_INDEX, CALL_BUILTIN },
44 [](
const Entities entities,
const std::size_t start_idx) {
45 return start_idx == 0 && entities[7].inst() == RET;
48 return IR::Entity(CALL_BUILTIN_WITHOUT_RETURN_ADDRESS, e[5].primaryArg(), 2);
50 Rule { { STORE, STORE, STORE, PUSH_RETURN_ADDRESS, LOAD_FAST_BY_INDEX, LOAD_FAST_BY_INDEX, LOAD_FAST_BY_INDEX, CALL_BUILTIN },
51 [](
const Entities entities,
const std::size_t start_idx) {
52 return start_idx == 0 && entities[9].inst() == RET;
55 return IR::Entity(CALL_BUILTIN_WITHOUT_RETURN_ADDRESS, e[7].primaryArg(), 3);
57 Rule { { LOAD_FAST, GET_FIELD }, GET_FIELD_FROM_SYMBOL },
58 Rule { { LOAD_FAST_BY_INDEX, GET_FIELD }, GET_FIELD_FROM_SYMBOL_INDEX },
59 Rule { { LIST, STORE }, STORE_LIST },
60 Rule { { LOAD_FAST, APPEND_IN_PLACE }, APPEND_IN_PLACE_SYM },
61 Rule { { LOAD_FAST_BY_INDEX, APPEND_IN_PLACE }, APPEND_IN_PLACE_SYM_INDEX },
64 Rule { { LOAD_CONST, LOAD_FAST, MUL, SET_VAL }, [
this](
const Entities e,
const std::size_t) {
70 Rule { { LOAD_FAST, LOAD_CONST, MUL, SET_VAL }, [
this](
const Entities e,
const std::size_t) {
78 Rule { { LOAD_CONST, LOAD_FAST, MUL }, [
this](
const Entities e,
const std::size_t) {
84 Rule { { LOAD_FAST, LOAD_CONST, MUL }, [
this](
const Entities e,
const std::size_t) {
90 Rule { { LOAD_CONST, LOAD_FAST_BY_INDEX, MUL }, [
this](
const Entities e,
const std::size_t) {
96 Rule { { LOAD_FAST_BY_INDEX, LOAD_CONST, MUL }, [
this](
const Entities e,
const std::size_t) {
104 Rule { { LOAD_CONST, LOAD_FAST, ADD, SET_VAL }, [
this](
const Entities e,
const std::size_t) {
110 Rule { { LOAD_FAST, LOAD_CONST, ADD, SET_VAL }, [
this](
const Entities e,
const std::size_t) {
116 Rule { { LOAD_FAST, LOAD_CONST, SUB, SET_VAL }, [
this](
const Entities e,
const std::size_t) {
123 Rule { { LOAD_CONST, LOAD_FAST, ADD }, [
this](
const Entities e,
const std::size_t) {
129 Rule { { LOAD_FAST, LOAD_CONST, ADD }, [
this](
const Entities e,
const std::size_t) {
135 Rule { { LOAD_FAST, LOAD_CONST, SUB }, [
this](
const Entities e,
const std::size_t) {
141 Rule { { LOAD_CONST, LOAD_FAST_BY_INDEX, ADD }, [
this](
const Entities e,
const std::size_t) {
147 Rule { { LOAD_FAST_BY_INDEX, LOAD_CONST, ADD }, [
this](
const Entities e,
const std::size_t) {
153 Rule { { LOAD_FAST_BY_INDEX, LOAD_CONST, SUB }, [
this](
const Entities e,
const std::size_t) {
161 Rule { { LOAD_FAST, TAIL, STORE }, [](
const Entities e) {
162 return IR::Entity(STORE_TAIL, e[0].primaryArg(), e[2].primaryArg());
164 Rule { { LOAD_FAST, TAIL, SET_VAL }, [](
const Entities e) {
165 return IR::Entity(SET_VAL_TAIL, e[0].primaryArg(), e[2].primaryArg());
167 Rule { { LOAD_FAST, HEAD, STORE }, [](
const Entities e) {
168 return IR::Entity(STORE_HEAD, e[0].primaryArg(), e[2].primaryArg());
170 Rule { { LOAD_FAST, HEAD, SET_VAL }, [](
const Entities e) {
171 return IR::Entity(SET_VAL_HEAD, e[0].primaryArg(), e[2].primaryArg());
173 Rule { { LOAD_FAST_BY_INDEX, TAIL, STORE }, [](
const Entities e) {
174 return IR::Entity(STORE_TAIL_BY_INDEX, e[0].primaryArg(), e[2].primaryArg());
176 Rule { { LOAD_FAST_BY_INDEX, TAIL, SET_VAL }, [](
const Entities e) {
177 return IR::Entity(SET_VAL_TAIL_BY_INDEX, e[0].primaryArg(), e[2].primaryArg());
179 Rule { { LOAD_FAST_BY_INDEX, HEAD, STORE }, [](
const Entities e) {
180 return IR::Entity(STORE_HEAD_BY_INDEX, e[0].primaryArg(), e[2].primaryArg());
182 Rule { { LOAD_FAST_BY_INDEX, HEAD, SET_VAL }, [](
const Entities e) {
183 return IR::Entity(SET_VAL_HEAD_BY_INDEX, e[0].primaryArg(), e[2].primaryArg());
187 Rule { { LOAD_CONST, LT, POP_JUMP_IF_FALSE }, [](
const Entities e) {
190 Rule { { LOAD_CONST, LT, POP_JUMP_IF_TRUE }, [](
const Entities e) {
193 Rule { { LOAD_FAST, LT, POP_JUMP_IF_FALSE }, [](
const Entities e) {
196 Rule { { LOAD_CONST, GT, POP_JUMP_IF_TRUE }, [](
const Entities e) {
199 Rule { { LOAD_CONST, GT, POP_JUMP_IF_FALSE }, [](
const Entities e) {
202 Rule { { LOAD_FAST, GT, POP_JUMP_IF_FALSE }, [](
const Entities e) {
205 Rule { { LOAD_CONST, EQ, POP_JUMP_IF_TRUE }, [](
const Entities e) {
208 Rule { { LOAD_FAST_BY_INDEX, EQ, POP_JUMP_IF_TRUE }, [](
const Entities e) {
211 Rule { { LOAD_CONST, NEQ, POP_JUMP_IF_TRUE }, [](
const Entities e) {
214 Rule { { LOAD_FAST, NEQ, POP_JUMP_IF_FALSE }, [](
const Entities e) {
219 Rule { { LOAD_FAST, LOAD_FAST, AT }, AT_SYM_SYM },
220 Rule { { LOAD_FAST_BY_INDEX, LOAD_FAST_BY_INDEX, AT }, AT_SYM_INDEX_SYM_INDEX },
221 Rule { { LOAD_FAST_BY_INDEX, LOAD_CONST, AT }, AT_SYM_INDEX_CONST },
225 Rule { { LOAD_FAST, TYPE, LOAD_CONST, EQ }, [](
const Entities e) {
226 return IR::Entity(CHECK_TYPE_OF, e[0].primaryArg(), e[2].primaryArg());
228 Rule { { LOAD_CONST, LOAD_FAST, TYPE, EQ }, [](
const Entities e) {
229 return IR::Entity(CHECK_TYPE_OF, e[1].primaryArg(), e[0].primaryArg());
231 Rule { { LOAD_FAST_BY_INDEX, TYPE, LOAD_CONST, EQ }, [](
const Entities e) {
232 return IR::Entity(CHECK_TYPE_OF_BY_INDEX, e[0].primaryArg(), e[2].primaryArg());
234 Rule { { LOAD_CONST, LOAD_FAST_BY_INDEX, TYPE, EQ }, [](
const Entities e) {
235 return IR::Entity(CHECK_TYPE_OF_BY_INDEX, e[1].primaryArg(), e[0].primaryArg());
238 Rule { { LOAD_FAST_BY_INDEX, LEN, STORE }, [](
const Entities e) {
239 return IR::Entity(STORE_LEN, e[0].primaryArg(), e[2].primaryArg());
241 Rule { { LOAD_FAST, LEN, LT, POP_JUMP_IF_FALSE }, [](
const Entities e) {
246 const auto math_ops = { ADD, SUB, MUL, DIV };
247 for (
const auto& one : math_ops)
249 for (
const auto& two : math_ops)
251 for (
const auto& three : math_ops)