MCPcopy Index your code
hub / github.com/apache/tvm / _visit_class_def

Function _visit_class_def

python/tvm/script/parser/ir/parser.py:36–83  ·  view source on GitHub ↗

The class definition visiting method for ir module. Parameters ---------- self : Parser The visiting parser. node : doc.ClassDef The doc AST class definition node.

(self: Parser, node: doc.ClassDef)

Source from the content-addressed store, hash-verified

34
35@dispatch.register(token="ir", type_name="ClassDef")
36def _visit_class_def(self: Parser, node: doc.ClassDef) -> None:
37 """The class definition visiting method for ir module.
38
39 Parameters
40 ----------
41 self : Parser
42 The visiting parser.
43
44 node : doc.ClassDef
45 The doc AST class definition node.
46 """
47
48 with self.var_table.with_frame():
49 with I.ir_module():
50 # Step 0. Add the class name to the var table
51 fake_module = ModuleWithGlobalVars()
52 self.var_table.add(node.name, fake_module)
53
54 # Step 1: Check if this class inherits from BasePyModule
55 is_base_py_module = _check_base_py_module_inheritance(node)
56 if is_base_py_module:
57 # Store this information in the IRModule for later use
58 I.module_attrs({"base_py_module": True})
59 # Set the parser context to allow Python functions
60 self.set_class_context(node.name, True)
61 else:
62 # Set the parser context to disallow Python functions
63 self.set_class_context(node.name, False)
64
65 # Step 2. Visit non-function stmts, including but not limited to
66 # 1. `I.module_attrs`
67 # 2. `I.module_global_infos`
68 with self.with_dispatch_token("ir"):
69 for stmt in node.body:
70 if not isinstance(stmt, doc.FunctionDef):
71 self.visit(stmt)
72
73 # Step 3. Visit function stmts to declare the global vars
74 for stmt in node.body:
75 if isinstance(stmt, doc.FunctionDef):
76 global_var = self.visit_tvm_declare_function(stmt)
77 fake_module.__setattr__(stmt.name, global_var)
78
79 # Step 4. Visit and parse the functions
80 with self.with_dispatch_token("ir"):
81 for stmt in node.body:
82 if isinstance(stmt, doc.FunctionDef):
83 self.visit(stmt)
84
85
86@dispatch.register(token="ir", type_name="Assign")

Callers

nothing calls this directly

Calls 9

with_frameMethod · 0.80
set_class_contextMethod · 0.80
with_dispatch_tokenMethod · 0.80
addMethod · 0.45
visitMethod · 0.45
__setattr__Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…