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,
105 std::move(patterns))))
117 patterns.
add<PoisonOpLowering, UnreachableOpLowering>(converter);
126struct UBToLLVMDialectInterface :
public ConvertToLLVMPatternInterface {
127 UBToLLVMDialectInterface(
Dialect *dialect)
128 : ConvertToLLVMPatternInterface(dialect) {}
130 void loadDependentDialects(
MLIRContext *context)
const final {
131 context->loadDialect<LLVM::LLVMDialect>();
136 void populateConvertToLLVMConversionPatterns(
137 ConversionTarget &
target, LLVMTypeConverter &typeConverter,
138 RewritePatternSet &patterns)
const final {
146 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)
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...