llvm

LLVM 中间代码归纳

醉酒当歌 提交于 2020-01-29 04:07:09
Identifiers 标识符 @ 全局 % 局部 后接字符串 命名量 @name %name 无符号数字 未命名量 @42 %42 类型系统 void 空类型 <type> * 指针类型 <returntype> (<parameter list>) 函数类型 < <# elements> x <elementtype> > 向量类型 [<# elements> x <elementtype>] 数组类型 { <type list> } 普通结构体类型 <{ <type list> }> 打包结构体类型 metadata 元数据类型 label 标签类型 token 词元类型 类型系统(例子) void 空 i32 * 指针 i32 (i32) 函数 <5 x i32> 向量 [5 x i32] 数组 { i32, i32, i32 } 普通结构体 <{ i32, i32, i32 }> 打包结构体 元数据 ; 未命名元数据节点 ; 用于被命名元数据引用 !0 = !{!"zero"} !1 = !{!"one"} !2 = !{!"two"} ; 命名元数据 !name = !{!0, !1, !2} !name --- !0 |-- !1 |-- !2 模块层次内联汇编 module asm "内联汇编代码" Target Triple target triple =

如何给llvm添加一个pass

安稳与你 提交于 2020-01-29 00:32:03
记录,没什么实际内容,参照 PLCT talk 和 2019 LLVM Developers’ Meeting: A. Warzynski “Writing an LLVM Pass: 101” * 注:部分内容摘自PLCT开放日 talk 和 2019 LLVM Developers’ Meeting: A. Warzynski “Writing an LLVM Pass: 101” Pass分类 Analysis passes - 用于信息计算,其它Pass可以使用和调试相关信息 Transform passes - 可以使用Analysis passes - 以某种方式转换程序,通常是要对程序做出相应的改变 Utility passes - 提供了一些实用功能 - 例如-view-cfg可以查看函数的控制流图 但是PLCT使用的方式是 legacy pass manager 的方式,我这里使用的 new pass manager 。 添加一个LLVM pass来实现 Using LLVM For Program Transformation 中提出的 Lab: Find Non-Constant Format String . Any time the first parameter to printf, sprintf (others?) is nonconstant,

[LLVM]在汇编语言上插入指令

痴心易碎 提交于 2020-01-26 05:27:07
问题: LLVM 如何实现在汇编语言的 .s 文件中所有 call 指令前后添加2行固定指令? 答: LLVM 中 function 相关的 pass 用于修改 ir ,而 machine function 相关的 pas 用于修改 mir ,也就相当于修改生成的汇编 编写 machine function pass 然后遍历每个指令,在 call 之前调用 buildMI 函数插入需要的指令,这个 pass 必须在 code emit 之前,指令调度之后,为了避免指令调度把插入的固定指令移动到其它位置 判断一个 mir 是否 call 函数,可以使用 mi->desc().isCall 判断 来源: CSDN 作者: adream307 链接: https://blog.csdn.net/adream307/article/details/103885963

Is there a FunctionType with named arguments in LLVM?

允我心安 提交于 2020-01-25 08:11:17
问题 In LLVM, a function looks like this: define i32 @foo(i32, i32) By playing with lli , I noticed that this is also accepted: define i32 @foo(i32 %first-arg, i32 %second-arg) and then the arguments are accessible from the given names. How should I generate such a function with named arguments using the C++ API? I checked the documentation and it seems that there's no way to supply names to FunctionType::get as its second argument is of type ArrayRef<Type *> where there isn't a field for name (or

Is there a FunctionType with named arguments in LLVM?

孤者浪人 提交于 2020-01-25 08:11:09
问题 In LLVM, a function looks like this: define i32 @foo(i32, i32) By playing with lli , I noticed that this is also accepted: define i32 @foo(i32 %first-arg, i32 %second-arg) and then the arguments are accessible from the given names. How should I generate such a function with named arguments using the C++ API? I checked the documentation and it seems that there's no way to supply names to FunctionType::get as its second argument is of type ArrayRef<Type *> where there isn't a field for name (or

Can't open Llvm in ocaml

别等时光非礼了梦想. 提交于 2020-01-25 04:55:08
问题 I'm trying to use llvm binding in ocaml, in my file test.ml, I have one line of code: open Llvm When I run the command ocamlbuild -use-ocamlfind test.byte -package llvm I get this result: + ocamlfind ocamldep -package llvm -modules test.ml > test.ml.depends ocamlfind: Package `llvm' not found Command exited with code 2. Compilation unsuccessful after building 1 target (0 cached) in 00:00:00. What did I do wrong in this? Thanks. BTW, the _tag file contains: "src": traverse <src/{lexer,parser}

Is it possible to compile & link Clang/LLVM using the gold linker?

半腔热情 提交于 2020-01-24 05:42:05
问题 I'm writing a custom pass for LLVM/Clang, and recompiling tends to take a while and use a lot of memory. I've heard that the gold linker (1) takes less time and (2) uses less memory than the standard ld linker. Is there a way to pass flags into the LLVM/Clang build process and change to the gold linker? As per this answer, I've been attempting to use an override file, but I don't seem to be having a lot of success. I'll also note that I'm compiling the latest Clang/LLVM build (4.0) using

llvm: strategies to build JIT content incrementally

微笑、不失礼 提交于 2020-01-24 00:59:07
问题 I want my language backend to build functions and types incrementally but don't pollute the main module and context when functions and types fail to build successfully (due to problems with the user input). I ask an earlier question regarding this. One strategy i can see for this would be building everything in temp module and LLVMContext , migrating to main context only after success, but i am not sure if that is possible with the current API. For instance, i wouldn't know know to migrate

How to create a ConstantInt in LLVM?

好久不见. 提交于 2020-01-22 09:51:04
问题 I'm not sure how to create a ConstantInt in LLVM- I know the number I would like to create, but I'm unsure how I can make a ConstantInt representing that number; I can't seem to find the constructor I need in the documentation. I'm thinking it has to be along the lines of ConstantInt consVal = new ConstantInt(something here). I know I want it to be an int type, and I know my value... I just want to create a number! 回答1: Most things in LLVM are created through a static method call instead of

How to create a ConstantInt in LLVM?

只愿长相守 提交于 2020-01-22 09:49:09
问题 I'm not sure how to create a ConstantInt in LLVM- I know the number I would like to create, but I'm unsure how I can make a ConstantInt representing that number; I can't seem to find the constructor I need in the documentation. I'm thinking it has to be along the lines of ConstantInt consVal = new ConstantInt(something here). I know I want it to be an int type, and I know my value... I just want to create a number! 回答1: Most things in LLVM are created through a static method call instead of