18 template <
typename OpType>
20 std::string calleeStr;
24 LowerToEmitCCallOpaque(
MLIRContext *context, std::string calleeStr,
27 languageTarget(languageTarget) {}
29 LogicalResult matchAndRewrite(OpType op,
33 template <
typename OpType>
34 LogicalResult LowerToEmitCCallOpaque<OpType>::matchAndRewrite(
36 if (!llvm::all_of(op->getOperandTypes(),
37 llvm::IsaPred<Float32Type, Float64Type>) ||
38 !llvm::all_of(op->getResultTypes(),
39 llvm::IsaPred<Float32Type, Float64Type>))
42 "expected all operands and results to be of type f32 or f64");
43 std::string modifiedCalleeStr = calleeStr;
45 modifiedCalleeStr =
"std::" + calleeStr;
47 auto operandType = op->getOperandTypes()[0];
48 if (operandType.isF32())
49 modifiedCalleeStr = calleeStr +
"f";
52 op, op.getType(), modifiedCalleeStr, op->getOperands());
62 auto *context =
patterns.getContext();
63 patterns.insert<LowerToEmitCCallOpaque<math::FloorOp>>(context,
"floor",
65 patterns.insert<LowerToEmitCCallOpaque<math::RoundOp>>(context,
"round",
67 patterns.insert<LowerToEmitCCallOpaque<math::ExpOp>>(context,
"exp",
69 patterns.insert<LowerToEmitCCallOpaque<math::CosOp>>(context,
"cos",
71 patterns.insert<LowerToEmitCCallOpaque<math::SinOp>>(context,
"sin",
73 patterns.insert<LowerToEmitCCallOpaque<math::AcosOp>>(context,
"acos",
75 patterns.insert<LowerToEmitCCallOpaque<math::AsinOp>>(context,
"asin",
77 patterns.insert<LowerToEmitCCallOpaque<math::Atan2Op>>(context,
"atan2",
79 patterns.insert<LowerToEmitCCallOpaque<math::CeilOp>>(context,
"ceil",
81 patterns.insert<LowerToEmitCCallOpaque<math::AbsFOp>>(context,
"fabs",
83 patterns.insert<LowerToEmitCCallOpaque<math::PowFOp>>(context,
"pow",
MLIRContext is the top-level object for a collection of MLIR operations.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
LanguageTarget
Enum to specify the language target for EmitC code generation.
Include the generated interface declarations.
void populateConvertMathToEmitCPatterns(RewritePatternSet &patterns, emitc::LanguageTarget languageTarget)
const FrozenRewritePatternSet & patterns
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...