Browse Source

Using logs utils from LLVM

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

3
libevmjit/Arith256.cpp

@ -9,6 +9,7 @@
#include "Type.h"
#include "Endianness.h"
#include "Utils.h"
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)
{
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";
}
}

12
libevmjit/BasicBlock.cpp

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

16
libevmjit/Cache.cpp

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

3
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)
{
auto compilationStartTime = std::chrono::high_resolution_clock::now();
auto module = std::unique_ptr<llvm::Module>(new llvm::Module(_id, m_builder.getContext()));
// Create main function
@ -228,8 +227,6 @@ std::unique_ptr<llvm::Module> Compiler::compile(code_iterator _begin, code_itera
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;
}

10
libevmjit/Stack.cpp

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

19
libevmjit/Utils.h

@ -2,23 +2,10 @@
#include <iostream>
#include "Common.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)
#include <llvm/Support/Debug.h>
// The same as assert, but expression is always evaluated and result returned
#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