[LLVMdev] How do I get the result of an instruction?
bhavani krishnan
bhavi63 at yahoo.com
Sun Nov 16 07:54:19 PST 2008
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?
Hope this is clear.
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, "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu>
> Cc: "John Criswell" <criswell at uiuc.edu>
> Date: Sunday, November 16, 2008, 6:35 AM
> On Sat, Nov 15, 2008 at 3:58 PM, bhavani krishnan
> <bhavi63 at yahoo.com> wrote:
> > Thanks!
> >
> > How do I cast the result to a string? I basically need
> to store the results of some instructions in a file.
>
> If you're confused about how the IR works,
> http://llvm.org/demo/ can
> be useful. The question you're asking doesn't
> really seem to make
> sense.
>
> -Eli
More information about the llvm-dev
mailing list