Skip to content

Commit 3eebcfd

Browse files
committed
Add initial mlir-format PoC
1 parent 5d81b14 commit 3eebcfd

File tree

6 files changed

+465
-0
lines changed

6 files changed

+465
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: mlir-format %s --mlir-use-nameloc-as-prefix --insert-name-loc-only | FileCheck %s
2+
3+
// Append NameLocs (`loc("[ssa_name]")`) to operations and block arguments
4+
5+
// CHECK: func.func @add_one(%my_input: f64 loc("my_input"), %my_input2: f64 loc("my_input2")) -> f64 {
6+
func.func @add_one(%my_input: f64, %my_input2: f64) -> f64 {
7+
// CHECK: %my_constant = arith.constant 1.00000e+00 : f64 loc("my_constant")
8+
%my_constant = arith.constant 1.00000e+00 : f64
9+
10+
%my_output = arith.addf %my_input, %my_constant : f64
11+
// CHECK: %my_output = arith.addf %my_input, %my_constant : f64 loc("my_output")
12+
return %my_output : f64
13+
}

mlir/test/mlir-format/simple.mlir

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: mlir-format %s --mlir-use-nameloc-as-prefix | FileCheck %s
2+
3+
// CHECK: func.func @add_one(%my_input: f64) -> f64 {
4+
func.func @add_one(%my_input: f64) -> f64 {
5+
// CHECK: %my_constant = arith.constant 1.00000e+00 : f64
6+
%my_constant = arith.constant 1.00000e+00 : f64
7+
// CHECK: // Dinnae drop this comment!
8+
// Dinnae drop this comment!
9+
%my_output = arith.addf
10+
%my_input,
11+
%my_constant : f64
12+
// CHECK-STRICT: %my_output = arith.addf %my_input, %my_constant : f64
13+
return %my_output : f64
14+
// CHECK: return %my_output : f64
15+
}

mlir/test/mlir-format/simple2.mlir

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: mlir-format %s --mlir-use-nameloc-as-prefix | FileCheck %s
2+
3+
// CHECK: func.func @my_func(%x: f64, %y: f64) -> f64 {
4+
func.func @my_func(%x: f64, %y: f64) -> f64 {
5+
// CHECK: %cst1 = arith.constant 1.00000e+00 : f64
6+
%cst1 = arith.constant 1.00000e+00 : f64
7+
// CHECK: %cst2 = arith.constant 2.00000e+00 : f64
8+
%cst2 = arith.constant 2.00000e+00 : f64
9+
// CHECK-STRICT: %x1 = arith.addf %x, %cst1 : f64
10+
%x1 = arith.addf
11+
%x,
12+
%cst1 : f64
13+
// CHECK-STRICT: %y2 = arith.addf %y, %cst2 : f64
14+
%y2 = arith.addf %y, %cst2 : f64
15+
// CHECK: %z = arith.addf %x1, %y2 : f64
16+
%z = arith.addf %x1, %y2 : f64
17+
// return %z : f64
18+
return %z : f64
19+
}

mlir/tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_subdirectory(mlir-pdll-lsp-server)
55
add_subdirectory(mlir-query)
66
add_subdirectory(mlir-reduce)
77
add_subdirectory(mlir-rewrite)
8+
add_subdirectory(mlir-format)
89
add_subdirectory(mlir-shlib)
910
add_subdirectory(mlir-translate)
1011
add_subdirectory(mlir-vulkan-runner)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
2+
set(LLVM_LINK_COMPONENTS
3+
Support
4+
)
5+
6+
set(LIBS
7+
${dialect_libs}
8+
9+
MLIRAffineAnalysis
10+
MLIRAnalysis
11+
MLIRCastInterfaces
12+
MLIRDialect
13+
MLIRParser
14+
MLIRPass
15+
MLIRTransforms
16+
MLIRTransformUtils
17+
MLIRSupport
18+
MLIRIR
19+
)
20+
21+
include_directories(../../../clang/include)
22+
23+
add_mlir_tool(mlir-format
24+
mlir-format.cpp
25+
26+
SUPPORT_PLUGINS
27+
)
28+
mlir_target_link_libraries(mlir-format PRIVATE ${LIBS})
29+
llvm_update_compile_flags(mlir-format)
30+
31+
mlir_check_all_link_libraries(mlir-format)
32+
export_executable_symbols_for_plugins(mlir-format)

0 commit comments

Comments
 (0)