public static void testForLoop() {
int i;
for (i = 0; i < 10; i++)
;
assertEquals(i, 10);
}
Signed-off-by: Tomek Grabiec <[email protected]>
---
include/jit/compilation-unit.h | 1 +
include/vm/list.h | 66 +++++++++++++++++++++++++++++
jit/compilation-unit.c | 10 ++++
jit/compiler.c | 8 ++-
regression/jamvm/ControlTransferTest.java | 3 +-
5 files changed, 83 insertions(+), 5 deletions(-)
diff --git a/include/jit/compilation-unit.h b/include/jit/compilation-unit.h
index 28a6614..e08edec 100644
--- a/include/jit/compilation-unit.h
+++ b/include/jit/compilation-unit.h
@@ -43,6 +43,7 @@ struct var_info *get_fixed_var(struct compilation_unit *,
enum machine_reg);
struct basic_block *find_bb(struct compilation_unit *, unsigned long);
unsigned long nr_bblocks(struct compilation_unit *);
void compute_insn_positions(struct compilation_unit *);
+void sort_basic_blocks(struct compilation_unit *);
#define for_each_variable(var, var_list) for (var = var_list; var != NULL; var
= var->next)
diff --git a/include/vm/list.h b/include/vm/list.h
index b94e737..5f70171 100644
--- a/include/vm/list.h
+++ b/include/vm/list.h
@@ -4,6 +4,8 @@
#include <vm/system.h>
#include <stdbool.h>
+#include <malloc.h>
+#include <stdlib.h>
/*
* This doubly-linked list is shamelessly stolen from Linux kernel.
@@ -190,4 +192,68 @@ static inline struct list_head *list_last(struct list_head
*head)
return head->prev;
}
+/**
+ * list_length - returns the length of list
+ */
+static inline int list_length(struct list_head *head)
+{
+ int len;
+ struct list_head *p;
+
+ for (len = 0, p = head->next; p != head; p = p->next)
+ len++;
+
+ return len;
+}
+
+/**
+ * __list_sort - sort the list using given comparator
+ * @head: is a head of the list to be sorted
+ * @member_offset: is machine offset inside the list entry structure to the
+ * field of type struct list_head which links that entry with
+ * the list.
+ */
+static inline void __list_sort(struct list_head *head,
+ int member_offset,
+ int (*comparator)(const void *, const void *))
+{
+ int len;
+ int i;
+ void ** arr;
+ struct list_head *node;
+
+ len = list_length(head);
+ arr = malloc(sizeof(void*) * len);
+
+ for (i = 0, node = head->next; i < len; i++, node = node->next)
+ arr[i] = (void*)node - member_offset;
+
+ qsort(arr,len,sizeof(void*),comparator);
+
+ INIT_LIST_HEAD(head);
+
+ for (i = 0; i < len; i++) {
+ node = (struct list_head*)(arr[i] + member_offset);
+ list_add_tail(node, head);
+ }
+
+ free(arr);
+}
+
+/**
+ * list_sort - wrapper for __list_sort
+ * @head: is a head of the list to be sorted
+ * @type: is the type of list entry
+ * @member: is the name of the field inside entry that links that entry with
+ * other entries in the list.
+ * @comaprator: function comparing two entries, should return value lesser
+ * than 0 when the first argument is lesser than the second one.
+ */
+#define list_sort(head,type,member,comparator) \
+ ({ \
+ __list_sort(head, \
+ offsetof(type, member), \
+ (int (*)(const void *, const void *)) comparator); \
+ })
+
#endif
diff --git a/jit/compilation-unit.c b/jit/compilation-unit.c
index 55a592d..33b57fa 100644
--- a/jit/compilation-unit.c
+++ b/jit/compilation-unit.c
@@ -165,3 +165,13 @@ void compute_insn_positions(struct compilation_unit *cu)
}
}
+static int bb_comparator(const struct basic_block **bb1,
+ const struct basic_block **bb2)
+{
+ return (*bb1)->start - (*bb2)->start;
+}
+
+void sort_basic_blocks(struct compilation_unit *cu)
+{
+ list_sort(&cu->bb_list,struct basic_block,bb_list_node,bb_comparator);
+}
diff --git a/jit/compiler.c b/jit/compiler.c
index 7aa8c5b..76956d5 100644
--- a/jit/compiler.c
+++ b/jit/compiler.c
@@ -35,13 +35,15 @@ int compile(struct compilation_unit *cu)
if (err)
goto out;
- if (opt_trace_cfg)
- trace_cfg(cu);
-
err = convert_to_ir(cu);
if (err)
goto out;
+ sort_basic_blocks(cu);
+
+ if (opt_trace_cfg)
+ trace_cfg(cu);
+
if (opt_trace_tree_ir)
trace_tree_ir(cu);
diff --git a/regression/jamvm/ControlTransferTest.java
b/regression/jamvm/ControlTransferTest.java
index 36ce94d..7d42e41 100644
--- a/regression/jamvm/ControlTransferTest.java
+++ b/regression/jamvm/ControlTransferTest.java
@@ -33,8 +33,7 @@ public class ControlTransferTest extends TestCase {
for (i = 0; i < 10; i++)
;
- // FIXME:
- // assertEquals(i, 10);
+ assertEquals(i, 10);
}
public static boolean ifeq(int x) {
--
1.6.0.6
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel