MCPcopy Create free account
hub / github.com/apache/tvm / visit_tvm_declare_function

Function visit_tvm_declare_function

python/tvm/tirx/script/parser/parser.py:871–910  ·  view source on GitHub ↗

The function declaration step for tirx Parameters ---------- self : Parser The visiting parser. node : doc.Return The doc AST return node.

(self: Parser, node: doc.FunctionDef)

Source from the content-addressed store, hash-verified

869
870@dispatch.register(token="tirx", type_name="tvm_declare_function")
871def visit_tvm_declare_function(self: Parser, node: doc.FunctionDef) -> GlobalVar:
872 """The function declaration step for tirx
873
874 Parameters
875 ----------
876 self : Parser
877 The visiting parser.
878
879 node : doc.Return
880 The doc AST return node.
881 """
882
883 supplied_annotation = self.function_annotations
884 func_annotation = supplied_annotation.get(node.name, {})
885
886 ret_type = None
887 with self.var_table.with_frame():
888 if node.returns is not None:
889 ret_type = self.eval_expr(node.returns)
890 if callable(ret_type):
891 ret_type = PrimType(ret_type().dtype)
892
893 arg_annotations = []
894 for arg in node.args.args:
895 if arg.annotation is None:
896 self.report_error(arg, "Type annotation required for function parameters.")
897 try:
898 ann = self.eval_expr(arg.annotation)
899 if callable(ann):
900 ann = ann()
901 except Exception: # pylint: disable=broad-except
902 ann = func_annotation.get(arg.arg, None)
903 if ann is None:
904 raise
905
906 IRBuilder.name(arg.arg, ann)
907 arg_annotations.append(ann)
908
909 func_signature = tvm.tirx.PrimFunc(arg_annotations, None, ret_type=ret_type)
910 return I.decl_function(node.name, func_signature)

Callers

nothing calls this directly

Calls 7

PrimTypeClass · 0.90
with_frameMethod · 0.80
eval_exprMethod · 0.80
report_errorMethod · 0.80
getMethod · 0.45
nameMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…