2021-10-13 07:14:57 +08:00
|
|
|
//===- Pattern.h - SPIRV Common Conversion Patterns -----------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef MLIR_CONVERSION_SPIRVCOMMON_PATTERN_H
|
|
|
|
#define MLIR_CONVERSION_SPIRVCOMMON_PATTERN_H
|
|
|
|
|
|
|
|
#include "mlir/Dialect/SPIRV/IR/SPIRVOpTraits.h"
|
|
|
|
#include "mlir/Transforms/DialectConversion.h"
|
|
|
|
|
|
|
|
namespace mlir {
|
|
|
|
namespace spirv {
|
|
|
|
|
2022-01-20 02:32:16 +08:00
|
|
|
/// Converts elementwise unary, binary and ternary standard operations to SPIR-V
|
|
|
|
/// operations.
|
2021-10-13 07:14:57 +08:00
|
|
|
template <typename Op, typename SPIRVOp>
|
2022-01-20 02:32:16 +08:00
|
|
|
class ElementwiseOpPattern final : public OpConversionPattern<Op> {
|
2021-10-13 07:14:57 +08:00
|
|
|
public:
|
|
|
|
using OpConversionPattern<Op>::OpConversionPattern;
|
|
|
|
|
|
|
|
LogicalResult
|
|
|
|
matchAndRewrite(Op op, typename Op::Adaptor adaptor,
|
|
|
|
ConversionPatternRewriter &rewriter) const override {
|
2022-01-20 02:32:16 +08:00
|
|
|
assert(adaptor.getOperands().size() <= 3);
|
2021-10-13 07:14:57 +08:00
|
|
|
auto dstType = this->getTypeConverter()->convertType(op.getType());
|
|
|
|
if (!dstType)
|
|
|
|
return failure();
|
|
|
|
if (SPIRVOp::template hasTrait<OpTrait::spirv::UnsignedOp>() &&
|
2022-04-27 22:13:17 +08:00
|
|
|
!op.getType().isIndex() && dstType != op.getType()) {
|
2021-10-13 07:14:57 +08:00
|
|
|
return op.emitError(
|
|
|
|
"bitwidth emulation is not implemented yet on unsigned op");
|
|
|
|
}
|
|
|
|
rewriter.template replaceOpWithNewOp<SPIRVOp>(op, dstType,
|
|
|
|
adaptor.getOperands());
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-12-08 02:27:58 +08:00
|
|
|
} // namespace spirv
|
|
|
|
} // namespace mlir
|
2021-10-13 07:14:57 +08:00
|
|
|
|
|
|
|
#endif // MLIR_CONVERSION_SPIRVCOMMON_PATTERN_H
|