Abstract
Large Language Models (LLMs) have revolutionized code generation by treating programming languages as text. However, they often struggle with the underlying structural logic and semantic properties of programs. This paper introduces IRCoder, a hybrid framework that integrates Graph Neural Networks (GNNs) with LLMs. By encoding structured program information from LLVM Intermediate Representation (IR) into "soft prompts," IRCoder enhances the model's ability to reason about data flow and control paths. Our results demonstrate significant improvements across diverse tasks, including vulnerability detection, algorithm classification, and complex code translation.
Introduction
Modern code LLMs are primarily high-powered pattern matchers. While they excel at lexical and syntactic patterns, they frequently fail at deep analytical reasoning. A critical issue is the lack of semantic symmetry: minor textual changes that preserve logic (e.g., variable renaming) can lead to wildly different model outputs. In contrast, compiler-style representations like Control Flow Graphs remain stable under such transformations. To bridge this gap, we propose that models must move beyond raw text to embrace the structured, graph-like nature of software.
Methodology: The IRCoder Framework
IRCoder employs a two-pronged approach to inject structural awareness into LLMs:
1. IRGraph Representation
We developed IRGraph, an enhanced graph format based on LLVM IR. Unlike previous methods restricted to single functions, IRGraph represents entire compilation units. It utilizes six node types (e.g., Values, Instructions, Types) and eight edge types (e.g., Dataflow, Control Flow, Symbols) to capture nuanced program relationships.
2. GNN Soft Prompting
To avoid the complexity of linearizing graphs into text, we use a GNN to encode the IRGraph into continuous embeddings. These are prepended to the LLM’s input as "soft prompts." The training involves two stages:
- Pre-training: The GNN learns via masked node prediction on the massive ComPile dataset (~2 million C/C++ files).
- Alignment: The GNN is fine-tuned to map its structural insights into the latent space of a frozen LLM (DeepSeek-Coder-6.7b), using synthetic Q&A pairs generated by GPT-4o to bridge IR and natural language.
Experimental Results
IRCoder was evaluated against pure GNN models (e.g., ProGraML) and pure LLMs (e.g., DeepSeek-Coder-6.7b) across several benchmarks, including device mapping (DevMap), algorithm classification (POJ-104), and vulnerability detection (Juliet).
Code Translation Performance
On the ParEval benchmark, which requires translating code between parallel programming models, IRCoder showed substantial gains in "Pass@1" scores. The most significant improvement occurred in the transition from OpenMP to CUDA, where structural context proved vital for navigating complex parallel logic.
Structural Reasoning and Vulnerability Detection
IRCoder achieved higher pairwise accuracy in vulnerability detection compared to the base LLM. By leveraging the IRGraph, the model identifies bugs that may "look" like normal code textually but contain logical flaws visible in the data flow.
Analysis: The Importance of Graph Structure
Ablation studies were conducted to determine which components of the IRGraph contribute most to performance. Interestingly, Dataflow and Type edges were found to be the most critical for maintaining accuracy.
As shown in the ablation results, removing Dataflow edges leads to a significant drop in accuracy for device mapping tasks. Surprisingly, removing Control Flow edges resulted in only a minor (4%) decrease, suggesting that data dependencies often carry more weight than execution paths for specific optimization tasks.
Conclusion
IRCoder demonstrates that "text is not all you need" for sophisticated code intelligence. By using GNNs as "structural advisors" to frozen LLMs, we achieve superior performance with lower computational overhead than full fine-tuning. Future work will focus on expanding this approach to other languages beyond C/C++ and optimizing the number of graph tokens to fit within tighter context windows.
Summary updated