用脚本生成¶
Bash
# 进入RISCV.td所在目录,即/home/ken/workspace/OpenCL_Compiler/llvm/lib/Target/RISCV
# 再执行此脚本,会在当前目录下生成Records目录,里面有所生成的record文件。
set -x
export PATH=/home/ken/workspace/OpenCL_Compiler/build/bin:$PATH # 修改
export INCLUDE_PATH=/home/ken/workspace/OpenCL_Compiler/llvm/include # 修改
export ARCH_TD=RISCV.td # 修改
# 清理之前的记录
if [ -d "Records" ]; then
rm -rf Records
fi
mkdir Records
# 当前时间
current_time=$(date +'%Y%m%d_%H%M%S')
# 打印所有类和记录到标准输出
llvm-tblgen --print-records ${ARCH_TD} -I ${INCLUDE_PATH} > Records/printRecords_$current_time.td
# 导出 JSON 格式数据指令
llvm-tblgen --dump-json ${ARCH_TD} -I ${INCLUDE_PATH} > Records/DumpJson_$current_time.json
# 生成指令说明文档
llvm-tblgen --gen-instr-docs ${ARCH_TD} -I ${INCLUDE_PATH} > Records/InstrDocs_$current_time.rst
# 生成机器代码生成器
llvm-tblgen --gen-emitter ${ARCH_TD} -I ${INCLUDE_PATH} > Records/CodeEmitter_$current_time.inc
# 生成指令描述
llvm-tblgen --gen-instr-info ${ARCH_TD} -I ${INCLUDE_PATH} > Records/InstrInfo_$current_time.inc
# 打印扩展集以测试 DAG 表达式。(没有)
#llvm-tblgen --print-sets ${ARCH_TD} -I ${INCLUDE_PATH} > Records/printSets_$current_time.td
# 生成 DAG(有向无环图)指令选择器。可能还没写
llvm-tblgen --gen-dag-isel ${ARCH_TD} -I ${INCLUDE_PATH} > Records/DagIsel_$current_time.txt
Bash
$ ./TableGen.sh
+ export PATH=/home/ken/workspace/llvm-project/install/bin:/home/ken/software/dotnet:/home/ke
n/workspace/llvm-project/install/bin:/home/ken/workspace/SPIRV-LLVM-Translator/install/bin:/h
ome/ken/workspace/clinfo:/home/ken/software/dotnet:/home/ken/miniconda3/envs/Acuity/bin:/home
/ken/miniconda3/condabin:/home/ken/workspace/llvm-project/install/bin:/home/ken/workspace/SPI
RV-LLVM-Translator/install/bin:/home/ken/workspace/clinfo:/home/ken/.local/bin:/usr/local/sbi
n:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bi
n
+ export INCLUDE_PATH=/home/ken/workspace/llvm-project/llvm/include
+ export ARCH_TD=BPF.td
+ [ -d Records ]
+ rm -rf Records
+ mkdir Records
+ date +%Y%m%d_%H%M%S
+ current_time=20260302_165201
+ llvm-tblgen --print-records BPF.td -I /home/ken/workspace/llvm-project/llvm/include
+ llvm-tblgen --dump-json BPF.td -I /home/ken/workspace/llvm-project/llvm/include
+ llvm-tblgen --gen-instr-docs BPF.td -I /home/ken/workspace/llvm-project/llvm/include
+ llvm-tblgen --gen-emitter BPF.td -I /home/ken/workspace/llvm-project/llvm/include
+ llvm-tblgen --gen-instr-info BPF.td -I /home/ken/workspace/llvm-project/llvm/include
+ llvm-tblgen --print-sets BPF.td -I /home/ken/workspace/llvm-project/llvm/include
error: The class 'Set' is not defined
+ llvm-tblgen --gen-dag-isel BPF.td -I /home/ken/workspace/llvm-project/llvm/include