Optimizing compilers are essential for the efficient and correct execution of software across various scientific fields. Domain-specific languages (DSL) typically use higher level intermediate representations (IR) in their compiler pipelines for domain-specific optimizations. As these IRs add to complexity, it is crucial to test them thoroughly. Random program generators have proven to be an effective tool to test compilers through differential and fuzz testing. However, developing specialized program generators for compiler IRs is not straightforward and demands considerable resources. We introduce MLIR-Forge, a novel random program generator framework that leverages the flexibility of MLIR, aiming to simplify the creation of specialized program generators. MLIR-Forge achieves this by splitting the generation process into fundamental building blocks that are language specific, and reusable program creation logic that constructs random programs from these building blocks. This hides complexity and furthermore, even the language specific components can be defined using a set of common tools. We demonstrate MLIR-Forge's capabilities by generating MLIR with built-in dialects, WebAssembly, and a data-centric program representation, DaCe -- requiring less than a week of development time in total for each of them. Using the generated programs we conduct differential testing and find 9 MLIR, 15 WebAssembly, and 774 DaCe groups of bugs with the corresponding program generators, after running them until the rate of new bugs stagnates.
翻译:优化编译器对于确保软件在各个科学领域中的高效与正确执行至关重要。领域特定语言(DSL)通常在其编译器流水线中使用更高层次的中间表示(IR)来实现领域特定的优化。随着这些IR的增加,复杂性也随之上升,因此对其进行全面测试显得尤为关键。随机程序生成器已被证明是通过差异测试和模糊测试来验证编译器的有效工具。然而,为编译器IR开发专门的程序生成器并非易事,且需要投入大量资源。本文介绍MLIR-Forge,一个新颖的随机程序生成器框架,它充分利用了MLIR的灵活性,旨在简化专门程序生成器的创建过程。MLIR-Forge通过将生成过程分解为语言特定的基础构建块,以及从这些构建块构造随机程序的可复用程序创建逻辑,来实现这一目标。这隐藏了复杂性,此外,即使是语言特定的组件也可以使用一组通用工具进行定义。我们通过生成内置方言的MLIR、WebAssembly以及以数据为中心的程序表示DaCe,展示了MLIR-Forge的能力——其中每一项的开发总时间均不足一周。利用生成的程序,我们进行了差异测试,并在运行至新错误发现率趋于停滞时,使用相应的程序生成器分别发现了9组MLIR错误、15组WebAssembly错误和774组DaCe错误。