mie: implement instruction selection graph generation for binary ops and load/store

This commit is contained in:
2025-08-29 15:46:52 +01:00
parent 7fdae9f1e0
commit 9c1e0958b0
19 changed files with 1343 additions and 13 deletions

32
mie/select/instr.c Normal file
View File

@@ -0,0 +1,32 @@
#include "builder.h"
#include <mie/select/opcode.h>
#include <stddef.h>
#define DECLARE_INSTR_TYPE(name) extern struct select_instr_type select_##name
#define INSTR_TYPE_ENTRY(op, name) [MIE_INSTR_##op] = &select_##name
DECLARE_INSTR_TYPE(alloca);
DECLARE_INSTR_TYPE(add);
DECLARE_INSTR_TYPE(sub);
DECLARE_INSTR_TYPE(mul);
DECLARE_INSTR_TYPE(div);
DECLARE_INSTR_TYPE(load);
DECLARE_INSTR_TYPE(store);
static const struct select_instr_type *instr_types[] = {
INSTR_TYPE_ENTRY(ALLOCA, alloca), INSTR_TYPE_ENTRY(ADD, add),
INSTR_TYPE_ENTRY(SUB, sub), INSTR_TYPE_ENTRY(MUL, mul),
INSTR_TYPE_ENTRY(DIV, div), INSTR_TYPE_ENTRY(LOAD, load),
INSTR_TYPE_ENTRY(STORE, store),
};
static const size_t nr_instr_types = sizeof instr_types / sizeof instr_types[0];
const struct select_instr_type *select_type_for_instr(enum mie_instr_type instr)
{
if (instr < 0 || instr >= nr_instr_types) {
return NULL;
}
return instr_types[instr];
}