diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-25 14:29:48 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-25 14:55:25 +0200 |
| commit | 96f388f0f55cfa1984daa70d7dc4faa63a85c590 (patch) | |
| tree | 5a8af02749000a8228f4d8f68720f088356faef6 /linearize.c | |
| parent | d46b7b2f9fc4769d8dce72913bfac370f1d69df5 (diff) | |
| parent | 3f06ccfcc0be01c0d5bc6a982c2fbadf62fa502a (diff) | |
| download | sparse-dev-96f388f0f55cfa1984daa70d7dc4faa63a85c590.tar.gz | |
Merge branch 'ssa' into tip
* do 'classical' SSA conversion (via the iterated dominance frontier).
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'linearize.c')
| -rw-r--r-- | linearize.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/linearize.c b/linearize.c index 2e9a5638..a56c272f 100644 --- a/linearize.c +++ b/linearize.c @@ -172,6 +172,8 @@ const char *show_pseudo(pseudo_t pseudo) if (pseudo->ident) sprintf(buf+i, "(%s)", show_ident(pseudo->ident)); break; + case PSEUDO_UNDEF: + return "UNDEF"; default: snprintf(buf, 64, "<bad pseudo type %d>", pseudo->type); } @@ -829,6 +831,13 @@ pseudo_t value_pseudo(long long val) return pseudo; } +pseudo_t undef_pseudo(void) +{ + pseudo_t pseudo = __alloc_pseudo(0); + pseudo->type = PSEUDO_UNDEF; + return pseudo; +} + static pseudo_t argument_pseudo(struct entrypoint *ep, int nr) { pseudo_t pseudo = __alloc_pseudo(0); @@ -871,6 +880,42 @@ pseudo_t alloc_phi(struct basic_block *source, pseudo_t pseudo, struct symbol *t return insn->target; } +struct instruction *alloc_phi_node(struct basic_block *bb, struct symbol *type, struct ident *ident) +{ + struct instruction *phi_node = alloc_typed_instruction(OP_PHI, type); + pseudo_t phi; + + phi = alloc_pseudo(phi_node); + phi->ident = ident; + phi->def = phi_node; + phi_node->target = phi; + phi_node->bb = bb; + return phi_node; +} + +void add_phi_node(struct basic_block *bb, struct instruction *phi_node) +{ + struct instruction *insn; + + FOR_EACH_PTR(bb->insns, insn) { + enum opcode op = insn->opcode; + if (op == OP_PHI) + continue; + INSERT_CURRENT(phi_node, insn); + return; + } END_FOR_EACH_PTR(insn); + + // FIXME + add_instruction(&bb->insns, phi_node); +} + +struct instruction *insert_phi_node(struct basic_block *bb, struct symbol *var) +{ + struct instruction *phi_node = alloc_phi_node(bb, var, var->ident); + add_phi_node(bb, phi_node); + return phi_node; +} + /* * We carry the "access_data" structure around for any accesses, * which simplifies things a lot. It contains all the access |
