Skip to content

Commit

Permalink
Use LLVM 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekotekina committed Apr 30, 2018
1 parent 49a2f18 commit 0b6d639
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 64 deletions.
15 changes: 6 additions & 9 deletions .travis.yml
Expand Up @@ -27,7 +27,7 @@ git:

env:
- QTVER=5.10.1

before_install:
- if [ "$TRAVIS_OS_NAME" = "linux" ] && [ "$CXX" = "g++" ]; then
export CXX="g++-5" CC="gcc-5" CXXFLAGS="-Wno-format-security";
Expand All @@ -43,11 +43,11 @@ install:
sudo dpkg -i libglew2.0_2.0.0-5_amd64.deb libglew-dev_2.0.0-5_amd64.deb libvulkan1_1.0.61.1+dfsg1-1ubuntu1~16.04.1_amd64.deb libvulkan-dev_1.0.61.1+dfsg1-1ubuntu1~16.04.1_amd64.deb;
else
brew update;
brew install ccache glew llvm40;
brew install ccache glew;
fi;

before_script:
- git submodule update --init asmjit 3rdparty/ffmpeg 3rdparty/pugixml 3rdparty/GSL 3rdparty/libpng Utilities/yaml-cpp 3rdparty/cereal 3rdparty/hidapi 3rdparty/Optional Vulkan/glslang Vulkan/Vulkan-LoaderAndValidationLayers
- git submodule update --init llvm asmjit 3rdparty/ffmpeg 3rdparty/pugixml 3rdparty/GSL 3rdparty/libpng Utilities/yaml-cpp 3rdparty/cereal 3rdparty/hidapi 3rdparty/Optional Vulkan/glslang Vulkan/Vulkan-LoaderAndValidationLayers
- mkdir build ; cd build
- export CMAKE_PREFIX_PATH=~/Qt/${QTVER}/gcc_64/lib/cmake
- if [ "$TRAVIS_PULL_REQUEST" = false ]; then
Expand All @@ -59,7 +59,7 @@ before_script:

script:
- ninja

after_script:
- cd build
- # AppImage generation
Expand All @@ -79,15 +79,15 @@ after_script:
rm -r ./appdir/usr/share/man ;
rm -r ./appdir/usr/include ;
export PATH=${TRAVIS_BUILD_DIR}/build/squashfs-root/usr/bin/:${PATH} ;

echo "Embed newer libstdc++ for distros that don't come with it (ubuntu 14.04)";
mkdir -p appdir/usr/optional/ ; mkdir -p appdir/usr/optional/libstdc++/ ;
cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6 ./appdir/usr/optional/libstdc++/ ;
rm ./appdir/AppRun ;
wget -c https://github.com/RPCS3/AppImageKit-checkrt/releases/download/continuous/AppRun-patched-x86_64 -O ./appdir/AppRun ;
chmod a+x ./appdir/AppRun ;
wget -c https://github.com/RPCS3/AppImageKit-checkrt/releases/download/continuous/exec-x86_64.so -O ./appdir/usr/optional/exec.so ;

echo "Package it up and send it off" ;
./linuxdeployqt*.AppImage --appimage-extract ;
./squashfs-root/usr/bin/appimagetool ${TRAVIS_BUILD_DIR}/build/appdir ;
Expand All @@ -100,7 +100,6 @@ addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-4.0
- sourceline: 'ppa:jonathonf/binutils' # We need to update binutils to a newer version to link against the ffmpeg libs on.
- sourceline: 'ppa:beineri/opt-qt-5.10.1-trusty' # <<WARNING>>: This needs to be updated manually whenever the QT Version changes. Add QT PPA since the installer is quite bad.
packages:
Expand All @@ -114,8 +113,6 @@ addons:
#- libvulkan1
#- libvulkan-dev
- libc6-dev
- llvm-4.0
- llvm-4.0-dev
# Clang 5.0 is now bundled in travis, so we no longer need the ppa version.
#- clang-4.0
- libedit-dev
Expand Down
49 changes: 22 additions & 27 deletions Utilities/JIT.cpp
Expand Up @@ -72,7 +72,7 @@ static void* s_next = s_memory;
static std::deque<std::vector<RUNTIME_FUNCTION>> s_unwater;
static std::vector<std::vector<RUNTIME_FUNCTION>> s_unwind; // .pdata
#else
static std::deque<std::tuple<u8*, u64, std::size_t>> s_unfire;
static std::deque<std::pair<u8*, std::size_t>> s_unfire;
#endif

// Reset memory manager
Expand All @@ -89,27 +89,9 @@ extern void jit_finalize()

s_unwind.clear();
#else
struct MemoryManager : llvm::RTDyldMemoryManager
{
u8* allocateCodeSection(std::uintptr_t size, uint align, uint sec_id, llvm::StringRef sec_name) override
{
return nullptr;
}

u8* allocateDataSection(std::uintptr_t size, uint align, uint sec_id, llvm::StringRef sec_name, bool is_ro) override
{
return nullptr;
}

bool finalizeMemory(std::string* = nullptr) override
{
return false;
}
} mem;

for (auto&& t : s_unfire)
{
mem.deregisterEHFrames(std::get<0>(t), std::get<1>(t), std::get<2>(t));
llvm::RTDyldMemoryManager::deregisterEHFramesInProcess(t.first, t.second);
}

s_unfire.clear();
Expand Down Expand Up @@ -287,13 +269,13 @@ struct MemoryManager : llvm::RTDyldMemoryManager
s_unwind.emplace_back(std::move(pdata));
}
#else
s_unfire.push_front(std::make_tuple(addr, load_addr, size));
s_unfire.push_front(std::make_pair(addr, size));
#endif

return RTDyldMemoryManager::registerEHFrames(addr, load_addr, size);
}

void deregisterEHFrames(u8* addr, u64 load_addr, std::size_t size) override
void deregisterEHFrames() override
{
}
};
Expand Down Expand Up @@ -380,8 +362,8 @@ class ObjectCache final : public llvm::ObjectCache
{
if (fs::file cached{path, fs::read})
{
auto buf = llvm::MemoryBuffer::getNewUninitMemBuffer(cached.size());
cached.read(const_cast<char*>(buf->getBufferStart()), buf->getBufferSize());
auto buf = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(cached.size());
cached.read(buf->getBufferStart(), buf->getBufferSize());
return buf;
}

Expand Down Expand Up @@ -429,7 +411,7 @@ std::string jit_compiler::cpu(const std::string& _cpu)
return m_cpu;
}

jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, const std::string& _cpu)
jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, const std::string& _cpu, bool large)
: m_link(_link)
, m_cpu(cpu(_cpu))
{
Expand All @@ -441,7 +423,7 @@ jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, co
m_engine.reset(llvm::EngineBuilder(std::make_unique<llvm::Module>("null_", m_context))
.setErrorStr(&result)
.setOptLevel(llvm::CodeGenOpt::Aggressive)
.setCodeModel(llvm::CodeModel::Small)
.setCodeModel(large ? llvm::CodeModel::Large : llvm::CodeModel::Small)
.setMCPU(m_cpu)
.create());
}
Expand All @@ -455,7 +437,7 @@ jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, co
.setErrorStr(&result)
.setMCJITMemoryManager(std::move(mem))
.setOptLevel(llvm::CodeGenOpt::Aggressive)
.setCodeModel(llvm::CodeModel::Small)
.setCodeModel(large ? llvm::CodeModel::Large : llvm::CodeModel::Small)
.setMCPU(m_cpu)
.create());

Expand Down Expand Up @@ -492,6 +474,19 @@ void jit_compiler::add(std::unique_ptr<llvm::Module> module, const std::string&
}
}

void jit_compiler::add(std::unique_ptr<llvm::Module> module)
{
const auto ptr = module.get();
m_engine->addModule(std::move(module));
m_engine->generateCodeForModule(ptr);

for (auto& func : ptr->functions())
{
// Delete IR to lower memory consumption
func.deleteBody();
}
}

void jit_compiler::add(const std::string& path)
{
m_engine->addObjectFile(std::move(llvm::object::ObjectFile::createObjectFile(*ObjectCache::load(path)).get()));
Expand Down
10 changes: 9 additions & 1 deletion Utilities/JIT.h
Expand Up @@ -40,7 +40,7 @@ class jit_compiler final
std::string m_cpu;

public:
jit_compiler(const std::unordered_map<std::string, u64>& _link, const std::string& _cpu);
jit_compiler(const std::unordered_map<std::string, u64>& _link, const std::string& _cpu, bool large = false);
~jit_compiler();

// Get LLVM context
Expand All @@ -49,9 +49,17 @@ class jit_compiler final
return m_context;
}

auto& get_engine() const
{
return *m_engine;
}

// Add module (path to obj cache dir)
void add(std::unique_ptr<llvm::Module> module, const std::string& path);

// Add module (not cached)
void add(std::unique_ptr<llvm::Module> module);

// Add object (path to obj file)
void add(const std::string& path);

Expand Down
10 changes: 4 additions & 6 deletions appveyor.yml
Expand Up @@ -5,12 +5,11 @@ image: Visual Studio 2015

environment:
QTDIR: C:\Qt\5.10\msvc2015_64
LLVMLIBS: https://drive.google.com/uc?export=download&id=0B8A6NaxhQAGRY2k3Q2Yya05lcm8
VULKAN: https://drive.google.com/uc?export=download&id=1A2eOMmCO714i0U7J0qI4aEMKnuWl8l_R
COMPATDB: https://rpcs3.net/compatibility?api=v1&export

cache:
- llvmlibs.7z -> appveyor.yml
- llvm_build -> llvm
- vulkan.7z -> appveyor.yml
- compat_database.dat

Expand All @@ -19,7 +18,7 @@ install:
$env:COMM_TAG = $(git describe --tags $(git rev-list --tags --max-count=1))
$env:COMM_COUNT = $(git rev-list --count HEAD)
$env:COMM_HASH = $env:APPVEYOR_REPO_COMMIT.Substring(0,8)
if ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
$env:BUILD = "rpcs3-{0}-{1}_win64.7z" -f $env:COMM_TAG, $env:COMM_HASH
$env:AVVER = "{0}-{1}" -f $env:COMM_TAG.TrimStart("v"), $env:COMM_HASH
Expand All @@ -40,6 +39,7 @@ install:
- ps: | # update and init submodules
git submodule -q update --init `
llvm `
3rdparty/cereal `
3rdparty/ffmpeg `
3rdparty/GSL `
Expand All @@ -64,9 +64,7 @@ build:

before_build:
- ps: | # fetch precompiled build dependencies
if (!(test-path llvmlibs.7z)) { irm $env:LLVMLIBS -outfile llvmlibs.7z }
if (!(test-path vulkan.7z)) { irm $env:VULKAN -outfile vulkan.7z }
7z x llvmlibs.7z -aos -o"." | out-null
7z x vulkan.7z -aos -o".\lib\$env:CONFIGURATION-$env:PLATFORM" | out-null
after_build:
Expand Down Expand Up @@ -101,6 +99,6 @@ artifacts:
- path: openssl_win64.7z.sha256
name: openssl sha256 hash

on_finish:
on_finish:
- ps: | # update appveyor build version, done last to prevent webhook breakage
update-appveyorbuild -version $env:AVVER
2 changes: 1 addition & 1 deletion llvm
Submodule llvm updated 14737 files
2 changes: 2 additions & 0 deletions rpcs3.sln
Expand Up @@ -104,9 +104,11 @@ Global
{C4A10229-4712-4BD2-B63E-50D93C67A038}.Release|x64.ActiveCfg = Release|x64
{C4A10229-4712-4BD2-B63E-50D93C67A038}.Release|x64.Build.0 = Release|x64
{8BC303AB-25BE-4276-8E57-73F171B2D672}.Debug - LLVM|x64.ActiveCfg = Debug|x64
{8BC303AB-25BE-4276-8E57-73F171B2D672}.Debug - LLVM|x64.Build.0 = Debug|x64
{8BC303AB-25BE-4276-8E57-73F171B2D672}.Debug - MemLeak|x64.ActiveCfg = Debug|x64
{8BC303AB-25BE-4276-8E57-73F171B2D672}.Debug|x64.ActiveCfg = Debug|x64
{8BC303AB-25BE-4276-8E57-73F171B2D672}.Release - LLVM|x64.ActiveCfg = Release|x64
{8BC303AB-25BE-4276-8E57-73F171B2D672}.Release - LLVM|x64.Build.0 = Release|x64
{8BC303AB-25BE-4276-8E57-73F171B2D672}.Release|x64.ActiveCfg = Release|x64
{FAC9B17B-F4B8-4B75-8AEB-C8C7CB92B078}.Debug - LLVM|x64.ActiveCfg = Debug - LLVM|x64
{FAC9B17B-F4B8-4B75-8AEB-C8C7CB92B078}.Debug - LLVM|x64.Build.0 = Debug - LLVM|x64
Expand Down
10 changes: 5 additions & 5 deletions rpcs3/CMakeLists.txt
Expand Up @@ -181,9 +181,9 @@ set(CMAKE_MODULE_PATH "${RPCS3_SRC_DIR}/cmake_modules")
find_package(OpenGL REQUIRED)
find_package(OpenAL REQUIRED)
if(NOT WITHOUT_LLVM)
find_package(LLVM 4.0 CONFIG)
find_package(LLVM 999.666 CONFIG)
if(NOT LLVM_FOUND)
message("System LLVM was not found, LLVM will be built from the submodule.")
message("LLVM will be built from the submodule.")

set(LLVM_TARGETS_TO_BUILD "X86" CACHE INTERNAL "")
option(LLVM_BUILD_RUNTIME OFF)
Expand All @@ -200,7 +200,7 @@ if(NOT WITHOUT_LLVM)
set(LLVM_DIR "${CMAKE_CURRENT_BINARY_DIR}/../llvm_build/lib/cmake/llvm/")

# now tries to find LLVM again
find_package(LLVM 4.0 CONFIG)
find_package(LLVM 6.0 CONFIG)
if(NOT LLVM_FOUND)
message(WARNING "Couldn't build LLVM from the submodule. You might need to run `git submodule update --init`")
endif()
Expand Down Expand Up @@ -309,7 +309,7 @@ if(WIN32)
endif()

if(NOT LLVM_FOUND)
message("LLVM 4.0 not found. RPCS3 will be compiled without LLVM support.")
message("LLVM submodule not found. RPCS3 will be compiled without LLVM support.")
else()
add_definitions(${LLVM_DEFINITIONS})
add_definitions(-DLLVM_AVAILABLE)
Expand Down Expand Up @@ -486,7 +486,7 @@ add_custom_command(TARGET rpcs3 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/bin/Icons $<TARGET_FILE_DIR:rpcs3>/Icons)
endif()

# Unix installation
if(UNIX AND NOT APPLE)
# Install the binary
Expand Down
6 changes: 4 additions & 2 deletions rpcs3/Emu/CPU/CPUTranslator.cpp
Expand Up @@ -2,8 +2,10 @@

#include "CPUTranslator.h"

cpu_translator::cpu_translator(llvm::LLVMContext& context, llvm::Module* module, bool is_be)
: m_context(context)
llvm::LLVMContext g_llvm_ctx;

cpu_translator::cpu_translator(llvm::Module* module, bool is_be)
: m_context(g_llvm_ctx)
, m_module(module)
, m_is_be(is_be)
{
Expand Down

0 comments on commit 0b6d639

Please sign in to comment.