mie: ir: implement generation and text output of phi instruction
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <mie/ir/module.h>
|
||||
#include <mie/ir/msg.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/phi.h>
|
||||
#include <mie/ir/ptr.h>
|
||||
#include <mie/ir/record.h>
|
||||
#include <mie/type.h>
|
||||
@@ -785,9 +786,47 @@ struct mie_value *mie_builder_setelementptr(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_phi *mie_builder_phi(
|
||||
struct mie_value *mie_builder_phi(
|
||||
struct mie_builder *builder, struct mie_type *type,
|
||||
unsigned int nr_edges, const char *name)
|
||||
struct mie_phi_edge *edges, unsigned int nr_edges, const char *name)
|
||||
{
|
||||
return NULL;
|
||||
struct mie_block *block = builder->b_current_block;
|
||||
|
||||
if (!block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (block->b_terminator || !b_queue_empty(&block->b_instr)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_phi *phi = malloc(sizeof *phi);
|
||||
if (!phi) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(phi, 0x0, sizeof *phi);
|
||||
|
||||
mie_instr_init(&phi->p_base, MIE_INSTR_PHI);
|
||||
|
||||
phi->p_type = type;
|
||||
phi->p_nr_edges = nr_edges;
|
||||
phi->p_edges = calloc(nr_edges, sizeof(struct mie_phi_edge));
|
||||
if (!phi->p_edges) {
|
||||
free(phi);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(phi->p_edges, edges, nr_edges * sizeof(struct mie_phi_edge));
|
||||
|
||||
if (!mie_block_add_instr(builder->b_current_block, &phi->p_base)) {
|
||||
free(phi);
|
||||
free(phi->p_edges);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_func_generate_value_name(
|
||||
builder->b_current_block->b_parent, MIE_VALUE(phi), name);
|
||||
|
||||
return MIE_VALUE(phi);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user