Abstract
Traditional compiler architectures, such as GCC and Clang, rely on complex, multi-stage pipelines that have been the industry standard for decades. However, these systems are difficult to maintain and often suffer from information loss during the translation from high-level source code to low-level machine instructions. This paper explores a paradigm shift: LLM as a Compiler (LaaC). By treating compilation as a direct translation task, researchers evaluate whether Large Language Models (LLMs) can bypass intermediate representations to generate executable assembly. Using a new benchmark, CompilerEval, the study assesses the performance of state-of-the-art models across different hardware architectures. While results show that reasoning-enhanced models and simpler instruction sets (RISC-V) improve success rates, significant hurdles in logical reliability and instruction accuracy remain before LaaC can be considered for production environments.
Introduction
For over 70 years, compilers have served as the essential bridge between human-readable code and machine-executable instructions. Despite their maturity, traditional compilers are incredibly complex, requiring extensive manual effort to support new programming languages or hardware targets. Furthermore, the "lowering" process—converting source code into Intermediate Representation (IR) and then to assembly—often strips away high-level semantic intent, leading to modular redundancy.
The researchers propose the LaaC (LLM as a Compiler) paradigm to address these challenges. By utilizing the vast semantic knowledge of LLMs, the goal is to create a unified system architecture that is easier to maintain, preserves semantic information, and adapts rapidly to emerging hardware without the need for manual backend engineering.
Methodology
To evaluate the feasibility of LaaC, the authors developed a systematic framework consisting of three primary phases:
- Assembly Generation: High-level C kernels are fed into an LLM with specific prompts to generate corresponding assembly code.
- Wrapping and Compilation: The LLM-generated assembly is inserted into a predefined code template to create a complete source file.
- Verification: The framework attempts to assemble the code into an executable. It then runs a suite of tests to verify both syntactic correctness (successful build) and semantic correctness (producing the mathematically correct output).
The CompilerEval Benchmark
The study introduced CompilerEval, a specialized benchmark designed for this task. It contains 20 representative kernels covering domains such as linear algebra, image processing, and audio processing (e.g., matrix multiplication, 2D convolution, and ReLU activation). Each case includes a C kernel definition and a "main" program for automated verification. Traditional compilers (GCC and Clang) were used to generate ground-truth assembly for baseline comparisons.
Experimental Results and Insights
The researchers evaluated four major models: GPT-4o, Claude-3.5-Sonnet, Gemini-2.0-Flash-Exp, and Llama-3.1-405B. Several key factors influenced the success of the compilation task:
1. The Impact of Hardware Architecture
LLMs demonstrated a clear preference for RISC-V and ARM architectures over x86. The success rates were notably higher for Reduced Instruction Set Computer (RISC) architectures, likely because their simpler, more regular instruction sets are easier for models to predict and generate accurately compared to the complex, legacy-heavy x86 instruction set.
2. Reasoning vs. Translation
Compilation is more than a translation task; it is a logic-intensive process. The study found that GPT-o1, a model designed for chain-of-thought reasoning, outperformed GPT-4o by over 30% on complex tasks like image resizing. This suggests that the ability to "reason" through the logic of the code is a critical bottleneck for LLM-based compilers.
3. Model Scaling and Prompting
Scaling laws were evident in the results. While the Llama-8B model failed to generate a single executable sample, the 405B version showed significant improvement, indicating that "compilation sense" is an emergent property of larger models. Additionally, targeted prompt engineering—providing specific instructions to avoid common assembly pitfalls—improved average success rates by 2.32 percentage points.
4. Performance Metrics
Claude-3.5-Sonnet emerged as the top performer among standard models, achieving an average success rate of 35.02% on ARM and 27.85% on x86. While these results are promising for a nascent technology, they fall far short of the near-100% reliability required for production compilers.
Error Analysis and Limitations
The study identified several recurring failure modes in LLM-generated assembly:
- Instruction Errors: With 7,269 occurrences, this was the most common failure, where models hallucinated non-existent instructions or used them incorrectly.
- Symbol Redefinition: Models frequently lost track of variable naming conventions, leading to assembly-time errors.
- Computational Cost: Compiling via a massive LLM is orders of magnitude more expensive and slower than using a traditional compiler.
- Context Constraints: Large programs often exceed the context window limits of current LLMs, making them unsuitable for full-scale software projects.
Conclusion
The LaaC paradigm represents a provocative shift in systems programming. While current LLMs are not yet reliable enough to replace GCC or Clang—given that even the best models fail more than 60% of the time—the study highlights a path forward. Future work will likely focus on specialized fine-tuning for compilation, the integration of hardware manuals into "knowledge-rich" prompts, and the development of LLM-driven debuggers that can iteratively correct generated assembly. As reasoning capabilities and context windows expand, the dream of a unified, LLM-based compiler architecture may move closer to reality.
Summary updated