19#define GEN_PASS_DEF_NVVMOPTIMIZEFORTARGETPASS
20#include "mlir/Dialect/LLVMIR/Transforms/Passes.h.inc"
35 using OpRewritePattern<LLVM::FDivOp>::OpRewritePattern;
38 LogicalResult matchAndRewrite(LLVM::FDivOp op,
39 PatternRewriter &rewriter)
const override;
42struct NVVMOptimizeForTarget
44 void runOnOperation()
override;
46 void getDependentDialects(DialectRegistry ®istry)
const override {
47 registry.
insert<NVVM::NVVMDialect>();
52LogicalResult ExpandDivF16::matchAndRewrite(LLVM::FDivOp op,
54 if (!op.getType().isF16())
56 Location loc = op.getLoc();
62 Value
lhs = LLVM::FPExtOp::create(rewriter, loc, f32Type, op.getLhs());
63 Value
rhs = LLVM::FPExtOp::create(rewriter, loc, f32Type, op.getRhs());
66 Value rcp = NVVM::RcpApproxFtzF32Op::create(rewriter, loc, f32Type,
rhs);
67 Value approx = LLVM::FMulOp::create(rewriter, loc,
lhs, rcp);
71 Value err = LLVM::FMAOp::create(
72 rewriter, loc, approx, LLVM::FNegOp::create(rewriter, loc,
rhs),
lhs);
73 Value refined = LLVM::FMAOp::create(rewriter, loc, err, rcp, approx);
76 Value mask = LLVM::ConstantOp::create(
78 Value cast = LLVM::BitcastOp::create(rewriter, loc, i32Type, approx);
79 Value exp = LLVM::AndOp::create(rewriter, loc, i32Type, cast, mask);
80 Value zero = LLVM::ConstantOp::create(rewriter, loc, i32Type,
82 Value pred = LLVM::OrOp::create(
84 LLVM::ICmpOp::create(rewriter, loc, LLVM::ICmpPredicate::eq, exp, zero),
85 LLVM::ICmpOp::create(rewriter, loc, LLVM::ICmpPredicate::eq, exp, mask));
87 LLVM::SelectOp::create(rewriter, loc, f32Type, pred, approx, refined);
95void NVVMOptimizeForTarget::runOnOperation() {
96 MLIRContext *ctx = getOperation()->getContext();
100 return signalPassFailure();
IntegerAttr getUI32IntegerAttr(uint32_t value)
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...
Include the generated interface declarations.
LogicalResult applyPatternsGreedily(Region ®ion, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...
const FrozenRewritePatternSet & patterns
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...