Skip to content

Metrics and Objective Functions

Andrew Johnson edited this page May 24, 2024 · 8 revisions

When appropriate, the compiler may choose from among equivalent candidate functions and data to minimize a final objective metric.

What is a Metric?

Metrics are integer tuples. Zero is the perfect score.

0 < 1 < (1 1) < (1 (0 2))

One Expression, Multiple Metrics

A single expression may yield multiple metrics such as memory pressure or cpu pressure.

cpu( e ) = (2 34 (5 67))
memory( e ) = (8 (9 1011))

Objectives are Goals to be Minimized

Objective functions are optimization goals that can be tweaked and weighted.

Goal: min( 0.8 * cpu(program) + 0.2 * memory(program) )

Selecting a Representation from a Class

Sometimes selecting a candidate representation is straightforward. Sometimes it can be not so simple. Constraint Solvers may be involved in the future.

mov := λ(: src Imm64)(: tgt Register64). asm!( 'mov \s src , \s tgt \n );

mov := λ(: src Imm64/0)(: tgt Register64). asm!( 'xor \s tgt , \s tgt \n );

In this code two forms of mov are declared. Types define equivalence. Metrics define preference.