MLIR  19.0.0git
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
mlir::AsmPrinter Class Reference

This base class exposes generic asm printer hooks, usable across the various derived printers. More...

#include "mlir/IR/OpImplementation.h"

+ Inheritance diagram for mlir::AsmPrinter:

Classes

class  CyclicPrintReset
 Class used to automatically end a cyclic region on destruction. More...
 
class  Impl
 

Public Types

template<typename AttrOrType >
using has_print_method = decltype(std::declval< AttrOrType >().print(std::declval< AsmPrinter & >()))
 Trait to check if AttrType provides a print method. More...
 
template<typename AttrOrType >
using detect_has_print_method = llvm::is_detected< has_print_method, AttrOrType >
 

Public Member Functions

 AsmPrinter (Impl &impl)
 Initialize the printer with the given internal implementation. More...
 
virtual ~AsmPrinter ()
 
virtual raw_ostream & getStream () const
 Return the raw output stream used by this printer. More...
 
virtual void printFloat (const APFloat &value)
 Print the given floating point value in a stabilized form that can be roundtripped through the IR. More...
 
virtual void printType (Type type)
 
virtual void printAttribute (Attribute attr)
 
template<typename AttrOrType , std::enable_if_t< detect_has_print_method< AttrOrType >::value > * sfinae = nullptr>
void printStrippedAttrOrType (AttrOrType attrOrType)
 Print the provided attribute in the context of an operation custom printer/parser: this will invoke directly the print method on the attribute class and skip the #dialect.mnemonic prefix in most cases. More...
 
template<typename AttrOrType , std::enable_if_t< detect_has_print_method< AttrOrType >::value > * sfinae = nullptr>
void printStrippedAttrOrType (ArrayRef< AttrOrType > attrOrTypes)
 Print the provided array of attributes or types in the context of an operation custom printer/parser: this will invoke directly the print method on the attribute class and skip the #dialect.mnemonic prefix in most cases. More...
 
template<typename AttrOrType , std::enable_if_t<!detect_has_print_method< AttrOrType >::value > * sfinae = nullptr>
void printStrippedAttrOrType (AttrOrType attrOrType)
 SFINAE for printing the provided attribute in the context of an operation custom printer in the case where the attribute does not define a print method. More...
 
virtual void printAttributeWithoutType (Attribute attr)
 Print the given attribute without its type. More...
 
virtual LogicalResult printAlias (Attribute attr)
 Print the alias for the given attribute, return failure if no alias could be printed. More...
 
virtual LogicalResult printAlias (Type type)
 Print the alias for the given type, return failure if no alias could be printed. More...
 
virtual void printKeywordOrString (StringRef keyword)
 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...
 
virtual void printString (StringRef string)
 Print the given string as a quoted string, escaping any special or non-printable characters in it. More...
 
virtual void printSymbolName (StringRef symbolRef)
 Print the given string as a symbol reference, i.e. More...
 
virtual void printResourceHandle (const AsmDialectResourceHandle &resource)
 Print a handle to the given dialect resource. More...
 
template<typename TypeRange >
void printOptionalArrowTypeList (TypeRange &&types)
 Print an optional arrow followed by a type list. More...
 
template<typename TypeRange >
void printArrowTypeList (TypeRange &&types)
 
template<typename InputRangeT , typename ResultRangeT >
void printFunctionalType (InputRangeT &&inputs, ResultRangeT &&results)
 Print the two given type ranges in a functional form. More...
 
void printDimensionList (ArrayRef< int64_t > shape)
 
template<class AttrOrTypeT >
FailureOr< CyclicPrintResettryStartCyclicPrint (AttrOrTypeT attrOrType)
 Attempts to start a cyclic printing region for attrOrType. More...
 

Protected Member Functions

 AsmPrinter ()=default
 Initialize the printer with no internal implementation. More...
 
virtual LogicalResult pushCyclicPrinting (const void *opaquePointer)
 Pushes a new attribute or type in the form of a type erased pointer into an internal set. More...
 
virtual void popCyclicPrinting ()
 Removes the element that was last inserted with a successful call to pushCyclicPrinting. More...
 

Detailed Description

This base class exposes generic asm printer hooks, usable across the various derived printers.

Definition at line 106 of file OpImplementation.h.

Member Typedef Documentation

◆ detect_has_print_method

template<typename AttrOrType >
using mlir::AsmPrinter::detect_has_print_method = llvm::is_detected<has_print_method, AttrOrType>

Definition at line 132 of file OpImplementation.h.

◆ has_print_method

template<typename AttrOrType >
using mlir::AsmPrinter::has_print_method = decltype(std::declval<AttrOrType>().print(std::declval<AsmPrinter &>()))

Trait to check if AttrType provides a print method.

Definition at line 129 of file OpImplementation.h.

Constructor & Destructor Documentation

◆ AsmPrinter() [1/2]

mlir::AsmPrinter::AsmPrinter ( Impl impl)
inline

Initialize the printer with the given internal implementation.

Definition at line 113 of file OpImplementation.h.

◆ ~AsmPrinter()

AsmPrinter::~AsmPrinter ( )
virtualdefault

◆ AsmPrinter() [2/2]

mlir::AsmPrinter::AsmPrinter ( )
protecteddefault

Initialize the printer with no internal implementation.

In this case, all virtual methods of this class must be overriden.

Member Function Documentation

◆ getStream()

raw_ostream & AsmPrinter::getStream ( ) const
virtual

◆ popCyclicPrinting()

void AsmPrinter::popCyclicPrinting ( )
protectedvirtual

Removes the element that was last inserted with a successful call to pushCyclicPrinting.

There must be exactly one popCyclicPrinting call in reverse order of all successful pushCyclicPrinting.

Definition at line 2830 of file AsmPrinter.cpp.

Referenced by mlir::AsmPrinter::CyclicPrintReset::~CyclicPrintReset().

◆ printAlias() [1/2]

LogicalResult AsmPrinter::printAlias ( Attribute  attr)
virtual

Print the alias for the given attribute, return failure if no alias could be printed.

Definition at line 2784 of file AsmPrinter.cpp.

Referenced by mlir::AsmPrinter::Impl::printLocation(), and printStrippedAttrOrType().

◆ printAlias() [2/2]

LogicalResult AsmPrinter::printAlias ( Type  type)
virtual

Print the alias for the given type, return failure if no alias could be printed.

Definition at line 2789 of file AsmPrinter.cpp.

◆ printArrowTypeList()

template<typename TypeRange >
void mlir::AsmPrinter::printArrowTypeList ( TypeRange &&  types)
inline

Definition at line 215 of file OpImplementation.h.

References getStream().

Referenced by printFunctionalType(), and printOptionalArrowTypeList().

◆ printAttribute()

void AsmPrinter::printAttribute ( Attribute  attr)
virtual

Definition at line 2779 of file AsmPrinter.cpp.

◆ printAttributeWithoutType()

void AsmPrinter::printAttributeWithoutType ( Attribute  attr)
virtual

Print the given attribute without its type.

The corresponding parser must provide a valid type for the attribute.

Definition at line 2794 of file AsmPrinter.cpp.

References mlir::AsmPrinter::Impl::Must.

◆ printDimensionList()

void AsmPrinter::printDimensionList ( ArrayRef< int64_t >  shape)

Definition at line 2822 of file AsmPrinter.cpp.

References getStream(), and mlir::detail::printDimensionList().

◆ printFloat()

void AsmPrinter::printFloat ( const APFloat &  value)
virtual

Print the given floating point value in a stabilized form that can be roundtripped through the IR.

Print the given floating point value in a stablized form.

This is the companion to the 'parseFloat' hook on the AsmParser.

Definition at line 2769 of file AsmPrinter.cpp.

References printFloatValue().

◆ printFunctionalType()

template<typename InputRangeT , typename ResultRangeT >
void mlir::AsmPrinter::printFunctionalType ( InputRangeT &&  inputs,
ResultRangeT &&  results 
)
inline

Print the two given type ranges in a functional form.

Definition at line 229 of file OpImplementation.h.

References getStream(), and printArrowTypeList().

◆ printKeywordOrString()

void AsmPrinter::printKeywordOrString ( StringRef  keyword)
virtual

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 2800 of file AsmPrinter.cpp.

◆ printOptionalArrowTypeList()

template<typename TypeRange >
void mlir::AsmPrinter::printOptionalArrowTypeList ( TypeRange &&  types)
inline

Print an optional arrow followed by a type list.

Definition at line 210 of file OpImplementation.h.

References printArrowTypeList().

Referenced by printNamedStructuredOpResults().

◆ printResourceHandle()

void AsmPrinter::printResourceHandle ( const AsmDialectResourceHandle resource)
virtual

Print a handle to the given dialect resource.

Definition at line 2817 of file AsmPrinter.cpp.

◆ printString()

void AsmPrinter::printString ( StringRef  string)
virtual

Print the given string as a quoted string, escaping any special or non-printable characters in it.

Definition at line 2805 of file AsmPrinter.cpp.

References getStream().

◆ printStrippedAttrOrType() [1/3]

template<typename AttrOrType , std::enable_if_t< detect_has_print_method< AttrOrType >::value > * sfinae = nullptr>
void mlir::AsmPrinter::printStrippedAttrOrType ( ArrayRef< AttrOrType >  attrOrTypes)
inline

Print the provided array of attributes or types in the context of an operation custom printer/parser: this will invoke directly the print method on the attribute class and skip the #dialect.mnemonic prefix in most cases.

Definition at line 163 of file OpImplementation.h.

References getStream(), and printStrippedAttrOrType().

◆ printStrippedAttrOrType() [2/3]

template<typename AttrOrType , std::enable_if_t< detect_has_print_method< AttrOrType >::value > * sfinae = nullptr>
void mlir::AsmPrinter::printStrippedAttrOrType ( AttrOrType  attrOrType)
inline

Print the provided attribute in the context of an operation custom printer/parser: this will invoke directly the print method on the attribute class and skip the #dialect.mnemonic prefix in most cases.

Definition at line 141 of file OpImplementation.h.

References getStream(), printAlias(), and mlir::succeeded().

Referenced by printStrippedAttrOrType().

◆ printStrippedAttrOrType() [3/3]

template<typename AttrOrType , std::enable_if_t<!detect_has_print_method< AttrOrType >::value > * sfinae = nullptr>
void mlir::AsmPrinter::printStrippedAttrOrType ( AttrOrType  attrOrType)
inline

SFINAE for printing the provided attribute in the context of an operation custom printer in the case where the attribute does not define a print method.

Definition at line 175 of file OpImplementation.h.

◆ printSymbolName()

void AsmPrinter::printSymbolName ( StringRef  symbolRef)
virtual

Print the given string as a symbol reference, i.e.

a form representable by a SymbolRefAttr. 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 2812 of file AsmPrinter.cpp.

References printSymbolReference().

◆ printType()

void AsmPrinter::printType ( Type  type)
virtual

Definition at line 2774 of file AsmPrinter.cpp.

Referenced by dispatchPrint(), and printLaunchFuncOperands().

◆ pushCyclicPrinting()

LogicalResult AsmPrinter::pushCyclicPrinting ( const void *  opaquePointer)
protectedvirtual

Pushes a new attribute or type in the form of a type erased pointer into an internal set.

Returns success if the type or attribute was inserted in the set or failure if it was already contained.

Definition at line 2826 of file AsmPrinter.cpp.

Referenced by tryStartCyclicPrint().

◆ tryStartCyclicPrint()

template<class AttrOrTypeT >
FailureOr<CyclicPrintReset> mlir::AsmPrinter::tryStartCyclicPrint ( AttrOrTypeT  attrOrType)
inline

Attempts to start a cyclic printing region for attrOrType.

A cyclic printing region starts with this call and ends with the destruction of the returned CyclicPrintReset. During this time, calling tryStartCyclicPrint with the same attribute in any printer will lead to returning failure.

This makes it possible to break infinite recursions when trying to print cyclic attributes or types by printing only immutable parameters if nested within itself.

Definition at line 275 of file OpImplementation.h.

References mlir::failed(), mlir::failure(), and pushCyclicPrinting().

Referenced by print(), and printStructType().


The documentation for this class was generated from the following files: