llvm-ir

How do I get debug information from a function?

自闭症网瘾萝莉.ら 提交于 2019-12-04 07:26:01
I've used Clang to compile a function with debug information enabled. For Instruction s there's the handy getDebugLoc() , but there's no such thing for Function s. Given a Function instance, how can I get the debug information (I'm guessing in DISubProgram form) for it? I've seen the guide entry explaining how that debug information is represented , and the metadata does contain a link back to the function, but there's apparently no link back. Am I supposed to iterate over all the metadata in the module? I don't think there's currently an easier way. There used to be a global metadata node

Why is LLVM segfaulting when I try to emit object code?

扶醉桌前 提交于 2019-12-03 16:58:43
I'm trying to follow along with the LLVM tutorial on compiler implementation, but my code segfaults when I try to emit object code. Here's a minimal example that attempts to compile a function func . To keep things simple, func is a function that does nothing. #include <iostream> #include <llvm/ADT/Optional.h> #include <llvm/IR/BasicBlock.h> #include <llvm/IR/DerivedTypes.h> #include <llvm/IR/Function.h> #include <llvm/IR/IRBuilder.h> #include <llvm/IR/LLVMContext.h> #include <llvm/IR/LegacyPassManager.h> #include <llvm/IR/Module.h> #include <llvm/IR/Type.h> #include <llvm/IR/Verifier.h>

Possible to auto-generate llvm c++ api code from LLVM-IR?

只愿长相守 提交于 2019-12-03 16:13:36
The clang 3.0 online demo page http://llvm.org/demo/index.cgi provides an option to output LLVM C++ API code" representing the LLVM-IR for the input program. Is "produce LLVM C++ API code" output a clang option (and if so, what is it)? Or is it an llvm tool option (which one)? Is it possible to do the same thing but from LLVM-IR input? Basically I'd like to see the proper llvm c++ api calls needed to produce a particular given llvm-ir sequence. I'd like to learn backwards by example rather than forwards from the documentation. Manual pages and --help and --help-hidden for clang, llvm-as and

LLVM and compiler nomenclature

断了今生、忘了曾经 提交于 2019-12-03 10:42:57
I am looking into the LLVM system and I have read through the Getting Started documentation . However, some of the nomenclature (and the wording in the clang example) is still a little confusing. The following terms and commands are all part of the compilation process, and I was wondering if someone might be able to explain them a little better for me: clang -S vs. clang -c (I know what -c does, but how do the results differ?) * (Edit) LLVM Bitcode vs. LLVM IR (what is the difference?) .ll files vs. .bc files (what are they, how do they differ?) LLVM assembly code vs. native assembly code (is

Integrating LLVM passes

瘦欲@ 提交于 2019-12-03 09:23:27
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 for linking too, and the linker has no idea what it can do with this information and fails the build :\ )

Conversion from ___attribute___((shared)) to addrspace(3) in Clang compiler when compiling CUDA files

半世苍凉 提交于 2019-12-02 10:52:54
问题 The clang compiler includes CUDA header file host_defines.h in which the __shared__ is defined as __attribute__((shared)) . When CUDA source files are compiled to internal representation (IR) using clang, the __shared__ gets converted to addrspace(3) . These address spaces can be observed in the clang file llvm/tools/clang/lib/Basic/Targets.cpp line number 1601 as an array static const unsigned NVPTXAddrSpaceMap[] = { 1, // opencl_global 3, // opencl_local 4, // opencl_constant // FIXME:

what does machine value type “other” mean in llvm SDnodes

£可爱£侵袭症+ 提交于 2019-12-02 07:13:37
问题 I am trying to understand more deeply the instruction selection process in llvm and for that I am debuging step-by-step the CodeGenAndEmitDAG function. I have printed a small function (see below) just before the combine step - the first step in the above function. In the graph I see blue lines and it seems that they are always pointing at "ch" , which I think means "other" machine value type. What I don't understand is the meaning of the blue lines... what is this dependency ? And, am I right

Compiled Haskell program to LLVM IR is missing main

别说谁变了你拦得住时间么 提交于 2019-12-02 07:13:15
问题 following this SO post regarding the compilation of Haskell programs to LLVM IR, I took the same Haskell program and tried to run its resulting LLVM IR code: quicksort [] = [] quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater) where lesser = filter (< p) xs greater = filter (>= p) xs main = print(quicksort([5,2,1,0,8,3])) I first compiled it to LLVM IR with $ ghc -keep-llvm-files main.hs Then I transformed it to bitcode with: $ llvm-as main.ll However, when I tried to run it

Compiled Haskell program to LLVM IR is missing main

一世执手 提交于 2019-12-02 06:26:00
following this SO post regarding the compilation of Haskell programs to LLVM IR, I took the same Haskell program and tried to run its resulting LLVM IR code: quicksort [] = [] quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater) where lesser = filter (< p) xs greater = filter (>= p) xs main = print(quicksort([5,2,1,0,8,3])) I first compiled it to LLVM IR with $ ghc -keep-llvm-files main.hs Then I transformed it to bitcode with: $ llvm-as main.ll However, when I tried to run it with lli I get the following error regarding a missing main: $ lli main.bc 'main' function not found in

Error in Compiling haskell .ll file with llvm backend

…衆ロ難τιáo~ 提交于 2019-12-02 01:15:47
I want to compile haskell using ghc front-end and llvm back-end. I have following code in my haskell hello.hs file: main = putStrLn "Hello World!" I compile hello.hs with ghc using following command ghc -fllvm -keep-llvm-files -force-recomp -hello.hs which generate a hello.ll file along with other files. I then try to compile this .ll file into a .bc file. llvm-as hello.ll -o hello.bc and then this .bc file to executable file llc hello.bc -o hello which generate an executable file. The problem is when I run this file I found the following error ./hello: line 1: .file: command not found ./hello