tvm
Loading...
Searching...
No Matches
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_TIRX_SCRIPT_IR_BUILDER_FRAME_H_
20#define TVM_TIRX_SCRIPT_IR_BUILDER_FRAME_H_
21
24#include <tvm/tirx/function.h>
25#include <tvm/tirx/stmt.h>
27
28#include <functional>
29#include <utility>
30
31namespace tvm {
32namespace script {
33namespace ir_builder {
34namespace tirx {
35
36// Retain dialect imports as aliases of the shared canonical frames.
37using ir::AssertFrame;
39using ir::ElseFrame;
41using ir::ForFrame;
42using ir::ForFrameObj;
43using ir::IfFrame;
44using ir::IfFrameObj;
45using ir::RegionFrame;
47using ir::ThenFrame;
49using ir::WhileFrame;
51
58 public:
60 ffi::Optional<ffi::String> name;
62 ffi::Array<tvm::Var> args;
66 ffi::Optional<Type> ret_type;
68 ffi::Map<ffi::String, Any> attrs;
72 bool is_declaration{false};
74 ffi::Optional<tvm::tirx::Function> function;
75 ffi::Optional<GlobalVar> global_var;
76
77 static void RegisterReflection() {
78 namespace refl = tvm::ffi::reflection;
79 refl::ObjectDef<FunctionFrameObj>()
80 .def_ro("name", &FunctionFrameObj::name)
81 .def_ro("args", &FunctionFrameObj::args)
82 .def_ro("is_private", &FunctionFrameObj::is_private)
83 .def_ro("ret_type", &FunctionFrameObj::ret_type)
84 .def_ro("attrs", &FunctionFrameObj::attrs)
85 .def_ro("persistent", &FunctionFrameObj::persistent)
86 .def_ro("is_declaration", &FunctionFrameObj::is_declaration)
87 .def_ro("function", &FunctionFrameObj::function)
88 .def_ro("global_var", &FunctionFrameObj::global_var);
89 }
90 TVM_FFI_DECLARE_OBJECT_INFO("script.ir_builder.tirx.FunctionFrame", FunctionFrameObj,
92
93 public:
98 void ExitWithScope() final;
99
101 using AttrValidator = std::function<void(const FunctionFrameObj*, const ffi::Any&)>;
102 static void RegisterAttrValidator(ffi::String key, AttrValidator validator);
103 void ValidateAttrs() const;
104
106 virtual tvm::tirx::Function FinalizeFunction(tvm::tirx::Function func);
107};
108
114class FunctionFrame : public ir::StmtFrame {
115 public:
116 explicit FunctionFrame(ffi::ObjectPtr<FunctionFrameObj> data) : ir::StmtFrame(ffi::UnsafeInit{}) {
117 TVM_FFI_ICHECK(data != nullptr);
118 data_ = std::move(data);
119 }
121};
122
123} // namespace tirx
124} // namespace ir_builder
125} // namespace script
126} // namespace tvm
127
128#endif // TVM_TIRX_SCRIPT_IR_BUILDER_FRAME_H_
A frame that represents the assert statement. Proceeds if the condition is true, otherwise aborts wit...
Definition frame.h:167
Managed reference to AssertFrameObj.
Definition frame.h:204
A frame that represents else.
Definition frame.h:391
Managed reference to ElseFrameObj.
Definition frame.h:417
A frame that represents the for loop.
Definition frame.h:110
Managed reference to ForFrameObj.
Definition frame.h:152
A frame that represents if statement.
Definition frame.h:304
Managed reference to IfFrameObj.
Definition frame.h:339
A result-free region with lexical body parameters.
Definition frame.h:217
Managed reference to RegionFrameObj.
Definition frame.h:247
A shared frame containing a sequence of core IR statements.
Definition frame.h:84
Managed reference to StmtFrameObj.
Definition frame.h:96
A frame that represents then.
Definition frame.h:352
Managed reference to ThenFrameObj.
Definition frame.h:378
A frame that represents while loop.
Definition frame.h:261
Managed reference to WhileFrameObj.
Definition frame.h:290
A frame that represents the Function containing TIR statements.
Definition frame.h:57
ffi::Optional< GlobalVar > global_var
Definition frame.h:75
bool is_private
Whether the Function is annotated as private.
Definition frame.h:64
ffi::Array< tvm::Var > args
Function parameters.
Definition frame.h:62
ffi::Map< ffi::String, Any > attrs
Additional attributes storing the meta-data.
Definition frame.h:68
TVM_FFI_DECLARE_OBJECT_INFO("script.ir_builder.tirx.FunctionFrame", FunctionFrameObj, ir::StmtFrameObj)
ffi::Optional< Type > ret_type
The return type of the function.
Definition frame.h:66
std::function< void(const FunctionFrameObj *, const ffi::Any &)> AttrValidator
Register validation for an extension-owned function attribute.
Definition frame.h:101
bool is_declaration
Whether this frame declares a bodyless signature.
Definition frame.h:72
bool persistent
Whether it is a persistent kernel.
Definition frame.h:70
void ExitWithScope() final
The method called when exiting RAII scope.
virtual tvm::tirx::Function FinalizeFunction(tvm::tirx::Function func)
Complete dialect-specific function construction before publication.
ffi::Optional< tvm::tirx::Function > function
Finalized function and its module identity.
Definition frame.h:74
static void RegisterReflection()
Definition frame.h:77
static void RegisterAttrValidator(ffi::String key, AttrValidator validator)
ffi::Optional< ffi::String > name
The name of the block.
Definition frame.h:60
Managed reference to FunctionFrameObj.
Definition frame.h:114
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(FunctionFrame, ir::StmtFrame, FunctionFrameObj)
FunctionFrame(ffi::ObjectPtr< FunctionFrameObj > data)
Definition frame.h:116
FunctionFrame Function(bool is_private, bool persistent=false)
The primitive function statement.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
TIR Function.
TIRx statements and shared statement entry header.