[pypy-svn] r37821 - in pypy/branch/jit-virtual-world/pypy/jit/codegen: . dump/test i386 llgraph llvm ppc test
arigo at codespeak.net
arigo at codespeak.net
Fri Feb 2 20:55:42 CET 2007
Author: arigo
Date: Fri Feb 2 20:55:35 2007
New Revision: 37821
Modified:
pypy/branch/jit-virtual-world/pypy/jit/codegen/dump/test/test_rgenop.py
pypy/branch/jit-virtual-world/pypy/jit/codegen/i386/rgenop.py
pypy/branch/jit-virtual-world/pypy/jit/codegen/llgraph/llimpl.py
pypy/branch/jit-virtual-world/pypy/jit/codegen/llgraph/rgenop.py
pypy/branch/jit-virtual-world/pypy/jit/codegen/llvm/rgenop.py
pypy/branch/jit-virtual-world/pypy/jit/codegen/model.py
pypy/branch/jit-virtual-world/pypy/jit/codegen/ppc/rgenop.py
pypy/branch/jit-virtual-world/pypy/jit/codegen/test/rgenop_tests.py
Log:
(arre, pedronis, arigo)
Added RGenOp.genzeroconst(kind), convenient for the front-end and
allowing the llgraph backend to produce a NULL pointer of precisely
the correct type. Easy implementation for the other backends.
Modified: pypy/branch/jit-virtual-world/pypy/jit/codegen/dump/test/test_rgenop.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/codegen/dump/test/test_rgenop.py (original)
+++ pypy/branch/jit-virtual-world/pypy/jit/codegen/dump/test/test_rgenop.py Fri Feb 2 20:55:35 2007
@@ -15,6 +15,9 @@
def compile(self, runner, argtypes):
py.test.skip("cannot compile tests for now")
+ # for the individual tests see
+ # ====> ../../test/rgenop_tests.py
+
class Whatever(object):
def __eq__(self, other):
Modified: pypy/branch/jit-virtual-world/pypy/jit/codegen/i386/rgenop.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/codegen/i386/rgenop.py (original)
+++ pypy/branch/jit-virtual-world/pypy/jit/codegen/i386/rgenop.py Fri Feb 2 20:55:35 2007
@@ -600,10 +600,14 @@
return AddrConst(lladdr)
else:
assert 0, "XXX not implemented"
-
+
# attached later constPrebuiltGlobal = global_rgenop.genconst
@staticmethod
+ def genzeroconst(kind):
+ return zero_const
+
+ @staticmethod
@specialize.memo()
def fieldToken(T, name):
FIELD = getattr(T, name)
@@ -694,5 +698,6 @@
global_rgenop = RI386GenOp()
RI386GenOp.constPrebuiltGlobal = global_rgenop.genconst
+zero_const = AddrConst(llmemory.NULL)
MALLOC_SIGTOKEN = RI386GenOp.sigToken(GC_MALLOC.TO)
Modified: pypy/branch/jit-virtual-world/pypy/jit/codegen/llgraph/llimpl.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/codegen/llgraph/llimpl.py (original)
+++ pypy/branch/jit-virtual-world/pypy/jit/codegen/llgraph/llimpl.py Fri Feb 2 20:55:35 2007
@@ -198,6 +198,12 @@
assert not isinstance(llvalue, str) and not isinstance(llvalue, lltype.LowLevelType)
return to_opaque_object(v)
+def genzeroconst(gv_TYPE):
+ TYPE = from_opaque_object(gv_TYPE).value
+ c = flowmodel.Constant(TYPE._defl())
+ c.concretetype = TYPE
+ return to_opaque_object(c)
+
def _generalcast(T, value):
if isinstance(T, lltype.Ptr):
return lltype.cast_pointer(T, value)
@@ -550,6 +556,7 @@
setannotation(genop, s_ConstOrVar)
setannotation(end, None)
setannotation(genconst, s_ConstOrVar)
+setannotation(genzeroconst, s_ConstOrVar)
setannotation(cast, s_ConstOrVar)
setannotation(revealconst, lambda s_T, s_gv: annmodel.lltype_to_annotation(
s_T.const))
Modified: pypy/branch/jit-virtual-world/pypy/jit/codegen/llgraph/rgenop.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/codegen/llgraph/rgenop.py (original)
+++ pypy/branch/jit-virtual-world/pypy/jit/codegen/llgraph/rgenop.py Fri Feb 2 20:55:35 2007
@@ -404,6 +404,10 @@
constPrebuiltGlobal = genconst
+ @staticmethod
+ def genzeroconst(gv_TYPE):
+ return LLConst(llimpl.genzeroconst(gv_TYPE.v))
+
def replay(self, label, kinds):
builder = LLBuilder(self, label.g, llimpl.nullblock)
args_gv = builder._newblock(kinds)
Modified: pypy/branch/jit-virtual-world/pypy/jit/codegen/llvm/rgenop.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/codegen/llvm/rgenop.py (original)
+++ pypy/branch/jit-virtual-world/pypy/jit/codegen/llvm/rgenop.py Fri Feb 2 20:55:35 2007
@@ -1,7 +1,7 @@
import py, os
from pypy.rlib.objectmodel import specialize
from pypy.rpython.lltypesystem import lltype, llmemory
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, r_uint
from pypy.jit.codegen.model import AbstractRGenOp, GenLabel, GenBuilder
from pypy.jit.codegen.model import GenVar, GenConst, CodeGenSwitch
from pypy.jit.codegen.llvm import llvmjit
@@ -859,6 +859,10 @@
# attached later constPrebuiltGlobal = global_rgenop.genconst
@staticmethod
+ def genzeroconst(kind):
+ return zero_consts[kind]
+
+ @staticmethod
@specialize.memo()
def kindToken(T):
# turn the type T into the llvm approximation that we'll use here
@@ -941,3 +945,11 @@
global_rgenop = RLLVMGenOp()
RLLVMGenOp.constPrebuiltGlobal = global_rgenop.genconst
+zero_consts = {
+ pi8: AddrConst(llmemory.NULL),
+ i1: BoolConst(False),
+ i8: CharConst('\x00'),
+ u32: UIntConst(r_uint(0)),
+ f64: FloatConst(0.0),
+ i32: IntConst(0),
+ }
Modified: pypy/branch/jit-virtual-world/pypy/jit/codegen/model.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/codegen/model.py (original)
+++ pypy/branch/jit-virtual-world/pypy/jit/codegen/model.py Fri Feb 2 20:55:35 2007
@@ -261,6 +261,12 @@
# This is for immortal prebuilt data."""
# raise NotImplementedError
+ #@staticmethod
+ #def genzeroconst(kind):
+ # """Get a GenConst containing the value 0 (or NULL) of the
+ # correct kind."""
+ # raise NotImplementedError
+
def replay(self, label, kinds):
'''Return a builder that will "generate" exactly the same code
as was already generated, starting from label. kinds is a
Modified: pypy/branch/jit-virtual-world/pypy/jit/codegen/ppc/rgenop.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/codegen/ppc/rgenop.py (original)
+++ pypy/branch/jit-virtual-world/pypy/jit/codegen/ppc/rgenop.py Fri Feb 2 20:55:35 2007
@@ -1060,6 +1060,10 @@
## @specialize.genconst(0)
## def constPrebuiltGlobal(llvalue):
+ @staticmethod
+ def genzeroconst(kind):
+ return zero_const
+
def replay(self, label, kinds):
return ReplayBuilder(self), [dummy_var] * len(kinds)
@@ -1227,3 +1231,4 @@
global_rgenop = RPPCGenOp()
RPPCGenOp.constPrebuiltGlobal = global_rgenop.genconst
+zero_const = AddrConst(llmemory.NULL)
Modified: pypy/branch/jit-virtual-world/pypy/jit/codegen/test/rgenop_tests.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/jit/codegen/test/rgenop_tests.py (original)
+++ pypy/branch/jit-virtual-world/pypy/jit/codegen/test/rgenop_tests.py Fri Feb 2 20:55:35 2007
@@ -1576,3 +1576,11 @@
res = fnptr(2, 10, 10, 400, 0)
assert res == 0
+
+ def test_genzeroconst(self):
+ RGenOp = self.RGenOp
+ gv = RGenOp.genzeroconst(RGenOp.kindToken(lltype.Signed))
+ assert gv.revealconst(lltype.Signed) == 0
+ P = lltype.Ptr(lltype.Struct('S'))
+ gv = RGenOp.genzeroconst(RGenOp.kindToken(P))
+ assert gv.revealconst(llmemory.Address) == llmemory.NULL
More information about the Pypy-commit
mailing list