My Project
Classes | Public Member Functions | List of all members
mlir::OpBuilder Class Reference

#include <Builders.h>

Inheritance diagram for mlir::OpBuilder:
Inheritance graph
[legend]
Collaboration diagram for mlir::OpBuilder:
Collaboration graph
[legend]

Classes

class  InsertionGuard
 RAII guard to reset the insertion point of the builder when destroyed. More...
 
class  InsertPoint
 This class represents a saved insertion point. More...
 

Public Member Functions

 OpBuilder (MLIRContext *ctx)
 Create a builder with the given context. More...
 
 OpBuilder (Region *region)
 Create a builder and set the insertion point to the start of the region. More...
 
 OpBuilder (Region &region)
 
virtual ~OpBuilder ()
 
 OpBuilder (Operation *op)
 
 OpBuilder (Block *block)
 
 OpBuilder (Block *block, Block::iterator insertPoint)
 
void clearInsertionPoint ()
 
InsertPoint saveInsertionPoint () const
 Return a saved insertion point. More...
 
void restoreInsertionPoint (InsertPoint ip)
 Restore the insert point to a previously saved point. More...
 
void setInsertionPoint (Block *block, Block::iterator insertPoint)
 Set the insertion point to the specified location. More...
 
void setInsertionPoint (Operation *op)
 
void setInsertionPointAfter (Operation *op)
 
void setInsertionPointToStart (Block *block)
 Sets the insertion point to the start of the specified block. More...
 
void setInsertionPointToEnd (Block *block)
 Sets the insertion point to the end of the specified block. More...
 
BlockgetInsertionBlock () const
 
Block::iterator getInsertionPoint () const
 Returns the current insertion point of the builder. More...
 
virtual Operationinsert (Operation *op)
 Insert the given operation at the current insertion point and return it. More...
 
BlockcreateBlock (Region *parent, Region::iterator insertPt={})
 
BlockcreateBlock (Block *insertBefore)
 
BlockgetBlock () const
 Returns the current block of the builder. More...
 
OperationcreateOperation (const OperationState &state)
 Creates an operation given the fields represented as an OperationState. More...
 
template<typename OpTy , typename... Args>
OpTy create (Location location, Args &&... args)
 Create an operation of specific op type at the current insertion point. More...
 
template<typename OpTy , typename... Args>
void createOrFold (SmallVectorImpl< Value > &results, Location location, Args &&... args)
 
template<typename OpTy , typename... Args>
std::enable_if< OpTy::template hasTrait< OpTrait::OneResult >), Value >::type createOrFold (Location location, Args &&... args)
 Overload to create or fold a single result operation. More...
 
template<typename OpTy , typename... Args>
std::enable_if< OpTy::template hasTrait< OpTrait::ZeroResult >), OpTy >::type createOrFold (Location location, Args &&... args)
 Overload to create or fold a zero result operation. More...
 
LogicalResult tryFold (Operation *op, SmallVectorImpl< Value > &results)
 
Operationclone (Operation &op, BlockAndValueMapping &mapper)
 
Operationclone (Operation &op)
 
OperationcloneWithoutRegions (Operation &op, BlockAndValueMapping &mapper)
 
OperationcloneWithoutRegions (Operation &op)
 
template<typename OpT >
OpT cloneWithoutRegions (OpT op)
 
- Public Member Functions inherited from mlir::Builder
 Builder (MLIRContext *context)
 
 Builder (ModuleOp module)
 
MLIRContextgetContext () const
 
Identifier getIdentifier (StringRef str)
 
Location getUnknownLoc ()
 
Location getFileLineColLoc (Identifier filename, unsigned line, unsigned column)
 
Location getFusedLoc (ArrayRef< Location > locs, Attribute metadata=Attribute())
 
FloatType getBF16Type ()
 
FloatType getF16Type ()
 
FloatType getF32Type ()
 
FloatType getF64Type ()
 
IndexType getIndexType ()
 
IntegerType getI1Type ()
 
IntegerType getIntegerType (unsigned width)
 
FunctionType getFunctionType (ArrayRef< Type > inputs, ArrayRef< Type > results)
 
TupleType getTupleType (ArrayRef< Type > elementTypes)
 
NoneType getNoneType ()
 
template<typename Ty , typename... Args>
Ty getType (Args... args)
 Get or construct an instance of the type 'ty' with provided arguments. More...
 
NamedAttribute getNamedAttr (StringRef name, Attribute val)
 
UnitAttr getUnitAttr ()
 
BoolAttr getBoolAttr (bool value)
 
DictionaryAttr getDictionaryAttr (ArrayRef< NamedAttribute > value)
 
IntegerAttr getIntegerAttr (Type type, int64_t value)
 
IntegerAttr getIntegerAttr (Type type, const APInt &value)
 
FloatAttr getFloatAttr (Type type, double value)
 
FloatAttr getFloatAttr (Type type, const APFloat &value)
 
StringAttr getStringAttr (StringRef bytes)
 
ArrayAttr getArrayAttr (ArrayRef< Attribute > value)
 
FlatSymbolRefAttr getSymbolRefAttr (Operation *value)
 
FlatSymbolRefAttr getSymbolRefAttr (StringRef value)
 
SymbolRefAttr getSymbolRefAttr (StringRef value, ArrayRef< FlatSymbolRefAttr > nestedReferences)
 
Attribute getZeroAttr (Type type)
 
FloatAttr getF16FloatAttr (float value)
 
FloatAttr getF32FloatAttr (float value)
 
FloatAttr getF64FloatAttr (double value)
 
IntegerAttr getI8IntegerAttr (int8_t value)
 
IntegerAttr getI16IntegerAttr (int16_t value)
 
IntegerAttr getI32IntegerAttr (int32_t value)
 
IntegerAttr getI64IntegerAttr (int64_t value)
 
DenseIntElementsAttr getI32VectorAttr (ArrayRef< int32_t > values)
 
ArrayAttr getAffineMapArrayAttr (ArrayRef< AffineMap > values)
 
ArrayAttr getI32ArrayAttr (ArrayRef< int32_t > values)
 
ArrayAttr getI64ArrayAttr (ArrayRef< int64_t > values)
 
ArrayAttr getIndexArrayAttr (ArrayRef< int64_t > values)
 
ArrayAttr getF32ArrayAttr (ArrayRef< float > values)
 
ArrayAttr getF64ArrayAttr (ArrayRef< double > values)
 
ArrayAttr getStrArrayAttr (ArrayRef< StringRef > values)
 
AffineExpr getAffineDimExpr (unsigned position)
 
AffineExpr getAffineSymbolExpr (unsigned position)
 
AffineExpr getAffineConstantExpr (int64_t constant)
 
AffineMap getEmptyAffineMap ()
 Returns a zero result affine map with no dimensions or symbols: () -> (). More...
 
AffineMap getConstantAffineMap (int64_t val)
 
AffineMap getDimIdentityMap ()
 
AffineMap getMultiDimIdentityMap (unsigned rank)
 
AffineMap getSymbolIdentityMap ()
 
AffineMap getSingleDimShiftAffineMap (int64_t shift)
 
AffineMap getShiftedAffineMap (AffineMap map, int64_t shift)
 

Additional Inherited Members

- Protected Attributes inherited from mlir::Builder
MLIRContextcontext
 

Detailed Description

This class helps build Operations. Operations that are created are automatically inserted at an insertion point. The builder is copyable.

Constructor & Destructor Documentation

◆ OpBuilder() [1/6]

mlir::OpBuilder::OpBuilder ( MLIRContext ctx)
inlineexplicit

Create a builder with the given context.

◆ OpBuilder() [2/6]

mlir::OpBuilder::OpBuilder ( Region region)
inlineexplicit

Create a builder and set the insertion point to the start of the region.

◆ OpBuilder() [3/6]

mlir::OpBuilder::OpBuilder ( Region region)
inlineexplicit

◆ ~OpBuilder()

OpBuilder::~OpBuilder ( )
virtual

◆ OpBuilder() [4/6]

mlir::OpBuilder::OpBuilder ( Operation op)
inlineexplicit

Create a builder and set insertion point to the given operation, which will cause subsequent insertions to go right before it.

◆ OpBuilder() [5/6]

mlir::OpBuilder::OpBuilder ( Block block)
inlineexplicit

◆ OpBuilder() [6/6]

mlir::OpBuilder::OpBuilder ( Block block,
Block::iterator  insertPoint 
)
inline

Member Function Documentation

◆ clearInsertionPoint()

void mlir::OpBuilder::clearInsertionPoint ( )
inline

Reset the insertion point to no location. Creating an operation without a set insertion point is an error, but this can still be useful when the current insertion point a builder refers to is being removed.

◆ clone() [1/2]

Operation* mlir::OpBuilder::clone ( Operation op,
BlockAndValueMapping mapper 
)
inline

Creates a deep copy of the specified operation, remapping any operands that use values outside of the operation using the map that is provided ( leaving them alone if no entry is present). Replaces references to cloned sub-operations to the corresponding operation that is copied, and adds those mappings to the map.

◆ clone() [2/2]

Operation* mlir::OpBuilder::clone ( Operation op)
inline

◆ cloneWithoutRegions() [1/3]

Operation* mlir::OpBuilder::cloneWithoutRegions ( Operation op,
BlockAndValueMapping mapper 
)
inline

Creates a deep copy of this operation but keep the operation regions empty. Operands are remapped using mapper (if present), and mapper is updated to contain the results.

◆ cloneWithoutRegions() [2/3]

Operation* mlir::OpBuilder::cloneWithoutRegions ( Operation op)
inline

◆ cloneWithoutRegions() [3/3]

template<typename OpT >
OpT mlir::OpBuilder::cloneWithoutRegions ( OpT  op)
inline

◆ create()

template<typename OpTy , typename... Args>
OpTy mlir::OpBuilder::create ( Location  location,
Args &&...  args 
)
inline

Create an operation of specific op type at the current insertion point.

◆ createBlock() [1/2]

Block * OpBuilder::createBlock ( Region parent,
Region::iterator  insertPt = {} 
)

Add new block and set the insertion point to the end of it. The block is inserted at the provided insertion point of 'parent'.

◆ createBlock() [2/2]

Block * OpBuilder::createBlock ( Block insertBefore)

Add new block and set the insertion point to the end of it. The block is placed before 'insertBefore'.

◆ createOperation()

Operation * OpBuilder::createOperation ( const OperationState state)

Creates an operation given the fields represented as an OperationState.

Create an operation given the fields represented as an OperationState.

◆ createOrFold() [1/3]

template<typename OpTy , typename... Args>
void mlir::OpBuilder::createOrFold ( SmallVectorImpl< Value > &  results,
Location  location,
Args &&...  args 
)
inline

Create an operation of specific op type at the current insertion point, and immediately try to fold it. This functions populates 'results' with the results after folding the operation.

◆ createOrFold() [2/3]

template<typename OpTy , typename... Args>
std::enable_if<OpTy::template hasTrait<OpTrait::OneResult>), Value>::type mlir::OpBuilder::createOrFold ( Location  location,
Args &&...  args 
)
inline

Overload to create or fold a single result operation.

◆ createOrFold() [3/3]

template<typename OpTy , typename... Args>
std::enable_if<OpTy::template hasTrait<OpTrait::ZeroResult>), OpTy>::type mlir::OpBuilder::createOrFold ( Location  location,
Args &&...  args 
)
inline

Overload to create or fold a zero result operation.

◆ getBlock()

Block* mlir::OpBuilder::getBlock ( ) const
inline

Returns the current block of the builder.

◆ getInsertionBlock()

Block* mlir::OpBuilder::getInsertionBlock ( ) const
inline

Return the block the current insertion point belongs to. Note that the the insertion point is not necessarily the end of the block.

◆ getInsertionPoint()

Block::iterator mlir::OpBuilder::getInsertionPoint ( ) const
inline

Returns the current insertion point of the builder.

◆ insert()

Operation * OpBuilder::insert ( Operation op)
virtual

Insert the given operation at the current insertion point and return it.

Reimplemented in mlir::ConversionPatternRewriter, and mlir::PatternRewriter.

◆ restoreInsertionPoint()

void mlir::OpBuilder::restoreInsertionPoint ( InsertPoint  ip)
inline

Restore the insert point to a previously saved point.

◆ saveInsertionPoint()

InsertPoint mlir::OpBuilder::saveInsertionPoint ( ) const
inline

Return a saved insertion point.

◆ setInsertionPoint() [1/2]

void mlir::OpBuilder::setInsertionPoint ( Block block,
Block::iterator  insertPoint 
)
inline

Set the insertion point to the specified location.

◆ setInsertionPoint() [2/2]

void mlir::OpBuilder::setInsertionPoint ( Operation op)
inline

Sets the insertion point to the specified operation, which will cause subsequent insertions to go right before it.

◆ setInsertionPointAfter()

void mlir::OpBuilder::setInsertionPointAfter ( Operation op)
inline

Sets the insertion point to the node after the specified operation, which will cause subsequent insertions to go right after it.

◆ setInsertionPointToEnd()

void mlir::OpBuilder::setInsertionPointToEnd ( Block block)
inline

Sets the insertion point to the end of the specified block.

◆ setInsertionPointToStart()

void mlir::OpBuilder::setInsertionPointToStart ( Block block)
inline

Sets the insertion point to the start of the specified block.

◆ tryFold()

LogicalResult OpBuilder::tryFold ( Operation op,
SmallVectorImpl< Value > &  results 
)

Attempts to fold the given operation and places new results within 'results'. Returns success if the operation was folded, failure otherwise. Note: This function does not erase the operation on a successful fold.


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