25#ifndef TVM_IR_WITH_CONTEXT_H_
26#define TVM_IR_WITH_CONTEXT_H_
57template <
typename ContextType>
64 template <
typename... Args>
65 explicit With(Args&&... args) : ctx_(std::forward<Args>(args)...) {
66 ctx_.EnterWithScope();
69 ~With() noexcept(false) { ctx_.ExitWithScope(); }
80 ContextType*
get() {
return &ctx_; }
81 const ContextType*
get()
const {
return &ctx_; }
112template <
typename ContextType>
125 template <
typename... Args>
127 entries_.push_back(std::make_unique<
With<ContextType>>(std::forward<Args>(args)...));
131 size_t size()
const {
return entries_.size(); }
144 bool unwinding = std::uncaught_exceptions() > 0;
145 std::exception_ptr first_exc;
146 while (!entries_.empty()) {
149 auto entry = std::move(entries_.back());
154 if (!unwinding && !first_exc) {
155 first_exc = std::current_exception();
159 if (first_exc) std::rethrow_exception(first_exc);
163 std::vector<std::unique_ptr<With<ContextType>>> entries_;
A group of RAII contexts managed together.
Definition with_context.h:113
~WithGroup() noexcept(false)
Destructor — exits all contexts in reverse order.
Definition with_context.h:143
WithGroup(const WithGroup &)=delete
WithGroup & operator=(const WithGroup &)=delete
void Emplace(Args &&... args)
Construct a context and enter its scope.
Definition with_context.h:126
WithGroup & operator=(WithGroup &&)=default
WithGroup(WithGroup &&)=default
size_t size() const
Number of active contexts in this group.
Definition with_context.h:131
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:58
const ContextType & operator*() const
Definition with_context.h:86
With(Args &&... args)
constructor. Enter the scope of the context.
Definition with_context.h:65
With(With &&other)=delete
ContextType * operator->()
Definition with_context.h:83
ContextType operator()()
Definition with_context.h:88
With(const With &other)=delete
const ContextType * get() const
Definition with_context.h:81
~With() noexcept(false)
destructor, leaves the scope of the context.
Definition with_context.h:69
ContextType & operator*()
Definition with_context.h:85
With & operator=(With &&other)=delete
const ContextType * operator->() const
Definition with_context.h:84
ContextType * get()
Definition with_context.h:80
With & operator=(const With &other)=delete
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41