[pypy-commit] pypy llconst: Remove concretetype attribute from Constant and create LLConstant

rlamy noreply at buildbot.pypy.org
Sat Oct 10 03:09:26 CEST 2015


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: llconst
Changeset: r80099:251f3b632147
Date: 2015-10-10 00:58 +0100
http://bitbucket.org/pypy/pypy/changeset/251f3b632147/

Log:	Remove concretetype attribute from Constant and create LLConstant

diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -337,12 +337,7 @@
 
 
 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/memory/gctransform/transform.py b/rpython/memory/gctransform/transform.py
--- 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 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 @@
 
     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/rlib/nonconst.py b/rpython/rlib/nonconst.py
--- 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 @@
 
     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/rtyper/annlowlevel.py b/rpython/rtyper/annlowlevel.py
--- a/rpython/rtyper/annlowlevel.py
+++ b/rpython/rtyper/annlowlevel.py
@@ -11,10 +11,9 @@
     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
 
 
 class KeyComp(object):
@@ -162,7 +161,7 @@
 
     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 LLConstant(p, lltype.typeOf(p))
 
     def graph2delayed(self, graph, FUNCTYPE=None):
         if FUNCTYPE is None:
@@ -177,7 +176,7 @@
 
     def graph2const(self, graph):
         p = self.graph2delayed(graph)
-        return Constant(p, lltype.typeOf(p))
+        return LLConstant(p, lltype.typeOf(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 @@
         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/rmodel.py b/rpython/rtyper/rmodel.py
--- a/rpython/rtyper/rmodel.py
+++ b/rpython/rtyper/rmodel.py
@@ -355,8 +355,15 @@
 
 # ____________________________________________________________
 
+class LLConstant(Constant):
+    __slots__ = ["concretetype"]
+    def __init__(self, value, concretetype):
+        Constant.__init__(self, value)
+        self.concretetype = concretetype
+
+
 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 +376,7 @@
     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
--- a/rpython/rtyper/rnone.py
+++ b/rpython/rtyper/rnone.py
@@ -1,6 +1,5 @@
-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
 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 +10,7 @@
     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")
diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -17,7 +17,7 @@
     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)
+    warning, impossible_repr, LLConstant)
 from rpython.tool.pairtype import pair, pairtype
 from rpython.translator.unsimplify import varoftype
 
@@ -779,7 +779,7 @@
         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
--- a/rpython/rtyper/rptr.py
+++ b/rpython/rtyper/rptr.py
@@ -4,7 +4,7 @@
 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
 from rpython.rtyper.rint import IntegerRepr
 from rpython.tool.pairtype import pairtype
 
@@ -48,7 +48,7 @@
             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 @@
     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 @@
             opname = 'direct_call'
         else:
             opname = 'indirect_call'
-            vlist.append(hop.inputconst(lltype.Void, None))
+            vlist.append(inputconst(lltype.Void, None))
         hop.exception_is_here()
         return hop.genop(opname, vlist,
                          resulttype = self.lowleveltype.TO.RESULT)
@@ -123,15 +123,14 @@
             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 @@
                 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 @@
             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 @@
                 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 @@
         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/translator/backendopt/constfold.py b/rpython/translator/backendopt/constfold.py
--- 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
 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 @@
         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 @@
                     # 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 @@
         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 @@
         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 @@
         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 @@
         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
--- a/rpython/translator/backendopt/inline.py
+++ b/rpython/translator/backendopt/inline.py
@@ -2,6 +2,7 @@
 
 from rpython.flowspace.model import (Variable, Constant, Block, Link,
     SpaceOperation, FunctionGraph, mkentrymap)
+from rpython.rtyper.rmodel import LLConstant, inputconst
 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 @@
     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 = inputconst(typeOf(ll_exc_match), ll_exc_match)
         blocks = []
         for i, link in enumerate(afterblock.exits[1:]):
             etype = copiedexceptblock.inputargs[0].copy()
@@ -366,8 +366,8 @@
             block = Block([etype, evalue] + passon_vars)
             res = Variable()
             res.concretetype = Bool
-            cexitcase = Constant(link.llexitcase)
-            cexitcase.concretetype = typeOf(cexitcase.value)
+            exitcase = link.llexitcase
+            cexitcase = LLConstant(exitcase, typeOf(exitcase))
             args = [exc_match, etype, cexitcase]
             block.operations.append(SpaceOperation("direct_call", args, res))
             block.exitswitch = res
@@ -597,8 +597,8 @@
                                    '_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
--- 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
 from rpython.translator import simplify
 from rpython.translator.backendopt import removenoops
 from rpython.translator.backendopt.support import log
@@ -88,7 +89,7 @@
                 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 @@
         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 @@
                                                           ('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 @@
         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 = LLConstant(ll_msg, lltype.typeOf(ll_msg))
         return SpaceOperation("debug_fatalerror", [c_msg], v_result)
 
     def flowin_op(self, op, vars, newvarsmap):
@@ -469,7 +467,7 @@
             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 @@
                 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 @@
                 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 @@
         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
--- a/rpython/translator/backendopt/mallocv.py
+++ b/rpython/translator/backendopt/mallocv.py
@@ -7,6 +7,7 @@
 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
 
 
 def virtualize_mallocs(translator, graphs, verbose=False):
@@ -576,16 +577,15 @@
         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 @@
         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 @@
         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 @@
         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 = LLConstant(ll_msg, lltype.typeOf(ll_msg))
         newresult = self.make_rt_result(op.result)
         return [SpaceOperation('debug_fatalerror', [c_msg], newresult)]
 
@@ -889,8 +888,7 @@
             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 @@
 
     def handle_residual_call(self, op, newgraph, newnodes):
         fspecptr = getfunctionptr(newgraph)
-        newargs = [Constant(fspecptr,
-                            concretetype=lltype.typeOf(fspecptr))]
+        newargs = [LLConstant(fspecptr, concretetype=lltype.typeOf(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/test/test_constfold.py b/rpython/translator/backendopt/test/test_constfold.py
--- 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 @@
     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 @@
         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 @@
         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/exceptiontransform.py b/rpython/translator/exceptiontransform.py
--- a/rpython/translator/exceptiontransform.py
+++ b/rpython/translator/exceptiontransform.py
@@ -2,13 +2,13 @@
 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
 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,10 @@
     assert 0, "not implemented yet"
 
 def error_constant(T):
-    return Constant(error_value(T), T)
+    return LLConstant(error_value(T), T)
 
 def constant_value(llvalue):
-    return Constant(llvalue, lltype.typeOf(llvalue))
+    return LLConstant(llvalue, lltype.typeOf(llvalue))
 
 class ExceptionTransformer(object):
 
@@ -460,16 +460,16 @@
         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 LLConstant(fn_ptr, lltype.Ptr(FUNC_TYPE))
 
     def gen_getfield(self, name, llops):
         c_name = inputconst(lltype.Void, name)
diff --git a/rpython/translator/transform.py b/rpython/translator/transform.py
--- a/rpython/translator/transform.py
+++ b/rpython/translator/transform.py
@@ -9,6 +9,7 @@
     SpaceOperation, Variable, Constant, Link, checkgraph)
 from rpython.annotator import model as annmodel
 from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.rmodel import inputconst
 
 def checkgraphs(self, blocks):
     seen = set()
@@ -205,7 +206,8 @@
     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 = inputconst(lltype.typeOf(stack_check_ptr),
+                                       stack_check_ptr)
     edges = set()
     insert_in = set()
     block2graph = {}


More information about the pypy-commit mailing list