10 #include "../PassDetail.h" 28 using DivUIOpLowering =
30 using DivSIOpLowering =
32 using RemUIOpLowering =
34 using RemSIOpLowering =
40 using ShRUIOpLowering =
42 using ShRSIOpLowering =
50 using ExtUIOpLowering =
52 using ExtSIOpLowering =
55 using TruncIOpLowering =
57 using TruncFOpLowering =
59 using UIToFPOpLowering =
61 using SIToFPOpLowering =
63 using FPToUIOpLowering =
65 using FPToSIOpLowering =
67 using BitcastOpLowering =
69 using SelectOpLowering =
81 matchAndRewrite(arith::ConstantOp op, OpAdaptor adaptor,
93 matchAndRewrite(arith::IndexCastOp op, OpAdaptor adaptor,
101 matchAndRewrite(arith::CmpIOp op, OpAdaptor adaptor,
109 matchAndRewrite(arith::CmpFOp op, OpAdaptor adaptor,
120 ConstantOpLowering::matchAndRewrite(arith::ConstantOp op, OpAdaptor adaptor,
123 adaptor.getOperands(),
124 *getTypeConverter(), rewriter);
132 arith::IndexCastOp op, OpAdaptor adaptor,
134 auto targetType = typeConverter->convertType(op.getResult().getType());
135 auto targetElementType =
137 .cast<IntegerType>();
138 auto sourceElementType =
140 unsigned targetBits = targetElementType.getWidth();
141 unsigned sourceBits = sourceElementType.getWidth();
143 if (targetBits == sourceBits)
145 else if (targetBits < sourceBits)
158 template <
typename LLVMPredType,
typename PredType>
160 return static_cast<LLVMPredType
>(pred);
164 CmpIOpLowering::matchAndRewrite(arith::CmpIOp op, OpAdaptor adaptor,
166 auto operandType = adaptor.getLhs().getType();
167 auto resultType = op.getResult().getType();
172 op, typeConverter->convertType(resultType),
173 convertCmpPredicate<LLVM::ICmpPredicate>(op.getPredicate()),
174 adaptor.getLhs(), adaptor.getRhs());
178 auto vectorType = resultType.dyn_cast<VectorType>();
183 op.getOperation(), adaptor.getOperands(), *getTypeConverter(),
185 OpAdaptor adaptor(operands);
186 return rewriter.
create<LLVM::ICmpOp>(
187 op.getLoc(), llvm1DVectorTy,
188 convertCmpPredicate<LLVM::ICmpPredicate>(op.getPredicate()),
189 adaptor.getLhs(), adaptor.getRhs());
199 CmpFOpLowering::matchAndRewrite(arith::CmpFOp op, OpAdaptor adaptor,
201 auto operandType = adaptor.getLhs().getType();
202 auto resultType = op.getResult().getType();
207 op, typeConverter->convertType(resultType),
208 convertCmpPredicate<LLVM::FCmpPredicate>(op.getPredicate()),
209 adaptor.getLhs(), adaptor.getRhs());
213 auto vectorType = resultType.dyn_cast<VectorType>();
218 op.getOperation(), adaptor.getOperands(), *getTypeConverter(),
220 OpAdaptor adaptor(operands);
221 return rewriter.
create<LLVM::FCmpOp>(
222 op.getLoc(), llvm1DVectorTy,
223 convertCmpPredicate<LLVM::FCmpPredicate>(op.getPredicate()),
224 adaptor.getLhs(), adaptor.getRhs());
234 struct ConvertArithmeticToLLVMPass
235 :
public ConvertArithmeticToLLVMBase<ConvertArithmeticToLLVMPass> {
236 ConvertArithmeticToLLVMPass() =
default;
238 void runOnOperation()
override {
251 std::move(patterns))))
304 return std::make_unique<ConvertArithmeticToLLVMPass>();
Include the generated interface declarations.
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
LogicalResult applyPartialConversion(ArrayRef< Operation *> ops, ConversionTarget &target, const FrozenRewritePatternSet &patterns, DenseSet< Operation *> *unconvertedOps=nullptr)
Below we define several entry points for operation conversion.
Basic lowering implementation to rewrite Ops with just one result to the LLVM Dialect.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
LogicalResult handleMultidimensionalVectors(Operation *op, ValueRange operands, LLVMTypeConverter &typeConverter, std::function< Value(Type, ValueRange)> createOperand, ConversionPatternRewriter &rewriter)
Derived class that automatically populates legalization information for different LLVM ops...
void populateArithmeticToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns)
std::unique_ptr< Pass > createConvertArithmeticToLLVMPass()
void replaceOp(Operation *op, ValueRange newValues) override
PatternRewriter hook for replacing the results of an operation.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
This class represents an efficient way to signal success or failure.
Type getElementTypeOrSelf(Type type)
Return the element type or return the type itself.
void overrideIndexBitwidth(unsigned bitwidth)
Set the index bitwidth to the given value.
LogicalResult notifyMatchFailure(Location loc, function_ref< void(Diagnostic &)> reasonCallback) override
PatternRewriter hook for notifying match failure reasons.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
static constexpr unsigned kDeriveIndexBitwidthFromDataLayout
Value to pass as bitwidth for the index type when the converter is expected to derive the bitwidth fr...
static llvm::ManagedStatic< PassManagerOptions > options
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.
Conversion from types to the LLVM IR dialect.
static VectorType vectorType(CodeGen &codegen, Type etp)
Constructs vector type.
Options to control the LLVM lowering.
This class implements a pattern rewriter for use with ConversionPatterns.
LogicalResult oneToOneRewrite(Operation *op, StringRef targetOp, ValueRange operands, LLVMTypeConverter &typeConverter, ConversionPatternRewriter &rewriter)
Replaces the given operation "op" with a new operation of type "targetOp" and given operands...
This class provides an abstraction over the different types of ranges over Values.
static LLVMPredType convertCmpPredicate(PredType pred)