Browse Source

Use common builder in GasMeter and Memory

cl-refactor
Paweł Bylica 10 years ago
parent
commit
b5abb70075
  1. 7
      libevmjit/GasMeter.cpp
  2. 4
      libevmjit/GasMeter.h
  3. 2
      libevmjit/Memory.cpp

7
libevmjit/GasMeter.cpp

@ -169,11 +169,10 @@ void GasMeter::commitCostBlock(llvm::Value* _additionalCost)
assert(m_blockCost == 0);
}
void GasMeter::checkMemory(llvm::Value* _additionalMemoryInWords, llvm::IRBuilder<>& _builder)
void GasMeter::checkMemory(llvm::Value* _additionalMemoryInWords)
{
// Memory uses other builder, but that can be changes later
auto cost = _builder.CreateMul(_additionalMemoryInWords, Constant::get(static_cast<uint64_t>(c_memoryGas)), "memcost");
_builder.CreateCall(m_gasCheckFunc, cost);
auto cost = m_builder.CreateNUWMul(_additionalMemoryInWords, Constant::get(static_cast<uint64_t>(c_memoryGas)), "memcost");
m_builder.CreateCall(m_gasCheckFunc, cost);
}
}

4
libevmjit/GasMeter.h

@ -32,7 +32,7 @@ public:
void giveBack(llvm::Value* _gas);
/// Generate code that checks the cost of additional memory used by program
void checkMemory(llvm::Value* _additionalMemoryInWords, llvm::IRBuilder<>& _builder);
void checkMemory(llvm::Value* _additionalMemoryInWords);
private:
/// Cumulative gas cost of a block of instructions
@ -40,7 +40,7 @@ private:
uint64_t m_blockCost = 0;
llvm::CallInst* m_checkCall = nullptr;
llvm::Function* m_gasCheckFunc;
llvm::Function* m_gasCheckFunc = nullptr;
RuntimeManager& m_runtimeManager;
};

2
libevmjit/Memory.cpp

@ -90,7 +90,7 @@ llvm::Function* Memory::createRequireFunc(GasMeter& _gasMeter, RuntimeManager& _
sizeRequired = m_builder.CreateMul(wordsRequired, Constant::get(32), "roundedSizeReq");
auto words = m_builder.CreateUDiv(currSize, Constant::get(32), "words"); // size is always 32*k
auto newWords = m_builder.CreateSub(wordsRequired, words, "addtionalWords");
_gasMeter.checkMemory(newWords, m_builder);
_gasMeter.checkMemory(newWords);
// Resize
m_builder.CreateStore(sizeRequired, m_size);
auto newData = m_builder.CreateCall2(m_resize, _runtimeManager.getRuntimePtr(), m_size, "newData");

Loading…
Cancel
Save