20#define GEN_PASS_DEF_UBTOLLVMCONVERSIONPASS
21#include "mlir/Conversion/Passes.h.inc"
32 matchAndRewrite(ub::PoisonOp op, OpAdaptor adaptor,
33 ConversionPatternRewriter &rewriter)
const override;
43PoisonOpLowering::matchAndRewrite(ub::PoisonOp op, OpAdaptor adaptor,
44 ConversionPatternRewriter &rewriter)
const {
45 if (!isa<ub::PoisonAttr>(op.getValue())) {
46 return rewriter.notifyMatchFailure(op, [&](Diagnostic &
diag) {
47 diag <<
"pattern can only convert op with '"
48 << ub::PoisonAttr::getMnemonic() <<
"' poison value";
52 Type resType = getTypeConverter()->convertType(op.getType());
54 return rewriter.notifyMatchFailure(op, [&](Diagnostic &
diag) {
55 diag <<
"failed to convert result type " << op.getType();
59 rewriter.replaceOpWithNewOp<LLVM::PoisonOp>(op, resType);
68struct UBToLLVMConversionPass
69 :
public impl::UBToLLVMConversionPassBase<UBToLLVMConversionPass> {
72 void runOnOperation()
override {
78 options.overrideIndexBitwidth(indexBitwidth);
83 if (
failed(applyPartialConversion(getOperation(),
target,
96 patterns.add<PoisonOpLowering>(converter);
107 void loadDependentDialects(
MLIRContext *context)
const final {
108 context->loadDialect<LLVM::LLVMDialect>();
113 void populateConvertToLLVMConversionPatterns(
123 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