llvm

How do I use an exisiting function pass from my LLVM - pass?

前提是你 提交于 2019-11-30 04:53:14
问题 I have been using LLVM and I was confused how to use a different already present pass from my own pass ? Precisely my program needs Dominance Frontier Calculation for any given instruction. LLVM already has the Dominance function Class that is implemented as a function pass. How can i invoke it/make use of it in my Module Pass ? 回答1: WARNING: I have no real experience and answer may be incorrect or outdated. (it is based largely on outdated LLVM sources: version 1.3.) Add an include: #include

Installing LLVM libraries along with Xcode

六月ゝ 毕业季﹏ 提交于 2019-11-30 03:54:01
So I just installed Xcode on my Mac and now I would like to install LLVM as well in order to play around a bit with LLVM itself. Currently the compiler can (obviously) not find the required header files. So what is the best way to install LLVM if you already have clang, packed with Xcode, on your system? Thanks in advance. Hongxu Chen If you do not need to read LLVM implementation source code(such as in lib / tools directories) and might only play with libclang , perhaps using homebrew is enough for you. brew install --with-clang --with-lld --with-python --HEAD llvm Next you need to set PATH ,

Out-of-Line Virtual Method

我的梦境 提交于 2019-11-30 02:44:23
What exactly is a out-of-line virtual method and why does it affect link times? http://llvm.org/docs/CodingStandards.html says If a class is defined in a header file and has a vtable (either it has virtual methods or it derives from classes with virtual methods), it must always have at least one out-of-line virtual method in the class. Without this, the compiler will copy the vtable and RTTI into every .o file that #includes the header, bloating .o file sizes and increasing link times. The compiler must emit a vtable for classes with virtual methods. This contains the pointers to these methods

Cmake and clang tooling linking error (outside of source tree)

拜拜、爱过 提交于 2019-11-30 02:24:31
I am trying to compile the RecursiveASTVisitor example of Clang using a CMake file. Building the project goes well, however linking C++ executable fails with multiple undefined reference to LLVM and Clang libraries. I am building the example outside of the LLVM/Clang source file tree. Here is my CMakeLists.txt (I am using FindClang.cmake and FindLLVM.cmake from this project ): cmake_minimum_required(VERSION 2.8.4) project(ifcount) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) message(STATUS "CMAKE module path: ${CMAKE_MODULE_PATH}") find_path(LibClang

Adding a function call in my IR code in llvm

感情迁移 提交于 2019-11-30 01:36:53
Can you give me an example ,how to add a simple call of a function foo(x); on my IR code with my pass in llvm? A simple way is to learn is to use ELLCC with Output Options as LLVM C++ API Code . Two key notes: Make sure foo 's definition is available; otherwise you need to define it firstly. Typically you need to get the prototype by using getOrInsertFunction and then use IRBuilder to insert the body for the function. Create the CallInst , an easy way is to use CallInst*IRBuilder::CreateCall(Value*, ArrayRef<Value*>, const Twine &) . Here is a segment I wrote before for llvm3.4; hope it can

如何利用llvm得到一个函数的CFG结构

故事扮演 提交于 2019-11-30 01:29:25
1.llvm-5.0安装 参考:https://www.jianshu.com/p/861c1a630059 准备工作 首先安装必要的软件,官方是使用 svn 进行版本控制的,我们可以通过 svn 获取其源码。安装过程中要用到 cmake 命令,所以我们需要安装 subversion 和 cmake 两个软件。LLVM 也支持 Git 了,但是好像不是所有的子项目都支持,所以这里没做研究。 sudo apt install subversion sudo apt install cmake 下载 LLVM 核心代码 Checkout LLVM from Subversion 首先我们建立一个文件夹 llvm-source 用来存放源代码。由于同学使用的是 RELEASE_500 这一版本,所以这里我也下载这一版本 LLVM 核心代码仓库。 mkdir llvm-source-build cd llvm-source-build svn co http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_500/final llvm 下载 Clang 源码 llvm-project,切到 llvm 核心代码的 tools 目录下,下载 Clang 的源码。下载完成后,返回到 llvm 目录下。 cd llvm/tools svn co http

can I count on my compiler to optimize strlen on const char *?

老子叫甜甜 提交于 2019-11-30 01:06:00
问题 In my SAX xml parsing callback (XCode 4, LLVM), I am doing a lot of calls to this type of code: static const char* kFoo = "Bar"; void SaxCallBack(char* sax_string,.....) { if ( strcmp(sax_string, kFoo, strlen(kFoo) ) == 0) { } } Is it safe to assume that strlen(kFoo) is optimized by the compiler? (The Apple sample code had pre-calculated strlen(kFoo), but I think this is error prone for large numbers of constant strings.) Edit: Motivation for optimizing: parsing my SVG map on iPod touch 2G

In Xcode project target build settings, What is Mach-O Type?

不想你离开。 提交于 2019-11-30 00:21:21
After getting tired of numerous Match-O linker error, I want to know that this thing means. Instead of trial and error solution, I would like to know the concept behind these things. Specifically I want to know the difference between : Executable Dynamic Library Bundle Static Library Relocatable Object File These are the options presented when I click on Mach-O Type settings on Linking section. Some small definition or some link to appropriate content is ok too. Srikar Appalaraju Mach-O , short for Mach object file format, is a file format for executables, object code, shared libraries,

【iOS Tips】给Xcode添加PCH文件

一个人想着一个人 提交于 2019-11-30 00:17:45
1、 打开你的Xcode工程. 在Supporting Files目录下,选择 File > New > File > iOS > Other > PCH File 然后点击下一步(或者使用快捷键创建:cmd+N); 2、假设你的项目名称为TestPch, 你可将PCH 文件命名为 TestPch-Prefix.pch,然后创建; 3、选择 PCH 文件(文章的示例文件为 TestPch-Prefix.pch) ,可以看到里面的内容如下: 4、找到 TARGETS > Build Settings > 搜索 “Prefix Header“; 5、“Apple LLVM 7.0 -Language″ 栏目中你将会看到 Prefix Header 关键字,将Precompile Prefix Header为YES,预编译后的pch文件会被缓存起来,可以提高编译速度; 6、 输入: TestPch/TestPch-Prefix.pch,如下所示; 7、 Clean 并且 Build 你的项目. 8、测试一下在pch中加一个宏,发现在ViewController中可以使用这个宏 pch中: viewController中: 测试结果: OK!成功!现在你可以使用你的 PCH 文件就像你使用老版本的Xcode一样了 来源: oschina 链接: https://my.oschina.net

How to detect LLVM and its version through #define directives?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 22:46:32
The question is quite clear I think. I'm trying to write a compiler detection header to be able to include in the application information on which compiler was used and which version. This is part of the code I'm using: /* GNU C Compiler Detection */ #elif defined __GNUC__ #ifdef __MINGW32__ #define COMPILER "MinGW GCC %d.%d.%d" #else #define COMPILER "GCC %d.%d.%d" #endif #define COMP_VERSION __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ #endif Which could be used like this: printf(" Compiled using " COMPILER "\n", COMP_VERSION); Is there any way to detect LLVM and its version? And CLANG?