llvm

Add LLVM to project using cmake

匿名 (未验证) 提交于 2019-12-03 01:01:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to add LLVM to a cmake project, using cygwin as a compiler. I downloaded LLVM from cygwin's installer (just installed all of the llvm related packages). The files are there, however I cannot include LLVM in my project. I tried using the official guide for 3.5.2 (the version it installed) and my CMakeLists.txt looks like cmake_minimum_required ( VERSION 3.2 ) project ( Lang ) find_package ( LLVM REQUIRED CONFIG ) message ( STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}" ) message ( STATUS "Using LLVMConfig.cmake in: ${LLVM

LLVM opt mem2reg has no effect

匿名 (未验证) 提交于 2019-12-03 01:00:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am currently playing around with LLVM and am trying to write a few optimizers to familiarize myself with opt and clang. I wrote a test.c file that is as follow: int foo(int aa, int bb, int cc){ int sum = aa + bb; return sum/cc; } I compiled the source code and generated 2 .ll files, one unoptimized and one with mem2reg optimizer pass: clang -emit-llvm -O0 -c test.c -o test.bc llvm-dis test.bc opt -mem2reg -S test.ll -o test-mem2reg.ll Both .ll files gave me the following output: ModuleID = 'test.bc' source_filename = "test.c" target

design suggestion: llvm multiple runtime contexts

雨燕双飞 提交于 2019-12-03 00:53:20
My application needs to run many separate contexts in the same (single-threaded) process. They all share a single LLVMContext . The process will run many contexts (in the thread sense); that is, each one runs a function in a continuation object based on boost::context (still on vault, pre-approved lib) it means that each context can yield, but they basically run in the same single-threaded process. Each one should run basically independent of the other, and more importantly, a compilation error in each one should not affect the execution of the others. Each of these contexts, will invoke code

Archive apple LLVM 6.0 error could not read profile

匿名 (未验证) 提交于 2019-12-03 00:48:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When in device test it's ok. But when I want to archive, xcode give the error like this. error: Could not read profile: No such file or directory it is the errors CompileC /Users/wikimo/Library/Developer/Xcode/DerivedData/jinbi-anvflcahmvfrbchckuahzoashzvm/Build/Intermediates/ArchiveIntermediates/jinbi/IntermediateBuildFilesPath/jinbi.build/Release-iphoneos/jinbi.build/Objects-normal/armv7/UIColor+Extension.o jinbi/Views/NavigationMenuView/UIColor+Extension.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler cd /wikimo

基于LLVM的Pass优化

匿名 (未验证) 提交于 2019-12-03 00:39:02
当我们如果完成了对源码的转换,得到了LLVM的IR表示形式,它是作为一种向汇编代码转换的一个公共平台,依赖不同的后端会得到不同的汇编码,在转换为汇编码之前,如果我们对IR进行优化的话就可以得到执行效率更高的代码 在LLVM的架构当中,Pass的作用就是优化LLVM IR,Pass作用于LLVM IR,用来处理IR,分析IR,寻找优化的机会并修改IR,从而产生优化的代码。在下面命令行工具opt就是用来在LLVM IR上运行各种优化Pass的 通常来说编译器的优化会有多种级别,有0~3级别,优化级别越高,代码得到的优化也越多 首先我们先去写一个C语言程序 int main(int argc,char **argv) { int i,j,k,t= 0 ; for (i= 0 ; i< 10 ; i++) { for (j= 0 ; j< 10 ; j++) { for (k= 0 ; k< 10 ; k++) { t++; } } for ( j = 0 ; j < 10 ; j ++) { t++; } } for ( i = 0 ; i < 20 ; i ++) { for (j= 0 ; j< 20 ; j++) { t++; } for ( j = 0 ; j < 20 ; j ++) { t++; } } return t; } 使用clang命令也就是clang -S -O0

基于LLVM-增加JIT支持

匿名 (未验证) 提交于 2019-12-03 00:37:01
JIT其实就是Just-In-Time也就是即时编译,在程序运行的时候会将代码翻译成机器码并且去执行,与之相对的就是AOT(Ahead Of Time),它在程序运行之前就会将代码翻译成机器码,JIT结合了AOT和解释执行的优势,它能够产生高效的机器码,并且具备足够的灵活性 首先我们定义一个执行引擎作为全局静态变量 static ExecutionEngine *TheExecutionEngine; 然后就是在main函数当中增加如下代码 //InitializeNativeTarget――主程序应该调用此函数来初始化与主机对应的本机目标。这对于JIT应用程序非常有用,以确保目标被正确地链接。客户端对这个函数进行多次调用是合法的。 InitializeNativeTarget() ; //主程序应该调用此函数来初始化本机目标asm打印机 InitializeNativeTargetAsmPrinter() ; //InitializeNativeTargetAsmParser――主程序应该调用这个函数来初始化本机目标asm解析器。 InitializeNativeTargetAsmParser() ; 还有下面的代码 std: :unique_ptr<Module> Owner = make_unique< Module >( "my compiler" , *llvmcx);

Set value for llvm::ConstantInt

杀马特。学长 韩版系。学妹 提交于 2019-12-03 00:36:09
I'm playing around with LLVM. I thought about changing value of a constant in the intermediate code. However, for the class llvm::ConstantInt , I don't see a setvalue function. Any idea how can I modify value of a constant in the IR code? ConstantInt is a factory, isn't it? Class has the get method to construct new constant: /* ... return a ConstantInt for the given value. */ 00069 static Constant *get(Type *Ty, uint64_t V, bool isSigned = false); So, I think, you can't modify existing ConstantInt. If you want to modify IR, you should try to change pointer to argument (change the IR itself,

Can C/C++ software be compiled into bytecode for later execution? (Architecture independent unix software.)

别等时光非礼了梦想. 提交于 2019-12-03 00:25:52
I would want to compile existing software into presentation that can later be run on different architectures (and OS). For that I need a (byte)code that can be easily run/emulated on another arch/OS ( LLVM IR? Some RISC assemby?) Some random ideas: Compiling into JVM bytecode and running with java. Too restricting? C-compilers available? MS CIL. C-Compilers available? LLVM? Can Intermediate representation be run later? Compiling into RISC arch such as MMIX. What about system calls? Then there is the system call mapping thing, but e.g. BSD have system call translation layers. Are there any

LLVM每日谈之五十五 浅谈对Pass的错误认知及其原因

匿名 (未验证) 提交于 2019-12-02 23:43:01
Pass作为LLVM的一个重要的组成部分,在LLVM IR层面和LLVM Backend层面都发挥了重要的作用。很多LLVM的使用者容易将Pass理解为LLVM IR层面的analysis和transform,而忽略了Pass在LLVM Backend层面的作用。而实际上,Pass在LLVM Backend层面发挥的作用一点都不小。以后端的结构为例: Notes: 《Getting Started with LLVM Core Libraries》P134. 《Getting Started with LLVM Core Libraries》作者将空白框内的内容直接写为Pass,带灰色框的内容解释为由多个小Pass组成的super Pass。按照这种说法,可以将Pass理解为整个后端的主要组成部分。当然,后端也不完全是Pass,只不过从执行的流程来看,Pass参与了整个后端的主要环节。 那么,为什么后端的Pass总那么容易被忽略? 首先,要从Pass的子类及其子类的子类说起。Pass的子类主要有: 其中,我们在LLVM IR层面用的最多的是FunctionPass。而LLVM Backend中的Pass,主要是以MachineFunctionPass为父类的。而MachineFunctionPass是FunctionPass的子类,其结构如图: 这种结构上

LLVM笔记(3) - PASS

匿名 (未验证) 提交于 2019-12-02 23:43:01
1. pass的概念 2. 跟踪与调试pass 1 [13:38:49] hansy@hansy:~$ cat test.c 2 int sigma(int cnt) 3 { 4 int sum = 0, i = 0; 5 for (i = 0; i < cnt; i++) 6 sum += i; 7 return sum; 8 } 9 10 [13:38:55] hansy@hansy:~$ clang test.c -O2 -mllvm -debug -S 2>test.ll 11 [13:39:02] hansy@hansy:~$ clang test.c -O2 -mllvm -debug-only=early-cse -S 2>test.ll 12 [13:39:05] hansy@hansy:~$ clang test.c -O2 -mllvm -print-before-all -S 2>test.ll 13 [13:39:16] hansy@hansy:~$ clang test.c -O2 -mllvm -print-after-all -S 2>test.ll 14 [13:39:25] hansy@hansy:~$ clang test.c -O2 -mllvm -print-after-all -mllvm -filter-print-funcs=sigma