llvm

In LLVM IR, I want to copy a set of Instructions and paste those instructions to another place in IR through LLVM pass. How to do this?

柔情痞子 提交于 2019-12-04 12:20:45
I want to copy these set of instructions from one part and paste to that in another part in IR %0 = load i32, i32* @x, align 4 %1 = load i32, i32* @y, align 4 %add = add nsw i32 %0, %1 %2 = load i32, i32* @n, align 4 %cmp = icmp slt i32 %add, %2 %conv = zext i1 %cmp to i32 Assuming you are using C++ API, you will just have to clone each instruction separately while fixing references between them. Something like the following: llvm::ValueToValueMapTy vmap; for (auto *inst: instructions_to_clone) { auto *new_inst = inst->clone(); new_inst->insertBefore(insertion_pos); vmap[inst] = new_inst; llvm

Debugging with Clang

╄→гoц情女王★ 提交于 2019-12-04 12:04:20
I'd like to use clang on my Xcode iPhone project. However this is the getting started guide: http://clang.llvm.org/get_started.html I've been working with Xcode for a year but this is far far far from being understandable to me! Can anyone explain in plain english how to install and use Clang with my existing iPhone project? I am not familiar with loading things from the console. Thanks! Dan Ben Gottlieb Nikita Zhuk has wrapped Clang in a GUI and made it available at http://www.karppinen.fi/analysistool/ . Very useful. Download and extract the clang distribution to some directory. Optionally

LLVM translation unit

我是研究僧i 提交于 2019-12-04 11:43:46
I try to understand LLVM program high level structure. I read in the book that " programs are composed of modules ,each of which correspons to tranlation unit ".Can someone explain me in more details the above and what is the diffrenece between modules and translation units(if any). I am also interested to know which part of the code is called when translation unit starts and completes debugging information encoding? Translation unit is term from language standard. For example, this is from C (c99 iso draft) 5.1 Conceptual models; 5.1.1 Translation environment; 5.1.1.1 Program structure A C

@autoreleasepool semantics

假装没事ソ 提交于 2019-12-04 11:28:23
问题 I was reading the ARC docs on the llvm site: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool ..in particular about @autoreleasepool. In lot of current implementation using NSAutoreleasePool, I see cases where the pool is drained periodically during a loop iteration - how do we do the same with @autorelease pool, or is it all done for us somehow under the hood? Secondly, the docs state that if an exception is thrown, the pool isn't drained.... ok exceptions are by

running x86 program _on_ llvm

梦想与她 提交于 2019-12-04 11:24:18
问题 Is it possible to use llvm to run x86 programs? I.e. I want to use llvm as an x86 simulator to run x86 programs and then instrument the x86 program. Thanks! 回答1: I think you are looking for LibCPU. It has an x86 frontend (well, actually only 8086 at the moment, and that is not even complete, but they're working on it), and since it is built on top of LLVM, it obviously also has an x86 backend, thus making it possible to run x86-on-x86 but passing it through LLVM's optimization,

Print arguments of a function using Clang AST

时光毁灭记忆、已成空白 提交于 2019-12-04 11:23:09
问题 I want to get the arguments passed to a function. for example, if I have the call printf("%d%d", i, j); the output should be %d%d i j I am able to get to function calls using VisitCallExpr() in RecursiveASTVisitor. Also able to get the number of arguments and the argument types. But I don't know how to get the arguments. bool MyRecursiveASTVisitor::VisitCallExpr (clang::CallExpr *E) { for(int i=0, j=E->getNumArgs(); i<j; i++) { llvm::errs() << "argType: " << E->getArg(i)->getType()

Alias Analysis in LLVM

家住魔仙堡 提交于 2019-12-04 10:59:55
I am trying to find the alias between a store instruction's pointer operand and function arguments. This is the code, virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequiredTransitive<AliasAnalysis>(); AU.addPreserved<AliasAnalysis>(); } virtual bool runOnFunction(Function &F) { AliasAnalysis &AA = getAnalysis<AliasAnalysis>(); for(Function::iterator i=F.begin();i!=F.end();++i){ for(BasicBlock::iterator j=i->begin();j!=i->end();++j) { if(dyn_cast<StoreInst>(j)){ const StoreInst *SI=dyn_cast<StoreInst>(j); AliasAnalysis::Location LocA = AA.getLocation(SI); const Value *si_v= SI-

Print the type of a parameter (ParmVarDecl) with clang API

倖福魔咒の 提交于 2019-12-04 10:25:58
问题 I need to print the type of a parameter in a C++ source file using the clang API. If I have a parameter representation in clang ( ParmVarDecl* param ) I can print the name of the parameter using param->getNameAsString() . I would need a method param->getTypeAsString() , but there is no such method. So is there another way to do this task? 回答1: Got the answer to my question in the llvm irc: There is a method std::string clang::QualType::getAsString(SplitQualType split) So this does work for me

How can I get Function Name of indirect call from CallInst in LLVM

早过忘川 提交于 2019-12-04 10:18:36
Function *fun = call->getCalledFunction(); getCalledFunction(); returns null if it's indirect call. How can I get the name of the function or the name of the pointer? I found all questions in Stack Overflow related to this issue talked about function name of direct call, or type of pointer. I just want to track cases like this one: void foo(){} void goo(){} void main(){ int x = 1; void (*p)(); if(x) p = &foo; else p = &goo; p(); // print the called function name } firefroge I get the same problem. Here is my solution after reading the llvm source code: Function* fp = CI->getCalledFunction();

Is anyone able to get the Address-Sanitizer (known as asan or -fsanitize=address) working on iOS?

陌路散爱 提交于 2019-12-04 10:17:48
Address-Sanitizer https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer I have compile my own llvm (pretty straight forward compiling) because apple's llvm not support this function. I have tested the clang for mac command line program, it works (but without showing the line the sourcecode). for iOS, there is still some problems: compile simulator version : report error for pre-compiled header: In file included from /Users/fluke/Documents/projects/tmp/testAsanNoARC/testAsanNoARC/testAsanNoARC-Prefix.pch:12: In file included from /Applications/Xcode.app/Contents/Developer/Platforms