From 8260232cdd138d1357d308e43c33f0f16044f44c Mon Sep 17 00:00:00 2001 From: clementval Date: Tue, 16 Feb 2021 11:48:20 -0500 Subject: [PATCH] [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 --- flang/test/CMakeLists.txt | 2 +- flang/test/Fir/fir-ops.fir | 4 ++-- flang/test/Fir/fir-types.fir | 4 ++-- flang/tools/CMakeLists.txt | 1 + flang/tools/fir-opt/CMakeLists.txt | 13 +++++++++++++ flang/tools/fir-opt/fir-opt.cpp | 25 +++++++++++++++++++++++++ 6 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 flang/tools/fir-opt/CMakeLists.txt create mode 100644 flang/tools/fir-opt/fir-opt.cpp diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt index abda950..7328afc 100644 --- a/flang/test/CMakeLists.txt +++ b/flang/test/CMakeLists.txt @@ -34,7 +34,7 @@ set(FLANG_TEST_PARAMS flang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py) set(FLANG_TEST_DEPENDS - f18 FileCheck count not module_files + f18 FileCheck count not module_files fir-opt ) list(APPEND FLANG_TEST_DEPENDS tco) diff --git a/flang/test/Fir/fir-ops.fir b/flang/test/Fir/fir-ops.fir index 4a1f21a..58b679c 100644 --- a/flang/test/Fir/fir-ops.fir +++ b/flang/test/Fir/fir-ops.fir @@ -1,6 +1,6 @@ // Test the FIR operations - -// RUN: tco -emit-fir %s | tco -emit-fir | FileCheck %s +// Parse operations and check that we can reparse what we print. +// RUN: fir-opt %s | fir-opt | FileCheck %s // CHECK-LABEL: func private @it1() -> !fir.int<4> // CHECK: func private @box1() -> !fir.boxchar<2> diff --git a/flang/test/Fir/fir-types.fir b/flang/test/Fir/fir-types.fir index 2a46301..d9f46e9 100644 --- a/flang/test/Fir/fir-types.fir +++ b/flang/test/Fir/fir-types.fir @@ -1,6 +1,6 @@ // Test the FIR types - -// RUN: tco -emit-fir %s | tco -emit-fir | FileCheck %s +// Parse types and check that we can reparse what we print. +// RUN: fir-opt %s | fir-opt | FileCheck %s // Fortran Intrinsic types // CHECK-LABEL: func private @it1() -> !fir.int<4> diff --git a/flang/tools/CMakeLists.txt b/flang/tools/CMakeLists.txt index ecce727..98b20a1 100644 --- a/flang/tools/CMakeLists.txt +++ b/flang/tools/CMakeLists.txt @@ -12,3 +12,4 @@ if(FLANG_BUILD_NEW_DRIVER) endif() add_subdirectory(tco) add_subdirectory(f18-parse-demo) +add_subdirectory(fir-opt) diff --git a/flang/tools/fir-opt/CMakeLists.txt b/flang/tools/fir-opt/CMakeLists.txt new file mode 100644 index 0000000..efd33f9 --- /dev/null +++ b/flang/tools/fir-opt/CMakeLists.txt @@ -0,0 +1,13 @@ +add_flang_tool(fir-opt fir-opt.cpp) +llvm_update_compile_flags(fir-opt) +get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) + +target_link_libraries(fir-opt PRIVATE + FIROptimizer + ${dialect_libs} + + # TODO: these should be transitive dependencies from a target providing + # "registerFIRPasses()" + MLIRAffineToStandard + MLIROptLib +) diff --git a/flang/tools/fir-opt/fir-opt.cpp b/flang/tools/fir-opt/fir-opt.cpp new file mode 100644 index 0000000..b2d383c --- /dev/null +++ b/flang/tools/fir-opt/fir-opt.cpp @@ -0,0 +1,25 @@ +//===- fir-opt.cpp - FIR Optimizer Driver -----------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This is to be like LLVM's opt program, only for FIR. Such a program is +// required for roundtrip testing, etc. +// +//===----------------------------------------------------------------------===// + +#include "mlir/Support/MlirOptMain.h" +#include "flang/Optimizer/Support/InitFIR.h" + +using namespace mlir; + +int main(int argc, char **argv) { + fir::support::registerFIRPasses(); + DialectRegistry registry; + fir::support::registerDialects(registry); + return failed(MlirOptMain(argc, argv, "FIR modular optimizer driver\n", + registry, /*preloadDialectsInContext*/ false)); +} -- 2.7.4