目录
Introduction to Machine Descriptions
1.Influences on Machine Descriptions
(3)Relationship Between .md, .c, and.h Files
(5)Retargetability Mechanism of GCC
(2)Registering Spim with GCC Build Process
(3)Building a Cross-Compiler for Spim
(4) Level 0 of Spim Machine Descriptions
Introduction to Machine Descriptions
1.Influences on Machine Descriptions
2.Organization of GCC MD
GCC要知道目标处理器的指令、特征、目标汇编码的特征。以及目标平台需要执行的特定的优化,例如窥孔优化、指令调度。
- GCC MD的文件结构
- <target>.h: A set of C macros that describe
- 目标寄存器(子)集和特征
- 系统软件详细信息:汇编程序格式、可执行文件格式等。
- <target>.md: Target instructions described using MD constructs.
- <target>.c: Optional, but usually required.
- 实现特定目标代码的函数
3. Machine Descriptions的基本结构
RTL是一种目标特异性IR。
GIMPLE →non strict RTL →strict RTL→(操作符匹配+粗操作数匹配,改进操作数匹配)→Unique target ASM string.
考虑生成GIMPLE节点的RTL表达式,有两种构造: define insn和define expand。
(1)指定目标指令语义
(2)General Move Instruction
这个定义可以生成所有组合的数据移动模式,甚至是Mem→Mem都是偶可能的。我们还需要一种机制来生成更多受限的数据移动RTX实例.
(3)Relationship Between <target>.md, <target>.c, and<target>.h Files
寄存器类约束在<target>中使用。md文件
这里z是在REG_CLASS_FROM_LETTER_P中定义的约束字符。使用的是寄存器$ 0。
Register类定义在<target>.h文件中
寄存器类的检查在<target>.c文件中实现
(4)GCC中的翻译顺序
machine descriptions什么时候会用到?
在构建过程中当gcc编译程序时,会参考从机器描述中收集到的信息
(5)Retargetability Mechanism of GCC
GCC通过读取机器描述并生成自定义机器描述的后端来实现可重定向性
•机器描述受以下因素影响:
HLLs、GCC体系结构,以及目标、主机和构建系统的属性
•编写机器描述需要:指定C宏、目标指令和任何所需的支持功能
•define insn和define expand用于将GIMPLE表示转换为RTL
Spim移植示例
- spim is mips simulator developed by James Larus
- I RISC machine
- I Assembly level simulator: No need of assembler, linkers, or libraries
(1)Retargeting GCC to Spim
• Registering spim target with GCC build process
• Making machine description files available
• Building the compiler
(2)Registering Spim with GCC Build Process
Step 1
Step 2
(3)Building a Cross-Compiler for Spim
普通的交叉编译器构建过程尝试使用生成的cc1将模拟库(LIBGCC)编译为可执行文件,并使用汇编器、链接器和归档器。
(4) Level 0 of Spim Machine Descriptions