24 #ifndef TVM_RELAX_ANALYSIS_H_
25 #define TVM_RELAX_ANALYSIS_H_
56 TVM_DLL
bool CanProveShapeEqual(
const ffi::Array<PrimExpr>& lhs,
const ffi::Array<PrimExpr>& rhs,
167 std::function<ffi::Optional<PrimExpr>(
const tirx::Var&
var)> f_shape_var_map =
nullptr,
168 std::function<ffi::Optional<Expr>(
const Var&
var)> f_var_map =
nullptr);
182 const Type& info, std::function<ffi::Optional<PrimExpr>(
const tirx::Var&
var)> f_shape_var_map,
198 ffi::Map<Var, Expr> var_map);
611 const Expr& expr,
const ffi::Optional<Expr>& own_name = ffi::Optional<Expr>(std::nullopt));
625 const Expr& expr,
const ffi::Optional<Expr>& own_name = ffi::Optional<Expr>(std::nullopt));
640 TVM_DLL
void WellFormed(ffi::Variant<IRModule, Function> obj,
bool check_ty =
true);
652 TVM_DLL
bool CheckWellFormed(ffi::Variant<IRModule, Function> obj,
bool check_ty =
true);
665 const Function& fn, ffi::Array<tirx::IndexMap> write_buffer_transformations);
Algebra expression simplifications.
Managed reference to CallNode.
Definition: expr.h:348
Managed reference to ExprNode.
Definition: base_expr.h:311
Managed reference class to IRModuleNode.
Definition: module.h:255
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition: base_expr.h:354
Managed reference to TypeNode.
Definition: base_expr.h:77
Managed reference to AnalyzerObj.
Definition: analyzer.h:913
Definition: block_builder.h:257
Managed reference to FuncTypeNode.
Definition: type.h:312
Managed reference to PrimFuncNode.
Definition: function.h:154
a named variable in TIR
Definition: var.h:68
Defines a remapping of buffer indices.
IRModule that holds the functions and type definitions.
BaseCheckResult
Fine grained result of base check.
Definition: analysis.h:227
@ kPass
LSet is superset of RSet.
@ kFailL2
WLSet is not superset of RSet because of mismatch in value information.
@ kFailL1
LSet is not superset of RSet by only looking at static information.
@ kFailL0
The two value sets have no intersection at all: Interset(LSet, RSet) = empty.
Type GetStaticType(const Type &info)
Get the corresponding static type from a given type.
ffi::Array< PrimExpr > CollectNonNegativeExpressions(const Type &ty)
Collect expressions whose usage requires them to be non-negative.
ffi::Map< tirx::SBlock, ffi::Map< ffi::ObjectRef, tirx::IndexMap > > SuggestLayoutTransforms(const Function &fn, ffi::Array< tirx::IndexMap > write_buffer_transformations)
Using the layout transforms on the outputs, suggest layout transformation on the blocks and buffers f...
ffi::Optional< Expr > FindImpureCall(const Expr &expr, const ffi::Optional< Expr > &own_name=ffi::Optional< Expr >(std::nullopt))
Check if the given expression (likely a function body) contains any impure calls.
bool ContainsImpureCall(const Expr &expr, const ffi::Optional< Expr > &own_name=ffi::Optional< Expr >(std::nullopt))
Check if the given expression (likely a function body) contains any impure calls.
Expr RemoveAllUnused(Expr expr)
Remove unused statements inside DataflowBlocks.
BaseCheckResult TypeBaseCheck(const Type &base, const Type &derived)
Run a base check to see if base subsumes derived.
Type EraseToWellDefined(const Type &info, std::function< ffi::Optional< PrimExpr >(const tirx::Var &var)> f_shape_var_map=nullptr, std::function< ffi::Optional< Expr >(const Var &var)> f_var_map=nullptr)
Erase the info to a corresponding more coarse grained type that is still well-defined(with all the va...
bool CheckWellFormed(ffi::Variant< IRModule, Function > obj, bool check_ty=true)
Return whether an IRModule or Function is well-formed.
ffi::Array< tirx::Var > TIRVarsInType(const Type &ty)
Get the TIR variables that appear in the input type. The returned list is deduplicated - each TIR var...
std::set< const VarNode * > GetUsedVars(const Expr &expr)
Get the used variables in an expression.
ffi::Map< Var, Expr > AnalyzeVar2Value(const IRModule &m)
Analyze var -> value mapping from VarBindings.
bool CanProveShapeEqual(const ffi::Array< PrimExpr > &lhs, const ffi::Array< PrimExpr > &rhs, const arith::Analyzer &ana)
Can prove the two symbolic shape arrays equals to each other.
PrimExpr TypeBaseCheckPrecondition(const Type &base, const Type &derived)
Return the condition for which base is a superset of derived.
ffi::Array< Var > ComputableAtCompileTime(const Function &func)
Type TypeFromStaticType(const Type &type)
Get the corresponding type from static type.
tvm::ffi::Array< Var > FreeVars(const Expr &expr)
Get free type parameters from expression expr.
ffi::Map< Var, ffi::Array< Var > > DataflowBlockUseDef(const DataflowBlock &dfb)
Get the use-def chain of variables inside a dataflow block.
bool IsBaseOf(const Type &base, const Type &derived)
Check the relation of two type to see if one subsumes another one.
void WellFormed(ffi::Variant< IRModule, Function > obj, bool check_ty=true)
Check if an IRModule or Function is well-formed.
ffi::Map< ffi::String, ffi::Array< Binding > > NameToBinding(const Function &fn)
Return a mapping from variable name to its Bindings.
OpPatternKind AnalyzeOpPatternKind(const tirx::PrimFunc &func)
Annotate Op Pattern Kind for PrimFunc, which is used in relax FuseOps.
tvm::ffi::Array< GlobalVar > AllGlobalVars(const Expr &expr)
Get all global variables from expression expr.
OpPatternKind
Definition: op_attr_types.h:35
tvm::ffi::Array< Var > AllVars(const Expr &expr)
Get all variables from expression expr.
ffi::Array< tirx::Var > DefinedSymbolicVars(const Expr &expr)
Get the TIR variables that defined in the input function. The returned list is deduplicated - each TI...
ffi::Array< tirx::Var > DefinableTIRVarsInType(const Type &ty)
Get the TIR variables that appear in the input type.
tvm::ffi::Array< Var > BoundVars(const Expr &expr)
Get all bound variables from expression expr.
Type TypeLCA(const Type &lhs, const Type &rhs)
Unify the two type to their least common ancestor.
Type DeriveCallRetType(const FuncType &finfo, const Call &call, const BlockBuilder &ctx)
bool HasReshapePattern(const tirx::PrimFunc &func)
Check if the given PrimFunc is essentially doing a reshape operation. The reshape operation also incl...
ffi::Array< tirx::Var > FreeSymbolicVars(const Expr &expr)
Get the TIR variables that are used but not defined in the input function. The returned list is dedup...
tvm::ffi::Array< tvm::ffi::Array< GlobalVar > > DetectRecursion(const IRModule &m)
Find all sets of recursive or mutually recursive functions in the module.
std::pair< ffi::Map< Var, ffi::Array< Var > >, ffi::Array< Var > > FunctionUseDef(const Expr &expr)
Get the use-def chain of variables inside a function.
VarUsageInfo CollectVarUsage(const Expr &expr)
Collect variable bindings and usage.
PrimVar var(std::string name_hint, PrimType t=PrimType::Int(32))
Construct a new Var expression.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
Data structures that can appear in operator attributes.
Relax types, including the richer dependent Relax type nodes.
A utility struct returned by CollectVarUsage.
Definition: analysis.h:519
ffi::Array< Var > outputs
Definition: analysis.h:536
ffi::Map< Var, ffi::Array< Var > > downstream_usage
Definition: analysis.h:530
ffi::Map< Var, Expr > bound_values
Definition: analysis.h:524