24 #ifndef TVM_ARITH_ANALYZER_H_ 25 #define TVM_ARITH_ANALYZER_H_ 33 #include <unordered_map> 74 v->Visit(
"min_value", &min_value);
75 v->Visit(
"max_value", &max_value);
90 static constexpr
const char*
_type_key =
"arith.ConstIntBound";
117 using BoundMapType = std::unordered_map<PrimExpr, ConstIntBound, ObjectPtrHash, ObjectPtrEqual>;
140 TVM_DLL
void Update(
const Var&
var,
const ConstIntBound& info,
bool allow_override =
false);
148 TVM_DLL
void Bind(
const Var&
var,
const Range& range,
bool allow_override =
false);
161 std::function<void()> EnterConstraint(
const PrimExpr& constraint);
188 v->Visit(
"coeff", &coeff);
189 v->Visit(
"base", &base);
196 static constexpr
const char*
_type_key =
"arith.ModularSet";
206 TVM_DLL
ModularSet(int64_t coeff, int64_t base);
229 TVM_DLL
void Update(
const Var&
var,
const ModularSet& info,
bool allow_override =
false);
242 std::function<void()> EnterConstraint(
const PrimExpr& constraint);
268 TVM_DLL
void Update(
const Var&
var,
const PrimExpr& new_expr,
bool allow_override =
false);
276 TVM_DLL std::function<void()> EnterConstraint(
const PrimExpr& constraint);
299 kTransitivelyProveInequalities = (1 << 0),
307 kConvertBooleanToAndOfOrs = (1 << 1),
320 kApplyConstraintsToBooleanBranches = (1 << 2),
328 TVM_DLL
void SetEnabledExtensions(
Extension flags);
331 TVM_DLL
Extension GetEnabledExtensions()
const;
363 TVM_DLL
void Update(
const Var& var,
const PrimExpr& new_expr,
bool allow_override =
false);
392 return CompareResult(static_cast<int>(lhs) & static_cast<int>(rhs));
395 return CompareResult(static_cast<int>(lhs) | static_cast<int>(rhs));
424 bool propagate_inequalities =
true);
432 TVM_DLL
void Bind(
const Var& var,
const PrimExpr& expr,
bool allow_override =
false);
440 TVM_DLL
void Bind(
const Var& var,
const Range& range,
bool allow_override =
false);
448 TVM_DLL std::function<void()> EnterConstraint(
const PrimExpr& constraint);
457 std::unique_ptr<Impl> impl_;
486 : analyzer_(analyzer), constraint_(constraint) {}
488 void EnterWithScope();
490 void ExitWithScope();
496 std::vector<std::function<void()>> recovery_functions_;
531 TVM_DLL
void Update(
const Var& var,
const IntSet& new_interval_set,
bool allow_override =
false);
540 TVM_DLL
void Bind(
const Var& var,
const Range& new_range,
bool allow_override =
false);
542 std::function<void()> EnterConstraint(
const PrimExpr& constraint);
596 void Bind(
const Var& var,
const PrimExpr& expr,
bool allow_override =
false);
609 void Bind(
const Var& var,
const Range& range,
bool allow_override =
false);
631 bool CanProveGreaterEqual(
const PrimExpr& expr, int64_t lower_bound);
644 bool CanProveLess(
const PrimExpr& expr, int64_t upper_bound);
663 bool CanProve(
const PrimExpr& cond);
682 #endif // TVM_ARITH_ANALYZER_H_ void VisitAttrs(tvm::AttrVisitor *v)
Definition: analyzer.h:73
static const constexpr int64_t kPosInf
Number to represent +inf.
Definition: analyzer.h:83
int64_t max_value
Definition: analyzer.h:71
void VisitAttrs(tvm::AttrVisitor *v)
Definition: analyzer.h:187
Constant integer up and lower bound(inclusive). Useful for value bound analysis.
Definition: analyzer.h:68
constexpr CompareResult operator &(CompareResult lhs, CompareResult rhs)
Definition: analyzer.h:391
int64_t coeff
linear co-efficient
Definition: analyzer.h:183
std::unordered_map< PrimExpr, ConstIntBound, ObjectPtrHash, ObjectPtrEqual > BoundMapType
Definition: analyzer.h:117
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:124
Type Bind(const Type &type, const Map< TypeVar, Type > &args_map)
Bind free type variables in the type.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Extension
Flags to enable more computationally-intensive simplifications.
Definition: analyzer.h:290
bool SEqualReduce(const ModularSetNode *other, SEqualReducer equal) const
Definition: analyzer.h:192
Range of a linear integer function. Use to do specify the possible index values.
Definition: analyzer.h:180
Canonical-form based simplifier.
Definition: analyzer.h:347
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
a named variable in TIR
Definition: var.h:88
base class of all object containers.
Definition: object.h:167
constexpr CompareResult operator|(CompareResult lhs, CompareResult rhs)
Definition: analyzer.h:394
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
Range constainer.
Definition: expr.h:713
reference of ModularSetNode
Definition: analyzer.h:204
Floor division.
Definition: analyzer.h:59
Truncated division.
Definition: analyzer.h:57
IntSetAnalyzer int_set
sub-analyzer: int set
Definition: analyzer.h:579
Analyzer to get constant integer bound over expression.
Definition: analyzer.h:115
Using previously specified knowns, compare the expressions provided.
Definition: analyzer.h:404
TVM_DECLARE_FINAL_OBJECT_INFO(ConstIntBoundNode, Object)
Managed reference to IntSetNode.
Definition: int_set.h:68
RewriteSimplifier rewrite_simplify
sub-analyzer rewrite simplify
Definition: analyzer.h:575
CanonicalSimplifier canonical_simplify
sub-analyzer canonical simplify
Definition: analyzer.h:577
Analyzer to get modular information over expression.
Definition: analyzer.h:214
int64_t base
The base.
Definition: analyzer.h:185
PrimExpr max(PrimExpr a, PrimExpr b, Span span=Span())
take maximum of two values
static const constexpr int64_t kNegInf
Number to represent -inf.
Definition: analyzer.h:88
TransitiveComparisonAnalyzer transitive_comparisons
sub-analyzer transitive comparisons
Definition: analyzer.h:581
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:713
RAII wrapper function to enter and exit a context object similar to python's with syntax...
Definition: with.h:58
DivMode
Definition: analyzer.h:55
Object & operator=(const Object &other)
Definition: object.h:251
Constraint context.
Definition: analyzer.h:476
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
Base class of all object reference.
Definition: object.h:511
Integer set analyzer.
Definition: analyzer.h:502
int64_t min_value
Definition: analyzer.h:70
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
ConstIntBoundAnalyzer const_int_bound
sub-analyzer: const integer bound
Definition: analyzer.h:571
static constexpr const char * _type_key
Definition: analyzer.h:90
Rewrite-rule based simplifier.
Definition: analyzer.h:252
ModularSetAnalyzer modular_set
sub-analyzer: modular set
Definition: analyzer.h:573
reference class to ConstIntBoundNode
Definition: analyzer.h:98
Reference to PrimExprNode.
Definition: expr.h:112
bool SEqualReduce(const ConstIntBoundNode *other, SEqualReducer equal) const
Definition: analyzer.h:78
Analyzer that contains bunch of sub-analyzers.
Definition: analyzer.h:563
CompareResult
Structure for representing result of known.
Definition: analyzer.h:380
RAII wrapper function to enter and exit a context object similar to python's with syntax...