Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to LLVM 8 #187

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmake/ProjectLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ function(configure_llvm_project)
include(ExternalProject)
ExternalProject_Add(llvm
PREFIX ${CMAKE_SOURCE_DIR}/deps
URL http://llvm.org/releases/5.0.0/llvm-5.0.0.src.tar.xz
URL_HASH SHA256=e35dcbae6084adcf4abb32514127c5eabd7d63b733852ccdb31e06f1373136da
URL http://llvm.org/releases/8.0.0/llvm-8.0.0.src.tar.xz
URL_HASH SHA256=8872be1b12c61450cacc82b3d153eab02be2546ef34fa3580ed14137bb26224c
DOWNLOAD_NO_PROGRESS TRUE
BINARY_DIR ${CMAKE_SOURCE_DIR}/deps # Build directly to install dir to avoid copy.
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
Expand Down
3 changes: 1 addition & 2 deletions libevmjit/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ namespace
std::string getVersionedCacheDir()
{
llvm::SmallString<256> path;
llvm::sys::path::user_cache_directory(path, "ethereum", "evmjit",
std::to_string(c_internalABIVersion));
userCacheDirectory(path, "ethereum", "evmjit", std::to_string(c_internalABIVersion));
return path.str();
}

Expand Down
4 changes: 2 additions & 2 deletions libevmjit/Ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ llvm::Value* Ext::calldataload(llvm::Value* _idx)
auto copySize = m_builder.CreateNUWSub(end, idx);
auto padSize = m_builder.CreateNUWSub(m_builder.getInt64(32), copySize);
auto dataBegin = m_builder.CreateGEP(Type::Byte, getRuntimeManager().getCallData(), idx);
m_builder.CreateMemCpy(result, dataBegin, copySize, 1);
m_builder.CreateMemCpy(result, /*DstAlign*/ 1, dataBegin, /*SrcAlign*/ 1, copySize);
auto pad = m_builder.CreateGEP(Type::Byte, result, copySize);
m_builder.CreateMemSet(pad, m_builder.getInt8(0), padSize, 1);

Expand Down Expand Up @@ -531,7 +531,7 @@ void Ext::log(llvm::Value* _memIdx, llvm::Value* _numBytes, llvm::ArrayRef<llvm:

auto addrTy = m_builder.getIntNTy(160);
auto func = getLogFunc(getModule());

auto myAddr = Endianness::toBE(m_builder, m_builder.CreateTrunc(Endianness::toNative(m_builder, getRuntimeManager().getAddress()), addrTy));
createCABICall(func, {
getRuntimeManager().getEnvPtr(), myAddr, dataPtr, dataSize, m_topics, numTopics
Expand Down
14 changes: 7 additions & 7 deletions libevmjit/JIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ std::string makeCodeId(evmc_uint256be codeHash, evmc_revision rev, uint32_t flag
return str;
}

void printVersion()
void printVersion(llvm::raw_ostream &out)
{
std::cout << "Ethereum EVM JIT Compiler (http://github.com/ethereum/evmjit):\n"
<< " EVMJIT version " << EVMJIT_VERSION << "\n"
out << "Ethereum EVM JIT Compiler (http://github.com/ethereum/evmjit):\n"
<< " EVMJIT version " << EVMJIT_VERSION << "\n"
#ifdef NDEBUG
<< " Optimized build, "
<< " Optimized build, "
#else
<< " DEBUG build, "
<< " DEBUG build, "
#endif
<< __DATE__ << " (" << __TIME__ << ")\n"
<< std::endl;
<< __DATE__ << " (" << __TIME__ << ")\n"
<< "\n";
}

namespace cl = llvm::cl;
Expand Down
6 changes: 3 additions & 3 deletions libevmjit/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ llvm::Function* Memory::createFunc(bool _isStore, llvm::Type* _valueType)
InsertPointGuard guard(m_builder); // Restores insert point at function exit

m_builder.SetInsertPoint(llvm::BasicBlock::Create(func->getContext(), {}, func));

auto iter = func->arg_begin();
llvm::Argument* mem = &(*iter++);
mem->setName("mem");
Expand Down Expand Up @@ -240,7 +240,7 @@ void Memory::copyBytes(llvm::Value* _srcPtr, llvm::Value* _srcSize, llvm::Value*
auto padIdx = m_builder.CreateNUWAdd(dstIdx, bytesToCopy, "padIdx");
auto dst = m_memory.getPtr(getRuntimeManager().getMem(), dstIdx);
auto pad = m_memory.getPtr(getRuntimeManager().getMem(), padIdx);
m_builder.CreateMemCpy(dst, src, bytesToCopy, 0);
m_builder.CreateMemCpy(dst, /*DstAlign*/ 0, src, /*SrcAlign*/ 0, bytesToCopy);
m_builder.CreateMemSet(pad, m_builder.getInt8(0), bytesToZero, 0);
}

Expand All @@ -267,7 +267,7 @@ void Memory::copyBytesNoPadding(llvm::Value* _srcPtr, llvm::Value* _srcSize, llv
auto src = m_builder.CreateGEP(_srcPtr, srcIdx, "src");
auto dstIdx = m_builder.CreateTrunc(_destMemIdx, Type::Size, "dstIdx");
auto dst = m_memory.getPtr(getRuntimeManager().getMem(), dstIdx);
m_builder.CreateMemCpy(dst, src, reqBytes, 0);
m_builder.CreateMemCpy(dst, /*DstAlign*/ 0, src, /*SrcAlign*/ 0, reqBytes);
}

}
Expand Down
2 changes: 2 additions & 0 deletions libevmjit/Optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Transforms/Scalar.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/InstCombine/InstCombine.h>
#include <llvm/Transforms/Utils.h>
#include <llvm/Transforms/Utils/BasicBlockUtils.h>
#include "preprocessor/llvm_includes_end.h"

Expand Down
63 changes: 63 additions & 0 deletions libevmjit/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstring>

#include <llvm/Support/Debug.h>
#include <llvm/Support/Path.h>

#include "BuildInfo.gen.h"

Expand Down Expand Up @@ -180,5 +181,67 @@ void keccak(uint8_t const* _data, uint64_t _size, uint8_t* o_hash)
keccak_256(o_hash, 32, _data, _size);
}

namespace
{

bool getDarwinConfDir(bool _tempDir, llvm::SmallVectorImpl<char> &_result) {
#if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR)
// On Darwin, use DARWIN_USER_TEMP_DIR or DARWIN_USER_CACHE_DIR.
// macros defined in <unistd.h> on darwin >= 9
int ConfName = _tempDir ? _CS_DARWIN_USER_TEMP_DIR
: _CS_DARWIN_USER_CACHE_DIR;
size_t ConfLen = confstr(ConfName, nullptr, 0);
if (ConfLen > 0) {
do {
_result.resize(ConfLen);
ConfLen = confstr(ConfName, _result.data(), _result.size());
} while (ConfLen > 0 && ConfLen != _result.size());

if (ConfLen > 0) {
assert(_result.back() == 0);
_result.pop_back();
return true;
}

_result.clear();
}
#endif
return false;
}

bool getUserCacheDir(llvm::SmallVectorImpl<char> &_result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where these functions removed from LLVM?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions are removed in this PR: https://reviews.llvm.org/D52184

{
// First try using XDS_CACHE_HOME env variable,
// as specified in XDG Base Directory Specification at
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
if (const char *XdsCacheDir = std::getenv("XDS_CACHE_HOME")) {
_result.clear();
_result.append(XdsCacheDir, XdsCacheDir + strlen(XdsCacheDir));
return true;
}

// Try Darwin configuration query
if (getDarwinConfDir(false, _result))
return true;

// Use "$HOME/.cache" if $HOME is available
if (llvm::sys::path::home_directory(_result)) {
llvm::sys::path::append(_result, ".cache");
return true;
}

return false;
}
}

bool userCacheDirectory(llvm::SmallVectorImpl<char> &_result, const llvm::Twine &_path1, const llvm::Twine &_path2, const llvm::Twine &_path3)
{
if (getUserCacheDir(_result)) {
llvm::sys::path::append(_result, _path1, _path2, _path3);
return true;
}
return false;
}

}
}
7 changes: 7 additions & 0 deletions libevmjit/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

#include <cstdint>
#include <iostream>
#include <llvm/ADT/SmallVector.h>
#include <llvm/ADT/Twine.h>

namespace dev {
namespace evmjit {

void keccak(uint8_t const *_data, uint64_t _size, uint8_t *o_hash);
bool userCacheDirectory(llvm::SmallVectorImpl<char> &_result,
const llvm::Twine &_path1,
const llvm::Twine &Path2 = "",
const llvm::Twine &Path3 = "");


// The same as assert, but expression is always evaluated and result returned
#define CHECK(expr) (assert(expr), expr)
Expand Down