llvm

llvm JIT add library to module

不羁的心 提交于 2019-12-22 08:40:37
问题 I am working on a JIT that uses LLVM. The language has a small run-time written in C++ which I compile down to LLVM IR using clang clang++ runtime.cu --cuda-gpu-arch=sm_50 -c -emit-llvm and then load the *.bc files, generate additional IR, and execute on the fly. The reason for the CUDA stuff is that I want to add some GPU acceleration to the runtime. However, this introduces CUDA specific external functions which gives errors such as: LLVM ERROR: Program used external function

How do I create named metadata via the llvm-c api?

╄→гoц情女王★ 提交于 2019-12-22 07:58:40
问题 I want to add debug metadata to my generated llvm IR, which is created via the C API. However, I can't figure out how to create named metadata nodes (such as !llvm.dbg.cu), or even how to create metadata nodes with unique numbers (ie. !0, !1, etc.). Adding metadata operands to instructions looks pretty simple, but I cannot figure out how to create standalone metadata nodes. 回答1: As at LLVM 3.0, there is no function exposed in the C API for creating or modifying named metadata. A new function

It there an equivalent to size_t in llvm

半世苍凉 提交于 2019-12-22 04:47:21
问题 Some system libraries like malloc strlen want or return size_t as parameter. What is the right choice in LLVM IR to interact with these functions? Is the selection the task for the compiler? Does LLVM IR have a size_t type? 回答1: At the LLVM level, size_t doesn't exist. It is a construct for the benefit of the developer that is typedef'd to a native type. The native types have a fixed size for the target architecture and that is how the compiler represents them in LLVM bit code. So on x86,

Is Clang really this smart?

天大地大妈咪最大 提交于 2019-12-22 04:24:07
问题 If I compile the following code with Clang 3.3 using -O3 -fno-vectorize I get the same assembly output even if I remove the commented line. The code type puns all possible 32-bit integers to floats and counts the ones in a [0, 1] range. Is Clang's optimizer actually smart enough to realize that 0xFFFFFFFF when punned to float is not in the range [0, 1], so ignore the second call to fn entirely? GCC produces different code when the second call is removed. #include <limits> #include <cstring>

LLVM Struct Return Optimization

拟墨画扇 提交于 2019-12-22 04:07:24
问题 I'm wondering why LLVM fails to optimize the following IR code (using the PassManagerBuilder with optimisation set to '3', and also using LLVM's 'opt' tool): %GenericStruct = type { i32 } define void @makeGenericStructOuter(%GenericStruct* noalias nocapture sret) { entry: %1 = alloca %GenericStruct call void @makeGenericStructInner(%GenericStruct* %1) %2 = load %GenericStruct* %1 store %GenericStruct %2, %GenericStruct* %0 ret void } declare void @makeGenericStructInner(%GenericStruct*

OpenCL LLVM IR generation from Clang

佐手、 提交于 2019-12-22 00:06:20
问题 I am using the following command line for clang: clang -Dcl_clang_storage_class_specifiers -isystem $LIBCLC/generic/include -include clc/clc.h -target nvptx--nvidiacl -x cl some_kernel.cl -emit-llvm -S -o some_kernel.ll the result is: ; ModuleID = 'kernel.cl' target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64" target triple = "nvptx--nvidiacl" ; Function Attrs: noinline nounwind define void

AST of a project by Clang

混江龙づ霸主 提交于 2019-12-21 23:17:15
问题 I use the Clang python binding to extract the AST of c/c++ files. It works perfectly for a simple program I wrote. The problem is when I want to employ it for a big project like openssl. I can run clang for any single file of the project, but clang seems to miss some headers of the project, and just gives me the AST of a few functions of the file, not all of the functions. I set the include folder by -I, but still getting part of the functions. This is my code: import clang.cindex as cl cl

Using LLVM opt with built-in passes

两盒软妹~` 提交于 2019-12-21 21:59:39
问题 I have successfully run llvm opt with my toy transformation pass but do not see how to use 'opt' with built-in transformation passes http://llvm.org/docs/Passes.html#introduction I have an empty hi.c file int main(){ } For example, if I want to use -instcount pass, opt -instcount hi.c gives me strange error. opt: hi.c:1:1: error: expected top-level entity int main(){ ^ Use opt -instcount hi.bc does not work neither, with WARNING: You're attempting to print out a bitcode file. This is

“Invalid symbol redefinition” in inline ASM on LLVM

一曲冷凌霜 提交于 2019-12-21 21:55:52
问题 I've got a project in Xcode (4.5.2) that builds fine using the Debug configuration. However, now that I've switched to building the Release configuration, I'm getting an issue: one of my inline assembly functions is getting the error Invalid symbol redefinition . Googling that error message finds me a few people who have got that compiler error, but no information as to what it means. Here's the function, with the error lines annotated: inline int MulDivAdd(int nNumber, int nNumerator, int

How can I code generate unused declarations with Clang?

你。 提交于 2019-12-21 20:37:00
问题 I'm looking to code generate an llvm::Module from some C++ code. Specifically, I will be mixing code generated by Clang and code from another source. Unfortunately, Clang's CodeGenModule class appears to insist on only generating a declaration into the Module if there is a definition which uses it. How can I convince the CodeGenModule to generate these declarations anyway? 回答1: Apparently, -femit-all-decls does not actually emit all the decls, so I had to modify Clang's source code to