[llvm-dev] llvm Branch instruction using SplitBlockAndInsertIfThenElse
Yasser NEZZARI via llvm-dev
llvm-dev at lists.llvm.org
Thu Mar 3 03:05:33 PST 2016
Hello everyone,
I'm trying to build an LLVM pass that splits the BasicBlock and make a decision using "SplitBlockAndInsertIfThenElse" every time a binary operation is encountered, however this only allows me to split once (split at the 1st binop). could you please help me make it iterate through all the binop instructions? Knowing that changing the position of "break;" gives me errors when running the pass. same thing happens when I put the "SplitBlockAndInsertIfThenElse" in a nested loop. Here is my code:
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
{
if (auto *op = dyn_cast<BinaryOperator>(&*I))
{
IRBuilder<> Builder(op);
Value *lhs = op->getOperand(0);
Value *rhs = op->getOperand(1);
Value *xpv = Builder.CreateAlloca(llvm::Type::getInt32Ty(llvm::getGlobalContext()), nullptr, "x");
Value *xpv2 = Builder.CreateAlloca(llvm::Type::getInt32Ty(llvm::getGlobalContext()), nullptr, "x2");
Value *add1 = Builder.CreateAdd(lhs, rhs);
Value *add2 = Builder.CreateAdd(lhs, rhs);
Value *icmp1 = Builder.CreateICmpEQ(add1, add2);
TerminatorInst *ThenTerm , *ElseTerm ;
SplitBlockAndInsertIfThenElse(icmp1, op, &ThenTerm, &ElseTerm,nullptr);
Builder.SetInsertPoint(ThenTerm);
Value *xp1 = Builder.CreateStore(add1, xpv);
Builder.SetInsertPoint(ElseTerm);
break ;
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160303/c2126a86/attachment.html>
More information about the llvm-dev
mailing list