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);
55void Appender::append(
const mlir::MemorySlot &a) {
56 stream <<
"ptr: " << a.ptr <<
"; type: " << a.elemType;
59void Appender::append(
const mlir::DestructurableMemorySlot &a) {
60 stream <<
"ptr: " << a.ptr <<
"; type: " << a.elemType <<
"; elementPtrs:\n";
61 for (
auto &p : a.elementPtrs) {
68void Appender::append(
const mlir::OpOperand &a) { stream << a.get(); }
70void Appender::append(
const mlir::NamedAttribute &a) {
71 stream << a.getName() <<
'=' << a.getValue();
74void Appender::append(
const mlir::SymbolTable::SymbolUse &a) { stream << a.getUser()->getName(); }
76template <
typename T>
inline void Appender::append(
const std::optional<T> &a) {
84template <
typename Any>
void Appender::append(
const Any &value) { stream << value; }
86template <
typename A,
typename B>
void Appender::append(
const std::pair<A, B> &a) {
94template <
typename A,
typename B>
void Appender::append(
const llvm::detail::DenseMapPair<A, B> &a) {
102template <Iterable InputIt>
inline void Appender::append(
const InputIt &collection) {
103 appendList(std::begin(collection), std::end(collection));
106template <
typename InputIt>
void Appender::appendList(InputIt begin, InputIt end) {
108 llvm::interleave(begin, end, [
this](
const auto &n) { append(n); }, [
this] { stream <<
", "; });
112template <
typename Any> Appender &Appender::operator<<(
const Any &v) {
121template <
typename InputIt>
inline std::string
toStringList(InputIt begin, InputIt end) {
123 Appender(output).appendList(begin, end);
129template <
typename InputIt>
inline std::string
toStringList(
const InputIt &collection) {
130 return toStringList(collection.begin(), collection.end());
133template <
typename InputIt>
134inline std::string
toStringList(
const std::optional<InputIt> &optionalCollection) {
135 if (optionalCollection.has_value()) {
142template <
typename T>
inline std::string
toStringOne(
const T &value) {
144 Appender(output).append(value);
150void dumpSymbolTable(llvm::raw_ostream &stream, mlir::SymbolTable &symTab,
unsigned indent = 0);
158void 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)
mlir::raw_ostream & operator<<(mlir::raw_ostream &os, const ConstrainRef &rhs)