Browse Source

Using logs utils from LLVM

cl-refactor
Paweł Bylica 10 years ago
parent
commit
7d7e6ec7f5
  1. 3
      evmjit/libevmjit/Arith256.cpp
  2. 12
      evmjit/libevmjit/BasicBlock.cpp
  3. 16
      evmjit/libevmjit/Cache.cpp
  4. 3
      evmjit/libevmjit/Compiler.cpp
  5. 10
      evmjit/libevmjit/Stack.cpp
  6. 19
      evmjit/libevmjit/Utils.h

3
evmjit/libevmjit/Arith256.cpp

@ -9,6 +9,7 @@
#include "Type.h" #include "Type.h"
#include "Endianness.h" #include "Endianness.h"
#include "Utils.h"
namespace dev namespace dev
{ {
@ -400,7 +401,7 @@ extern "C"
{ {
EXPORT void debug(uint64_t a, uint64_t b, uint64_t c, uint64_t d, char z) EXPORT void debug(uint64_t a, uint64_t b, uint64_t c, uint64_t d, char z)
{ {
std::cerr << "DEBUG " << std::dec << z << ": " //<< d << c << b << a DLOG(JIT) << "DEBUG " << std::dec << z << ": " //<< d << c << b << a
<< " [" << std::hex << std::setfill('0') << std::setw(16) << d << std::setw(16) << c << std::setw(16) << b << std::setw(16) << a << "]\n"; << " [" << std::hex << std::setfill('0') << std::setw(16) << d << std::setw(16) << c << std::setw(16) << b << std::setw(16) << a << "]\n";
} }
} }

12
evmjit/libevmjit/BasicBlock.cpp

@ -11,6 +11,7 @@
#include "preprocessor/llvm_includes_end.h" #include "preprocessor/llvm_includes_end.h"
#include "Type.h" #include "Type.h"
#include "Utils.h"
namespace dev namespace dev
{ {
@ -242,13 +243,12 @@ void BasicBlock::linkLocalStacks(std::vector<BasicBlock*> basicBlocks, llvm::IRB
bool valuesChanged = true; bool valuesChanged = true;
while (valuesChanged) while (valuesChanged)
{ {
if (getenv("EVMCC_DEBUG_BLOCKS")) for (auto& pair : cfg)
{ {
for (auto& pair : cfg) DLOG(bb) << pair.second.bblock.llvm()->getName().str()
std::cerr << pair.second.bblock.llvm()->getName().str() << ": in " << pair.second.inputItems
<< ": in " << pair.second.inputItems << ", out " << pair.second.outputItems
<< ", out " << pair.second.outputItems << "\n";
<< "\n";
} }
valuesChanged = false; valuesChanged = false;

16
evmjit/libevmjit/Cache.cpp

@ -1,8 +1,5 @@
#include "Cache.h" #include "Cache.h"
#include <iostream>
#include <cassert>
#include "preprocessor/llvm_includes_start.h" #include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/Module.h> #include <llvm/IR/Module.h>
#include <llvm/IR/LLVMContext.h> #include <llvm/IR/LLVMContext.h>
@ -22,9 +19,6 @@ namespace eth
namespace jit namespace jit
{ {
//#define CACHE_LOG std::cerr << "CACHE "
#define CACHE_LOG std::ostream(nullptr)
namespace namespace
{ {
llvm::MemoryBuffer* g_lastObject; llvm::MemoryBuffer* g_lastObject;
@ -43,7 +37,7 @@ std::unique_ptr<llvm::Module> Cache::getObject(std::string const& id)
if (g_listener) if (g_listener)
g_listener->stateChanged(ExecState::CacheLoad); g_listener->stateChanged(ExecState::CacheLoad);
CACHE_LOG << id << ": search\n"; DLOG(cache) << id << ": search\n";
if (!CHECK(!g_lastObject)) if (!CHECK(!g_lastObject))
g_lastObject = nullptr; g_lastObject = nullptr;
@ -72,7 +66,7 @@ std::unique_ptr<llvm::Module> Cache::getObject(std::string const& id)
if (g_lastObject) // if object found create fake module if (g_lastObject) // if object found create fake module
{ {
CACHE_LOG << id << ": found\n"; DLOG(cache) << id << ": found\n";
auto&& context = llvm::getGlobalContext(); auto&& context = llvm::getGlobalContext();
auto module = std::unique_ptr<llvm::Module>(new llvm::Module(id, context)); auto module = std::unique_ptr<llvm::Module>(new llvm::Module(id, context));
auto mainFuncType = llvm::FunctionType::get(llvm::Type::getVoidTy(context), {}, false); auto mainFuncType = llvm::FunctionType::get(llvm::Type::getVoidTy(context), {}, false);
@ -81,7 +75,7 @@ std::unique_ptr<llvm::Module> Cache::getObject(std::string const& id)
bb->getInstList().push_back(new llvm::UnreachableInst{context}); bb->getInstList().push_back(new llvm::UnreachableInst{context});
return module; return module;
} }
CACHE_LOG << id << ": not found\n"; DLOG(cache) << id << ": not found\n";
return nullptr; return nullptr;
} }
@ -101,7 +95,7 @@ void ObjectCache::notifyObjectCompiled(llvm::Module const* _module, llvm::Memory
llvm::sys::path::append(cachePath, id); llvm::sys::path::append(cachePath, id);
CACHE_LOG << id << ": write\n"; DLOG(cache) << id << ": write\n";
std::string error; std::string error;
llvm::raw_fd_ostream cacheFile(cachePath.c_str(), error, llvm::sys::fs::F_None); llvm::raw_fd_ostream cacheFile(cachePath.c_str(), error, llvm::sys::fs::F_None);
cacheFile << _object->getBuffer(); cacheFile << _object->getBuffer();
@ -109,7 +103,7 @@ void ObjectCache::notifyObjectCompiled(llvm::Module const* _module, llvm::Memory
llvm::MemoryBuffer* ObjectCache::getObject(llvm::Module const* _module) llvm::MemoryBuffer* ObjectCache::getObject(llvm::Module const* _module)
{ {
CACHE_LOG << _module->getModuleIdentifier() << ": use\n"; DLOG(cache) << _module->getModuleIdentifier() << ": use\n";
auto o = g_lastObject; auto o = g_lastObject;
g_lastObject = nullptr; g_lastObject = nullptr;
return o; return o;

3
evmjit/libevmjit/Compiler.cpp

@ -122,7 +122,6 @@ llvm::BasicBlock* Compiler::getBadJumpBlock(RuntimeManager& _runtimeManager)
std::unique_ptr<llvm::Module> Compiler::compile(code_iterator _begin, code_iterator _end, std::string const& _id) std::unique_ptr<llvm::Module> Compiler::compile(code_iterator _begin, code_iterator _end, std::string const& _id)
{ {
auto compilationStartTime = std::chrono::high_resolution_clock::now();
auto module = std::unique_ptr<llvm::Module>(new llvm::Module(_id, m_builder.getContext())); auto module = std::unique_ptr<llvm::Module>(new llvm::Module(_id, m_builder.getContext()));
// Create main function // Create main function
@ -228,8 +227,6 @@ std::unique_ptr<llvm::Module> Compiler::compile(code_iterator _begin, code_itera
dumpCFGifRequired("blocks-sync.dot"); dumpCFGifRequired("blocks-sync.dot");
auto compilationEndTime = std::chrono::high_resolution_clock::now();
clog(JIT) << "JIT: " << std::chrono::duration_cast<std::chrono::milliseconds>(compilationEndTime - compilationStartTime).count();
return module; return module;
} }

10
evmjit/libevmjit/Stack.cpp

@ -6,9 +6,9 @@
#include "RuntimeManager.h" #include "RuntimeManager.h"
#include "Runtime.h" #include "Runtime.h"
#include "Utils.h"
#include <iostream> #include <set> // DEBUG only
#include <set>
namespace dev namespace dev
{ {
@ -353,7 +353,7 @@ namespace
~AllocatedMemoryWatchdog() ~AllocatedMemoryWatchdog()
{ {
if (!allocatedMemory.empty()) if (!allocatedMemory.empty())
std::cerr << allocatedMemory.size() << " MEM LEAKS!" << std::endl; DLOG(mem) << allocatedMemory.size() << " MEM LEAKS!\n";
} }
}; };
@ -392,7 +392,7 @@ extern "C"
auto newData = std::realloc(_data, _size); auto newData = std::realloc(_data, _size);
if (_data != newData) if (_data != newData)
{ {
std::cerr << "REALLOC: " << _data << " -> " << newData << " [" << _size << "]" << std::endl; DLOG(mem) << "REALLOC: " << _data << " -> " << newData << " [" << _size << "]\n";
watchdog.allocatedMemory.erase(_data); watchdog.allocatedMemory.erase(_data);
watchdog.allocatedMemory.insert(newData); watchdog.allocatedMemory.insert(newData);
} }
@ -404,7 +404,7 @@ extern "C"
std::free(_data); std::free(_data);
if (_data) if (_data)
{ {
std::cerr << "FREE : " << _data << std::endl; DLOG(mem) << "FREE : " << _data << "\n";
watchdog.allocatedMemory.erase(_data); watchdog.allocatedMemory.erase(_data);
} }
} }

19
evmjit/libevmjit/Utils.h

@ -2,23 +2,10 @@
#include <iostream> #include <iostream>
#include "Common.h" #include <llvm/Support/Debug.h>
namespace dev
{
namespace eth
{
namespace jit
{
struct JIT: public NoteChannel { static const char* name() { return "JIT"; } };
//#define clog(CHANNEL) std::cerr
#define clog(CHANNEL) std::ostream(nullptr)
// The same as assert, but expression is always evaluated and result returned // The same as assert, but expression is always evaluated and result returned
#define CHECK(expr) (assert(expr), expr) #define CHECK(expr) (assert(expr), expr)
} // FIXME: Disable for NDEBUG mode
} #define DLOG(CHANNEL) !(llvm::DebugFlag && llvm::isCurrentDebugType(#CHANNEL)) ? (void)0 : std::cerr
}

Loading…
Cancel
Save