[pypy-svn] r69816 - in pypy/branch/cli-jit/pypy/translator: cli jvm oosupport
antocuni at codespeak.net
antocuni at codespeak.net
Tue Dec 1 18:53:26 CET 2009
Author: antocuni
Date: Tue Dec 1 18:53:25 2009
New Revision: 69816
Modified:
pypy/branch/cli-jit/pypy/translator/cli/constant.py
pypy/branch/cli-jit/pypy/translator/jvm/constant.py
pypy/branch/cli-jit/pypy/translator/oosupport/constant.py
Log:
not all the constants needs to be initialized (e.g., instances without fields,
empty lists, etc.). This saves a bit of useless "ldsfld xxx; pop" sequences
during the constant initialization phase
Modified: pypy/branch/cli-jit/pypy/translator/cli/constant.py
==============================================================================
--- pypy/branch/cli-jit/pypy/translator/cli/constant.py (original)
+++ pypy/branch/cli-jit/pypy/translator/cli/constant.py Tue Dec 1 18:53:25 2009
@@ -293,9 +293,6 @@
gen.ilasm.opcode('ldftn', signature)
gen.ilasm.new('instance void class %s::.ctor(object, native int)' % self.delegate_type)
self.db.const_count.inc('StaticMethod')
-
- def initialize_data(self, constgen, gen):
- return
class CLIWeakRefConst(CLIBaseConstMixin, WeakRefConst):
@@ -305,6 +302,9 @@
def get_type(self, include_class=True):
return 'class ' + WEAKREF
+
+ def needs_initialization(self):
+ return bool(self.value)
def initialize_data(self, constgen, gen):
if self.value is not None:
Modified: pypy/branch/cli-jit/pypy/translator/jvm/constant.py
==============================================================================
--- pypy/branch/cli-jit/pypy/translator/jvm/constant.py (original)
+++ pypy/branch/cli-jit/pypy/translator/jvm/constant.py Tue Dec 1 18:53:25 2009
@@ -158,8 +158,6 @@
else:
gen.push_null(jvm.jObject)
- def initialize_data(self, constgen, gen):
- return
class JVMCustomDictConst(CustomDictConst):
@@ -199,9 +197,8 @@
push_constant(self.db, self.value._TYPE, self.value, gen)
gen.create_weakref(TYPE)
- def initialize_data(self, constgen, gen):
- gen.pop(ootype.ROOT)
- return True
+ def needs_initialization(self):
+ return False
Modified: pypy/branch/cli-jit/pypy/translator/oosupport/constant.py
==============================================================================
--- pypy/branch/cli-jit/pypy/translator/oosupport/constant.py (original)
+++ pypy/branch/cli-jit/pypy/translator/oosupport/constant.py Tue Dec 1 18:53:25 2009
@@ -282,6 +282,8 @@
""" Iterates through each constant, initializing its data. """
gen.add_section("Initialize Data Phase")
for const in all_constants:
+ if not const.needs_initialization():
+ continue
self._consider_step(gen)
gen.add_comment("Constant: %s" % const.name)
self._push_constant_during_init(gen, const)
@@ -426,6 +428,12 @@
assert not self.is_null()
gen.new(self.value._TYPE)
+ def needs_initialization(self):
+ """
+ if True, calls initialize_data
+ """
+ return True
+
def initialize_data(self, constgen, gen):
"""
Initializes the internal data. Begins with a pointer to
@@ -475,6 +483,9 @@
value = self.value._items[f_name]
self._record_const_if_complex(FIELD_TYPE, value)
+ def needs_initialization(self):
+ return bool(self.value._TYPE._fields)
+
def initialize_data(self, constgen, gen):
assert not self.is_null()
SELFTYPE = self.value._TYPE
@@ -543,13 +554,17 @@
return const_list
+ def needs_initialization(self):
+ self.const_list = self._sorted_const_list()
+ return bool(self.const_list)
+
def initialize_data(self, constgen, gen):
assert not self.is_null()
# Get a list of all the constants we'll need to initialize.
# I am not clear on why this needs to be sorted, actually,
# but we sort it.
- const_list = self._sorted_const_list()
+ const_list = self.const_list
# Push ourself on the stack, and cast to our actual type if it
# is not the same as our static type
@@ -585,8 +600,8 @@
INSTANCE = self.value._INSTANCE
gen.getclassobject(INSTANCE)
- def initialize_data(self, constgen, gen):
- pass
+ def needs_initialization(self):
+ return False
# ______________________________________________________________________
# List constants
@@ -627,6 +642,9 @@
Void. """
return self.value._TYPE.ITEM is ootype.Void
+ def needs_initialization(self):
+ return bool(self.value._list)
+
def initialize_data(self, constgen, gen):
assert not self.is_null()
SELFTYPE = self.value._TYPE
@@ -675,6 +693,9 @@
Void. """
return self.value._TYPE.ITEM is ootype.Void
+ def needs_initialization(self):
+ return bool(self.value._array)
+
def initialize_data(self, constgen, gen):
assert not self.is_null()
SELFTYPE = self.value._TYPE
@@ -713,6 +734,9 @@
self._record_const_if_complex(self.value._TYPE._KEYTYPE, key)
self._record_const_if_complex(self.value._TYPE._VALUETYPE, value)
+ def needs_initialization(self):
+ return bool(self.value._dict)
+
def initialize_data(self, constgen, gen):
assert not self.is_null()
SELFTYPE = self.value._TYPE
@@ -752,8 +776,8 @@
self.db.pending_function(self.value.graph)
self.delegate_type = self.db.record_delegate(self.value._TYPE)
- def initialize_data(self, constgen, gen):
- raise NotImplementedError
+ def needs_initialization(self):
+ return False
# ______________________________________________________________________
# Weak Reference constants
More information about the Pypy-commit
mailing list