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);
57 StringRef funcName = getFunctionName(
62 LLVMFuncOp funcOp = appendOrGetFuncOp(funcName, funcType, op);
63 auto callOp = rewriter.
create<LLVM::CallOp>(
64 op->getLoc(), resultType, SymbolRefAttr::get(funcOp), castedOperands);
66 if (resultType == adaptor.getOperands().front().getType()) {
67 rewriter.
replaceOp(op, {callOp.getResult(0)});
72 op->getLoc(), adaptor.getOperands().front().getType(),
81 if (!type.
isa<Float16Type>())
84 return rewriter.
create<LLVM::FPExtOp>(
93 StringRef getFunctionName(
Type type)
const {
94 if (type.
isa<Float32Type>())
96 if (type.
isa<Float64Type>())
101 LLVM::LLVMFuncOp appendOrGetFuncOp(StringRef funcName,
Type funcType,
103 using LLVM::LLVMFuncOp;
105 auto funcAttr = StringAttr::get(op->
getContext(), funcName);
108 return cast<LLVMFuncOp>(*funcOp);
111 return b.
create<LLVMFuncOp>(op->
getLoc(), funcName, funcType);
114 const std::string f32Func;
115 const std::string f64Func;
120 #endif // MLIR_CONVERSION_GPUCOMMON_OPTOFUNCCALLLOWERING_H_ TODO: Remove this file when SCCP and integer range analysis have been ported to the new framework...
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
MLIRContext * getContext() const
OpToFuncCallLowering(LLVMTypeConverter &lowering, StringRef f32Func, StringRef f64Func)
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
Operation is a basic unit of execution within MLIR.
This class provides return value APIs for ops that are known to have a single result.
LLVM dialect function type.
static LLVMFunctionType get(Type result, ArrayRef< Type > arguments, bool isVarArg=false)
Gets or creates an instance of LLVM dialect function in the same context as the result type...
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
void replaceOp(Operation *op, ValueRange newValues) override
PatternRewriter hook for replacing the results of an operation.
static constexpr const bool value
MLIRContext * getContext()
Return the context this operation is associated with.
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.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
This class provides verification for ops that are known to have the same operand and result type...
Location getLoc()
The source location the operation was defined or derived from.
Location getLoc() const
Return the location of this value.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
static Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of...
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.
type_range getTypes() const
Conversion from types to the LLVM IR dialect.
This class implements a pattern rewriter for use with ConversionPatterns.
Type getReturnType() const
Returns the result type of the function.
LogicalResult matchAndRewrite(SourceOp op, typename SourceOp::Adaptor adaptor, ConversionPatternRewriter &rewriter) const override
This class helps build Operations.
This class provides an abstraction over the different types of ranges over Values.
Rewriting that replace SourceOp with a CallOp to f32Func or f64Func depending on the element type tha...