21#include "llvm/Support/FormatVariadic.h"
23#define DEBUG_TYPE "cf-to-spirv-pattern"
34 if (converter.isLegal(arg.
getType()))
37 Type newTy = converter.convertType(ty);
40 op, llvm::formatv(
"failed to legalize type for argument {0})", arg));
45 Value convertedValue = converter.materializeSourceConversion(
46 builder, op->
getLoc(), ty, newArg);
47 if (!convertedValue) {
49 op, llvm::formatv(
"failed to cast new argument {0} to type {1})",
64struct BranchOpPattern final : OpConversionPattern<cf::BranchOp> {
68 matchAndRewrite(cf::BranchOp op, OpAdaptor adaptor,
69 ConversionPatternRewriter &rewriter)
const override {
71 *getTypeConverter())))
74 rewriter.replaceOpWithNewOp<spirv::BranchOp>(op, op.getDest(),
75 adaptor.getDestOperands());
81struct CondBranchOpPattern final : OpConversionPattern<cf::CondBranchOp> {
85 matchAndRewrite(cf::CondBranchOp op, OpAdaptor adaptor,
86 ConversionPatternRewriter &rewriter)
const override {
88 *getTypeConverter())))
92 *getTypeConverter())))
95 rewriter.replaceOpWithNewOp<spirv::BranchConditionalOp>(
96 op, adaptor.getCondition(), op.getTrueDest(),
97 adaptor.getTrueDestOperands(), op.getFalseDest(),
98 adaptor.getFalseDestOperands());
112 patterns.add<BranchOpPattern, CondBranchOpPattern>(typeConverter, context);
static LogicalResult legalizeBlockArguments(Block &block, Operation *op, PatternRewriter &rewriter, const TypeConverter &converter)
Legailze target block arguments.
This class represents an argument of a Block.
Location getLoc() const
Return the location for this argument.
unsigned getArgNumber() const
Returns the number of this argument.
Block represents an ordered list of Operations.
BlockArgument getArgument(unsigned i)
unsigned getNumArguments()
BlockArgument insertArgument(args_iterator it, Type type, Location loc)
Insert one value to the position in the argument list indicated by the given iterator.
void eraseArgument(unsigned index)
Erase the argument at 'index' and remove it from the argument list.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
static OpBuilder atBlockBegin(Block *block, Listener *listener=nullptr)
Create a builder and set the insertion point to before the first operation in the block but still ins...
Operation is the basic unit of execution within MLIR.
Location getLoc()
The source location the operation was defined or derived from.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
Type conversion from builtin types to SPIR-V types for shader interface.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
void replaceAllUsesWith(Value newValue)
Replace all uses of 'this' value with the new value, updating anything in the IR that uses 'this' to ...
void populateControlFlowToSPIRVPatterns(const SPIRVTypeConverter &typeConverter, RewritePatternSet &patterns)
Appends to a pattern list additional patterns for translating ControlFLow ops to SPIR-V ops.
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns