If you want to eliminate phi instructions, you can try to just use the
reg2mem pass. This will do what you're trying to accomplish here.
On Wed, Jul 18, 2012 at 5:04 PM, ryan baird <ryanrbaird at gmail.com>
wrote:
> I'm working on translating llvm's optimized intermediate code to
another
> compiler's intermediate code, and I'm working on the PHI
instruction.
>
> Here's an example phi instruction to help explain what I'm trying
to do:
> %inc25 = phi i32 [ 1, %entry ], [ %inc, %for.body ]
>
> What I would want to do here is allocate some memory memory (i'm trying
to
> use %phi1 = alloca i32, allign 4 ). Then, I want to go to the %entry block
> and say "store i32 1, i32* %phi1", and in the %for.body I want
to add
> "store i32 1, i32* %phi1".
>
> So first, I'm iterating through my function and basicblock:
> int phi = 0;
> Function::iterator func_bblock_itr = func->begin();
> for(; func_bblock_itr != func->end(); ++func_bblock_itr)
> {
> BasicBlock::iterator bblock_inst_itr = func_bblock_itr->begin();
> for(; bblock_inst_itr != func_bblock_itr->end();
++bblock_inst_itr)
> {
> Then, I look for PHI instructions:
> if(bblock_inst_itr->getOpcode() == Instruction::PHI) {
> If I find one, I allocate space:
> string name = "phi";
> name.insert(3,to_string(phi));
> Twine tname= Twine(name);
> AllocaInst alloca >
AllocaInst(bblock_inst_itr->getOperand(0)->getType(),tname,func_bblock_itr->begin());
> and then i go through the operands one by one to find where to put store
> instructions:
> for(unsigned int i = 0; i <
> bblock_inst_itr->getNumOperands();i++) {
> Value *v = bblock_inst_itr->getOperand(i);
> Here's where I don't know what to do: I want to create a store
instruction
> in that place
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
--
Thanks,
Justin Holewinski
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120718/31cd4bd7/attachment.html>