[pypy-svn] r13282 - pypy/dist/pypy/translator/llvm
ericvrp at codespeak.net
ericvrp at codespeak.net
Sat Jun 11 00:01:57 CEST 2005
Author: ericvrp
Date: Sat Jun 11 00:01:56 2005
New Revision: 13282
Modified:
pypy/dist/pypy/translator/llvm/funcrepr.py
pypy/dist/pypy/translator/llvm/genllvm.py
pypy/dist/pypy/translator/llvm/lazyattribute.py
pypy/dist/pypy/translator/llvm/llvmbc.py
pypy/dist/pypy/translator/llvm/pointerrepr.py
pypy/dist/pypy/translator/llvm/representation.py
pypy/dist/pypy/translator/llvm/seqrepr.py
pypy/dist/pypy/translator/llvm/typerepr.py
Log:
Added casts, same_as and ..._is_true for all lltypes by using casts for all of then.
This raises the question whether the rtyper should really generate same_as and ..._is_true instructions.
Perhaps the rtyper could also stick to casts to same type (same_as) or to bool (..._is_true)?
XXX some instructions fail silently (for instance pow(...)) in t_op(...) methods. This should be fixed!
Modified: pypy/dist/pypy/translator/llvm/funcrepr.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/funcrepr.py (original)
+++ pypy/dist/pypy/translator/llvm/funcrepr.py Sat Jun 11 00:01:56 2005
@@ -21,8 +21,8 @@
from pypy.translator.llvm.representation import SimpleRepr
from pypy.translator.llvm.typerepr import TypeRepr, PointerTypeRepr
-debug = True
-lazy_debug = True
+debug = False
+lazy_debug = False
INTRINSIC_OPS = ["lt", "le", "eq", "ne", "gt", "ge", "is_", "is_true", "len",
"neg", "pos", "invert", "add", "sub", "mul", "truediv",
@@ -31,7 +31,7 @@
"inplace_truediv", "inplace_floordiv", "inplace_div",
"inplace_mod", "inplace_pow", "inplace_lshift",
"inplace_rshift", "inplace_and", "inplace_or", "inplace_xor",
- "contains", "alloc_and_set", "issubtype", "type", "ord"]
+ "contains", "alloc_and_set", "issubtype", "type", "ord" ]
C_SIMPLE_TYPES = {annmodel.SomeChar: "char",
annmodel.SomeString: "char*",
@@ -82,9 +82,7 @@
l_functions = {}
def get(obj, gen):
if isinstance(obj, lltype._func):
- print "1a)"
if obj._callable not in FunctionRepr.l_functions:
- print "1b)"
FunctionRepr.l_functions[obj._callable] = FunctionRepr(obj, gen)
return FunctionRepr.l_functions[obj._callable]
return None
@@ -115,36 +113,29 @@
self.gen = gen
self.func = function
self.translator = gen.translator
- if debug: print "init 1a)"
- #if debug: print 'QQQ',function.name,'QQQ'
- #if debug: print "init 1b)"
- print function, function.__class__
+ if debug:
+ print function, function.__class__
self.name = gen.get_global_tmp(function._name)
- if debug: print "init 2)"
self.graph = function.graph
self.annotator = gen.translator.annotator
self.blocknum = {}
self.allblocks = []
self.pyrex_source = ""
self.dependencies = sets.Set()
- if debug: print "init 3)"
self.type = self.gen.get_repr(function._TYPE)
- if debug: print "init 4)"
self.l_args = [self.gen.get_repr(ar)
for ar in self.graph.startblock.inputargs]
self.dependencies.add(self.type)
self.dependencies.update(self.l_args)
- if debug: print "init 8)"
self.l_default_args = None
remove_double_links(self.translator, self.graph)
- print "init 9)"
self.get_bbs()
- print "init done"
lazy_attributes = ['llvm_func', 'lblocks']
def setup(self):
- print "setup"
+ if debug:
+ print "setup"
self.se = True
self.lblocks = []
self.build_bbs()
@@ -197,10 +188,11 @@
l_args = [self.gen.get_repr(arg) for arg in args]
if len(l_args) - 1 < len(self.l_args):
if self.func.func_defaults is None:
- for l_a in l_args:
- print l_a, l_a.llvmname(),
- for l_a in self.l_args:
- print l_a, l_a.llvmname(),
+ if debug:
+ for l_a in l_args:
+ print l_a, l_a.llvmname(),
+ for l_a in self.l_args:
+ print l_a, l_a.llvmname(),
assert self.func.func_defaults is not None
if self.l_default_args is None:
self.l_default_args = [self.gen.get_repr(Constant(de))
@@ -271,6 +263,9 @@
return
l_arg0 = self.gen.get_repr(op.args[0])
self.l_func.dependencies.add(l_arg0)
+ if op.opname.startswith("cast_") or op.opname.startswith("same_as") or op.opname.endswith("_is_true"):
+ self.lblock.cast(l_target, l_arg0)
+ return
l_op = getattr(l_arg0, "op_" + op.opname, None)
if l_op is not None:
l_op(l_target, op.args, self.lblock, self.l_func)
@@ -486,7 +481,8 @@
def setup(self):
f = self.gen.rtyper.getfunctionptr(self.function)._obj
- print "EntryFunctionRepr", f
+ if debug:
+ print "EntryFunctionRepr", f
self.l_function = self.gen.get_repr(f)
self.dependencies.add(self.l_function)
#XXX clean this up
@@ -544,7 +540,8 @@
return fd
def llvmfuncdef(self):
- print self.l_function.l_args
+ if debug:
+ print self.l_function.l_args
s = "%s %s(" % (self.l_function.type.l_returntype.typename(), self.name)
s += ", ".join([a.typed_name() for a in self.l_function.l_args]) + ")"
return s
Modified: pypy/dist/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/genllvm.py (original)
+++ pypy/dist/pypy/translator/llvm/genllvm.py Sat Jun 11 00:01:56 2005
@@ -33,7 +33,7 @@
from pypy.translator.llvm import reprmap
-debug = True
+debug = False
def llvmcompile(transl, optimize=False):
@@ -75,11 +75,7 @@
for mod in [representation, funcrepr, typerepr, pointerrepr]:
self.repr_classes += [getattr(mod, s)
for s in dir(mod) if "Repr" in s]
- #if debug:
- # print 'LLVMGenerator before repr_classes=', len(self.repr_classes), self.repr_classes
self.repr_classes = [c for c in self.repr_classes if hasattr(c, "get")]
- #if debug:
- # print 'LLVMGenerator after repr_classes=', len(self.repr_classes), self.repr_classes
self.llvm_reprs = {}
self.depth = 0
self.entryname = self.translator.functions[0].__name__
@@ -94,6 +90,8 @@
from pypy.tool.udir import udir
name = self.entryname
llvmfile = udir.join('%s.ll' % name)
+ if debug:
+ print "llvmfile:", llvmfile
f = llvmfile.open('w')
self.write(f)
f.close()
@@ -159,22 +157,16 @@
except AttributeError:
pass
for cl in self.repr_classes:
- if 0: #debug:
+ if debug and 0:
print 'try cl.get(obj, self) where cl=', cl
try:
g = cl.get(obj, self)
- #if debug:
- # print 'A) g=', g
except AttributeError:
continue
- #if debug:
- # print 'B) g=', g
if g is not None:
self.llvm_reprs[key] = g
self.local_counts[g] = 0
self.depth -= 1
- #if debug:
- # print 'C) should return here'
return g
raise CompileError, "Can't get repr of %s, %s" % (obj, obj.__class__)
Modified: pypy/dist/pypy/translator/llvm/lazyattribute.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/lazyattribute.py (original)
+++ pypy/dist/pypy/translator/llvm/lazyattribute.py Sat Jun 11 00:01:56 2005
@@ -2,7 +2,7 @@
import sets
-debug = True
+debug = False
def create_property(cls, la, name):
def get(self):
Modified: pypy/dist/pypy/translator/llvm/llvmbc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmbc.py (original)
+++ pypy/dist/pypy/translator/llvm/llvmbc.py Sat Jun 11 00:01:56 2005
@@ -94,6 +94,15 @@
l_a.typed_name(), l_b.llvmname())
self.instructions.append(s)
+ #Shift instructions
+ def shift_instruction(self, instr, l_target, l_a, l_b):
+ self.phi_done = True
+ assert l_target.llvmtype() == l_a.llvmtype()
+ #assert l_b.llvmtype() == 'ubyte' #or cast to ubyte or assuma nothing goes wrong
+ s = "%s = %s %s, ubyte %s" % (l_target.llvmname(), instr,
+ l_a.typed_name(), l_b.llvmname())
+ self.instructions.append(s)
+
#Memory access instructions
def load(self, l_target, l_pter):
self.phi_done = True
Modified: pypy/dist/pypy/translator/llvm/pointerrepr.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/pointerrepr.py (original)
+++ pypy/dist/pypy/translator/llvm/pointerrepr.py Sat Jun 11 00:01:56 2005
@@ -11,7 +11,7 @@
from pypy.translator.llvm import representation
from pypy.translator.llvm import typerepr
-debug = True
+debug = False
class PointerRepr(representation.LLVMRepr):
def __init__(self, ptr, gen):
@@ -56,4 +56,4 @@
def typename(self):
return self.l_to.typename()
-
\ No newline at end of file
+
Modified: pypy/dist/pypy/translator/llvm/representation.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/representation.py (original)
+++ pypy/dist/pypy/translator/llvm/representation.py Sat Jun 11 00:01:56 2005
@@ -253,18 +253,18 @@
def llvmname(self):
return repr(self.value)
- def cast_to_unsigned(self, l_val, lblock, l_function):
- if self.type.annotation.unsigned:
- return self
- else:
- return IntRepr(annmodel.SomeInteger(True, True),
- self.value, self.gen)
-
- def cast_to_signed(self, l_val, lblock, l_function):
- if not self.type.annotation.unsigned:
- return self
- else:
- return IntRepr(annmodel.SomeInteger(), self.value, self.gen)
+ #def cast_to_unsigned(self, l_val, lblock, l_function):
+ # if self.type.annotation.unsigned:
+ # return self
+ # else:
+ # return IntRepr(annmodel.SomeInteger(True, True),
+ # self.value, self.gen)
+ #
+ #def cast_to_signed(self, l_val, lblock, l_function):
+ # if not self.type.annotation.unsigned:
+ # return self
+ # else:
+ # return IntRepr(annmodel.SomeInteger(), self.value, self.gen)
class VariableRepr(LLVMRepr):
def get(obj, gen):
@@ -290,11 +290,10 @@
return "%" + self.var.name
def __getattr__(self, name):
- print "getattr called", name, self.type.typename()
+ if debug:
+ print "getattr called", name, self.type.typename()
if name.startswith("op_"):
return getattr(self.type, "t_" + name, None)
- elif name.startswith("cast_"):
- return getattr(self.type, name, None)
else:
raise AttributeError, ("VariableRepr instance has no attribute %s"
% repr(name))
@@ -363,6 +362,6 @@
if name.startswith("op_"):
return getattr(self.type, "t_" + name, None)
else:
- raise AttributeError, ("VariableRepr instance has no attribute %s"
+ raise AttributeError, ("StringRepr instance has no attribute %s"
% repr(name))
Modified: pypy/dist/pypy/translator/llvm/seqrepr.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/seqrepr.py (original)
+++ pypy/dist/pypy/translator/llvm/seqrepr.py Sat Jun 11 00:01:56 2005
@@ -272,7 +272,7 @@
l_func.dependencies.update(l_args)
l_tmp = self.gen.get_local_tmp(PointerTypeRepr(l_target.llvmtype(),
self.gen), l_func)
- cast = getattr(l_args[1], "cast_to_unsigned", None)
+ cast = getattr(l_args[1], "cast_to_unsigned", None) #XXX that method is gone now, need to change this too!
if cast is not None:
l_unsigned = cast(l_args[1], lblock, l_func)
else:
Modified: pypy/dist/pypy/translator/llvm/typerepr.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/typerepr.py (original)
+++ pypy/dist/pypy/translator/llvm/typerepr.py Sat Jun 11 00:01:56 2005
@@ -24,8 +24,8 @@
else:
BYTES_IN_INT = 8
-lazy_debug = True
-debug = True
+lazy_debug = False
+debug = False
class TypeRepr(LLVMRepr):
def get(obj, gen):
@@ -77,39 +77,64 @@
class SignedTypeRepr(TypeRepr):
- directly_supported_ops = {
+ directly_supported_binary_ops = {
"int_add": "add",
"int_sub": "sub",
"int_mul": "mul",
"int_div": "div",
"int_mod": "rem",
"int_xor": "xor",
- "int_and_": "and",
+ "int_and": "and",
+ "int_lshift": "shl",
+ "int_rshift": "shr",
+ "int_or": "or",
"int_eq": "seteq",
"int_ne": "setne",
"int_gt": "setgt",
"int_ge": "setge",
"int_lt": "setlt",
"int_le": "setle"}
-
+
def __init__(self, gen):
if debug:
print "SignedTypeRepr"
self.gen = gen
def t_op(self, opname, l_target, args, lblock, l_func):
- if opname in SignedTypeRepr.directly_supported_ops:
+ if opname in SignedTypeRepr.directly_supported_binary_ops:
assert len(args) == 2
l_args = [self.gen.get_repr(arg) for arg in args]
l_func.dependencies.update(l_args)
- lblock.binary_instruction(
- SignedTypeRepr.directly_supported_ops[opname], l_target,
- l_args[0], l_args[1])
+ l_op = SignedTypeRepr.directly_supported_binary_ops[opname]
+ if l_op in ('shl', 'shr'): #feel free to refactor this
+ lblock.shift_instruction(
+ l_op, l_target,
+ l_args[0], l_args[1])
+ else:
+ lblock.binary_instruction(
+ l_op, l_target,
+ l_args[0], l_args[1])
+
+ def t_op_int_pos(self, l_target, args, lblock, l_func):
+ pass
+
+ def t_op_int_neg(self, l_target, args, lblock, l_func):
+ l_arg = self.gen.get_repr(args[0])
+ l_func.dependencies.add(l_arg)
+ lblock.instruction("%s = sub int 0, %s" % (l_target.llvmname(),
+ l_arg.llvmname()))
+
+ def t_op_int_invert(self, l_target, args, lblock, l_func):
+ l_arg = self.gen.get_repr(args[0])
+ l_func.dependencies.add(l_arg)
+ lblock.instruction("%s = xor int -1, %s" % (l_target.llvmname(),
+ l_arg.llvmname()))
- def t_op_int_is_true(self, l_target, args, lblock, l_func):
+ def t_op_int_abs(self, l_target, args, lblock, l_func):
l_arg = self.gen.get_repr(args[0])
l_func.dependencies.add(l_arg)
- lblock.cast(l_target, l_arg)
+ lblock.instruction("%s = and int 2147483647, %s" % (l_target.llvmname(),
+ l_arg.llvmname()))
def typename(self):
return "int"
@@ -138,18 +163,12 @@
def typename(self):
return "bool"
- def t_op_same_as(self, l_target, args, lblock, l_func):
- l_arg0 = self.gen.get_repr(args[0])
- l_func.dependencies.add(l_arg0)
- lblock.instruction("%s = or %s, false" % (l_target.llvmname(),
- l_arg0.typed_name()))
-
def llvmsize(self):
return 1
class FloatTypeRepr(TypeRepr):
- directly_supported_ops = {
+ directly_supported_binary_ops = {
"float_add": "add",
"float_sub": "sub",
"float_mul": "mul",
@@ -173,12 +192,12 @@
return "double"
def t_op(self, opname, l_target, args, lblock, l_func):
- if opname in FloatTypeRepr.directly_supported_ops:
+ if opname in FloatTypeRepr.directly_supported_binary_ops:
assert len(args) == 2
l_args = [self.gen.get_repr(arg) for arg in args]
l_func.dependencies.update(l_args)
lblock.binary_instruction(
- FloatTypeRepr.directly_supported_ops[opname], l_target,
+ FloatTypeRepr.directly_supported_binary_ops[opname], l_target,
l_args[0], l_args[1])
def llvmsize(self):
@@ -268,25 +287,25 @@
def typename(self):
return self.name
- def cast_to_signed(self, l_val, lblock, l_function):
- if not self.annotation.unsigned:
- return l_val
- ann = annmodel.SomeInteger()
- l_type = self.gen.get_repr(ann)
- l_tmp = self.gen.get_local_tmp(l_type, l_function)
- l_function.dependencies.update([l_type, l_tmp])
- lblock.cast(l_tmp, l_val, l_type)
- return l_tmp
-
- def cast_to_unsigned(self, l_val, lblock, l_function):
- if self.annotation.unsigned:
- return l_val
- ann = annmodel.SomeInteger(True, True)
- l_type = self.gen.get_repr(ann)
- l_tmp = self.gen.get_local_tmp(l_type, l_function)
- l_function.dependencies.update([l_type, l_tmp])
- lblock.cast(l_tmp, l_val, l_type)
- return l_tmp
+ #def cast_to_signed(self, l_val, lblock, l_function):
+ # if not self.annotation.unsigned:
+ # return l_val
+ # ann = annmodel.SomeInteger()
+ # l_type = self.gen.get_repr(ann)
+ # l_tmp = self.gen.get_local_tmp(l_type, l_function)
+ # l_function.dependencies.update([l_type, l_tmp])
+ # lblock.cast(l_tmp, l_val, l_type)
+ # return l_tmp
+ #
+ #def cast_to_unsigned(self, l_val, lblock, l_function):
+ # if self.annotation.unsigned:
+ # return l_val
+ # ann = annmodel.SomeInteger(True, True)
+ # l_type = self.gen.get_repr(ann)
+ # l_tmp = self.gen.get_local_tmp(l_type, l_function)
+ # l_function.dependencies.update([l_type, l_tmp])
+ # lblock.cast(l_tmp, l_val, l_type)
+ # return l_tmp
class SimpleTypeRepr(TypeRepr):
def get(obj, gen):
More information about the Pypy-commit
mailing list