Compiler SSA Pattern Matching for Loop Instruction Selection

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing compilers face limitations in handling loops during the instruction selection process, as tree and DAG pattern matching techniques fail to consider the relationships between generic operations in loop iterations, leading to suboptimal machine instruction choices.

Innovation Solution

The method involves converting source code into single static assignment form, unlooping Φ nodes, performing tree pattern matching, re-looping, and then applying directed acyclic graph pattern matching to extend optimization techniques to loops, allowing for more effective instruction selection.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If tree pattern matching is used for instruction selection, then instruction selection can be performed on straight-line code, but it cannot handle loops and cannot consider relationships between generic operations in loop iterations

Engineering Contradiction:
Improveability to handle loopsVSAvoidcomplexity of pattern matching system
Core Design Contradiction:
Adaptability or versatilityVSDevice complexity

Solution Approach 1:

The patent segments the instruction selection process into multiple phases: first converting code to SSA form, then performing pattern matching on straight-line sections, and finally handling loops separately. This allows tree pattern matching to work on manageable straight-line code segments while loops are processed through specialized loop analysis, resolving the contradiction between handling loops and maintaining pattern matching simplicity.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent applies preliminary transformation of source code into single static assignment (SSA) form before pattern matching. This preliminary action prepares the code structure to make loop relationships explicit through phi nodes and versioned variables, enabling subsequent pattern matching to consider loop iteration relationships without complicating the core matching algorithm.

Inventive Principle:
Principle #10Preliminary action

2Productivity

If definition analysis is performed to determine redundant assignments, then optimization can be achieved, but the analysis is computationally expensive

Engineering Contradiction:
Improveoptimization effectivenessVSAvoidcompilation time
Core Design Contradiction:
ProductivityVSLoss of time

Solution Approach 1:

The patent performs the computationally expensive definition analysis as a preliminary action during the SSA form conversion phase. By completing this analysis early when the code structure is being transformed, the compiler can identify redundant assignments and optimize them without adding separate expensive analysis passes later, thus improving optimization effectiveness while controlling compilation time.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent merges the definition analysis with the SSA form conversion process. Instead of performing definition analysis as a separate independent phase, it is integrated into the transformation process itself, combining multiple operations into a single unified pass that achieves both code transformation and optimization identification simultaneously.

Inventive Principle:
Principle #5Merging (Combining)

3Ease of manufacture

If simple one-to-one replacement of generic operations with machine instructions is used, then code generation is simple, but it does not consider context and produces suboptimal instructions

Engineering Contradiction:
Improvesimplicity of code generationVSAvoidprocessor performance
Core Design Contradiction:
Ease of manufactureVSProductivity

Solution Approach 1:

The patent segments the code into straight-line sections and loop sections, applying different code generation strategies to each. Straight-line sections use pattern matching for optimized instruction selection, while loop sections use specialized loop analysis. This segmentation allows simple one-to-one replacement to work on straight-line code while adding optimization for loops, balancing simplicity and performance.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent applies different code generation qualities to different code regions. Straight-line code receives simple pattern-based replacement, while loop code receives enhanced treatment with loop-specific optimization. This local differentiation allows the compiler to maintain simplicity where appropriate while achieving optimization where needed, improving overall processor performance without unnecessarily complicating the entire code generation process.

Inventive Principle:
Principle #3Local quality

Data Source

PatentUS7694288B2Static single assignment form pattern matcher
Publication Date: 2010.04.06 ANALOG DEVICES INC
  • US7694288B2 patent drawing
  • US7694288B2 patent drawing
  • US7694288B2 patent drawing

AI summary

The invention provides a method of processing a sequence of operands to produce compiled code for a target data processor, the method comprising the steps of: automatically analysing a source code to produce a fist representation of that code in single static assignment form; transforming the first representation into a second representation by unlooping Φ nodes within the single static assignment form so as to create code suitable for tree pattern matching to be performed thereon; performing tree pattern matching on the second representation of the code; and re-looping the Φ nodes.