- Instruction selection
In computer programming, Instruction selection is a compiler optimization that transforms an
intermediate representation of a program into the final compiled code, either in binary or assembly format. It works by "covering" the intermediate representation with as few tiles as possible.A basic approach in instruction selection is to use some templates for translation of each instruction in an intermediate representation. But naïve use of templates leads to inefficient code in general. Additional attention needs to be paid to avoid duplicated memory access by reordering and merging instructions and promote the usage of registers.
For example, see the following sequence of intermediate instructions:
t1 = at2 = bt3 = t1 + t2a = t3b = t1A good tiling for the x86 architecture is a succinct set of instructions:
XCHG EAX, bXADD a, EAXTypically, instruction selection is implemented with a backwards
dynamic programming algorithm which computes the "optimal" tiling for each point starting from the end of the program and based from there. Instruction selection can also be implemented with agreedy algorithm that chooses a local optimum at each step.The code that performs instruction selection is usually automatically generated from a list of valid patterns. Various generator programs differ in the amount of analysis that they perform while they run, rather during the compiler's instruction selection phase. An example of generator program for instruction selection is
BURG .
Wikimedia Foundation. 2010.