[RFC] add a mlir refactor tool to clang-tools-extra

Abstract

This RFC introduces a tool for refactoring MLIR, based on clang, aimed at simplifying and accelerating the refactoring process within the MLIR codebase. By marking deprecated interfaces with [[deprecated]], the tool helps achieve clarity and maintainability in the MLIR codebase. Furthermore, it offers the capability to seamlessly refactor downstream projects to ensure they can easily adapt to changes in MLIR.

Background

Recently, the MLIR project has undergone a series of refactoring efforts involving extensive changes to files and interfaces. To streamline this process, we have developed a clang-based refactoring tool. The main goals of the tool are:

  1. Assisted Refactoring: The tool provides a set of custom rules for automatically performing common refactoring operations, easing the burden on developers.
  2. Support for Downstream Projects: We designed the tool’s interface to enable downstream projects to effortlessly apply the same refactoring standards, ensuring their code stays in sync with the latest MLIR version.

Detailed Description

Tool Features

Key features of the tool include:

  • Deprecation Interface Marking: Automatically recognizes and marks interfaces slated for deprecation with [[deprecated]], allowing developers to identify areas in need of updating.
  • Custom Rules Engine: Supports user-defined refactoring rules to accommodate the requirements of different projects.
  • Downstream Project Support: Provides API and documentation to allow downstream projects to integrate the tool and apply the latest MLIR refactoring.

Usage Example

Here are basic examples of using the tool:

llvm-project/build/bin/mlir-member-cast-rewriter --target-type=AffineExpr -p build llvm-project/mlir/lib/IR/AffineMap.cpp

Future Work

We plan to expand the tool’s capabilities in the future, including:

  • More Custom Rules: Continuously extend the rules engine to support additional common refactoring patterns.

Conclusion

The MLIR Refactoring Tool is designed to simplify refactoring within the MLIR codebase while also offering support for downstream projects. We encourage community members to try it out and provide feedback for ongoing improvements and expansions.

5 Likes

Hi, interesting work! Did you consider implement that tool as a clang-tify check?

“clang-tify” is a technology that I find unfamiliar. This tool has relatively simple functionality and is designed for straightforward refactoring of MLIR (Multi-Level Intermediate Representation). Therefore, I think placing it in the “clang-tools-extra” directory would be quite appropriate.

1 Like