The list of predecessors is not set yet, this is just the
infrastructure.
Signed-off-by: Arthur HUILLET
---
include/jit/basic-block.h |2 ++
jit/basic-block.c | 32 +++-
jit/trace-jit.c | 23 +++
test/jit/basic-block-assert.h | 22 +-
4 files changed, 61 insertions(+), 18 deletions(-)
diff --git a/include/jit/basic-block.h b/include/jit/basic-block.h
index b555d9e..4919c95 100644
--- a/include/jit/basic-block.h
+++ b/include/jit/basic-block.h
@@ -24,6 +24,8 @@ struct basic_block {
unsigned long br_target_off;/* Branch target offset in bytecode
insns. */
unsigned long nr_successors;
struct basic_block **successors;
+ unsigned long nr_predecessors;
+ struct basic_block **predecessors;
unsigned long mach_offset;
/* The mimic stack is used to simulate JVM operand stack at
diff --git a/jit/basic-block.c b/jit/basic-block.c
index 22b102a..df984eb 100644
--- a/jit/basic-block.c
+++ b/jit/basic-block.c
@@ -76,6 +76,7 @@ void free_basic_block(struct basic_block *bb)
free_stmt_list(&bb->stmt_list);
free_insn_list(&bb->insn_list);
free(bb->successors);
+ free(bb->predecessors);
free(bb->use_set);
free(bb->def_set);
free(bb->live_in_set);
@@ -112,6 +113,9 @@ struct basic_block *bb_split(struct basic_block *orig_bb,
unsigned long offset)
new_bb->nr_successors = orig_bb->nr_successors;
orig_bb->nr_successors = 0;
+ new_bb->predecessors = NULL;
+ new_bb->nr_predecessors = 0;
+
if (orig_bb->has_branch) {
orig_bb->has_branch = false;
new_bb->has_branch = true;
@@ -142,25 +146,35 @@ void bb_add_insn(struct basic_block *bb, struct insn
*insn)
list_add_tail(&insn->insn_list_node, &bb->insn_list);
}
-int bb_add_successor(struct basic_block *bb, struct basic_block *successor)
+int __bb_add_neighbor(struct basic_block *new, struct basic_block ***array,
unsigned long *nb)
{
- int new_size;
- struct basic_block **new_successors;
+ unsigned long new_size;
+ struct basic_block **new_neighbors;
- new_size = sizeof(struct basic_block *) * (bb->nr_successors + 1);
+ new_size = sizeof(struct basic_block *) * (*nb + 1);
- new_successors = realloc(bb->successors, new_size);
- if (new_successors == NULL)
+ new_neighbors = realloc(*array, new_size);
+ if (new_neighbors == NULL)
return -ENOMEM;
- bb->successors = new_successors;
+ *array = new_neighbors;
- bb->successors[bb->nr_successors] = successor;
- bb->nr_successors++;
+ (*array)[*nb] = new;
+ (*nb)++;
return 0;
}
+int bb_add_successor(struct basic_block *bb, struct basic_block *successor)
+{
+ return __bb_add_neighbor(successor, &bb->successors,
&bb->nr_successors);
+}
+
+int bb_add_predecessor(struct basic_block *bb, struct basic_block *predecessor)
+{
+ return __bb_add_neighbor(predecessor, &bb->predecessors,
&bb->nr_predecessors);
+}
+
unsigned char *bb_native_ptr(struct basic_block *bb)
{
return buffer_ptr(bb->b_parent->objcode) + bb->mach_offset;
diff --git a/jit/trace-jit.c b/jit/trace-jit.c
index c11a896..feb23d8 100644
--- a/jit/trace-jit.c
+++ b/jit/trace-jit.c
@@ -54,7 +54,7 @@ void trace_cfg(struct compilation_unit *cu)
struct basic_block *bb;
printf("Control Flow Graph:\n\n");
- printf(" #:\t\tRange\t\tSuccessors\n");
+ printf(" #:\t\tRange\t\tSuccessors\t\tPredecessors\n");
for_each_basic_block(bb, &cu->bb_list) {
unsigned long i;
@@ -63,15 +63,30 @@ void trace_cfg(struct compilation_unit *cu)
if (bb->is_eh)
printf(" (eh)");
+ printf("\t");
+
for (i = 0; i < bb->nr_successors; i++) {
- if (i == 0)
- printf("\t");
- else
+ if (i != 0)
printf(", ");
printf("%p", bb->successors[i]);
}
+ if (i == 0)
+ printf("none");
+
+ printf("\t");
+
+ for (i = 0; i < bb->nr_predecessors; i++) {
+ if (i != 0)
+ printf(", ");
+
+ printf("%p", bb->predecessors[i]);
+ }
+
+ if (i == 0)
+ printf("none");
+
printf("\n");
}
diff --git a/test/jit/basic-block-assert.h b/test/jit/basic-block-assert.h
index 8f00672..abec84c 100644
--- a/test/jit/basic-block-assert.h
+++ b/test/jit/basic-block-assert.h
@@ -12,16 +12,28 @@ static void inline assert_basic_block(struct
compilation_unit *parent,
assert_int_equals(end, bb->e