Browse Source

Eliminate dead instructions replaced in AP arithmetic lowering.

cl-refactor
Paweł Bylica 10 years ago
parent
commit
03ea86c855
  1. 28
      evmjit/libevmjit/Optimizer.cpp

28
evmjit/libevmjit/Optimizer.cpp

@ -54,27 +54,32 @@ bool LowerEVMPass::runOnBasicBlock(llvm::BasicBlock& _bb)
{
auto modified = false;
auto module = _bb.getParent()->getParent();
for (auto&& inst : _bb)
{
if (inst.getOpcode() == llvm::Instruction::Mul)
for (auto it = _bb.begin(); it != _bb.end(); )
{
auto& inst = *it++;
llvm::Function* func = nullptr;
if (inst.getType() == Type::Word)
{
auto call = llvm::CallInst::Create(Arith256::getMulFunc(*module), {inst.getOperand(0), inst.getOperand(1)}, "", &inst);
inst.replaceAllUsesWith(call);
modified = true;
switch (inst.getOpcode())
{
case llvm::Instruction::Mul:
func = Arith256::getMulFunc(*module);
break;
case llvm::Instruction::UDiv:
func = Arith256::getUDiv256Func(*module);
break;
}
}
else if (inst.getOpcode() == llvm::Instruction::UDiv)
{
if (inst.getType() == Type::Word)
if (func)
{
auto call = llvm::CallInst::Create(Arith256::getUDiv256Func(*module), {inst.getOperand(0), inst.getOperand(1)}, "", &inst);
auto call = llvm::CallInst::Create(func, {inst.getOperand(0), inst.getOperand(1)}, "", &inst);
inst.replaceAllUsesWith(call);
inst.eraseFromParent();
modified = true;
}
}
}
return modified;
}
@ -90,7 +95,6 @@ bool prepare(llvm::Module& _module)
auto pm = llvm::legacy::PassManager{};
pm.add(llvm::createDeadCodeEliminationPass());
pm.add(new LowerEVMPass{});
pm.add(llvm::createDeadInstEliminationPass()); // Remove leftovers
return pm.run(_module);
}

Loading…
Cancel
Save