MLIR  16.0.0git
Classes | Namespaces | Macros | Functions | Variables
AsmPrinter.cpp File Reference
#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/BuiltinDialect.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/SubElementInterfaces.h"
#include "mlir/IR/Verifier.h"
#include "llvm/ADT/APFloat.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/Regex.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/Threading.h"
#include <tuple>
#include "mlir/IR/OpAsmInterface.cpp.inc"
+ Include dependency graph for AsmPrinter.cpp:

Go to the source code of this file.

Classes

class  mlir::detail::AsmStateImpl
 
class  mlir::AsmPrinter::Impl
 

Namespaces

 mlir
 Include the generated interface declarations.
 
 mlir::detail
 

Macros

#define DEBUG_TYPE   "mlir-asm-printer"
 

Functions

static bool shouldPrintElementsAttrWithHex (int64_t numElements)
 Returns true if an ElementsAttr with the given number of elements should be printed with hex. More...
 
static StringRef sanitizeIdentifier (StringRef name, SmallString< 16 > &buffer, StringRef allowedPunctChars="$._-", bool allowTrailingDigit=true)
 Sanitize the given name such that it can be used as a valid identifier. More...
 
template<typename T >
static void initializeAliases (llvm::MapVector< StringRef, std::vector< T >> &aliasToSymbol, llvm::MapVector< T, SymbolAlias > &symbolToAlias, DenseSet< T > *deferrableAliases=nullptr)
 Given a collection of aliases and symbols, initialize a mapping from a symbol to a given alias. More...
 
static OpPrintingFlags verifyOpAndAdjustFlags (Operation *op, OpPrintingFlags printerFlags)
 Verifies the operation and switches to generic op printing if verification fails. More...
 
static void printFloatValue (const APFloat &apValue, raw_ostream &os)
 Print a floating point value in a way that the parser will be able to round-trip losslessly. More...
 
static bool isDialectSymbolSimpleEnoughForPrettyForm (StringRef symName)
 Returns true if the given dialect symbol data is simple enough to print in the pretty form. More...
 
static void printDialectSymbol (raw_ostream &os, StringRef symPrefix, StringRef dialectName, StringRef symString)
 Print the given dialect symbol to the stream. More...
 
static bool isBareIdentifier (StringRef name)
 Returns true if the given string can be represented as a bare identifier. More...
 
static void printKeywordOrString (StringRef keyword, raw_ostream &os)
 Print the given string as a keyword, or a quoted and escaped string if it has any special or non-printable characters in it. More...
 
static void printSymbolReference (StringRef symbolRef, raw_ostream &os)
 Print the given string as a symbol reference. More...
 
static void printElidedElementsAttr (raw_ostream &os)
 
static void printDenseIntElement (const APInt &value, raw_ostream &os, bool isSigned)
 Print the integer element of a DenseElementsAttr. More...
 
static void printDenseElementsAttrImpl (bool isSplat, ShapedType type, raw_ostream &os, function_ref< void(unsigned)> printEltFn)
 

Variables

static llvm::ManagedStatic< AsmPrinterOptions > clOptions
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "mlir-asm-printer"

Definition at line 53 of file AsmPrinter.cpp.

Referenced by verifyOpAndAdjustFlags().

Function Documentation

◆ initializeAliases()

template<typename T >
static void initializeAliases ( llvm::MapVector< StringRef, std::vector< T >> &  aliasToSymbol,
llvm::MapVector< T, SymbolAlias > &  symbolToAlias,
DenseSet< T > *  deferrableAliases = nullptr 
)
static

Given a collection of aliases and symbols, initialize a mapping from a symbol to a given alias.

Definition at line 643 of file AsmPrinter.cpp.

◆ isBareIdentifier()

static bool isBareIdentifier ( StringRef  name)
static

Returns true if the given string can be represented as a bare identifier.

Definition at line 1688 of file AsmPrinter.cpp.

◆ isDialectSymbolSimpleEnoughForPrettyForm()

static bool isDialectSymbolSimpleEnoughForPrettyForm ( StringRef  symName)
static

Returns true if the given dialect symbol data is simple enough to print in the pretty form.

This is essentially when the symbol takes the form: identifier (< body >)?

Definition at line 1655 of file AsmPrinter.cpp.

Referenced by printDialectSymbol().

◆ printDenseElementsAttrImpl()

static void printDenseElementsAttrImpl ( bool  isSplat,
ShapedType  type,
raw_ostream &  os,
function_ref< void(unsigned)>  printEltFn 
)
static

Definition at line 1899 of file AsmPrinter.cpp.

◆ printDenseIntElement()

static void printDenseIntElement ( const APInt &  value,
raw_ostream &  os,
bool  isSigned 
)
static

Print the integer element of a DenseElementsAttr.

Definition at line 1890 of file AsmPrinter.cpp.

◆ printDialectSymbol()

static void printDialectSymbol ( raw_ostream &  os,
StringRef  symPrefix,
StringRef  dialectName,
StringRef  symString 
)
static

Print the given dialect symbol to the stream.

Definition at line 1673 of file AsmPrinter.cpp.

References isDialectSymbolSimpleEnoughForPrettyForm().

◆ printElidedElementsAttr()

static void printElidedElementsAttr ( raw_ostream &  os)
static

Definition at line 1729 of file AsmPrinter.cpp.

◆ printFloatValue()

static void printFloatValue ( const APFloat &  apValue,
raw_ostream &  os 
)
static

Print a floating point value in a way that the parser will be able to round-trip losslessly.

Definition at line 1594 of file AsmPrinter.cpp.

Referenced by mlir::AsmPrinter::printFloat().

◆ printKeywordOrString()

static void printKeywordOrString ( StringRef  keyword,
raw_ostream &  os 
)
static

Print the given string as a keyword, or a quoted and escaped string if it has any special or non-printable characters in it.

Definition at line 1702 of file AsmPrinter.cpp.

Referenced by mlir::AsmPrinter::printKeywordOrString(), mlir::AsmPrinter::printStrippedAttrOrType(), and shouldPrintElementsAttrWithHex().

◆ printSymbolReference()

static void printSymbolReference ( StringRef  symbolRef,
raw_ostream &  os 
)
static

Print the given string as a symbol reference.

A symbol reference is represented as a string prefixed with '@'. The reference is surrounded with ""'s and escaped if it has any special or non-printable characters in it.

Definition at line 1718 of file AsmPrinter.cpp.

Referenced by mlir::AsmPrinter::printSymbolName().

◆ sanitizeIdentifier()

static StringRef sanitizeIdentifier ( StringRef  name,
SmallString< 16 > &  buffer,
StringRef  allowedPunctChars = "$._-",
bool  allowTrailingDigit = true 
)
static

Sanitize the given name such that it can be used as a valid identifier.

If the string needs to be modified in any way, the provided buffer is used to store the new copy,

Definition at line 594 of file AsmPrinter.cpp.

◆ shouldPrintElementsAttrWithHex()

static bool shouldPrintElementsAttrWithHex ( int64_t  numElements)
static

◆ verifyOpAndAdjustFlags()

static OpPrintingFlags verifyOpAndAdjustFlags ( Operation op,
OpPrintingFlags  printerFlags 
)
static

Verifies the operation and switches to generic op printing if verification fails.

We need to do this because custom print functions may fail for invalid ops.

Definition at line 1346 of file AsmPrinter.cpp.

References DEBUG_TYPE, diag(), mlir::failed(), mlir::failure(), mlir::Operation::getContext(), mlir::Operation::getName(), mlir::OpPrintingFlags::printGenericOpForm(), mlir::OpPrintingFlags::shouldAssumeVerified(), mlir::OpPrintingFlags::shouldPrintGenericOpForm(), mlir::success(), and mlir::verify().

Variable Documentation

◆ clOptions

llvm::ManagedStatic<AsmPrinterOptions> clOptions
static