MLIR  18.0.0git
ArithToLLVM.cpp
Go to the documentation of this file.
1 //===- ArithToLLVM.cpp - Arithmetic to LLVM dialect conversion -------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
17 #include "mlir/IR/TypeUtilities.h"
18 #include "mlir/Pass/Pass.h"
19 #include <type_traits>
20 
21 namespace mlir {
22 #define GEN_PASS_DEF_ARITHTOLLVMCONVERSIONPASS
23 #include "mlir/Conversion/Passes.h.inc"
24 } // namespace mlir
25 
26 using namespace mlir;
27 
28 namespace {
29 
30 //===----------------------------------------------------------------------===//
31 // Straightforward Op Lowerings
32 //===----------------------------------------------------------------------===//
33 
34 using AddFOpLowering =
35  VectorConvertToLLVMPattern<arith::AddFOp, LLVM::FAddOp,
36  arith::AttrConvertFastMathToLLVM>;
39 using BitcastOpLowering =
41 using DivFOpLowering =
42  VectorConvertToLLVMPattern<arith::DivFOp, LLVM::FDivOp,
43  arith::AttrConvertFastMathToLLVM>;
44 using DivSIOpLowering =
46 using DivUIOpLowering =
49 using ExtSIOpLowering =
51 using ExtUIOpLowering =
53 using FPToSIOpLowering =
55 using FPToUIOpLowering =
57 using MaximumFOpLowering =
58  VectorConvertToLLVMPattern<arith::MaximumFOp, LLVM::MaximumOp,
59  arith::AttrConvertFastMathToLLVM>;
60 using MaxNumFOpLowering =
61  VectorConvertToLLVMPattern<arith::MaxNumFOp, LLVM::MaxNumOp,
62  arith::AttrConvertFastMathToLLVM>;
63 using MaxSIOpLowering =
65 using MaxUIOpLowering =
67 using MinimumFOpLowering =
68  VectorConvertToLLVMPattern<arith::MinimumFOp, LLVM::MinimumOp,
69  arith::AttrConvertFastMathToLLVM>;
70 using MinNumFOpLowering =
71  VectorConvertToLLVMPattern<arith::MinNumFOp, LLVM::MinNumOp,
72  arith::AttrConvertFastMathToLLVM>;
73 using MinSIOpLowering =
75 using MinUIOpLowering =
77 using MulFOpLowering =
78  VectorConvertToLLVMPattern<arith::MulFOp, LLVM::FMulOp,
79  arith::AttrConvertFastMathToLLVM>;
81 using NegFOpLowering =
82  VectorConvertToLLVMPattern<arith::NegFOp, LLVM::FNegOp,
83  arith::AttrConvertFastMathToLLVM>;
85 using RemFOpLowering =
86  VectorConvertToLLVMPattern<arith::RemFOp, LLVM::FRemOp,
87  arith::AttrConvertFastMathToLLVM>;
88 using RemSIOpLowering =
90 using RemUIOpLowering =
92 using SelectOpLowering =
95 using ShRSIOpLowering =
97 using ShRUIOpLowering =
99 using SIToFPOpLowering =
101 using SubFOpLowering =
102  VectorConvertToLLVMPattern<arith::SubFOp, LLVM::FSubOp,
103  arith::AttrConvertFastMathToLLVM>;
105 using TruncFOpLowering =
107 using TruncIOpLowering =
109 using UIToFPOpLowering =
112 
113 //===----------------------------------------------------------------------===//
114 // Op Lowering Patterns
115 //===----------------------------------------------------------------------===//
116 
117 /// Directly lower to LLVM op.
118 struct ConstantOpLowering : public ConvertOpToLLVMPattern<arith::ConstantOp> {
120 
122  matchAndRewrite(arith::ConstantOp op, OpAdaptor adaptor,
123  ConversionPatternRewriter &rewriter) const override;
124 };
125 
126 /// The lowering of index_cast becomes an integer conversion since index
127 /// becomes an integer. If the bit width of the source and target integer
128 /// types is the same, just erase the cast. If the target type is wider,
129 /// sign-extend the value, otherwise truncate it.
130 template <typename OpTy, typename ExtCastTy>
131 struct IndexCastOpLowering : public ConvertOpToLLVMPattern<OpTy> {
133 
135  matchAndRewrite(OpTy op, typename OpTy::Adaptor adaptor,
136  ConversionPatternRewriter &rewriter) const override;
137 };
138 
139 using IndexCastOpSILowering =
140  IndexCastOpLowering<arith::IndexCastOp, LLVM::SExtOp>;
141 using IndexCastOpUILowering =
142  IndexCastOpLowering<arith::IndexCastUIOp, LLVM::ZExtOp>;
143 
144 struct AddUIExtendedOpLowering
145  : public ConvertOpToLLVMPattern<arith::AddUIExtendedOp> {
147 
149  matchAndRewrite(arith::AddUIExtendedOp op, OpAdaptor adaptor,
150  ConversionPatternRewriter &rewriter) const override;
151 };
152 
153 template <typename ArithMulOp, bool IsSigned>
154 struct MulIExtendedOpLowering : public ConvertOpToLLVMPattern<ArithMulOp> {
156 
158  matchAndRewrite(ArithMulOp op, typename ArithMulOp::Adaptor adaptor,
159  ConversionPatternRewriter &rewriter) const override;
160 };
161 
162 using MulSIExtendedOpLowering =
163  MulIExtendedOpLowering<arith::MulSIExtendedOp, true>;
164 using MulUIExtendedOpLowering =
165  MulIExtendedOpLowering<arith::MulUIExtendedOp, false>;
166 
167 struct CmpIOpLowering : public ConvertOpToLLVMPattern<arith::CmpIOp> {
169 
171  matchAndRewrite(arith::CmpIOp op, OpAdaptor adaptor,
172  ConversionPatternRewriter &rewriter) const override;
173 };
174 
175 struct CmpFOpLowering : public ConvertOpToLLVMPattern<arith::CmpFOp> {
177 
179  matchAndRewrite(arith::CmpFOp op, OpAdaptor adaptor,
180  ConversionPatternRewriter &rewriter) const override;
181 };
182 
183 } // namespace
184 
185 //===----------------------------------------------------------------------===//
186 // ConstantOpLowering
187 //===----------------------------------------------------------------------===//
188 
190 ConstantOpLowering::matchAndRewrite(arith::ConstantOp op, OpAdaptor adaptor,
191  ConversionPatternRewriter &rewriter) const {
192  return LLVM::detail::oneToOneRewrite(op, LLVM::ConstantOp::getOperationName(),
193  adaptor.getOperands(), op->getAttrs(),
194  *getTypeConverter(), rewriter);
195 }
196 
197 //===----------------------------------------------------------------------===//
198 // IndexCastOpLowering
199 //===----------------------------------------------------------------------===//
200 
201 template <typename OpTy, typename ExtCastTy>
202 LogicalResult IndexCastOpLowering<OpTy, ExtCastTy>::matchAndRewrite(
203  OpTy op, typename OpTy::Adaptor adaptor,
204  ConversionPatternRewriter &rewriter) const {
205  Type resultType = op.getResult().getType();
206  Type targetElementType =
207  this->typeConverter->convertType(getElementTypeOrSelf(resultType));
208  Type sourceElementType =
209  this->typeConverter->convertType(getElementTypeOrSelf(op.getIn()));
210  unsigned targetBits = targetElementType.getIntOrFloatBitWidth();
211  unsigned sourceBits = sourceElementType.getIntOrFloatBitWidth();
212 
213  if (targetBits == sourceBits) {
214  rewriter.replaceOp(op, adaptor.getIn());
215  return success();
216  }
217 
218  // Handle the scalar and 1D vector cases.
219  Type operandType = adaptor.getIn().getType();
220  if (!isa<LLVM::LLVMArrayType>(operandType)) {
221  Type targetType = this->typeConverter->convertType(resultType);
222  if (targetBits < sourceBits)
223  rewriter.replaceOpWithNewOp<LLVM::TruncOp>(op, targetType,
224  adaptor.getIn());
225  else
226  rewriter.replaceOpWithNewOp<ExtCastTy>(op, targetType, adaptor.getIn());
227  return success();
228  }
229 
230  if (!isa<VectorType>(resultType))
231  return rewriter.notifyMatchFailure(op, "expected vector result type");
232 
234  op.getOperation(), adaptor.getOperands(), *(this->getTypeConverter()),
235  [&](Type llvm1DVectorTy, ValueRange operands) -> Value {
236  typename OpTy::Adaptor adaptor(operands);
237  if (targetBits < sourceBits) {
238  return rewriter.create<LLVM::TruncOp>(op.getLoc(), llvm1DVectorTy,
239  adaptor.getIn());
240  }
241  return rewriter.create<ExtCastTy>(op.getLoc(), llvm1DVectorTy,
242  adaptor.getIn());
243  },
244  rewriter);
245 }
246 
247 //===----------------------------------------------------------------------===//
248 // AddUIExtendedOpLowering
249 //===----------------------------------------------------------------------===//
250 
251 LogicalResult AddUIExtendedOpLowering::matchAndRewrite(
252  arith::AddUIExtendedOp op, OpAdaptor adaptor,
253  ConversionPatternRewriter &rewriter) const {
254  Type operandType = adaptor.getLhs().getType();
255  Type sumResultType = op.getSum().getType();
256  Type overflowResultType = op.getOverflow().getType();
257 
258  if (!LLVM::isCompatibleType(operandType))
259  return failure();
260 
261  MLIRContext *ctx = rewriter.getContext();
262  Location loc = op.getLoc();
263 
264  // Handle the scalar and 1D vector cases.
265  if (!isa<LLVM::LLVMArrayType>(operandType)) {
266  Type newOverflowType = typeConverter->convertType(overflowResultType);
267  Type structType =
268  LLVM::LLVMStructType::getLiteral(ctx, {sumResultType, newOverflowType});
269  Value addOverflow = rewriter.create<LLVM::UAddWithOverflowOp>(
270  loc, structType, adaptor.getLhs(), adaptor.getRhs());
271  Value sumExtracted =
272  rewriter.create<LLVM::ExtractValueOp>(loc, addOverflow, 0);
273  Value overflowExtracted =
274  rewriter.create<LLVM::ExtractValueOp>(loc, addOverflow, 1);
275  rewriter.replaceOp(op, {sumExtracted, overflowExtracted});
276  return success();
277  }
278 
279  if (!isa<VectorType>(sumResultType))
280  return rewriter.notifyMatchFailure(loc, "expected vector result types");
281 
282  return rewriter.notifyMatchFailure(loc,
283  "ND vector types are not supported yet");
284 }
285 
286 //===----------------------------------------------------------------------===//
287 // MulIExtendedOpLowering
288 //===----------------------------------------------------------------------===//
289 
290 template <typename ArithMulOp, bool IsSigned>
291 LogicalResult MulIExtendedOpLowering<ArithMulOp, IsSigned>::matchAndRewrite(
292  ArithMulOp op, typename ArithMulOp::Adaptor adaptor,
293  ConversionPatternRewriter &rewriter) const {
294  Type resultType = adaptor.getLhs().getType();
295 
296  if (!LLVM::isCompatibleType(resultType))
297  return failure();
298 
299  Location loc = op.getLoc();
300 
301  // Handle the scalar and 1D vector cases. Because LLVM does not have a
302  // matching extended multiplication intrinsic, perform regular multiplication
303  // on operands zero-extended to i(2*N) bits, and truncate the results back to
304  // iN types.
305  if (!isa<LLVM::LLVMArrayType>(resultType)) {
306  // Shift amount necessary to extract the high bits from widened result.
307  TypedAttr shiftValAttr;
308 
309  if (auto intTy = dyn_cast<IntegerType>(resultType)) {
310  unsigned resultBitwidth = intTy.getWidth();
311  auto attrTy = rewriter.getIntegerType(resultBitwidth * 2);
312  shiftValAttr = rewriter.getIntegerAttr(attrTy, resultBitwidth);
313  } else {
314  auto vecTy = cast<VectorType>(resultType);
315  unsigned resultBitwidth = vecTy.getElementTypeBitWidth();
316  auto attrTy = VectorType::get(
317  vecTy.getShape(), rewriter.getIntegerType(resultBitwidth * 2));
318  shiftValAttr = SplatElementsAttr::get(
319  attrTy, APInt(resultBitwidth * 2, resultBitwidth));
320  }
321  Type wideType = shiftValAttr.getType();
322  assert(LLVM::isCompatibleType(wideType) &&
323  "LLVM dialect should support all signless integer types");
324 
325  using LLVMExtOp = std::conditional_t<IsSigned, LLVM::SExtOp, LLVM::ZExtOp>;
326  Value lhsExt = rewriter.create<LLVMExtOp>(loc, wideType, adaptor.getLhs());
327  Value rhsExt = rewriter.create<LLVMExtOp>(loc, wideType, adaptor.getRhs());
328  Value mulExt = rewriter.create<LLVM::MulOp>(loc, wideType, lhsExt, rhsExt);
329 
330  // Split the 2*N-bit wide result into two N-bit values.
331  Value low = rewriter.create<LLVM::TruncOp>(loc, resultType, mulExt);
332  Value shiftVal = rewriter.create<LLVM::ConstantOp>(loc, shiftValAttr);
333  Value highExt = rewriter.create<LLVM::LShrOp>(loc, mulExt, shiftVal);
334  Value high = rewriter.create<LLVM::TruncOp>(loc, resultType, highExt);
335 
336  rewriter.replaceOp(op, {low, high});
337  return success();
338  }
339 
340  if (!isa<VectorType>(resultType))
341  return rewriter.notifyMatchFailure(op, "expected vector result type");
342 
343  return rewriter.notifyMatchFailure(op,
344  "ND vector types are not supported yet");
345 }
346 
347 //===----------------------------------------------------------------------===//
348 // CmpIOpLowering
349 //===----------------------------------------------------------------------===//
350 
351 // Convert arith.cmp predicate into the LLVM dialect CmpPredicate. The two enums
352 // share numerical values so just cast.
353 template <typename LLVMPredType, typename PredType>
354 static LLVMPredType convertCmpPredicate(PredType pred) {
355  return static_cast<LLVMPredType>(pred);
356 }
357 
359 CmpIOpLowering::matchAndRewrite(arith::CmpIOp op, OpAdaptor adaptor,
360  ConversionPatternRewriter &rewriter) const {
361  Type operandType = adaptor.getLhs().getType();
362  Type resultType = op.getResult().getType();
363 
364  // Handle the scalar and 1D vector cases.
365  if (!isa<LLVM::LLVMArrayType>(operandType)) {
366  rewriter.replaceOpWithNewOp<LLVM::ICmpOp>(
367  op, typeConverter->convertType(resultType),
368  convertCmpPredicate<LLVM::ICmpPredicate>(op.getPredicate()),
369  adaptor.getLhs(), adaptor.getRhs());
370  return success();
371  }
372 
373  if (!isa<VectorType>(resultType))
374  return rewriter.notifyMatchFailure(op, "expected vector result type");
375 
377  op.getOperation(), adaptor.getOperands(), *getTypeConverter(),
378  [&](Type llvm1DVectorTy, ValueRange operands) {
379  OpAdaptor adaptor(operands);
380  return rewriter.create<LLVM::ICmpOp>(
381  op.getLoc(), llvm1DVectorTy,
382  convertCmpPredicate<LLVM::ICmpPredicate>(op.getPredicate()),
383  adaptor.getLhs(), adaptor.getRhs());
384  },
385  rewriter);
386 }
387 
388 //===----------------------------------------------------------------------===//
389 // CmpFOpLowering
390 //===----------------------------------------------------------------------===//
391 
393 CmpFOpLowering::matchAndRewrite(arith::CmpFOp op, OpAdaptor adaptor,
394  ConversionPatternRewriter &rewriter) const {
395  Type operandType = adaptor.getLhs().getType();
396  Type resultType = op.getResult().getType();
397 
398  // Handle the scalar and 1D vector cases.
399  if (!isa<LLVM::LLVMArrayType>(operandType)) {
400  rewriter.replaceOpWithNewOp<LLVM::FCmpOp>(
401  op, typeConverter->convertType(resultType),
402  convertCmpPredicate<LLVM::FCmpPredicate>(op.getPredicate()),
403  adaptor.getLhs(), adaptor.getRhs());
404  return success();
405  }
406 
407  if (!isa<VectorType>(resultType))
408  return rewriter.notifyMatchFailure(op, "expected vector result type");
409 
411  op.getOperation(), adaptor.getOperands(), *getTypeConverter(),
412  [&](Type llvm1DVectorTy, ValueRange operands) {
413  OpAdaptor adaptor(operands);
414  return rewriter.create<LLVM::FCmpOp>(
415  op.getLoc(), llvm1DVectorTy,
416  convertCmpPredicate<LLVM::FCmpPredicate>(op.getPredicate()),
417  adaptor.getLhs(), adaptor.getRhs());
418  },
419  rewriter);
420 }
421 
422 //===----------------------------------------------------------------------===//
423 // Pass Definition
424 //===----------------------------------------------------------------------===//
425 
426 namespace {
427 struct ArithToLLVMConversionPass
428  : public impl::ArithToLLVMConversionPassBase<ArithToLLVMConversionPass> {
429  using Base::Base;
430 
431  void runOnOperation() override {
433  RewritePatternSet patterns(&getContext());
434 
436  if (indexBitwidth != kDeriveIndexBitwidthFromDataLayout)
437  options.overrideIndexBitwidth(indexBitwidth);
438 
439  LLVMTypeConverter converter(&getContext(), options);
441 
442  if (failed(applyPartialConversion(getOperation(), target,
443  std::move(patterns))))
444  signalPassFailure();
445  }
446 };
447 } // namespace
448 
449 //===----------------------------------------------------------------------===//
450 // ConvertToLLVMPatternInterface implementation
451 //===----------------------------------------------------------------------===//
452 
453 namespace {
454 /// Implement the interface to convert MemRef to LLVM.
455 struct ArithToLLVMDialectInterface : public ConvertToLLVMPatternInterface {
457  void loadDependentDialects(MLIRContext *context) const final {
458  context->loadDialect<LLVM::LLVMDialect>();
459  }
460 
461  /// Hook for derived dialect interface to provide conversion patterns
462  /// and mark dialect legal for the conversion target.
464  ConversionTarget &target, LLVMTypeConverter &typeConverter,
465  RewritePatternSet &patterns) const final {
466  arith::populateArithToLLVMConversionPatterns(typeConverter, patterns);
467  }
468 };
469 } // namespace
470 
472  DialectRegistry &registry) {
473  registry.addExtension(+[](MLIRContext *ctx, arith::ArithDialect *dialect) {
474  dialect->addInterfaces<ArithToLLVMDialectInterface>();
475  });
476 }
477 
478 //===----------------------------------------------------------------------===//
479 // Pattern Population
480 //===----------------------------------------------------------------------===//
481 
483  LLVMTypeConverter &converter, RewritePatternSet &patterns) {
484  // clang-format off
485  patterns.add<
486  AddFOpLowering,
487  AddIOpLowering,
488  AndIOpLowering,
489  AddUIExtendedOpLowering,
490  BitcastOpLowering,
491  ConstantOpLowering,
492  CmpFOpLowering,
493  CmpIOpLowering,
494  DivFOpLowering,
495  DivSIOpLowering,
496  DivUIOpLowering,
497  ExtFOpLowering,
498  ExtSIOpLowering,
499  ExtUIOpLowering,
500  FPToSIOpLowering,
501  FPToUIOpLowering,
502  IndexCastOpSILowering,
503  IndexCastOpUILowering,
504  MaximumFOpLowering,
505  MaxNumFOpLowering,
506  MaxSIOpLowering,
507  MaxUIOpLowering,
508  MinimumFOpLowering,
509  MinNumFOpLowering,
510  MinSIOpLowering,
511  MinUIOpLowering,
512  MulFOpLowering,
513  MulIOpLowering,
514  MulSIExtendedOpLowering,
515  MulUIExtendedOpLowering,
516  NegFOpLowering,
517  OrIOpLowering,
518  RemFOpLowering,
519  RemSIOpLowering,
520  RemUIOpLowering,
521  SelectOpLowering,
522  ShLIOpLowering,
523  ShRSIOpLowering,
524  ShRUIOpLowering,
525  SIToFPOpLowering,
526  SubFOpLowering,
527  SubIOpLowering,
528  TruncFOpLowering,
529  TruncIOpLowering,
530  UIToFPOpLowering,
531  XOrIOpLowering
532  >(converter);
533  // clang-format on
534 }
static LLVMPredType convertCmpPredicate(PredType pred)
static MLIRContext * getContext(OpFoldResult val)
static llvm::ManagedStatic< PassManagerOptions > options
static Value handleMultidimensionalVectors(ImplicitLocOpBuilder &builder, ValueRange operands, int64_t vectorWidth, llvm::function_ref< Value(ValueRange)> compute)
IntegerAttr getIntegerAttr(Type type, int64_t value)
Definition: Builders.cpp:238
IntegerType getIntegerType(unsigned width)
Definition: Builders.cpp:87
MLIRContext * getContext() const
Definition: Builders.h:55
This class implements a pattern rewriter for use with ConversionPatterns.
void replaceOp(Operation *op, ValueRange newValues) override
PatternRewriter hook for replacing an operation.
LogicalResult notifyMatchFailure(Location loc, function_ref< void(Diagnostic &)> reasonCallback) override
PatternRewriter hook for notifying match failure reasons.
This class describes a specific conversion target.
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
Definition: Pattern.h:139
ConvertOpToLLVMPattern(const LLVMTypeConverter &typeConverter, PatternBenefit benefit=1)
Definition: Pattern.h:143
Base class for dialect interfaces providing translation to LLVM IR.
virtual void populateConvertToLLVMConversionPatterns(ConversionTarget &target, LLVMTypeConverter &typeConverter, RewritePatternSet &patterns) const =0
Hook for derived dialect interface to provide conversion patterns and mark dialect legal for the conv...
virtual void loadDependentDialects(MLIRContext *context) const
Hook for derived dialect interface to load the dialects they target.
ConvertToLLVMPatternInterface(Dialect *dialect)
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
void addExtension(std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
Derived class that automatically populates legalization information for different LLVM ops.
Conversion from types to the LLVM IR dialect.
Definition: TypeConverter.h:33
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
Options to control the LLVM lowering.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Definition: Builders.cpp:446
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
Definition: Operation.h:402
Location getLoc()
The source location the operation was defined or derived from.
Definition: Operation.h:223
ArrayRef< NamedAttribute > getAttrs()
Return all of the attributes on this operation.
Definition: Operation.h:486
operand_range getOperands()
Returns an iterator on the underlying Value's.
Definition: Operation.h:373
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replaces the result op with a new op that is created without verification.
Definition: PatternMatch.h:539
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
Definition: Types.cpp:123
This class provides an abstraction over the different types of ranges over Values.
Definition: ValueRange.h:378
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
Type getType() const
Return the type of this value.
Definition: Value.h:125
Basic lowering implementation to rewrite Ops with just one result to the LLVM Dialect.
Definition: VectorPattern.h:87
LogicalResult handleMultidimensionalVectors(Operation *op, ValueRange operands, const LLVMTypeConverter &typeConverter, std::function< Value(Type, ValueRange)> createOperand, ConversionPatternRewriter &rewriter)
LogicalResult oneToOneRewrite(Operation *op, StringRef targetOp, ValueRange operands, ArrayRef< NamedAttribute > targetAttrs, const LLVMTypeConverter &typeConverter, ConversionPatternRewriter &rewriter)
Replaces the given operation "op" with a new operation of type "targetOp" and given operands.
Definition: Pattern.cpp:335
bool isCompatibleType(Type type)
Returns true if the given type is compatible with the LLVM dialect.
Definition: LLVMTypes.cpp:845
void registerConvertArithToLLVMInterface(DialectRegistry &registry)
void populateArithToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns)
LLVM_ATTRIBUTE_ALWAYS_INLINE bool addOverflow(int64_t x, int64_t y, int64_t &result)
If builtin intrinsics for overflow-checked arithmetic are available, use them.
Definition: MPInt.h:45
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
static constexpr unsigned kDeriveIndexBitwidthFromDataLayout
Value to pass as bitwidth for the index type when the converter is expected to derive the bitwidth fr...
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, DenseSet< Operation * > *unconvertedOps=nullptr)
Below we define several entry points for operation conversion.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
Type getElementTypeOrSelf(Type type)
Return the element type or return the type itself.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26