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>
38 llvm::raw_string_ostream stream;
39 Appender(std::string &out) : stream(out) {}
41 void append(
const mlir::MemorySlot &a);
42 void append(
const mlir::DestructurableMemorySlot &a);
43 void append(
const mlir::OpOperand &a);
44 void append(
const mlir::NamedAttribute &a);
45 void append(
const mlir::SymbolTable::SymbolUse &a);
46 template <
typename T>
void append(
const std::optional<T> &a);
47 template <
typename Any>
void append(
const Any &value);
48 template <
typename A,
typename B>
void append(
const std::pair<A, B> &a);
49 template <
typename A,
typename B>
void append(
const llvm::detail::DenseMapPair<A, B> &a);
50 template <Iterable InputIt>
void append(
const InputIt &collection);
51 template <
typename InputIt>
void appendList(InputIt begin, InputIt end);
52 template <
typename Any> Appender &
operator<<(
const Any &v);
56void Appender::append(
const mlir::MemorySlot &a) {
57 stream <<
"ptr: " << a.ptr <<
"; type: " << a.elemType;
61void Appender::append(
const mlir::DestructurableMemorySlot &a) {
62 stream <<
"ptr: " << a.ptr <<
"; type: " << a.elemType <<
"; elementPtrs:\n";
63 for (
auto &p : a.elementPtrs) {
71void Appender::append(
const mlir::OpOperand &a) {
76void Appender::append(
const mlir::NamedAttribute &a) {
77 stream << a.getName() <<
'=' << a.getValue();
81void Appender::append(
const mlir::SymbolTable::SymbolUse &a) {
82 stream << a.getUser()->getName();
87inline void Appender::append(
const std::optional<T> &a) {
95template <
typename Any>
97void Appender::append(
const Any &value) {
101template <
typename A,
typename B>
103void Appender::append(
const std::pair<A, B> &a) {
111template <
typename A,
typename B>
113void Appender::append(
const llvm::detail::DenseMapPair<A, B> &a) {
121template <Iterable InputIt>
123inline void Appender::append(
const InputIt &collection) {
124 appendList(std::begin(collection), std::end(collection));
127template <
typename InputIt>
129void Appender::appendList(InputIt begin, InputIt end) {
131 llvm::interleave(begin, end, [
this](
const auto &n) { this->append(n); }, [
this] {
132 this->stream <<
", ";
137template <
typename Any>
139Appender &Appender::operator<<(
const Any &v) {
148template <
typename InputIt>
152 Appender(output).appendList(begin, end);
158template <
typename InputIt>
161 return toStringList(collection.begin(), collection.end());
164template <
typename InputIt>
166inline std::string
toStringList(
const std::optional<InputIt> &optionalCollection) {
167 if (optionalCollection.has_value()) {
178 Appender(output).append(value);
186void dumpSymbolTable(llvm::raw_ostream &stream, mlir::SymbolTable &symTab,
unsigned indent = 0);
198void 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)
raw_ostream & operator<<(raw_ostream &os, const ConstrainRef &rhs)