[pypy-svn] r37606 - pypy/dist/pypy/jit/hintannotator
arigo at codespeak.net
arigo at codespeak.net
Tue Jan 30 16:20:12 CET 2007
Author: arigo
Date: Tue Jan 30 16:20:11 2007
New Revision: 37606
Modified:
pypy/dist/pypy/jit/hintannotator/annotator.py
pypy/dist/pypy/jit/hintannotator/bookkeeper.py
pypy/dist/pypy/jit/hintannotator/model.py
Log:
Consider unfollowed calls to pure functions as atomic operations, so
that concreteness propagation and other algorithms work as expected
around them. Should fix a color problem in goal/targetjit.
Modified: pypy/dist/pypy/jit/hintannotator/annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/annotator.py (original)
+++ pypy/dist/pypy/jit/hintannotator/annotator.py Tue Jan 30 16:20:11 2007
@@ -34,12 +34,11 @@
def __init__(self, translator=None, base_translator=None, policy=None):
if policy is None:
policy = HintAnnotatorPolicy()
+ self.base_translator = base_translator
+ assert base_translator is not None # None not supported any more
bookkeeper = HintBookkeeper(self)
RPythonAnnotator.__init__(self, translator, policy=policy,
bookkeeper=bookkeeper)
-
- self.base_translator = base_translator
- assert base_translator is not None # None not supported any more
self.exceptiontransformer = base_translator.getexceptiontransformer()
def build_types(self, origgraph, input_args_hs):
Modified: pypy/dist/pypy/jit/hintannotator/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/bookkeeper.py (original)
+++ pypy/dist/pypy/jit/hintannotator/bookkeeper.py Tue Jan 30 16:20:11 2007
@@ -73,7 +73,8 @@
given arguments."""
def analyze_exceptblock(self, block, seen=None):
- raise AssertionError("graphs here should be exception-transformed")
+ return True # for now, we simplify and say that functions
+ # raising exceptions cannot be pure
def operation_is_true(self, op):
operation = lloperation.LL_OPERATIONS[op.opname]
@@ -91,6 +92,9 @@
self.tsgraph_maximal_call_families = UnionFind(TsGraphCallFamily)
self.annotator = hannotator
self.tsgraphsigs = {}
+ if hannotator is not None: # for tests
+ t = hannotator.base_translator
+ self.impurity_analyzer = ImpurityAnalyzer(t)
# circular imports hack
global hintmodel
from pypy.jit.hintannotator import model as hintmodel
@@ -158,11 +162,6 @@
hs_red = hintmodel.variableoftype(v.concretetype)
self.annotator.setbinding(v, hs_red)
- # is_green_call() is only meaningful at fixpoint,
- # so initialize the state here
- t = self.annotator.base_translator
- self.impurity_analyzer = ImpurityAnalyzer(t)
-
# propagate the green/red constraints
log.event("Computing maximal green set...")
greenorigindependencies = {}
@@ -219,6 +218,10 @@
ha.binding(tsgraph.getreturnvar()))
self.tsgraphsigs[tsgraph] = sig_hs
+ def is_pure_graph(self, graph):
+ impure = self.impurity_analyzer.analyze_direct_call(graph)
+ return not impure
+
def is_green_call(self, callop):
"Is the given call operation completely computable at compile-time?"
for v in callop.args:
Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py (original)
+++ pypy/dist/pypy/jit/hintannotator/model.py Tue Jan 30 16:20:11 2007
@@ -336,7 +336,9 @@
bookkeeper = getbookkeeper()
if not bookkeeper.annotator.policy.look_inside_graphs(graph_list):
# cannot follow
- return variableoftype(hs_v1.concretetype.TO.RESULT)
+ return cannot_follow_call(bookkeeper, graph_list,
+ (hs_v1,) + args_hs,
+ hs_v1.concretetype.TO.RESULT)
myorigin = bookkeeper.myorigin()
myorigin.__class__ = CallOpOriginFlags # thud
@@ -397,7 +399,8 @@
if not hasattr(fnobj, 'graph'):
raise NotImplementedError("XXX call to externals or primitives")
if not bookkeeper.annotator.policy.look_inside_graph(fnobj.graph):
- return variableoftype(lltype.typeOf(fnobj).RESULT)
+ return cannot_follow_call(bookkeeper, [fnobj.graph], args_hs,
+ lltype.typeOf(fnobj).RESULT)
# recursive call from the entry point to itself: ignore them and
# just hope the annotations are correct
@@ -643,6 +646,26 @@
hs_result = handler(*args_hs) # which may raise NotImplementedError
return hs_result
+def cannot_follow_call(bookkeeper, graph_list, args_hs, RESTYPE):
+ # the policy prevents us from following the call
+ if not graph_list: # no known target, give up
+ return variableoftype(RESTYPE)
+ for graph in graph_list:
+ if not bookkeeper.is_pure_graph(graph):
+ # it's not calling pure graphs either, so the result
+ # is entierely unknown
+ return variableoftype(RESTYPE)
+ # when calling pure graphs, consider the call as an operation.
+ for hs in args_hs:
+ if not isinstance(hs, SomeLLAbstractConstant):
+ return variableoftype(RESTYPE)
+ # if all arguments are SomeLLAbstractConstant, so can the result be.
+ origin = bookkeeper.myorigin()
+ d = newset({origin: True}, *[hs_c.origins for hs_c in args_hs])
+ return SomeLLAbstractConstant(RESTYPE, d,
+ eager_concrete = False, # probably
+ myorigin = origin)
+
# ____________________________________________________________
#
# Register automatically simple operations
More information about the Pypy-commit
mailing list