Global Code Selection of Directed Acyclic Graphs

Andreas Fauth, Günter Hommel, Alois C. Knoll, Carsten Müller

Introduction

In the domain of Digital Signal Processors (DSPs), hardware architectures are often highly specialized to meet stringent performance and power requirements. A hallmark of these processors is their ability to perform "chaining"—executing multiple operations, such as a shift followed by an addition, within a single clock cycle. However, traditional compiler backends often struggle to exploit these capabilities. Most code selection algorithms operate on tree-based intermediate representations, where each operation produces a single result for a single consumer. Real-world DSP algorithms, conversely, are better represented as Directed Acyclic Graphs (DAGs), featuring common subexpressions and complex data dependencies. This paper presents a global code selection technique for the Custom Berlin Compiler (CBC) that addresses the "undagging" problem through heuristic node duplication.

Methodology and System Architecture

The proposed approach is integrated into the CBC framework, which automates much of the compiler generation process. The system relies on several core components to bridge the gap between high-level algorithms and specialized hardware.

Overview of the CBC compiler framework, illustrating the flow from machine description to code generation.
  1. Machine Description (nML): The target processor's architecture is defined using the nML language. An analyzer processes this description to generate a formal machine model, including available instructions and their costs.
  2. Pattern Matching with IBURG: The compiler uses an extended version of the Bottom-Up Rewrite System (IBURG) to find optimal matches between the operations in the control/data flowgraph and the instructions defined in the machine model.
  3. Heuristic Node Duplication: To handle DAGs, the compiler identifies "join" nodes where a value is used by multiple operations. Instead of always saving these values to registers (undagging), the compiler evaluates whether duplicating the operation allows it to be merged into multiple complex instructions.
  4. Cost-Based Decision Making: The selection process is guided by a cost function that weighs code size and estimated execution cycles, choosing the most efficient implementation for each specific context.

Key Insights: Exploiting Hardware Parallelism

The core challenge in DSP code selection is the "spill" penalty. In many architectures, moving a value from one functional unit to another requires a cycle to store it in a register file. Traditional tree-based selection often forces these spills at every join point in a DAG.

The mapping of DAG operations to a hardware datapath, showing how multiple operations can be 'chained' into a single cycle.

The researchers' key insight is that strategic redundancy can lead to higher performance. By duplicating a node in the graph, the compiler might perform the same calculation twice. While this seems inefficient, it can eliminate the need for register spills and allow the redundant operations to occupy "holes" in existing complex instructions, ultimately reducing the total number of machine cycles. Furthermore, by modeling control flow using "scopes," the compiler can apply these optimizations across branch boundaries, providing a more global optimization than local code generators.

Experimental Results

The system was evaluated using the ADPCM (Adaptive Differential Pulse Code Modulation) benchmark, a standard for speech compression. The "Node Duplication" strategy was compared against a baseline "Undagging" method across several critical components:

  • ENCODE: Node duplication achieved a 22.4% reduction in datapath operations, outperforming the 18.9% reduction from simple undagging.
  • IADQUANT: This component saw a 28.6% reduction with node duplication, compared to 23.8% for the baseline.
  • PREDICT: Performance improved by 21.5%.

In scenarios where duplication offered no benefit, such as TONE_DET, the cost-based heuristic correctly reverted to the standard undagging method, ensuring that the optimization never degraded performance.

Limitations and Future Work

While successful, the authors identify several areas for further research. A primary limitation is the separation of code selection and scheduling. Since the optimal instruction choice often depends on the final execution schedule, coupling these phases could yield even better results. Additionally, the current heuristic for node duplication—based on edge occurrences—could be replaced by a more formal optimal search, though this would increase compilation time. Future work will also focus on extending these DAG-based optimizations to more complex loop structures.

Summary updated

BibTeX
@inproceedings{fauth1994global,
  author = {Andreas Fauth and Günter Hommel and Alois C. Knoll and Carsten Müller},
  title = {{Global Code Selection of Directed Acyclic Graphs}},
  booktitle = {CC},
  year = {1994},
  doi = {10.1007/3-540-57877-3\_9},
}
Figure