[PATCH] D96535: [flang][fir] Add fir-opt tool

Valentin Clement via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 11 12:01:45 PST 2021


clementval created this revision.
clementval added reviewers: schweitz, mehdi_amini.
Herald added subscribers: rriddle, mgorny.
Herald added a reviewer: sscalpone.
Herald added a reviewer: awarzynski.
clementval requested review of this revision.
Herald added subscribers: llvm-commits, stephenneuendorffer.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96535

Files:
  flang/test/CMakeLists.txt
  flang/tools/CMakeLists.txt
  flang/tools/fir-opt/CMakeLists.txt
  flang/tools/fir-opt/fir-opt.cpp


Index: flang/tools/fir-opt/fir-opt.cpp
===================================================================
--- /dev/null
+++ flang/tools/fir-opt/fir-opt.cpp
@@ -0,0 +1,26 @@
+//===- 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/Dialect/FIRDialect.h"
+
+using namespace mlir;
+
+int main(int argc, char **argv) {
+  fir::registerFIRPasses();
+  DialectRegistry registry;
+  registerAllDialects(registry);
+  registry.insert<fir::FIROpsDialect>();
+  return failed(MlirOptMain(argc, argv, "FIR modular optimizer driver\n",
+      registry, /*preloadDialectsInContext*/ false));
+}
\ No newline at end of file
Index: flang/tools/fir-opt/CMakeLists.txt
===================================================================
--- /dev/null
+++ flang/tools/fir-opt/CMakeLists.txt
@@ -0,0 +1,22 @@
+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}
+  MLIRIR
+  MLIRLLVMIR
+  MLIRPass
+  MLIRStandardToLLVM
+  MLIRTransforms
+  MLIRAffineToStandard
+  MLIRAnalysis
+  MLIRSCFToStandard
+  MLIREDSC
+  MLIRParser
+  MLIRStandardToLLVM
+  MLIRSupport
+  MLIRVectorToLLVM
+  MLIROptLib
+)
Index: flang/tools/CMakeLists.txt
===================================================================
--- flang/tools/CMakeLists.txt
+++ flang/tools/CMakeLists.txt
@@ -12,3 +12,4 @@
 endif()
 add_subdirectory(tco)
 add_subdirectory(f18-parse-demo)
+add_subdirectory(fir-opt)
Index: flang/test/CMakeLists.txt
===================================================================
--- flang/test/CMakeLists.txt
+++ flang/test/CMakeLists.txt
@@ -34,7 +34,7 @@
   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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96535.323111.patch
Type: text/x-patch
Size: 2508 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210211/563e704b/attachment.bin>


More information about the llvm-commits mailing list