this feature comes from the need to switch between different instruction formats during various optimizations. One
approach could be to use switch cases which list all the instructions along with formats they can transition to. However,it has large maintenance overhead because of the hardcoded instruction names. Also, whenever a new instruction isadded in the .td files, all the relevant switch cases should be modified accordingly. Instead, the same functionalitycould be achieved with TableGen and some support from the .td files for a fraction of maintenance cost.
这个文档包括了加载指令映射支持为了一个目标的信息。这个动机来源于在各式各样的优化中不同指令格式之间转换的需要。
其中的一个方法是,switch case这个东西能够把所有的能转换的指令格式列出来。但是代价太大。
所以有一个叫TableGen的东西以及一些对于.td文件的支持可以降低损耗。
TableGen用关系模型去把不同的指令进行互相的映射,比如IR到机器码,到汇编码之类的。
这些模型用一个InstrMapping的类来描述。也就是说一个InstrMapping对象代表一个模型。
TableGen分析所有的关系模型并且用这些信息去建立关系表,这个关系表把不同的指令链接起来。这些表被发布在XXXInstrInfo.inc这么一个文件里,跟着一串的函数跟着它。
class InstrMapping
{
string FilterClass;//用来减少搜索空间,只针对那些用了关系模型的指令。
list<string> RowFields = [];//列出域或者说属性值,这些值应该一样对于所有的在关系表中的列。可以把这个看作是一系列被所有关系表连接在一起的指令共有的属性。
list<string> ColFields = [];//和上面一样不过是行。
list<string>KeyCol = [];//上面的一些值,不过这些值比较重要,和关键指令在一起,这些指令是需要用关系表进行转换的。
list<list<string>> ValueCols = [];//这就是上面那些关键指令被转换后的样子。
}