tvm
Loading...
Searching...
No Matches
analysis.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
24#ifndef TVM_TIR_ANALYSIS_H_
25#define TVM_TIR_ANALYSIS_H_
26
27#include <tvm/ir/module.h>
28#include <tvm/ir/prim/expr.h>
29#include <tvm/ir/transform.h>
30#include <tvm/s_tir/analysis.h>
31#include <tvm/target/target.h>
32#include <tvm/tirx/function.h>
34#include <tvm/tirx/stmt.h>
35
36#include <string>
37
38namespace tvm {
39
40namespace tirx {
41
58 public:
59 TVM_DLL bool operator()(const PrimExpr& lhs, const PrimExpr& rhs) const;
60};
61
68template <class FLambda>
69inline void VisitPrimFuncs(const IRModule& mod, FLambda fvisit) {
70 for (const auto& kv : mod->functions) {
71 const BaseFunc& base_func = kv.second;
72 if (const auto* prim_func = base_func.as<PrimFuncNode>()) {
74 }
75 }
76}
77
84TVM_DLL ffi::Array<Var> UndefinedVars(const Stmt& stmt, const ffi::Array<Var>& defs);
85
91TVM_DLL ffi::Array<Var> UndefinedVars(const PrimExpr& expr);
92
99TVM_DLL ffi::Array<Var> UndefinedVars(const PrimExpr& expr, const ffi::Array<Var>& defs);
100
108
115TVM_DLL bool UsesVar(const Stmt& stmt, std::function<bool(const VarNode*)> vset_contains);
116
123TVM_DLL bool UsesVar(const PrimExpr& expr, std::function<bool(const VarNode*)> vset_contains);
124
134TVM_DLL bool VerifySSA(const PrimFunc& func);
135
146TVM_DLL bool VerifyMemory(const PrimFunc& func);
147
153
160
168
189TVM_DLL bool VerifyWellFormed(const PrimFunc& func, bool assert_mode = true);
190
203TVM_DLL bool VerifyWellFormed(const IRModule& mod, bool assert_mode = true);
204
213
214// Pass variants of verification analysis
215// directly throws RuntimeError when verification fails.
216namespace transform {
217
220
228
236
245/******** TIRx analysis helpers ********/
246
254TVM_DLL bool VerifyTIRxWellFormed(const PrimFunc& func, bool assert_mode = true,
255 bool device_func = false);
256
265 bool device_func = false);
266
267} // namespace transform
268} // namespace tirx
269} // namespace tvm
270#endif // TVM_TIR_ANALYSIS_H_
Managed reference to BaseFuncNode.
Definition function.h:250
Managed reference to GlobalVarNode.
Definition expr.h:429
Managed reference class to IRModuleNode.
Definition module.h:255
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:401
A local variable in the IR.
Definition expr.h:355
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
Primitive functions that contains TIR statements.
Definition function.h:49
Managed reference to PrimFuncNode.
Definition function.h:105
Container of all statements.
Definition stmt.h:67
PassContext that is used to configure the pass behavior.
Definition transform.h:151
Definition transform.h:417
TIR expressions.
IRModule that holds the functions and type definitions.
bool VerifyTIRxWellFormed(const PrimFunc &func, bool assert_mode=true, bool device_func=false)
Pass variant of VerifyGPUCode.
Pass VerifySSA()
Pass variant of VerifySSA.
Pass VerifyMemory()
Pass variant of VerifyMemory.
size_t CalculateExprComplexity(const PrimExpr &expr)
Calculate the expression complexity based on number of symbols it contains.
size_t CalculateConstantBytes(const PrimFunc &func, int64_t constant_byte_alignment)
Calculate the constants size in bytes needed by the TIR allocates inside the TIR PrimFunc.
bool VerifyMemory(const PrimFunc &func)
Verify if memory accesses are legal for a specific target device type.
bool VerifyWellFormed(const PrimFunc &func, bool assert_mode=true)
Verify if the given TIR is well-formed. The verification includes:
ffi::Array< Var > UndefinedVars(const Stmt &stmt, const ffi::Array< Var > &defs)
Find undefined vars in the statement.
bool VerifySSA(const PrimFunc &func)
Verifies whether the IR stmt or Expr is in SSA form. That is: each Var is defined and assigned once(i...
CallEffectKind SideEffect(const PrimExpr &expr)
Analyze the side effect of an expression.
size_t CalculateWorkspaceBytes(const PrimFunc &func, int64_t workspace_byte_alignment)
Calculate the workspace size in bytes needed by the TIR allocates inside the TIR PrimFunc.
bool UsesVar(const Stmt &stmt, std::function< bool(const VarNode *)> vset_contains)
Whether the given Stmt uses any var in the given variable set.
CallEffectKind
The effect type of the call.
Definition op_attr_types.h:105
void VisitPrimFuncs(const IRModule &mod, FLambda fvisit)
Visit the PrimFuncs in the IRModule.
Definition analysis.h:69
const PrimFuncNode * FindEntryFunc(const IRModule &mod, GlobalVar *result_g_var)
Find the entry function of the given IRModule, i.e, functions marked by tirx::attr::kIsEntryFunc,...
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
Analysis utilities for Schedulable TensorIR (S-TIR).
Compare two expressions recursively and check if they are equal to each other without var remapping.
Definition analysis.h:57
bool operator()(const PrimExpr &lhs, const PrimExpr &rhs) const
Compilation target object.
TIR Function.
Attribute types in the Op registry for TIR ops.
TIR statements.