12#include <mlir/IR/Attributes.h>
13#include <mlir/IR/Operation.h>
14#include <mlir/IR/SymbolTable.h>
15#include <mlir/IR/Value.h>
16#include <mlir/Interfaces/MemorySlotInterfaces.h>
18#include <llvm/ADT/DenseMap.h>
19#include <llvm/Support/raw_ostream.h>
37 llvm::raw_string_ostream stream;
38 Appender(std::string &out) : stream(out) {}
40 void append(
const mlir::MemorySlot &a);
41 void append(
const mlir::DestructurableMemorySlot &a);
42 void append(
const mlir::OpOperand &a);
43 void append(
const mlir::NamedAttribute &a);
44 void append(
const mlir::SymbolTable::SymbolUse &a);
45 template <
typename T>
void append(
const std::optional<T> &a);
46 template <
typename Any>
void append(
const Any &value);
47 template <
typename A,
typename B>
void append(
const std::pair<A, B> &a);
48 template <
typename A,
typename B>
void append(
const llvm::detail::DenseMapPair<A, B> &a);
49 template <Iterable InputIt>
void append(
const InputIt &collection);
50 template <
typename InputIt>
void appendList(InputIt begin, InputIt end);
51 template <
typename Any> Appender &
operator<<(
const Any &v);
55void Appender::append(
const mlir::MemorySlot &a) {
56 stream <<
"ptr: " << a.ptr <<
"; type: " << a.elemType;
60void Appender::append(
const mlir::DestructurableMemorySlot &a) {
61 stream <<
"ptr: " << a.ptr <<
"; type: " << a.elemType <<
"; subelementTypes:\n";
62 for (
auto &p : a.subelementTypes) {
70void Appender::append(
const mlir::OpOperand &a) {
75void Appender::append(
const mlir::NamedAttribute &a) {
76 stream << a.getName() <<
'=' << a.getValue();
80void Appender::append(
const mlir::SymbolTable::SymbolUse &a) {
81 stream << a.getUser()->getName();
86inline void Appender::append(
const std::optional<T> &a) {
94template <
typename Any>
96void Appender::append(
const Any &value) {
100template <
typename A,
typename B>
102void Appender::append(
const std::pair<A, B> &a) {
110template <
typename A,
typename B>
112void Appender::append(
const llvm::detail::DenseMapPair<A, B> &a) {
120template <Iterable InputIt>
122inline void Appender::append(
const InputIt &collection) {
123 appendList(std::begin(collection), std::end(collection));
126template <
typename InputIt>
128void Appender::appendList(InputIt begin, InputIt end) {
130 llvm::interleave(begin, end, [
this](
const auto &n) { this->append(n); }, [
this] {
131 this->stream <<
", ";
136template <
typename Any>
138Appender &Appender::operator<<(
const Any &v) {
147template <
typename InputIt>
151 Appender(output).appendList(begin, end);
157template <
typename InputIt>
160 return toStringList(collection.begin(), collection.end());
163template <
typename InputIt>
165inline std::string
toStringList(
const std::optional<InputIt> &optionalCollection) {
166 if (optionalCollection.has_value()) {
177 Appender(output).append(value);
185void dumpSymbolTable(llvm::raw_ostream &stream, mlir::SymbolTable &symTab,
unsigned indent = 0);
197void dumpToFile(mlir::Operation *op, llvm::StringRef filename);
std::string toStringOne(const T &value)
std::string toStringList(InputIt begin, InputIt end)
Generate a comma-separated string representation by traversing elements from begin to end where the e...
void dumpSymbolTable(llvm::raw_ostream &stream, SymbolTable &symTab, unsigned indent)
void dumpSymbolTables(llvm::raw_ostream &stream, SymbolTableCollection &tables)
void dumpSymbolTableWalk(Operation *symbolTableOp)
void dumpToFile(Operation *op, llvm::StringRef filename)
Interval operator<<(const Interval &lhs, const Interval &rhs)