20#define GEN_PASS_DEF_UBTOLLVMCONVERSIONPASS
21#include "mlir/Conversion/Passes.h.inc"
35 matchAndRewrite(ub::PoisonOp op, OpAdaptor adaptor,
36 ConversionPatternRewriter &rewriter)
const override;
41PoisonOpLowering::matchAndRewrite(ub::PoisonOp op, OpAdaptor adaptor,
42 ConversionPatternRewriter &rewriter)
const {
43 if (!isa<ub::PoisonAttr>(op.getValue())) {
44 return rewriter.notifyMatchFailure(op, [&](Diagnostic &
diag) {
45 diag <<
"pattern can only convert op with '"
46 << ub::PoisonAttr::getMnemonic() <<
"' poison value";
50 Type resType = getTypeConverter()->convertType(op.getType());
52 return rewriter.notifyMatchFailure(op, [&](Diagnostic &
diag) {
53 diag <<
"failed to convert result type " << op.getType();
57 rewriter.replaceOpWithNewOp<LLVM::PoisonOp>(op, resType);
66struct UnreachableOpLowering
67 :
public ConvertOpToLLVMPattern<ub::UnreachableOp> {
71 matchAndRewrite(ub::UnreachableOp op, OpAdaptor adaptor,
72 ConversionPatternRewriter &rewriter)
const override;
77UnreachableOpLowering::matchAndRewrite(
78 ub::UnreachableOp op, OpAdaptor adaptor,
79 ConversionPatternRewriter &rewriter)
const {
80 rewriter.replaceOpWithNewOp<LLVM::UnreachableOp>(op);
89struct UBToLLVMConversionPass
90 :
public impl::UBToLLVMConversionPassBase<UBToLLVMConversionPass> {
93 void runOnOperation()
override {
99 options.overrideIndexBitwidth(indexBitwidth);
104 if (
failed(applyPartialConversion(getOperation(),
target,
117 patterns.add<PoisonOpLowering, UnreachableOpLowering>(converter);
128 void loadDependentDialects(
MLIRContext *context)
const final {
129 context->loadDialect<LLVM::LLVMDialect>();
134 void populateConvertToLLVMConversionPatterns(
144 dialect->addInterfaces<UBToLLVMDialectInterface>();
static std::string diag(const llvm::Value &value)
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)
Base class for dialect interfaces providing translation to LLVM IR.
ConvertToLLVMPatternInterface(Dialect *dialect)
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.
Conversion from types to the LLVM IR dialect.
MLIRContext is the top-level object for a collection of MLIR operations.
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...
const FrozenRewritePatternSet & patterns