llvm-ir

LLVM retrieve name of AllocaInst

徘徊边缘 提交于 2020-07-18 07:35:08
问题 I am trying to retrieve the name of the pointer passed to a cudaMalloc call. CallInst *CUMallocCI = ... ; // CI of cudaMalloc call Value *Ptr = CUMallocCI->getOperand(0); if (AllocaInst *AI = dyn_cast<AllocaInst>(Ptr) != nullptr) { errs() << AI->getName() << "\n"; } The above however just prints an empty line. Is is possible to get the pointer name out of this alloca? This is the relevant IR: %28 = alloca i8*, align 8 ... ... call void @llvm.dbg.declare(metadata i8** %28, metadata !926,

LLVM retrieve name of AllocaInst

a 夏天 提交于 2020-07-18 07:35:08
问题 I am trying to retrieve the name of the pointer passed to a cudaMalloc call. CallInst *CUMallocCI = ... ; // CI of cudaMalloc call Value *Ptr = CUMallocCI->getOperand(0); if (AllocaInst *AI = dyn_cast<AllocaInst>(Ptr) != nullptr) { errs() << AI->getName() << "\n"; } The above however just prints an empty line. Is is possible to get the pointer name out of this alloca? This is the relevant IR: %28 = alloca i8*, align 8 ... ... call void @llvm.dbg.declare(metadata i8** %28, metadata !926,

Is it possible to get LLVM-IR from Assembly file?

我与影子孤独终老i 提交于 2020-05-23 21:43:11
问题 I compiled .S file using command: clang-8 -c funcs.s -o funcs.o -emit-llvm I found, that .o file was generated in ELF format. I was expected to see llvm-ir format (with "BC" characters at the beginning of resulting file). Seems, Clang ignores "-emit-llvm" flag. 回答1: Your question isn't fundamentally different from Is it possible to translate an assembly language to LLVM IR, optimize it and then recompile it to a different architecture?. asm source and binary executables / object files are

How to distinguish signed and unsigned integer in LLVM

允我心安 提交于 2020-04-29 11:48:19
问题 The LLVM project does not distinguish between signed and unsigned integers as described here. There are situations where you need to know if a particular variable should be interpreted as signed or as unsigned though, for instance when it is size extended or when it is used in a division. My solution to this is to keep a separate type information for every variable that describes whether it is an integer or a cardinal type. However, I am wondering, isn't there a way to "attribute" a type in

How to distinguish signed and unsigned integer in LLVM

a 夏天 提交于 2020-04-29 11:48:06
问题 The LLVM project does not distinguish between signed and unsigned integers as described here. There are situations where you need to know if a particular variable should be interpreted as signed or as unsigned though, for instance when it is size extended or when it is used in a division. My solution to this is to keep a separate type information for every variable that describes whether it is an integer or a cardinal type. However, I am wondering, isn't there a way to "attribute" a type in

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,

LLVM IR: expose variables to GDB?

你离开我真会死。 提交于 2020-01-05 17:51:38
问题 I am writing a custom programming language. I am generating LLVM IR as an intermediate (via LLVMlite), and I want to expose variables to GDB. This is an example of the generated IR: ; ModuleID = "tests/debuginfo.xan" source_filename = "debuginfo.xan" target triple = "x86_64-unknown-linux-gnu" target datalayout = "" define void @"main"(i32 %".1", i8** %".2") !dbg !10 { entry: %"$argc" = alloca i32 store i32 %".1", i32* %"$argc" %"$argv" = alloca i8** store i8** %".2", i8*** %"$argv" %"$a" =