Play-/Source/BasicBlock.h

133 lines
2.9 KiB
C
Raw Permalink Normal View History

#pragma once
#include "MIPS.h"
#include "MemoryFunction.h"
#ifdef AOT_BUILD_CACHE
#include "StdStream.h"
#include <mutex>
#endif
struct AOT_BLOCK_KEY
{
2018-04-30 21:01:23 +01:00
uint32 crc;
uint32 begin;
uint32 end;
uint32 align;
2018-04-30 21:01:23 +01:00
bool operator<(const AOT_BLOCK_KEY& k2) const
{
const auto& k1 = (*this);
if(k1.crc == k2.crc)
{
if(k1.begin == k2.begin)
{
return k1.end < k2.end;
}
else
{
return k1.begin < k2.begin;
}
}
else
{
return k1.crc < k2.crc;
}
}
};
static_assert(sizeof(AOT_BLOCK_KEY) == 0x10, "AOT_BLOCK_KEY must be 16 bytes long.");
namespace Jitter
{
class CJitter;
};
extern "C"
{
void EmptyBlockHandler(CMIPS*);
void NextBlockTrampoline(CMIPS*);
}
enum LINK_SLOT
{
LINK_SLOT_NEXT,
LINK_SLOT_BRANCH,
LINK_SLOT_MAX,
};
//Block outgoing link
struct BLOCK_OUT_LINK
{
LINK_SLOT slot; //slot used in the source block
uint32 srcAddress; //address of source block
bool live; //live if linked to another block, otherwise, link is pending
};
//Block outgoing links map (key: target link address, value: struct describing link status)
typedef std::multimap<uint32, BLOCK_OUT_LINK> BlockOutLinkMap;
//When block linking is used, each basic block will maintain pointers
//to their outgoing link definitions inside the map
typedef BlockOutLinkMap::iterator BlockOutLinkPointer;
class CBasicBlock
{
public:
2018-06-05 13:26:17 -04:00
CBasicBlock(CMIPS&, uint32 = MIPS_INVALID_PC, uint32 = MIPS_INVALID_PC);
2018-04-30 21:01:23 +01:00
virtual ~CBasicBlock() = default;
void Execute();
2018-04-30 21:01:23 +01:00
void Compile();
2019-05-02 12:45:14 -04:00
virtual void CompileRange(CMipsJitter*);
2018-04-30 21:01:23 +01:00
uint32 GetBeginAddress() const;
uint32 GetEndAddress() const;
bool IsCompiled() const;
2018-06-05 13:26:17 -04:00
bool IsEmpty() const;
uint32 GetRecycleCount() const;
void SetRecycleCount(uint32);
BlockOutLinkPointer GetOutLink(LINK_SLOT) const;
void SetOutLink(LINK_SLOT, BlockOutLinkPointer);
2018-06-27 08:20:55 -04:00
void LinkBlock(LINK_SLOT, CBasicBlock*);
void UnlinkBlock(LINK_SLOT);
2018-06-14 06:35:56 -04:00
#ifdef AOT_BUILD_CACHE
2018-04-30 21:01:23 +01:00
static void SetAotBlockOutputStream(Framework::CStdStream*);
#endif
protected:
2018-04-30 21:01:23 +01:00
uint32 m_begin;
uint32 m_end;
CMIPS& m_context;
2018-07-21 20:49:58 -04:00
void CompileProlog(CMipsJitter*);
2018-07-17 18:51:31 -04:00
void CompileEpilog(CMipsJitter*);
private:
void HandleExternalFunctionReference(uintptr_t, uint32, Jitter::CCodeGen::SYMBOL_REF_TYPE);
2018-06-14 06:35:56 -04:00
2018-07-23 12:40:17 -04:00
#ifdef DEBUGGER_INCLUDED
2018-07-21 20:49:58 -04:00
bool HasBreakpoint() const;
static uint32 BreakpointFilter(CMIPS*);
static void BreakpointHandler(CMIPS*);
2018-07-23 12:40:17 -04:00
#endif
#ifdef AOT_BUILD_CACHE
2018-04-30 21:01:23 +01:00
static Framework::CStdStream* m_aotBlockOutputStream;
static std::mutex m_aotBlockOutputStreamMutex;
#endif
#ifndef AOT_USE_CACHE
2018-04-30 21:01:23 +01:00
CMemoryFunction m_function;
#else
2018-04-30 21:01:23 +01:00
void (*m_function)(void*);
#endif
uint32 m_recycleCount = 0;
BlockOutLinkPointer m_outLinks[LINK_SLOT_MAX];
2018-06-27 08:20:55 -04:00
uint32 m_linkBlockTrampolineOffset[LINK_SLOT_MAX];
#ifdef _DEBUG
CBasicBlock* m_linkBlock[LINK_SLOT_MAX];
#endif
};