当前位置:网站首页>LLVM TargetPassConfig
LLVM TargetPassConfig
2022-06-24 20:15:00 【Huo的藏经阁】
TargetPassConfig
TargetPassConfig类是LLVM 后端添加pass入口,LLVM 框架将整个后端依次划分为指令选择、指令调度,寄存器分配等几个阶段,,如下图:

其中每个阶段包含有一个或者多个pass,LLVM后端一个重要的处理就是兼容性和模块化,为了对这些后端所加的pass进行管理,LLVM后端对上述几个比较重要的阶段封装成接口,而每个接口基本代表一个 重要阶段,每个target可以根据需要添加所需要pass,
TargetPassConfig该类为codegen中各个阶段提供了各个接口,提供主要接口如下:
接口 | 说明 |
addISelPasses | 添加所有必须的从llvm IR转成生成MI的pass |
addIRPasses | 添加对llvm IR->IR的优化pass |
addPassesToHandleExceptions | 添加较低级别的各种异常pass,这些pass主要处理CodeGen中产生的各种异常 |
addCodeGenPrepare | 在LLVM IR这个级别中添加CodeGen前准备的pass,这些pass此时还只处理IR,因此需要在addPassesToHandleExceptions之前添加 |
addISelPrepare | 添加指令选择前的一些优化IR的pass,这个阶段也处于IR阶段,还未转换成DAG,主要优化IR |
addInstSelector | 添加指令选择器selector以及必要pass |
addIRTranslator | 添加IR转换成机器码相关pass,调用关系时addIRTranslatoràaddInstSelector |
addMachinePasses | 添加一套CodeGen标准所需要的pass |
addMachineSSAOptimization | SSA优化所需要添加pass |
addPreRegAlloc/addPostRegAlloc | 分别是寄存器分配前/后所需要添加pass |
addFastRegAlloc | 快速分配寄存器所需要添加pass |
addPassesToGenerateCode
addPassesToGenerateCode函数为添加CodeGen Pass总入口:
/// addPassesToX helper drives creation and initialization of TargetPassConfig.
static TargetPassConfig *
addPassesToGenerateCode(LLVMTargetMachine &TM, PassManagerBase &PM,
bool DisableVerify,
MachineModuleInfoWrapperPass &MMIWP) {
// Targets may override createPassConfig to provide a target-specific
// subclass.
TargetPassConfig *PassConfig = TM.createPassConfig(PM);
// Set PassConfig options provided by TargetMachine.
PassConfig->setDisableVerify(DisableVerify);
PM.add(PassConfig);
PM.add(&MMIWP);
if (PassConfig->addISelPasses())
return nullptr;
PassConfig->addMachinePasses();
PassConfig->setInitialized();
return PassConfig;
}
- createPassConfig :根据PM 创建对应target 的 TargetPassConfig ,每个target都会基于该类,对阶段中重要接口重新实现以实现添加独有pass,而不会影响其他target
- PassConfig->addISelPasses:添加指令选择阶段中所需要的pass 总入口
- PassConfig->addMachinePasses(): 指令由IR 转换成机器码之后,所添加的pass,包括寄存器分配,以及机器码级别优化pass等
AMDGPU TargetPassConfig
新写一个后端时,一个重要内容就是实现该target 所需要的添加pass, 以AMDGPU为例TargetPassConfig继承关系如下:

- AMDGPUPassConfig: 是所有AMDGPU后端所必须要添加的pass
- GCNPassConfig和 R600PassConfig分别针对的是GCN 和R600 平台。
边栏推荐
- 生成订单30分钟未支付,则自动取消,该怎么实现?
- JMeter socket connection sends data
- 移动安全工具-apktool
- Xcode preview displays a bug in the content of the list view and its solution
- Go crawler framework -colly actual combat (II) -- Douban top250 crawling
- 2021-11-05
- Technologie des fenêtres coulissantes en octets dans la couche de transmission
- Sliding window technology based on byte in transport layer
- Realization of MNIST handwritten numeral recognition
- 2022 simulated 100 questions of safety officer-c certificate examination and online simulated examination
猜你喜欢

2022熔化焊接与热切割复训题库模拟考试平台操作

Virtual machine - network configuration

百公里加速仅5.92秒,威兰达高性能版以高能产品实力领跑

JMeter socket connection sends data

Tiktok wallpaper applet, starlight wallpaper applet version 2.0, upgraded version

2019 summary and 2020 outlook

Add information on the left and add parts on the right of the status bar

图书馆管理系统代码源码(php+css+js+mysql) 完整的代码源码

2022年全国最新消防设施操作员(高级消防设施操作员)模拟题及答案

Applet opening traffic master
随机推荐
Helm chart warehouse operation
Source code analysis the problem that fragments cannot be displayed in the custom ViewGroup
The basic principle and application of iterator and enhanced for
Virtual machine - network configuration
Custom animation (simulated win10 loading animation)
我想问一下兴业证券怎么开户?通过链接办理股票开户安全吗
图书馆管理系统代码源码(php+css+js+mysql) 完整的代码源码
Realization of MNIST handwritten numeral recognition
2022熔化焊接与热切割复训题库模拟考试平台操作
移动安全工具-apktool
Applet opening traffic master
Leetcode 1248. 统计「优美子数组」(害,突然发现只会暴力枚举了)
Scala adapter pattern
ServerSocket and socket connection
Add information on the left and add parts on the right of the status bar
最新QQ微信域名防红PHP程序源码+强制跳转打开
Tiktok wallpaper applet source code
Eliminate duplicate dependencies
A website for programmers with a monthly salary of 30K
Scala classes inherit multiple attributes