llvm-ir

How get IR value from llvm.dbg.declare

谁说我不能喝 提交于 2019-12-11 13:55:31
问题 Given a llvm.dbg.declare , how can I get its llvm value? e.g. call void @llvm.dbg.declare(metadata !{i32** %r}, metadata !23), !dbg !24 I want get the Value i32** %r , not the metadata !{i32** %r} . Please give me the code! Thanks! 回答1: metadata !{i32** %r} is the 1st operand of the call instruction, and i32** %r is the 1st operand of the metadata. So something like this should work: CallInst I = ... // get the @llvm.dbg.declare call Value* referredValue = cast<MDNode>(I->getOperand(0))-

Method to create LLVM IR

只愿长相守 提交于 2019-12-11 11:42:36
问题 I am creating clang tool and I want to generate LLVM IR from clang AST. I am aware of -emit-llvm option that I can use to get *.ll file, but is there way to generate IR inside code? Some method that I can call that takes clang AST or AST context and returns llvm::Module ? I cannot find any example that shows this. Edited: So I tried using CodeGenAction for this, but I can't get it to work. I end up with unresolved external symbol error. Am I missing something? #include <clang/CodeGen

In LLVM IR, how can I print the name of a unnamed value which is represented as an unsigned numeric value with their prefix such as %2?

☆樱花仙子☆ 提交于 2019-12-11 10:37:57
问题 I want to print out the instructions written in LLVM IR( for practice ) and I have a BitCastInst like this: %0 = bitcast [32xi32]* %reg to i8* How can I print its name of left value which is a unnamed value %0 in this case? 回答1: Those names don't really exist in the in-memory representation of the IR -- there, values just refer to other values using pointers. The names are computed and added to the textual form as it's being written out. This makes sense since transforms are constantly

“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

Compile Haskell programs to LLVM IR

…衆ロ難τιáo~ 提交于 2019-12-11 03:26:40
问题 According to this SO post compilation of Haskell programs to C is no longer (officially) supported. So I wanted to explore the option of compiling Haskell programs to LLVM IR. I chose the same program of the mentioned post: 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])) and then tried to compile it to LLVM IR with: $ ghc -fllvm main.hs Then I get this error

LLVM: Instruction does not dominate all uses

筅森魡賤 提交于 2019-12-11 02:48:01
问题 I'm splitting all Basic Blocks with minimum number of instructions (usually 3-5): llvm::SplitBlock(BasicBlock, &*BasicBlockiter, Pass); and trying to get object file from IR llc -filetype=obj 2.ll I got the following errors: Instruction does not dominate all uses! %1 = alloca i32 %mul = load i32* %1 Instruction does not dominate all uses! %1 = alloca i32 %99 = load i32* %1 and While deleting: i32 % Use still stuck around after Def is destroyed: %var = alloca i32 Assertion failed: use_empty()

Adding support for a memory type similar to __shared__ in CUDA using clang-llvm compiler

◇◆丶佛笑我妖孽 提交于 2019-12-11 00:27:33
问题 I am working towards adding a new memory type similar to __shared__ in CUDA called __noc__ which needs to be compiled using clang-llvm. Following are the steps followed to achieve the parsing for the new memory type taking reference from the answer: Step 1 : In the clangs's Attr.td file (clang/include/clang/Basic/Attr.td), the noc keyword was added similar to shared keyword. def CUDAShared : InheritableAttr { let Spellings = [GNU<"shared">]; let Subjects = SubjectList<[Var]>; let LangOpts =

LLVM-IR syntax folding for Vim

本秂侑毒 提交于 2019-12-10 23:27:09
问题 I am working with LLVM-IR code, generated by clang -emit-llvm and want to get code folding working. So far I am using foldmethod=expr and foldexpr=LLVMFold() . I would like to use syntax based folding (i.e. foldmethod=syntax ) using the syntax file from the llvm repository. Available here. Note that the first regex is from the syntax file for the label. function! LLVMFolds() let thisline = getline(v:lnum) if match(thisline, '^[-a-zA-Z$._][-a-zA-Z$._0-9]*:') >= 0 return ">2" elseif match