Finetuning Lightweight LLMs for Control Flow Graph Generation

2026-07-06Software Engineering

Software Engineering
AI summary

The authors explore using smaller, specialized language models to create control flow graphs (CFGs), which are maps showing how a program runs step-by-step. Traditional methods need perfect, error-free code and language-specific tools, limiting their use. The authors designed a new way to train these models using partly broken code and tested six different models. Their results show that these fine-tuned models can generate CFGs even when the code is incomplete or has mistakes, and they also work across different programming languages. This approach could make CFG creation more flexible and accessible.

Control Flow Graph (CFG)Large Language Models (LLMs)Fine-tuningCode AnalysisAbstract Syntax TreeBytecodeError AugmentationCross-language GeneralizationLightweight ModelsSoftware Maintenance
Authors
Hanyu Zhang, Tomoji Kishi
Abstract
Control Flow Graph (CFG) is an important program representations for software analysis, code understanding, and software maintenance. Traditional CFG generation techniques mainly rely on bytecode or abstract syntax trees. However, these approaches usually require complete, compilable, and syntax error-free code, which limits their applicability to incomplete or erroneous code. Furthermore, they often depend on language specific tools, making it difficult to support multiple programming languages in a unified manner. To address these limitations, this paper investigates the use of fine-tuned lightweight large language models (LLMs) for CFG generation. We first design a unified CFG output format and a task-specific fine-tuning prompt for CFG generation. Then, we construct a dataset based on an existing LeetCode dataset through automatic CFG generation and error augmentation. We evaluate the proposed approach on six lightweight LLM models, including three code-specific LLMs: CodeLlama, QwenCoder, and DeepSeekCoder; and three general purpose LLMs: Llama3.2-3B, Qwen-4B, and Phi-4B. The experimental results show that, through fine-tuning, lightweight LLMs achieve promising results for CFG generation, particularly when the input code is incomplete or erroneous. It also demonstrates cross-language generalization capability on programming language not included in the fine-tuning data.