38 _top = std::move(_rest.back());
45 _rest.push_back(std::move(_top));
68 return _empty ? 0 : (_rest.size() + 1);
93 template<
typename T =
void>
96 std::map<std::string, SmallStack<T>> table;
98 const Scope<T> *containing_scope =
nullptr;
114 containing_scope = s;
126 template<
typename T2 = T,
127 typename =
typename std::enable_if<!std::is_same<T2, void>::value>::type>
128 T2
get(
const std::string &name)
const {
130 if (iter ==
table.end() || iter->second.empty()) {
131 if (containing_scope) {
132 return containing_scope->
get(name);
138 return iter->second.top();
142 template<
typename T2 = T,
143 typename =
typename std::enable_if<!std::is_same<T2, void>::value>::type>
144 T2 &
ref(
const std::string &name) {
145 typename std::map<std::string, SmallStack<T>>::iterator iter =
table.find(name);
146 if (iter ==
table.end() || iter->second.empty()) {
150 return iter->second.top_ref();
156 if (iter ==
table.end() || iter->second.empty()) {
157 if (containing_scope) {
158 return containing_scope->
contains(name);
167 size_t count(
const std::string &name)
const {
168 auto it =
table.find(name);
169 if (it ==
table.end()) {
172 return it->second.size();
179 template<
typename T2 = T,
180 typename =
typename std::enable_if<!std::is_same<T2, void>::value>::type>
181 void push(
const std::string &name, T2 &&value) {
182 table[name].push(std::forward<T2>(value));
185 template<
typename T2 = T,
186 typename =
typename std::enable_if<std::is_same<T2, void>::value>::type>
187 void push(
const std::string &name) {
194 void pop(
const std::string &name) {
195 typename std::map<std::string, SmallStack<T>>::iterator iter =
table.find(name);
199 if (iter->second.empty()) {
216 return iter != other.iter;
231 template<
typename T2 = T,
232 typename =
typename std::enable_if<!std::is_same<T2, void>::value>::type>
234 return iter->second.top_ref();
247 table.swap(other.table);
248 std::swap(containing_scope, other.containing_scope);
256 for (iter = s.
cbegin(); iter != s.
cend(); ++iter) {
257 stream <<
" " << iter.
name() <<
"\n";
271 template<
typename T =
void>
284 :
scope(condition ? &s : nullptr),
name(n) {
291 return scope !=
nullptr;
304 name(std::move(that.name)) {
306 that.scope =
nullptr;
322 :
scope(condition ? &s : nullptr),
name(n) {
337 name(std::move(that.name)) {
339 that.scope =
nullptr;
Defines functions for debug logging during code generation.
#define internal_assert(c)
Iterate through the scope.
bool operator!=(const const_iterator &other)
const std::string & name()
const_iterator(const typename std::map< std::string, SmallStack< T >>::const_iterator &i)
const SmallStack< T > & stack()
A common pattern when traversing Halide IR is that you need to keep track of stuff when you find a Le...
Scope< T > & operator=(const Scope< T > &)=delete
Scope(const Scope< T > &)=delete
Scope(Scope &&that) noexcept=default
void push(const std::string &name, T2 &&value)
Add a new (name, value) pair to the current scope.
void swap(Scope< T > &other)
T2 get(const std::string &name) const
Retrieve the value referred to by a name.
size_t count(const std::string &name) const
How many nested definitions of a single name exist?
const_iterator cbegin() const
static const Scope< T > & empty_scope()
A const ref to an empty scope.
bool contains(const std::string &name) const
Tests if a name is in scope.
void push(const std::string &name)
Scope & operator=(Scope &&that) noexcept=default
const_iterator cend() const
void set_containing_scope(const Scope< T > *s)
Set the parent scope.
T2 & ref(const std::string &name)
Return a reference to an entry.
void pop(const std::string &name)
A name goes out of scope.
A stack which can store one item very efficiently.
const T & top_ref() const
std::ostream & operator<<(std::ostream &stream, const Stmt &)
Emit a halide statement on an output stream (such as std::cout) in a human-readable form.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
ScopedBinding(const ScopedBinding &that)=delete
void operator=(const ScopedBinding &that)=delete
ScopedBinding(bool condition, Scope<> &s, const std::string &n)
ScopedBinding(Scope<> &s, const std::string &n)
void operator=(ScopedBinding &&that)=delete
ScopedBinding(ScopedBinding &&that) noexcept
Helper class for pushing/popping Scope<> values, to allow for early-exit in Visitor/Mutators that pre...
void operator=(const ScopedBinding &that)=delete
ScopedBinding(Scope< T > &s, const std::string &n, T value)
ScopedBinding(const ScopedBinding &that)=delete
ScopedBinding(bool condition, Scope< T > &s, const std::string &n, const T &value)
ScopedBinding(ScopedBinding &&that) noexcept
void operator=(ScopedBinding &&that)=delete