diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py index c07632cc43b0683b07f27f8da00d2b5c53257fd1..56a319ce18d48f21a0057fa740f7c989a630a30b 100644 --- a/rpython/flowspace/model.py +++ b/rpython/flowspace/model.py @@ -337,12 +337,7 @@ class Variable(object): class Constant(Hashable): - __slots__ = ["concretetype"] - - def __init__(self, value, concretetype=None): - Hashable.__init__(self, value) - if concretetype is not None: - self.concretetype = concretetype + __slots__ = [] def foldable(self): to_check = self.value diff --git a/rpython/jit/codewriter/flatten.py b/rpython/jit/codewriter/flatten.py index 82bb8fd2d365a443949e88310b906abc4a3c7a11..13a6523cc43c0b3a6bb9ba26715736408abc857b 100644 --- a/rpython/jit/codewriter/flatten.py +++ b/rpython/jit/codewriter/flatten.py @@ -1,4 +1,5 @@ from rpython.flowspace.model import Variable, Constant, c_last_exception +from rpython.rtyper.rmodel import ll_const from rpython.jit.metainterp.history import AbstractDescr, getkind from rpython.rtyper.lltypesystem import lltype @@ -166,7 +167,7 @@ class GraphFlattener(object): exc_data = self.cpu.rtyper.exceptiondata ll_ovf = exc_data.get_standard_ll_exc_instance_by_class( OverflowError) - c = Constant(ll_ovf, concretetype=lltype.typeOf(ll_ovf)) + c = ll_const(ll_ovf) self.emitline("raise", c) else: self.emitline("reraise") @@ -226,8 +227,7 @@ class GraphFlattener(object): self.make_exception_link(link, False) break self.emitline('goto_if_exception_mismatch', - Constant(link.llexitcase, - lltype.typeOf(link.llexitcase)), + ll_const(link.llexitcase), TLabel(link)) self.make_exception_link(link, False) self.emitline(Label(link)) diff --git a/rpython/jit/codewriter/format.py b/rpython/jit/codewriter/format.py index 3013976f30576d06c56c61e752712e2e832041ef..aa36ed214fe947adf48a0dc3bcfe895a6694ac9e 100644 --- a/rpython/jit/codewriter/format.py +++ b/rpython/jit/codewriter/format.py @@ -1,5 +1,5 @@ import py -from rpython.flowspace.model import Constant +from rpython.rtyper.rmodel import ll_const, LLConstant from rpython.rtyper.lltypesystem import lltype from rpython.jit.codewriter.flatten import SSARepr, Label, TLabel, Register from rpython.jit.codewriter.flatten import ListOfKind, IndirectCallTargets @@ -14,7 +14,7 @@ def format_assembler(ssarepr): def repr(x): if isinstance(x, Register): return '%%%s%d' % (x.kind[0], x.index) # e.g. %i1 or %r2 or %f3 - elif isinstance(x, Constant): + elif isinstance(x, LLConstant): if (isinstance(x.concretetype, lltype.Ptr) and isinstance(x.concretetype.TO, lltype.Struct)): return '$<* struct %s>' % (x.concretetype.TO._name,) @@ -117,7 +117,7 @@ def unformat_assembler(text, registers=None): return reg elif s[0] == '$': intvalue = int(s[1:]) - return Constant(intvalue, lltype.Signed) + return ll_const(intvalue) elif s[0] == 'L': return TLabel(s) elif s[0] in 'IRF' and s[1] == '[' and s[-1] == ']': diff --git a/rpython/jit/codewriter/jtransform.py b/rpython/jit/codewriter/jtransform.py index 60c3756ee4addf99816cd4b70baa6e02075b91f1..6fd711972c763d029ae1d227888b77a9b386262d 100644 --- a/rpython/jit/codewriter/jtransform.py +++ b/rpython/jit/codewriter/jtransform.py @@ -8,11 +8,11 @@ from rpython.jit.metainterp import quasiimmut from rpython.jit.metainterp.history import getkind from rpython.jit.metainterp.typesystem import deref, arrayItem from rpython.jit.metainterp.blackhole import BlackholeInterpreter -from rpython.flowspace.model import SpaceOperation, Variable, Constant,\ - c_last_exception +from rpython.flowspace.model import SpaceOperation, Variable, Constant from rpython.rlib import objectmodel from rpython.rlib.jit import _we_are_jitted from rpython.rlib.rgc import lltype_is_gc +from rpython.rtyper.rmodel import ll_const, LLConstant from rpython.rtyper.lltypesystem import lltype, llmemory, rstr, rffi from rpython.rtyper.lltypesystem import rbytearray from rpython.rtyper import rclass @@ -44,7 +44,7 @@ def constant_fold_ll_issubclass(graph, cpu): constant_result = excmatch(*[a.value for a in op.args[1:]]) block.operations[i] = SpaceOperation( 'same_as', - [Constant(constant_result, lltype.Bool)], + [LLConstant(constant_result, lltype.Bool)], op.result) if block.exitswitch is op.result: block.exitswitch = None @@ -81,13 +81,13 @@ class Transformer(object): # def do_rename(var, var_or_const): if var.concretetype is lltype.Void: - renamings[var] = Constant(None, lltype.Void) + renamings[var] = ll_const(None) return renamings[var] = var_or_const if isinstance(var_or_const, Constant): value = var_or_const.value value = lltype._cast_whatever(var.concretetype, value) - renamings_constants[var] = Constant(value, var.concretetype) + renamings_constants[var] = LLConstant(value, var.concretetype) # for op in block.operations: if renamings_constants: @@ -221,7 +221,7 @@ class Transformer(object): for link in block.exits: while v in link.args: index = link.args.index(v) - link.args[index] = Constant(link.llexitcase, + link.args[index] = LLConstant(link.llexitcase, lltype.Bool) return True return False @@ -257,7 +257,7 @@ class Transformer(object): vtable = heaptracker.get_vtable_for_gcstruct(self.cpu, TO) if vtable.subclassrange_max - vtable.subclassrange_min == 1: # it's a precise class check - const_vtable = Constant(vtable, lltype.typeOf(vtable)) + const_vtable = ll_const(vtable) return [None, # hack, do the right renaming from op.args[0] to op.result SpaceOperation("record_exact_class", [op.args[0], const_vtable], None)] @@ -274,7 +274,7 @@ class Transformer(object): # only for untranslated tests: get a real integer estimate arg = op.args[0].value arg = llmemory.raw_malloc_usage(arg) - return [Constant(arg, lltype.Signed)] + return [LLConstant(arg, lltype.Signed)] def rewrite_op_jit_record_exact_class(self, op): return SpaceOperation("record_exact_class", [op.args[0], op.args[1]], None) @@ -471,7 +471,7 @@ class Transformer(object): assert jitdriver_sd is not None ops = self.promote_greens(op.args[1:], jitdriver_sd.jitdriver) num_green_args = len(jitdriver_sd.jitdriver.greens) - args = ([Constant(jitdriver_sd.index, lltype.Signed)] + + args = ([LLConstant(jitdriver_sd.index, lltype.Signed)] + self.make_three_lists(op.args[1:1+num_green_args]) + self.make_three_lists(op.args[1+num_green_args:])) kind = getkind(op.result.concretetype)[0] @@ -582,7 +582,7 @@ class Transformer(object): EffectInfo.OS_STREQ_NONNULL) # XXX this is fairly ugly way of creating a constant, # however, callinfocollection has no better interface - c = Constant(p.adr.ptr, lltype.typeOf(p.adr.ptr)) + c = ll_const(p.adr.ptr) op1 = SpaceOperation('str_guard_value', [op.args[0], c, descr], op.result) return [SpaceOperation('-live-', [], None), op1, None] @@ -643,8 +643,8 @@ class Transformer(object): # substruct self.zero_contents(ops, v, FIELD) else: - c_name = Constant(name, lltype.Void) - c_null = Constant(FIELD._defl(), FIELD) + c_name = LLConstant(name, lltype.Void) + c_null = LLConstant(FIELD._defl(), FIELD) op = SpaceOperation('setfield', [v, c_name, c_null], None) self.extend_with(ops, self.rewrite_op_setfield(op, @@ -851,7 +851,7 @@ class Transformer(object): raise Exception("%r: only supported for gckind=raw" % (op,)) ofs = llmemory.offsetof(STRUCT, op.args[1].value) return SpaceOperation('int_add', - [op.args[0], Constant(ofs, lltype.Signed)], + [op.args[0], LLConstant(ofs, lltype.Signed)], op.result) def is_typeptr_getset(self, op): @@ -909,7 +909,7 @@ class Transformer(object): def handle_getfield_typeptr(self, op): if isinstance(op.args[0], Constant): cls = op.args[0].value.typeptr - return Constant(cls, concretetype=rclass.CLASSTYPE) + return LLConstant(cls, rclass.CLASSTYPE) op0 = SpaceOperation('-live-', [], None) op1 = SpaceOperation('guard_class', [op.args[0]], op.result) return [op0, op1] @@ -1232,7 +1232,7 @@ class Transformer(object): elif longlong_arg: if v_result.concretetype is lltype.Bool: longlong_zero = rffi.cast(v_arg.concretetype, 0) - c_longlong_zero = Constant(longlong_zero, v_arg.concretetype) + c_longlong_zero = ll_const(longlong_zero) if unsigned1: name = 'ullong_ne' else: @@ -1295,11 +1295,11 @@ class Transformer(object): if v_result.concretetype is lltype.Bool: result.append(SpaceOperation('int_is_true', [v_arg], v_result)) elif min2: - c_bytes = Constant(size2, lltype.Signed) + c_bytes = LLConstant(size2, lltype.Signed) result.append(SpaceOperation('int_signext', [v_arg, c_bytes], v_result)) else: - c_mask = Constant(int((1 << (8 * size2)) - 1), lltype.Signed) + c_mask = LLConstant(int((1 << (8 * size2)) - 1), lltype.Signed) result.append(SpaceOperation('int_and', [v_arg, c_mask], v_result)) return result @@ -1323,7 +1323,7 @@ class Transformer(object): if op.args[0].concretetype != rffi.CCHARP: v_prod = varoftype(lltype.Signed) by = llmemory.sizeof(op.args[0].concretetype.TO.OF) - c_by = Constant(by, lltype.Signed) + c_by = LLConstant(by, lltype.Signed) ops.append(SpaceOperation('int_mul', [v_shift, c_by], v_prod)) v_shift = v_prod # @@ -1407,9 +1407,7 @@ class Transformer(object): def rewrite_op_llong_neg(self, op): v = varoftype(lltype.SignedLongLong) - op0 = SpaceOperation('cast_int_to_longlong', - [Constant(0, lltype.Signed)], - v) + op0 = SpaceOperation('cast_int_to_longlong', [ll_const(0)], v) args = [v, op.args[0]] op1 = SpaceOperation('llong_sub', args, op.result) return (self._normalize(self.rewrite_operation(op0)) + @@ -1417,9 +1415,7 @@ class Transformer(object): def rewrite_op_llong_is_true(self, op): v = varoftype(op.args[0].concretetype) - op0 = SpaceOperation('cast_primitive', - [Constant(0, lltype.Signed)], - v) + op0 = SpaceOperation('cast_primitive', [ll_const(0)], v) args = [op.args[0], v] op1 = SpaceOperation('llong_ne', args, op.result) return (self._normalize(self.rewrite_operation(op0)) + @@ -1471,14 +1467,12 @@ class Transformer(object): def rewrite_op_int_neg_ovf(self, op): op1 = SpaceOperation('int_sub_ovf', - [Constant(0, lltype.Signed), op.args[0]], - op.result) + [ll_const(0), op.args[0]], op.result) return self.rewrite_operation(op1) def rewrite_op_float_is_true(self, op): op1 = SpaceOperation('float_ne', - [op.args[0], Constant(0.0, lltype.Float)], - op.result) + [op.args[0], ll_const(0.0)], op.result) return self.rewrite_operation(op1) def rewrite_op_int_is_true(self, op): @@ -1491,7 +1485,7 @@ class Transformer(object): else: raise AssertionError("don't know the truth value of %r" % (value,)) - return Constant(value, lltype.Bool) + return LLConstant(value, lltype.Bool) return op def promote_greens(self, args, jitdriver): @@ -1545,7 +1539,7 @@ class Transformer(object): "Constant specified red in jit_merge_point()") assert len(dict.fromkeys(redlist)) == len(list(redlist)), ( "duplicate red variable on jit_merge_point()") - args = ([Constant(self.portal_jd.index, lltype.Signed)] + + args = ([LLConstant(self.portal_jd.index, lltype.Signed)] + self.make_three_lists(op.args[2:2+num_green_args]) + redlists) op1 = SpaceOperation('jit_merge_point', args, None) @@ -1558,7 +1552,7 @@ class Transformer(object): def handle_jit_marker__loop_header(self, op, jitdriver): jd = self.callcontrol.jitdriver_sd_from_jitdriver(jitdriver) assert jd is not None - c_index = Constant(jd.index, lltype.Signed) + c_index = LLConstant(jd.index, lltype.Signed) return SpaceOperation('loop_header', [c_index], None) # a 'can_enter_jit' in the source graph becomes a 'loop_header' @@ -1683,7 +1677,7 @@ class Transformer(object): assert v_length.concretetype is lltype.Signed return v_length else: - return Constant(0, lltype.Signed) # length: default to 0 + return ll_const(0) # length: default to 0 # ---------- fixed lists ---------- diff --git a/rpython/jit/codewriter/support.py b/rpython/jit/codewriter/support.py index 177a507e69be5f4788f4083936ee13b2dfc6ac1d..946d06d582fb81a66827793e9296a8930aa4f074 100644 --- a/rpython/jit/codewriter/support.py +++ b/rpython/jit/codewriter/support.py @@ -3,12 +3,13 @@ import sys from rpython.annotator import model as annmodel from rpython.rtyper.llannotation import lltype_to_annotation from rpython.annotator.policy import AnnotatorPolicy -from rpython.flowspace.model import Variable, Constant +from rpython.flowspace.model import Variable from rpython.jit.metainterp.typesystem import deref from rpython.rlib import rgc from rpython.rlib.jit import elidable, oopspec from rpython.rlib.rarithmetic import r_longlong, r_ulonglong, r_uint, intmask from rpython.rlib.rarithmetic import LONG_BIT +from rpython.rtyper.rmodel import ll_const, LLConstant from rpython.rtyper import rlist from rpython.rtyper.lltypesystem import rlist as rlist_ll from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator @@ -758,7 +759,7 @@ def normalize_opargs(argtuple, opargs): if isinstance(obj, Index): result.append(opargs[obj.n]) else: - result.append(Constant(obj, lltype.typeOf(obj))) + result.append(ll_const(obj)) return result def get_call_oopspec_opargs(fnobj, opargs): @@ -837,8 +838,8 @@ def builtin_func_for_spec(rtyper, oopspec_name, ll_args, ll_res, mixlevelann.finish() else: # for testing only - c_func = Constant(oopspec_name, - lltype.Ptr(lltype.FuncType(ll_args, ll_res))) + c_func = LLConstant(oopspec_name, + lltype.Ptr(lltype.FuncType(ll_args, ll_res))) # if not hasattr(rtyper, '_builtin_func_for_spec_cache'): rtyper._builtin_func_for_spec_cache = {} diff --git a/rpython/jit/codewriter/test/test_assembler.py b/rpython/jit/codewriter/test/test_assembler.py index 3bb5db952817ee98074fb7a08c0bb65988b31fce..9bbfc7bb0bf9baf5bd31d0ad1c545469972bcca0 100644 --- a/rpython/jit/codewriter/test/test_assembler.py +++ b/rpython/jit/codewriter/test/test_assembler.py @@ -5,7 +5,7 @@ from rpython.jit.codewriter.flatten import ListOfKind, IndirectCallTargets from rpython.jit.codewriter.jitcode import MissingLiveness from rpython.jit.codewriter import heaptracker, longlong from rpython.jit.metainterp.history import AbstractDescr -from rpython.flowspace.model import Constant +from rpython.rtyper.rmodel import LLConstant from rpython.rtyper.lltypesystem import lltype, llmemory @@ -30,10 +30,10 @@ def test_assemble_consts(): ssarepr = SSARepr("test") ssarepr.insns = [ ('int_return', Register('int', 13)), - ('int_return', Constant(18, lltype.Signed)), - ('int_return', Constant(-4, lltype.Signed)), - ('int_return', Constant(128, lltype.Signed)), - ('int_return', Constant(-129, lltype.Signed)), + ('int_return', LLConstant(18, lltype.Signed)), + ('int_return', LLConstant(-4, lltype.Signed)), + ('int_return', LLConstant(128, lltype.Signed)), + ('int_return', LLConstant(-129, lltype.Signed)), ] assembler = Assembler() jitcode = assembler.assemble(ssarepr) @@ -50,9 +50,9 @@ def test_assemble_float_consts(): ssarepr = SSARepr("test") ssarepr.insns = [ ('float_return', Register('float', 13)), - ('float_return', Constant(18.0, lltype.Float)), - ('float_return', Constant(-4.0, lltype.Float)), - ('float_return', Constant(128.1, lltype.Float)), + ('float_return', LLConstant(18.0, lltype.Float)), + ('float_return', LLConstant(-4.0, lltype.Float)), + ('float_return', LLConstant(128.1, lltype.Float)), ] assembler = Assembler() jitcode = assembler.assemble(ssarepr) @@ -71,9 +71,9 @@ def test_assemble_llong_consts(): from rpython.rlib.rarithmetic import r_longlong, r_ulonglong ssarepr = SSARepr("test") ssarepr.insns = [ - ('float_return', Constant(r_longlong(-18000000000000000), + ('float_return', LLConstant(r_longlong(-18000000000000000), lltype.SignedLongLong)), - ('float_return', Constant(r_ulonglong(9900000000000000000), + ('float_return', LLConstant(r_ulonglong(9900000000000000000), lltype.UnsignedLongLong)), ] assembler = Assembler() @@ -91,10 +91,10 @@ def test_assemble_cast_consts(): F = lltype.FuncType([], lltype.Signed) f = lltype.functionptr(F, 'f') ssarepr.insns = [ - ('int_return', Constant('X', lltype.Char)), - ('int_return', Constant(unichr(0x1234), lltype.UniChar)), - ('int_return', Constant(f, lltype.Ptr(F))), - ('ref_return', Constant(s, lltype.Ptr(S))), + ('int_return', LLConstant('X', lltype.Char)), + ('int_return', LLConstant(unichr(0x1234), lltype.UniChar)), + ('int_return', LLConstant(f, lltype.Ptr(F))), + ('ref_return', LLConstant(s, lltype.Ptr(S))), ] assembler = Assembler() jitcode = assembler.assemble(ssarepr) @@ -115,9 +115,9 @@ def test_assemble_loop(): i0, i1 = Register('int', 0x16), Register('int', 0x17) ssarepr.insns = [ (Label('L1'),), - ('goto_if_not_int_gt', i0, Constant(4, lltype.Signed), TLabel('L2')), + ('goto_if_not_int_gt', i0, LLConstant(4, lltype.Signed), TLabel('L2')), ('int_add', i1, i0, '->', i1), - ('int_sub', i0, Constant(1, lltype.Signed), '->', i0), + ('int_sub', i0, LLConstant(1, lltype.Signed), '->', i0), ('goto', TLabel('L1')), (Label('L2'),), ('int_return', i1), @@ -139,7 +139,7 @@ def test_assemble_list(): ssarepr = SSARepr("test") i0, i1 = Register('int', 0x16), Register('int', 0x17) ssarepr.insns = [ - ('foobar', ListOfKind('int', [i0, i1, Constant(42, lltype.Signed)]), + ('foobar', ListOfKind('int', [i0, i1, LLConstant(42, lltype.Signed)]), ListOfKind('ref', [])), ] assembler = Assembler() @@ -154,10 +154,10 @@ def test_assemble_list_semibug(): # encoded directly. ssarepr = SSARepr("test") ssarepr.insns = [ - ('foobar', ListOfKind('int', [Constant(42, lltype.Signed)])), - ('foobar', ListOfKind('int', [Constant(42, lltype.Signed)])), - ('baz', Constant(42, lltype.Signed)), - ('bok', Constant(41, lltype.Signed)), + ('foobar', ListOfKind('int', [LLConstant(42, lltype.Signed)])), + ('foobar', ListOfKind('int', [LLConstant(42, lltype.Signed)])), + ('baz', LLConstant(42, lltype.Signed)), + ('bok', LLConstant(41, lltype.Signed)), ] assembler = Assembler() jitcode = assembler.assemble(ssarepr) @@ -214,10 +214,10 @@ def test_liveness(): ssarepr = SSARepr("test") i0, i1, i2 = Register('int', 0), Register('int', 1), Register('int', 2) ssarepr.insns = [ - ('int_add', i0, Constant(10, lltype.Signed), '->', i1), + ('int_add', i0, LLConstant(10, lltype.Signed), '->', i1), ('-live-', i0, i1), ('-live-', i1, i2), - ('int_add', i0, Constant(3, lltype.Signed), '->', i2), + ('int_add', i0, LLConstant(3, lltype.Signed), '->', i2), ('-live-', i2), ] assembler = Assembler() @@ -233,7 +233,7 @@ def test_liveness(): def test_assemble_error_string_constant(): ssarepr = SSARepr("test") - c = Constant('foobar', lltype.Void) + c = LLConstant('foobar', lltype.Void) ssarepr.insns = [ ('duh', c), ] diff --git a/rpython/jit/codewriter/test/test_call.py b/rpython/jit/codewriter/test/test_call.py index d5c4fe03cc8f3b7664dff9e38dec434b0fd5af9c..92c31fa48c610fe63ddd6a530a8cf61cc401f75d 100644 --- a/rpython/jit/codewriter/test/test_call.py +++ b/rpython/jit/codewriter/test/test_call.py @@ -1,6 +1,7 @@ import py from rpython.flowspace.model import SpaceOperation, Constant, Variable +from rpython.rtyper.rmodel import ll_const, LLConstant from rpython.rtyper.lltypesystem import lltype, llmemory, rffi from rpython.translator.unsimplify import varoftype from rpython.rlib import jit @@ -19,7 +20,7 @@ def test_graphs_from_direct_call(): F = lltype.FuncType([], lltype.Signed) f = lltype.functionptr(F, 'f', graph='fgraph') v = varoftype(lltype.Signed) - op = SpaceOperation('direct_call', [Constant(f, lltype.Ptr(F))], v) + op = SpaceOperation('direct_call', [ll_const(f)], v) # lst = cc.graphs_from(op, {}.__contains__) assert lst is None # residual call @@ -33,7 +34,7 @@ def test_graphs_from_indirect_call(): v = varoftype(lltype.Signed) graphlst = ['f1graph', 'f2graph'] op = SpaceOperation('indirect_call', [varoftype(lltype.Ptr(F)), - Constant(graphlst, lltype.Void)], v) + LLConstant(graphlst, lltype.Void)], v) # lst = cc.graphs_from(op, {'f1graph': True, 'f2graph': True}.__contains__) assert lst == ['f1graph', 'f2graph'] # normal indirect call @@ -48,8 +49,8 @@ def test_graphs_from_no_target(): cc = CallControl() F = lltype.FuncType([], lltype.Signed) v = varoftype(lltype.Signed) - op = SpaceOperation('indirect_call', [varoftype(lltype.Ptr(F)), - Constant(None, lltype.Void)], v) + op = SpaceOperation('indirect_call', + [varoftype(lltype.Ptr(F)), ll_const(None)], v) lst = cc.graphs_from(op, {}.__contains__) assert lst is None diff --git a/rpython/jit/codewriter/test/test_flatten.py b/rpython/jit/codewriter/test/test_flatten.py index 96eea00dccb8bf9465e9c93f760cd11c32bf1c61..f0745590dd4aa78d917d43996115fadaaaf43c34 100644 --- a/rpython/jit/codewriter/test/test_flatten.py +++ b/rpython/jit/codewriter/test/test_flatten.py @@ -1,4 +1,4 @@ -import py, sys +import py from rpython.jit.codewriter import support from rpython.jit.codewriter.heaptracker import int_signext from rpython.jit.codewriter.flatten import flatten_graph, reorder_renaming_list @@ -9,7 +9,8 @@ from rpython.jit.codewriter.effectinfo import EffectInfo from rpython.jit.metainterp.history import AbstractDescr from rpython.rtyper.lltypesystem import lltype, rstr, rffi from rpython.rtyper import rclass -from rpython.flowspace.model import SpaceOperation, Variable, Constant +from rpython.flowspace.model import SpaceOperation +from rpython.rtyper.rmodel import LLConstant, ll_const from rpython.translator.unsimplify import varoftype from rpython.rlib.rarithmetic import ovfcheck, r_uint, r_longlong, r_ulonglong from rpython.rlib.jit import dont_look_inside, _we_are_jitted, JitDriver @@ -44,7 +45,7 @@ class FakeDict(object): def __getitem__(self, key): F = lltype.FuncType([lltype.Signed, lltype.Signed], lltype.Signed) f = lltype.functionptr(F, key[0]) - c_func = Constant(f, lltype.typeOf(f)) + c_func = ll_const(f) return c_func, lltype.Signed class FakeCPU: @@ -140,7 +141,7 @@ class TestFlatten: def encoding_test(self, func, args, expected, transform=False, liveness=False, cc=None, jd=None): - + graphs = self.make_graphs(func, args) #graphs[0].show() if transform: @@ -252,7 +253,7 @@ class TestFlatten: v4 = varoftype(lltype.Ptr(rstr.STR)) v5 = varoftype(lltype.Float) op = SpaceOperation('residual_call_ir_f', - [Constant(12345, lltype.Signed), # function ptr + [LLConstant(12345, lltype.Signed), # function ptr ListOfKind('int', [v1, v2]), # int args ListOfKind('ref', [v3, v4])], # ref args v5) # result diff --git a/rpython/jit/codewriter/test/test_format.py b/rpython/jit/codewriter/test/test_format.py index e03c4770073287d817e35296d0b142aa8854d289..df473db04ba659a6054c40fd0bb7322c8bc8f954 100644 --- a/rpython/jit/codewriter/test/test_format.py +++ b/rpython/jit/codewriter/test/test_format.py @@ -1,5 +1,5 @@ import py -from rpython.flowspace.model import Constant +from rpython.rtyper.rmodel import ll_const from rpython.jit.codewriter.format import format_assembler, unformat_assembler from rpython.jit.codewriter.flatten import Label, TLabel, SSARepr, Register from rpython.jit.codewriter.flatten import ListOfKind @@ -39,9 +39,7 @@ def test_format_assembler_const_struct(): s = lltype.malloc(S) s.x = 123 ssarepr = SSARepr("test") - ssarepr.insns = [ - ('foobar', '->', Constant(s, lltype.typeOf(s))), - ] + ssarepr.insns = [('foobar', '->', ll_const(s))] asm = format_assembler(ssarepr) expected = """ foobar -> $<* struct S> @@ -53,9 +51,9 @@ def test_format_assembler_loop(): i0, i1 = Register('int', 0), Register('int', 1) ssarepr.insns = [ (Label('L1'),), - ('goto_if_not_int_gt', i0, Constant(0, lltype.Signed), TLabel('L2')), + ('goto_if_not_int_gt', i0, ll_const(0), TLabel('L2')), ('int_add', i1, i0, '->', i1), - ('int_sub', i0, Constant(1, lltype.Signed), '->', i0), + ('int_sub', i0, ll_const(1), '->', i0), ('goto', TLabel('L1')), (Label('L2'),), ('int_return', i1), @@ -75,9 +73,7 @@ def test_format_assembler_loop(): def test_format_assembler_list(): ssarepr = SSARepr("test") i0, i1 = Register('int', 0), Register('int', 1) - ssarepr.insns = [ - ('foobar', ListOfKind('int', [i0, Constant(123, lltype.Signed), i1])), - ] + ssarepr.insns = [('foobar', ListOfKind('int', [i0, ll_const(123), i1]))] asm = format_assembler(ssarepr) expected = """ foobar I[%i0, $123, %i1] @@ -117,9 +113,7 @@ def test_unformat_assembler_consts(): foo $123 """ ssarepr = unformat_assembler(input) - assert ssarepr.insns == [ - ('foo', Constant(123, lltype.Signed)), - ] + assert ssarepr.insns == [('foo', ll_const(123))] def test_unformat_assembler_single_return(): input = """ diff --git a/rpython/jit/codewriter/test/test_jtransform.py b/rpython/jit/codewriter/test/test_jtransform.py index 975bb605b3fbd7fcb5b4d4d5977765abf6b772ef..1e3d1b1334704e6de6dc99dd91a044aa0dc090d5 100644 --- a/rpython/jit/codewriter/test/test_jtransform.py +++ b/rpython/jit/codewriter/test/test_jtransform.py @@ -1,22 +1,10 @@ - import py import random -try: - from itertools import product -except ImportError: - # Python 2.5, this is taken from the CPython docs, but simplified. - def product(*args): - # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy - # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111 - pools = map(tuple, args) - result = [[]] - for pool in pools: - result = [x+[y] for x in result for y in pool] - for prod in result: - yield tuple(prod) - -from rpython.flowspace.model import FunctionGraph, Block, Link, c_last_exception -from rpython.flowspace.model import SpaceOperation, Variable, Constant +from itertools import product + +from rpython.flowspace.model import ( + Block, Link, SpaceOperation, Variable, Constant) +from rpython.rtyper.rmodel import ll_const, LLConstant from rpython.rtyper.lltypesystem import lltype, llmemory, rstr, rffi from rpython.rtyper import rclass from rpython.rtyper.lltypesystem.module import ll_math @@ -26,9 +14,6 @@ from rpython.jit.codewriter.flatten import ListOfKind from rpython.jit.codewriter.jtransform import Transformer, UnsupportedMallocFlags from rpython.jit.metainterp.history import getkind -def const(x): - return Constant(x, lltype.typeOf(x)) - class FakeRTyper: instance_reprs = {} @@ -212,7 +197,7 @@ def test_optimize_goto_if_not__exit(): assert block.operations == [] assert block.exitswitch == ('int_gt', v1, v2, '-live-before') assert block.exits == exits - assert exits[1].args == [const(True)] + assert exits[1].args == [ll_const(True)] def test_optimize_goto_if_not__unknownop(): v3 = Variable(); v3.concretetype = lltype.Bool @@ -264,8 +249,8 @@ def test_symmetric(): 'float_gt': ('float_gt', 'float_lt'), } v3 = varoftype(lltype.Signed) - for v1 in [varoftype(lltype.Signed), const(42)]: - for v2 in [varoftype(lltype.Signed), const(43)]: + for v1 in [varoftype(lltype.Signed), ll_const(42)]: + for v2 in [varoftype(lltype.Signed), ll_const(43)]: for name1, name2 in ops.items(): op = SpaceOperation(name1, [v1, v2], v3) op1 = Transformer(FakeCPU()).rewrite_operation(op) @@ -282,8 +267,8 @@ def test_symmetric(): def test_symmetric_int_add_ovf(): v3 = varoftype(lltype.Signed) - for v1 in [varoftype(lltype.Signed), const(42)]: - for v2 in [varoftype(lltype.Signed), const(43)]: + for v1 in [varoftype(lltype.Signed), ll_const(42)]: + for v2 in [varoftype(lltype.Signed), ll_const(43)]: op = SpaceOperation('int_add_nonneg_ovf', [v1, v2], v3) oplist = Transformer(FakeCPU()).rewrite_operation(op) op1, op0 = oplist @@ -332,7 +317,7 @@ def test_calls(): def get_direct_call_op(argtypes, restype): FUNC = lltype.FuncType(argtypes, restype) fnptr = lltype.functionptr(FUNC, "g") # no graph - c_fnptr = const(fnptr) + c_fnptr = ll_const(fnptr) vars = [varoftype(TYPE) for TYPE in argtypes] v_result = varoftype(restype) op = SpaceOperation('direct_call', [c_fnptr] + vars, v_result) @@ -386,7 +371,7 @@ def indirect_residual_call_test(argtypes, restype, expectedkind): op = get_direct_call_op(argtypes, restype) op.opname = 'indirect_call' op.args[0] = varoftype(op.args[0].concretetype) - op.args.append(Constant(['somegraph1', 'somegraph2'], lltype.Void)) + op.args.append(LLConstant(['somegraph1', 'somegraph2'], lltype.Void)) tr = Transformer(FakeCPU(), FakeResidualIndirectCallControl()) tr.graph = 'someinitialgraph' oplist = tr.rewrite_operation(op) @@ -414,7 +399,7 @@ def indirect_regular_call_test(argtypes, restype, expectedkind): op = get_direct_call_op(argtypes, restype) op.opname = 'indirect_call' op.args[0] = varoftype(op.args[0].concretetype) - op.args.append(Constant(['somegraph1', 'somegraph2'], lltype.Void)) + op.args.append(LLConstant(['somegraph1', 'somegraph2'], lltype.Void)) tr = Transformer(FakeCPU(), FakeRegularIndirectCallControl()) tr.graph = 'someinitialgraph' oplist = tr.rewrite_operation(op) @@ -467,7 +452,7 @@ def test_getfield(): ('chr', 'i'), ('unc', 'i')]: v_parent = varoftype(lltype.Ptr(S)) - c_name = Constant(name, lltype.Void) + c_name = LLConstant(name, lltype.Void) v_result = varoftype(getattr(S, name)) op = SpaceOperation('getfield', [v_parent, c_name], v_result) op1 = Transformer(FakeCPU()).rewrite_operation(op) @@ -478,7 +463,7 @@ def test_getfield(): def test_getfield_typeptr(): v_parent = varoftype(rclass.OBJECTPTR) - c_name = Constant('typeptr', lltype.Void) + c_name = LLConstant('typeptr', lltype.Void) v_result = varoftype(rclass.OBJECT.typeptr) op = SpaceOperation('getfield', [v_parent, c_name], v_result) oplist = Transformer(FakeCPU()).rewrite_operation(op) @@ -508,7 +493,7 @@ def test_setfield(): ('chr', 'i'), ('unc', 'i')]: v_parent = varoftype(lltype.Ptr(S)) - c_name = Constant(name, lltype.Void) + c_name = LLConstant(name, lltype.Void) v_newvalue = varoftype(getattr(S, name)) op = SpaceOperation('setfield', [v_parent, c_name, v_newvalue], varoftype(lltype.Void)) @@ -521,8 +506,8 @@ def test_setfield(): def test_malloc_new(): S = lltype.GcStruct('S') v = varoftype(lltype.Ptr(S)) - op = SpaceOperation('malloc', [Constant(S, lltype.Void), - Constant({'flavor': 'gc'}, lltype.Void)], v) + op = SpaceOperation('malloc', [LLConstant(S, lltype.Void), + LLConstant({'flavor': 'gc'}, lltype.Void)], v) op1 = Transformer(FakeCPU()).rewrite_operation(op) assert op1.opname == 'new' assert op1.args == [('sizedescr', S)] @@ -530,8 +515,8 @@ def test_malloc_new(): def test_malloc_new_zero_2(): S = lltype.GcStruct('S', ('x', lltype.Signed)) v = varoftype(lltype.Ptr(S)) - op = SpaceOperation('malloc', [Constant(S, lltype.Void), - Constant({'flavor': 'gc', + op = SpaceOperation('malloc', [LLConstant(S, lltype.Void), + LLConstant({'flavor': 'gc', 'zero': True}, lltype.Void)], v) op1, op2 = Transformer(FakeCPU()).rewrite_operation(op) assert op1.opname == 'new' @@ -545,8 +530,8 @@ def test_malloc_new_zero_nested(): S2 = lltype.GcStruct('S2', ('parent', S), ('xx', lltype.Ptr(S0))) v = varoftype(lltype.Ptr(S2)) - op = SpaceOperation('malloc', [Constant(S2, lltype.Void), - Constant({'flavor': 'gc', + op = SpaceOperation('malloc', [LLConstant(S2, lltype.Void), + LLConstant({'flavor': 'gc', 'zero': True}, lltype.Void)], v) op1, op2, op3 = Transformer(FakeCPU()).rewrite_operation(op) assert op1.opname == 'new' @@ -561,8 +546,8 @@ def test_malloc_new_with_vtable(): S = lltype.GcStruct('S', ('parent', rclass.OBJECT)) heaptracker.set_testing_vtable_for_gcstruct(S, vtable, 'S') v = varoftype(lltype.Ptr(S)) - op = SpaceOperation('malloc', [Constant(S, lltype.Void), - Constant({'flavor': 'gc'}, lltype.Void)], v) + op = SpaceOperation('malloc', [LLConstant(S, lltype.Void), + LLConstant({'flavor': 'gc'}, lltype.Void)], v) cpu = FakeCPU() op1 = Transformer(cpu).rewrite_operation(op) assert op1.opname == 'new_with_vtable' @@ -576,8 +561,8 @@ def test_malloc_new_with_destructor(): lltype.attachRuntimeTypeInfo(S, destrptr=destructor) heaptracker.set_testing_vtable_for_gcstruct(S, vtable, 'S') v = varoftype(lltype.Ptr(S)) - op = SpaceOperation('malloc', [Constant(S, lltype.Void), - Constant({'flavor': 'gc'}, lltype.Void)], v) + op = SpaceOperation('malloc', [LLConstant(S, lltype.Void), + LLConstant({'flavor': 'gc'}, lltype.Void)], v) tr = Transformer(FakeCPU(), FakeResidualCallControl()) oplist = tr.rewrite_operation(op) op0, op1 = oplist @@ -591,8 +576,8 @@ def test_raw_malloc(): S = rffi.CArray(lltype.Char) v1 = varoftype(lltype.Signed) v = varoftype(lltype.Ptr(S)) - flags = Constant({'flavor': 'raw'}, lltype.Void) - op = SpaceOperation('malloc_varsize', [Constant(S, lltype.Void), flags, + flags = LLConstant({'flavor': 'raw'}, lltype.Void) + op = SpaceOperation('malloc_varsize', [LLConstant(S, lltype.Void), flags, v1], v) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) op0, op1 = tr.rewrite_operation(op) @@ -608,8 +593,8 @@ def test_raw_malloc_zero(): S = rffi.CArray(lltype.Signed) v1 = varoftype(lltype.Signed) v = varoftype(lltype.Ptr(S)) - flags = Constant({'flavor': 'raw', 'zero': True}, lltype.Void) - op = SpaceOperation('malloc_varsize', [Constant(S, lltype.Void), flags, + flags = LLConstant({'flavor': 'raw', 'zero': True}, lltype.Void) + op = SpaceOperation('malloc_varsize', [LLConstant(S, lltype.Void), flags, v1], v) tr = Transformer(FakeCPU(), FakeResidualCallControl()) op0, op1 = tr.rewrite_operation(op) @@ -622,8 +607,8 @@ def test_raw_malloc_unsupported_flag(): S = rffi.CArray(lltype.Signed) v1 = varoftype(lltype.Signed) v = varoftype(lltype.Ptr(S)) - flags = Constant({'flavor': 'raw', 'unsupported_flag': True}, lltype.Void) - op = SpaceOperation('malloc_varsize', [Constant(S, lltype.Void), flags, + flags = LLConstant({'flavor': 'raw', 'unsupported_flag': True}, lltype.Void) + op = SpaceOperation('malloc_varsize', [LLConstant(S, lltype.Void), flags, v1], v) tr = Transformer(FakeCPU(), FakeResidualCallControl()) py.test.raises(UnsupportedMallocFlags, tr.rewrite_operation, op) @@ -631,8 +616,8 @@ def test_raw_malloc_unsupported_flag(): def test_raw_malloc_fixedsize(): S = lltype.Struct('dummy', ('x', lltype.Signed)) v = varoftype(lltype.Ptr(S)) - flags = Constant({'flavor': 'raw', 'zero': True}, lltype.Void) - op = SpaceOperation('malloc', [Constant(S, lltype.Void), flags], v) + flags = LLConstant({'flavor': 'raw', 'zero': True}, lltype.Void) + op = SpaceOperation('malloc', [LLConstant(S, lltype.Void), flags], v) tr = Transformer(FakeCPU(), FakeResidualCallControl()) op0, op1 = tr.rewrite_operation(op) assert op0.opname == 'residual_call_r_i' @@ -642,7 +627,7 @@ def test_raw_malloc_fixedsize(): def test_raw_free(): S = rffi.CArray(lltype.Char) - flags = Constant({'flavor': 'raw', 'track_allocation': True}, + flags = LLConstant({'flavor': 'raw', 'track_allocation': True}, lltype.Void) op = SpaceOperation('free', [varoftype(lltype.Ptr(S)), flags], varoftype(lltype.Void)) @@ -654,7 +639,7 @@ def test_raw_free(): def test_raw_free_no_track_allocation(): S = rffi.CArray(lltype.Signed) - flags = Constant({'flavor': 'raw', 'track_allocation': False}, + flags = LLConstant({'flavor': 'raw', 'track_allocation': False}, lltype.Void) op = SpaceOperation('free', [varoftype(lltype.Ptr(S)), flags], varoftype(lltype.Void)) @@ -689,7 +674,7 @@ def test_int_eq(): v1 = varoftype(lltype.Signed) v2 = varoftype(lltype.Signed) v3 = varoftype(lltype.Bool) - c0 = const(0) + c0 = ll_const(0) # for opname, reducedname in [('int_eq', 'int_is_zero'), ('int_ne', 'int_is_true')]: @@ -712,7 +697,7 @@ def test_ptr_eq(): v1 = varoftype(lltype.Ptr(rstr.STR)) v2 = varoftype(lltype.Ptr(rstr.STR)) v3 = varoftype(lltype.Bool) - c0 = const(lltype.nullptr(rstr.STR)) + c0 = ll_const(lltype.nullptr(rstr.STR)) # for opname, reducedname in [('ptr_eq', 'ptr_iszero'), ('ptr_ne', 'ptr_nonzero')]: @@ -735,7 +720,7 @@ def test_instance_ptr_eq(): v1 = varoftype(rclass.OBJECTPTR) v2 = varoftype(rclass.OBJECTPTR) v3 = varoftype(lltype.Bool) - c0 = const(lltype.nullptr(rclass.OBJECT)) + c0 = ll_const(lltype.nullptr(rclass.OBJECT)) for opname, newopname, reducedname in [ ('ptr_eq', 'instance_ptr_eq', 'ptr_iszero'), @@ -760,7 +745,7 @@ def test_nongc_ptr_eq(): v1 = varoftype(rclass.NONGCOBJECTPTR) v2 = varoftype(rclass.NONGCOBJECTPTR) v3 = varoftype(lltype.Bool) - c0 = const(lltype.nullptr(rclass.NONGCOBJECT)) + c0 = ll_const(lltype.nullptr(rclass.NONGCOBJECT)) # for opname, reducedname in [('ptr_eq', 'int_is_zero'), ('ptr_ne', 'int_is_true')]: @@ -793,7 +778,7 @@ def test_str_getinteriorarraysize(): v = varoftype(lltype.Ptr(rstr.STR)) v_result = varoftype(lltype.Signed) op = SpaceOperation('getinteriorarraysize', - [v, Constant('chars', lltype.Void)], + [v, LLConstant('chars', lltype.Void)], v_result) op1 = Transformer().rewrite_operation(op) assert op1.opname == 'strlen' @@ -804,7 +789,7 @@ def test_unicode_getinteriorarraysize(): v = varoftype(lltype.Ptr(rstr.UNICODE)) v_result = varoftype(lltype.Signed) op = SpaceOperation('getinteriorarraysize', - [v, Constant('chars', lltype.Void)], + [v, LLConstant('chars', lltype.Void)], v_result) op1 = Transformer().rewrite_operation(op) assert op1.opname == 'unicodelen' @@ -816,7 +801,7 @@ def test_str_getinteriorfield(): v_index = varoftype(lltype.Signed) v_result = varoftype(lltype.Char) op = SpaceOperation('getinteriorfield', - [v, Constant('chars', lltype.Void), v_index], + [v, LLConstant('chars', lltype.Void), v_index], v_result) op1 = Transformer().rewrite_operation(op) assert op1.opname == 'strgetitem' @@ -828,7 +813,7 @@ def test_unicode_getinteriorfield(): v_index = varoftype(lltype.Signed) v_result = varoftype(lltype.UniChar) op = SpaceOperation('getinteriorfield', - [v, Constant('chars', lltype.Void), v_index], + [v, LLConstant('chars', lltype.Void), v_index], v_result) op1 = Transformer().rewrite_operation(op) assert op1.opname == 'unicodegetitem' @@ -841,13 +826,13 @@ def test_dict_getinteriorfield(): v = varoftype(lltype.Ptr(DICT)) i = varoftype(lltype.Signed) v_result = varoftype(lltype.Signed) - op = SpaceOperation('getinteriorfield', [v, i, Constant('v', lltype.Void)], + op = SpaceOperation('getinteriorfield', [v, i, LLConstant('v', lltype.Void)], v_result) op1 = Transformer(FakeCPU()).rewrite_operation(op) assert op1.opname == 'getinteriorfield_gc_i' assert op1.args == [v, i, ('interiorfielddescr', DICT, 'v')] - op = SpaceOperation('getinteriorfield', [v, i, Constant('v', lltype.Void)], - Constant(None, lltype.Void)) + op = SpaceOperation('getinteriorfield', [v, i, LLConstant('v', lltype.Void)], + LLConstant(None, lltype.Void)) op1 = Transformer(FakeCPU()).rewrite_operation(op) assert op1 is None @@ -857,7 +842,7 @@ def test_str_setinteriorfield(): v_newchr = varoftype(lltype.Char) v_void = varoftype(lltype.Void) op = SpaceOperation('setinteriorfield', - [v, Constant('chars', lltype.Void), v_index, v_newchr], + [v, LLConstant('chars', lltype.Void), v_index, v_newchr], v_void) op1 = Transformer().rewrite_operation(op) assert op1.opname == 'strsetitem' @@ -870,7 +855,7 @@ def test_unicode_setinteriorfield(): v_newchr = varoftype(lltype.UniChar) v_void = varoftype(lltype.Void) op = SpaceOperation('setinteriorfield', - [v, Constant('chars', lltype.Void), v_index, v_newchr], + [v, LLConstant('chars', lltype.Void), v_index, v_newchr], v_void) op1 = Transformer().rewrite_operation(op) assert op1.opname == 'unicodesetitem' @@ -883,13 +868,13 @@ def test_dict_setinteriorfield(): v = varoftype(lltype.Ptr(DICT)) i = varoftype(lltype.Signed) v_void = varoftype(lltype.Void) - op = SpaceOperation('setinteriorfield', [v, i, Constant('v', lltype.Void), + op = SpaceOperation('setinteriorfield', [v, i, LLConstant('v', lltype.Void), i], v_void) op1 = Transformer(FakeCPU()).rewrite_operation(op) assert op1.opname == 'setinteriorfield_gc_i' assert op1.args == [v, i, i, ('interiorfielddescr', DICT, 'v')] - op = SpaceOperation('setinteriorfield', [v, i, Constant('v', lltype.Void), + op = SpaceOperation('setinteriorfield', [v, i, LLConstant('v', lltype.Void), v_void], v_void) op1 = Transformer(FakeCPU()).rewrite_operation(op) assert not op1 @@ -922,7 +907,7 @@ def test_promote_1(): v1 = varoftype(lltype.Signed) v2 = varoftype(lltype.Signed) op = SpaceOperation('hint', - [v1, Constant({'promote': True}, lltype.Void)], + [v1, LLConstant({'promote': True}, lltype.Void)], v2) oplist = Transformer().rewrite_operation(op) op0, op1, op2 = oplist @@ -937,7 +922,7 @@ def test_promote_2(): v1 = varoftype(lltype.Signed) v2 = varoftype(lltype.Signed) op = SpaceOperation('hint', - [v1, Constant({'promote': True}, lltype.Void)], + [v1, LLConstant({'promote': True}, lltype.Void)], v2) returnblock = Block([varoftype(lltype.Signed)]) returnblock.operations = () @@ -970,8 +955,8 @@ def test_jit_merge_point_1(): vvoid2 = varoftype(lltype.Void) v5 = varoftype(lltype.Void) op = SpaceOperation('jit_marker', - [Constant('jit_merge_point', lltype.Void), - Constant(jd.jitdriver, lltype.Void), + [LLConstant('jit_merge_point', lltype.Void), + LLConstant(jd.jitdriver, lltype.Void), v1, v2, vvoid1, v3, v4, vvoid2], v5) tr = Transformer() tr.portal_jd = jd @@ -994,7 +979,7 @@ def test_getfield_gc(): S = lltype.GcStruct('S', ('x', lltype.Char)) v1 = varoftype(lltype.Ptr(S)) v2 = varoftype(lltype.Char) - op = SpaceOperation('getfield', [v1, Constant('x', lltype.Void)], v2) + op = SpaceOperation('getfield', [v1, LLConstant('x', lltype.Void)], v2) op1 = Transformer(FakeCPU()).rewrite_operation(op) assert op1.opname == 'getfield_gc_i' assert op1.args == [v1, ('fielddescr', S, 'x')] @@ -1005,7 +990,7 @@ def test_getfield_gc_pure(): hints={'immutable': True}) v1 = varoftype(lltype.Ptr(S)) v2 = varoftype(lltype.Char) - op = SpaceOperation('getfield', [v1, Constant('x', lltype.Void)], v2) + op = SpaceOperation('getfield', [v1, LLConstant('x', lltype.Void)], v2) op1 = Transformer(FakeCPU()).rewrite_operation(op) assert op1.opname == 'getfield_gc_i_pure' assert op1.args == [v1, ('fielddescr', S, 'x')] @@ -1023,7 +1008,7 @@ def test_getfield_gc_greenfield(): hints={'immutable': True}) v1 = varoftype(lltype.Ptr(S)) v2 = varoftype(lltype.Char) - op = SpaceOperation('getfield', [v1, Constant('x', lltype.Void)], v2) + op = SpaceOperation('getfield', [v1, LLConstant('x', lltype.Void)], v2) op1 = Transformer(FakeCPU(), FakeCC()).rewrite_operation(op) assert op1.opname == 'getfield_gc_i_greenfield' assert op1.args == [v1, ('fielddescr', S, 'x')] @@ -1040,8 +1025,8 @@ def test_int_abs(): assert oplist[0].args[0] == 'somejitcode' def test_str_newstr(): - c_STR = Constant(rstr.STR, lltype.Void) - c_flavor = Constant({'flavor': 'gc'}, lltype.Void) + c_STR = LLConstant(rstr.STR, lltype.Void) + c_flavor = LLConstant({'flavor': 'gc'}, lltype.Void) v1 = varoftype(lltype.Signed) v2 = varoftype(lltype.Ptr(rstr.STR)) op = SpaceOperation('malloc_varsize', [c_STR, c_flavor, v1], v2) @@ -1051,10 +1036,10 @@ def test_str_newstr(): assert op1.result == v2 def test_malloc_varsize_zero(): - c_A = Constant(lltype.GcArray(lltype.Signed), lltype.Void) + c_A = LLConstant(lltype.GcArray(lltype.Signed), lltype.Void) v1 = varoftype(lltype.Signed) v2 = varoftype(c_A.value) - c_flags = Constant({"flavor": "gc", "zero": True}, lltype.Void) + c_flags = LLConstant({"flavor": "gc", "zero": True}, lltype.Void) op = SpaceOperation('malloc_varsize', [c_A, c_flags, v1], v2) op1 = Transformer(FakeCPU()).rewrite_operation(op) assert op1.opname == 'new_array_clear' @@ -1068,7 +1053,7 @@ def test_str_concat(): v1 = varoftype(PSTR) v2 = varoftype(PSTR) v3 = varoftype(PSTR) - op = SpaceOperation('direct_call', [const(func), v1, v2], v3) + op = SpaceOperation('direct_call', [ll_const(func), v1, v2], v3) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) op1 = tr.rewrite_operation(op) assert op1.opname == 'residual_call_r_r' @@ -1082,7 +1067,7 @@ def test_str_promote(): v1 = varoftype(PSTR) v2 = varoftype(PSTR) op = SpaceOperation('hint', - [v1, Constant({'promote_string': True}, lltype.Void)], + [v1, LLConstant({'promote_string': True}, lltype.Void)], v2) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) op0, op1, _ = tr.rewrite_operation(op) @@ -1098,10 +1083,10 @@ def test_double_promote_str(): v2 = varoftype(PSTR) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) op1 = SpaceOperation('hint', - [v1, Constant({'promote_string': True}, lltype.Void)], + [v1, LLConstant({'promote_string': True}, lltype.Void)], v2) op2 = SpaceOperation('hint', - [v1, Constant({'promote_string': True, + [v1, LLConstant({'promote_string': True, 'promote': True}, lltype.Void)], v2) lst1 = tr.rewrite_operation(op1) @@ -1113,10 +1098,10 @@ def test_double_promote_nonstr(): v2 = varoftype(lltype.Signed) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) op1 = SpaceOperation('hint', - [v1, Constant({'promote': True}, lltype.Void)], + [v1, LLConstant({'promote': True}, lltype.Void)], v2) op2 = SpaceOperation('hint', - [v1, Constant({'promote_string': True, + [v1, LLConstant({'promote_string': True, 'promote': True}, lltype.Void)], v2) lst1 = tr.rewrite_operation(op1) @@ -1132,7 +1117,7 @@ def test_unicode_concat(): v1 = varoftype(PSTR) v2 = varoftype(PSTR) v3 = varoftype(PSTR) - op = SpaceOperation('direct_call', [const(func), v1, v2], v3) + op = SpaceOperation('direct_call', [ll_const(func), v1, v2], v3) cc = FakeBuiltinCallControl() tr = Transformer(FakeCPU(), cc) op1 = tr.rewrite_operation(op) @@ -1159,7 +1144,7 @@ def test_str_slice(): v2 = varoftype(INT) v3 = varoftype(INT) v4 = varoftype(PSTR) - op = SpaceOperation('direct_call', [const(func), v1, v2, v3], v4) + op = SpaceOperation('direct_call', [ll_const(func), v1, v2, v3], v4) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) op1 = tr.rewrite_operation(op) assert op1.opname == 'residual_call_ir_r' @@ -1180,7 +1165,7 @@ def test_unicode_slice(): v2 = varoftype(INT) v3 = varoftype(INT) v4 = varoftype(PUNICODE) - op = SpaceOperation('direct_call', [const(func), v1, v2, v3], v4) + op = SpaceOperation('direct_call', [ll_const(func), v1, v2, v3], v4) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) op1 = tr.rewrite_operation(op) assert op1.opname == 'residual_call_ir_r' @@ -1199,7 +1184,7 @@ def test_str2unicode(): _callable=rstr.LLHelpers.ll_str2unicode) v1 = varoftype(PSTR) v2 = varoftype(PUNICODE) - op = SpaceOperation('direct_call', [const(func), v1], v2) + op = SpaceOperation('direct_call', [ll_const(func), v1], v2) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) op1 = tr.rewrite_operation(op) assert op1.opname == 'residual_call_r_r' @@ -1217,7 +1202,7 @@ def test_unicode_eq_checknull_char(): v1 = varoftype(PUNICODE) v2 = varoftype(PUNICODE) v3 = varoftype(lltype.Bool) - op = SpaceOperation('direct_call', [const(func), v1, v2], v3) + op = SpaceOperation('direct_call', [ll_const(func), v1, v2], v3) cc = FakeBuiltinCallControl() tr = Transformer(FakeCPU(), cc) op1 = tr.rewrite_operation(op) @@ -1244,7 +1229,7 @@ def test_list_ll_arraycopy(): v4 = varoftype(INT) v5 = varoftype(INT) v6 = varoftype(lltype.Void) - op = SpaceOperation('direct_call', [const(func), v1, v2, v3, v4, v5], v6) + op = SpaceOperation('direct_call', [ll_const(func), v1, v2, v3, v4, v5], v6) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) op1 = tr.rewrite_operation(op) assert op1.opname == 'residual_call_ir_v' @@ -1261,7 +1246,7 @@ def test_math_sqrt(): _callable=ll_math.sqrt_nonneg) v1 = varoftype(FLOAT) v2 = varoftype(FLOAT) - op = SpaceOperation('direct_call', [const(func), v1], v2) + op = SpaceOperation('direct_call', [ll_const(func), v1], v2) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) op1 = tr.rewrite_operation(op) assert op1.opname == 'residual_call_irf_f' @@ -1280,8 +1265,8 @@ def test_quasi_immutable(): STRUCT = lltype.GcStruct('struct', ('inst_x', lltype.Signed), ('mutate_x', rclass.OBJECTPTR), hints={'immutable_fields': accessor}) - for v_x in [const(lltype.malloc(STRUCT)), varoftype(lltype.Ptr(STRUCT))]: - op = SpaceOperation('getfield', [v_x, Constant('inst_x', lltype.Void)], + for v_x in [ll_const(lltype.malloc(STRUCT)), varoftype(lltype.Ptr(STRUCT))]: + op = SpaceOperation('getfield', [v_x, LLConstant('inst_x', lltype.Void)], v2) tr = Transformer(FakeCPU()) [_, op1, op2] = tr.rewrite_operation(op) @@ -1305,9 +1290,9 @@ def test_quasi_immutable_setfield(): STRUCT = lltype.GcStruct('struct', ('inst_x', lltype.Signed), ('mutate_x', rclass.OBJECTPTR), hints={'immutable_fields': accessor}) - for v_x in [const(lltype.malloc(STRUCT)), varoftype(lltype.Ptr(STRUCT))]: + for v_x in [ll_const(lltype.malloc(STRUCT)), varoftype(lltype.Ptr(STRUCT))]: op = SpaceOperation('jit_force_quasi_immutable', - [v_x, Constant('mutate_x', lltype.Void)], + [v_x, LLConstant('mutate_x', lltype.Void)], varoftype(lltype.Void)) tr = Transformer(FakeCPU(), FakeRegularCallControl()) tr.graph = 'currentgraph' @@ -1322,7 +1307,7 @@ def test_no_gcstruct_nesting_outside_of_OBJECT(): STRUCT = lltype.GcStruct('struct', ('parent', PARENT), ('x', lltype.Signed)) v_x = varoftype(lltype.Ptr(STRUCT)) - op = SpaceOperation('getfield', [v_x, Constant('x', lltype.Void)], + op = SpaceOperation('getfield', [v_x, LLConstant('x', lltype.Void)], varoftype(lltype.Signed)) tr = Transformer(None, None) py.test.raises(NotImplementedError, tr.rewrite_operation, op) @@ -1332,7 +1317,7 @@ def _test_threadlocalref_get(loop_inv): tlfield = ThreadLocalField(lltype.Signed, 'foobar_test_', loop_invariant=loop_inv) OS_THREADLOCALREF_GET = effectinfo.EffectInfo.OS_THREADLOCALREF_GET - c = const(tlfield.offset) + c = ll_const(tlfield.offset) v = varoftype(lltype.Signed) op = SpaceOperation('threadlocalref_get', [c], v) cc = FakeBuiltinCallControl() diff --git a/rpython/jit/codewriter/test/test_list.py b/rpython/jit/codewriter/test/test_list.py index 41d92043020df9e97db3f9c5f707f924e309ecce..ae2d05237496203252460579159fae224dd6cac2 100644 --- a/rpython/jit/codewriter/test/test_list.py +++ b/rpython/jit/codewriter/test/test_list.py @@ -1,6 +1,7 @@ from rpython.rtyper.lltypesystem import lltype from rpython.translator.unsimplify import varoftype -from rpython.flowspace.model import Constant, SpaceOperation +from rpython.flowspace.model import SpaceOperation +from rpython.rtyper.rmodel import LLConstant from rpython.jit.codewriter.jtransform import Transformer, NotSupported from rpython.jit.codewriter.flatten import GraphFlattener @@ -63,7 +64,7 @@ def builtin_test(oopspec_name, args, RESTYPE, expected): raise ValueError(property) tr._get_list_nonneg_canraise_flags = force_flags op = SpaceOperation('direct_call', - [Constant("myfunc", lltype.Void)] + args, + [LLConstant("myfunc", lltype.Void)] + args, v_result) try: oplist = tr._handle_list_call(op, oopspec_name, args) @@ -85,11 +86,11 @@ def builtin_test(oopspec_name, args, RESTYPE, expected): def test_newlist(): builtin_test('newlist', [], FIXEDLIST, """new_array $0, -> %r0""") - builtin_test('newlist', [Constant(5, lltype.Signed)], FIXEDLIST, + builtin_test('newlist', [LLConstant(5, lltype.Signed)], FIXEDLIST, """new_array $5, -> %r0""") builtin_test('newlist', [varoftype(lltype.Signed)], FIXEDLIST, """new_array %i0, -> %r0""") - builtin_test('newlist_clear', [Constant(5, lltype.Signed)], FIXEDLIST, + builtin_test('newlist_clear', [LLConstant(5, lltype.Signed)], FIXEDLIST, """new_array_clear $5, -> %r0""") builtin_test('newlist', [], FIXEDPTRLIST, """new_array_clear $0, -> %r0""") @@ -98,8 +99,8 @@ def test_fixed_ll_arraycopy(): builtin_test('list.ll_arraycopy', [varoftype(FIXEDLIST), varoftype(FIXEDLIST), - varoftype(lltype.Signed), - varoftype(lltype.Signed), + varoftype(lltype.Signed), + varoftype(lltype.Signed), varoftype(lltype.Signed)], lltype.Void, """ residual_call_ir_v $'myfunc', I[%i0, %i1, %i2], R[%r0, %r1], @@ -165,11 +166,11 @@ def test_resizable_newlist(): " , ") builtin_test('newlist', [], VARLIST, """newlist $0, """+alldescrs+""" -> %r0""") - builtin_test('newlist', [Constant(5, lltype.Signed)], VARLIST, + builtin_test('newlist', [LLConstant(5, lltype.Signed)], VARLIST, """newlist $5, """+alldescrs+""" -> %r0""") builtin_test('newlist', [varoftype(lltype.Signed)], VARLIST, """newlist %i0, """+alldescrs+""" -> %r0""") - builtin_test('newlist_clear', [Constant(5, lltype.Signed)], VARLIST, + builtin_test('newlist_clear', [LLConstant(5, lltype.Signed)], VARLIST, """newlist_clear $5, """+alldescrs+""" -> %r0""") def test_resizable_getitem(): diff --git a/rpython/jit/codewriter/test/test_longlong.py b/rpython/jit/codewriter/test/test_longlong.py index c4de1d65ca1cff718a38fd1dbb56ac2af062ef45..0a92024487bbedd70d38b4a9e044bd8bc72d1909 100644 --- a/rpython/jit/codewriter/test/test_longlong.py +++ b/rpython/jit/codewriter/test/test_longlong.py @@ -1,13 +1,12 @@ import py, sys from rpython.rlib.rarithmetic import r_longlong, intmask, is_valid_int -from rpython.flowspace.model import SpaceOperation, Variable, Constant -from rpython.flowspace.model import Block, Link +from rpython.flowspace.model import SpaceOperation, Variable +from rpython.rtyper.rmodel import ll_const from rpython.translator.unsimplify import varoftype from rpython.rtyper.lltypesystem import lltype, rffi -from rpython.jit.codewriter.jtransform import Transformer, NotSupported +from rpython.jit.codewriter.jtransform import Transformer from rpython.jit.codewriter.effectinfo import EffectInfo -from rpython.jit.codewriter.test.test_jtransform import const from rpython.jit.codewriter import longlong @@ -79,7 +78,7 @@ class TestLongLong: assert len(oplist) == 2 assert oplist[0].opname == 'residual_call_irf_f' assert oplist[0].args[0].value == opname.split('_')[0]+'_from_int' - assert list(oplist[0].args[1]) == [const(0)] + assert list(oplist[0].args[1]) == [ll_const(0)] assert list(oplist[0].args[2]) == [] assert list(oplist[0].args[3]) == [] assert oplist[0].args[4] == 'calldescr-84' @@ -104,7 +103,7 @@ class TestLongLong: assert len(oplist) == 2 assert oplist[0].opname == 'residual_call_irf_f' assert oplist[0].args[0].value == 'llong_from_int' - assert list(oplist[0].args[1]) == [const(0)] + assert list(oplist[0].args[1]) == [ll_const(0)] assert list(oplist[0].args[2]) == [] assert list(oplist[0].args[3]) == [] assert oplist[0].args[4] == 'calldescr-84' @@ -224,7 +223,7 @@ class TestLongLong: def test_constants(self): for TYPE in [lltype.SignedLongLong, lltype.UnsignedLongLong]: v_x = varoftype(TYPE) - vlist = [v_x, const(rffi.cast(TYPE, 7))] + vlist = [v_x, ll_const(rffi.cast(TYPE, 7))] v_result = varoftype(TYPE) op = SpaceOperation('llong_add', vlist, v_result) tr = Transformer(FakeCPU(), FakeBuiltinCallControl()) diff --git a/rpython/jit/codewriter/test/test_regalloc.py b/rpython/jit/codewriter/test/test_regalloc.py index 7d2ac3a265c89e150c6346b9d551e406dba90d26..a99f10c9e3df8c384511687b2c667d7dc63ac0e0 100644 --- a/rpython/jit/codewriter/test/test_regalloc.py +++ b/rpython/jit/codewriter/test/test_regalloc.py @@ -1,15 +1,14 @@ -import py, sys from rpython.jit.codewriter import support from rpython.jit.codewriter.regalloc import perform_register_allocation from rpython.jit.codewriter.flatten import flatten_graph, ListOfKind from rpython.jit.codewriter.format import assert_format from rpython.jit.metainterp.history import AbstractDescr -from rpython.flowspace.model import Variable, Constant, SpaceOperation +from rpython.flowspace.model import Variable, SpaceOperation from rpython.flowspace.model import FunctionGraph, Block, Link from rpython.flowspace.model import c_last_exception +from rpython.rtyper.rmodel import ll_const from rpython.rtyper.lltypesystem import lltype, llmemory from rpython.rtyper import rclass -from rpython.rlib.rarithmetic import ovfcheck class TestRegAlloc: @@ -158,7 +157,7 @@ class TestRegAlloc: v4 = Variable(); v4.concretetype = lltype.Signed block = Block([v1]) block.operations = [ - SpaceOperation('int_add', [v1, Constant(1, lltype.Signed)], v2), + SpaceOperation('int_add', [v1, ll_const(1)], v2), SpaceOperation('rescall', [ListOfKind('int', [v1, v2])], v3), ] graph = FunctionGraph('f', block, v4) @@ -212,7 +211,7 @@ class TestRegAlloc: v5 = Variable(); v5.concretetype = lltype.Signed block = Block([v1]) block.operations = [ - SpaceOperation('int_add', [v1, Constant(1, lltype.Signed)], v2), + SpaceOperation('int_add', [v1, ll_const(1)], v2), SpaceOperation('rescall', [ListOfKind('int', [v1, v2])], v5), SpaceOperation('rescall', [ListOfKind('int', [v1, v2])], v3), ] diff --git a/rpython/jit/codewriter/test/test_support.py b/rpython/jit/codewriter/test/test_support.py index 392912b5f131069f20b27d736d180ba4a981aaaf..3f1d995ff8554a22a99821d7a34e859693a20885 100644 --- a/rpython/jit/codewriter/test/test_support.py +++ b/rpython/jit/codewriter/test/test_support.py @@ -1,15 +1,13 @@ import py, sys from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.annlowlevel import llstr -from rpython.flowspace.model import Variable, Constant, SpaceOperation +from rpython.flowspace.model import Variable, SpaceOperation +from rpython.rtyper.rmodel import ll_const, LLConstant from rpython.jit.codewriter.support import decode_builtin_call, LLtypeHelpers from rpython.jit.codewriter.support import _ll_1_int_abs -def newconst(x): - return Constant(x, lltype.typeOf(x)) - def voidconst(x): - return Constant(x, lltype.Void) + return LLConstant(x, lltype.Void) # ____________________________________________________________ @@ -27,14 +25,14 @@ def test_decode_builtin_call_nomethod(): vc.concretetype = lltype.Char v_result = Variable('result') v_result.concretetype = lltype.Signed - op = SpaceOperation('direct_call', [newconst(fnobj), + op = SpaceOperation('direct_call', [ll_const(fnobj), vi, voidconst('mymarker'), vc], v_result) oopspec, opargs = decode_builtin_call(op) assert oopspec == 'foobar' - assert opargs == [newconst(2), vc, vi] + assert opargs == [ll_const(2), vc, vi] #impl = runner.get_oopspec_impl('foobar', lltype.Signed) #assert impl(2, 'A', 5) == 5 * ord('A') @@ -56,15 +54,15 @@ def test_decode_builtin_call_method(): v_result.concretetype = lltype.Signed myarray = lltype.malloc(A, 10) myarray[5] = 42 - op = SpaceOperation('direct_call', [newconst(fnobj), - newconst(myarray), + op = SpaceOperation('direct_call', [ll_const(fnobj), + ll_const(myarray), vi, voidconst('mymarker'), vc], v_result) oopspec, opargs = decode_builtin_call(op) assert oopspec == 'spam.foobar' - assert opargs == [newconst(myarray), newconst(2), vc, vi] + assert opargs == [ll_const(myarray), ll_const(2), vc, vi] #impl = runner.get_oopspec_impl('spam.foobar', lltype.Ptr(A)) #assert impl(myarray, 2, 'A', 5) == 42 * ord('A') diff --git a/rpython/jit/codewriter/test/test_void_list.py b/rpython/jit/codewriter/test/test_void_list.py index 2c6299bf7ec2230c8a2c29d074324c742006e4e4..9336a72798e50bc5743af867a1b4774cb42eee4d 100644 --- a/rpython/jit/codewriter/test/test_void_list.py +++ b/rpython/jit/codewriter/test/test_void_list.py @@ -1,6 +1,6 @@ +from rpython.rtyper.rmodel import ll_const from rpython.rtyper.lltypesystem import lltype from rpython.translator.unsimplify import varoftype -from rpython.flowspace.model import Constant from rpython.jit.codewriter.jtransform import NotSupported from rpython.jit.codewriter.test.test_list import builtin_test @@ -20,26 +20,23 @@ VARLIST = lltype.Ptr(lltype.GcStruct('VARLIST', def test_newlist(): builtin_test('newlist', [], FIXEDLIST, NotSupported) - builtin_test('newlist', [Constant(5, lltype.Signed)], FIXEDLIST, + builtin_test('newlist', [ll_const(5)], FIXEDLIST, NotSupported) builtin_test('newlist', [varoftype(lltype.Signed)], FIXEDLIST, NotSupported) - builtin_test('newlist', [Constant(5, lltype.Signed), - Constant(0, lltype.Signed)], FIXEDLIST, + builtin_test('newlist', [ll_const(5), ll_const(0)], FIXEDLIST, NotSupported) - builtin_test('newlist', [Constant(5, lltype.Signed), - Constant(1, lltype.Signed)], FIXEDLIST, + builtin_test('newlist', [ll_const(5), ll_const(1)], FIXEDLIST, NotSupported) - builtin_test('newlist', [Constant(5, lltype.Signed), - varoftype(lltype.Signed)], FIXEDLIST, + builtin_test('newlist', [ll_const(5), varoftype(lltype.Signed)], FIXEDLIST, NotSupported) def test_fixed_ll_arraycopy(): builtin_test('list.ll_arraycopy', [varoftype(FIXEDLIST), varoftype(FIXEDLIST), - varoftype(lltype.Signed), - varoftype(lltype.Signed), + varoftype(lltype.Signed), + varoftype(lltype.Signed), varoftype(lltype.Signed)], lltype.Void, NotSupported) @@ -82,20 +79,12 @@ def test_fixed_len_foldable(): # Resizable lists def test_resizable_newlist(): - builtin_test('newlist', [], VARLIST, - NotSupported) - builtin_test('newlist', [Constant(5, lltype.Signed)], VARLIST, - NotSupported) - builtin_test('newlist', [varoftype(lltype.Signed)], VARLIST, - NotSupported) - builtin_test('newlist', [Constant(5, lltype.Signed), - Constant(0, lltype.Signed)], VARLIST, - NotSupported) - builtin_test('newlist', [Constant(5, lltype.Signed), - Constant(1, lltype.Signed)], VARLIST, - NotSupported) - builtin_test('newlist', [Constant(5, lltype.Signed), - varoftype(lltype.Signed)], VARLIST, + builtin_test('newlist', [], VARLIST, NotSupported) + builtin_test('newlist', [ll_const(5)], VARLIST, NotSupported) + builtin_test('newlist', [varoftype(lltype.Signed)], VARLIST, NotSupported) + builtin_test('newlist', [ll_const(5), ll_const(0)], VARLIST, NotSupported) + builtin_test('newlist', [ll_const(5), ll_const(1)], VARLIST, NotSupported) + builtin_test('newlist', [ll_const(5), varoftype(lltype.Signed)], VARLIST, NotSupported) def test_resizable_getitem(): diff --git a/rpython/jit/metainterp/warmspot.py b/rpython/jit/metainterp/warmspot.py index 0fd046df74e112d67dc2b27dfebccb45eb6b9014..ff7ebeb1e2742acd7d12fc41d7427ca0f6892fe9 100644 --- a/rpython/jit/metainterp/warmspot.py +++ b/rpython/jit/metainterp/warmspot.py @@ -8,8 +8,9 @@ from rpython.rtyper.llannotation import lltype_to_annotation from rpython.annotator import model as annmodel from rpython.rtyper.llinterp import LLException from rpython.rtyper.test.test_llinterp import get_interpreter, clear_tcache -from rpython.flowspace.model import SpaceOperation, Variable, Constant +from rpython.flowspace.model import SpaceOperation, Variable from rpython.flowspace.model import checkgraph, Link, copygraph +from rpython.rtyper.rmodel import LLConstant from rpython.rlib.objectmodel import we_are_translated from rpython.rlib.unroll import unrolling_iterable from rpython.rlib.debug import fatalerror @@ -364,7 +365,7 @@ class WarmRunnerDesc(object): if not driver.inline_jit_merge_point: continue new_driver = driver.clone() - c_new_driver = Constant(new_driver, v_driver.concretetype) + c_new_driver = LLConstant(new_driver, v_driver.concretetype) op.args[1] = c_new_driver def find_portals(self): @@ -674,7 +675,7 @@ class WarmRunnerDesc(object): jitdriver_name, func, ARGS, argspec) v_result = op.result - c_accessor = Constant(accessor, concretetype=lltype.Void) + c_accessor = LLConstant(accessor, concretetype=lltype.Void) newop = SpaceOperation('direct_call', [c_accessor] + op.args[2:], v_result) block.operations[index] = newop @@ -728,7 +729,7 @@ class WarmRunnerDesc(object): op1.args[0].value == 'jit_merge_point') op0 = SpaceOperation( 'jit_marker', - [Constant('can_enter_jit', lltype.Void)] + op1.args[1:], + [LLConstant('can_enter_jit', lltype.Void)] + op1.args[1:], None) operations.insert(0, op0) can_enter_jits = [(jd.portal_graph, jd.portal_graph.startblock, 0)] @@ -741,7 +742,7 @@ class WarmRunnerDesc(object): greens_v, reds_v = support.decode_hp_hint_args(op) args_v = greens_v + reds_v - vlist = [Constant(jit_enter_fnptr, FUNCPTR)] + args_v + vlist = [LLConstant(jit_enter_fnptr, FUNCPTR)] + args_v v_result = Variable() v_result.concretetype = lltype.Void @@ -789,7 +790,7 @@ class WarmRunnerDesc(object): FUNCPTR = lltype.Ptr(lltype.FuncType(ARGS, RESULT)) ptr = self.helper_func(FUNCPTR, new_func) op.opname = 'direct_call' - op.args = [Constant(ptr, FUNCPTR)] + op.args[2:] + op.args = [LLConstant(ptr, FUNCPTR)] + op.args[2:] def rewrite_jit_merge_points(self, policy): for jd in self.jitdrivers_sd: @@ -993,7 +994,7 @@ class WarmRunnerDesc(object): assert op.opname == 'jit_marker' assert op.args[0].value == 'jit_merge_point' greens_v, reds_v = support.decode_hp_hint_args(op) - vlist = [Constant(jd.portal_runner_ptr, jd._PTR_PORTAL_FUNCTYPE)] + vlist = [LLConstant(jd.portal_runner_ptr, jd._PTR_PORTAL_FUNCTYPE)] vlist += greens_v vlist += reds_v v_result = Variable() @@ -1046,7 +1047,7 @@ class WarmRunnerDesc(object): else: TP = PTR_SET_PARAM_FUNCTYPE funcptr = self.helper_func(TP, closure) - return Constant(funcptr, TP) + return LLConstant(funcptr, TP) # for graph, block, i in find_set_param(graphs): @@ -1082,7 +1083,7 @@ class WarmRunnerDesc(object): func = quasiimmut.make_invalidation_function(ARG, mutatefieldname) FUNC = lltype.Ptr(lltype.FuncType([ARG], lltype.Void)) llptr = self.helper_func(FUNC, func) - cptr = Constant(llptr, FUNC) + cptr = LLConstant(llptr, FUNC) self._cache_force_quasiimmed_funcs[key] = cptr op.opname = 'direct_call' op.args = [cptr, op.args[0]] diff --git a/rpython/memory/gctransform/asmgcroot.py b/rpython/memory/gctransform/asmgcroot.py index 12f86e0282674a7c72c98cb1afd13d267e0933c0..505b727a4580da2944378acb59a91cacfdd50e64 100644 --- a/rpython/memory/gctransform/asmgcroot.py +++ b/rpython/memory/gctransform/asmgcroot.py @@ -1,8 +1,10 @@ -from rpython.flowspace.model import (Constant, Variable, Block, Link, - copygraph, SpaceOperation, checkgraph) +import sys +from rpython.flowspace.model import ( + Variable, Block, Link, copygraph, SpaceOperation, checkgraph) from rpython.rlib.debug import ll_assert from rpython.rlib.nonconst import NonConstant from rpython.rlib import rgil +from rpython.rtyper.rmodel import ll_const, LLConstant from rpython.rtyper.annlowlevel import llhelper from rpython.rtyper.lltypesystem import lltype, llmemory, rffi from rpython.rtyper.lltypesystem.lloperation import llop @@ -12,7 +14,6 @@ from rpython.rtyper.llannotation import SomeAddress from rpython.rtyper.rbuiltin import gen_cast from rpython.translator.unsimplify import varoftype from rpython.translator.tool.cbuild import ExternalCompilationInfo -import sys # @@ -94,7 +95,7 @@ class AsmGcRootFrameworkGCTransformer(BaseFrameworkGCTransformer): CONTAINER = lltype.FixedSizeArray(TYPE, 1) p = lltype.malloc(CONTAINER, flavor='raw', zero=True, immortal=True) - sradict[key] = Constant(p, lltype.Ptr(CONTAINER)) + sradict[key] = ll_const(p) sra.append(sradict[key]) # # make a copy of the graph that will reload the values @@ -103,7 +104,7 @@ class AsmGcRootFrameworkGCTransformer(BaseFrameworkGCTransformer): # # edit the original graph to only store the value of the arguments block = Block(graph.startblock.inputargs) - c_item0 = Constant('item0', lltype.Void) + c_item0 = LLConstant('item0', lltype.Void) assert len(block.inputargs) == len(sra) for v_arg, c_p in zip(block.inputargs, sra): if isinstance(v_arg.concretetype, lltype.Ptr): @@ -120,7 +121,7 @@ class AsmGcRootFrameworkGCTransformer(BaseFrameworkGCTransformer): fnptr2 = lltype.functionptr(FUNC2, fnptr._obj._name + '_reload', graph=graph2) - c_fnptr2 = Constant(fnptr2, lltype.Ptr(FUNC2)) + c_fnptr2 = ll_const(fnptr2) HELPERFUNC = lltype.FuncType([lltype.Ptr(FUNC2), ASM_FRAMEDATA_HEAD_PTR], FUNC1.RESULT) v_asm_stackwalk = varoftype(lltype.Ptr(HELPERFUNC), "asm_stackwalk") @@ -129,8 +130,7 @@ class AsmGcRootFrameworkGCTransformer(BaseFrameworkGCTransformer): v_result = varoftype(FUNC1.RESULT) block.operations.append( SpaceOperation("indirect_call", [v_asm_stackwalk, c_fnptr2, - c_gcrootanchor, - Constant(None, lltype.Void)], + c_gcrootanchor, ll_const(None)], v_result)) block.closeblock(Link([v_result], graph.returnblock)) graph.startblock = block @@ -819,7 +819,7 @@ ASM_FRAMEDATA_HEAD_PTR.TO.become(lltype.Struct('ASM_FRAMEDATA_HEAD', gcrootanchor = lltype.malloc(ASM_FRAMEDATA_HEAD_PTR.TO, immortal=True) gcrootanchor.prev = gcrootanchor gcrootanchor.next = gcrootanchor -c_gcrootanchor = Constant(gcrootanchor, ASM_FRAMEDATA_HEAD_PTR) +c_gcrootanchor = ll_const(gcrootanchor) eci = ExternalCompilationInfo(compile_extra=['-DPYPY_USE_ASMGCC']) @@ -831,21 +831,20 @@ pypy_asm_stackwalk = rffi.llexternal('pypy_asm_stackwalk', _nowrapper=True, random_effects_on_gcobjs=True, compilation_info=eci) -c_asm_stackwalk = Constant(pypy_asm_stackwalk, - lltype.typeOf(pypy_asm_stackwalk)) +c_asm_stackwalk = ll_const(pypy_asm_stackwalk) pypy_asm_gcroot = rffi.llexternal('pypy_asm_gcroot', [llmemory.Address], llmemory.Address, sandboxsafe=True, _nowrapper=True) -c_asm_gcroot = Constant(pypy_asm_gcroot, lltype.typeOf(pypy_asm_gcroot)) +c_asm_gcroot = ll_const(pypy_asm_gcroot) pypy_asm_nocollect = rffi.llexternal('pypy_asm_gc_nocollect', [rffi.CCHARP], lltype.Void, sandboxsafe=True, _nowrapper=True) -c_asm_nocollect = Constant(pypy_asm_nocollect, lltype.typeOf(pypy_asm_nocollect)) +c_asm_nocollect = ll_const(pypy_asm_nocollect) QSORT_CALLBACK_PTR = lltype.Ptr(lltype.FuncType([llmemory.Address, llmemory.Address], rffi.INT)) diff --git a/rpython/memory/gctransform/boehm.py b/rpython/memory/gctransform/boehm.py index f88a6ba7c1db9172789d630ad20b05567fbcb686..81da2bade1e6b09f76ccdb839c73fbddf64b08b8 100644 --- a/rpython/memory/gctransform/boehm.py +++ b/rpython/memory/gctransform/boehm.py @@ -2,7 +2,7 @@ from rpython.memory.gctransform.transform import GCTransformer, mallocHelpers from rpython.memory.gctransform.support import (get_rtti, _static_deallocator_body_for_type, LLTransformerOp, ll_call_destructor) from rpython.rtyper.lltypesystem import lltype, llmemory -from rpython.flowspace.model import Constant +from rpython.rtyper.rmodel import LLConstant from rpython.rtyper.lltypesystem.lloperation import llop from rpython.rtyper import rmodel @@ -68,13 +68,13 @@ class BoehmGCTransformer(GCTransformer): resulttype=llmemory.Address) finalizer_ptr = self.finalizer_funcptr_for_type(TYPE) if finalizer_ptr: - c_finalizer_ptr = Constant(finalizer_ptr, self.FINALIZER_PTR) + c_finalizer_ptr = LLConstant(finalizer_ptr, self.FINALIZER_PTR) hop.genop("boehm_register_finalizer", [v_raw, c_finalizer_ptr]) return v_raw def gct_fv_gc_malloc_varsize(self, hop, flags, TYPE, v_length, c_const_size, c_item_size, c_offset_to_length): - # XXX same behavior for zero=True: in theory that's wrong + # XXX same behavior for zero=True: in theory that's wrong if c_offset_to_length is None: v_raw = hop.genop("direct_call", [self.malloc_varsize_no_length_ptr, v_length, diff --git a/rpython/memory/gctransform/test/test_framework.py b/rpython/memory/gctransform/test/test_framework.py index 92420e919c3b7bf0bb5ef2c044bc821100b534fe..5ecb5501fd38ad3c2a1aa51f50df72162980c21c 100644 --- a/rpython/memory/gctransform/test/test_framework.py +++ b/rpython/memory/gctransform/test/test_framework.py @@ -1,6 +1,7 @@ from rpython.annotator.listdef import s_list_of_strings from rpython.annotator.model import SomeInteger -from rpython.flowspace.model import Constant, SpaceOperation, mkentrymap +from rpython.flowspace.model import SpaceOperation, mkentrymap +from rpython.rtyper.rmodel import LLConstant from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rtyper.lltypesystem.lloperation import llop from rpython.memory.gc.semispace import SemiSpaceGC @@ -69,7 +70,7 @@ def test_cancollect(): return -x t = rtype(g, [int]) gg = graphof(t, g) - assert not CollectAnalyzer(t).analyze_direct_call(gg) + assert not CollectAnalyzer(t).analyze_direct_call(gg) def test_cancollect_external(): fext1 = rffi.llexternal('fext1', [], lltype.Void, releasegil=False) @@ -110,7 +111,7 @@ def test_no_collect(): def entrypoint(argv): return g() + 2 - + t = rtype(entrypoint, [s_list_of_strings]) t.config.translation.gc = "minimark" cbuild = CStandaloneBuilder(t, entrypoint, t.config, @@ -134,7 +135,7 @@ def test_no_collect_detection(): def entrypoint(argv): return g() + 2 - + t = rtype(entrypoint, [s_list_of_strings]) t.config.translation.gc = "minimark" cbuild = CStandaloneBuilder(t, entrypoint, t.config, @@ -167,7 +168,7 @@ def test_custom_trace_function_no_collect(): assert 'can cause the GC to be called' in str(f.value) assert 'trace_func' in str(f.value) assert 'MyStructure' in str(f.value) - + class WriteBarrierTransformer(ShadowStackFrameworkGCTransformer): clean_sets = {} GC_PARAMS = {} @@ -198,7 +199,7 @@ def test_write_barrier_support_setfield(): PTR_TYPE = lltype.Ptr(lltype.GcStruct('S', ('x', PTR_TYPE2))) write_barrier_check(SpaceOperation( "setfield", - [varoftype(PTR_TYPE), Constant('x', lltype.Void), + [varoftype(PTR_TYPE), LLConstant('x', lltype.Void), varoftype(PTR_TYPE2)], varoftype(lltype.Void))) @@ -208,8 +209,8 @@ def test_dont_add_write_barrier_for_constant_new_value(): PTR_TYPE = lltype.Ptr(lltype.GcStruct('S', ('x', PTR_TYPE2))) write_barrier_check(SpaceOperation( "setfield", - [varoftype(PTR_TYPE), Constant('x', lltype.Void), - Constant('foo', varoftype(PTR_TYPE2))], + [varoftype(PTR_TYPE), LLConstant('x', lltype.Void), + LLConstant('foo', varoftype(PTR_TYPE2))], varoftype(lltype.Void)), needs_write_barrier=False) def test_write_barrier_support_setarrayitem(): @@ -228,7 +229,7 @@ def test_write_barrier_support_setinteriorfield(): write_barrier_check(SpaceOperation( "setinteriorfield", [varoftype(ARRAYPTR2), varoftype(lltype.Signed), - Constant('b', lltype.Void), varoftype(PTR_TYPE2)], + LLConstant('b', lltype.Void), varoftype(PTR_TYPE2)], varoftype(lltype.Void))) def test_remove_duplicate_write_barrier(): @@ -306,7 +307,7 @@ def test_find_initializing_stores_across_blocks(): def test_find_clean_setarrayitems(): S = lltype.GcStruct('S') A = lltype.GcArray(lltype.Ptr(S)) - + def f(): l = lltype.malloc(A, 3) l[0] = lltype.malloc(S) @@ -327,7 +328,7 @@ def test_find_clean_setarrayitems(): def test_find_clean_setarrayitems_2(): S = lltype.GcStruct('S') A = lltype.GcArray(lltype.Ptr(S)) - + def f(): l = lltype.malloc(A, 3) l[0] = lltype.malloc(S) @@ -349,7 +350,7 @@ def test_find_clean_setarrayitems_2(): def test_find_clean_setarrayitems_3(): S = lltype.GcStruct('S') A = lltype.GcArray(lltype.Ptr(S)) - + def f(): l = lltype.malloc(A, 3) l[0] = lltype.malloc(S) diff --git a/rpython/memory/gctransform/transform.py b/rpython/memory/gctransform/transform.py index fff97de90fcadacad79be5b4df28af28a6932d29..345aae91d0cef64ee5807243633ebc178a540e8d 100644 --- a/rpython/memory/gctransform/transform.py +++ b/rpython/memory/gctransform/transform.py @@ -1,6 +1,6 @@ from rpython.rtyper.lltypesystem import lltype, llmemory from rpython.flowspace.model import ( - SpaceOperation, Variable, Constant, checkgraph) + SpaceOperation, Variable, checkgraph) from rpython.translator.unsimplify import insert_empty_block from rpython.translator.unsimplify import insert_empty_startblock from rpython.translator.unsimplify import starts_with_empty_block @@ -13,6 +13,7 @@ from rpython.rtyper.llannotation import lltype_to_annotation from rpython.rtyper import rmodel from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator from rpython.rtyper.rtyper import LowLevelOpList +from rpython.rtyper.rmodel import inputconst from rpython.rtyper.rbuiltin import gen_cast from rpython.rlib.rarithmetic import ovfcheck from rpython.rtyper.lltypesystem.lloperation import llop @@ -273,7 +274,7 @@ class BaseGCTransformer(object): def inittime_helper(self, ll_helper, ll_args, ll_result, inline=True): ptr = self.annotate_helper(ll_helper, ll_args, ll_result, inline=inline) - return Constant(ptr, lltype.typeOf(ptr)) + return inputconst(lltype.typeOf(ptr), ptr) def annotate_finalizer(self, ll_finalizer, ll_args, ll_result): fptr = self.annotate_helper(ll_finalizer, ll_args, ll_result) diff --git a/rpython/memory/test/test_gctypelayout.py b/rpython/memory/test/test_gctypelayout.py index 056e162536c5b41bb9cabedeabe0e832ab3cf1e7..f6f45b4da4e87722ee02bd56569efba884b44f35 100644 --- a/rpython/memory/test/test_gctypelayout.py +++ b/rpython/memory/test/test_gctypelayout.py @@ -6,7 +6,7 @@ from rpython.rtyper.lltypesystem import lltype, llmemory from rpython.rtyper import rclass from rpython.rtyper.rclass import IR_IMMUTABLE, IR_QUASIIMMUTABLE from rpython.rtyper.test.test_llinterp import get_interpreter -from rpython.flowspace.model import Constant +from rpython.rtyper.rmodel import LLConstant class FakeGC: object_minimal_size = 0 @@ -92,7 +92,7 @@ def test_constfold(): 100000 * gc.is_gcarrayofgcptr(tid2)) interp, graph = get_interpreter(f, [], backendopt=True) assert interp.eval_graph(graph, []) == 11001 - assert graph.startblock.exits[0].args == [Constant(11001, lltype.Signed)] + assert graph.startblock.exits[0].args == [LLConstant(11001, lltype.Signed)] def test_gc_pointers_inside(): from rpython.rtyper import rclass diff --git a/rpython/memory/test/test_transformed_gc.py b/rpython/memory/test/test_transformed_gc.py index 8e97d4bf656e965ae64cd2f26b31e769f389b21f..d84c832fb8f7ba5992c5db79153473073a6cdedf 100644 --- a/rpython/memory/test/test_transformed_gc.py +++ b/rpython/memory/test/test_transformed_gc.py @@ -741,7 +741,7 @@ class GenericMovingGCTests(GenericGCTests): def fix_graph_of_g(translator): from rpython.translator.translator import graphof - from rpython.flowspace.model import Constant + from rpython.rtyper.rmodel import LLConstant from rpython.rtyper.lltypesystem import rffi layoutbuilder = cls.ensure_layoutbuilder(translator) @@ -751,11 +751,11 @@ class GenericMovingGCTests(GenericGCTests): graph = graphof(translator, g) for op in graph.startblock.operations: if op.opname == 'do_malloc_fixedsize': - op.args = [Constant(type_id, llgroup.HALFWORD), - Constant(llmemory.sizeof(P), lltype.Signed), - Constant(False, lltype.Bool), # has_finalizer - Constant(False, lltype.Bool), # is_finalizer_light - Constant(False, lltype.Bool)] # contains_weakptr + op.args = [LLConstant(type_id, llgroup.HALFWORD), + LLConstant(llmemory.sizeof(P), lltype.Signed), + LLConstant(False, lltype.Bool), # has_finalizer + LLConstant(False, lltype.Bool), # is_finalizer_light + LLConstant(False, lltype.Bool)] # contains_weakptr break else: assert 0, "oups, not found" @@ -779,7 +779,7 @@ class GenericMovingGCTests(GenericGCTests): return 0 def fix_graph_of_g(translator): from rpython.translator.translator import graphof - from rpython.flowspace.model import Constant + from rpython.rtyper.rmodel import LLConstant from rpython.rtyper.lltypesystem import rffi layoutbuilder = cls.ensure_layoutbuilder(translator) type_id = layoutbuilder.get_type_id(P) @@ -788,11 +788,11 @@ class GenericMovingGCTests(GenericGCTests): graph = graphof(translator, g) for op in graph.startblock.operations: if op.opname == 'do_malloc_fixedsize': - op.args = [Constant(type_id, llgroup.HALFWORD), - Constant(llmemory.sizeof(P), lltype.Signed), - Constant(False, lltype.Bool), # has_finalizer - Constant(False, lltype.Bool), # is_finalizer_light - Constant(False, lltype.Bool)] # contains_weakptr + op.args = [LLConstant(type_id, llgroup.HALFWORD), + LLConstant(llmemory.sizeof(P), lltype.Signed), + LLConstant(False, lltype.Bool), # has_finalizer + LLConstant(False, lltype.Bool), # is_finalizer_light + LLConstant(False, lltype.Bool)] # contains_weakptr break else: assert 0, "oups, not found" @@ -1071,7 +1071,7 @@ class TestGenerationGC(GenericMovingGCTests): def test_adr_of_nursery(self): run = self.runner("adr_of_nursery") res = run([]) - + class TestGenerationalNoFullCollectGC(GCTest): # test that nursery is doing its job and that no full collection @@ -1131,7 +1131,7 @@ class TestHybridGC(TestGenerationGC): 'large_object': 8*WORD, 'translated_to_c': False} root_stack_depth = 200 - + def define_ref_from_rawmalloced_to_regular(cls): import gc S = lltype.GcStruct('S', ('x', lltype.Signed)) @@ -1182,7 +1182,7 @@ class TestHybridGC(TestGenerationGC): run = self.runner("write_barrier_direct") res = run([]) assert res == 42 - + class TestMiniMarkGC(TestHybridGC): gcname = "minimark" GC_CAN_TEST_ID = True @@ -1199,7 +1199,7 @@ class TestMiniMarkGC(TestHybridGC): 'translated_to_c': False, } root_stack_depth = 200 - + def define_no_clean_setarrayitems(cls): # The optimization find_clean_setarrayitems() in # gctransformer/framework.py does not work with card marking. @@ -1224,7 +1224,7 @@ class TestMiniMarkGC(TestHybridGC): run = self.runner("no_clean_setarrayitems") res = run([]) assert res == 123 - + def define_nursery_hash_base(cls): class A: pass @@ -1263,19 +1263,19 @@ class TestIncrementalMiniMarkGC(TestMiniMarkGC): 'translated_to_c': False, } root_stack_depth = 200 - + def define_malloc_array_of_gcptr(self): S = lltype.GcStruct('S', ('x', lltype.Signed)) A = lltype.GcArray(lltype.Ptr(S)) def f(): lst = lltype.malloc(A, 5) - return (lst[0] == lltype.nullptr(S) + return (lst[0] == lltype.nullptr(S) and lst[1] == lltype.nullptr(S) and lst[2] == lltype.nullptr(S) and lst[3] == lltype.nullptr(S) and lst[4] == lltype.nullptr(S)) return f - + def test_malloc_array_of_gcptr(self): run = self.runner('malloc_array_of_gcptr') res = run([]) @@ -1356,7 +1356,7 @@ class TaggedPointerGCTests(GCTest): def define_gettypeid(cls): class A(object): pass - + def fn(): a = A() return rgc.get_typeid(a) diff --git a/rpython/rlib/jit_hooks.py b/rpython/rlib/jit_hooks.py index 85423e6c0970690aa604d2b4c065c09619804bcf..dae567cffdde7617885f9bbcde3823bdab47dad6 100644 --- a/rpython/rlib/jit_hooks.py +++ b/rpython/rlib/jit_hooks.py @@ -5,7 +5,7 @@ from rpython.rtyper.annlowlevel import (cast_instance_to_base_ptr, cast_base_ptr_to_instance, llstr) from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.rtyper.lltypesystem import llmemory, lltype -from rpython.flowspace.model import Constant +from rpython.rtyper.rmodel import LLConstant from rpython.rtyper import rclass @@ -152,8 +152,8 @@ def _new_hook(name, resulttype): return resulttype def specialize_call(self, hop): - c_jitdriver = Constant(hop.args_s[0].const, concretetype=lltype.Void) - c_name = Constant(name, concretetype=lltype.Void) + c_jitdriver = LLConstant(hop.args_s[0].const, lltype.Void) + c_name = LLConstant(name, lltype.Void) hop.exception_cannot_occur() args_v = [hop.inputarg(arg, arg=i + 1) for i, arg in enumerate(hop.args_r[1:])] diff --git a/rpython/rlib/nonconst.py b/rpython/rlib/nonconst.py index dedd9baf1005c48b60cb1a57d97834bd7009b45f..600f4f2da966e12a13c70db59c744af41511e592 100644 --- a/rpython/rlib/nonconst.py +++ b/rpython/rlib/nonconst.py @@ -1,9 +1,8 @@ - -""" simple non-constant constant. Ie constant which does not get annotated as constant +""" simple non-constant constant. +Ie constant which does not get annotated as constant """ from rpython.rtyper.extregistry import ExtRegistryEntry -from rpython.flowspace.model import Constant from rpython.annotator.model import not_const class NonConstant(object): @@ -39,7 +38,6 @@ class EntryNonConstant(ExtRegistryEntry): def specialize_call(self, hop): hop.exception_cannot_occur() - retval = Constant(hop.r_result.convert_const(hop.args_v[0].value)) - retval.concretetype = hop.r_result.lowleveltype - return retval - + value = hop.r_result.convert_const(hop.args_v[0].value) + lltype = hop.r_result.lowleveltype + return hop.inputconst(lltype, value) diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py index b4c2682e7f5a35bac6e6bd9dc9b7cfe3e09f6515..f8efcb96f0d02f111ce87bfda2e010b04e20635d 100644 --- a/rpython/rlib/rgc.py +++ b/rpython/rlib/rgc.py @@ -7,6 +7,7 @@ from rpython.rlib import jit from rpython.rlib.objectmodel import we_are_translated, enforceargs, specialize from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.rtyper.lltypesystem import lltype, llmemory +from rpython.rtyper.rmodel import ll_const # ____________________________________________________________ # General GC features @@ -46,7 +47,7 @@ def pin(obj): """ _pinned_objects.append(obj) return True - + class PinEntry(ExtRegistryEntry): _about_ = pin @@ -617,14 +618,13 @@ class Entry(ExtRegistryEntry): def specialize_call(self, hop): from rpython.rtyper.rclass import getclassrepr, CLASSTYPE - from rpython.flowspace.model import Constant Class = hop.args_s[0].const classdef = hop.rtyper.annotator.bookkeeper.getuniqueclassdef(Class) classrepr = getclassrepr(hop.rtyper, classdef) vtable = classrepr.getvtable() assert lltype.typeOf(vtable) == CLASSTYPE hop.exception_cannot_occur() - return Constant(vtable, concretetype=CLASSTYPE) + return ll_const(vtable) class Entry(ExtRegistryEntry): _about_ = dump_rpy_heap @@ -774,7 +774,7 @@ def clear_gcflag_extra(fromlist): pending.extend(get_rpy_referents(gcref)) all_typeids = {} - + def get_typeid(obj): raise Exception("does not work untranslated") diff --git a/rpython/rtyper/annlowlevel.py b/rpython/rtyper/annlowlevel.py index ba160b062b632dd79ef07fb55c84443d0136b5f7..87acdd80058261251ca2dc6bc147c324c6868dbc 100644 --- a/rpython/rtyper/annlowlevel.py +++ b/rpython/rtyper/annlowlevel.py @@ -11,10 +11,9 @@ from rpython.rtyper.llannotation import ( SomePtr, annotation_to_lltype, lltype_to_annotation) from rpython.rtyper.normalizecalls import perform_normalizations from rpython.rtyper.lltypesystem import lltype, llmemory -from rpython.flowspace.model import Constant from rpython.rlib.objectmodel import specialize from rpython.rtyper import extregistry -from rpython.rtyper.rmodel import warning +from rpython.rtyper.rmodel import warning, LLConstant, ll_const class KeyComp(object): @@ -162,7 +161,7 @@ class MixLevelHelperAnnotator(object): def constfunc(self, ll_function, args_s, s_result): p = self.delayedfunction(ll_function, args_s, s_result) - return Constant(p, lltype.typeOf(p)) + return ll_const(p) def graph2delayed(self, graph, FUNCTYPE=None): if FUNCTYPE is None: @@ -177,7 +176,7 @@ class MixLevelHelperAnnotator(object): def graph2const(self, graph): p = self.graph2delayed(graph) - return Constant(p, lltype.typeOf(p)) + return ll_const(p) def getdelayedrepr(self, s_value, check_never_seen=True): """Like rtyper.getrepr(), but the resulting repr will not be setup() at @@ -309,7 +308,7 @@ class PseudoHighLevelCallableEntry(extregistry.ExtRegistryEntry): vlist = hop.inputargs(*args_r) p = self.instance.llfnptr TYPE = lltype.typeOf(p) - c_func = Constant(p, TYPE) + c_func = LLConstant(p, TYPE) FUNCTYPE = TYPE.TO for r_arg, ARGTYPE in zip(args_r, FUNCTYPE.ARGS): assert r_arg.lowleveltype == ARGTYPE diff --git a/rpython/rtyper/controllerentry.py b/rpython/rtyper/controllerentry.py index f235686fee487c79bbe8e27e8b67fd3cf927c6d1..17363d4ecf5898eb390f22640e7a6dabbe9d49c4 100644 --- a/rpython/rtyper/controllerentry.py +++ b/rpython/rtyper/controllerentry.py @@ -201,7 +201,7 @@ class IsBoxEntry(ExtRegistryEntry): from rpython.rtyper.lltypesystem import lltype assert hop.s_result.is_constant() hop.exception_cannot_occur() - return hop.inputconst(lltype.Bool, hop.s_result.const) + return hop.inputconst(hop.s_result.const) # ____________________________________________________________ diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py index 96c8555c47d714b7f8bebba951a05873740fd256..71131b04b72db63995d79c028d3d9afcaff91d7f 100644 --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -1,6 +1,7 @@ from rpython.rtyper import extregistry from rpython.rtyper.extregistry import ExtRegistryEntry -from rpython.rtyper.lltypesystem.lltype import typeOf, FuncType, functionptr +from rpython.rtyper.lltypesystem.lltype import FuncType, functionptr +from rpython.rtyper.rmodel import ll_const from rpython.annotator import model as annmodel from rpython.annotator.signature import annotation @@ -204,7 +205,7 @@ class ExtFuncEntry(ExtRegistryEntry): obj = functionptr(FT, name, _external_name=self.name, _callable=fakeimpl, _safe_not_sandboxed=self.safe_not_sandboxed) - vlist = [hop.inputconst(typeOf(obj), obj)] + hop.inputargs(*args_r) + vlist = [ll_const(obj)] + hop.inputargs(*args_r) hop.exception_is_here() return hop.genop('direct_call', vlist, r_result) diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py index bae25d7c65fb9fb5a423363c2337c30c0a0397ad..352f144cd986d0299820538f7e601ff14432b2f3 100644 --- a/rpython/rtyper/lltypesystem/lloperation.py +++ b/rpython/rtyper/lltypesystem/lloperation.py @@ -3,6 +3,7 @@ The table of all LL operations. """ from rpython.rtyper.extregistry import ExtRegistryEntry +from rpython.rtyper.rmodel import ll_const class LLOp(object): @@ -118,7 +119,7 @@ class Entry(ExtRegistryEntry): def specialize_call(self, hop): from rpython.rtyper.lltypesystem import lltype hop.exception_cannot_occur() - return hop.inputconst(lltype.Void, None) + return ll_const(None) def enum_ops_without_sideeffects(raising_is_ok=False): """Enumerate operations that have no side-effects diff --git a/rpython/rtyper/lltypesystem/rstr.py b/rpython/rtyper/lltypesystem/rstr.py index 558b0a405544bef95bc60df7ae22e0aab18c5d76..0c1d762e7b01af1249b69cf213cc017bfbde1f0d 100644 --- a/rpython/rtyper/lltypesystem/rstr.py +++ b/rpython/rtyper/lltypesystem/rstr.py @@ -12,7 +12,7 @@ from rpython.rtyper.lltypesystem import ll_str, llmemory from rpython.rtyper.lltypesystem.lltype import (GcStruct, Signed, Array, Char, UniChar, Ptr, malloc, Bool, Void, GcArray, nullptr, cast_primitive, typeOf, staticAdtMethod, GcForwardReference) -from rpython.rtyper.rmodel import inputconst, Repr +from rpython.rtyper.rmodel import inputconst, Repr, ll_const from rpython.rtyper.rint import IntegerRepr from rpython.rtyper.rstr import (AbstractStringRepr, AbstractCharRepr, AbstractUniCharRepr, AbstractStringIteratorRepr, AbstractLLHelpers, @@ -1179,11 +1179,11 @@ class LLHelpers(AbstractLLHelpers): elif code == 'x': assert isinstance(r_arg, IntegerRepr) vchunk = hop.gendirectcall(ll_str.ll_int2hex, vitem, - inputconst(Bool, False)) + ll_const(False)) elif code == 'o': assert isinstance(r_arg, IntegerRepr) vchunk = hop.gendirectcall(ll_str.ll_int2oct, vitem, - inputconst(Bool, False)) + ll_const(False)) else: raise TyperError("%%%s is not RPython" % (code,)) else: diff --git a/rpython/rtyper/rint.py b/rpython/rtyper/rint.py index e666455529a40aa7448bfa6370d194bdf462f3bc..fcca88da0b23d9691257433c7288e31384f7293c 100644 --- a/rpython/rtyper/rint.py +++ b/rpython/rtyper/rint.py @@ -9,7 +9,7 @@ from rpython.rtyper.lltypesystem.lltype import (Signed, Unsigned, Bool, Float, Char, UniChar, UnsignedLongLong, SignedLongLong, build_number, Number, cast_primitive, typeOf, SignedLongLongLong) from rpython.rtyper.rfloat import FloatRepr -from rpython.rtyper.rmodel import inputconst, log +from rpython.rtyper.rmodel import inputconst, log, ll_const from rpython.tool.pairtype import pairtype class IntegerRepr(FloatRepr): @@ -158,15 +158,13 @@ class IntegerRepr(FloatRepr): from rpython.rtyper.lltypesystem.ll_str import ll_int2hex self = self.as_int varg = hop.inputarg(self, 0) - true = inputconst(Bool, True) - return hop.gendirectcall(ll_int2hex, varg, true) + return hop.gendirectcall(ll_int2hex, varg, ll_const(True)) def rtype_oct(self, hop): from rpython.rtyper.lltypesystem.ll_str import ll_int2oct self = self.as_int varg = hop.inputarg(self, 0) - true = inputconst(Bool, True) - return hop.gendirectcall(ll_int2oct, varg, true) + return hop.gendirectcall(ll_int2oct, varg, ll_const(True)) _integer_reprs = {} diff --git a/rpython/rtyper/rmodel.py b/rpython/rtyper/rmodel.py index b0d7bfb69faed75590781033d2a04b22a6a418e7..f70a36ad8e51ed6aa0ef2bd3e1b6625838af029e 100644 --- a/rpython/rtyper/rmodel.py +++ b/rpython/rtyper/rmodel.py @@ -2,7 +2,8 @@ from rpython.annotator import model as annmodel, unaryop, binaryop, description from rpython.flowspace.model import Constant from rpython.rtyper.error import TyperError, MissingRTypeOperation from rpython.rtyper.lltypesystem import lltype -from rpython.rtyper.lltypesystem.lltype import Void, Bool, LowLevelType, Ptr +from rpython.rtyper.lltypesystem.lltype import ( + Void, Bool, LowLevelType, Ptr, typeOf) from rpython.tool.pairtype import pairtype, extendabletype, pair @@ -355,8 +356,19 @@ class SimplePointerRepr(Repr): # ____________________________________________________________ +class LLConstant(Constant): + """Low-level constant""" + __slots__ = ["concretetype"] + def __init__(self, value, concretetype): + Constant.__init__(self, value) + self.concretetype = concretetype + +def ll_const(obj): + """Convert an object into a LLConstant""" + return LLConstant(obj, typeOf(obj)) + def inputconst(reqtype, value): - """Return a Constant with the given value, of the requested type, + """Return a LLConstant with the given value, of the requested type, which can be a Repr instance or a low-level type. """ if isinstance(reqtype, Repr): @@ -369,9 +381,7 @@ def inputconst(reqtype, value): if not lltype._contains_value(value): raise TyperError("inputconst(): expected a %r, got %r" % (lltype, value)) - c = Constant(value) - c.concretetype = lltype - return c + return LLConstant(value, lltype) class BrokenReprTyperError(TyperError): """ raised when trying to setup a Repr whose setup diff --git a/rpython/rtyper/rnone.py b/rpython/rtyper/rnone.py index 331ef2ebdc9be632af76125d71717153c02c78ce..2aaf1a3d04cde61312157d7ad2cf0cdec3d5015d 100644 --- a/rpython/rtyper/rnone.py +++ b/rpython/rtyper/rnone.py @@ -1,6 +1,6 @@ -from rpython.flowspace.model import Constant from rpython.annotator.model import SomeNone -from rpython.rtyper.rmodel import Repr, TyperError, inputconst +from rpython.rtyper.rmodel import ( + Repr, TyperError, inputconst, LLConstant, ll_const) from rpython.rtyper.lltypesystem.lltype import Void, Bool, Ptr, Char from rpython.rtyper.lltypesystem.llmemory import Address from rpython.rtyper.rpbc import SmallFunctionSetPBCRepr @@ -11,7 +11,7 @@ class NoneRepr(Repr): lowleveltype = Void def rtype_bool(self, hop): - return Constant(False, Bool) + return LLConstant(False, Bool) def none_call(self, hop): raise TyperError("attempt to call constant None") @@ -44,7 +44,7 @@ def ll_none_hash(_): class __extend__(pairtype(Repr, NoneRepr)): def convert_from_to((r_from, _), v, llops): - return inputconst(Void, None) + return ll_const(None) def rtype_is_((robj1, rnone2), hop): if hop.s_result.is_constant(): @@ -70,13 +70,13 @@ def rtype_is_None(robj1, rnone2, hop, pos=0): cnull = hop.inputconst(Address, robj1.null_instance()) return hop.genop('adr_eq', [v1, cnull], resulttype=Bool) elif robj1 == none_repr: - return hop.inputconst(Bool, True) + return ll_const(True) elif isinstance(robj1, SmallFunctionSetPBCRepr): if robj1.s_pbc.can_be_None: v1 = hop.inputarg(robj1, pos) return hop.genop('char_eq', [v1, inputconst(Char, '\000')], resulttype=Bool) else: - return inputconst(Bool, False) + return ll_const(False) else: raise TyperError('rtype_is_None of %r' % (robj1)) diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py index 46098a3fc884b8e9b9d4b1e45cd24f90e9220b1c..95fbe47863ddfbe90671a36496e35c5c11a49a49 100644 --- a/rpython/rtyper/rpbc.py +++ b/rpython/rtyper/rpbc.py @@ -16,8 +16,9 @@ from rpython.rtyper.lltypesystem import llmemory from rpython.rtyper.lltypesystem.lltype import ( typeOf, Void, ForwardReference, Struct, Bool, Char, Ptr, malloc, nullptr, Array, Signed, cast_pointer, getfunctionptr) -from rpython.rtyper.rmodel import (Repr, inputconst, CanBeNull, mangle, - warning, impossible_repr) +from rpython.rtyper.rmodel import ( + Repr, inputconst, CanBeNull, mangle, warning, impossible_repr, + LLConstant, ll_const) from rpython.tool.pairtype import pair, pairtype from rpython.translator.unsimplify import varoftype @@ -332,7 +333,7 @@ class FunctionRepr(FunctionReprBase): row_of_one_graph = self.callfamily.calltables[shape][index] graph = row_of_one_graph[funcdesc] llfn = self.rtyper.getcallable(graph) - return inputconst(typeOf(llfn), llfn) + return ll_const(llfn) def get_unique_llfn(self): # try to build a unique low-level function. Avoid to use @@ -356,7 +357,7 @@ class FunctionRepr(FunctionReprBase): if graphs != [graph] * len(graphs): raise TyperError("cannot pass a specialized function here") llfn = self.rtyper.getcallable(graph) - return inputconst(typeOf(llfn), llfn) + return ll_const(llfn) def get_concrete_llfn(self, s_pbc, args_s, op): bk = self.rtyper.annotator.bookkeeper @@ -365,8 +366,7 @@ class FunctionRepr(FunctionReprBase): with bk.at_position(None): graph = funcdesc.get_graph(args, op) llfn = self.rtyper.getcallable(graph) - return inputconst(typeOf(llfn), llfn) - + return ll_const(llfn) class __extend__(pairtype(FunctionRepr, FunctionRepr)): @@ -379,7 +379,7 @@ class __extend__(pairtype(FunctionRepr, FunctionsPBCRepr)): class __extend__(pairtype(FunctionsPBCRepr, FunctionRepr)): def convert_from_to((r_fpbc1, r_fpbc2), v, llops): - return inputconst(Void, None) + return ll_const(None) class __extend__(pairtype(FunctionsPBCRepr, FunctionsPBCRepr)): def convert_from_to((r_fpbc1, r_fpbc2), v, llops): @@ -421,7 +421,7 @@ class SmallFunctionSetPBCRepr(FunctionReprBase): pointer_table[i] = self.pointer_repr.convert_desc(desc) else: pointer_table[i] = self.pointer_repr.convert_const(None) - self.c_pointer_table = inputconst(Ptr(POINTER_TABLE), pointer_table) + self.c_pointer_table = ll_const(pointer_table) def convert_desc(self, funcdesc): return chr(self.descriptions.index(funcdesc)) @@ -441,7 +441,7 @@ class SmallFunctionSetPBCRepr(FunctionReprBase): graph = self.make_dispatcher(shape, index, argtypes, resulttype) self.rtyper.annotator.translator.graphs.append(graph) ll_ret = getfunctionptr(graph) - c_ret = self._dispatch_cache[key] = inputconst(typeOf(ll_ret), ll_ret) + c_ret = self._dispatch_cache[key] = ll_const(ll_ret) return c_ret def make_dispatcher(self, shape, index, argtypes, resulttype): @@ -460,7 +460,7 @@ class SmallFunctionSetPBCRepr(FunctionReprBase): args_v = [varoftype(t) for t in argtypes] b = Block(args_v) llfn = self.rtyper.getcallable(row_of_graphs[desc]) - v_fn = inputconst(typeOf(llfn), llfn) + v_fn = ll_const(llfn) v_result = varoftype(resulttype) b.operations.append( SpaceOperation("direct_call", [v_fn] + args_v, v_result)) @@ -491,7 +491,7 @@ class SmallFunctionSetPBCRepr(FunctionReprBase): def rtype_bool(self, hop): if not self.s_pbc.can_be_None: - return inputconst(Bool, True) + return ll_const(True) else: v1, = hop.inputargs(self) return hop.genop('char_ne', [v1, inputconst(Char, '\000')], @@ -500,7 +500,7 @@ class SmallFunctionSetPBCRepr(FunctionReprBase): class __extend__(pairtype(SmallFunctionSetPBCRepr, FunctionRepr)): def convert_from_to((r_set, r_ptr), v, llops): - return inputconst(Void, None) + return ll_const(None) class __extend__(pairtype(SmallFunctionSetPBCRepr, FunctionsPBCRepr)): def convert_from_to((r_set, r_ptr), v, llops): @@ -779,7 +779,7 @@ class __extend__(pairtype(SingleFrozenPBCRepr, MultipleFrozenPBCRepr)): if access is r_pbc2.access_set: value = r_pbc2.convert_desc(frozendesc1) lltype = r_pbc2.lowleveltype - return Constant(value, lltype) + return LLConstant(value, lltype) return NotImplemented class __extend__(pairtype(MultipleFrozenPBCReprBase, diff --git a/rpython/rtyper/rptr.py b/rpython/rtyper/rptr.py index b0b5270cef19b38565b5e9b326d37b49b577c352..9e50425e184c1c1ee95e7cc688f9a8a1cd71dadf 100644 --- a/rpython/rtyper/rptr.py +++ b/rpython/rtyper/rptr.py @@ -4,7 +4,7 @@ from rpython.flowspace import model as flowmodel from rpython.rlib.rarithmetic import r_uint from rpython.rtyper.error import TyperError from rpython.rtyper.lltypesystem import lltype -from rpython.rtyper.rmodel import Repr +from rpython.rtyper.rmodel import Repr, inputconst, ll_const from rpython.rtyper.rint import IntegerRepr from rpython.tool.pairtype import pairtype @@ -48,7 +48,7 @@ class PtrRepr(Repr): pass else: assert hop.s_result.is_constant() - return hop.inputconst(hop.r_result, hop.s_result.const) + return inputconst(hop.r_result, hop.s_result.const) assert attr in self.lowleveltype.TO._flds # check that the field exists FIELD_TYPE = getattr(self.lowleveltype.TO, attr) if isinstance(FIELD_TYPE, lltype.ContainerType): @@ -75,7 +75,7 @@ class PtrRepr(Repr): def rtype_len(self, hop): ARRAY = hop.args_r[0].lowleveltype.TO if isinstance(ARRAY, lltype.FixedSizeArray): - return hop.inputconst(lltype.Signed, ARRAY.length) + return inputconst(lltype.Signed, ARRAY.length) else: vlist = hop.inputargs(self) return hop.genop('getarraysize', vlist, @@ -100,7 +100,7 @@ class PtrRepr(Repr): opname = 'direct_call' else: opname = 'indirect_call' - vlist.append(hop.inputconst(lltype.Void, None)) + vlist.append(ll_const(None)) hop.exception_is_here() return hop.genop(opname, vlist, resulttype = self.lowleveltype.TO.RESULT) @@ -123,15 +123,14 @@ class __extend__(pairtype(PtrRepr, IntegerRepr)): if isinstance(hop.r_result, InteriorPtrRepr): v_array, v_index = hop.inputargs(r_ptr, lltype.Signed) INTERIOR_PTR_TYPE = r_ptr.lowleveltype._interior_ptr_type_with_index(ITEM_TYPE) - cflags = hop.inputconst(lltype.Void, {'flavor': 'gc'}) - args = [flowmodel.Constant(INTERIOR_PTR_TYPE, lltype.Void), - cflags] + cflags = inputconst(lltype.Void, {'flavor': 'gc'}) + args = [inputconst(lltype.Void, INTERIOR_PTR_TYPE), cflags] v_interior_ptr = hop.genop('malloc', args, resulttype=lltype.Ptr(INTERIOR_PTR_TYPE)) hop.genop('setfield', - [v_interior_ptr, flowmodel.Constant('ptr', lltype.Void), v_array]) + [v_interior_ptr, inputconst(lltype.Void, 'ptr'), v_array]) hop.genop('setfield', - [v_interior_ptr, flowmodel.Constant('index', lltype.Void), v_index]) + [v_interior_ptr, inputconst(lltype.Void, 'index'), v_index]) return v_interior_ptr else: newopname = 'getarraysubstruct' @@ -220,7 +219,7 @@ class InteriorPtrRepr(Repr): self.v_offsets.append(None) else: assert isinstance(offset, str) - self.v_offsets.append(flowmodel.Constant(offset, lltype.Void)) + self.v_offsets.append(inputconst(lltype.Void, offset)) self.parentptrtype = lltype.Ptr(ptrtype.PARENTTYPE) self.resulttype = lltype.Ptr(ptrtype.TO) assert numitemoffsets <= 1 @@ -237,7 +236,7 @@ class InteriorPtrRepr(Repr): name = nameiter.next() vlist.append( hop.genop('getfield', - [v_self, flowmodel.Constant(name, lltype.Void)], + [v_self, inputconst(lltype.Void, name)], resulttype=INTERIOR_TYPE._flds[name])) else: vlist.append(v_self) @@ -246,7 +245,7 @@ class InteriorPtrRepr(Repr): name = nameiter.next() vlist.append( hop.genop('getfield', - [v_self, flowmodel.Constant(name, lltype.Void)], + [v_self, inputconst(lltype.Void, name)], resulttype=INTERIOR_TYPE._flds[name])) else: vlist.append(v_offset) @@ -296,14 +295,14 @@ class __extend__(pairtype(InteriorPtrRepr, IntegerRepr)): if isinstance(ITEM_TYPE, lltype.ContainerType): v_array, v_index = hop.inputargs(r_ptr, lltype.Signed) INTERIOR_PTR_TYPE = r_ptr.lowleveltype._interior_ptr_type_with_index(ITEM_TYPE) - cflags = hop.inputconst(lltype.Void, {'flavor': 'gc'}) - args = [flowmodel.Constant(INTERIOR_PTR_TYPE, lltype.Void), cflags] + cflags = inputconst(lltype.Void, {'flavor': 'gc'}) + args = [inputconst(lltype.Void, INTERIOR_PTR_TYPE), cflags] v_interior_ptr = hop.genop('malloc', args, resulttype=lltype.Ptr(INTERIOR_PTR_TYPE)) hop.genop('setfield', - [v_interior_ptr, flowmodel.Constant('ptr', lltype.Void), v_array]) + [v_interior_ptr, inputconst(lltype.Void, 'ptr'), v_array]) hop.genop('setfield', - [v_interior_ptr, flowmodel.Constant('index', lltype.Void), v_index]) + [v_interior_ptr, inputconst(lltype.Void, 'index'), v_index]) return v_interior_ptr else: v_self, v_index = hop.inputargs(r_ptr, lltype.Signed) diff --git a/rpython/rtyper/rrange.py b/rpython/rtyper/rrange.py index 2bcf0c982de2319f18b8111cb9f782495318e0a5..8a1fe14346c184fe008dcc6bff7e2ece06110b0c 100644 --- a/rpython/rtyper/rrange.py +++ b/rpython/rtyper/rrange.py @@ -2,7 +2,7 @@ from rpython.flowspace.model import Constant from rpython.rtyper.error import TyperError from rpython.rtyper.lltypesystem.lltype import Signed, Void, Ptr from rpython.rtyper.rlist import dum_nocheck, dum_checkidx -from rpython.rtyper.rmodel import Repr, IteratorRepr +from rpython.rtyper.rmodel import Repr, IteratorRepr, ll_const from rpython.rtyper.rint import IntegerRepr from rpython.tool.pairtype import pairtype @@ -94,9 +94,9 @@ def ll_rangeitem(func, l, index, step): # Irregular operations. def rtype_builtin_range(hop): - vstep = hop.inputconst(Signed, 1) + vstep = ll_const(1) if hop.nb_args == 1: - vstart = hop.inputconst(Signed, 0) + vstart = ll_const(0) vstop, = hop.inputargs(Signed) elif hop.nb_args == 2: vstart, vstop = hop.inputargs(Signed, Signed) diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py index 4bff53745469a2f59f41446d5ff2426d1708b95e..75a0c2dea63c8e450daf8e6f277d41046cd08502 100644 --- a/rpython/rtyper/rtyper.py +++ b/rpython/rtyper/rtyper.py @@ -24,7 +24,8 @@ from rpython.rtyper.exceptiondata import ExceptionData from rpython.rtyper.lltypesystem.lltype import (Signed, Void, LowLevelType, Ptr, ContainerType, FuncType, functionptr, typeOf, RuntimeTypeInfo, attachRuntimeTypeInfo, Primitive, getfunctionptr) -from rpython.rtyper.rmodel import Repr, inputconst, BrokenReprTyperError +from rpython.rtyper.rmodel import ( + Repr, inputconst, BrokenReprTyperError, ll_const) from rpython.rtyper import rclass from rpython.rtyper.rclass import RootClassRepr from rpython.tool.pairtype import pair @@ -871,7 +872,7 @@ class LowLevelOpList(list): # build the 'direct_call' operation f = self.rtyper.getcallable(graph) - c = inputconst(typeOf(f), f) + c = ll_const(f) fobj = f._obj return self.genop('direct_call', [c]+newargs_v, resulttype = typeOf(fobj).RESULT) @@ -882,14 +883,14 @@ class LowLevelOpList(list): argtypes = [v.concretetype for v in args_v] FUNCTYPE = FuncType(argtypes, resulttype or Void) f = functionptr(FUNCTYPE, fnname, **flags) - cf = inputconst(typeOf(f), f) + cf = ll_const(f) return self.genop('direct_call', [cf]+list(args_v), resulttype) def gencapicall(self, cfnname, args_v, resulttype=None, **flags): return self.genexternalcall(cfnname, args_v, resulttype=resulttype, external="CPython", **flags) def genconst(self, ll_value): - return inputconst(typeOf(ll_value), ll_value) + return ll_const(ll_value) def genvoidconst(self, placeholder): return inputconst(Void, placeholder) diff --git a/rpython/rtyper/rvirtualizable.py b/rpython/rtyper/rvirtualizable.py index 426d54a553203546ee5f312daa36243cb0830dab..9bdcc6ea9319d8732edc3816d1f243d695150a0c 100644 --- a/rpython/rtyper/rvirtualizable.py +++ b/rpython/rtyper/rvirtualizable.py @@ -1,4 +1,4 @@ -from rpython.rtyper.rmodel import inputconst, log +from rpython.rtyper.rmodel import inputconst, log, ll_const from rpython.rtyper.lltypesystem import lltype, llmemory from rpython.rtyper.rclass import (FieldListAccessor, InstanceRepr) @@ -55,7 +55,7 @@ class VirtualizableInstanceRepr(InstanceRepr): def replace_force_virtualizable_with_call(graphs, VTYPEPTR, funcptr): # funcptr should be a function pointer with a VTYPEPTR argument - c_funcptr = inputconst(lltype.typeOf(funcptr), funcptr) + c_funcptr = ll_const(funcptr) count = 0 for graph in graphs: for block in graph.iterblocks(): diff --git a/rpython/translator/backendopt/constfold.py b/rpython/translator/backendopt/constfold.py index 5efa7033067a4fa460bcc0623a4fc48219d8aa29..91dcf60528094b42b96f8f2c0c5d08b4554cba8f 100644 --- a/rpython/translator/backendopt/constfold.py +++ b/rpython/translator/backendopt/constfold.py @@ -1,5 +1,6 @@ -from rpython.flowspace.model import (Constant, Variable, SpaceOperation, +from rpython.flowspace.model import (Variable, SpaceOperation, mkentrymap) +from rpython.rtyper.rmodel import LLConstant, ll_const from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.lloperation import llop from rpython.translator.unsimplify import insert_empty_block, split_block @@ -13,7 +14,7 @@ def fold_op_list(operations, constants, exit_early=False, exc_catch=False): vargs = [] args = [] for v in spaceop.args: - if isinstance(v, Constant): + if isinstance(v, LLConstant): args.append(v.value) elif v in constants: v = constants[v] @@ -41,7 +42,7 @@ def fold_op_list(operations, constants, exit_early=False, exc_catch=False): # success in folding this space operation if spaceop.opname in fixup_op_result: result = fixup_op_result[spaceop.opname](result) - constants[spaceop.result] = Constant(result, RESTYPE) + constants[spaceop.result] = LLConstant(result, RESTYPE) folded_count += 1 continue # failed to fold an operation, exit early if requested @@ -50,7 +51,7 @@ def fold_op_list(operations, constants, exit_early=False, exc_catch=False): else: if vargsmodif: if (spaceop.opname == 'indirect_call' - and isinstance(vargs[0], Constant)): + and isinstance(vargs[0], LLConstant)): spaceop = SpaceOperation('direct_call', vargs[:-1], spaceop.result) else: @@ -216,7 +217,7 @@ def constant_diffuse(graph): if isinstance(vexit, Variable): for link in block.exits: if vexit in link.args and link.exitcase != 'default': - remap = {vexit: Constant(link.llexitcase, + remap = {vexit: LLConstant(link.llexitcase, vexit.concretetype)} link.args = [remap.get(v, v) for v in link.args] count += 1 @@ -233,7 +234,7 @@ def constant_diffuse(graph): rest = links[1:] diffuse = [] for i, c in enumerate(firstlink.args): - if not isinstance(c, Constant): + if not isinstance(c, LLConstant): continue for lnk in rest: if lnk.args[i] != c: @@ -268,7 +269,7 @@ def constant_fold_graph(graph): for link in list(graph.iterlinks()): constants = {} for v1, v2 in zip(link.args, link.target.inputargs): - if isinstance(v1, Constant): + if isinstance(v1, LLConstant): constants[v2] = v1 if constants: prepare_constant_fold_link(link, constants, splitblocks) diff --git a/rpython/translator/backendopt/inline.py b/rpython/translator/backendopt/inline.py index e7a97a876ecfd78e70966464a9e7e9bced312d59..152a015698f8fb56d95fc400a816f43182cf80d7 100644 --- a/rpython/translator/backendopt/inline.py +++ b/rpython/translator/backendopt/inline.py @@ -2,6 +2,7 @@ import sys from rpython.flowspace.model import (Variable, Constant, Block, Link, SpaceOperation, FunctionGraph, mkentrymap) +from rpython.rtyper.rmodel import LLConstant, ll_const from rpython.rtyper.lltypesystem.lltype import Bool, Signed, typeOf, Void, Ptr, normalizeptr from rpython.tool.algo import sparsemat from rpython.translator.backendopt import removenoops @@ -355,9 +356,8 @@ class BaseInliner(object): def generic_exception_matching(self, afterblock, copiedexceptblock): #XXXXX don't look: insert blocks that do exception matching #for the cases where direct matching did not work - exc_match = Constant( - self.translator.rtyper.exceptiondata.fn_exception_match) - exc_match.concretetype = typeOf(exc_match.value) + ll_exc_match = self.translator.rtyper.exceptiondata.fn_exception_match + exc_match = ll_const(ll_exc_match) blocks = [] for i, link in enumerate(afterblock.exits[1:]): etype = copiedexceptblock.inputargs[0].copy() @@ -366,8 +366,7 @@ class BaseInliner(object): block = Block([etype, evalue] + passon_vars) res = Variable() res.concretetype = Bool - cexitcase = Constant(link.llexitcase) - cexitcase.concretetype = typeOf(cexitcase.value) + cexitcase = ll_const(link.llexitcase) args = [exc_match, etype, cexitcase] block.operations.append(SpaceOperation("direct_call", args, res)) block.exitswitch = res @@ -597,8 +596,8 @@ def instrument_inline_candidates(graphs, threshold): '_dont_inline_', False): continue if candidate(graph): - tag = Constant('inline', Void) - label = Constant(n, Signed) + tag = LLConstant('inline', Void) + label = LLConstant(n, Signed) dummy = Variable() dummy.concretetype = Void count = SpaceOperation('instrument_count', diff --git a/rpython/translator/backendopt/malloc.py b/rpython/translator/backendopt/malloc.py index bfbdd4dc53f8f837f7cd977873cd732075236690..a2b2f1cd698a71ca777f2b0081491ba8b70d313f 100644 --- a/rpython/translator/backendopt/malloc.py +++ b/rpython/translator/backendopt/malloc.py @@ -1,6 +1,7 @@ from rpython.flowspace.model import Variable, Constant, SpaceOperation from rpython.tool.algo.unionfind import UnionFind from rpython.rtyper.lltypesystem import lltype +from rpython.rtyper.rmodel import LLConstant, ll_const from rpython.translator import simplify from rpython.translator.backendopt import removenoops from rpython.translator.backendopt.support import log @@ -88,7 +89,7 @@ class BaseMallocRemover(object): for key in self.needsubmallocs: v = Variable() v.concretetype = self.newvarstype[key] - c = Constant(v.concretetype.TO, lltype.Void) + c = LLConstant(v.concretetype.TO, lltype.Void) if c.value == op.args[0].value: progress = False # replacing a malloc with # the same malloc! @@ -348,10 +349,8 @@ class LLTypeMallocRemover(BaseMallocRemover): return False def recreate_malloc(self, c, v): - return SpaceOperation(self.MALLOC_OP, [c, - Constant({'flavor': 'gc'}, - lltype.Void)], - v) + return SpaceOperation( + self.MALLOC_OP, [c, LLConstant({'flavor': 'gc'}, lltype.Void)], v) def get_STRUCT(self, TYPE): STRUCT = TYPE.TO @@ -436,8 +435,7 @@ class LLTypeMallocRemover(BaseMallocRemover): ('data', FIELDTYPE))) elif not isinstance(FIELDTYPE, lltype.ContainerType): example = FIELDTYPE._defl() - constant = Constant(example) - constant.concretetype = FIELDTYPE + constant = LLConstant(example, FIELDTYPE) self.flatconstants[key] = constant self.flatnames.append(key) self.newvarstype[key] = FIELDTYPE @@ -458,7 +456,7 @@ class LLTypeMallocRemover(BaseMallocRemover): from rpython.rtyper.lltypesystem.rstr import string_repr msg = "unreachable operation (from malloc.py)" ll_msg = string_repr.convert_const(msg) - c_msg = Constant(ll_msg, lltype.typeOf(ll_msg)) + c_msg = ll_const(ll_msg) return SpaceOperation("debug_fatalerror", [c_msg], v_result) def flowin_op(self, op, vars, newvarsmap): @@ -469,7 +467,7 @@ class LLTypeMallocRemover(BaseMallocRemover): if key not in newvarsmap: newop = self.handle_unreachable(op.result) elif key in self.accessed_substructs: - c_name = Constant('data', lltype.Void) + c_name = LLConstant('data', lltype.Void) newop = SpaceOperation("getfield", [newvarsmap[key], c_name], op.result) @@ -486,7 +484,7 @@ class LLTypeMallocRemover(BaseMallocRemover): newop = self.handle_unreachable(op.result) self.newops.append(newop) elif key in self.accessed_substructs: - c_name = Constant('data', lltype.Void) + c_name = LLConstant('data', lltype.Void) newop = SpaceOperation("setfield", [newvarsmap[key], c_name, op.args[2]], op.result) @@ -522,7 +520,7 @@ class LLTypeMallocRemover(BaseMallocRemover): except KeyError: newop = self.handle_unreachable(op.result) else: - cname = Constant('data', lltype.Void) + cname = LLConstant('data', lltype.Void) newop = SpaceOperation(opname, [v, cname], op.result) @@ -530,7 +528,7 @@ class LLTypeMallocRemover(BaseMallocRemover): elif op.opname in ("ptr_iszero", "ptr_nonzero"): # we know the pointer is not NULL if it comes from # a successful malloc - c = Constant(op.opname == "ptr_nonzero", lltype.Bool) + c = LLConstant(op.opname == "ptr_nonzero", lltype.Bool) newop = SpaceOperation('same_as', [c], op.result) self.newops.append(newop) else: diff --git a/rpython/translator/backendopt/mallocv.py b/rpython/translator/backendopt/mallocv.py index dda732d7003724d9765319763d523328c24c9f54..c80ccc507e8c37b1518df9e0ea5df9347dccc901 100644 --- a/rpython/translator/backendopt/mallocv.py +++ b/rpython/translator/backendopt/mallocv.py @@ -7,6 +7,7 @@ from rpython.translator.unsimplify import varoftype from rpython.rtyper.lltypesystem.lltype import getfunctionptr from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.lloperation import llop +from rpython.rtyper.rmodel import LLConstant, ll_const def virtualize_mallocs(translator, graphs, verbose=False): @@ -576,16 +577,15 @@ class GraphBuilder(object): v_incoming_value = varoftype(TVAL) block = Block([v_ignored_type, v_incoming_value]) # - c_EXCTYPE = Constant(typedesc.MALLOCTYPE, lltype.Void) + c_EXCTYPE = LLConstant(typedesc.MALLOCTYPE, lltype.Void) v = varoftype(lltype.Ptr(typedesc.MALLOCTYPE)) - c_flavor = Constant({'flavor': 'gc'}, lltype.Void) + c_flavor = LLConstant({'flavor': 'gc'}, lltype.Void) op = SpaceOperation('malloc', [c_EXCTYPE, c_flavor], v) block.operations.append(op) # for name, FIELDTYPE in typedesc.names_and_types: EXACTPTR = lltype.Ptr(typedesc.name2subtype[name]) - c_name = Constant(name) - c_name.concretetype = lltype.Void + c_name = LLConstant(name, lltype.Void) # v_in = varoftype(EXACTPTR) op = SpaceOperation('cast_pointer', [v_incoming_value], v_in) @@ -608,7 +608,7 @@ class GraphBuilder(object): block.operations.append(op) # exc_type = self.mallocv.EXCTYPE_to_vtable[typedesc.MALLOCTYPE] - c_exc_type = Constant(exc_type, TEXC) + c_exc_type = LLConstant(exc_type, TEXC) block.closeblock(Link([c_exc_type, v_exc_value], exceptblock)) return block @@ -774,8 +774,7 @@ class BlockSpecializer(object): self.setnode(v_result, newrtnode) if v_result.concretetype is not lltype.Void: assert v_result.concretetype == lltype.typeOf(value) - c_value = Constant(value) - c_value.concretetype = v_result.concretetype + c_value = LLConstant(value, v_result.concretetype) self.renamings[newrtnode] = c_value def handle_default(self, op): @@ -793,7 +792,7 @@ class BlockSpecializer(object): from rpython.rtyper.lltypesystem.rstr import string_repr msg = 'unreachable: %s' % (op,) ll_msg = string_repr.convert_const(msg) - c_msg = Constant(ll_msg, lltype.typeOf(ll_msg)) + c_msg = ll_const(ll_msg) newresult = self.make_rt_result(op.result) return [SpaceOperation('debug_fatalerror', [c_msg], newresult)] @@ -889,8 +888,7 @@ class BlockSpecializer(object): for name, FIELDTYPE in typedesc.names_and_types: fieldnode = RuntimeSpecNode(name, FIELDTYPE) virtualnode.fields.append(fieldnode) - c = Constant(FIELDTYPE._defl()) - c.concretetype = FIELDTYPE + c = LLConstant(FIELDTYPE._defl(), FIELDTYPE) self.renamings[fieldnode] = c self.v_expand_malloc = None # done return [] @@ -939,8 +937,7 @@ class BlockSpecializer(object): def handle_residual_call(self, op, newgraph, newnodes): fspecptr = getfunctionptr(newgraph) - newargs = [Constant(fspecptr, - concretetype=lltype.typeOf(fspecptr))] + newargs = [ll_const(fspecptr)] newargs += self.expand_nodes(newnodes) newresult = self.make_rt_result(op.result) newop = SpaceOperation('direct_call', newargs, newresult) diff --git a/rpython/translator/backendopt/support.py b/rpython/translator/backendopt/support.py index 0f9b0202b16365908909fa077eaced77cb6c20bf..87636de58282acbba0f15990f481fc32b5be38f9 100644 --- a/rpython/translator/backendopt/support.py +++ b/rpython/translator/backendopt/support.py @@ -1,7 +1,7 @@ import py from rpython.rtyper.lltypesystem import lltype -from rpython.rtyper.rmodel import inputconst +from rpython.rtyper.rmodel import ll_const from rpython.tool.ansi_print import ansi_log from rpython.translator.simplify import get_graph @@ -22,10 +22,11 @@ def all_operations(graphs): yield op def annotate(translator, func, result, args): - args = [arg.concretetype for arg in args] - graph = translator.rtyper.annotate_helper(func, args) - fptr = lltype.functionptr(lltype.FuncType(args, result.concretetype), func.func_name, graph=graph) - c = inputconst(lltype.typeOf(fptr), fptr) + args = [arg.concretetype for arg in args] + graph = translator.rtyper.annotate_helper(func, args) + fptr = lltype.functionptr(lltype.FuncType(args, result.concretetype), + func.func_name, graph=graph) + c = ll_const(fptr) return c def var_needsgc(var): diff --git a/rpython/translator/backendopt/test/test_constfold.py b/rpython/translator/backendopt/test/test_constfold.py index da41a1c20d5a705efbf9cd4e08026e79c8a883b3..5829ca2659561b764548384893393003a70f54f6 100644 --- a/rpython/translator/backendopt/test/test_constfold.py +++ b/rpython/translator/backendopt/test/test_constfold.py @@ -1,9 +1,9 @@ -import py -from rpython.flowspace.model import checkgraph, Constant, summary +from rpython.flowspace.model import checkgraph, summary from rpython.translator.translator import TranslationContext, graphof from rpython.rtyper.llinterp import LLInterpreter from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.lloperation import llop +from rpython.rtyper.rmodel import LLConstant from rpython.rtyper import rclass from rpython.rlib import objectmodel from rpython.translator.backendopt.constfold import constant_fold_graph @@ -99,7 +99,7 @@ def test_multiple_incoming_links(): constant_fold_graph(graph) assert summary(graph) == {'int_mul': 1, 'int_eq': 3, 'int_add': 2} for link in graph.iterlinks(): - if Constant(139) in link.args: + if LLConstant(139, lltype.Signed) in link.args: break else: raise AssertionError("139 not found in the graph as a constant") @@ -316,7 +316,7 @@ def test_merge_if_blocks_bug(): elif n == 4: return -123 elif n == 5: return 12973 else: return n - + graph, t = get_graph(fn, [int]) from rpython.translator.backendopt.removenoops import remove_same_as from rpython.translator.backendopt import merge_if_blocks @@ -335,7 +335,7 @@ def test_merge_if_blocks_bug_2(): elif n == 4: return -123 elif n == 5: return 12973 else: return n - + graph, t = get_graph(fn, []) from rpython.translator.backendopt.removenoops import remove_same_as from rpython.translator.backendopt import merge_if_blocks diff --git a/rpython/translator/c/test/test_database.py b/rpython/translator/c/test/test_database.py index 18ebb408cd3e5f0b4b11cec5427c364c0292fe72..efe64e68269703d2bf6e79d334c94b0f37a1d201 100644 --- a/rpython/translator/c/test/test_database.py +++ b/rpython/translator/c/test/test_database.py @@ -1,9 +1,9 @@ -import sys from rpython.rtyper.lltypesystem.lltype import * from rpython.translator.translator import TranslationContext from rpython.translator.c.database import LowLevelDatabase -from rpython.flowspace.model import Constant, Variable, SpaceOperation -from rpython.flowspace.model import Block, Link, FunctionGraph +from rpython.flowspace.model import ( + Variable, SpaceOperation, Block, Link, FunctionGraph) +from rpython.rtyper.rmodel import ll_const from rpython.rtyper.lltypesystem.lltype import getfunctionptr from rpython.rtyper.lltypesystem.rffi import VOIDP, INT_real, INT, CArrayPtr @@ -127,8 +127,7 @@ def test_func_simple(): x.concretetype = Signed result = Variable("result") result.concretetype = Signed - one = Constant(1) - one.concretetype = Signed + one = ll_const(1) op = SpaceOperation("int_add", [x, one], result) block = Block([x]) graph = FunctionGraph("f", block) diff --git a/rpython/translator/exceptiontransform.py b/rpython/translator/exceptiontransform.py index c57c1002501e0649303adfb855904fa819177c0d..c550178cd540cd556b48d714cec8285e2d122a21 100644 --- a/rpython/translator/exceptiontransform.py +++ b/rpython/translator/exceptiontransform.py @@ -2,13 +2,13 @@ from rpython.translator.simplify import join_blocks, cleanup_graph from rpython.translator.unsimplify import varoftype from rpython.translator.unsimplify import insert_empty_block, split_block from rpython.translator.backendopt import canraise, inline -from rpython.flowspace.model import Block, Constant, Variable, Link, \ - SpaceOperation, FunctionGraph, mkentrymap +from rpython.flowspace.model import ( + Block, Variable, Link, SpaceOperation, FunctionGraph, mkentrymap) from rpython.rtyper.lltypesystem import lltype, llmemory, rffi from rpython.rtyper.lltypesystem import lloperation from rpython.rtyper.rclass import ll_inst_type from rpython.rtyper import rtyper -from rpython.rtyper.rmodel import inputconst +from rpython.rtyper.rmodel import inputconst, LLConstant, ll_const from rpython.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong from rpython.rlib.rarithmetic import r_singlefloat, r_longfloat from rpython.rlib.debug import ll_assert @@ -41,10 +41,7 @@ def error_value(T): assert 0, "not implemented yet" def error_constant(T): - return Constant(error_value(T), T) - -def constant_value(llvalue): - return Constant(llvalue, lltype.typeOf(llvalue)) + return LLConstant(error_value(T), T) class ExceptionTransformer(object): @@ -62,9 +59,9 @@ class ExceptionTransformer(object): (n_i_error_ll_exc_type, n_i_error_ll_exc) = self.get_builtin_exception(NotImplementedError) - self.c_assertion_error_ll_exc_type = constant_value( + self.c_assertion_error_ll_exc_type = ll_const( assertion_error_ll_exc_type) - self.c_n_i_error_ll_exc_type = constant_value(n_i_error_ll_exc_type) + self.c_n_i_error_ll_exc_type = ll_const(n_i_error_ll_exc_type) def rpyexc_occured(): exc_type = exc_data.exc_type @@ -460,16 +457,16 @@ class ExceptionTransformer(object): null_value = lltype.nullptr(self.lltype_of_exception_value.TO) self.exc_data_ptr = exc_data - self.cexcdata = Constant(exc_data, lltype.Ptr(self.EXCDATA)) - self.c_null_etype = Constant(null_type, self.lltype_of_exception_type) - self.c_null_evalue = Constant(null_value, self.lltype_of_exception_value) + self.cexcdata = LLConstant(exc_data, lltype.Ptr(self.EXCDATA)) + self.c_null_etype = LLConstant(null_type, self.lltype_of_exception_type) + self.c_null_evalue = LLConstant(null_value, self.lltype_of_exception_value) return exc_data, null_type, null_value def constant_func(self, name, inputtypes, rettype, graph, **kwds): FUNC_TYPE = lltype.FuncType(inputtypes, rettype) fn_ptr = lltype.functionptr(FUNC_TYPE, name, graph=graph, **kwds) - return Constant(fn_ptr, lltype.Ptr(FUNC_TYPE)) + return ll_const(fn_ptr) def gen_getfield(self, name, llops): c_name = inputconst(lltype.Void, name) diff --git a/rpython/translator/test/test_simplify.py b/rpython/translator/test/test_simplify.py index cf708592e72c27622683bd42b3b84b6edea325b0..9d56405ce8a1b5471df88ad7758d73bfc25049bd 100644 --- a/rpython/translator/test/test_simplify.py +++ b/rpython/translator/test/test_simplify.py @@ -3,6 +3,7 @@ from rpython.translator.translator import TranslationContext, graphof from rpython.translator.backendopt.all import backend_optimizations from rpython.translator.simplify import (get_graph, transform_dead_op_vars) from rpython.flowspace.model import Block, Constant, summary +from rpython.rtyper.rmodel import ll_const from rpython.conftest import option def translate(func, argtypes, backend_optimize=True): @@ -204,7 +205,6 @@ def test_huge_func(): def test_join_blocks_cleans_links(): from rpython.rtyper.lltypesystem import lltype - from rpython.flowspace.model import Constant from rpython.translator.backendopt.removenoops import remove_same_as def f(x): return bool(x + 2) @@ -215,7 +215,7 @@ def test_join_blocks_cleans_links(): return 2 graph, t = translate(g, [int], backend_optimize=False) fgraph = graphof(t, f) - fgraph.startblock.exits[0].args = [Constant(True, lltype.Bool)] + fgraph.startblock.exits[0].args = [ll_const(True)] # does not crash: previously join_blocks would barf on this remove_same_as(graph) backend_optimizations(t) diff --git a/rpython/translator/transform.py b/rpython/translator/transform.py index b8472272dc515f1e1e1088c33f33fdddb04ad47e..18a4654871443b00568906c6f654aa4ec58083c3 100644 --- a/rpython/translator/transform.py +++ b/rpython/translator/transform.py @@ -9,6 +9,7 @@ from rpython.flowspace.model import ( SpaceOperation, Variable, Constant, Link, checkgraph) from rpython.annotator import model as annmodel from rpython.rtyper.lltypesystem import lltype +from rpython.rtyper.rmodel import ll_const def checkgraphs(self, blocks): seen = set() @@ -205,7 +206,7 @@ def insert_ll_stackcheck(translator): graph = rtyper.annotate_helper(stack_check, []) rtyper.specialize_more_blocks() stack_check_ptr = rtyper.getcallable(graph) - stack_check_ptr_const = Constant(stack_check_ptr, lltype.typeOf(stack_check_ptr)) + stack_check_ptr_const = ll_const(stack_check_ptr) edges = set() insert_in = set() block2graph = {} diff --git a/rpython/translator/unsimplify.py b/rpython/translator/unsimplify.py index ee3041967259312e21f593bb5eda022bb8ec63c4..9983e4b4290cff5972b36eb12a878cf50fa912a2 100644 --- a/rpython/translator/unsimplify.py +++ b/rpython/translator/unsimplify.py @@ -1,5 +1,6 @@ from rpython.flowspace.model import (Variable, Constant, Block, Link, SpaceOperation, c_last_exception, checkgraph) +from rpython.rtyper.rmodel import ll_const def varoftype(concretetype, name=None): @@ -101,7 +102,7 @@ def split_block(block, index, _forcelink=None): " containing an int or str or instance is actually" " known to be constant, e.g. always 42." % ( v, v.concretetype)) - c = Constant(None, lltype.Void) + c = ll_const(None) w = varmap[v] newop = SpaceOperation('same_as', [c], w) i = 0