tvm
frame.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 #ifndef TVM_SCRIPT_PRINTER_FRAME_H_
20 #define TVM_SCRIPT_PRINTER_FRAME_H_
21 
22 #include <tvm/node/node.h>
23 #include <tvm/script/printer/doc.h>
24 
25 #include <utility>
26 #include <vector>
27 
28 namespace tvm {
29 namespace script {
30 namespace printer {
31 
36 class FrameNode : public Object {
37  public:
39 
40  virtual ~FrameNode() = default;
41 
46  template <typename TCallback>
47  void AddExitCallback(TCallback&& cb) {
48  callbacks_.emplace_back(std::forward<TCallback>(cb));
49  }
50 
54  virtual void EnterWithScope() {}
55 
59  virtual void ExitWithScope() {
60  for (const std::function<void()>& callback : callbacks_) {
61  callback();
62  }
63  callbacks_.clear();
64  }
65 
66  static constexpr const char* _type_key = "script.printer.Frame";
68 
69  private:
70  std::vector<std::function<void()>> callbacks_;
71 };
72 
76 class Frame : public ObjectRef {
77  protected:
78  Frame() = default;
79 
80  public:
81  virtual ~Frame() = default;
83 };
84 
88 class MetadataFrameNode : public FrameNode {
89  public:
91 
94  v->Visit("metadata", &metadata);
95  }
96 
97  static constexpr const char* _type_key = "script.printer.MetadataFrame";
99 };
100 
104 class MetadataFrame : public Frame {
105  public:
106  MetadataFrame();
108 };
109 
114 class VarDefFrameNode : public FrameNode {
115  public:
117 
120  v->Visit("stmts", &stmts);
121  }
122 
123  static constexpr const char* _type_key = "script.printer.VarDefFrame";
125 };
126 
130 class VarDefFrame : public Frame {
131  public:
132  VarDefFrame();
134 };
135 
136 } // namespace printer
137 } // namespace script
138 } // namespace tvm
139 
140 #endif // TVM_SCRIPT_PRINTER_FRAME_H_
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:92
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:38
Definition: frame.h:36
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:758
Definitions and helper macros for IR/AST nodes.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
MetadataFrame contains information like contant parameter array.
Definition: frame.h:88
base class of all object containers.
Definition: object.h:167
VarDefFrame contains information about the free variables that needs to be defined at the beginning o...
Definition: frame.h:114
Array< StmtDoc > stmts
Definition: frame.h:116
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
Array< ObjectRef > metadata
Definition: frame.h:90
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Reference type of FrameNode.
Definition: frame.h:76
static constexpr const char * _type_key
Definition: frame.h:66
Reference type of VarDefFrameNode.
Definition: frame.h:130
Base class of all object reference.
Definition: object.h:511
virtual void ExitWithScope()
Method that&#39;s called when Frame exits the scope.
Definition: frame.h:59
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
TVM_DECLARE_BASE_OBJECT_INFO(FrameNode, Object)
void AddExitCallback(TCallback &&cb)
Add a callback function to be called when this frame exits.
Definition: frame.h:47
virtual void EnterWithScope()
Method that&#39;s called when Frame enters the scope.
Definition: frame.h:54
Reference type of MetadataFrameNode.
Definition: frame.h:104
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:118