MLIR  15.0.0git
Macros | Functions
ArithmeticToSPIRV.cpp File Reference
#include "mlir/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.h"
#include "../PassDetail.h"
#include "../SPIRVCommon/Pattern.h"
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
#include "llvm/Support/Debug.h"
+ Include dependency graph for ArithmeticToSPIRV.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "arith-to-spirv-pattern"
 
#define DISPATCH(cmpPredicate, spirvOp)
 
#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...
 
template<typename SignedAbsOp >
static Value emulateSignedRemainder (Location loc, Value lhs, Value rhs, Value signOperand, OpBuilder &builder)
 Returns signed remainder for lhs and rhs and lets the result follow the sign of signOperand. More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

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

Definition at line 19 of file ArithmeticToSPIRV.cpp.

◆ DISPATCH [1/3]

#define DISPATCH (   cmpPredicate,
  spirvOp 
)
Value:
case cmpPredicate: \
rewriter.replaceOpWithNewOp<spirvOp>(op, op.getResult().getType(), \
adaptor.getLhs(), adaptor.getRhs()); \
return success();
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56

◆ DISPATCH [2/3]

#define DISPATCH (   cmpPredicate,
  spirvOp 
)
Value:
case cmpPredicate: \
if (spirvOp::template hasTrait<OpTrait::spirv::UnsignedOp>() && \
operandType != this->getTypeConverter()->convertType(operandType)) { \
return op.emitError( \
"bitwidth emulation is not implemented yet on unsigned op"); \
} \
rewriter.replaceOpWithNewOp<spirvOp>(op, op.getResult().getType(), \
adaptor.getLhs(), adaptor.getRhs()); \
return success();
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56

◆ DISPATCH [3/3]

#define DISPATCH (   cmpPredicate,
  spirvOp 
)
Value:
case cmpPredicate: \
rewriter.replaceOpWithNewOp<spirvOp>(op, op.getResult().getType(), \
adaptor.getLhs(), adaptor.getRhs()); \
return success();
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56

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 211 of file ArithmeticToSPIRV.cpp.

References mlir::Attribute::dyn_cast(), and mlir::Builder::getBoolAttr().

Referenced by isBoolScalarOrVector().

◆ 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 248 of file ArithmeticToSPIRV.cpp.

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

Referenced by isBoolScalarOrVector().

◆ 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 221 of file ArithmeticToSPIRV.cpp.

References mlir::Builder::getIntegerAttr().

Referenced by isBoolScalarOrVector().

◆ emulateSignedRemainder()

template<typename SignedAbsOp >
static Value emulateSignedRemainder ( Location  loc,
Value  lhs,
Value  rhs,
Value  signOperand,
OpBuilder builder 
)
static

Returns signed remainder for lhs and rhs and lets the result follow the sign of signOperand.

Note that this is needed for Vulkan. Per the Vulkan's SPIR-V environment spec, "for the OpSRem and OpSMod instructions, if either operand is negative the result is undefined." So we cannot directly use spv.SRem/spv.SMod if either operand can be negative. Emulate it via spv.UMod.

Definition at line 439 of file ArithmeticToSPIRV.cpp.

◆ isBoolScalarOrVector()

static bool isBoolScalarOrVector ( Type  type)
static