llvm

clang-analyzer-alpha.unix.PthreadLock check missing from clang-tidy version 3.8 and 4.0?

£可爱£侵袭症+ 提交于 2019-12-12 02:33:07
问题 I am trying to modernize my module's C++ source code using clang-tidy. A few weeks ago, I downloaded and built clang and clang tools version 3.9 and when I ran it on one of my cpp files I got clang-analyzer-alpha.unix.PthreadLock saying that lock has already been taken. Later, because of space constraints I removed that version of clang and used version 3.8 and 4.0 available in our 3rd party repos. In both of these versions, I did not get any warnings regarding this alpha check. How do I

LLVM Error When Using a Pass from Another Pass

匆匆过客 提交于 2019-12-12 01:52:58
问题 Here is my LLVM Pass: #include <llvm/IR/Function.h> #include <llvm/Pass.h> #include <llvm/Support/raw_ostream.h> #include <llvm/Analysis/MemoryDependenceAnalysis.h> using namespace llvm; namespace { struct MemDepend : public FunctionPass { static char ID; MemDepend() : FunctionPass(ID){} virtual bool runOnFunction(Function &F) { MemoryDependenceAnalysis *MDA = &getAnalysis<MemoryDependenceAnalysis>(); return false; } virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(

Haskell LLVM Binding linker error

走远了吗. 提交于 2019-12-12 01:49:48
问题 update: I'm now on LLVM 2.9 with binding llvm-0.9.1.2 running on ghc 7.0.4 and I'm down to just one of these errors: /home/jfmiller28/.cabal/lib/llvm-0.9.1.2/ghc-7.0.4/libHSllvm-0.9.1.2.a(Scalar.o): In function `sm03_info': (.text+0x24d): undefined reference to `LLVMAddLoopIndexSplitPass' collect2: ld returned 1 exit status I am getting the following linker error for the haskell LLVM bindings: Linking llvm ... /home/jfmiller28/.cabal/lib/llvm-0.9.0.1/ghc-6.12.3/libHSllvm-0.9.0.1.a(Core.o): In

Size of types in LLVM

若如初见. 提交于 2019-12-12 01:47:41
问题 We are currently building a compiler in Java that uses LLVM as intermediate code representation. We use several types and we need to allocate memory for them, using malloc for instance. I would like to know how to compute the size that elements will need in memory: pointers, structures, ... I know that we can use DataLayout if we use the LLVM API, but unfortunately we don't use it and we generate LLVM code "by hand" (mainly because we were not able to find a decent and easy to use Java

Determining and setting host target triple and instruction extensions in LLVM-C API

▼魔方 西西 提交于 2019-12-12 01:43:10
问题 The following lengthy C program generates a simple LLVM module containing a function that merely calls llvm.x86.sse41.round.ps . It emits the bitcode file and then runs the code generated by LLVM. My question is how do I find out target triple and instruction extensions like SSE or AVX of the host machine and how do I add this information to the LLVM module or how do I otherwise tell it to the LLVM execution engine. Here is, what I do: $ cat ctest/avx-instruction-selection.c #include <llvm-c

Count number of arrays

蓝咒 提交于 2019-12-12 00:13:23
问题 How can the total number of arrays be counted in a C program ? The array declarations in LLVM IR correspond to alloca type of operation. So int a[10]; corresponds to %a = alloca [10 x i32], align 4 in LLVM IR. But I also noticed that int j = 0; also corresponds to an alloca instruction %j = alloca i32, align 4 So how to count the number of alloca instructions that correspond only to arrays ? EDIT: for (Function::iterator i = F.begin(), e = F.end(); i != e; ++i) { for (BasicBlock::iterator ii

Convert constant Double to Int in llvm IR

有些话、适合烂在心里 提交于 2019-12-11 23:24:49
问题 Given the following IR, %1 = call double @llvm.pow.f64(double %conv, double 9.000000e+00) when the fraction part of second argument is zero, I want to get it(second argument) in int type. Can someone please suggest a method for this conversion? Thank you in advance. 回答1: There are conversion instructions for this: fptoui fptosi EDIT: If you wish to convert llvm::ConstantFP , you can call getValueAPF() method, which would return you llvm::APFloat . See documentation on how to convert llvm:

Incorrect LLVM alias analysis

孤街醉人 提交于 2019-12-11 21:31:41
问题 I'm asking a question similar to this post about an LLVM alias analysis that seems to give incorrect results. Since it contains considerable re-writing, I have decided to post it as a separate question. I'm running this very simple code: char *foo() { int i; int size; char *s=malloc(5); char *p=malloc(8); while ((i < size) && (s < p)) { i--; } return NULL; } Every time my code runs into an icmp instruction, I ask whether its operands can be aliases of one another. For the first comparison it

Llvm Remove Terminator Instruction

走远了吗. 提交于 2019-12-11 20:46:51
问题 I want to remove an UnreachableInst since a previous transformation has made it reachable. However, calling eraseFromParent() gives me a malformed BasicBlock since the UnreachableInst is the terminator of its BasicBlock. How do I fix the BasicBlock to terminate at the instruction previous to the UnreachableInst? 回答1: Every basic block must end with a terminator. I think that the most straightforward way to remove the unreachable instruction, then, is to replace it with another terminator -

How to fix segmentation fault in genrated llvm bytecode?

我们两清 提交于 2019-12-11 17:57:50
问题 I'm currently working on a compiler using llvm, and it generates this code, which produces a segfault at the last dtore instruction of the case_body block of the test.main$v function. I'm not an expert in debugging manually in general and am especially a beginner with gdb etc. If someone could point out what grave error I've made here I'd be very grateful! ; ModuleID = 'test.bc' source_filename = "test" %test.Node = type { i32, %test.OptionalNode } %test.OptionalNode = type { i8, [8 x i8] }