MLIR  19.0.0git
MemRefToEmitCPass.cpp
Go to the documentation of this file.
1 //===- MemRefToEmitC.cpp - MemRef to EmitC conversion ---------------------===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a pass to convert memref ops into emitc ops.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
18 #include "mlir/Pass/Pass.h"
20 
21 namespace mlir {
22 #define GEN_PASS_DEF_CONVERTMEMREFTOEMITC
23 #include "mlir/Conversion/Passes.h.inc"
24 } // namespace mlir
25 
26 using namespace mlir;
27 
28 namespace {
29 struct ConvertMemRefToEmitCPass
30  : public impl::ConvertMemRefToEmitCBase<ConvertMemRefToEmitCPass> {
31  void runOnOperation() override {
32  TypeConverter converter;
33 
34  // Fallback for other types.
35  converter.addConversion([](Type type) -> std::optional<Type> {
36  if (isa<MemRefType>(type))
37  return {};
38  return type;
39  });
40 
42 
43  RewritePatternSet patterns(&getContext());
44  populateMemRefToEmitCConversionPatterns(patterns, converter);
45 
46  ConversionTarget target(getContext());
47  target.addIllegalDialect<memref::MemRefDialect>();
48  target.addLegalDialect<emitc::EmitCDialect>();
49 
50  if (failed(applyPartialConversion(getOperation(), target,
51  std::move(patterns))))
52  return signalPassFailure();
53  }
54 };
55 } // namespace
static MLIRContext * getContext(OpFoldResult val)
This class describes a specific conversion target.
void addLegalDialect(StringRef name, Names... names)
Register the operations of the given dialects as legal.
void addIllegalDialect(StringRef name, Names... names)
Register the operations of the given dialects as illegal, i.e.
Type conversion class.
void addConversion(FnT &&callback)
Register a conversion function.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
Include the generated interface declarations.
void populateMemRefToEmitCConversionPatterns(RewritePatternSet &patterns, TypeConverter &converter)
void populateMemRefToEmitCTypeConversion(TypeConverter &typeConverter)
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72