#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/AsmState.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinDialect.h"
#include "mlir/IR/BuiltinTypeInterfaces.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/DialectResourceBlobManager.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/Verifier.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/ScopedHashTable.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/raw_ostream.h"
#include <type_traits>
#include <optional>
#include <tuple>
usingnamespacemlir;
usingnamespacemlir::detail;
#define DEBUG_TYPE …
void OperationName::print(raw_ostream &os) const { … }
void OperationName::dump() const { … }
AsmParser::~AsmParser() = default;
DialectAsmParser::~DialectAsmParser() = default;
OpAsmParser::~OpAsmParser() = default;
MLIRContext *AsmParser::getContext() const { … }
ParseResult AsmParser::parseTypeList(SmallVectorImpl<Type> &result) { … }
DialectAsmPrinter::~DialectAsmPrinter() = default;
OpAsmPrinter::~OpAsmPrinter() = default;
void OpAsmPrinter::printFunctionalType(Operation *op) { … }
#include "mlir/IR/OpAsmInterface.cpp.inc"
LogicalResult
OpAsmDialectInterface::parseResource(AsmParsedResourceEntry &entry) const { … }
namespace {
struct AsmPrinterOptions { … };
}
static llvm::ManagedStatic<AsmPrinterOptions> clOptions;
void mlir::registerAsmPrinterCLOptions() { … }
OpPrintingFlags::OpPrintingFlags()
: … { … }
OpPrintingFlags &
OpPrintingFlags::elideLargeElementsAttrs(int64_t largeElementLimit) { … }
OpPrintingFlags &
OpPrintingFlags::printLargeElementsAttrWithHex(int64_t largeElementLimit) { … }
OpPrintingFlags &
OpPrintingFlags::elideLargeResourceString(int64_t largeResourceLimit) { … }
OpPrintingFlags &OpPrintingFlags::enableDebugInfo(bool enable,
bool prettyForm) { … }
OpPrintingFlags &OpPrintingFlags::printGenericOpForm(bool enable) { … }
OpPrintingFlags &OpPrintingFlags::skipRegions(bool skip) { … }
OpPrintingFlags &OpPrintingFlags::assumeVerified() { … }
OpPrintingFlags &OpPrintingFlags::useLocalScope() { … }
OpPrintingFlags &OpPrintingFlags::printValueUsers() { … }
bool OpPrintingFlags::shouldElideElementsAttr(ElementsAttr attr) const { … }
bool OpPrintingFlags::shouldPrintElementsAttrWithHex(ElementsAttr attr) const { … }
std::optional<int64_t> OpPrintingFlags::getLargeElementsAttrLimit() const { … }
int64_t OpPrintingFlags::getLargeElementsAttrHexLimit() const { … }
std::optional<uint64_t> OpPrintingFlags::getLargeResourceStringLimit() const { … }
bool OpPrintingFlags::shouldPrintDebugInfo() const { … }
bool OpPrintingFlags::shouldPrintDebugInfoPrettyForm() const { … }
bool OpPrintingFlags::shouldPrintGenericOpForm() const { … }
bool OpPrintingFlags::shouldSkipRegions() const { … }
bool OpPrintingFlags::shouldAssumeVerified() const { … }
bool OpPrintingFlags::shouldUseLocalScope() const { … }
bool OpPrintingFlags::shouldPrintValueUsers() const { … }
bool OpPrintingFlags::shouldPrintUniqueSSAIDs() const { … }
namespace {
struct NewLineCounter { … };
static raw_ostream &operator<<(raw_ostream &os, NewLineCounter &newLine) { … }
}
namespace mlir {
class AsmPrinter::Impl { … };
}
namespace {
class SymbolAlias { … };
class AliasInitializer { … };
class DummyAliasOperationPrinter : private OpAsmPrinter { … };
class DummyAliasDialectAsmPrinter : public DialectAsmPrinter { … };
}
static StringRef sanitizeIdentifier(StringRef name, SmallString<16> &buffer,
StringRef allowedPunctChars = "$._-",
bool allowTrailingDigit = true) { … }
void AliasInitializer::initializeAliases(
llvm::MapVector<const void *, InProgressAliasInfo> &visitedSymbols,
llvm::MapVector<const void *, SymbolAlias> &symbolToAlias) { … }
void AliasInitializer::initialize(
Operation *op, const OpPrintingFlags &printerFlags,
llvm::MapVector<const void *, SymbolAlias> &attrTypeToAlias) { … }
template <typename T, typename... PrintArgs>
std::pair<size_t, size_t> AliasInitializer::visitImpl(
T value, llvm::MapVector<const void *, InProgressAliasInfo> &aliases,
bool canBeDeferred, PrintArgs &&...printArgs) { … }
void AliasInitializer::markAliasNonDeferrable(size_t aliasIndex) { … }
template <typename T>
void AliasInitializer::generateAlias(T symbol, InProgressAliasInfo &alias,
bool canBeDeferred) { … }
namespace {
class AliasState { … };
}
void AliasState::initialize(
Operation *op, const OpPrintingFlags &printerFlags,
DialectInterfaceCollection<OpAsmDialectInterface> &interfaces) { … }
LogicalResult AliasState::getAlias(Attribute attr, raw_ostream &os) const { … }
LogicalResult AliasState::getAlias(Type ty, raw_ostream &os) const { … }
void AliasState::printAliases(AsmPrinter::Impl &p, NewLineCounter &newLine,
bool isDeferred) { … }
namespace {
struct BlockInfo { … };
class SSANameState { … };
}
SSANameState::SSANameState(Operation *op, const OpPrintingFlags &printerFlags)
: … { … }
void SSANameState::printValueID(Value value, bool printResultNo,
raw_ostream &stream) const { … }
void SSANameState::printOperationID(Operation *op, raw_ostream &stream) const { … }
ArrayRef<int> SSANameState::getOpResultGroups(Operation *op) { … }
BlockInfo SSANameState::getBlockInfo(Block *block) { … }
void SSANameState::shadowRegionArgs(Region ®ion, ValueRange namesToUse) { … }
void SSANameState::numberValuesInRegion(Region ®ion) { … }
void SSANameState::numberValuesInBlock(Block &block) { … }
void SSANameState::numberValuesInOp(Operation &op) { … }
void SSANameState::getResultIDAndNumber(
OpResult result, Value &lookupValue,
std::optional<int> &lookupResultNo) const { … }
void SSANameState::setValueName(Value value, StringRef name) { … }
StringRef SSANameState::uniqueValueName(StringRef name) { … }
namespace {
class DistinctState { … };
}
uint64_t DistinctState::getId(DistinctAttr distinctAttr) { … }
AsmParsedResourceEntry::~AsmParsedResourceEntry() = default;
AsmResourceBuilder::~AsmResourceBuilder() = default;
AsmResourceParser::~AsmResourceParser() = default;
AsmResourcePrinter::~AsmResourcePrinter() = default;
StringRef mlir::toString(AsmResourceEntryKind kind) { … }
AsmResourceParser &FallbackAsmResourceMap::getParserFor(StringRef key) { … }
std::vector<std::unique_ptr<AsmResourcePrinter>>
FallbackAsmResourceMap::getPrinters() { … }
LogicalResult FallbackAsmResourceMap::ResourceCollection::parseResource(
AsmParsedResourceEntry &entry) { … }
void FallbackAsmResourceMap::ResourceCollection::buildResources(
Operation *op, AsmResourceBuilder &builder) const { … }
namespace mlir {
namespace detail {
class AsmStateImpl { … };
template <typename Range>
void printDimensionList(raw_ostream &stream, Range &&shape) { … }
}
}
static OpPrintingFlags verifyOpAndAdjustFlags(Operation *op,
OpPrintingFlags printerFlags) { … }
AsmState::AsmState(Operation *op, const OpPrintingFlags &printerFlags,
LocationMap *locationMap, FallbackAsmResourceMap *map)
: … { … }
AsmState::AsmState(MLIRContext *ctx, const OpPrintingFlags &printerFlags,
LocationMap *locationMap, FallbackAsmResourceMap *map)
: … { … }
AsmState::~AsmState() = default;
const OpPrintingFlags &AsmState::getPrinterFlags() const { … }
void AsmState::attachResourcePrinter(
std::unique_ptr<AsmResourcePrinter> printer) { … }
DenseMap<Dialect *, SetVector<AsmDialectResourceHandle>> &
AsmState::getDialectResources() const { … }
AsmPrinter::Impl::Impl(raw_ostream &os, AsmStateImpl &state)
: … { … }
void AsmPrinter::Impl::printTrailingLocation(Location loc, bool allowAlias) { … }
void AsmPrinter::Impl::printLocationInternal(LocationAttr loc, bool pretty,
bool isTopLevel) { … }
static void printFloatValue(const APFloat &apValue, raw_ostream &os,
bool *printedHex = nullptr) { … }
void AsmPrinter::Impl::printLocation(LocationAttr loc, bool allowAlias) { … }
void AsmPrinter::Impl::printResourceHandle(
const AsmDialectResourceHandle &resource) { … }
static bool isDialectSymbolSimpleEnoughForPrettyForm(StringRef symName) { … }
static void printDialectSymbol(raw_ostream &os, StringRef symPrefix,
StringRef dialectName, StringRef symString) { … }
static bool isBareIdentifier(StringRef name) { … }
static void printKeywordOrString(StringRef keyword, raw_ostream &os) { … }
static void printSymbolReference(StringRef symbolRef, raw_ostream &os) { … }
static void printElidedElementsAttr(raw_ostream &os) { … }
LogicalResult AsmPrinter::Impl::printAlias(Attribute attr) { … }
LogicalResult AsmPrinter::Impl::printAlias(Type type) { … }
void AsmPrinter::Impl::printAttribute(Attribute attr,
AttrTypeElision typeElision) { … }
void AsmPrinter::Impl::printAttributeImpl(Attribute attr,
AttrTypeElision typeElision) { … }
static void printDenseIntElement(const APInt &value, raw_ostream &os,
Type type) { … }
static void
printDenseElementsAttrImpl(bool isSplat, ShapedType type, raw_ostream &os,
function_ref<void(unsigned)> printEltFn) { … }
void AsmPrinter::Impl::printDenseElementsAttr(DenseElementsAttr attr,
bool allowHex) { … }
void AsmPrinter::Impl::printDenseIntOrFPElementsAttr(
DenseIntOrFPElementsAttr attr, bool allowHex) { … }
void AsmPrinter::Impl::printDenseStringElementsAttr(
DenseStringElementsAttr attr) { … }
void AsmPrinter::Impl::printDenseArrayAttr(DenseArrayAttr attr) { … }
void AsmPrinter::Impl::printType(Type type) { … }
void AsmPrinter::Impl::printTypeImpl(Type type) { … }
void AsmPrinter::Impl::printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
ArrayRef<StringRef> elidedAttrs,
bool withKeyword) { … }
void AsmPrinter::Impl::printNamedAttribute(NamedAttribute attr) { … }
void AsmPrinter::Impl::printDialectAttribute(Attribute attr) { … }
void AsmPrinter::Impl::printDialectType(Type type) { … }
void AsmPrinter::Impl::printEscapedString(StringRef str) { … }
void AsmPrinter::Impl::printHexString(StringRef str) { … }
void AsmPrinter::Impl::printHexString(ArrayRef<char> data) { … }
LogicalResult AsmPrinter::Impl::pushCyclicPrinting(const void *opaquePointer) { … }
void AsmPrinter::Impl::popCyclicPrinting() { … }
void AsmPrinter::Impl::printDimensionList(ArrayRef<int64_t> shape) { … }
AsmPrinter::~AsmPrinter() = default;
raw_ostream &AsmPrinter::getStream() const { … }
void AsmPrinter::printFloat(const APFloat &value) { … }
void AsmPrinter::printType(Type type) { … }
void AsmPrinter::printAttribute(Attribute attr) { … }
LogicalResult AsmPrinter::printAlias(Attribute attr) { … }
LogicalResult AsmPrinter::printAlias(Type type) { … }
void AsmPrinter::printAttributeWithoutType(Attribute attr) { … }
void AsmPrinter::printKeywordOrString(StringRef keyword) { … }
void AsmPrinter::printString(StringRef keyword) { … }
void AsmPrinter::printSymbolName(StringRef symbolRef) { … }
void AsmPrinter::printResourceHandle(const AsmDialectResourceHandle &resource) { … }
void AsmPrinter::printDimensionList(ArrayRef<int64_t> shape) { … }
LogicalResult AsmPrinter::pushCyclicPrinting(const void *opaquePointer) { … }
void AsmPrinter::popCyclicPrinting() { … }
void AsmPrinter::Impl::printAffineExpr(
AffineExpr expr, function_ref<void(unsigned, bool)> printValueName) { … }
void AsmPrinter::Impl::printAffineExprInternal(
AffineExpr expr, BindingStrength enclosingTightness,
function_ref<void(unsigned, bool)> printValueName) { … }
void AsmPrinter::Impl::printAffineConstraint(AffineExpr expr, bool isEq) { … }
void AsmPrinter::Impl::printAffineMap(AffineMap map) { … }
void AsmPrinter::Impl::printIntegerSet(IntegerSet set) { … }
namespace {
class OperationPrinter : public AsmPrinter::Impl, private OpAsmPrinter { … };
}
void OperationPrinter::printTopLevelOperation(Operation *op) { … }
void OperationPrinter::printFileMetadataDictionary(Operation *op) { … }
void OperationPrinter::printResourceFileMetadata(
function_ref<void()> checkAddMetadataDict, Operation *op) { … }
void OperationPrinter::printRegionArgument(BlockArgument arg,
ArrayRef<NamedAttribute> argAttrs,
bool omitType) { … }
void OperationPrinter::printFullOpWithIndentAndLoc(Operation *op) { … }
void OperationPrinter::printFullOp(Operation *op) { … }
void OperationPrinter::printUsersComment(Operation *op) { … }
void OperationPrinter::printUsersComment(BlockArgument arg) { … }
void OperationPrinter::printValueUsers(Value value) { … }
void OperationPrinter::printUserIDs(Operation *user, bool prefixComma) { … }
void OperationPrinter::printCustomOrGenericOp(Operation *op) { … }
void OperationPrinter::printGenericOp(Operation *op, bool printOpName) { … }
void OperationPrinter::printBlockName(Block *block) { … }
void OperationPrinter::print(Block *block, bool printBlockArgs,
bool printBlockTerminator) { … }
void OperationPrinter::printValueID(Value value, bool printResultNo,
raw_ostream *streamOverride) const { … }
void OperationPrinter::printOperationID(Operation *op,
raw_ostream *streamOverride) const { … }
void OperationPrinter::printSuccessor(Block *successor) { … }
void OperationPrinter::printSuccessorAndUseList(Block *successor,
ValueRange succOperands) { … }
void OperationPrinter::printRegion(Region ®ion, bool printEntryBlockArgs,
bool printBlockTerminators,
bool printEmptyBlock) { … }
void OperationPrinter::printAffineMapOfSSAIds(AffineMapAttr mapAttr,
ValueRange operands) { … }
void OperationPrinter::printAffineExprOfSSAIds(AffineExpr expr,
ValueRange dimOperands,
ValueRange symOperands) { … }
void Attribute::print(raw_ostream &os, bool elideType) const { … }
void Attribute::print(raw_ostream &os, AsmState &state, bool elideType) const { … }
void Attribute::dump() const { … }
void Attribute::printStripped(raw_ostream &os, AsmState &state) const { … }
void Attribute::printStripped(raw_ostream &os) const { … }
void Type::print(raw_ostream &os) const { … }
void Type::print(raw_ostream &os, AsmState &state) const { … }
void Type::dump() const { … }
void AffineMap::dump() const { … }
void IntegerSet::dump() const { … }
void AffineExpr::print(raw_ostream &os) const { … }
void AffineExpr::dump() const { … }
void AffineMap::print(raw_ostream &os) const { … }
void IntegerSet::print(raw_ostream &os) const { … }
void Value::print(raw_ostream &os) const { … }
void Value::print(raw_ostream &os, const OpPrintingFlags &flags) const { … }
void Value::print(raw_ostream &os, AsmState &state) const { … }
void Value::dump() const { … }
void Value::printAsOperand(raw_ostream &os, AsmState &state) const { … }
static Operation *findParent(Operation *op, bool shouldUseLocalScope) { … }
void Value::printAsOperand(raw_ostream &os,
const OpPrintingFlags &flags) const { … }
void Operation::print(raw_ostream &os, const OpPrintingFlags &printerFlags) { … }
void Operation::print(raw_ostream &os, AsmState &state) { … }
void Operation::dump() { … }
void Block::print(raw_ostream &os) { … }
void Block::print(raw_ostream &os, AsmState &state) { … }
void Block::dump() { … }
void Block::printAsOperand(raw_ostream &os, bool printType) { … }
void Block::printAsOperand(raw_ostream &os, AsmState &state) { … }
raw_ostream &mlir::operator<<(raw_ostream &os, Block &block) { … }
namespace mlir {
void printDimensionList(OpAsmPrinter &printer, Operation *op,
ArrayRef<int64_t> dimensions) { … }
ParseResult parseDimensionList(OpAsmParser &parser,
DenseI64ArrayAttr &dimensions) { … }
}