1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
Twine * var4 = new Twine("condition"); FCmpInst * condition = new FCmpInst(*basicBlock, FCmpInst::FCMP_TRUE , LHS, RHS, *var4);
BranchInst::Create(originalBB, alteredBB, (Value *)condition, basicBlock);
BranchInst::Create(originalBB, alteredBB);
BasicBlock::iterator i = originalBB->end(); Twine * var5 = new Twine("originalBBpart2"); BasicBlock * originalBBpart2 = originalBB->splitBasicBlock(--i , *var5);
originalBB->getTerminator()->eraseFromParent();
Twine * var6 = new Twine("condition2"); FCmpInst * condition2 = new FCmpInst(*originalBB, CmpInst::FCMP_TRUE , LHS, RHS, *var6);
BranchInst::Create(originalBBpart2, alteredBB, (Value *)condition2, originalBB);
Twine *varX = new Twine("x"); Twine *varY = new Twine("y"); Value *x1 = ConstantInt::get(Type::getInt32Ty(M.getContext()), 0, false); Value *y1 = ConstantInt::get(Type::getInt32Ty(M.getContext()), 0, false);
for (Module::iterator mi = M.begin(), me = M.end(); mi != me; ++mi) { for (Function::iterator fi = mi->begin(), fe = mi->end(); fi != fe; ++fi) { TerminatorInst *tbb = fi->getTerminator(); if (tbb->getOpcode() == Instruction::Br) { if (cond->getPredicate() == FCmpInst::FCMP_TRUE) { toDelete.push_back(cond); toEdit.push_back(tbb); } } } }
for (std::vector<Instruction *>::iterator i = toEdit.begin(); i != toEdit.end(); ++i) { opX = new LoadInst((Value *)x, "", (*i)); opY = new LoadInst((Value *)y, "", (*i));
op = BinaryOperator::Create(Instruction::Sub, (Value *)opX, ConstantInt::get(Type::getInt32Ty(M.getContext()), 1, false), "", (*i)); op1 = BinaryOperator::Create(Instruction::Mul, (Value *)opX, op, "", (*i)); op = BinaryOperator::Create(Instruction::URem, op1, ConstantInt::get(Type::getInt32Ty(M.getContext()), 2, false), "", (*i)); condition = new ICmpInst((*i), ICmpInst::ICMP_EQ, op, ConstantInt::get(Type::getInt32Ty(M.getContext()), 0, false)); condition2 = new ICmpInst((*i), ICmpInst::ICMP_SLT, opY, ConstantInt::get(Type::getInt32Ty(M.getContext()), 10, false)); op1 = BinaryOperator::Create(Instruction::Or, (Value *)condition, (Value *)condition2, "", (*i));
BranchInst::Create(((BranchInst *)*i)->getSuccessor(0), ((BranchInst *)*i)->getSuccessor(1), (Value *)op1, ((BranchInst *)*i)->getParent()); (*i)->eraseFromParent(); }
|