Browse Source

Allow creating LLVM constants directly from u256

cl-refactor
Paweł Bylica 10 years ago
parent
commit
56bd2c3411
  1. 5
      libevmjit/GasMeter.cpp
  2. 8
      libevmjit/Type.cpp
  3. 4
      libevmjit/Type.h

5
libevmjit/GasMeter.cpp

@ -126,9 +126,6 @@ void GasMeter::countSStore(Ext& _ext, llvm::Value* _index, llvm::Value* _newValu
{ {
assert(!m_checkCall); // Everything should've been commited before 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 oldValue = _ext.store(_index);
auto oldValueIsZero = m_builder.CreateICmpEQ(oldValue, Constant::get(0), "oldValueIsZero"); auto oldValueIsZero = m_builder.CreateICmpEQ(oldValue, Constant::get(0), "oldValueIsZero");
auto newValueIsZero = m_builder.CreateICmpEQ(_newValue, Constant::get(0), "newValueIsZero"); 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 newValueIsntZero = m_builder.CreateICmpNE(_newValue, Constant::get(0), "newValueIsntZero");
auto isInsert = m_builder.CreateAnd(oldValueIsZero, newValueIsntZero, "isInsert"); auto isInsert = m_builder.CreateAnd(oldValueIsZero, newValueIsntZero, "isInsert");
auto isDelete = m_builder.CreateAnd(oldValueIsntZero, newValueIsZero, "isDelete"); 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"); cost = m_builder.CreateSelect(isDelete, Constant::get(0), cost, "cost");
createCall(m_gasCheckFunc, cost); createCall(m_gasCheckFunc, cost);
} }

8
libevmjit/Type.cpp

@ -41,6 +41,14 @@ llvm::ConstantInt* Constant::get(uint64_t _n)
return llvm::ConstantInt::get(Type::i256, _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) llvm::ConstantInt* Constant::get(ReturnCode _returnCode)
{ {
return llvm::ConstantInt::get(Type::MainReturn, static_cast<uint64_t>(_returnCode)); return llvm::ConstantInt::get(Type::MainReturn, static_cast<uint64_t>(_returnCode));

4
libevmjit/Type.h

@ -3,6 +3,7 @@
#include <llvm/IR/Type.h> #include <llvm/IR/Type.h>
#include <llvm/IR/Constants.h> #include <llvm/IR/Constants.h>
#include <libdevcore/Common.h>
namespace dev namespace dev
{ {
@ -50,7 +51,8 @@ enum class ReturnCode
struct Constant struct Constant
{ {
/// Returns word-size 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); static llvm::ConstantInt* get(ReturnCode _returnCode);
}; };

Loading…
Cancel
Save