MLIR 22.0.0git
MathToSPIRV.cpp File Reference
#include "../SPIRVCommon/Pattern.h"
#include "mlir/Dialect/Math/IR/Math.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/FormatVariadic.h"

Go to the source code of this file.

Namespaces

namespace  mlir
 Include the generated interface declarations.

Macros

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

Functions

static Value getScalarOrVectorI32Constant (Type type, int value, OpBuilder &builder, Location loc)
 Creates a 32-bit scalar/vector integer constant.
static bool isSupportedSourceType (Type originalType)
 Check if the type is supported by math-to-spirv conversion.
static LogicalResult checkSourceOpTypes (ConversionPatternRewriter &rewriter, Operation *sourceOp)
 Check if all sourceOp types are supported by math-to-spirv conversion.
void mlir::populateMathToSPIRVPatterns (const SPIRVTypeConverter &typeConverter, RewritePatternSet &patterns)
 Appends to a pattern list additional patterns for translating Math ops to SPIR-V ops.

Macro Definition Documentation

◆ DEBUG_TYPE

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

Definition at line 23 of file MathToSPIRV.cpp.

Function Documentation

◆ checkSourceOpTypes()

LogicalResult checkSourceOpTypes ( ConversionPatternRewriter & rewriter,
Operation * sourceOp )
static

Check if all sourceOp types are supported by math-to-spirv conversion.

Notify of a match failure othwerise and return a failure result. This is intended to simplify type checks in OpConversionPatterns.

Definition at line 73 of file MathToSPIRV.cpp.

References mlir::Operation::getOperandTypes(), mlir::Operation::getResultTypes(), isSupportedSourceType(), and success().

◆ getScalarOrVectorI32Constant()

Value getScalarOrVectorI32Constant ( Type type,
int value,
OpBuilder & builder,
Location loc )
static

Creates a 32-bit scalar/vector integer constant.

Returns nullptr if the given type is not a 32-bit scalar/vector type.

Definition at line 33 of file MathToSPIRV.cpp.

References mlir::Builder::getI32IntegerAttr(), mlir::Builder::getI32VectorAttr(), and mlir::Type::isInteger().

◆ isSupportedSourceType()

bool isSupportedSourceType ( Type originalType)
static

Check if the type is supported by math-to-spirv conversion.

We expect to only see scalars and vectors at this point, with higher-level types already lowered.

Definition at line 52 of file MathToSPIRV.cpp.

References mlir::Type::isIntOrIndexOrFloat().

Referenced by checkSourceOpTypes().