MLIR  19.0.0git
Namespaces | Macros | Functions
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 "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.

Namespaces

 mlir
 Include the generated interface declarations.
 

Macros

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

Functions

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

Macro Definition Documentation

◆ DEBUG_TYPE

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

Definition at line 33 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();
static bool hasSameBitwidth(Type a, Type b)
Returns true if scalar/vector type a and b have the same number of bitwidth.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
Definition: Operation.cpp:268
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
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_CONVERTARITHTOSPIRV

#define GEN_PASS_DEF_CONVERTARITHTOSPIRV

Definition at line 29 of file ArithToSPIRV.cpp.

Function Documentation

◆ convertBoolAttr()

static 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 43 of file ArithToSPIRV.cpp.

References mlir::Builder::getBoolAttr().

◆ convertFloatAttr()

static 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 80 of file ArithToSPIRV.cpp.

References mlir::Builder::getF32FloatAttr(), and mlir::Type::isF32().

◆ convertIntegerAttr()

static 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 53 of file ArithToSPIRV.cpp.

References mlir::Builder::getIntegerAttr().

◆ getDecorationString()

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

Definition at line 162 of file ArithToSPIRV.cpp.

◆ getScalarOrVectorConstInt()

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

Creates a scalar/vector integer constant.

Definition at line 114 of file ArithToSPIRV.cpp.

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

◆ getTypeConversionFailure() [1/2]

static LogicalResult getTypeConversionFailure ( ConversionPatternRewriter rewriter,
Operation op 
)
static

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

Definition at line 156 of file ArithToSPIRV.cpp.

◆ getTypeConversionFailure() [2/2]

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

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

Definition at line 147 of file ArithToSPIRV.cpp.

◆ hasSameBitwidth()

static 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 131 of file ArithToSPIRV.cpp.

◆ isBoolScalarOrVector()

static bool isBoolScalarOrVector ( Type  type)
static

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

Definition at line 102 of file ArithToSPIRV.cpp.

References mlir::Type::isInteger().