bhavani krishnan
2008-Nov-17 04:25 UTC
[LLVMdev] How do I get the result of an instruction?
ok. I think I get it now. I need to create the instructions as you have given. For eg: I could pass Instruction*(for storing the result of this instruction) while creating the store instruction. This is what you meant rite?? Thanks, Bhavani --- On Mon, 11/17/08, bhavani krishnan <bhavi63 at yahoo.com> wrote:> From: bhavani krishnan <bhavi63 at yahoo.com> > Subject: Re: [LLVMdev] How do I get the result of an instruction? > To: "Eli Friedman" <eli.friedman at gmail.com> > Cc: "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu>, "John Criswell" <criswell at uiuc.edu> > Date: Monday, November 17, 2008, 4:20 AM > Thanks Eli! > But I still have a question. What you have written is in > IR. When I am writing the pass, I donot have access to the > result of the instruction (%resulttoprint in your > example). All I have is a Instruction* right? So, how do I > get the result of the instruction? Am I missing something > here? > > Thanks, > Bhavani > > > > --- On Sun, 11/16/08, Eli Friedman > <eli.friedman at gmail.com> wrote: > > > From: Eli Friedman <eli.friedman at gmail.com> > > Subject: Re: [LLVMdev] How do I get the result of an > instruction? > > To: bhavi63 at yahoo.com > > Cc: "LLVM Developers Mailing List" > <llvmdev at cs.uiuc.edu>, "John Criswell" > <criswell at uiuc.edu> > > Date: Sunday, November 16, 2008, 9:22 PM > > On Sun, Nov 16, 2008 at 7:54 AM, bhavani krishnan > > <bhavi63 at yahoo.com> wrote: > > > Hi, > > > > > > I am writing an optimization pass where I need to > > instrument the code such that I need to store the > results of > > some instructions in file. Using llc -march=cpp option > I > > figured out how to add a function(say writeToFile) > which > > takes char* parameter and writes to file. Now, I need > put in > > a CallInst which calls writeToFile passing the > Instruction > > result as parameter. How do I do this? > > > > > > So, in my optimization pass... > > > Func *myprint = makewriteToFile() //creates a > function > > which writes to file > > > for (Function::iterator i = func->begin(), e > > func->end(); i != e; ++i) > > > { > > > blk=i; > > > for (BasicBlock::iterator j > blk->begin(), > > k = blk->end(); j != k; ++j){ > > > Instruction *inst = j; > > > //if inst satisfies my condition, > write > > reults to file > > > CallInst *CallPrint > > CallInst::Create(myprint, ???, "", j); > > > CallPrint->setTailCall(true); > > > } > > > } > > > What do I put in the ???. How do I cast > Instruction > > *inst into char * which can be passed into the > function? > > > > Well, you can do something like the following: > > define i32 @f() nounwind { > > entry: > > %x = alloca i32 > > %resulttoprint = call i32 (...)* @a() nounwind > > ;start instrumentation > > store i32 %resulttoprint, i32* %x, align 4 > > %x1 = bitcast i32* %x to i8* > > call void @print(i8* %x1) nounwind > > ;end instrumentation > > ret i32 %resulttoprint > > } > > > > That said, you might need to do something that's > aware > > of the type of > > the result; printing a value in human-readable form > > requires calling > > something like printf. > > > > -Eli
On Sun, Nov 16, 2008 at 8:25 PM, bhavani krishnan <bhavi63 at yahoo.com> wrote:> ok. I think I get it now. I need to create the instructions as you have given. For eg: I could pass Instruction*(for storing the result of this instruction) while creating the store instruction. This is what you meant rite??I think so. The Instrruction* is the value in this context. -Eli
Apparently Analagous Threads
- [LLVMdev] Assertion `InReg && "Value not in map!"' failed
- [LLVMdev] Assertion `InReg && "Value not in map!"' failed
- [LLVMdev] Assertion `castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"' failed.
- [LLVMdev] Assertion `InReg && "Value not in map!"' failed
- [LLVMdev] How do I get the result of an instruction?