MLIR  20.0.0git
Public Types | Public Member Functions | List of all members
mlir::AsmState Class Reference

This class provides management for the lifetime of the state used when printing the IR. More...

#include "mlir/IR/AsmState.h"

Public Types

using LocationMap = DenseMap< Operation *, std::pair< unsigned, unsigned > >
 This map represents the raw locations of operations within the output stream. More...
 

Public Member Functions

 AsmState (Operation *op, const OpPrintingFlags &printerFlags=OpPrintingFlags(), LocationMap *locationMap=nullptr, FallbackAsmResourceMap *map=nullptr)
 Initialize the asm state at the level of the given operation. More...
 
 AsmState (MLIRContext *ctx, const OpPrintingFlags &printerFlags=OpPrintingFlags(), LocationMap *locationMap=nullptr, FallbackAsmResourceMap *map=nullptr)
 
 ~AsmState ()
 
const OpPrintingFlagsgetPrinterFlags () const
 Get the printer flags. More...
 
detail::AsmStateImplgetImpl ()
 Return an instance of the internal implementation. More...
 
void attachResourcePrinter (std::unique_ptr< AsmResourcePrinter > printer)
 Attach the given resource printer to the AsmState. More...
 
template<typename CallableT >
std::enable_if_t< std::is_convertible< CallableT, function_ref< void(Operation *, AsmResourceBuilder &)> >::value > attachResourcePrinter (StringRef name, CallableT &&printFn)
 Attach an resource printer, in the form of a callable, to the AsmState. More...
 
void attachFallbackResourcePrinter (FallbackAsmResourceMap &map)
 Attach resource printers to the AsmState for the fallback resources in the given map. More...
 
DenseMap< Dialect *, SetVector< AsmDialectResourceHandle > > & getDialectResources () const
 Returns a map of dialect resources that were referenced when using this state to print IR. More...
 

Detailed Description

This class provides management for the lifetime of the state used when printing the IR.

It allows for alleviating the cost of recomputing the internal state of the asm printer.

The IR should not be mutated in-between invocations using this state, and the IR being printed must not be an parent of the IR originally used to initialize this state. This means that if a child operation is provided, a parent operation cannot reuse this state.

Definition at line 540 of file AsmState.h.

Member Typedef Documentation

◆ LocationMap

using mlir::AsmState::LocationMap = DenseMap<Operation *, std::pair<unsigned, unsigned> >

This map represents the raw locations of operations within the output stream.

This maps the original pointer to the operation, to a pair of line and column in the output stream.

Definition at line 545 of file AsmState.h.

Constructor & Destructor Documentation

◆ AsmState() [1/2]

AsmState::AsmState ( Operation op,
const OpPrintingFlags printerFlags = OpPrintingFlags(),
LocationMap locationMap = nullptr,
FallbackAsmResourceMap map = nullptr 
)

Initialize the asm state at the level of the given operation.

A location map may optionally be provided to be populated when printing. map is an optional fallback resource map, which when provided will attach resource printers for the fallback resources within the map.

Definition at line 1951 of file AsmPrinter.cpp.

References attachFallbackResourcePrinter().

◆ AsmState() [2/2]

AsmState::AsmState ( MLIRContext ctx,
const OpPrintingFlags printerFlags = OpPrintingFlags(),
LocationMap locationMap = nullptr,
FallbackAsmResourceMap map = nullptr 
)

Definition at line 1958 of file AsmPrinter.cpp.

References attachFallbackResourcePrinter().

◆ ~AsmState()

AsmState::~AsmState ( )
default

Member Function Documentation

◆ attachFallbackResourcePrinter()

void mlir::AsmState::attachFallbackResourcePrinter ( FallbackAsmResourceMap map)
inline

Attach resource printers to the AsmState for the fallback resources in the given map.

Definition at line 586 of file AsmState.h.

References attachResourcePrinter(), and mlir::FallbackAsmResourceMap::getPrinters().

Referenced by AsmState().

◆ attachResourcePrinter() [1/2]

void AsmState::attachResourcePrinter ( std::unique_ptr< AsmResourcePrinter printer)

Attach the given resource printer to the AsmState.

Definition at line 1970 of file AsmPrinter.cpp.

Referenced by attachFallbackResourcePrinter(), and attachResourcePrinter().

◆ attachResourcePrinter() [2/2]

template<typename CallableT >
std::enable_if_t<std::is_convertible< CallableT, function_ref<void(Operation *, AsmResourceBuilder &)> >::value> mlir::AsmState::attachResourcePrinter ( StringRef  name,
CallableT &&  printFn 
)
inline

Attach an resource printer, in the form of a callable, to the AsmState.

Definition at line 579 of file AsmState.h.

References attachResourcePrinter(), and mlir::AsmResourcePrinter::fromCallable().

◆ getDialectResources()

DenseMap< Dialect *, SetVector< AsmDialectResourceHandle > > & AsmState::getDialectResources ( ) const

Returns a map of dialect resources that were referenced when using this state to print IR.

Definition at line 1976 of file AsmPrinter.cpp.

◆ getImpl()

detail::AsmStateImpl& mlir::AsmState::getImpl ( )
inline

Return an instance of the internal implementation.

Returns nullptr if the state has not been initialized.

Definition at line 566 of file AsmState.h.

◆ getPrinterFlags()

const OpPrintingFlags & AsmState::getPrinterFlags ( ) const

Get the printer flags.

Definition at line 1966 of file AsmPrinter.cpp.


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