19#define GEN_PASS_DEF_NVVMOPTIMIZEFORTARGETPASS
20#include "mlir/Dialect/NVVM/Transforms/Passes.h.inc"
38 LogicalResult matchAndRewrite(LLVM::FDivOp op,
42struct NVVMOptimizeForTarget
47 registry.
insert<NVVM::NVVMDialect>();
52LogicalResult ExpandDivF16::matchAndRewrite(LLVM::FDivOp op,
54 if (!op.getType().isF16())
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() {
98 patterns.add<ExpandDivF16>(ctx);
100 return signalPassFailure();
IntegerAttr getUI32IntegerAttr(uint32_t value)
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
void getDependentDialects(::mlir::DialectRegistry ®istry) const override
Return the dialect that must be loaded in the context before this pass.
virtual void runOnOperation()=0
The polymorphic API that runs the pass over the currently held operation.
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...
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...
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...
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...