llvm-c++-api

LLVM. How to access to struct fields based on their names?

安稳与你 提交于 2019-12-18 13:34:42
问题 I have little example code in C++: struct RecordTest { int value1; int value2; }; void test() { RecordTest rt; rt.value1 = 15; rt.value2 = 75; } and LLVM 3.4 IR for it: %struct.RecordTest = type { i32, i32 } ; Function Attrs: nounwind define void @_Z4testv() #0 { entry: %rt = alloca %struct.RecordTest, align 4 %value1 = getelementptr inbounds %struct.RecordTest* %rt, i32 0, i32 0 store i32 15, i32* %value1, align 4 %value2 = getelementptr inbounds %struct.RecordTest* %rt, i32 0, i32 1 store

How to do type checking with the LLVM C++ API?

夙愿已清 提交于 2019-12-13 04:18:13
问题 I've just started learning the LLVM C++ API, and I'm a bit confused about how to do type checking. There's an example my instructor has provided to me about storing a variable in stack memory as follows: llvm::AllocaInst *Alloca; Alloca = llvm::Builder.CreateAlloca(llvm::IntegerType::get(getGlobalContext(), 32), nullptr, "variable_name"); I understand this, but in the next part it talks about type checking before assigning a value to a variable. To assign a value in a Decaf statement of the

Compiling C++ on the fly: clang/libtooling fails to set Triple for LLVM IR

跟風遠走 提交于 2019-12-12 12:16:48
问题 Let's say I want to compile a C++ string on the fly: llvm::LLVMContext context; std::unique_ptr<clang::CodeGenAction> action = std::make_unique<clang::EmitLLVMOnlyAction>(&context); clang::tooling::runToolOnCode/*WithArgs*/(action.get(), "int foo(int x){ return ++x;}"); std::unique_ptr<llvm::Module> module = action->takeModule(); Unfortunately, it seems that when LLVM tries to transform the IR, there is an exception saying that the Triple is not set (https://clang.llvm.org/docs

How to get variable definition line number etc. using dbg metadata?

纵然是瞬间 提交于 2019-12-11 14:36:48
问题 As far as I know, when I need to get the line number of a local variable I had to look for the invocation of the llvm.dbg.declare intrinsics and get the dbg metadata(since AllocaInst itself does not contain any dbg info). However there seems no guarantee that this CallInst is the next instruction of the the AllocaInst , and I have to traverse the instruction in a specified function, which is inefficient. So I'm wondering whether there is a method for AllocaInst to get the llvm.dbg.declare

“Attributes.inc” file not found

£可爱£侵袭症+ 提交于 2019-12-11 07:21:22
问题 I have been using the headers provided in include\llvm and include\llvm-c to try and make my own compiler. However, whenever I try to compile, I get this error. There is no llvm/IR/Attributes.inc in my files nor any LLVM project I have seen. I get this error: In file included from ./headers/llvm/IR/Function.h:26: In file included from ./headers/llvm/IR/Argument.h:19: ./headers/llvm/IR/Attributes.h(74,14): fatal error: 'llvm/IR/Attributes.inc' file not found #include "llvm/IR/Attributes.inc"

Getting the memory address of all Objects at runtime in LLVM

大憨熊 提交于 2019-12-11 04:49:27
问题 Is it possible to get Objects' memory address at runtime? For a certain c++ project, is it possible to track all objects' information, including memory address at runtime, lifetime and the counts of load & store? 来源: https://stackoverflow.com/questions/38527218/getting-the-memory-address-of-all-objects-at-runtime-in-llvm

Add LLVM to project using cmake

社会主义新天地 提交于 2019-12-11 02:07:59
问题 I'm trying to add LLVM to a cmake project, using cygwin as a compiler. I downloaded LLVM from cygwin's installer (just installed all of the llvm related packages). The files are there, however I cannot include LLVM in my project. I tried using the official guide for 3.5.2 (the version it installed) and my CMakeLists.txt looks like cmake_minimum_required(VERSION 3.2) project(Lang) find_package(LLVM REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using

LLVM error accessing loopinfo in function pass

心不动则不痛 提交于 2019-12-06 19:42:35
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" #include "llvm/Analysis/LoopPass.h" #include "llvm/Pass.h" #include "llvm/PassManager.h" using

llvm pass: How to insert a variable using existing variable value

蓝咒 提交于 2019-12-06 11:56:14
问题 I defined int a = 5 ; in the source code, and I transform the source to LLVM IR: %a = alloca i32, align 4 store i32 5, i32* %a, align 4 I want to insert int b = a; by writing a pass. I compile int a=5; int b=a into LLVM IR, it load "a" first, then store it. I also checked the doxygen, in which the LoadInst is LoadInst (Value *Ptr, const Twine &NameStr, Instruction *InsertBefore) Still, I don't know how to get the Value of "a". How to get a variable value? 回答1: In LLVM IR the sequence int a =

How to get the filename and directory from a LLVM Instruction?

六眼飞鱼酱① 提交于 2019-12-06 06:50:18
问题 I need to extract the directory and filename during a llvm pass. The current version of llvm moved getFilename and getDirectory from DebugLoc to DebugInfoMetadata . I can't find a class member getFilename directly in the DebugLoc header. Thus, how to do I go from an instruction to source code filename and directory? http://llvm.org/docs/doxygen/html/classllvm_1_1DebugLoc.html Additionally, there is a print function that might help but it only takes a llvm::raw_ostream and can't be redirected