(original) (raw)

Hi John,

I really appreciate your reply. Right now, I write some programming like CloneBasicBlock(), it works.

Thanks,
Yuxi

From: John Criswell \[jtcriswel@gmail.com\]
Sent: Sunday, July 12, 2015 11:59 AM
To: Yuxi Chen; llvmdev@cs.uiuc.edu
Cc: llvmdev-bounces@cs.uiuc.edu
Subject: Re: \[LLVMdev\] instructions copy

Dear Yuxi,

I haven't used the clone() method of the Instruction class, but if I had to guess, the problem is that you're not changing the operands of the new instructions to reference the new instructions. When you clone an instruction, the operands of the new instruction are identical to the operands of the old instruction.

In your example, if you clone the store, the store is still referencing %1 from the original LoadInst in the original basic block. You need to change the new store's operand to be the new LoadInst that you created in your new BasicBlock.

You may also want to look at the llvm::CloneBasicBlock() function. This utility function clones basic blocks; you can take a look at what it does and see how it works.

Regards,

John Criswell

On 7/11/15 6:13 PM, Yuxi Chen wrote:
Hi,

I want to copy some dependent statements, like a = b, b = c, from one basicblock to another basicblocks.
Because of SSA, a = b, will be like %1 = load %b, store %1, %a.
If I just use clone() method in Instruction class, it will be like = load %b, store , %a.
If I need remap the virtual registers, this map just will affect the whole module? And how to use it? I am a bit confused.

Any suggestion will be appreciated.

Best,
Yuxi
Uchicago


\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
LLVM Developers mailing list  
LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu  
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev  


--   
John Criswell  
Assistant Professor  
Department of Computer Science, University of Rochester  
http://www.cs.rochester.edu/u/criswell