MARTINI: The Little Match and Replace Tool for Automatic Application Rewriting with Code Examples

  • Alister Johnson
  • , Camille Coti
  • , Allen D. Malony
  • , Johannes Doerfert

Research output: Contribution to Book/Report typesContribution to conference proceedingspeer-review

3 Citations (Scopus)

Abstract

Rewriting code for cleanliness, API changes, and new programming models is a common, yet time-consuming task. Localized or syntax-based changes are often mechanical and can be automated with text-based rewriting tools, like sed. However, non-localized or semantic-based changes require specialized tools that usually come with complex, hard-coded rules that require expertise in compilers. This means techniques for source rewriting are either too simple for complex tasks or too complex to be customized by non-expert users; in either case, developers are often forced to manually update their code instead. This work describes a new approach to code rewriting which exposes complex and semantic-driven rewrite capabilities to users in a simple and natural way. Rewrite rules are expressed as a pair of parameterized “before-and-after” source code snippets, one to describe what to match and one to describe what the replacement looks like. Through this novel and user-friendly interface, programmers can automate and customize complex code changes which require a deep understanding of the language without any knowledge of compiler internals. As our prototype, MARTINI, is built on top of Clang, we can (conceptually) handle all Clang’s input languages, including CUDA, SYCL, and many other C/C++-based interfaces, like Kokkos and OpenMP. To showcase usability, we implemented the clang-tidy rule “modernize-use-nullptr” and a simple instrumentation example. To further illustrate the potential of MARTINI, we reimplemented HIPIFY, which translates CUDA to HIP. Compared to hipify-perl and hipify-clang from HIPIFY, our version is easier to implement, more understandable, and customizable. The latter allows us to outperform HIPIFY-generated code by slightly modifying the translation rules of MARTINI-HIPIFY.

Original languageEnglish
Title of host publicationEuro-Par 2022
Subtitle of host publicationParallel Processing - 28th International Conference on Parallel and Distributed Computing, Proceedings
EditorsJosé Cano, Phil Trinder
PublisherSpringer Science and Business Media Deutschland GmbH
Pages19-34
Number of pages16
ISBN (Print)9783031125966
DOIs
Publication statusPublished - 2022
Externally publishedYes
Event28th International European Conference on Parallel and Distributed Computing, Euro-Par 2022 - Glasgow, United Kingdom
Duration: 22 Aug 202226 Aug 2022

Publication series

NameLecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics)
Volume13440 LNCS
ISSN (Print)0302-9743
ISSN (Electronic)1611-3349

Conference

Conference28th International European Conference on Parallel and Distributed Computing, Euro-Par 2022
Country/TerritoryUnited Kingdom
CityGlasgow
Period22/08/2226/08/22

!!!Keywords

  • AST matchers
  • metaprogramming
  • refactoring

Fingerprint

Dive into the research topics of 'MARTINI: The Little Match and Replace Tool for Automatic Application Rewriting with Code Examples'. These topics are generated from the title and abstract of the publication. Together, they form a unique fingerprint.

Cite this