llvm-c++-api

clang: export symbols of implicitly instantiated functions with O3

假装没事ソ 提交于 2020-02-06 05:08:05
问题 TL,DR: How can I force clang to export the symbols of implicitly instantiated functions even when -O3 is active? Let's take the following code: #include <iostream> #include <llvm/Support/DynamicLibrary.h> #include <llvm/ExecutionEngine/ExecutionEngine.h> #include <llvm/ExecutionEngine/RTDyldMemoryManager.h> template <typename T> __attribute__((noinline)) int twice(const T& t) { return t * 2; } int thrice(const int& t) { return t * 3; } int main() { std::cout << twice(5) << std::endl; std:

Is there a FunctionType with named arguments in LLVM?

允我心安 提交于 2020-01-25 08:11:17
问题 In LLVM, a function looks like this: define i32 @foo(i32, i32) By playing with lli , I noticed that this is also accepted: define i32 @foo(i32 %first-arg, i32 %second-arg) and then the arguments are accessible from the given names. How should I generate such a function with named arguments using the C++ API? I checked the documentation and it seems that there's no way to supply names to FunctionType::get as its second argument is of type ArrayRef<Type *> where there isn't a field for name (or

Is there a FunctionType with named arguments in LLVM?

孤者浪人 提交于 2020-01-25 08:11:09
问题 In LLVM, a function looks like this: define i32 @foo(i32, i32) By playing with lli , I noticed that this is also accepted: define i32 @foo(i32 %first-arg, i32 %second-arg) and then the arguments are accessible from the given names. How should I generate such a function with named arguments using the C++ API? I checked the documentation and it seems that there's no way to supply names to FunctionType::get as its second argument is of type ArrayRef<Type *> where there isn't a field for name (or

LLVM IR: How to call a function in another .ll file

我是研究僧i 提交于 2020-01-17 06:09:26
问题 I am writing LLVM IR code, can I call a function in another .ll file? For example: In a.ll file, there is a function foo(); Can I use this function in b.ll, like just call foo? If so, how can I include a.ll Thanks 回答1: You need to add declaration of function foo in the ll file in which you are calling it, then as usual convert link ll files to generate executable llvm-link a.ll b.ll -o a.out example a.ll declare i32 @foo(i32) define i32 @main() { start: %0 = call i32 @foo(i32 0) ret i32 %0 }

Segmentation fault while using AAResultsWrapperPass in llvm3.8.1

99封情书 提交于 2020-01-14 06:09:10
问题 I am trying to migrate my project from llvm3.6.2 to llvm3.8.1. In my code, I have used AliasAnalysis and I am changing my code as follows: #if defined(DDP_LLVM_VERSION_3_8) AU.addRequired<AAResultsWrapperPass>(); #else AU.addRequired<AliasAnalysis>(); #endif And I am passing AliasAnalysis to the function as follow: #if defined(DDP_LLVM_VERSION_3_8) foo(*F,getAnalysis<AAResultsWrapperPass>().getAAResults()); #else foo(*F,getAnalysis<AliasAnalysis>()); #endif Function declaration is as follow:

LLVM error accessing loopinfo in function pass

喜欢而已 提交于 2020-01-14 03:50:12
问题 I'm trying to get loop information from IR by writing a function pass. So I followed some examples and wrote like following. I'm not very familiar with writing passes and pass managers. #include <iostream> #include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Function.h" #include "llvm/BasicBlock.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Support/IRReader.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Analysis/LoopInfo.h"

How to implement arrays - llvm

心不动则不痛 提交于 2020-01-06 05:25:22
问题 I am working on a toy language written using the llvm c++ api and I am trying to implement arrays. I have tried several different things none of which have worked very well. Here is what I am going for: A type that can resemble an array (struct, vector or array would work) Can be passed to and returned from functions Can have infinitely nested arrays (eg. [8 x [8 x [8 x [...] ) Can be re-assignable Arrays are all of the same type Arrays are of finite length specified on creation. Ideally,

Filling the LLVM CloneFunction VMAP

五迷三道 提交于 2020-01-06 02:24:29
问题 I want to write some code that, given an LLVM function F, creates an exact copy in the same module (so the copy can be manipulated later while preserving the original). I want to do this with the CloneFunctionInto method. My current attempt involves trying to insert each (new arg,old arg) pair into the VMap. Previously I've tried inserting an uninitialised VMap and putting the pair the other way round. Impressively, all 3 have resulted in the exact same error message: Assertion `VMap.count(&I

How to call a JITed LLVM function with unknown type?

女生的网名这么多〃 提交于 2020-01-04 04:19:08
问题 I am implementing a front-end for a JIT compiler using LLVM. I started by following the Kaleidoscope example in the LLVM tutorial. I know how to generate and JIT LLVM IR using the LLVM C++ API. I also know how to call the JITed function, using the "getPointerToFunction" method of llvm::ExecutionEngine. getPointerToFunction returns a void* which I must then cast to the correct function type. For example, in my compiler I have unit test that looks like the following: void* compiled_func =

What's the difference between “ModulePassManagers”, “FunctionPassManager” and “BasicBlockPassManagers” in LLVM?

前提是你 提交于 2019-12-24 16:07:43
问题 What's the difference between "ModulePassManagers", "FunctionPassManager" and "BasicBlockPassManagers" in LLVM? And, does "FunctionPassManager" can only be used on "function" type in LLVM-IR? 回答1: LLVM IR is subdivided into different units. The different units of LLVM IR are as follows Modules Functions Basic blocks Instructions A module consists of functions that are in turn made up of different basic blocks that contain a sequence of instructions. The different pass managers operate on