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_IR_BUILDER_IR_FRAME_H_
20 #define TVM_SCRIPT_IR_BUILDER_IR_FRAME_H_
21 
22 #include <tvm/ffi/reflection/registry.h>
23 #include <tvm/ir/expr.h>
24 #include <tvm/ir/function.h>
25 #include <tvm/ir/module.h>
26 #include <tvm/node/node.h>
28 
29 #include <vector>
30 
31 namespace tvm {
32 namespace script {
33 namespace ir_builder {
34 namespace ir {
35 
42  public:
44  ffi::Map<ffi::String, GlobalVar> global_var_map;
49  ffi::Map<GlobalVar, BaseFunc> functions;
51  ffi::Map<ffi::String, Any> attrs;
53  ffi::Map<ffi::String, ffi::Array<GlobalInfo>> global_infos;
54 
55  static void RegisterReflection() {
56  namespace refl = tvm::ffi::reflection;
57  refl::ObjectDef<IRModuleFrameNode>()
58  .def_ro("global_vars", &IRModuleFrameNode::global_var_map)
59  .def_ro("functions", &IRModuleFrameNode::functions)
60  .def_ro("attrs", &IRModuleFrameNode::attrs)
61  .def_ro("global_infos", &IRModuleFrameNode::global_infos);
62  }
63  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.IRModuleFrame", IRModuleFrameNode,
65 
66  public:
67  void ExitWithScope() final;
68 };
69 
75 class IRModuleFrame : public IRBuilderFrame {
76  public:
77  explicit IRModuleFrame(ObjectPtr<IRModuleFrameNode> data) : IRBuilderFrame(data) {
78  TVM_FFI_ICHECK(data != nullptr);
79  }
81 };
82 
83 } // namespace ir
84 } // namespace ir_builder
85 } // namespace script
86 } // namespace tvm
87 
88 #endif // TVM_SCRIPT_IR_BUILDER_IR_FRAME_H_
Managed reference to an IRBuilderFrameNode.
Definition: base.h:104
A frame that represents the IRModule frame with functions and global variables.
Definition: frame.h:41
ffi::Map< GlobalVar, BaseFunc > functions
A map from GlobalVar to all global functions.
Definition: frame.h:49
ffi::Map< ffi::String, Any > attrs
IRModule's attributes.
Definition: frame.h:51
ffi::Map< ffi::String, ffi::Array< GlobalInfo > > global_infos
IRModule's global_infos.
Definition: frame.h:53
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.IRModuleFrame", IRModuleFrameNode, IRBuilderFrameNode)
ffi::Map< ffi::String, GlobalVar > global_var_map
A map from string names to global variables that ensures global uniqueness.
Definition: frame.h:44
void ExitWithScope() final
The method called when exiting RAII scope.
static void RegisterReflection()
Definition: frame.h:55
Managed reference to IRModuleFrameNode.
Definition: frame.h:75
IRModuleFrame(ObjectPtr< IRModuleFrameNode > data)
Definition: frame.h:77
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IRModuleFrame, IRBuilderFrame, IRModuleFrameNode)
Base expr nodes in TVM.
Function nodes.
IRModule that holds the functions and type definitions.
Definition: repr_printer.h:91
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
Definitions and helper macros for IR/AST nodes.