Optimizing Machine Descriptions Specification

Motivation

Machine Description files (.md) in GCC have significant redundancy due to
  1. Repetition of almost similar RTL expressions across multiple define_insn and define_expand patterns.
  2. Repetition of c code along with RTL expression in these patterns.
There exists an opportunity to reuse several expressions instead of rewriting them in each pattern. This will facilitate writing of simpler and smaller Machine Description files.

Observations

The multiplicity of patterns with the same structure arises in MD file mainly because

Examples from MD files

Mode Iterators & Code Iterators

GCC provides some iterator facilities to define similar patterns for more than one machine mode or for more than one rtx code. These are Mode Iterators and Code Iterators which generate variations of patterns for different modes and codes respectively.

Shortcomings of Using Iterators

Proposed Solution

Three new constructs are to be introduced in MD files which will exploit the reuse opportunities explained earlier.
Construct Functionality Syntax
define_rtltemplate Introduces non-terminals for common RTL expressions instead of rewriting them in each define_insn/define_expand pattern. here
define_code Introduces non-terminals for c/asm code instead of rewriting them in each define_insn/define_expand pattern. here
define_patterns Allows to specify multiple define_insn and define_expand sharing rtl template and/or asm template or c code which is not possible with Iterators. here

Sample use of these constructs for Compare patterns from i386 is given here

Approaches for handling new Constructs

  1. Changes in GCC Source
  1. Developing an MD Parser. The parser will take as input the modified(optimized) version of MD files and will generate MD files currently used for building GCC. At the moment we favour this approach.

Positives