Skip to content

Commit 8260232

Browse files
committed
[flang][fir] Add fir-opt tool
This patch introduce the fir-opt tool. Similar to mlir-opt for FIR. It will be used in following patches to test fir opt and round-trip. Reviewed By: schweitz, mehdi_amini Differential Revision: https://reviews.llvm.org/D96535
1 parent 1e007cf commit 8260232

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

flang/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ set(FLANG_TEST_PARAMS
3434
flang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py)
3535

3636
set(FLANG_TEST_DEPENDS
37-
f18 FileCheck count not module_files
37+
f18 FileCheck count not module_files fir-opt
3838
)
3939

4040
list(APPEND FLANG_TEST_DEPENDS tco)

flang/test/Fir/fir-ops.fir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test the FIR operations
2-
3-
// RUN: tco -emit-fir %s | tco -emit-fir | FileCheck %s
2+
// Parse operations and check that we can reparse what we print.
3+
// RUN: fir-opt %s | fir-opt | FileCheck %s
44

55
// CHECK-LABEL: func private @it1() -> !fir.int<4>
66
// CHECK: func private @box1() -> !fir.boxchar<2>

flang/test/Fir/fir-types.fir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test the FIR types
2-
3-
// RUN: tco -emit-fir %s | tco -emit-fir | FileCheck %s
2+
// Parse types and check that we can reparse what we print.
3+
// RUN: fir-opt %s | fir-opt | FileCheck %s
44

55
// Fortran Intrinsic types
66
// CHECK-LABEL: func private @it1() -> !fir.int<4>

flang/tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ if(FLANG_BUILD_NEW_DRIVER)
1212
endif()
1313
add_subdirectory(tco)
1414
add_subdirectory(f18-parse-demo)
15+
add_subdirectory(fir-opt)

flang/tools/fir-opt/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
add_flang_tool(fir-opt fir-opt.cpp)
2+
llvm_update_compile_flags(fir-opt)
3+
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
4+
5+
target_link_libraries(fir-opt PRIVATE
6+
FIROptimizer
7+
${dialect_libs}
8+
9+
# TODO: these should be transitive dependencies from a target providing
10+
# "registerFIRPasses()"
11+
MLIRAffineToStandard
12+
MLIROptLib
13+
)

flang/tools/fir-opt/fir-opt.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===- fir-opt.cpp - FIR Optimizer Driver -----------------------*- 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+
// This is to be like LLVM's opt program, only for FIR. Such a program is
10+
// required for roundtrip testing, etc.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "mlir/Support/MlirOptMain.h"
15+
#include "flang/Optimizer/Support/InitFIR.h"
16+
17+
using namespace mlir;
18+
19+
int main(int argc, char **argv) {
20+
fir::support::registerFIRPasses();
21+
DialectRegistry registry;
22+
fir::support::registerDialects(registry);
23+
return failed(MlirOptMain(argc, argv, "FIR modular optimizer driver\n",
24+
registry, /*preloadDialectsInContext*/ false));
25+
}

0 commit comments

Comments
 (0)