mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Use common builder in GasMeter and Memory
This commit is contained in:
parent
33cc50d130
commit
b5abb70075
3 changed files with 6 additions and 7 deletions
|
|
@ -169,11 +169,10 @@ void GasMeter::commitCostBlock(llvm::Value* _additionalCost)
|
||||||
assert(m_blockCost == 0);
|
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 = m_builder.CreateNUWMul(_additionalMemoryInWords, Constant::get(static_cast<uint64_t>(c_memoryGas)), "memcost");
|
||||||
auto cost = _builder.CreateMul(_additionalMemoryInWords, Constant::get(static_cast<uint64_t>(c_memoryGas)), "memcost");
|
m_builder.CreateCall(m_gasCheckFunc, cost);
|
||||||
_builder.CreateCall(m_gasCheckFunc, cost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public:
|
||||||
void giveBack(llvm::Value* _gas);
|
void giveBack(llvm::Value* _gas);
|
||||||
|
|
||||||
/// Generate code that checks the cost of additional memory used by program
|
/// 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:
|
private:
|
||||||
/// Cumulative gas cost of a block of instructions
|
/// Cumulative gas cost of a block of instructions
|
||||||
|
|
@ -40,7 +40,7 @@ private:
|
||||||
uint64_t m_blockCost = 0;
|
uint64_t m_blockCost = 0;
|
||||||
|
|
||||||
llvm::CallInst* m_checkCall = nullptr;
|
llvm::CallInst* m_checkCall = nullptr;
|
||||||
llvm::Function* m_gasCheckFunc;
|
llvm::Function* m_gasCheckFunc = nullptr;
|
||||||
|
|
||||||
RuntimeManager& m_runtimeManager;
|
RuntimeManager& m_runtimeManager;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ llvm::Function* Memory::createRequireFunc(GasMeter& _gasMeter, RuntimeManager& _
|
||||||
sizeRequired = m_builder.CreateMul(wordsRequired, Constant::get(32), "roundedSizeReq");
|
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 words = m_builder.CreateUDiv(currSize, Constant::get(32), "words"); // size is always 32*k
|
||||||
auto newWords = m_builder.CreateSub(wordsRequired, words, "addtionalWords");
|
auto newWords = m_builder.CreateSub(wordsRequired, words, "addtionalWords");
|
||||||
_gasMeter.checkMemory(newWords, m_builder);
|
_gasMeter.checkMemory(newWords);
|
||||||
// Resize
|
// Resize
|
||||||
m_builder.CreateStore(sizeRequired, m_size);
|
m_builder.CreateStore(sizeRequired, m_size);
|
||||||
auto newData = m_builder.CreateCall2(m_resize, _runtimeManager.getRuntimePtr(), m_size, "newData");
|
auto newData = m_builder.CreateCall2(m_resize, _runtimeManager.getRuntimePtr(), m_size, "newData");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue