tvm
Loading...
Searching...
No Matches
object_functor_with_constraint_context.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_TIRX_OBJECT_FUNCTOR_WITH_CONSTRAINT_CONTEXT_H_
25#define TVM_TIRX_OBJECT_FUNCTOR_WITH_CONSTRAINT_CONTEXT_H_
26
29
30namespace tvm {
31namespace tirx {
41 public:
45
49 virtual ffi::Optional<ffi::VisitInterrupt> Visit(ffi::AnyView value);
50 ffi::Expected<ffi::Optional<ffi::VisitInterrupt>> VisitExpected(ffi::AnyView value) noexcept {
51 try {
52 return Visit(value);
53 } catch (ffi::Error& error) {
54 return ffi::Unexpected(std::move(error));
55 } catch (const std::exception& error) {
56 return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
57 }
58 }
59
60 protected:
62 const ffi::Object*, ObjectVisitorWithConstraintContext*)>;
63
65 : StructuralVisitorWithConstraintContextObj(StructuralVTable()), native_vtable_(table) {}
66
67 static void InitVTable(VTable* table) {}
68
69 template <typename Self, typename Node>
70 static void SetDispatch(VTable* table) {
71 table->SetDispatch<Node>([](const ffi::Object* node, ObjectVisitorWithConstraintContext* self) {
72 return static_cast<Self*>(self)->Visit_(static_cast<const Node*>(node));
73 });
74 }
75
76 private:
77 static const VTable* GlobalVTable();
78 static const ffi::StructuralVisitorVTable* StructuralVTable();
79 const VTable* const native_vtable_;
80};
81
90 : public ffi::detail::StructuralMutatorEngineBase<StructuralMutatorWithConstraintContextObj> {
91 using EngineBase =
92 ffi::detail::StructuralMutatorEngineBase<StructuralMutatorWithConstraintContextObj>;
93
94 public:
98
102 virtual ffi::UnchangedOr<ffi::Any> Mutate(ffi::AnyView value,
103 ffi::InplaceMode mode = ffi::InplaceMode::kDisallow);
104 ffi::Expected<ffi::UnchangedOr<ffi::Any>> MutateExpected(
105 ffi::AnyView value, ffi::InplaceMode mode = ffi::InplaceMode::kDisallow) noexcept {
106 try {
107 return Mutate(value, mode);
108 } catch (ffi::Error& error) {
109 return ffi::Unexpected(std::move(error));
110 } catch (const std::exception& error) {
111 return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
112 }
113 }
114
115 protected:
117 const ffi::Object*, ObjectMutatorWithConstraintContext*, ffi::InplaceMode)>;
118
120 : EngineBase(StructuralVTable()), native_vtable_(table) {}
121
122 static void InitVTable(VTable* table) {}
123
124 template <typename Self, typename Node>
125 static void SetDispatch(VTable* table) {
126 table->SetDispatch<Node>([](const ffi::Object* node, ObjectMutatorWithConstraintContext* self,
127 ffi::InplaceMode mode) -> ffi::UnchangedOr<ffi::Any> {
128 return static_cast<Self*>(self)->Mutate_(static_cast<const Node*>(node), mode);
129 });
130 }
131
132 private:
133 static const VTable* GlobalVTable();
134 static const ffi::StructuralMutatorVTable* StructuralVTable();
135 const VTable* const native_vtable_;
136};
137
138} // namespace tirx
139} // namespace tvm
140#endif // TVM_TIRX_OBJECT_FUNCTOR_WITH_CONSTRAINT_CONTEXT_H_
#define TVM_TIRX_DLL
Definition base.h:55
A dynamically dispatched functor on the type of the first argument.
Definition object_functor.h:85
Native object mutation over one constraint-aware engine and variable remap.
Definition object_functor_with_constraint_context.h:90
static void SetDispatch(VTable *table)
Definition object_functor_with_constraint_context.h:125
static void InitVTable(VTable *table)
Definition object_functor_with_constraint_context.h:122
ObjectMutatorWithConstraintContext & operator=(const ObjectMutatorWithConstraintContext &)=delete
virtual ffi::UnchangedOr< ffi::Any > Mutate(ffi::AnyView value, ffi::InplaceMode mode=ffi::InplaceMode::kDisallow)
Dispatch a borrowed value after checking mutation permission and uniqueness.
ObjectMutatorWithConstraintContext(const ObjectMutatorWithConstraintContext &)=delete
ffi::Expected< ffi::UnchangedOr< ffi::Any > > MutateExpected(ffi::AnyView value, ffi::InplaceMode mode=ffi::InplaceMode::kDisallow) noexcept
Definition object_functor_with_constraint_context.h:104
ObjectMutatorWithConstraintContext()
Definition object_functor_with_constraint_context.h:95
ObjectMutatorWithConstraintContext(const VTable *table)
Definition object_functor_with_constraint_context.h:119
Native object dispatch over one constraint-aware structural visitor.
Definition object_functor_with_constraint_context.h:40
virtual ffi::Optional< ffi::VisitInterrupt > Visit(ffi::AnyView value)
Dispatch a borrowed value, preserving structural error context.
static void InitVTable(VTable *table)
Definition object_functor_with_constraint_context.h:67
ObjectVisitorWithConstraintContext(const ObjectVisitorWithConstraintContext &)=delete
ffi::Expected< ffi::Optional< ffi::VisitInterrupt > > VisitExpected(ffi::AnyView value) noexcept
Definition object_functor_with_constraint_context.h:50
ObjectVisitorWithConstraintContext & operator=(const ObjectVisitorWithConstraintContext &)=delete
ObjectVisitorWithConstraintContext()
Definition object_functor_with_constraint_context.h:42
static void SetDispatch(VTable *table)
Definition object_functor_with_constraint_context.h:70
ObjectVisitorWithConstraintContext(const VTable *table)
Definition object_functor_with_constraint_context.h:64
Visits values using their structural visit behavior while maintaining the constraint context relevant...
Definition structural_visit_with_constraint_context.h:38
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41
Native object dispatch, visiting and mutation with structural fallback.
Structural mutation with lexical symbolic premises.