Browse Source

Rename Type::i256 -> Type::Word

cl-refactor
Paweł Bylica 10 years ago
parent
commit
23c7da66fa
  1. 8
      libevmjit/Arith256.cpp
  2. 2
      libevmjit/BasicBlock.cpp
  3. 20
      libevmjit/Compiler.cpp
  4. 4
      libevmjit/Endianness.cpp
  5. 4
      libevmjit/GasMeter.cpp
  6. 26
      libevmjit/Memory.cpp
  7. 2
      libevmjit/Runtime.cpp
  8. 2
      libevmjit/Stack.cpp
  9. 10
      libevmjit/Type.cpp
  10. 2
      libevmjit/Type.h

8
libevmjit/Arith256.cpp

@ -18,10 +18,10 @@ Arith256::Arith256(llvm::IRBuilder<>& _builder) :
{
using namespace llvm;
m_result = m_builder.CreateAlloca(Type::i256, nullptr, "arith.result");
m_arg1 = m_builder.CreateAlloca(Type::i256, nullptr, "arith.arg1");
m_arg2 = m_builder.CreateAlloca(Type::i256, nullptr, "arith.arg2");
m_arg3 = m_builder.CreateAlloca(Type::i256, nullptr, "arith.arg3");
m_result = m_builder.CreateAlloca(Type::Word, nullptr, "arith.result");
m_arg1 = m_builder.CreateAlloca(Type::Word, nullptr, "arith.arg1");
m_arg2 = m_builder.CreateAlloca(Type::Word, nullptr, "arith.arg2");
m_arg3 = m_builder.CreateAlloca(Type::Word, nullptr, "arith.arg3");
using Linkage = GlobalValue::LinkageTypes;

2
libevmjit/BasicBlock.cpp

@ -171,7 +171,7 @@ llvm::Value* BasicBlock::LocalStack::get(size_t _index)
assert(m_initialStack[initialIdx] == nullptr);
// Create a dummy value.
std::string name = "get_" + boost::lexical_cast<std::string>(_index);
m_initialStack[initialIdx] = m_builder.CreatePHI(Type::i256, 0, name);
m_initialStack[initialIdx] = m_builder.CreatePHI(Type::Word, 0, name);
*itemIter = m_initialStack[initialIdx];
}

20
libevmjit/Compiler.cpp

@ -376,7 +376,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto lhs = stack.pop();
auto rhs = stack.pop();
auto res1 = m_builder.CreateICmpULT(lhs, rhs);
auto res256 = m_builder.CreateZExt(res1, Type::i256);
auto res256 = m_builder.CreateZExt(res1, Type::Word);
stack.push(res256);
break;
}
@ -386,7 +386,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto lhs = stack.pop();
auto rhs = stack.pop();
auto res1 = m_builder.CreateICmpUGT(lhs, rhs);
auto res256 = m_builder.CreateZExt(res1, Type::i256);
auto res256 = m_builder.CreateZExt(res1, Type::Word);
stack.push(res256);
break;
}
@ -396,7 +396,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto lhs = stack.pop();
auto rhs = stack.pop();
auto res1 = m_builder.CreateICmpSLT(lhs, rhs);
auto res256 = m_builder.CreateZExt(res1, Type::i256);
auto res256 = m_builder.CreateZExt(res1, Type::Word);
stack.push(res256);
break;
}
@ -406,7 +406,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto lhs = stack.pop();
auto rhs = stack.pop();
auto res1 = m_builder.CreateICmpSGT(lhs, rhs);
auto res256 = m_builder.CreateZExt(res1, Type::i256);
auto res256 = m_builder.CreateZExt(res1, Type::Word);
stack.push(res256);
break;
}
@ -416,7 +416,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto lhs = stack.pop();
auto rhs = stack.pop();
auto res1 = m_builder.CreateICmpEQ(lhs, rhs);
auto res256 = m_builder.CreateZExt(res1, Type::i256);
auto res256 = m_builder.CreateZExt(res1, Type::Word);
stack.push(res256);
break;
}
@ -425,7 +425,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
{
auto top = stack.pop();
auto iszero = m_builder.CreateICmpEQ(top, Constant::get(0), "iszero");
auto result = m_builder.CreateZExt(iszero, Type::i256);
auto result = m_builder.CreateZExt(iszero, Type::Word);
stack.push(result);
break;
}
@ -465,7 +465,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
value = Endianness::toBE(m_builder, value);
auto bytes = m_builder.CreateBitCast(value, llvm::VectorType::get(Type::Byte, 32), "bytes");
auto byte = m_builder.CreateExtractElement(bytes, byteNum, "byte");
value = m_builder.CreateZExt(byte, Type::i256);
value = m_builder.CreateZExt(byte, Type::Word);
auto byteNumValid = m_builder.CreateICmpULT(byteNum, Constant::get(32));
value = m_builder.CreateSelect(byteNumValid, value, Constant::get(0));
@ -499,7 +499,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto word = stack.pop();
auto k32_ = m_builder.CreateTrunc(idx, m_builder.getIntNTy(5), "k_32");
auto k32 = m_builder.CreateZExt(k32_, Type::i256);
auto k32 = m_builder.CreateZExt(k32_, Type::Word);
auto k32x8 = m_builder.CreateMul(k32, Constant::get(8), "kx8");
// test for word >> (k * 8 + 7)
@ -510,11 +510,11 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto mask_ = m_builder.CreateShl(Constant::get(1), bitpos);
auto mask = m_builder.CreateSub(mask_, Constant::get(1), "mask");
auto negmask = m_builder.CreateXor(mask, llvm::ConstantInt::getAllOnesValue(Type::i256), "negmask");
auto negmask = m_builder.CreateXor(mask, llvm::ConstantInt::getAllOnesValue(Type::Word), "negmask");
auto val1 = m_builder.CreateOr(word, negmask);
auto val0 = m_builder.CreateAnd(word, mask);
auto kInRange = m_builder.CreateICmpULE(idx, llvm::ConstantInt::get(Type::i256, 30));
auto kInRange = m_builder.CreateICmpULE(idx, llvm::ConstantInt::get(Type::Word, 30));
auto result = m_builder.CreateSelect(kInRange,
m_builder.CreateSelect(bittest, val1, val0),
word);

4
libevmjit/Endianness.cpp

@ -15,8 +15,8 @@ namespace jit
llvm::Value* Endianness::bswap(llvm::IRBuilder<>& _builder, llvm::Value* _word)
{
// TODO: Native is Little Endian
assert(_word->getType() == Type::i256);
auto bswap = llvm::Intrinsic::getDeclaration(_builder.GetInsertBlock()->getParent()->getParent(), llvm::Intrinsic::bswap, Type::i256);
assert(_word->getType() == Type::Word);
auto bswap = llvm::Intrinsic::getDeclaration(_builder.GetInsertBlock()->getParent()->getParent(), llvm::Intrinsic::bswap, Type::Word);
return _builder.CreateCall(bswap, _word);
}

4
libevmjit/GasMeter.cpp

@ -84,7 +84,7 @@ GasMeter::GasMeter(llvm::IRBuilder<>& _builder, RuntimeManager& _runtimeManager)
{
auto module = getModule();
m_gasCheckFunc = llvm::Function::Create(llvm::FunctionType::get(Type::Void, Type::i256, false), llvm::Function::PrivateLinkage, "gas.check", module);
m_gasCheckFunc = llvm::Function::Create(llvm::FunctionType::get(Type::Void, Type::Word, false), llvm::Function::PrivateLinkage, "gas.check", module);
InsertPointGuard guard(m_builder);
auto checkBB = llvm::BasicBlock::Create(_builder.getContext(), "Check", m_gasCheckFunc);
@ -113,7 +113,7 @@ void GasMeter::count(Instruction _inst)
if (!m_checkCall)
{
// Create gas check call with mocked block cost at begining of current cost-block
m_checkCall = m_builder.CreateCall(m_gasCheckFunc, llvm::UndefValue::get(Type::i256));
m_checkCall = m_builder.CreateCall(m_gasCheckFunc, llvm::UndefValue::get(Type::Word));
}
m_blockCost += getStepCost(_inst);

26
libevmjit/Memory.cpp

@ -29,7 +29,7 @@ Memory::Memory(RuntimeManager& _runtimeManager, GasMeter& _gasMeter):
RuntimeHelper(_runtimeManager)
{
auto module = getModule();
llvm::Type* argTypes[] = {Type::i256, Type::i256};
llvm::Type* argTypes[] = {Type::Word, Type::Word};
auto dumpTy = llvm::FunctionType::get(m_builder.getVoidTy(), llvm::ArrayRef<llvm::Type*>(argTypes), false);
m_memDump = llvm::Function::Create(dumpTy, llvm::GlobalValue::LinkageTypes::ExternalLinkage,
"evmccrt_memory_dump", module);
@ -37,7 +37,7 @@ Memory::Memory(RuntimeManager& _runtimeManager, GasMeter& _gasMeter):
m_data = new llvm::GlobalVariable(*module, Type::BytePtr, false, llvm::GlobalVariable::PrivateLinkage, llvm::UndefValue::get(Type::BytePtr), "mem.data");
m_data->setUnnamedAddr(true); // Address is not important
m_size = new llvm::GlobalVariable(*module, Type::i256, false, llvm::GlobalVariable::PrivateLinkage, Constant::get(0), "mem.size");
m_size = new llvm::GlobalVariable(*module, Type::Word, false, llvm::GlobalVariable::PrivateLinkage, Constant::get(0), "mem.size");
m_size->setUnnamedAddr(true); // Address is not important
llvm::Type* resizeArgs[] = {Type::RuntimePtr, Type::WordPtr};
@ -47,14 +47,14 @@ Memory::Memory(RuntimeManager& _runtimeManager, GasMeter& _gasMeter):
m_resize->setAttributes(llvm::AttributeSet::get(m_resize->getContext(), 1, attrBuilder));
m_require = createRequireFunc(_gasMeter, _runtimeManager);
m_loadWord = createFunc(false, Type::i256, _gasMeter);
m_storeWord = createFunc(true, Type::i256, _gasMeter);
m_loadWord = createFunc(false, Type::Word, _gasMeter);
m_storeWord = createFunc(true, Type::Word, _gasMeter);
m_storeByte = createFunc(true, Type::Byte, _gasMeter);
}
llvm::Function* Memory::createRequireFunc(GasMeter& _gasMeter, RuntimeManager& _runtimeManager)
{
llvm::Type* argTypes[] = {Type::i256, Type::i256};
llvm::Type* argTypes[] = {Type::Word, Type::Word};
auto func = llvm::Function::Create(llvm::FunctionType::get(Type::Void, argTypes, false), llvm::Function::PrivateLinkage, "mem.require", getModule());
auto offset = func->arg_begin();
offset->setName("offset");
@ -67,9 +67,9 @@ llvm::Function* Memory::createRequireFunc(GasMeter& _gasMeter, RuntimeManager& _
InsertPointGuard guard(m_builder); // Restores insert point at function exit
// BB "check"
// BB "Check"
m_builder.SetInsertPoint(checkBB);
auto uaddWO = llvm::Intrinsic::getDeclaration(getModule(), llvm::Intrinsic::uadd_with_overflow, Type::i256);
auto uaddWO = llvm::Intrinsic::getDeclaration(getModule(), llvm::Intrinsic::uadd_with_overflow, Type::Word);
auto uaddRes = m_builder.CreateCall2(uaddWO, offset, size, "res");
auto sizeRequired = m_builder.CreateExtractValue(uaddRes, 0, "sizeReq");
auto overflow1 = m_builder.CreateExtractValue(uaddRes, 1, "overflow1");
@ -78,7 +78,7 @@ llvm::Function* Memory::createRequireFunc(GasMeter& _gasMeter, RuntimeManager& _
auto resizeNeeded = m_builder.CreateOr(tooSmall, overflow1, "resizeNeeded");
m_builder.CreateCondBr(resizeNeeded, resizeBB, returnBB); // OPT branch weights?
// BB "resize"
// BB "Resize"
m_builder.SetInsertPoint(resizeBB);
// Check gas first
uaddRes = m_builder.CreateCall2(uaddWO, sizeRequired, Constant::get(31), "res");
@ -97,7 +97,7 @@ llvm::Function* Memory::createRequireFunc(GasMeter& _gasMeter, RuntimeManager& _
m_builder.CreateStore(newData, m_data);
m_builder.CreateBr(returnBB);
// BB "return"
// BB "Return"
m_builder.SetInsertPoint(returnBB);
m_builder.CreateRetVoid();
return func;
@ -105,11 +105,11 @@ llvm::Function* Memory::createRequireFunc(GasMeter& _gasMeter, RuntimeManager& _
llvm::Function* Memory::createFunc(bool _isStore, llvm::Type* _valueType, GasMeter&)
{
auto isWord = _valueType == Type::i256;
auto isWord = _valueType == Type::Word;
llvm::Type* storeArgs[] = {Type::i256, _valueType};
llvm::Type* storeArgs[] = {Type::Word, _valueType};
auto name = _isStore ? isWord ? "mstore" : "mstore8" : "mload";
auto funcType = _isStore ? llvm::FunctionType::get(Type::Void, storeArgs, false) : llvm::FunctionType::get(Type::i256, Type::i256, false);
auto funcType = _isStore ? llvm::FunctionType::get(Type::Void, storeArgs, false) : llvm::FunctionType::get(Type::Word, Type::Word, false);
auto func = llvm::Function::Create(funcType, llvm::Function::PrivateLinkage, name, getModule());
InsertPointGuard guard(m_builder); // Restores insert point at function exit
@ -185,7 +185,7 @@ void Memory::require(llvm::Value* _offset, llvm::Value* _size)
void Memory::copyBytes(llvm::Value* _srcPtr, llvm::Value* _srcSize, llvm::Value* _srcIdx,
llvm::Value* _destMemIdx, llvm::Value* _reqBytes)
{
auto zero256 = llvm::ConstantInt::get(Type::i256, 0);
auto zero256 = llvm::ConstantInt::get(Type::Word, 0);
require(_destMemIdx, _reqBytes);

2
libevmjit/Runtime.cpp

@ -22,7 +22,7 @@ llvm::StructType* RuntimeData::getType()
{
llvm::Type* elems[] =
{
llvm::ArrayType::get(Type::i256, _size),
llvm::ArrayType::get(Type::Word, _size),
Type::BytePtr,
Type::BytePtr,
Type::BytePtr

2
libevmjit/Stack.cpp

@ -18,7 +18,7 @@ Stack::Stack(llvm::IRBuilder<>& _builder, RuntimeManager& _runtimeManager):
CompilerHelper(_builder),
m_runtimeManager(_runtimeManager)
{
m_arg = m_builder.CreateAlloca(Type::i256, nullptr, "stack.arg");
m_arg = m_builder.CreateAlloca(Type::Word, nullptr, "stack.arg");
using namespace llvm;
using Linkage = GlobalValue::LinkageTypes;

10
libevmjit/Type.cpp

@ -12,7 +12,7 @@ namespace eth
namespace jit
{
llvm::IntegerType* Type::i256;
llvm::IntegerType* Type::Word;
llvm::PointerType* Type::WordPtr;
llvm::IntegerType* Type::lowPrecision;
llvm::IntegerType* Type::Size;
@ -24,8 +24,8 @@ llvm::PointerType* Type::RuntimePtr;
void Type::init(llvm::LLVMContext& _context)
{
i256 = llvm::Type::getIntNTy(_context, 256);
WordPtr = i256->getPointerTo();
Word = llvm::Type::getIntNTy(_context, 256);
WordPtr = Word->getPointerTo();
lowPrecision = llvm::Type::getInt64Ty(_context);
// TODO: Size should be architecture-dependent
Size = llvm::Type::getInt64Ty(_context);
@ -38,14 +38,14 @@ void Type::init(llvm::LLVMContext& _context)
llvm::ConstantInt* Constant::get(int64_t _n)
{
return llvm::ConstantInt::getSigned(Type::i256, _n);
return llvm::ConstantInt::getSigned(Type::Word, _n);
}
llvm::ConstantInt* Constant::get(u256 _n)
{
llvm::APInt n(256, _n.str(0, std::ios_base::hex), 16);
assert(n.toString(10, false) == _n.str());
return static_cast<llvm::ConstantInt*>(llvm::ConstantInt::get(Type::i256, n));
return static_cast<llvm::ConstantInt*>(llvm::ConstantInt::get(Type::Word, n));
}
llvm::ConstantInt* Constant::get(ReturnCode _returnCode)

2
libevmjit/Type.h

@ -14,7 +14,7 @@ namespace jit
struct Type
{
static llvm::IntegerType* i256;
static llvm::IntegerType* Word;
static llvm::PointerType* WordPtr;
/// Type for doing low precision arithmetics where 256-bit precision is not supported by native target

Loading…
Cancel
Save