llvm-ir

Generate LLVM IR from Haskell code

拥有回忆 提交于 2019-12-10 13:02:00
问题 My goal is take source codes in different languages (mostly C, C++, Obj-C and Haskell) and tell every kind of statistics about them. (eg. number of variables, functions, memory allocations, complexity etc.) LLVM seemed to be a perfect tool for this, because I can generate the bitcode for these languages and with LLVM's customizable passes I can almost do anything. For the C family it works fine, take a C program ( test.c ) for example: #include <stdio.h> int main( ) { int num1, num2, sum;

Integrating LLVM passes

你说的曾经没有我的故事 提交于 2019-12-09 06:46:17
问题 This maybe a rookie question but is there a way to integrate my LLVM modulepass to be called by default during the transformation phase? Right now I am using this syntax to load my pass and register it ~/llvm/llvm/build/Debug+Asserts/bin/clang -Xclang -load -Xclang ~/llvm/llvm/build/Debug+Asserts/lib/SOMEPASSLIB.so (The problem is when I want to build some package with this pass, the compiler accepts it when I say, pass the loading part as CFLAGS env variable, but some makefiles use CFLAGS

Adding intrinsics using an LLVM pass

北战南征 提交于 2019-12-08 20:06:56
问题 I've added an intrinsic to an input code using an LLVM pass. I'm able to see the intrinsic call, yet I can't figure out how to compile the code to my target architecture (x86_64). I'm running the following command: clang++ $(llvm-config --ldflags --libs all) ff.s -o foo But the linker complains about undefined references: /tmp/ff-2ada42.o: In function `fact(unsigned int)': /home/rubens/Desktop/ff.cpp:9: undefined reference to `llvm.x86.sse3.mwait.i32.i32' /tmp/ff-2ada42.o: In function `fib

Clang Linking error: undefined reference to function calls added by LLVM pass

限于喜欢 提交于 2019-12-08 10:43:14
问题 So I am following this tutorial https://www.cs.cornell.edu/~asampson/blog/llvm.html to make a pass that instruments a program by adding calls to an external function (which is logop in rtlib.c). But unlike the tutorial I am trying to instrument a larger code-base which is masstree: https://github.com/kohler/masstree-beta. So as instructed for masstree I run ./configure first but then I edit the generated Makefile to use clang (instead of gcc/g++) and run my pass. I also add rtlib.c in the

How do I link when building with llvm libraries?

混江龙づ霸主 提交于 2019-12-08 07:55:12
问题 I am trying to parse a LLVM-IR file(.ll) and do a static analysis.. I found this sample code below, and I tried to build it, but I don't know which library to link. #include <iostream> #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IRReader/IRReader.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; int main(int argc, char** argv) { if (argc < 2) { errs() << "Expected an argument - IR file name\n"; exit(1); }

Get pointer to llvm::Value previously allocated for CreateLoad function

ぃ、小莉子 提交于 2019-12-08 07:34:16
问题 I'm new to llvm and I'm writing a small llvm IR Builder. I use the IRBuilder and all these Create* functions to generate my IR. What I'm trying to do is to create a load instruction which create a new SSA local variable with value of a previously allocated llvm::Value . What I expected to have : %2 = load i32* %1 With %2 results of load instruction and %1 my previously allocated Value (CreateAlloca) Here is what I tried : // Get Ptr from Val Value* ptr = ConstantExpr::getIntToPtr((Constant*

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:

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

Getting actual value of local variables in llvm

旧城冷巷雨未停 提交于 2019-12-07 11:45:21
问题 If I have this example: int a=0, b=0; a and b are local variables and make any modifications in their values, such as: a++; b++; I need to get the value in this line code during running MCJIT. I mean by value not Value class, but the actual integer or any type value. 回答1: You need to return the value from a JITed LLVM function in order to retrieve it from the code invoking MCJIT. Check out this Kaleidoscope example. The relevant code is in HandleTopLevelExpression(): if (FunctionAST *F =

LLVM tail call optimization

放肆的年华 提交于 2019-12-07 07:58:59
问题 Here is my understanding of things: A function "f" is tail recursive when calling itself is its last action. Tail-recursion can be significantly optimized by forming a loop instead of calling the function again; the function's parameters are updated in place, and the body is ran again. This is called recursive tail call optimization. LLVM implements recursive tail call optimization when using fastcc, GHC, or the HiPE calling convention. http://llvm.org/docs/CodeGenerator.html#tail-call