Instruction Selection
:material-circle-edit-outline: 约 245 个字 :material-clock-time-two-outline: 预计阅读时间 1 分钟
Instruction selection: tiling the tree with a minimal set of tree patterns.
Tiling: cover the tree with nonoverlapping tree patterns
The Jouette architecture
Some instructions correspond to more than one tree pattern
It is always possible to tile the tree with tiny tiles, each covering only one node
Optimal and Optimum Tilings
- Best tiling: 理论最最优
- Optimum tiling:全局最优,cost 最小的覆盖
- Optimal tiling: 局部最优,选择任意两个瓦片进行合并,代价没有变得更低
Every optimum tiling is also optimal, but not vice versa
Algorithms for Instruction Selection
Maximal Munch
能找到局部最优,能保证任意两个瓦片都不能合并
认为越大的瓦片越好,采用贪心算法,自顶向下遍历 IR tree,用尽可能大的瓦片进行覆盖当前的结点,再递归检查剩下的
遇到多个选择时随便选一个即可
Dynamic Programming
能找到全局最优
我们对树中每个结点赋予一个 cost:
就是自底向上,每到一个结点,计算最小的 cost,一直到根节点