<div dir="ltr"><div>Hi all,<br><br></div>I have problem with working by Instruction class of LLVM. I wrote the following pass in order to make a copy of binary instructions. But, when I run mypass with opt I face with an aborted error. I also got the same error when I used eraseFromParent() function. It would be a great help if you tell my where is my problem.<br>
<div><div><div><br><div>for (Function::iterator b = F.begin(), be = F.end(); b != be; ++b) {<br> for (BasicBlock::iterator i = b->begin(), ie = b->end(); i != ie; ++i) {<br> if (i->isBinaryOp()) {<br>
errs() << "This instruction is BinaryO, and I want to copy it! " << '\n';<br> Instruction *copyinst= i;<br> Instruction *IA = &* copyinst->clone();<br>
// i->eraseFromParent();<br> }<br> }<br> }<br><br></div><div><b>The output:</b><br>This instruction is BinaryO, and I want to copy it! <br>Instruction referencing instruction not embedded in a basic block!<br>
%indvars.iv = phi i64 [ 0, %.<a href="http://lr.ph">lr.ph</a> ], [ %indvars.iv.next, %.backedge ]<br> <badref> = add i64 %indvars.iv, 1<br>Broken module found, compilation aborted!<br>0 libLLVM-3.4.so.1 0x00007f5c1bc1fd82 llvm::sys::PrintStackTrace(_IO_FILE*) + 34<br>
1 libLLVM-3.4.so.1 0x00007f5c1bc1fb6c<br>2 libc.so.6 0x00007f5c1a69ffb0<br>3 libc.so.6 0x00007f5c1a69ff39 gsignal + 57<br>4 libc.so.6 0x00007f5c1a6a3348 abort + 328<br>5 libLLVM-3.4.so.1 0x00007f5c1b610871<br>
6 libLLVM-3.4.so.1 0x00007f5c1b619933<br>7 libLLVM-3.4.so.1 0x00007f5c1b5f0d77 llvm::FPPassManager::runOnFunction(llvm::Function&) + 471<br>8 libLLVM-3.4.so.1 0x00007f5c1b5f0e0b llvm::FPPassManager::runOnModule(llvm::Module&) + 43<br>
9 libLLVM-3.4.so.1 0x00007f5c1b5f32c5 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 693<br>10 opt-3.4 0x0000000000412c8d main + 2461<br>11 libc.so.6 0x00007f5c1a68aed5 __libc_start_main + 245<br>
12 opt-3.4 0x0000000000413b40<br>Stack dump:<br>0. Program arguments: opt-3.4 -load ../../../Debug+Asserts/lib/Mypass.so -mypass <br>1. Running pass 'Function Pass Manager' on module '<stdin>'.<br>
2. Running pass 'Module Verifier' on function '@main'<br>Aborted (core dumped)<br><br></div><div>Thank you,<br></div><div>Danna<br></div><div><br></div></div></div></div></div>