Traditional compilers, designed for optimizing low-level code, fall short when dealing with modern, computation-heavy applications like image processing, machine learning, or numerical simulations. Optimizations should understand the primitive operations of the specific application domain and thus happen on that level. Domain-specific languages (DSLs) fulfill these requirements. However, DSL compilers reinvent the wheel over and over again as standard optimizations, code generators, and general infrastructure & boilerplate code must be reimplemented for each DSL compiler. This paper presents MimIR, an extensible, higher-order intermediate representation. At its core, MimIR is a pure type system and, hence, a form of a typed lambda calculus. Developers can declare the signatures of new (domain-specific) operations, called "axioms". An axiom can be the declaration of a function, a type operator, or any other entity with a possibly polymorphic, polytypic, and/or dependent type. This way, developers can extend MimIR at any low or high level and bundle them in a plugin. Plugins extend the compiler and take care of optimizing and lowering the plugins' axioms. We show the expressiveness and effectiveness of MimIR in three case studies: Low-level plugins that operate at the same level of abstraction as LLVM, a regular-expression matching plugin, and plugins for linear algebra and automatic differentiation. We show that in all three studies, MimIR produces code that has state-of-the-art performance.
翻译:传统编译器专为优化低级代码而设计,在处理图像处理、机器学习或数值模拟等计算密集型现代应用时存在不足。优化应理解特定应用领域的原始操作,并基于该层级进行。领域特定语言(DSL)满足了这些需求。然而,DSL编译器需要反复重新实现标准优化、代码生成器以及通用基础设施与样板代码,导致大量重复工作。本文提出MimIR,一种可扩展的高阶中间表示。其核心是一个纯类型系统,因此属于类型化λ演算的一种形式。开发者可以声明称为“公理”的新(领域特定)操作签名。公理可以是函数声明、类型运算符声明,或任何可能具有多态、多型及/或依赖类型的实体。通过这种方式,开发者可以在任意低级或高级层次扩展MimIR,并将其封装为插件。插件通过扩展编译器来处理其公理的优化与降级转换。我们通过三个案例研究展示MimIR的表达能力与有效性:与LLVM处于相同抽象层级的低级插件、正则表达式匹配插件,以及线性代数与自动微分插件。研究表明,在所有案例中MimIR生成的代码均达到业界领先性能水平。