I'm new to LLVM and I was wondering if you could help me building a pass to duplicate instructions in LLVM IR, the problem I'm facing is that the cloned instructions couldn't be returned using (user class), is this the correct way to do it ? are there any other ways (excluding this http://ift.tt/1o922hO) My pass:
BasicBlock *B = I->getParent();
if (auto *op = dyn_cast<BinaryOperator>(&*I))
{
auto temp = op->clone();
B->getInstList().insert(op, temp);
temp->setName(op->getName());
if (temp->getOpcode() == Instruction::Add)
{
IRBuilder<> builder(temp); //building the cloned instruction
Value *lhs = temp->getOperand(0);
Value *rhs = temp->getOperand(1);
Value *add1 = builder.CreateAdd(lhs, rhs);
for (auto &v : temp->uses()) {
User *user = v.getUser(); // A User is anything with operands.
user->setOperand(v.getOperandNo(), add1);
}
}
}
Aucun commentaire:
Enregistrer un commentaire