24#ifndef TVM_SYM_CONSTRAINT_H_
25#define TVM_SYM_CONSTRAINT_H_
27#include <tvm/ffi/cast.h>
28#include <tvm/ffi/container/array.h>
54 explicit Constraint(ffi::ObjectPtr<ConstraintObj> node) : ffi::ObjectRef(std::move(node)) {}
76 namespace refl = ffi::reflection;
77 refl::ObjectDef<BindingConstraintObj>()
116 namespace refl = ffi::reflection;
117 refl::ObjectDef<RangeConstraintObj>()
158 namespace refl = ffi::reflection;
159 refl::ObjectDef<PredicateConstraintObj>()
202 : parent_(std::move(parent)), parent_prefix_size_(parent_prefix_size) {
203 TVM_FFI_CHECK(parent_ && 0 <= parent_prefix_size && parent_prefix_size <= parent_->
LocalSize(),
205 <<
"Constraint context parent local prefix is out of bounds";
222 int64_t
LocalSize()
const {
return constraints_.size(); }
247 template <
typename F>
250 auto context = ffi::GetObjectPtr<ConstraintContextObj>(
const_cast<ConstraintContextObj*
>(
this));
251 context->ForEach(context->LocalSize(), std::forward<F>(f));
272 ffi::Array<Constraint>
ToArray(int64_t local_prefix)
const {
274 if (local_prefix ==
LocalSize())
return constraints_;
275 return ffi::Array<Constraint>(constraints_.begin(), constraints_.begin() + local_prefix);
277 auto result = parent_->ToArray(parent_prefix_size_);
278 if (local_prefix != 0) {
279 result.insert(result.end(), constraints_.begin(), constraints_.begin() + local_prefix);
285 template <
typename F>
286 void ForEach(int64_t local_prefix, F&& f)
const {
287 if (parent_) parent_->ForEach(parent_prefix_size_, f);
288 for (int64_t i = 0; i < local_prefix; ++i) {
290 const Constraint constraint = constraints_[i];
296 const ffi::ObjectPtr<ConstraintContextObj> parent_;
298 const int64_t parent_prefix_size_{0};
300 ffi::Array<Constraint> constraints_;
323 : ffi::ObjectRef(std::move(node)) {}
Typed reference/view over any Expr whose ExprObj::ty is PrimType.
Definition expr.h:187
Range container
Definition expr.h:883
Managed reference to VarObj.
Definition expr.h:571
Coordinated symbolic analyses over an explicitly synchronized premise environment.
Definition analyzer.h:556
The value captured when a variable is bound. A mutable-read RHS is retained as data; it must not be r...
Definition constraint.h:62
BindingConstraintObj(Var var, PrimExpr value)
Definition constraint.h:64
BindingConstraintObj(ffi::UnsafeInit tag)
Definition constraint.h:65
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("sym.BindingConstraint", BindingConstraintObj, ConstraintObj)
Var var
The variable whose bound value is recorded.
Definition constraint.h:69
static void RegisterReflection()
Definition constraint.h:75
PrimExpr value
The RHS expression at the binding site, including any mutable reads.
Definition constraint.h:73
Managed reference to BindingConstraintObj.
Definition constraint.h:87
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(BindingConstraint, Constraint, BindingConstraintObj)
BindingConstraint(Var var, PrimExpr value)
Construct a premise from its fields, without inference.
Definition constraint.h:92
Tracks the constraints relevant to each point in a traversal.
Definition constraint.h:191
ConstraintContext Snapshot() const
Captures the constraints currently visible in this context. Later additions to this context do not af...
Definition constraint.h:328
void Append(const Constraint &constraint)
Append a premise locally, preserving every previously captured prefix.
Definition constraint.h:216
ConstraintContextObj()=default
Construct an empty root context.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("sym.ConstraintContext", ConstraintContextObj, ffi::Object)
static constexpr bool _type_mutable
Allow appending through a const context handle.
Definition constraint.h:264
ffi::Array< Constraint > ToArray() const
Returns an independent array of the constraints in this context. Includes inherited constraints in or...
Definition constraint.h:261
ConstraintContextObj(ffi::ObjectPtr< ConstraintContextObj > parent, int64_t parent_prefix_size)
Capture an inherited prefix and start an empty local sequence.
Definition constraint.h:201
ConstraintContextObj & operator=(const ConstraintContextObj &)=delete
static void RegisterReflection()
Register the context methods exposed through FFI reflection.
ConstraintContextObj(const ConstraintContextObj &)=delete
int64_t LocalSize() const
Count the local entries.
Definition constraint.h:222
void ForEach(F &&f) const
Read constraints in inherited/local order. Later appends do not enter this iteration....
Definition constraint.h:248
Managed reference to ConstraintContextObj. Copies share the same context.
Definition constraint.h:306
ConstraintContext(ffi::ObjectPtr< ConstraintContextObj > node)
Adopt a reference to a non-null context object.
Definition constraint.h:322
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ConstraintContext, ffi::ObjectRef, ConstraintContextObj)
ConstraintContext(ConstraintContext parent, int64_t parent_prefix_size)
Construct a child capturing [0, parent_prefix_size) of its parent's local entries....
Definition constraint.h:318
ConstraintContext()
Construct an empty root.
Definition constraint.h:309
Base node for a symbolic premise; it owns no analyzer state.
Definition constraint.h:40
TVM_FFI_DECLARE_OBJECT_INFO("sym.Constraint", ConstraintObj, ffi::Object)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition constraint.h:42
A binding, range, or predicate, without inference or normalization.
Definition constraint.h:49
Constraint(ffi::ObjectPtr< ConstraintObj > node)
Adopt an existing premise node.
Definition constraint.h:54
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Constraint, ffi::ObjectRef, ConstraintObj)
A boolean premise. Its validity and lifetime are supplied by the collector.
Definition constraint.h:140
PredicateConstraintObj(ffi::UnsafeInit tag)
Definition constraint.h:144
PredicateConstraintObj(PrimExpr condition, bool assume_always=false)
Definition constraint.h:142
bool assume_always
Whether to assume the predicate remains true throughout the active constraint scope,...
Definition constraint.h:155
PrimExpr condition
The boolean predicate supplied by the collector.
Definition constraint.h:148
static void RegisterReflection()
Definition constraint.h:157
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("sym.PredicateConstraint", PredicateConstraintObj, ConstraintObj)
Managed reference to PredicateConstraintObj.
Definition constraint.h:170
PredicateConstraint(PrimExpr condition, bool assume_always=false)
Construct a premise from its fields, without inference.
Definition constraint.h:175
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(PredicateConstraint, Constraint, PredicateConstraintObj)
A variable lies in a half-open range. The range need not enumerate every attainable value.
Definition constraint.h:102
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("sym.RangeConstraint", RangeConstraintObj, ConstraintObj)
Range range
A half-open superset of the variable's possible values.
Definition constraint.h:113
RangeConstraintObj(ffi::UnsafeInit tag)
Definition constraint.h:105
static void RegisterReflection()
Definition constraint.h:115
Var var
The variable whose possible values lie in the range.
Definition constraint.h:109
RangeConstraintObj(Var var, Range range)
Definition constraint.h:104
Managed reference to RangeConstraintObj.
Definition constraint.h:127
RangeConstraint(Var var, Range range)
Construct a premise from its fields, without inference.
Definition constraint.h:132
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RangeConstraint, Constraint, RangeConstraintObj)
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41