Browse Source

#include cleanups

cl-refactor
Paweł Bylica 10 years ago
parent
commit
4bcee00be9
  1. 3
      libevmjit/Arith256.cpp
  2. 1
      libevmjit/Arith256.h
  3. 14
      libevmjit/BasicBlock.cpp
  4. 3
      libevmjit/BasicBlock.h
  5. 11
      libevmjit/Cache.cpp
  6. 4
      libevmjit/Cache.h
  7. 1
      libevmjit/Common.h
  8. 29
      libevmjit/Compiler.cpp
  9. 4
      libevmjit/Compiler.h
  10. 98
      libevmjit/CompilerHelper.cpp
  11. 153
      libevmjit/CompilerHelper.h
  12. 76
      libevmjit/Endianness.cpp
  13. 49
      libevmjit/Endianness.h
  14. 4
      libevmjit/ExecStats.h
  15. 15
      libevmjit/ExecutionEngine.cpp
  16. 3
      libevmjit/ExecutionEngine.h
  17. 10
      libevmjit/Ext.cpp
  18. 4
      libevmjit/Ext.h
  19. 12
      libevmjit/GasMeter.cpp
  20. 2
      libevmjit/GasMeter.h
  21. 4
      libevmjit/Instruction.cpp
  22. 1
      libevmjit/Instruction.h
  23. 15
      libevmjit/Memory.cpp
  24. 1
      libevmjit/Memory.h
  25. 6
      libevmjit/Runtime.cpp
  26. 4
      libevmjit/Runtime.h
  27. 4
      libevmjit/RuntimeData.h
  28. 10
      libevmjit/RuntimeManager.cpp
  29. 1
      libevmjit/RuntimeManager.h
  30. 2
      libevmjit/Stack.cpp
  31. 83
      libevmjit/Stack.h
  32. 4
      libevmjit/Type.cpp
  33. 7
      libevmjit/Type.h
  34. 1
      libevmjit/Utils.cpp
  35. 1
      libevmjit/Utils.h
  36. 1
      libevmjit/preprocessor/llvm_includes_start.h

3
libevmjit/Arith256.cpp

@ -3,8 +3,9 @@
#include "Type.h"
#include "Endianness.h"
#include <llvm/IR/Function.h>
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
#include <iostream>

1
libevmjit/Arith256.h

@ -1,5 +1,4 @@
#pragma once
#include "CompilerHelper.h"
namespace dev

14
libevmjit/BasicBlock.cpp

@ -1,15 +1,15 @@
#include "BasicBlock.h"
#include "Type.h"
#include <iostream>
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/CFG.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/Support/raw_os_ostream.h>
#include "preprocessor/llvm_includes_end.h"
#include "Type.h"
#include <iostream>
namespace dev
{
@ -141,7 +141,7 @@ void BasicBlock::synchronizeLocalStack(Stack& _evmStack)
auto endIter = m_currentStack.end();
// Update (emit set()) changed values
for (int idx = m_currentStack.size() - 1 - m_tosOffset;
for (int idx = (int)m_currentStack.size() - 1 - m_tosOffset;
currIter < endIter && idx >= 0;
++currIter, --idx)
{
@ -308,7 +308,7 @@ void BasicBlock::linkLocalStacks(std::vector<BasicBlock*> basicBlocks, llvm::IRB
auto& initialStack = bblock.m_initialStack;
initialStack.erase(initialStack.begin(), initialStack.begin() + info.inputItems);
// Initial stack shrinks, so the size difference grows:
bblock.m_tosOffset += info.inputItems;
bblock.m_tosOffset += (int)info.inputItems;
}
// We must account for the items that were pushed directly to successor
@ -321,7 +321,7 @@ void BasicBlock::linkLocalStacks(std::vector<BasicBlock*> basicBlocks, llvm::IRB
auto& exitStack = bblock.m_currentStack;
exitStack.erase(exitStack.end() - info.outputItems, exitStack.end());
bblock.m_tosOffset -= info.outputItems;
bblock.m_tosOffset -= (int)info.outputItems; // FIXME: Fix types
}
}

3
libevmjit/BasicBlock.h

@ -1,8 +1,7 @@
#pragma once
#include <vector>
#include <llvm/IR/BasicBlock.h>
#include "Common.h"
#include "Stack.h"
#include <vector>
namespace dev
{

11
libevmjit/Cache.cpp

@ -1,14 +1,17 @@
#include "Cache.h"
#include <unordered_map>
#include <cassert>
#include <iostream>
#include "ExecutionEngine.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/Module.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Instructions.h>
#include <llvm/Support/Path.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/raw_os_ostream.h>
#include "ExecutionEngine.h"
#include "preprocessor/llvm_includes_end.h"
#include <cassert>
#include <iostream>
namespace dev
{

4
libevmjit/Cache.h

@ -1,8 +1,6 @@
#pragma once
#include <memory>
#include <llvm/ExecutionEngine/ObjectCache.h>
#include <memory>
namespace dev
{

1
libevmjit/Common.h

@ -1,5 +1,4 @@
#pragma once
#include <vector>
#include <tuple>
#include <cstdint>

29
libevmjit/Compiler.cpp

@ -1,19 +1,4 @@
#include "Compiler.h"
#include <functional>
#include <fstream>
#include <chrono>
#include <sstream>
#include <llvm/ADT/PostOrderIterator.h>
#include <llvm/IR/CFG.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/IntrinsicInst.h>
#include <llvm/PassManager.h>
#include <llvm/Transforms/Scalar.h>
#include "Instruction.h"
#include "Type.h"
#include "Memory.h"
@ -25,6 +10,20 @@
#include "Arith256.h"
#include "RuntimeManager.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/ADT/PostOrderIterator.h>
#include <llvm/IR/CFG.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/IntrinsicInst.h>
#include <llvm/PassManager.h>
#include <llvm/Transforms/Scalar.h>
#include "preprocessor/llvm_includes_end.h"
#include <functional>
#include <fstream>
#include <chrono>
#include <sstream>
namespace dev
{
namespace eth

4
libevmjit/Compiler.h

@ -1,8 +1,4 @@
#pragma once
#include <llvm/IR/IRBuilder.h>
#include "Common.h"
#include "BasicBlock.h"

98
libevmjit/CompilerHelper.cpp

@ -1,51 +1,47 @@
#include "CompilerHelper.h"
#include <llvm/IR/Function.h>
#include <llvm/IR/Module.h>
#include "RuntimeManager.h"
namespace dev
{
namespace eth
{
namespace jit
{
CompilerHelper::CompilerHelper(llvm::IRBuilder<>& _builder) :
m_builder(_builder)
{}
llvm::Module* CompilerHelper::getModule()
{
assert(m_builder.GetInsertBlock());
assert(m_builder.GetInsertBlock()->getParent()); // BB must be in a function
return m_builder.GetInsertBlock()->getParent()->getParent();
}
llvm::Function* CompilerHelper::getMainFunction()
{
// TODO: Rename or change semantics of getMainFunction() function
assert(m_builder.GetInsertBlock());
auto mainFunc = m_builder.GetInsertBlock()->getParent();
assert(mainFunc);
if (mainFunc == &mainFunc->getParent()->getFunctionList().front()) // Main function is the first one in module
return mainFunc;
return nullptr;
}
llvm::CallInst* CompilerHelper::createCall(llvm::Function* _func, std::initializer_list<llvm::Value*> const& _args)
{
return getBuilder().CreateCall(_func, {_args.begin(), _args.size()});
}
RuntimeHelper::RuntimeHelper(RuntimeManager& _runtimeManager):
CompilerHelper(_runtimeManager.getBuilder()),
m_runtimeManager(_runtimeManager)
{}
}
}
}
#include "CompilerHelper.h"
#include "RuntimeManager.h"
#include <llvm/IR/Module.h>
namespace dev
{
namespace eth
{
namespace jit
{
CompilerHelper::CompilerHelper(llvm::IRBuilder<>& _builder) :
m_builder(_builder)
{}
llvm::Module* CompilerHelper::getModule()
{
assert(m_builder.GetInsertBlock());
assert(m_builder.GetInsertBlock()->getParent()); // BB must be in a function
return m_builder.GetInsertBlock()->getParent()->getParent();
}
llvm::Function* CompilerHelper::getMainFunction()
{
// TODO: Rename or change semantics of getMainFunction() function
assert(m_builder.GetInsertBlock());
auto mainFunc = m_builder.GetInsertBlock()->getParent();
assert(mainFunc);
if (mainFunc == &mainFunc->getParent()->getFunctionList().front()) // Main function is the first one in module
return mainFunc;
return nullptr;
}
llvm::CallInst* CompilerHelper::createCall(llvm::Function* _func, std::initializer_list<llvm::Value*> const& _args)
{
return getBuilder().CreateCall(_func, {_args.begin(), _args.size()});
}
RuntimeHelper::RuntimeHelper(RuntimeManager& _runtimeManager):
CompilerHelper(_runtimeManager.getBuilder()),
m_runtimeManager(_runtimeManager)
{}
}
}
}

153
libevmjit/CompilerHelper.h

@ -1,78 +1,79 @@
#pragma once
#pragma once
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IRBuilder.h>
namespace dev
{
namespace eth
{
namespace jit
{
class RuntimeManager;
/// Base class for compiler helpers like Memory, GasMeter, etc.
class CompilerHelper
{
protected:
CompilerHelper(llvm::IRBuilder<>& _builder);
CompilerHelper(const CompilerHelper&) = delete;
void operator=(CompilerHelper) = delete;
/// Reference to the IR module being compiled
llvm::Module* getModule();
/// Reference to the main module function
llvm::Function* getMainFunction();
/// Reference to parent compiler IR builder
llvm::IRBuilder<>& m_builder;
llvm::IRBuilder<>& getBuilder() { return m_builder; }
llvm::CallInst* createCall(llvm::Function* _func, std::initializer_list<llvm::Value*> const& _args);
friend class RuntimeHelper;
};
/// Compiler helper that depends on runtime data
class RuntimeHelper : public CompilerHelper
{
protected:
RuntimeHelper(RuntimeManager& _runtimeManager);
RuntimeManager& getRuntimeManager() { return m_runtimeManager; }
private:
RuntimeManager& m_runtimeManager;
};
/// Saves the insert point of the IR builder and restores it when destructed
struct InsertPointGuard
{
InsertPointGuard(llvm::IRBuilder<>& _builder) :
m_builder(_builder),
m_insertBB(m_builder.GetInsertBlock()),
m_insertPt(m_builder.GetInsertPoint())
{}
InsertPointGuard(const InsertPointGuard&) = delete;
void operator=(InsertPointGuard) = delete;
~InsertPointGuard()
{
m_builder.SetInsertPoint(m_insertBB, m_insertPt);
}
private:
llvm::IRBuilder<>& m_builder;
llvm::BasicBlock* m_insertBB;
llvm::BasicBlock::iterator m_insertPt;
};
}
}
}
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth
{
namespace jit
{
class RuntimeManager;
/// Base class for compiler helpers like Memory, GasMeter, etc.
class CompilerHelper
{
protected:
CompilerHelper(llvm::IRBuilder<>& _builder);
CompilerHelper(const CompilerHelper&) = delete;
CompilerHelper& operator=(CompilerHelper) = delete;
/// Reference to the IR module being compiled
llvm::Module* getModule();
/// Reference to the main module function
llvm::Function* getMainFunction();
/// Reference to parent compiler IR builder
llvm::IRBuilder<>& m_builder;
llvm::IRBuilder<>& getBuilder() { return m_builder; }
llvm::CallInst* createCall(llvm::Function* _func, std::initializer_list<llvm::Value*> const& _args);
friend class RuntimeHelper;
};
/// Compiler helper that depends on runtime data
class RuntimeHelper : public CompilerHelper
{
protected:
RuntimeHelper(RuntimeManager& _runtimeManager);
RuntimeManager& getRuntimeManager() { return m_runtimeManager; }
private:
RuntimeManager& m_runtimeManager;
};
/// Saves the insert point of the IR builder and restores it when destructed
struct InsertPointGuard
{
InsertPointGuard(llvm::IRBuilder<>& _builder) :
m_builder(_builder),
m_insertBB(m_builder.GetInsertBlock()),
m_insertPt(m_builder.GetInsertPoint())
{}
InsertPointGuard(const InsertPointGuard&) = delete;
void operator=(InsertPointGuard) = delete;
~InsertPointGuard()
{
m_builder.SetInsertPoint(m_insertBB, m_insertPt);
}
private:
llvm::IRBuilder<>& m_builder;
llvm::BasicBlock* m_insertBB;
llvm::BasicBlock::iterator m_insertPt;
};
}
}
}

76
libevmjit/Endianness.cpp

@ -1,38 +1,38 @@
#include "Endianness.h"
#include <llvm/IR/IntrinsicInst.h>
#include "Type.h"
namespace dev
{
namespace eth
{
namespace jit
{
llvm::Value* Endianness::bswapIfLE(llvm::IRBuilder<>& _builder, llvm::Value* _word)
{
union tester
{
unsigned int x;
unsigned char isLE;
};
if (tester{1}.isLE)
{
// FIXME: Disabled because of problems with BYTE
//if (auto constant = llvm::dyn_cast<llvm::ConstantInt>(_word))
// return _builder.getInt(constant->getValue().byteSwap());
// OPT: Cache func declaration?
auto bswapFunc = llvm::Intrinsic::getDeclaration(_builder.GetInsertBlock()->getParent()->getParent(), llvm::Intrinsic::bswap, Type::Word);
return _builder.CreateCall(bswapFunc, _word);
}
return _word;
}
}
}
}
#include "Endianness.h"
#include "Type.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth
{
namespace jit
{
llvm::Value* Endianness::bswapIfLE(llvm::IRBuilder<>& _builder, llvm::Value* _word)
{
union tester
{
unsigned int x;
unsigned char isLE;
};
if (tester{1}.isLE)
{
// FIXME: Disabled because of problems with BYTE
//if (auto constant = llvm::dyn_cast<llvm::ConstantInt>(_word))
// return _builder.getInt(constant->getValue().byteSwap());
// OPT: Cache func declaration?
auto bswapFunc = llvm::Intrinsic::getDeclaration(_builder.GetInsertBlock()->getParent()->getParent(), llvm::Intrinsic::bswap, Type::Word);
return _builder.CreateCall(bswapFunc, _word);
}
return _word;
}
}
}
}

49
libevmjit/Endianness.h

@ -1,24 +1,25 @@
#pragma once
#include <llvm/IR/IRBuilder.h>
namespace dev
{
namespace eth
{
namespace jit
{
struct Endianness
{
static llvm::Value* toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word) { return bswapIfLE(_builder, _word); }
static llvm::Value* toNative(llvm::IRBuilder<>& _builder, llvm::Value* _word) { return bswapIfLE(_builder, _word); }
private:
static llvm::Value* bswapIfLE(llvm::IRBuilder<>& _builder, llvm::Value* _word);
};
}
}
}
#pragma once
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IRBuilder.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth
{
namespace jit
{
struct Endianness
{
static llvm::Value* toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word) { return bswapIfLE(_builder, _word); }
static llvm::Value* toNative(llvm::IRBuilder<>& _builder, llvm::Value* _word) { return bswapIfLE(_builder, _word); }
private:
static llvm::Value* bswapIfLE(llvm::IRBuilder<>& _builder, llvm::Value* _word);
};
}
}
}

4
libevmjit/ExecStats.h

@ -1,8 +1,6 @@
#pragma once
#include <string>
#include <chrono>
#include "ExecutionEngine.h"
#include <chrono>
namespace dev
{

15
libevmjit/ExecutionEngine.cpp

@ -1,7 +1,10 @@
#include "ExecutionEngine.h"
#include "Runtime.h"
#include "Compiler.h"
#include "Cache.h"
#include "ExecStats.h"
#include "BuildInfo.gen.h"
#include <chrono>
#include <cstdlib> // env options
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/Module.h>
#include <llvm/ADT/Triple.h>
@ -12,12 +15,8 @@
#include <llvm/Support/Host.h>
#include "preprocessor/llvm_includes_end.h"
#include "Runtime.h"
#include "Compiler.h"
#include "Cache.h"
#include "ExecStats.h"
#include "BuildInfo.gen.h"
#include <array>
#include <cstdlib> // env options
#include <iostream>
namespace dev

3
libevmjit/ExecutionEngine.h

@ -1,7 +1,6 @@
#pragma once
#include <memory>
#include "RuntimeData.h"
#include <memory>
namespace dev
{

10
libevmjit/Ext.cpp

@ -1,15 +1,13 @@
#include "Ext.h"
#include <llvm/IR/Function.h>
#include <llvm/IR/TypeBuilder.h>
#include <llvm/IR/IntrinsicInst.h>
#include "RuntimeManager.h"
#include "Memory.h"
#include "Type.h"
#include "Endianness.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth

4
libevmjit/Ext.h

@ -1,8 +1,6 @@
#pragma once
#include <array>
#include "CompilerHelper.h"
#include <array>
namespace dev
{

12
libevmjit/GasMeter.cpp

@ -1,14 +1,12 @@
#include "GasMeter.h"
#include <llvm/IR/GlobalVariable.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IntrinsicInst.h>
#include "Type.h"
#include "Ext.h"
#include "RuntimeManager.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth

2
libevmjit/GasMeter.h

@ -1,6 +1,4 @@
#pragma once
#include "CompilerHelper.h"
#include "Instruction.h"

4
libevmjit/Instruction.cpp

@ -1,6 +1,8 @@
#include "Instruction.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/ADT/APInt.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{

1
libevmjit/Instruction.h

@ -1,5 +1,4 @@
#pragma once
#include "Common.h"
namespace llvm

15
libevmjit/Memory.cpp

@ -1,21 +1,14 @@
#include "Memory.h"
#include <vector>
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cassert>
#include <llvm/IR/GlobalVariable.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IntrinsicInst.h>
#include "Type.h"
#include "Runtime.h"
#include "GasMeter.h"
#include "Endianness.h"
#include "RuntimeManager.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth

1
libevmjit/Memory.h

@ -1,5 +1,4 @@
#pragma once
#include "CompilerHelper.h"
namespace dev

6
libevmjit/Runtime.cpp

@ -1,9 +1,5 @@
#include "Runtime.h"
#include <llvm/IR/GlobalVariable.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IntrinsicInst.h>
#include <cassert>
namespace dev
{

4
libevmjit/Runtime.h

@ -1,8 +1,6 @@
#pragma once
#include <csetjmp>
#include "RuntimeData.h"
#include <csetjmp>
namespace dev
{

4
libevmjit/RuntimeData.h

@ -1,7 +1,5 @@
#pragma once
#include "Utils.h"
#include "Common.h"
namespace dev
{

10
libevmjit/RuntimeManager.cpp

@ -1,12 +1,8 @@
#include "RuntimeManager.h"
#include <llvm/IR/GlobalVariable.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IntrinsicInst.h>
#include "RuntimeData.h"
#include "Instruction.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{

1
libevmjit/RuntimeManager.h

@ -1,5 +1,4 @@
#pragma once
#include "CompilerHelper.h"
#include "Type.h"
#include "RuntimeData.h"

2
libevmjit/Stack.cpp

@ -1,10 +1,8 @@
#include "Stack.h"
#include "RuntimeManager.h"
#include "Runtime.h"
#include "Type.h"
#include <llvm/IR/Function.h>
#include <llvm/IR/TypeBuilder.h>
namespace dev
{

83
libevmjit/Stack.h

@ -1,43 +1,40 @@
#pragma once
#include "CompilerHelper.h"
#include <llvm/IR/Module.h>
namespace dev
{
namespace eth
{
namespace jit
{
class RuntimeManager;
class Stack : public CompilerHelper
{
public:
Stack(llvm::IRBuilder<>& builder, RuntimeManager& runtimeManager);
llvm::Value* get(size_t _index);
void set(size_t _index, llvm::Value* _value);
void pop(size_t _count);
void push(llvm::Value* _value);
static size_t maxStackSize;
private:
RuntimeManager& m_runtimeManager;
llvm::Function* m_push;
llvm::Function* m_pop;
llvm::Function* m_get;
llvm::Function* m_set;
llvm::Value* m_arg;
};
}
}
}
#pragma once
#include "CompilerHelper.h"
namespace dev
{
namespace eth
{
namespace jit
{
class RuntimeManager;
class Stack : public CompilerHelper
{
public:
Stack(llvm::IRBuilder<>& builder, RuntimeManager& runtimeManager);
llvm::Value* get(size_t _index);
void set(size_t _index, llvm::Value* _value);
void pop(size_t _count);
void push(llvm::Value* _value);
static size_t maxStackSize;
private:
RuntimeManager& m_runtimeManager;
llvm::Function* m_push;
llvm::Function* m_pop;
llvm::Function* m_get;
llvm::Function* m_set;
llvm::Value* m_arg;
};
}
}
}

4
libevmjit/Type.cpp

@ -1,8 +1,4 @@
#include "Type.h"
#include <llvm/IR/DerivedTypes.h>
#include "RuntimeManager.h"
namespace dev

7
libevmjit/Type.h

@ -1,9 +1,10 @@
#pragma once
#include "Common.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/Type.h>
#include <llvm/IR/Constants.h>
#include "Common.h"
#include <llvm/IR/Constants.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{

1
libevmjit/Utils.cpp

@ -1,4 +1,3 @@
#include "Utils.h"
namespace dev

1
libevmjit/Utils.h

@ -1,5 +1,4 @@
#pragma once
#include "Common.h"
namespace dev

1
libevmjit/preprocessor/llvm_includes_start.h

@ -1,4 +1,5 @@
#pragma warning(push)
#pragma warning(disable: 4267 4244 4800)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"

Loading…
Cancel
Save