AgRefactor Uses AI Agents to Turn Ordinary C++ Into FPGA-Ready HLS Code
By Breadboardhub Staff · Published 2026-08-12

Photo by Brecht Corbeel on Unsplash
If you have ever tried to push a real C or C++ algorithm through Xilinx Vitis HLS or Intel HLS Compiler, you know the pain. Pointer arithmetic that works fine on a CPU, dynamic memory allocation, unsupported standard library calls, and a dozen other constructs will stop synthesis cold. A team from UCLA has built AgRefactor, an open-source system that uses a crew of cooperating large language model agents to automatically rewrite software code into synthesizable High-Level Synthesis (HLS) code, and then tune it for performance. On most of their test cases, it outperforms or matches the best existing automated tools while delivering a 6.51x average speedup over the leading pragma tuning tool.
What Problem Does AgRefactor Actually Solve?
Getting software algorithms into FPGAs via HLS is rarely as simple as pressing compile. HLS tools impose strict constraints on the code they will accept, and bridging the gap between general-purpose software style and hardware-friendly code is a time-consuming manual process that requires deep expertise in both domains.
The researchers tested AgRefactor on benchmarks that are five to ten times longer than anything tackled by prior automated refactoring work. That scale matters because real engineering projects are not toy examples. When you are trying to accelerate a signal processing pipeline or a neural network kernel, the code you start with is complex, and existing tools either give up or produce results that compile but run slowly.
Beyond just making code synthesizable, AgRefactor also applies HLS pragmas, the directives that tell the synthesizer how to pipeline loops, partition arrays, and unroll computations. Getting those right is what separates a design that technically works from one that actually uses the FPGA's parallelism effectively.
How Does the Agent System Work?
AgRefactor is a multi-agent workflow, meaning several specialized AI agents collaborate rather than one model trying to do everything. The system combines LLM-driven code rewrites with conventional automated refactoring tools, letting each handle what it does best and keeping costs down.
The most interesting technical piece is the self-evolving memory system. As the agents work through refactoring tasks, they accumulate both factual knowledge (specific HLS rules and patterns) and strategic knowledge (approaches that worked or failed on previous programs). When a new piece of code arrives, the system retrieves relevant past experience to guide its decisions. This means AgRefactor gets better the more it is used, and it handles previously unseen programs more robustly than a stateless LLM call would.
The balance between LLM rewrites and tool-based transformations is deliberate. Pure LLM approaches tend to be expensive and can hallucinate incorrect transformations. Pure rule-based tools are cheap but rigid. By combining both under agent coordination, the system can handle the structured parts of refactoring efficiently while using the LLM's reasoning for the harder, context-dependent decisions.
What Does This Mean If You Are Building FPGA Accelerators?
The practical upside is significant. AgRefactor is fully automated and open-source, so you can feed it an existing algorithm and get back HLS-compatible code with pragmas already tuned, without manually hunting down every unsupported construct or hand-writing pipeline directives.
The reported 6.51x geometric mean speedup over the state-of-the-art pragma tuning tool, and a 1.20x speedup over optimized open-source reference designs, suggests the output is not just synthesizable but genuinely fast. The resource overhead for that performance gain stays under 20%, which is a reasonable trade-off for most acceleration use cases. For teams porting algorithms to Xilinx or Intel FPGAs where engineering time is the bottleneck, an automated first pass that produces near-optimized HLS could meaningfully shorten the design cycle.
What Are the Current Limitations?
The paper evaluates AgRefactor on 11 benchmarks, and it outperforms or matches the competition on 9 of them. That means there are cases where it falls short, and the authors do not claim it handles every possible software pattern. The system still relies on underlying LLM inference, which carries computational cost even if the hybrid tool approach reduces it compared to pure LLM baselines.
HLS itself also has target-specific quirks. What synthesizes cleanly for one vendor's toolchain may need adjustment for another. The benchmarks used are challenging by prior standards, but production codebases can be messier still, with legacy constructs, mixed C and C++ idioms, or heavy use of third-party libraries that no automated tool handles gracefully. The self-evolving memory is a promising direction for robustness, but it will need continued real-world exposure to cover the long tail of software patterns engineers actually use.
As LLM reasoning capabilities continue to improve and the memory system accumulates more hardware design knowledge, tools like AgRefactor could become a standard first step in any FPGA acceleration workflow.
Attribution
Adapted from “AgRefactor: Self-Evolving Agentic Workflow for HLS Compatibility and Performance” by Yang Zou, Zijian Ding, Yizhou Sun, Jason Cong, licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Source: https://arxiv.org/abs/2606.30949.
Original arXiv papers: