8 #ifndef MLIR_CONVERSION_GPUCOMMON_OPTOFUNCCALLLOWERING_H_
9 #define MLIR_CONVERSION_GPUCOMMON_OPTOFUNCCALLLOWERING_H_
30 template <
typename SourceOp>
41 using LLVM::LLVMFuncOp;
45 "expected single result op");
49 "expected op with same operand and result types");
52 for (
Value operand : adaptor.getOperands())
53 castedOperands.push_back(maybeCast(operand, rewriter));
55 Type resultType = castedOperands.front().getType();
56 Type funcType = getFunctionType(resultType, castedOperands);
58 getFunctionName(cast<LLVM::LLVMFunctionType>(funcType).getReturnType());
62 LLVMFuncOp funcOp = appendOrGetFuncOp(funcName, funcType, op);
64 rewriter.
create<LLVM::CallOp>(op->getLoc(), funcOp, castedOperands);
66 if (resultType == adaptor.getOperands().front().getType()) {
67 rewriter.
replaceOp(op, {callOp.getResult()});
72 op->getLoc(), adaptor.getOperands().front().getType(),
81 if (!isa<Float16Type>(type))
84 return rewriter.
create<LLVM::FPExtOp>(
88 Type getFunctionType(Type resultType, ValueRange operands)
const {
89 SmallVector<Type> operandTypes(operands.getTypes());
93 StringRef getFunctionName(Type type)
const {
94 if (isa<Float32Type>(type))
96 if (isa<Float64Type>(type))
101 LLVM::LLVMFuncOp appendOrGetFuncOp(StringRef funcName, Type funcType,
102 Operation *op)
const {
103 using LLVM::LLVMFuncOp;
108 return cast<LLVMFuncOp>(*funcOp);
111 return b.create<LLVMFuncOp>(op->getLoc(), funcName, funcType);
114 const std::string f32Func;
115 const std::string f64Func;
MLIRContext * getContext() const
This class implements a pattern rewriter for use with ConversionPatterns.
void replaceOp(Operation *op, ValueRange newValues) override
PatternRewriter hook for replacing an operation.
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
Conversion from types to the LLVM IR dialect.
This class helps build Operations.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
This class provides return value APIs for ops that are known to have a single result.
This class provides verification for ops that are known to have the same operand and result type.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
static Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
Location getLoc() const
Return the location of this value.
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
This class represents an efficient way to signal success or failure.
Rewriting that replace SourceOp with a CallOp to f32Func or f64Func depending on the element type tha...
LogicalResult matchAndRewrite(SourceOp op, typename SourceOp::Adaptor adaptor, ConversionPatternRewriter &rewriter) const override
OpToFuncCallLowering(LLVMTypeConverter &lowering, StringRef f32Func, StringRef f64Func)