MLIR 22.0.0git
ArithToSPIRV.cpp File Reference
#include "mlir/Conversion/ArithToSPIRV/ArithToSPIRV.h"
#include "../SPIRVCommon/Pattern.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h"
#include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/DialectResourceBlobManager.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
#include <memory>
#include "mlir/Conversion/Passes.h.inc"

Go to the source code of this file.

Classes

class  mlir::impl::ConvertArithToSPIRVPassBase< DerivedT >

Namespaces

namespace  mlir
 Include the generated interface declarations.
namespace  mlir::impl
 Attribute collections provide a dictionary-like interface.

Macros

#define GEN_PASS_DEF_CONVERTARITHTOSPIRVPASS
#define DEBUG_TYPE   "arith-to-spirv-pattern"
#define DISPATCH(cmpPredicate, spirvOp)
#define DISPATCH(cmpPredicate, spirvOp)

Functions

std::unique_ptr<::mlir::Passmlir::impl::createConvertArithToSPIRVPass ()
std::unique_ptr<::mlir::Passmlir::impl::createConvertArithToSPIRVPass (ConvertArithToSPIRVPassOptions options)
std::unique_ptr<::mlir::Passmlir::createConvertArithToSPIRVPass ()
std::unique_ptr<::mlir::Passmlir::createConvertArithToSPIRVPass (ConvertArithToSPIRVPassOptions options)
static BoolAttr convertBoolAttr (Attribute srcAttr, Builder builder)
 Converts the given srcAttr into a boolean attribute if it holds an integral value.
static IntegerAttr convertIntegerAttr (IntegerAttr srcAttr, IntegerType dstType, Builder builder)
 Converts the given srcAttr to a new attribute of the given dstType.
static FloatAttr convertFloatAttr (FloatAttr srcAttr, FloatType dstType, Builder builder)
 Converts the given srcAttr to a new attribute of the given dstType.
static IntegerAttr getIntegerAttrFromFloatAttr (FloatAttr floatAttr, Type dstType, ConversionPatternRewriter &rewriter)
static bool isBoolScalarOrVector (Type type)
 Returns true if the given type is a boolean scalar or vector type.
static Value getScalarOrVectorConstInt (Type type, uint64_t value, OpBuilder &builder, Location loc)
 Creates a scalar/vector integer constant.
static bool hasSameBitwidth (Type a, Type b)
 Returns true if scalar/vector type a and b have the same number of bitwidth.
static LogicalResult getTypeConversionFailure (ConversionPatternRewriter &rewriter, Operation *op, Type srcType)
 Returns a source type conversion failure for srcType and operation op.
static LogicalResult getTypeConversionFailure (ConversionPatternRewriter &rewriter, Operation *op)
 Returns a source type conversion failure for the result type of op.
static std::string getDecorationString (spirv::Decoration decor)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "arith-to-spirv-pattern"

Definition at line 34 of file ArithToSPIRV.cpp.

◆ DISPATCH [1/2]

#define DISPATCH ( cmpPredicate,
spirvOp )
Value:
case cmpPredicate: \
if (spirvOp::template hasTrait<OpTrait::spirv::UnsignedOp>() && \
!getElementTypeOrSelf(srcType).isIndex() && srcType != dstType && \
!hasSameBitwidth(srcType, dstType)) { \
return op.emitError( \
"bitwidth emulation is not implemented yet on unsigned op"); \
} \
rewriter.replaceOpWithNewOp<spirvOp>(op, adaptor.getLhs(), \
adaptor.getRhs()); \
return success();
return success()
static bool hasSameBitwidth(Type a, Type b)
Returns true if scalar/vector type a and b have the same number of bitwidth.
Type getElementTypeOrSelf(Type type)
Return the element type or return the type itself.

◆ DISPATCH [2/2]

#define DISPATCH ( cmpPredicate,
spirvOp )
Value:
case cmpPredicate: \
rewriter.replaceOpWithNewOp<spirvOp>(op, adaptor.getLhs(), \
adaptor.getRhs()); \
return success();

◆ GEN_PASS_DEF_CONVERTARITHTOSPIRVPASS

#define GEN_PASS_DEF_CONVERTARITHTOSPIRVPASS

Definition at line 30 of file ArithToSPIRV.cpp.

Function Documentation

◆ convertBoolAttr()

BoolAttr convertBoolAttr ( Attribute srcAttr,
Builder builder )
static

Converts the given srcAttr into a boolean attribute if it holds an integral value.

Returns null attribute if conversion fails.

Definition at line 44 of file ArithToSPIRV.cpp.

References mlir::Builder::getBoolAttr().

◆ convertFloatAttr()

FloatAttr convertFloatAttr ( FloatAttr srcAttr,
FloatType dstType,
Builder builder )
static

Converts the given srcAttr to a new attribute of the given dstType.

Returns null attribute if dstType is not 32-bit or conversion fails.

Definition at line 81 of file ArithToSPIRV.cpp.

References mlir::Builder::getF32FloatAttr().

◆ convertIntegerAttr()

IntegerAttr convertIntegerAttr ( IntegerAttr srcAttr,
IntegerType dstType,
Builder builder )
static

Converts the given srcAttr to a new attribute of the given dstType.

Returns null attribute if conversion fails.

Definition at line 54 of file ArithToSPIRV.cpp.

References mlir::Builder::getIntegerAttr().

◆ getDecorationString()

std::string getDecorationString ( spirv::Decoration decor)
static

Definition at line 174 of file ArithToSPIRV.cpp.

◆ getIntegerAttrFromFloatAttr()

IntegerAttr getIntegerAttrFromFloatAttr ( FloatAttr floatAttr,
Type dstType,
ConversionPatternRewriter & rewriter )
static

Definition at line 106 of file ArithToSPIRV.cpp.

◆ getScalarOrVectorConstInt()

Value getScalarOrVectorConstInt ( Type type,
uint64_t value,
OpBuilder & builder,
Location loc )
static

Creates a scalar/vector integer constant.

Definition at line 126 of file ArithToSPIRV.cpp.

References mlir::DenseElementsAttr::get(), and mlir::Builder::getIntegerAttr().

Referenced by mlir::createConvertArithToSPIRVPass().

◆ getTypeConversionFailure() [1/2]

LogicalResult getTypeConversionFailure ( ConversionPatternRewriter & rewriter,
Operation * op )
static

Returns a source type conversion failure for the result type of op.

Definition at line 168 of file ArithToSPIRV.cpp.

References mlir::ValueTypeRange< ValueRangeT >::front(), mlir::Operation::getNumResults(), mlir::Operation::getResultTypes(), and getTypeConversionFailure().

◆ getTypeConversionFailure() [2/2]

LogicalResult getTypeConversionFailure ( ConversionPatternRewriter & rewriter,
Operation * op,
Type srcType )
static

Returns a source type conversion failure for srcType and operation op.

Definition at line 159 of file ArithToSPIRV.cpp.

References mlir::Operation::getLoc().

Referenced by getTypeConversionFailure().

◆ hasSameBitwidth()

bool hasSameBitwidth ( Type a,
Type b )
static

Returns true if scalar/vector type a and b have the same number of bitwidth.

Definition at line 143 of file ArithToSPIRV.cpp.

References b.

◆ isBoolScalarOrVector()

bool isBoolScalarOrVector ( Type type)
static

Returns true if the given type is a boolean scalar or vector type.

Definition at line 114 of file ArithToSPIRV.cpp.

References mlir::Type::isInteger().

Referenced by mlir::impl::ConvertArithToSPIRVPassBase< DerivedT >::createConvertArithToSPIRVPass.