[pypy-commit] pypy libgccjit-backend: Get test_compile_loop to work
dmalcolm
noreply at buildbot.pypy.org
Wed Dec 17 17:48:36 CET 2014
Author: David Malcolm <dmalcolm at redhat.com>
Branch: libgccjit-backend
Changeset: r74982:e540b044a92d
Date: 2014-12-16 14:33 -0500
http://bitbucket.org/pypy/pypy/changeset/e540b044a92d/
Log: Get test_compile_loop to work
diff --git a/rpython/jit/backend/libgccjit/assembler.py b/rpython/jit/backend/libgccjit/assembler.py
--- a/rpython/jit/backend/libgccjit/assembler.py
+++ b/rpython/jit/backend/libgccjit/assembler.py
@@ -37,13 +37,15 @@
self.make_context()
self.t_long = self.ctxt.get_type(self.lib.GCC_JIT_TYPE_LONG)
+ self.t_bool = self.ctxt.get_type(self.lib.GCC_JIT_TYPE_BOOL)
self.t_void_ptr = self.ctxt.get_type(self.lib.GCC_JIT_TYPE_VOID_PTR)
def make_context(self):
eci = make_eci()
self.lib = Library(eci)
self.ctxt = Context.acquire(self.lib)#self.lib.gcc_jit_context_acquire()
- if 0:
+ self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE, r_int(1))
+ if 1:
self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE,
r_int(1))
self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DEBUGINFO,
@@ -55,7 +57,7 @@
r_int(1))
self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING,
r_int(1))
- if 0:
+ if 1:
self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE,
r_int(1))
@@ -171,7 +173,9 @@
params,
r_int(0))
- self.b_current = self.fn.new_block()
+ self.b_current = self.fn.new_block("initial")
+ self.label_for_descr = {}
+ self.block_for_label_descr = {}
# Add an initial comment summarizing the loop
text = '\n\tinputargs: %s\n\n' % inputargs
@@ -205,6 +209,8 @@
self.ctxt.dump_to_file("/tmp/foo.c", r_int(1))
+ #raise foo
+
jit_result = self.ctxt.compile()
self.ctxt.release()
@@ -213,7 +219,7 @@
looptoken._ll_function_addr = fn_ptr
looptoken.compiled_loop_token._ll_initial_locs = locs
-
+
# FIXME: this leaks the gcc_jit_result
def expr_to_rvalue(self, expr):
@@ -277,32 +283,95 @@
rval0, rval1))
self.b_current.add_assignment(lvalres, op_add)
- """
def emit_label(self, op):
print(op)
print(op.__dict__)
+ #print('op.getdescr(): %r' % op.getdescr())
+ #print('op.getdescr().__dict__: %r' % op.getdescr().__dict__)
+
+ b_new = self.fn.new_block(str(op))
+ self.block_for_label_descr[op.getdescr()] = b_new
+ self.label_for_descr[op.getdescr()] = op
+ self.b_current.end_with_jump(b_new)
+ self.b_current = b_new
+
+ def emit_jump(self, jumpop):
+ print(jumpop)
+ print(jumpop.__dict__)
+ label = self.label_for_descr[jumpop.getdescr()]
+ print(jumpop.getdescr())
+ print('label: %r' % label)
+
+ assert len(jumpop._args) == len(label._args)
+
+ # We need to write to the boxes listed in the label's args
+ # with the values from those listed in the jump's args.
+ # However, there are potential cases like JUMP(i0, i1) going to LABEL(i1, i0)
+ # where all such assignments happen "simultaneously".
+ # Hence we need to set up temporaries.
+ # First pass: capture the value of relevant boxes at the JUMP:
+ tmps = []
+ for i in range(len(jumpop._args)):
+ tmps.append(self.fn.new_local(self.t_long, "tmp%i" % i))
+ self.b_current.add_assignment(
+ tmps[i],
+ self.get_box_as_lvalue(jumpop._args[i]).as_rvalue())
+ # Second pass: write the values to the boxes at the LABEL:
+ for i in range(len(jumpop._args)):
+ self.b_current.add_assignment(
+ self.get_box_as_lvalue(label._args[i]),
+ tmps[i].as_rvalue())
+
+ self.b_current.end_with_jump(self.block_for_label_descr[jumpop.getdescr()])
+
+ def impl_int_cmp(self, op, gcc_jit_comparison):
+ rval0 = self.expr_to_rvalue(op._arg0)
+ rval1 = self.expr_to_rvalue(op._arg1)
+ lvalres = self.expr_to_lvalue(op.result)
+ op_cmp = (
+ self.ctxt.new_cast(
+ self.ctxt.new_comparison(gcc_jit_comparison,
+ rval0, rval1),
+ self.t_long)
+ )
+ self.b_current.add_assignment(lvalres,
+ op_cmp)
def emit_int_le(self, op):
- print(op)
- print(op.__dict__)
+ self.impl_int_cmp(op, self.lib.GCC_JIT_COMPARISON_LE)
def emit_int_ge(self, op):
- print(op)
- print(op.__dict__)
+ self.impl_int_cmp(op, self.lib.GCC_JIT_COMPARISON_GE)
def emit_guard_true(self, op):
print(op)
print(op.__dict__)
- """
+ b_true = self.fn.new_block("on_true_at_%s" % op)
+ b_false = self.fn.new_block("on_false_at_%s" % op)
+ boolval = self.ctxt.new_cast(self.expr_to_rvalue(op._arg0),
+ self.t_bool)
+ self.b_current.end_with_conditional(boolval,
+ b_true, b_false)
- def emit_finish(self, op):
+ self.b_current = b_false
+ self.impl_write_output_args(op._fail_args)
+ self.impl_write_jf_descr(op)
+ self.b_current.end_with_return(self.param_frame.as_rvalue ())
+ rd_locs = []
+ for idx, arg in enumerate(op._fail_args):
+ rd_locs.append(idx)
+ op.getdescr().rd_locs = rd_locs
+
+ self.b_current = b_true
+
+ def impl_write_output_args(self, args):
# Write outputs back:
- for idx, arg in enumerate(op._args):
- #self.b_current.add_comment(" op._args[%i]: %s" % (idx, arg))
+ for idx, arg in enumerate(args):
self.b_current.add_assignment(
self.get_arg_as_lvalue(idx),
self.get_box_as_lvalue(arg).as_rvalue())
+ def impl_write_jf_descr(self, op):
# Write back to the jf_descr:
# "jitframe->jf_descr = op.getdescr();"
descr = rffi.cast(lltype.Signed,
@@ -313,5 +382,8 @@
self.field_jf_descr),
self.ctxt.new_rvalue_from_ptr (self.t_void_ptr,
rffi.cast(VOIDP, descr)))
-
+
+ def emit_finish(self, op):
+ self.impl_write_output_args(op._args)
+ self.impl_write_jf_descr(op)
self.b_current.end_with_return(self.param_frame.as_rvalue ())
diff --git a/rpython/jit/backend/libgccjit/rffi_bindings.py b/rpython/jit/backend/libgccjit/rffi_bindings.py
--- a/rpython/jit/backend/libgccjit/rffi_bindings.py
+++ b/rpython/jit/backend/libgccjit/rffi_bindings.py
@@ -219,6 +219,19 @@
self.GCC_JIT_RVALUE_P,
self.GCC_JIT_RVALUE_P]),
+ (self.GCC_JIT_RVALUE_P,
+ 'gcc_jit_context_new_comparison', [self.GCC_JIT_CONTEXT_P,
+ self.GCC_JIT_LOCATION_P,
+ INT, # enum gcc_jit_binary_op op,
+ self.GCC_JIT_RVALUE_P,
+ self.GCC_JIT_RVALUE_P]),
+
+ (self.GCC_JIT_RVALUE_P,
+ 'gcc_jit_context_new_cast', [self.GCC_JIT_CONTEXT_P,
+ self.GCC_JIT_LOCATION_P,
+ self.GCC_JIT_RVALUE_P,
+ self.GCC_JIT_TYPE_P]),
+
(self.GCC_JIT_LVALUE_P,
'gcc_jit_rvalue_dereference_field', [self.GCC_JIT_RVALUE_P,
self.GCC_JIT_LOCATION_P,
@@ -237,6 +250,16 @@
self.GCC_JIT_LOCATION_P,
CCHARP]),
(lltype.Void,
+ 'gcc_jit_block_end_with_conditional', [self.GCC_JIT_BLOCK_P,
+ self.GCC_JIT_LOCATION_P,
+ self.GCC_JIT_RVALUE_P,
+ self.GCC_JIT_BLOCK_P,
+ self.GCC_JIT_BLOCK_P]),
+ (lltype.Void,
+ 'gcc_jit_block_end_with_jump', [self.GCC_JIT_BLOCK_P,
+ self.GCC_JIT_LOCATION_P,
+ self.GCC_JIT_BLOCK_P]),
+ (lltype.Void,
'gcc_jit_block_end_with_return', [self.GCC_JIT_BLOCK_P,
self.GCC_JIT_LOCATION_P,
self.GCC_JIT_RVALUE_P]),
@@ -303,6 +326,16 @@
GCC_JIT_BINARY_OP_RSHIFT
""")
+ self.make_enum_values(
+ """
+ GCC_JIT_COMPARISON_EQ,
+ GCC_JIT_COMPARISON_NE,
+ GCC_JIT_COMPARISON_LT,
+ GCC_JIT_COMPARISON_LE,
+ GCC_JIT_COMPARISON_GT,
+ GCC_JIT_COMPARISON_GE
+ """)
+
self.null_location_ptr = lltype.nullptr(self.GCC_JIT_LOCATION_P.TO)
@@ -418,6 +451,13 @@
type_.inner_type,
a.inner_rvalue, b.inner_rvalue))
+ def new_comparison(self, op, a, b):
+ return RValue(self.lib,
+ self.lib.gcc_jit_context_new_comparison(self.inner_ctxt,
+ self.lib.null_location_ptr,
+ op,
+ a.inner_rvalue, b.inner_rvalue))
+
def new_param(self, type_, name):
name_charp = str2charp(name)
param = self.lib.gcc_jit_context_new_param(self.inner_ctxt,
@@ -448,6 +488,12 @@
return Function(self.lib, fn)
+ def new_cast(self, rvalue, type_):
+ return RValue(self.lib,
+ self.lib.gcc_jit_context_new_cast(self.inner_ctxt,
+ self.lib.null_location_ptr,
+ rvalue.inner_rvalue,
+ type_.inner_type))
class Type(Wrapper):
def __init__(self, lib, inner_type):
@@ -557,6 +603,18 @@
text_charp)
free_charp(text_charp)
+ def end_with_conditional(self, boolval, on_true, on_false):
+ self.lib.gcc_jit_block_end_with_conditional(self.inner_block,
+ self.lib.null_location_ptr,
+ boolval.inner_rvalue,
+ on_true.inner_block,
+ on_false.inner_block)
+
+ def end_with_jump (self, target):
+ self.lib.gcc_jit_block_end_with_jump (self.inner_block,
+ self.lib.null_location_ptr,
+ target.inner_block)
+
def end_with_return(self, rvalue):
self.lib.gcc_jit_block_end_with_return(self.inner_block,
self.lib.null_location_ptr,
More information about the pypy-commit
mailing list