dynarmic/src/backend_x64/emit_x64.h

95 lines
3 KiB
C
Raw Normal View History

2016-07-01 14:01:06 +01:00
/* 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>
2016-07-01 14:01:06 +01:00
2016-08-12 18:17:31 +01:00
#include <boost/optional.hpp>
#include <xbyak_util.h>
2016-07-01 14:01:06 +01:00
#include "backend_x64/reg_alloc.h"
2016-08-25 18:22:08 +01:00
#include "dynarmic/callbacks.h"
#include "frontend/ir/location_descriptor.h"
#include "frontend/ir/terminal.h"
2016-07-01 14:01:06 +01:00
namespace Dynarmic {
class Jit;
namespace IR {
class Block;
class Inst;
} // namespace IR
2016-07-01 14:01:06 +01:00
namespace BackendX64 {
2016-12-05 04:14:58 +00:00
class BlockOfCode;
2016-07-01 14:01:06 +01:00
class EmitX64 final {
public:
struct BlockDescriptor {
2016-08-12 18:17:31 +01:00
CodePtr code_ptr; ///< Entrypoint of emitted code
size_t size; ///< Length in bytes of emitted code
};
EmitX64(BlockOfCode* code, UserCallbacks cb, Jit* jit_interface);
/**
* Emit host machine code for a basic block with intermediate representation `ir`.
* @note ir is modified.
*/
BlockDescriptor Emit(IR::Block& ir);
2016-08-12 18:17:31 +01:00
/// Looks up an emitted host block in the cache.
boost::optional<BlockDescriptor> GetBasicBlock(IR::LocationDescriptor descriptor) const;
2016-07-01 14:01:06 +01:00
2016-08-12 18:17:31 +01:00
/// Empties the cache.
void ClearCache();
private:
// Microinstruction emitters
2016-07-31 14:52:28 +01:00
#define OPCODE(name, type, ...) void Emit##name(IR::Block& block, IR::Inst* inst);
#include "frontend/ir/opcodes.inc"
#undef OPCODE
2016-07-01 14:01:06 +01:00
// Helpers
void EmitAddCycles(size_t cycles);
void EmitCondPrelude(const IR::Block& block);
2016-07-07 10:53:09 +01:00
// Terminal instruction emitters
void EmitTerminal(IR::Terminal terminal, IR::LocationDescriptor initial_location);
void EmitTerminalInterpret(IR::Term::Interpret terminal, IR::LocationDescriptor initial_location);
void EmitTerminalReturnToDispatch(IR::Term::ReturnToDispatch terminal, IR::LocationDescriptor initial_location);
void EmitTerminalLinkBlock(IR::Term::LinkBlock terminal, IR::LocationDescriptor initial_location);
void EmitTerminalLinkBlockFast(IR::Term::LinkBlockFast terminal, IR::LocationDescriptor initial_location);
void EmitTerminalPopRSBHint(IR::Term::PopRSBHint terminal, IR::LocationDescriptor initial_location);
void EmitTerminalIf(IR::Term::If terminal, IR::LocationDescriptor initial_location);
void EmitTerminalCheckHalt(IR::Term::CheckHalt terminal, IR::LocationDescriptor initial_location);
void Patch(IR::LocationDescriptor desc, CodePtr bb);
2016-07-01 14:01:06 +01:00
// Global CPU information
Xbyak::util::Cpu cpu_info;
// Per-block state
2016-07-01 14:01:06 +01:00
RegAlloc reg_alloc;
// State
BlockOfCode* code;
2016-07-01 14:01:06 +01:00
UserCallbacks cb;
2016-07-07 10:53:09 +01:00
Jit* jit_interface;
std::unordered_map<u64, CodePtr> unique_hash_to_code_ptr;
std::unordered_map<u64, std::vector<CodePtr>> patch_unique_hash_locations;
std::unordered_map<IR::LocationDescriptor, BlockDescriptor> basic_blocks;
std::unordered_map<IR::LocationDescriptor, std::vector<CodePtr>> patch_jg_locations;
std::unordered_map<IR::LocationDescriptor, std::vector<CodePtr>> patch_jmp_locations;
2016-07-01 14:01:06 +01:00
};
} // namespace BackendX64
} // namespace Dynarmic