some tricks
1.1 grep search
在当前目录下地柜查找
grep -riln xxx
insert键可以直接粘贴
1.2 cmake 使用
LLVM_TRAGE_TO_BUILD
cmake时,可以指定-DLLVM_TARGETS_TO_BUILD=”X86;Mips”只生成指定平台的后端
1.3 在线的API接口
LLVM classes
MDNode数据结构,可携带调试信息带入后端使用,与MetaData绑定在一起使用,如,可标记c的代码,与生成的汇编代码一一对应.
1.4 一本写后端的书
Tutorial: Creating an LLVM Backend for
the Cpu0 Architecture
1.5 google search
多使用谷歌搜索, llvm mips backend
1.6 vim插件
vim rc 可在github上搜索,下载
1.7 gdb clang
gdb时加上参数
touch foo.cpp
./clang foo.cpp -###
clang version 5.0.0 (tags/RELEASE_500/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/ghn/llvm/build/bin/.
"/home/ghn/llvm/build/bin/clang-5.0" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "foo.cpp" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/home/ghn/llvm/build/lib/clang/5.0.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/home/ghn/llvm/build/lib/clang/5.0.0/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/ghn/llvm/build/bin" "-ferror-limit" "19" "-fmessage-length" "151" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-o" "/tmp/foo-5641a4.o" "-x" "c++" "foo.cpp"
"/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "a.out" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o" "/usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o" "-L/usr/lib/gcc/x86_64-linux-gnu/4.8" "-L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu" "-L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib64" "-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu" "-L/usr/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu/../../lib64" "-L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.." "-L/home/ghn/llvm/build/bin/../lib" "-L/lib" "-L/usr/lib" "/tmp/foo-5641a4.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
XXX@ubuntuxxx:~/llvm/build/bin$ gdb --args "/home/ghn/llvm/build/bin/clang-5.0" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "foo.cpp" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/home/ghn/llvm/build/lib/clang/5.0.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/home/ghn/llvm/build/lib/clang/5.0.0/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/ghn/llvm/build/bin" "-ferror-limit" "19" "-fmessage-length" "151" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-o" "/tmp/foo-5641a4.o" "-x" "c++" "foo.cpp"
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/ghn/llvm/build/bin/clang-5.0...done.
(gdb)
删除Mips部分指令
需要对Mips架构,指令有所了解,不能随便删.可能会有未知的影响.
在include/llvm/IR/instrinsicsMips.td中,定义了前端与后端对应的指令名称,如:
// Multiplication
def int_mips_muleu_s_ph_qbl: GCCBuiltin<"__builtin_mips_muleu_s_ph_qbl">,
Intrinsic<[mips_v2q15_ty], [llvm_v4i8_ty, mips_v2q15_ty], []>;
// MIPS MSA
// This instruction is part of the MSA spec but it does not share the
// __builtin_msa prefix because it operates on GP registers.
def int_mips_fmin_w : GCCBuiltin<"__builtin_msa_fmin_w">,
Intrinsic<[llvm_v4f32_ty], [llvm_v4f32_ty, llvm_v4f32_ty], [IntrNoMem]>;
int_mips_fmin_w是后端定义的指令,builtin_msa_fmin_w是clang 使用的指令名称
找到需要删除的指令后,到llvm/lib/Target/Mips下grep相应的指令,找到相关的td和pass, 一个个点进去,注释,找到相应的子类, 以及继承的父类,然后注释.
前端暂时不需要动,如果需要生成新的target,那么则需要修改clang, 比如,
cd clang
grep -rin "mips64-linux-gnuabi64"
找到相对应的位置,可以直接将mips64替换为新的target.