def set_fixed(self): if not self.fixed: self.fixed = True if self.read_positions: annotator = getbookkeeper().annotator for p in self.read_positions: annotator.reflowfromposition(p)
def indirect_call(hs_v1, *args_hs): hs_graph_list = args_hs[-1] args_hs = args_hs[:-1] assert hs_graph_list.is_constant() graph_list = hs_graph_list.const if graph_list is None: # cannot follow indirect calls to unknown targets return variableoftype(hs_v1.concretetype.TO.RESULT) bookkeeper = getbookkeeper() myorigin = bookkeeper.myorigin() myorigin.__class__ = CallOpOriginFlags # thud fixed = myorigin.read_fixed() tsgraphs_accum = [] hs_res = bookkeeper.graph_family_call(graph_list, fixed, args_hs, tsgraphs_accum, hs_v1) myorigin.any_called_graph = tsgraphs_accum[0] if isinstance(hs_res, SomeLLAbstractConstant): hs_res.myorigin = myorigin # we need to make sure that hs_res does not become temporarily less # general as a result of calling another specialized version of the # function return annmodel.unionof(hs_res, bookkeeper.current_op_binding())
def _call_single_graph(hs_f1, graph, RESULT, *args_hs): bookkeeper = getbookkeeper() if not bookkeeper.annotator.policy.look_inside_graph(graph): return cannot_follow_call(bookkeeper, graph, args_hs, RESULT) # recursive call from the entry point to itself: ignore them and # just hope the annotations are correct if (bookkeeper.getdesc(graph)._cache.get(None, None) is bookkeeper.annotator.translator.graphs[0]): return variableoftype(RESULT) myorigin = bookkeeper.myorigin() myorigin.__class__ = CallOpOriginFlags # thud fixed = myorigin.read_fixed() tsgraphs_accum = [] hs_res = bookkeeper.graph_call(graph, fixed, args_hs, tsgraphs_accum) myorigin.any_called_graph = tsgraphs_accum[0] if isinstance(hs_res, SomeLLAbstractConstant): hs_res.myorigin = myorigin # we need to make sure that hs_res does not become temporarily less # general as a result of calling another specialized version of the # function return annmodel.unionof(hs_res, bookkeeper.current_op_binding())
def getsubstruct(hs_c1, hs_fieldname): S = hs_c1.concretetype.TO SUB_TYPE = getattr(S, hs_fieldname.const) origin = getbookkeeper().myorigin() d = setadd(hs_c1.origins, origin) return SomeLLAbstractConstant(lltype.Ptr(SUB_TYPE), d, myorigin=origin, deepfrozen=hs_c1.deepfrozen)
def getarraysubstruct((hs_c1, hs_index)): A = hs_c1.concretetype.TO SUB_TYPE = A.OF origin = getbookkeeper().myorigin() d = newset(hs_c1.origins, hs_index.origins, {origin: True}) return SomeLLAbstractConstant(lltype.Ptr(SUB_TYPE), d, myorigin=origin, deepfrozen=hs_c1.deepfrozen)
def cast_pointer(hs_c1): bk = getbookkeeper() origin = bk.myorigin() d = setadd(hs_c1.origins, origin) RESTYPE = bk.current_op_concretetype() return SomeLLAbstractConstant(RESTYPE, d, eager_concrete = hs_c1.eager_concrete, myorigin = origin, deepfrozen = hs_c1.deepfrozen)
def getfield_impl(hs_c1, S, FIELD_TYPE): if S._hints.get('immutable', False) or hs_c1.deepfrozen: origin = getbookkeeper().myorigin() d = setadd(hs_c1.origins, origin) return SomeLLAbstractConstant(FIELD_TYPE, d, eager_concrete=hs_c1.eager_concrete, myorigin=origin, deepfrozen=hs_c1.deepfrozen) else: return variableoftype(FIELD_TYPE)
def cast_pointer(hs_c1): bk = getbookkeeper() origin = bk.myorigin() d = setadd(hs_c1.origins, origin) RESTYPE = bk.current_op_concretetype() return SomeLLAbstractConstant(RESTYPE, d, eager_concrete=hs_c1.eager_concrete, myorigin=origin, deepfrozen=hs_c1.deepfrozen)
def getarrayitem((hs_c1, hs_index)): A = hs_c1.concretetype.TO READ_TYPE = A.OF if A._hints.get('immutable', False) or hs_c1.deepfrozen: origin = getbookkeeper().myorigin() d = newset(hs_c1.origins, hs_index.origins, {origin: True}) return SomeLLAbstractConstant(READ_TYPE, d, eager_concrete=hs_c1.eager_concrete, myorigin=origin, deepfrozen=hs_c1.deepfrozen) else: return variableoftype(READ_TYPE)
def getfield(hs_c1, hs_fieldname): S = hs_c1.concretetype.TO FIELD_TYPE = getattr(S, hs_fieldname.const) if S._hints.get('immutable', False) or hs_c1.deepfrozen: origin = getbookkeeper().myorigin() d = setadd(hs_c1.origins, origin) return SomeLLAbstractConstant(FIELD_TYPE, d, eager_concrete=hs_c1.eager_concrete, myorigin=origin, deepfrozen=hs_c1.deepfrozen) else: return variableoftype(FIELD_TYPE)
def reorigin(hs_v1, *deps_hs): """Make a copy of hs_v1 with its origins removed and replaced by myorigin(). Optionally, the origins of other annotations can also be added. """ if isinstance(hs_v1, SomeLLAbstractConstant): deps_origins = [hs_dep.origins for hs_dep in deps_hs if isinstance(hs_dep, SomeLLAbstractConstant)] d = newset({getbookkeeper().myorigin(): True}, *deps_origins) return SomeLLAbstractConstant(hs_v1.concretetype, d, eager_concrete=hs_v1.eager_concrete, deepfrozen=hs_v1.deepfrozen) else: return hs_v1
def direct_call(hs_f1, *args_hs): bookkeeper = getbookkeeper() fnobj = hs_f1.const._obj if (bookkeeper.annotator.policy.oopspec and hasattr(fnobj._callable, 'oopspec')): # try to handle the call as a high-level operation try: return handle_highlevel_operation(bookkeeper, fnobj._callable, *args_hs) except NotImplementedError: pass # don't try to annotate suggested_primitive graphs if getattr(getattr(fnobj, '_callable', None), 'suggested_primitive', False): return variableoftype(lltype.typeOf(fnobj).RESULT) # normal call if not hasattr(fnobj, 'graph'): raise NotImplementedError("XXX call to externals or primitives") if not bookkeeper.annotator.policy.look_inside_graph(fnobj.graph): 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 if (bookkeeper.getdesc(fnobj.graph)._cache.get(None, None) is bookkeeper.annotator.translator.graphs[0]): return variableoftype(lltype.typeOf(fnobj).RESULT) myorigin = bookkeeper.myorigin() myorigin.__class__ = CallOpOriginFlags # thud fixed = myorigin.read_fixed() tsgraphs_accum = [] hs_res = bookkeeper.graph_call(fnobj.graph, fixed, args_hs, tsgraphs_accum) myorigin.any_called_graph = tsgraphs_accum[0] if isinstance(hs_res, SomeLLAbstractConstant): hs_res.myorigin = myorigin ## elif fnobj.graph.name.startswith('ll_stritem'): ## if isinstance(hs_res, SomeLLAbstractVariable): ## print hs_res ## import pdb; pdb.set_trace() # we need to make sure that hs_res does not become temporarily less # general as a result of calling another specialized version of the # function return annmodel.unionof(hs_res, bookkeeper.current_op_binding())
def const_unary(llop, hs_c1): #XXX unsure hacks bk = getbookkeeper() origin = bk.myorigin() d = setadd(hs_c1.origins, origin) RESTYPE = bk.current_op_concretetype() hs_res = SomeLLAbstractConstant(RESTYPE, d, eager_concrete = hs_c1.eager_concrete, myorigin = origin) if hs_c1.is_constant(): try: hs_res.const = llop(RESTYPE, hs_c1.const) except Exception: # XXX not too nice pass return hs_res
def reorigin(hs_v1, *deps_hs): """Make a copy of hs_v1 with its origins removed and replaced by myorigin(). Optionally, the origins of other annotations can also be added. """ if isinstance(hs_v1, SomeLLAbstractConstant): deps_origins = [ hs_dep.origins for hs_dep in deps_hs if isinstance(hs_dep, SomeLLAbstractConstant) ] d = newset({getbookkeeper().myorigin(): True}, *deps_origins) return SomeLLAbstractConstant(hs_v1.concretetype, d, eager_concrete=hs_v1.eager_concrete, deepfrozen=hs_v1.deepfrozen) else: return hs_v1
def const_unary(llop, hs_c1): #XXX unsure hacks bk = getbookkeeper() origin = bk.myorigin() d = setadd(hs_c1.origins, origin) RESTYPE = bk.current_op_concretetype() hs_res = SomeLLAbstractConstant(RESTYPE, d, eager_concrete=hs_c1.eager_concrete, myorigin=origin) if hs_c1.is_constant(): try: hs_res.const = llop(RESTYPE, hs_c1.const) except Exception: # XXX not too nice pass return hs_res
def direct_call(hs_f1, *args_hs): bookkeeper = getbookkeeper() fnobj = get_funcobj(hs_f1.const) if (bookkeeper.annotator.policy.oopspec and hasattr(fnobj._callable, 'oopspec')): # try to handle the call as a high-level operation try: return handle_highlevel_operation(bookkeeper, fnobj._callable, *args_hs) except NotImplementedError: pass # normal call if not hasattr(fnobj, 'graph'): raise NotImplementedError("XXX call to externals or primitives") return hs_f1._call_single_graph(fnobj.graph, lltype.typeOf(fnobj).RESULT, *args_hs)
def oosend(hs_c1, hs_name, *args_hs): TYPE = hs_c1.concretetype name = hs_name.const _, meth = TYPE._lookup(name) METH = lltype.typeOf(meth) graph_list = TYPE._lookup_graphs(name) if not graph_list: # it's a graphless method of a BuiltinADTType bk = getbookkeeper() return handle_highlevel_operation_novirtual(bk, True, TYPE.immutable, hs_c1, *args_hs) elif len(graph_list) == 1: # like a direct_call graph = graph_list.pop() return hs_c1._call_single_graph(graph, METH.RESULT, hs_c1, *args_hs) # prepend hs_c1 to the args else: # like an indirect_call return hs_c1._call_multiple_graphs(graph_list, METH.RESULT, hs_c1, *args_hs) # prepend hs_c1 to the args
def _call_multiple_graphs(hs_v1, graph_list, RESULT, *args_hs): if graph_list is None: # cannot follow indirect calls to unknown targets return variableoftype(RESULT) bookkeeper = getbookkeeper() myorigin = bookkeeper.myorigin() myorigin.__class__ = CallOpOriginFlags # thud fixed = myorigin.read_fixed() tsgraphs_accum = [] hs_res = bookkeeper.graph_family_call(graph_list, fixed, args_hs, tsgraphs_accum, hs_v1) myorigin.any_called_graph = tsgraphs_accum[0] if isinstance(hs_res, SomeLLAbstractConstant): hs_res.myorigin = myorigin # we need to make sure that hs_res does not become temporarily less # general as a result of calling another specialized version of the # function return annmodel.unionof(hs_res, bookkeeper.current_op_binding())
def oosend(hs_c1, hs_name, *args_hs): TYPE = hs_c1.concretetype name = hs_name.const _, meth = TYPE._lookup(name) METH = lltype.typeOf(meth) graph_list = TYPE._lookup_graphs(name) if not graph_list: # it's a graphless method of a BuiltinADTType bk = getbookkeeper() return handle_highlevel_operation_novirtual( bk, True, TYPE.immutable, hs_c1, *args_hs) elif len(graph_list) == 1: # like a direct_call graph = graph_list.pop() return hs_c1._call_single_graph( graph, METH.RESULT, hs_c1, *args_hs) # prepend hs_c1 to the args else: # like an indirect_call return hs_c1._call_multiple_graphs( graph_list, METH.RESULT, hs_c1, *args_hs) # prepend hs_c1 to the args
def hint(hs_v1, hs_flags): if hs_flags.const.get('variable', False): # only for testing purposes!!! return SomeLLAbstractVariable(hs_v1.concretetype) if hs_flags.const.get('forget', False): # turn a variable to a constant origin = getbookkeeper().myorigin() return SomeLLAbstractConstant(hs_v1.concretetype, {origin: True}) if hs_flags.const.get('promote', False): hs_concrete = SomeLLAbstractConstant(hs_v1.concretetype, {}) #hs_concrete.eager_concrete = True return hs_concrete if hs_flags.const.get('deepfreeze', False): hs_clone = hs_v1.clone() hs_clone.deepfrozen = True return hs_clone for name in ["reverse_split_queue", "global_merge_point", "access_directly"]: if hs_flags.const.get(name, False): return raise HintError("hint %s makes no sense on %r" % (hs_flags.const, hs_v1))
def hint(hs_v1, hs_flags): if hs_flags.const.get('variable', False): # only for testing purposes!!! return SomeLLAbstractVariable(hs_v1.concretetype) if hs_flags.const.get('forget', False): # turn a variable to a constant origin = getbookkeeper().myorigin() return SomeLLAbstractConstant(hs_v1.concretetype, {origin: True}) if hs_flags.const.get('promote', False): hs_concrete = SomeLLAbstractConstant(hs_v1.concretetype, {}) #hs_concrete.eager_concrete = True return hs_concrete if hs_flags.const.get('deepfreeze', False): hs_clone = hs_v1.clone() hs_clone.deepfrozen = True return hs_clone for name in [ "reverse_split_queue", "global_merge_point", "access_directly" ]: if hs_flags.const.get(name, False): return raise HintError("hint %s makes no sense on %r" % (hs_flags.const, hs_v1))
def cast_pointer(hs_s1): TO = getbookkeeper().current_op_concretetype() res_vstruct =hs_s1.contentdef.cast(TO) return SomeLLAbstractContainer(res_vstruct)
def getarraysize(hs_a1): origin = getbookkeeper().myorigin() return SomeLLAbstractConstant(lltype.Signed, {origin: True})
def cast_pointer(hs_v1): RESTYPE = getbookkeeper().current_op_concretetype() return SomeLLAbstractVariable(RESTYPE, hs_v1.deepfrozen)
def oop_nonzero(self): origin = getbookkeeper().myorigin() return SomeLLAbstractConstant(lltype.Bool, {origin: True})
def ptr_ne(_): return getbookkeeper().immutablevalue(True)
def read_fixed(self): if self.read_positions is None: self.read_positions = {} self.read_positions[getbookkeeper().position_key] = True return self.fixed
def cast_pointer(hs_s1): TO = getbookkeeper().current_op_concretetype() res_vstruct = hs_s1.contentdef.cast(TO) return SomeLLAbstractContainer(res_vstruct)
eager_concrete = False, # probably myorigin = myorigin) else: h_res = variableoftype(RESTYPE) return h_res # ____________________________________________________________ # # Register automatically simple operations def var_unary(hs_v, *rest_hs): RESTYPE = getbookkeeper().current_op_concretetype() return SomeLLAbstractVariable(RESTYPE) def var_binary((hs_v1, hs_v2), *rest_hs): RESTYPE = getbookkeeper().current_op_concretetype() return SomeLLAbstractVariable(RESTYPE) def const_unary(llop, hs_c1): #XXX unsure hacks bk = getbookkeeper() origin = bk.myorigin() d = setadd(hs_c1.origins, origin) RESTYPE = bk.current_op_concretetype() hs_res = SomeLLAbstractConstant(RESTYPE, d, eager_concrete = hs_c1.eager_concrete, myorigin = origin) if hs_c1.is_constant(): try: hs_res.const = llop(RESTYPE, hs_c1.const) except Exception: # XXX not too nice
def ptr_nonzero(hs_s1): return getbookkeeper().immutablevalue(True)
def var_unary(hs_v, *rest_hs): RESTYPE = getbookkeeper().current_op_concretetype() return SomeLLAbstractVariable(RESTYPE)
def ptr_iszero(hs_s1): return getbookkeeper().immutablevalue(False)
h_res = variableoftype(RESTYPE) return h_res # ____________________________________________________________ # # Register automatically simple operations def var_unary(hs_v, *rest_hs): RESTYPE = getbookkeeper().current_op_concretetype() return SomeLLAbstractVariable(RESTYPE) def var_binary((hs_v1, hs_v2), *rest_hs): RESTYPE = getbookkeeper().current_op_concretetype() return SomeLLAbstractVariable(RESTYPE) def const_unary(llop, hs_c1): #XXX unsure hacks bk = getbookkeeper() origin = bk.myorigin() d = setadd(hs_c1.origins, origin) RESTYPE = bk.current_op_concretetype() hs_res = SomeLLAbstractConstant(RESTYPE, d, eager_concrete=hs_c1.eager_concrete, myorigin=origin) if hs_c1.is_constant(): try:
def ptr_eq(_): return getbookkeeper().immutablevalue(False)
def oop_newlist(hs_numitems, hs_item=None): bk = getbookkeeper() LIST = bk.current_op_concretetype().TO vlistdef = bk.getvirtualcontainerdef(LIST, VirtualListDef) return SomeLLAbstractContainer(vlistdef)
def oop_len(self): origin = getbookkeeper().myorigin() return SomeLLAbstractConstant(lltype.Signed, {origin: True})