llvm

How to generate metadata for LLVM IR?

两盒软妹~` 提交于 2019-12-07 23:59:54
问题 I am trying to generate a metadata for the LLVM IR i have generated. I want to generate a metadata of the form : !nvvm.annotations = !{!0} !0 = metadata !{void ()* @foo, metadata !"kernel", i32 1} Where foo is a function in my LLVM IR. Right now I am only able to generate a metadata of the form: !nvvm.annotations = !{!0} !0 = !{!"kernel"} I used the following code for the above metadata generation. char metaDataArgument[512]; sprintf(metaDataArgument, "%s", pipelineKernelName); llvm:

What is LLVM metadata

牧云@^-^@ 提交于 2019-12-07 20:51:53
问题 These might be very basic questions.. 1) What is LLVM metadata and how do I use it in my program? I've read all the documentation, but I don't understand how to use it. 2) How to I add my personal metadata in a file? Thanks in advance! 回答1: The best source of information would be the blog post from 2010 that introduced metadata into LLVM IR - Extensible Metadata in LLVM IR. The first paragraph mentions the motivation: This metadata could be used to influence language-specific optimization

LLVM每日谈之十二 LLVM的源码分析之Pass相关

…衆ロ難τιáo~ 提交于 2019-12-07 20:07:08
作者: snsn1984 题记:在学习LLVM的过程中,要想学的更加深入,掌握更多的技能,LLVM的源码是必须要读的,但是在这么多的源码中,从哪里下手?很容易让人找不到头脑,本文这里就先拿出几个Pass相关的源码文件进行分析。 1.Pass.h 源码中的位置:llvm源码/include/llvm/Pass.h 网络上位置: http://llvm.org/docs/doxygen/html/Pass_8h_source.html 此头文件的内容:此头文件主要对和Pass相关的几个类进行了声明。主要有Pass、ModulePass、ImmutablePass、 FunctionPass、BasicBlockPass这几个类。之前在关于Pass的博文里也介绍过一些和Pass相关的知识,而这几个类正是 LLVM的Pass框架所最常用的几个类,在Pass的编写或者修改的工作中,基本上都是在和这几个类打交道,所以对于这几个类要想有一个深的了解,这个 头文件是必须读的。 ModulePass、ImmutablePass、FunctionPass、BasicBlockPass这几个类都是Pass的子类,也 是在写Pass的时候最容易直接用到的类。自己编写LLVM的Pass的时候,使用的最多是FunctionPass和ModulePass这两个。而这 两个之中

move function body, avoiding full cloning

懵懂的女人 提交于 2019-12-07 20:03:02
问题 This is a follow up question from this one. I am using llvm::CloneFunctionInto defined in llvm/Transforms/Utils/Cloning.h in order to create a new function after code generation with the right signature inferred from the type of the return values. This works nicely but it is slow I am trying to optimize this a little bit by some way to move or transfer the function body from the old function to the new one, is there a utility for that? I am trying to hack a way to do the transfer by looking

How to tell if LLVM Instruction as a Left-Hand Side

岁酱吖の 提交于 2019-12-07 19:26:35
问题 Is there a way to tell if an LLVM Instruction has a left-hand side? That is, whether it produces a value? For example, an add instruction would have a left-hand side; however, a store or br instruction would not. 回答1: In general you can identify those instructions which cannot have a result assignment, but you cannot say if an instruction will result in an assignment, only that it might . This is because you don't have to assign the result of an operation. For instance, the following line of

Clang: How to check if LTO was performed

不羁的心 提交于 2019-12-07 19:23:16
问题 For gcc, this answer tells us how we can verify that Link-Time Optimization was performed. For clang, I cannot see any entries similar to .gnu.lto . More specifically, I have a binary where I am quite sure that LTO should have a significant benefit, but I am seeing nothing. I wonder if cmake actually does the right thing. Is there any way to tell if clang performed LTO by looking at a binary or an *.o file? 回答1: An option would be to try running llvm-dis on one of your .o files. If the LTO

LLVM Backend : Replacing indirect jmps for x86 backend

北慕城南 提交于 2019-12-07 17:53:47
问题 I want to replace indirect jmp *(eax) instructions in the code to mov *(eax),ebx; jmp *ebx for the x86 executables. Before implementing this, i would like to make LLVM compiler, log an output every time it detects a jmp *(eax) instruction by adding some print statements. Then i want to move on to replacing the indirect sequence. From what i have seen from google searches and articles, i can probably achieve this by modifying the x86asmprinter in the llvm backend. But i am not sure how to go

Alignment of vectors in LLVM's amd64 output

ⅰ亾dé卋堺 提交于 2019-12-07 16:29:34
问题 I'm trying to use vectors inside structs with LLVM. I have the following C definition of my struct: struct Foo { uint32_t len; uint32_t data[32] __attribute__ ((aligned (16))); }; and here's some LLVM code to add 42 to element number 3 of the data field: %Foo = type { i32, <32 x i32> } define void @process(%Foo*) { _L1: %data = getelementptr %Foo* %0, i32 0, i32 1 %vec = load <32 x i32>* %data %x = extractelement <32 x i32> %vec, i32 3 %xNew = add i32 42, %x %vecNew = insertelement <32 x i32>

(十四)Android NDK混淆

一笑奈何 提交于 2019-12-07 15:09:40
1、ollvm下载编译 我的是macbook环境。 参考obfuscator官网: https://github.com/obfuscator-llvm/obfuscator/wiki 执行下面的命令下载并编译: $ git clone -b llvm-4.0 https://github.com/obfuscator-llvm/obfuscator.git $ mkdir build $ cd build $ cmake -DCMAKE_BUILD_TYPE=Release ../obfuscator/ $ make -j7 cmake找不到的话,上cmake.org官网下载,并设置环境变量。 编译成功后,生成的文件主要在build/bin 和 build/lib 这2个文件夹。 2、整合到NDK 网上别人有介绍在NDK目录手动创建llvm之类的新文件夹,拷贝build/bin 和 build/lib2个文件夹,有编译问题,懒得去折腾。 我的做法是: 找到Android SDK目录中的 ../ndk-bundle/toolchains/llvm 文件夹,先备份下llvm文件夹,然后将obfuscator编译好的build/bin 和 build/lib2个文件夹直接拷贝到../llvm/prebuilt/darwin-x86_64/文件夹下,直接覆盖替换。

compiling with clang and plugin

纵饮孤独 提交于 2019-12-07 15:03:37
问题 clang supports plugins, and often this concept is used to build tools like static analysis and such. To start playing with it I took this example which prints all function names present in the target cpp file(s). I compiled the plugin running the following: clang++ -v -std=c++11 PrintFunctionNames.cpp \ $(llvm-config --cxxflags --ldflags) \ -o plugin.so -shared -Wl,-undefined,dynamic_lookup and then run it "by the book": clang++ \ -c main.cpp \ -Xclang -load \ -Xclang $PWD/plugin.so \ -Xclang