21#define GEN_PASS_DEF_UBTOLLVMCONVERSIONPASS
22#include "mlir/Conversion/Passes.h.inc"
36 matchAndRewrite(ub::PoisonOp op, OpAdaptor adaptor,
37 ConversionPatternRewriter &rewriter)
const override;
42PoisonOpLowering::matchAndRewrite(ub::PoisonOp op, OpAdaptor adaptor,
43 ConversionPatternRewriter &rewriter)
const {
44 if (!isa<ub::PoisonAttr>(op.getValue())) {
45 return rewriter.notifyMatchFailure(op, [&](Diagnostic &diag) {
46 diag <<
"pattern can only convert op with '"
47 << ub::PoisonAttr::getMnemonic() <<
"' poison value";
51 Type resType = getTypeConverter()->convertType(op.getType());
53 return rewriter.notifyMatchFailure(op, [&](Diagnostic &diag) {
54 diag <<
"failed to convert result type " << op.getType();
58 rewriter.replaceOpWithNewOp<LLVM::PoisonOp>(op, resType);
67struct UnreachableOpLowering
68 :
public ConvertOpToLLVMPattern<ub::UnreachableOp> {
72 matchAndRewrite(ub::UnreachableOp op, OpAdaptor adaptor,
73 ConversionPatternRewriter &rewriter)
const override;
78UnreachableOpLowering::matchAndRewrite(
79 ub::UnreachableOp op, OpAdaptor adaptor,
80 ConversionPatternRewriter &rewriter)
const {
81 rewriter.replaceOpWithNewOp<LLVM::UnreachableOp>(op);
90struct UBToLLVMConversionPass
91 :
public impl::UBToLLVMConversionPassBase<UBToLLVMConversionPass> {
94 void runOnOperation()
override {
100 options.overrideIndexBitwidth(indexBitwidth);
105 if (
failed(applyPartialConversion(getOperation(),
target,
106 std::move(patterns))))
118 patterns.
add<PoisonOpLowering, UnreachableOpLowering>(converter);
127struct UBToLLVMDialectInterface :
public ConvertToLLVMPatternInterface {
128 UBToLLVMDialectInterface(
Dialect *dialect)
129 : ConvertToLLVMPatternInterface(dialect) {}
131 void loadDependentDialects(
MLIRContext *context)
const final {
132 context->loadDialect<LLVM::LLVMDialect>();
137 void populateConvertToLLVMConversionPatterns(
138 ConversionTarget &
target, LLVMTypeConverter &typeConverter,
139 RewritePatternSet &patterns)
const final {
147 dialect->addInterfaces<UBToLLVMDialectInterface>();
static llvm::ManagedStatic< PassManagerOptions > options
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
ConvertOpToLLVMPattern(const LLVMTypeConverter &typeConverter, PatternBenefit benefit=1)
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Conversion from types to the LLVM IR dialect.
MLIRContext is the top-level object for a collection of MLIR operations.
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
void registerConvertUBToLLVMInterface(DialectRegistry ®istry)
void populateUBToLLVMConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns)
Include the generated interface declarations.
static constexpr unsigned kDeriveIndexBitwidthFromDataLayout
Value to pass as bitwidth for the index type when the converter is expected to derive the bitwidth fr...