Skip to content

Commit 9cbd0a1

Browse files
author
git apple-llvm automerger
committed
Merge commit '0009a1783490' from llvm.org/main into next
2 parents 0511ea0 + 0009a17 commit 9cbd0a1

File tree

32 files changed

+579
-21
lines changed

32 files changed

+579
-21
lines changed

mlir/include/mlir/Conversion/ArithToEmitC/ArithToEmitC.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
#define MLIR_CONVERSION_ARITHTOEMITC_ARITHTOEMITC_H
1111

1212
namespace mlir {
13+
class DialectRegistry;
1314
class RewritePatternSet;
1415
class TypeConverter;
1516

1617
void populateArithToEmitCPatterns(TypeConverter &typeConverter,
1718
RewritePatternSet &patterns);
19+
20+
void registerConvertArithToEmitCInterface(DialectRegistry &registry);
1821
} // namespace mlir
1922

2023
#endif // MLIR_CONVERSION_ARITHTOEMITC_ARITHTOEMITC_H
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===- ConvertToEmitCPass.h - Conversion to EmitC pass ----------*- C++ -*-===//
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+
#ifndef MLIR_CONVERSION_CONVERTTOEMITC_CONVERTTOEMITCPASS_H
10+
#define MLIR_CONVERSION_CONVERTTOEMITC_CONVERTTOEMITCPASS_H
11+
12+
#include "llvm/ADT/SmallVector.h"
13+
14+
#include <memory>
15+
16+
namespace mlir {
17+
class Pass;
18+
19+
#define GEN_PASS_DECL_CONVERTTOEMITC
20+
#include "mlir/Conversion/Passes.h.inc"
21+
22+
} // namespace mlir
23+
24+
#endif // MLIR_CONVERSION_CONVERTTOEMITC_CONVERTTOEMITCPASS_H
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===- ToEmitCInterface.h - Conversion to EmitC iface ---*- C++ -*-===========//
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+
#ifndef MLIR_CONVERSION_CONVERTTOEMITC_TOEMITCINTERFACE_H
10+
#define MLIR_CONVERSION_CONVERTTOEMITC_TOEMITCINTERFACE_H
11+
12+
#include "mlir/IR/DialectInterface.h"
13+
#include "mlir/IR/MLIRContext.h"
14+
#include "mlir/IR/OpDefinition.h"
15+
16+
namespace mlir {
17+
class ConversionTarget;
18+
class TypeConverter;
19+
class MLIRContext;
20+
class Operation;
21+
class RewritePatternSet;
22+
class AnalysisManager;
23+
24+
class ConvertToEmitCPatternInterface
25+
: public DialectInterface::Base<ConvertToEmitCPatternInterface> {
26+
public:
27+
ConvertToEmitCPatternInterface(Dialect *dialect) : Base(dialect) {}
28+
29+
/// Hook for derived dialect interface to provide conversion patterns
30+
/// and mark dialect legal for the conversion target.
31+
virtual void populateConvertToEmitCConversionPatterns(
32+
ConversionTarget &target, TypeConverter &typeConverter,
33+
RewritePatternSet &patterns) const = 0;
34+
};
35+
36+
/// Recursively walk the IR and collect all dialects implementing the interface,
37+
/// and populate the conversion patterns.
38+
void populateConversionTargetFromOperation(Operation *op,
39+
ConversionTarget &target,
40+
TypeConverter &typeConverter,
41+
RewritePatternSet &patterns);
42+
43+
} // namespace mlir
44+
45+
#endif // MLIR_CONVERSION_CONVERTTOEMITC_TOEMITCINTERFACE_H

mlir/include/mlir/Conversion/FuncToEmitC/FuncToEmitC.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
#define MLIR_CONVERSION_FUNCTOEMITC_FUNCTOEMITC_H
1111

1212
namespace mlir {
13+
class DialectRegistry;
1314
class RewritePatternSet;
15+
class TypeConverter;
1416

15-
void populateFuncToEmitCPatterns(RewritePatternSet &patterns);
17+
void populateFuncToEmitCPatterns(const TypeConverter &typeConverter,
18+
RewritePatternSet &patterns);
19+
20+
void registerConvertFuncToEmitCInterface(DialectRegistry &registry);
1621
} // namespace mlir
1722

1823
#endif // MLIR_CONVERSION_FUNCTOEMITC_FUNCTOEMITC_H

mlir/include/mlir/Conversion/MemRefToEmitC/MemRefToEmitC.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
#define MLIR_CONVERSION_MEMREFTOEMITC_MEMREFTOEMITC_H
1010

1111
namespace mlir {
12+
class DialectRegistry;
1213
class RewritePatternSet;
1314
class TypeConverter;
1415

1516
void populateMemRefToEmitCTypeConversion(TypeConverter &typeConverter);
1617

1718
void populateMemRefToEmitCConversionPatterns(RewritePatternSet &patterns,
1819
const TypeConverter &converter);
20+
21+
void registerConvertMemRefToEmitCInterface(DialectRegistry &registry);
1922
} // namespace mlir
2023

2124
#endif // MLIR_CONVERSION_MEMREFTOEMITC_MEMREFTOEMITC_H

mlir/include/mlir/Conversion/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "mlir/Conversion/ControlFlowToSCF/ControlFlowToSCF.h"
3030
#include "mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRV.h"
3131
#include "mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.h"
32+
#include "mlir/Conversion/ConvertToEmitC/ConvertToEmitCPass.h"
3233
#include "mlir/Conversion/ConvertToLLVM/ToLLVMPass.h"
3334
#include "mlir/Conversion/FuncToEmitC/FuncToEmitCPass.h"
3435
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"

mlir/include/mlir/Conversion/Passes.td

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@
1212
include "mlir/Pass/PassBase.td"
1313
include "mlir/Dialect/Vector/Transforms/VectorTransformsBase.td"
1414

15+
//===----------------------------------------------------------------------===//
16+
// ToEmitC
17+
//===----------------------------------------------------------------------===//
18+
19+
def ConvertToEmitC : Pass<"convert-to-emitc"> {
20+
let summary = "Convert to EmitC dialect via dialect interfaces";
21+
let description = [{
22+
This is a generic pass to convert to the EmitC dialect, it uses the
23+
`ConvertToEmitCPatternInterface` dialect interface to delegate to dialects
24+
the injection of conversion patterns.
25+
}];
26+
let options = [
27+
ListOption<"filterDialects", "filter-dialects", "std::string",
28+
"Test conversion patterns of only the specified dialects">,
29+
];
30+
}
31+
1532
//===----------------------------------------------------------------------===//
1633
// ToLLVM
1734
//===----------------------------------------------------------------------===//

mlir/include/mlir/Conversion/SCFToEmitC/SCFToEmitC.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <memory>
1414

1515
namespace mlir {
16+
class DialectRegistry;
1617
class Pass;
1718
class RewritePatternSet;
1819

@@ -22,6 +23,8 @@ class RewritePatternSet;
2223
/// Collect a set of patterns to convert SCF operations to the EmitC dialect.
2324
void populateSCFToEmitCConversionPatterns(RewritePatternSet &patterns,
2425
TypeConverter &typeConverter);
26+
27+
void registerConvertSCFToEmitCInterface(DialectRegistry &registry);
2528
} // namespace mlir
2629

2730
#endif // MLIR_CONVERSION_SCFTOEMITC_SCFTOEMITC_H

mlir/include/mlir/InitAllExtensions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@
1414
#ifndef MLIR_INITALLEXTENSIONS_H_
1515
#define MLIR_INITALLEXTENSIONS_H_
1616

17+
#include "mlir/Conversion/ArithToEmitC/ArithToEmitC.h"
1718
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
1819
#include "mlir/Conversion/ComplexToLLVM/ComplexToLLVM.h"
1920
#include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h"
21+
#include "mlir/Conversion/FuncToEmitC/FuncToEmitC.h"
2022
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
2123
#include "mlir/Conversion/GPUCommon/GPUToLLVM.h"
2224
#include "mlir/Conversion/GPUToNVVM/GPUToNVVM.h"
2325
#include "mlir/Conversion/IndexToLLVM/IndexToLLVM.h"
2426
#include "mlir/Conversion/MPIToLLVM/MPIToLLVM.h"
2527
#include "mlir/Conversion/MathToLLVM/MathToLLVM.h"
28+
#include "mlir/Conversion/MemRefToEmitC/MemRefToEmitC.h"
2629
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
2730
#include "mlir/Conversion/NVVMToLLVM/NVVMToLLVM.h"
2831
#include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h"
32+
#include "mlir/Conversion/SCFToEmitC/SCFToEmitC.h"
2933
#include "mlir/Conversion/UBToLLVM/UBToLLVM.h"
3034
#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h"
3135
#include "mlir/Dialect/AMX/Transforms.h"
@@ -63,18 +67,22 @@ namespace mlir {
6367
/// pipelines and transformations you are using.
6468
inline void registerAllExtensions(DialectRegistry &registry) {
6569
// Register all conversions to LLVM extensions.
70+
registerConvertArithToEmitCInterface(registry);
6671
arith::registerConvertArithToLLVMInterface(registry);
6772
registerConvertComplexToLLVMInterface(registry);
6873
cf::registerConvertControlFlowToLLVMInterface(registry);
6974
func::registerAllExtensions(registry);
7075
tensor::registerAllExtensions(registry);
76+
registerConvertFuncToEmitCInterface(registry);
7177
registerConvertFuncToLLVMInterface(registry);
7278
index::registerConvertIndexToLLVMInterface(registry);
7379
registerConvertMathToLLVMInterface(registry);
7480
mpi::registerConvertMPIToLLVMInterface(registry);
81+
registerConvertMemRefToEmitCInterface(registry);
7582
registerConvertMemRefToLLVMInterface(registry);
7683
registerConvertNVVMToLLVMInterface(registry);
7784
registerConvertOpenMPToLLVMInterface(registry);
85+
registerConvertSCFToEmitCInterface(registry);
7886
ub::registerConvertUBToLLVMInterface(registry);
7987
registerConvertAMXToLLVMInterface(registry);
8088
gpu::registerConvertGpuToLLVMInterface(registry);

mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "mlir/Conversion/ArithToEmitC/ArithToEmitC.h"
1515

16+
#include "mlir/Conversion/ConvertToEmitC/ToEmitCInterface.h"
1617
#include "mlir/Dialect/Arith/IR/Arith.h"
1718
#include "mlir/Dialect/EmitC/IR/EmitC.h"
1819
#include "mlir/Dialect/EmitC/Transforms/TypeConversions.h"
@@ -22,6 +23,27 @@
2223

2324
using namespace mlir;
2425

26+
namespace {
27+
/// Implement the interface to convert Arith to EmitC.
28+
struct ArithToEmitCDialectInterface : public ConvertToEmitCPatternInterface {
29+
using ConvertToEmitCPatternInterface::ConvertToEmitCPatternInterface;
30+
31+
/// Hook for derived dialect interface to provide conversion patterns
32+
/// and mark dialect legal for the conversion target.
33+
void populateConvertToEmitCConversionPatterns(
34+
ConversionTarget &target, TypeConverter &typeConverter,
35+
RewritePatternSet &patterns) const final {
36+
populateArithToEmitCPatterns(typeConverter, patterns);
37+
}
38+
};
39+
} // namespace
40+
41+
void mlir::registerConvertArithToEmitCInterface(DialectRegistry &registry) {
42+
registry.addExtension(+[](MLIRContext *ctx, arith::ArithDialect *dialect) {
43+
dialect->addInterfaces<ArithToEmitCDialectInterface>();
44+
});
45+
}
46+
2547
//===----------------------------------------------------------------------===//
2648
// Conversion Patterns
2749
//===----------------------------------------------------------------------===//

mlir/lib/Conversion/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ add_subdirectory(ComplexToStandard)
1919
add_subdirectory(ControlFlowToLLVM)
2020
add_subdirectory(ControlFlowToSCF)
2121
add_subdirectory(ControlFlowToSPIRV)
22+
add_subdirectory(ConvertToEmitC)
2223
add_subdirectory(ConvertToLLVM)
2324
add_subdirectory(FuncToEmitC)
2425
add_subdirectory(FuncToLLVM)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
add_mlir_conversion_library(MLIRConvertToEmitC
2+
ConvertToEmitCPass.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/ConvertToEmitC
6+
7+
DEPENDS
8+
MLIRConversionPassIncGen
9+
10+
LINK_LIBS PUBLIC
11+
MLIRArithToEmitC
12+
MLIRFuncToEmitC
13+
MLIRMemRefToEmitC
14+
MLIRPass
15+
MLIRSCFToEmitC
16+
MLIRTransformUtils
17+
)

0 commit comments

Comments
 (0)