28#include "llvm/Support/DebugLog.h"
29#include "llvm/Support/LogicalResult.h"
30#include "llvm/Support/raw_ostream.h"
32#define DEBUG_TYPE "nvvm-to-llvm"
35#define GEN_PASS_DEF_CONVERTNVVMTOLLVMPASS
36#include "mlir/Conversion/Passes.h.inc"
46 using OpInterfaceRewritePattern<
47 BasicPtxBuilderInterface>::OpInterfaceRewritePattern;
49 PtxLowering(MLIRContext *context, PatternBenefit benefit = 2)
50 : OpInterfaceRewritePattern(context, benefit) {}
52 LogicalResult matchAndRewrite(BasicPtxBuilderInterface op,
53 PatternRewriter &rewriter)
const override {
54 if (op.hasIntrinsic()) {
55 LDBG() <<
"Ptx Builder does not lower \n\t" << op;
59 SmallVector<std::pair<Value, PTXRegisterMod>> asmValues;
60 LDBG() << op.getPtx();
62 bool needsManualMapping = op.getAsmValues(rewriter, asmValues);
63 PtxBuilder
generator(op, rewriter, needsManualMapping);
64 for (
auto &[asmValue, modifier] : asmValues) {
65 LDBG() << asmValue <<
"\t Modifier : " << modifier;
75struct ConvertNVVMToLLVMPass
79 void getDependentDialects(DialectRegistry ®istry)
const override {
80 registry.
insert<LLVM::LLVMDialect, NVVM::NVVMDialect>();
83 void runOnOperation()
override {
85 target.addLegalDialect<::mlir::LLVM::LLVMDialect>();
89 applyPartialConversion(getOperation(),
target, std::move(pattern))))
97 void loadDependentDialects(MLIRContext *context)
const final {
98 context->loadDialect<NVVMDialect>();
103 void populateConvertToLLVMConversionPatterns(
104 ConversionTarget &
target, LLVMTypeConverter &typeConverter,
105 RewritePatternSet &
patterns)
const final {
118 dialect->addInterfaces<NVVMToLLVMDialectInterface>();
static const mlir::GenInfo * generator
Base class for dialect interfaces providing translation to LLVM IR.
ConvertToLLVMPatternInterface(Dialect *dialect)
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
MLIRContext is the top-level object for a collection of MLIR operations.
Include the generated interface declarations.
void populateNVVMToLLVMConversionPatterns(RewritePatternSet &patterns)
const FrozenRewritePatternSet & patterns
void registerConvertNVVMToLLVMInterface(DialectRegistry ®istry)
OpInterfaceRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting a...