Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial mlir-format PoC #121260

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mlir/test/mlir-format/annotate_locs.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: mlir-format %s --mlir-use-nameloc-as-prefix --insert-name-loc-only | FileCheck %s

// Append NameLocs (`loc("[ssa_name]")`) to operations and block arguments

// CHECK: func.func @add_one(%my_input: f64 loc("my_input"), %my_input2: f64 loc("my_input2")) -> f64 {
func.func @add_one(%my_input: f64, %my_input2: f64) -> f64 {
// CHECK: %my_constant = arith.constant 1.00000e+00 : f64 loc("my_constant")
%my_constant = arith.constant 1.00000e+00 : f64

%my_output = arith.addf %my_input, %my_constant : f64
// CHECK: %my_output = arith.addf %my_input, %my_constant : f64 loc("my_output")
return %my_output : f64
}
15 changes: 15 additions & 0 deletions mlir/test/mlir-format/simple.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: mlir-format %s --mlir-use-nameloc-as-prefix | FileCheck %s

// CHECK: func.func @add_one(%my_input: f64) -> f64 {
func.func @add_one(%my_input: f64) -> f64 {
// CHECK: %my_constant = arith.constant 1.00000e+00 : f64
%my_constant = arith.constant 1.00000e+00 : f64
// CHECK: // Dinnae drop this comment!
// Dinnae drop this comment!
%my_output = arith.addf
%my_input,
%my_constant : f64
// CHECK-STRICT: %my_output = arith.addf %my_input, %my_constant : f64
return %my_output : f64
// CHECK: return %my_output : f64
}
19 changes: 19 additions & 0 deletions mlir/test/mlir-format/simple2.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: mlir-format %s --mlir-use-nameloc-as-prefix | FileCheck %s

// CHECK: func.func @my_func(%x: f64, %y: f64) -> f64 {
func.func @my_func(%x: f64, %y: f64) -> f64 {
// CHECK: %cst1 = arith.constant 1.00000e+00 : f64
%cst1 = arith.constant 1.00000e+00 : f64
// CHECK: %cst2 = arith.constant 2.00000e+00 : f64
%cst2 = arith.constant 2.00000e+00 : f64
// CHECK-STRICT: %x1 = arith.addf %x, %cst1 : f64
%x1 = arith.addf
%x,
%cst1 : f64
// CHECK-STRICT: %y2 = arith.addf %y, %cst2 : f64
%y2 = arith.addf %y, %cst2 : f64
// CHECK: %z = arith.addf %x1, %y2 : f64
%z = arith.addf %x1, %y2 : f64
// return %z : f64
return %z : f64
}
21 changes: 21 additions & 0 deletions mlir/test/mlir-format/type_alias.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: mlir-format %s --mlir-use-nameloc-as-prefix | FileCheck %s

// CHECK: !funky64 = f64
!funky64 = f64
// CHECK: !fancy64 = f64
!fancy64 = f64

// CHECK: func.func @add_one(%b: f643) -> (f64, !funky64, !fancy64) {
func.func @add_one(%b: f64) -> (f64, !funky64, !fancy64) {
// CHECK: %c = arith.constant 1.00000e+00 : !funky64
%c = arith.constant 1.00000e+00 : !funky64
// CHECK: %x1 = arith.addf %b, %c : f64
%x1 = arith.addf %b,
%c : f64
// CHECK: %x2 = arith.addf %b, %b : !funky64
%x2 = arith.addf %b, %b : !funky64
// CHECK: %x3 = arith.addf %x2, %b : !fancy64
%x3 = arith.addf %x2, %b : !fancy64
// CHECK: return %x1, %x2, %x3 : f64, !funky64, !fancy64
return %x1, %x2, %x3 : f64, !funky64, !fancy64
}
1 change: 1 addition & 0 deletions mlir/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_subdirectory(mlir-pdll-lsp-server)
add_subdirectory(mlir-query)
add_subdirectory(mlir-reduce)
add_subdirectory(mlir-rewrite)
add_subdirectory(mlir-format)
add_subdirectory(mlir-shlib)
add_subdirectory(mlir-translate)
add_subdirectory(mlir-vulkan-runner)
Expand Down
32 changes: 32 additions & 0 deletions mlir/tools/mlir-format/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
set(LLVM_LINK_COMPONENTS
Support
)

set(LIBS
${dialect_libs}

MLIRAffineAnalysis
MLIRAnalysis
MLIRCastInterfaces
MLIRDialect
MLIRParser
MLIRPass
MLIRTransforms
MLIRTransformUtils
MLIRSupport
MLIRIR
)

include_directories(../../../clang/include)

add_mlir_tool(mlir-format
mlir-format.cpp

SUPPORT_PLUGINS
)
mlir_target_link_libraries(mlir-format PRIVATE ${LIBS})
llvm_update_compile_flags(mlir-format)

mlir_check_all_link_libraries(mlir-format)
export_executable_symbols_for_plugins(mlir-format)
Loading
Loading