mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Allow creating LLVM constants directly from u256
This commit is contained in:
parent
33f1253bbe
commit
e6b4761765
3 changed files with 12 additions and 5 deletions
|
|
@ -126,9 +126,6 @@ void GasMeter::countSStore(Ext& _ext, llvm::Value* _index, llvm::Value* _newValu
|
|||
{
|
||||
assert(!m_checkCall); // Everything should've been commited before
|
||||
|
||||
static const auto updateCost = static_cast<uint64_t>(c_sstoreResetGas); // TODO: Discuss naming (DB names look better)
|
||||
static const auto insertCost = static_cast<uint64_t>(c_sstoreSetGas);
|
||||
|
||||
auto oldValue = _ext.store(_index);
|
||||
auto oldValueIsZero = m_builder.CreateICmpEQ(oldValue, Constant::get(0), "oldValueIsZero");
|
||||
auto newValueIsZero = m_builder.CreateICmpEQ(_newValue, Constant::get(0), "newValueIsZero");
|
||||
|
|
@ -136,7 +133,7 @@ void GasMeter::countSStore(Ext& _ext, llvm::Value* _index, llvm::Value* _newValu
|
|||
auto newValueIsntZero = m_builder.CreateICmpNE(_newValue, Constant::get(0), "newValueIsntZero");
|
||||
auto isInsert = m_builder.CreateAnd(oldValueIsZero, newValueIsntZero, "isInsert");
|
||||
auto isDelete = m_builder.CreateAnd(oldValueIsntZero, newValueIsZero, "isDelete");
|
||||
auto cost = m_builder.CreateSelect(isInsert, Constant::get(insertCost), Constant::get(updateCost), "cost");
|
||||
auto cost = m_builder.CreateSelect(isInsert, Constant::get(c_sstoreSetGas), Constant::get(c_sstoreResetGas), "cost");
|
||||
cost = m_builder.CreateSelect(isDelete, Constant::get(0), cost, "cost");
|
||||
createCall(m_gasCheckFunc, cost);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,14 @@ llvm::ConstantInt* Constant::get(uint64_t _n)
|
|||
return llvm::ConstantInt::get(Type::i256, _n);
|
||||
}
|
||||
|
||||
llvm::ConstantInt* Constant::get(u256 _n)
|
||||
{
|
||||
auto limbs = _n.backend().limbs();
|
||||
auto words = reinterpret_cast<uint64_t*>(limbs);
|
||||
llvm::APInt n(256, 4, words);
|
||||
return static_cast<llvm::ConstantInt*>(llvm::ConstantInt::get(Type::i256, n));
|
||||
}
|
||||
|
||||
llvm::ConstantInt* Constant::get(ReturnCode _returnCode)
|
||||
{
|
||||
return llvm::ConstantInt::get(Type::MainReturn, static_cast<uint64_t>(_returnCode));
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <llvm/IR/Type.h>
|
||||
#include <llvm/IR/Constants.h>
|
||||
#include <libdevcore/Common.h>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
|
@ -50,7 +51,8 @@ enum class ReturnCode
|
|||
struct Constant
|
||||
{
|
||||
/// Returns word-size constant
|
||||
static llvm::ConstantInt* get(uint64_t _n); // TODO: add overload with u256
|
||||
static llvm::ConstantInt* get(uint64_t _n);
|
||||
static llvm::ConstantInt* get(u256 _n);
|
||||
|
||||
static llvm::ConstantInt* get(ReturnCode _returnCode);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue