内联,重要性不必多说。
基本思路不是很难,
module层面构建call graph
根据call graph根据SCC(强连通分量
遍历SCC尝试内联(注意递归函数) 在同一个SCC里面就是一个递归链
决定内联时候:
clone被内联函数,用valuemap[old] = new记录映射情况。
被clone内容加入caller中
更新下ssa的def use chain。
主要是各种cost和gain的评估,各种启发式。
...
2026.04.28
1234567asm volatile ( "asm template" : output_operands // ← 第一个冒号后 : input_operands // ← 第二个冒号后 : clobbers // ← 第三个冒号后);
example:
1234567891011121314151617181920212223#include <stdint.
...
2026.04.28
步骤如下:
本地安装zola
运行zola init <your blog dir>, like zola init myblog
目录如下:
1234567myblog/├── config.toml # 配置文件├── content/ # 内容文件(Markdown)├── sass/ # Sass 样式文件(可选)├── static/ # 静态资源(图片
...
2026.04.28
这里首先需要区分下树和图的遍历,只考虑dfs方式
树以二叉树为例子:dfs有pre-order,in-order,post-order。
图
只考虑有向图,一个start节点
拓扑排序考虑到图可能存在环,问题会有些复杂。
先考虑拓扑排序,有两种情况
DAG情况(无环),不断删除入度为0的节点或者用 reverse post order方式。
12345678图1: Entry / \ A B \ / Exit
pre-
...
2026.04.28
体系结构
计算机体系结构量化研究方法
编译器相关比较推荐的书
高级编译器设计与实现 (鲸书)
ssa based compiler design
深入理解llvm代码生成 (彭成寒等著)
LLVM Code Generation A deep dive into compiler backend development (Quentin Colombet)
编译器设计 (Engineering a Compiler)
https://gcc.godbolt.org/ h
...
2026.04.22
0
构建llvm-tblgen, cmake configure后 cd build && ninja llvm-tblgen
查看tblgen对某个td文件的实际命令:在build.ninja里面搜索。比如说 X86GenAsmMatcher.inc是怎么编译出来的.
12345678910# Custom command for lib\Target\X86\X86GenAsmMatcher.incbuild lib/Target/X86/X86GenA
...
2026.04.22
线程组织 grid,block,thread。 一个kernel启动的所有线程称为grid。block是调度单元。<<<网格大小,线程块大小>>>
实际硬件:GPU,SM (stream multiprocessor),SP。 SM: local register file + shared memory+L1 cache+ a number of functional units that perform computations
...
2026.04.13
学习下mlir
1. 基本概念
树形结构。Op,Region,Block,Op
使用基本块参数代替phi
Operand结构
操作
返回值:OpResult
regions
attrDict,属性字典
参数:OpOperand, 经典的Use结构
Value是ValueImpl*的包装,type+kind
Type, TypeStorage* 实际上是AbstractType* = {dialect, interface, typeid,name, subt
...
2026.04.13
以mac air构建为例,耗时26min。
123456789101112cmake -G Ninja \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -S ./llvm -B build \ -DCMAKE_BUILD_TYPE=RELWITHDEBINFO \ -DLLVM_BUILD_EXAMPLES=ON \ -DLLVM_ENABLE_PROJECTS="mlir" \ -DLL
...
2026.04.13
参考 https://cs.wheaton.edu/~tvandrun/writings/cc04.pdf只考虑表达式,基于SSA
GVN是将Global value numbering,而PRE是Partial redundancy elimination。一个是值编号,一个是部分冗余消除。
GVN的思路简单,按照domtree进行深度优先遍历,记录每个block中表达式的编号,如果重复就删除重复的。对如下ir
12345678910111213141516define
...
2026.04.08