brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · af3b660 Raw
63 lines · cpp
1//===- TestMemRefToLLVMWithTransforms.cpp ---------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"10#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"11#include "mlir/Conversion/LLVMCommon/LoweringOptions.h"12#include "mlir/Conversion/LLVMCommon/TypeConverter.h"13#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"14#include "mlir/Dialect/Func/IR/FuncOps.h"15#include "mlir/Dialect/LLVMIR/LLVMDialect.h"16#include "mlir/Dialect/MemRef/Transforms/Transforms.h"17#include "mlir/IR/PatternMatch.h"18#include "mlir/Pass/Pass.h"19 20using namespace mlir;21 22namespace {23 24struct TestMemRefToLLVMWithTransforms25    : public PassWrapper<TestMemRefToLLVMWithTransforms,26                         OperationPass<ModuleOp>> {27  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMemRefToLLVMWithTransforms)28 29  void getDependentDialects(DialectRegistry &registry) const final {30    registry.insert<LLVM::LLVMDialect>();31  }32 33  StringRef getArgument() const final {34    return "test-memref-to-llvm-with-transforms";35  }36 37  StringRef getDescription() const final {38    return "Tests conversion of MemRef dialects + `func.func` to LLVM dialect "39           "with MemRef transforms.";40  }41 42  void runOnOperation() override {43    MLIRContext *ctx = &getContext();44    LowerToLLVMOptions options(ctx);45    LLVMTypeConverter typeConverter(ctx, options);46    RewritePatternSet patterns(ctx);47    memref::populateExpandStridedMetadataPatterns(patterns);48    populateFuncToLLVMConversionPatterns(typeConverter, patterns);49    LLVMConversionTarget target(getContext());50    if (failed(applyPartialConversion(getOperation(), target,51                                      std::move(patterns))))52      signalPassFailure();53  }54};55 56} // namespace57 58namespace mlir::test {59void registerTestMemRefToLLVMWithTransforms() {60  PassRegistration<TestMemRefToLLVMWithTransforms>();61}62} // namespace mlir::test63