backend_x64: Split A32 specific emission into separate class
This commit is contained in:
parent
8bef20c24d
commit
63bd1ece23
6 changed files with 1470 additions and 1245 deletions
|
@ -75,6 +75,8 @@ add_library(dynarmic
|
||||||
|
|
||||||
if (ARCHITECTURE_x86_64)
|
if (ARCHITECTURE_x86_64)
|
||||||
target_sources(dynarmic PRIVATE
|
target_sources(dynarmic PRIVATE
|
||||||
|
backend_x64/a32_emit_x64.cpp
|
||||||
|
backend_x64/a32_emit_x64.h
|
||||||
backend_x64/abi.cpp
|
backend_x64/abi.cpp
|
||||||
backend_x64/abi.h
|
backend_x64/abi.h
|
||||||
backend_x64/block_of_code.cpp
|
backend_x64/block_of_code.cpp
|
||||||
|
|
1117
src/backend_x64/a32_emit_x64.cpp
Normal file
1117
src/backend_x64/a32_emit_x64.cpp
Normal file
File diff suppressed because it is too large
Load diff
63
src/backend_x64/a32_emit_x64.h
Normal file
63
src/backend_x64/a32_emit_x64.h
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/* This file is part of the dynarmic project.
|
||||||
|
* Copyright (c) 2016 MerryMage
|
||||||
|
* This software may be used and distributed according to the terms of the GNU
|
||||||
|
* General Public License version 2 or any later version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/icl/interval_map.hpp>
|
||||||
|
#include <boost/icl/interval_set.hpp>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
|
#include <xbyak_util.h>
|
||||||
|
|
||||||
|
#include "backend_x64/reg_alloc.h"
|
||||||
|
#include "backend_x64/emit_x64.h"
|
||||||
|
#include "common/address_range.h"
|
||||||
|
#include "dynarmic/callbacks.h"
|
||||||
|
#include "frontend/A32/location_descriptor.h"
|
||||||
|
#include "frontend/ir/terminal.h"
|
||||||
|
|
||||||
|
namespace Dynarmic {
|
||||||
|
namespace BackendX64 {
|
||||||
|
|
||||||
|
class A32EmitX64 final : public EmitX64<u32> {
|
||||||
|
public:
|
||||||
|
A32EmitX64(BlockOfCode* code, UserCallbacks cb, Jit* jit_interface);
|
||||||
|
~A32EmitX64();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit host machine code for a basic block with intermediate representation `ir`.
|
||||||
|
* @note ir is modified.
|
||||||
|
*/
|
||||||
|
BlockDescriptor Emit(IR::Block& ir);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Microinstruction emitters
|
||||||
|
#define OPCODE(...)
|
||||||
|
#define A32OPC(name, type, ...) void EmitA32##name(RegAlloc& reg_alloc, IR::Block& block, IR::Inst* inst);
|
||||||
|
#include "frontend/ir/opcodes.inc"
|
||||||
|
#undef OPCODE
|
||||||
|
#undef A32OPC
|
||||||
|
|
||||||
|
// Terminal instruction emitters
|
||||||
|
void EmitTerminalImpl(IR::Term::Interpret terminal, IR::LocationDescriptor initial_location) override;
|
||||||
|
void EmitTerminalImpl(IR::Term::ReturnToDispatch terminal, IR::LocationDescriptor initial_location) override;
|
||||||
|
void EmitTerminalImpl(IR::Term::LinkBlock terminal, IR::LocationDescriptor initial_location) override;
|
||||||
|
void EmitTerminalImpl(IR::Term::LinkBlockFast terminal, IR::LocationDescriptor initial_location) override;
|
||||||
|
void EmitTerminalImpl(IR::Term::PopRSBHint terminal, IR::LocationDescriptor initial_location) override;
|
||||||
|
void EmitTerminalImpl(IR::Term::If terminal, IR::LocationDescriptor initial_location) override;
|
||||||
|
void EmitTerminalImpl(IR::Term::CheckHalt terminal, IR::LocationDescriptor initial_location) override;
|
||||||
|
|
||||||
|
// Patching
|
||||||
|
void EmitPatchJg(const IR::LocationDescriptor& target_desc, CodePtr target_code_ptr = nullptr) override;
|
||||||
|
void EmitPatchJmp(const IR::LocationDescriptor& target_desc, CodePtr target_code_ptr = nullptr) override;
|
||||||
|
void EmitPatchMovRcx(CodePtr target_code_ptr = nullptr) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace BackendX64
|
||||||
|
} // namespace Dynarmic
|
File diff suppressed because it is too large
Load diff
|
@ -34,58 +34,51 @@ namespace BackendX64 {
|
||||||
|
|
||||||
class BlockOfCode;
|
class BlockOfCode;
|
||||||
|
|
||||||
class A32EmitX64 final {
|
template <typename ProgramCounterType>
|
||||||
|
class EmitX64 {
|
||||||
public:
|
public:
|
||||||
struct BlockDescriptor {
|
struct BlockDescriptor {
|
||||||
CodePtr entrypoint; // Entrypoint of emitted code
|
CodePtr entrypoint; // Entrypoint of emitted code
|
||||||
size_t size; // Length in bytes of emitted code
|
size_t size; // Length in bytes of emitted code
|
||||||
|
|
||||||
A32::LocationDescriptor start_location;
|
A32::LocationDescriptor start_location;
|
||||||
boost::icl::discrete_interval<u32> range;
|
boost::icl::discrete_interval<ProgramCounterType> range;
|
||||||
};
|
};
|
||||||
|
|
||||||
A32EmitX64(BlockOfCode* code, UserCallbacks cb, Jit* jit_interface);
|
EmitX64(BlockOfCode* code, UserCallbacks cb, Jit* jit_interface);
|
||||||
|
virtual ~EmitX64();
|
||||||
/**
|
|
||||||
* Emit host machine code for a basic block with intermediate representation `ir`.
|
|
||||||
* @note ir is modified.
|
|
||||||
*/
|
|
||||||
BlockDescriptor Emit(IR::Block& ir);
|
|
||||||
|
|
||||||
/// Looks up an emitted host block in the cache.
|
/// Looks up an emitted host block in the cache.
|
||||||
boost::optional<BlockDescriptor> GetBasicBlock(A32::LocationDescriptor descriptor) const;
|
boost::optional<BlockDescriptor> GetBasicBlock(IR::LocationDescriptor descriptor) const;
|
||||||
|
|
||||||
/// Empties the entire cache.
|
/// Empties the entire cache.
|
||||||
void ClearCache();
|
void ClearCache();
|
||||||
|
|
||||||
/**
|
void InvalidateCacheRanges(const boost::icl::interval_set<ProgramCounterType>& ranges);
|
||||||
* Invalidate the cache at a set of ranges of addresses.
|
|
||||||
* @param ranges The set of ranges of addresses to invalidate the cache at.
|
|
||||||
*/
|
|
||||||
void InvalidateCacheRanges(const boost::icl::interval_set<u32>& ranges);
|
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
// Microinstruction emitters
|
// Microinstruction emitters
|
||||||
#define OPCODE(name, type, ...) void Emit##name(RegAlloc& reg_alloc, IR::Block& block, IR::Inst* inst);
|
#define OPCODE(name, type, ...) void Emit##name(RegAlloc& reg_alloc, IR::Block& block, IR::Inst* inst);
|
||||||
#define A32OPC(name, type, ...) void EmitA32##name(RegAlloc& reg_alloc, IR::Block& block, IR::Inst* inst);
|
#define A32OPC(...)
|
||||||
#include "frontend/ir/opcodes.inc"
|
#include "frontend/ir/opcodes.inc"
|
||||||
#undef OPCODE
|
#undef OPCODE
|
||||||
#undef A32OPC
|
#undef A32OPC
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
void EmitAddCycles(size_t cycles);
|
void EmitAddCycles(size_t cycles);
|
||||||
|
Xbyak::Label EmitCond(IR::Cond cond);
|
||||||
void EmitCondPrelude(const IR::Block& block);
|
void EmitCondPrelude(const IR::Block& block);
|
||||||
void PushRSBHelper(Xbyak::Reg64 loc_desc_reg, Xbyak::Reg64 index_reg, u64 target_hash);
|
void PushRSBHelper(Xbyak::Reg64 loc_desc_reg, Xbyak::Reg64 index_reg, IR::LocationDescriptor target);
|
||||||
|
|
||||||
// Terminal instruction emitters
|
// Terminal instruction emitters
|
||||||
void EmitTerminal(IR::Terminal terminal, A32::LocationDescriptor initial_location);
|
void EmitTerminal(IR::Terminal terminal, IR::LocationDescriptor initial_location);
|
||||||
void EmitTerminal(IR::Term::Interpret terminal, A32::LocationDescriptor initial_location);
|
virtual void EmitTerminalImpl(IR::Term::Interpret terminal, IR::LocationDescriptor initial_location) = 0;
|
||||||
void EmitTerminal(IR::Term::ReturnToDispatch terminal, A32::LocationDescriptor initial_location);
|
virtual void EmitTerminalImpl(IR::Term::ReturnToDispatch terminal, IR::LocationDescriptor initial_location) = 0;
|
||||||
void EmitTerminal(IR::Term::LinkBlock terminal, A32::LocationDescriptor initial_location);
|
virtual void EmitTerminalImpl(IR::Term::LinkBlock terminal, IR::LocationDescriptor initial_location) = 0;
|
||||||
void EmitTerminal(IR::Term::LinkBlockFast terminal, A32::LocationDescriptor initial_location);
|
virtual void EmitTerminalImpl(IR::Term::LinkBlockFast terminal, IR::LocationDescriptor initial_location) = 0;
|
||||||
void EmitTerminal(IR::Term::PopRSBHint terminal, A32::LocationDescriptor initial_location);
|
virtual void EmitTerminalImpl(IR::Term::PopRSBHint terminal, IR::LocationDescriptor initial_location) = 0;
|
||||||
void EmitTerminal(IR::Term::If terminal, A32::LocationDescriptor initial_location);
|
virtual void EmitTerminalImpl(IR::Term::If terminal, IR::LocationDescriptor initial_location) = 0;
|
||||||
void EmitTerminal(IR::Term::CheckHalt terminal, A32::LocationDescriptor initial_location);
|
virtual void EmitTerminalImpl(IR::Term::CheckHalt terminal, IR::LocationDescriptor initial_location) = 0;
|
||||||
|
|
||||||
// Patching
|
// Patching
|
||||||
struct PatchInformation {
|
struct PatchInformation {
|
||||||
|
@ -93,19 +86,19 @@ private:
|
||||||
std::vector<CodePtr> jmp;
|
std::vector<CodePtr> jmp;
|
||||||
std::vector<CodePtr> mov_rcx;
|
std::vector<CodePtr> mov_rcx;
|
||||||
};
|
};
|
||||||
void Patch(const A32::LocationDescriptor& target_desc, CodePtr target_code_ptr);
|
void Patch(const IR::LocationDescriptor& target_desc, CodePtr target_code_ptr);
|
||||||
void Unpatch(const A32::LocationDescriptor& target_desc);
|
void Unpatch(const IR::LocationDescriptor& target_desc);
|
||||||
void EmitPatchJg(const A32::LocationDescriptor& target_desc, CodePtr target_code_ptr = nullptr);
|
virtual void EmitPatchJg(const IR::LocationDescriptor& target_desc, CodePtr target_code_ptr = nullptr) = 0;
|
||||||
void EmitPatchJmp(const A32::LocationDescriptor& target_desc, CodePtr target_code_ptr = nullptr);
|
virtual void EmitPatchJmp(const IR::LocationDescriptor& target_desc, CodePtr target_code_ptr = nullptr) = 0;
|
||||||
void EmitPatchMovRcx(CodePtr target_code_ptr = nullptr);
|
virtual void EmitPatchMovRcx(CodePtr target_code_ptr = nullptr) = 0;
|
||||||
|
|
||||||
// State
|
// State
|
||||||
BlockOfCode* code;
|
BlockOfCode* code;
|
||||||
UserCallbacks cb;
|
UserCallbacks cb;
|
||||||
boost::icl::interval_map<u32, std::set<A32::LocationDescriptor>> block_ranges;
|
|
||||||
Jit* jit_interface;
|
Jit* jit_interface;
|
||||||
std::unordered_map<u64, BlockDescriptor> block_descriptors;
|
std::unordered_map<IR::LocationDescriptor, BlockDescriptor> block_descriptors;
|
||||||
std::unordered_map<u64, PatchInformation> patch_information;
|
std::unordered_map<IR::LocationDescriptor, PatchInformation> patch_information;
|
||||||
|
boost::icl::interval_map<ProgramCounterType, std::set<IR::LocationDescriptor>> block_ranges;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BackendX64
|
} // namespace BackendX64
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
#include <llvm-c/Target.h>
|
#include <llvm-c/Target.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "backend_x64/a32_emit_x64.h"
|
||||||
#include "backend_x64/block_of_code.h"
|
#include "backend_x64/block_of_code.h"
|
||||||
#include "backend_x64/emit_x64.h"
|
|
||||||
#include "backend_x64/jitstate.h"
|
#include "backend_x64/jitstate.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
Loading…
Reference in a new issue