2013-04-12 02:35:55 +00:00
|
|
|
#pragma once
|
2007-12-01 04:08:34 +00:00
|
|
|
|
|
|
|
#include "MIPS.h"
|
2010-08-11 03:47:19 +00:00
|
|
|
#include "MemoryFunction.h"
|
2013-04-14 06:35:40 +00:00
|
|
|
#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;
|
2021-01-12 11:23:43 -05:00
|
|
|
uint32 align;
|
2013-04-14 06:35:40 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
bool operator<(const AOT_BLOCK_KEY& k2) const
|
2013-04-14 06:35:40 +00:00
|
|
|
{
|
2014-12-18 07:33:18 +00:00
|
|
|
const auto& k1 = (*this);
|
2013-04-14 06:35:40 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2021-01-12 11:23:43 -05:00
|
|
|
static_assert(sizeof(AOT_BLOCK_KEY) == 0x10, "AOT_BLOCK_KEY must be 16 bytes long.");
|
2007-12-01 04:08:34 +00:00
|
|
|
|
2010-08-11 03:47:19 +00:00
|
|
|
namespace Jitter
|
|
|
|
{
|
|
|
|
class CJitter;
|
|
|
|
};
|
2009-06-06 15:38:03 +00:00
|
|
|
|
2019-05-01 20:23:35 -04:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
void EmptyBlockHandler(CMIPS*);
|
|
|
|
void NextBlockTrampoline(CMIPS*);
|
|
|
|
}
|
|
|
|
|
2020-08-03 12:39:24 -04:00
|
|
|
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;
|
|
|
|
|
2007-12-01 04:08:34 +00:00
|
|
|
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;
|
2018-06-05 13:19:18 -04:00
|
|
|
void Execute();
|
2018-04-30 21:01:23 +01:00
|
|
|
void Compile();
|
2019-05-02 12:45:14 -04:00
|
|
|
virtual void CompileRange(CMipsJitter*);
|
2010-08-11 03:47:19 +00:00
|
|
|
|
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;
|
2013-04-14 06:35:40 +00:00
|
|
|
|
2019-12-20 21:25:33 -05:00
|
|
|
uint32 GetRecycleCount() const;
|
|
|
|
void SetRecycleCount(uint32);
|
|
|
|
|
2020-08-03 12:39:24 -04:00
|
|
|
BlockOutLinkPointer GetOutLink(LINK_SLOT) const;
|
|
|
|
void SetOutLink(LINK_SLOT, BlockOutLinkPointer);
|
|
|
|
|
2018-06-27 08:20:55 -04:00
|
|
|
void LinkBlock(LINK_SLOT, CBasicBlock*);
|
2018-06-29 20:34:04 -04:00
|
|
|
void UnlinkBlock(LINK_SLOT);
|
2018-06-14 06:35:56 -04:00
|
|
|
|
2013-04-14 06:35:40 +00:00
|
|
|
#ifdef AOT_BUILD_CACHE
|
2018-04-30 21:01:23 +01:00
|
|
|
static void SetAotBlockOutputStream(Framework::CStdStream*);
|
2013-04-14 06:35:40 +00:00
|
|
|
#endif
|
2007-12-01 04:08:34 +00:00
|
|
|
|
2009-06-06 15:38:03 +00:00
|
|
|
protected:
|
2018-04-30 21:01:23 +01:00
|
|
|
uint32 m_begin;
|
|
|
|
uint32 m_end;
|
|
|
|
CMIPS& m_context;
|
2009-06-06 15:38:03 +00:00
|
|
|
|
2022-01-18 10:23:23 -05:00
|
|
|
virtual void CompileProlog(CMipsJitter*);
|
|
|
|
virtual void CompileEpilog(CMipsJitter*);
|
2009-06-06 15:38:03 +00:00
|
|
|
|
|
|
|
private:
|
2018-09-28 13:31:24 -04:00
|
|
|
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
|
|
|
|
|
2013-04-14 06:35:40 +00:00
|
|
|
#ifdef AOT_BUILD_CACHE
|
2018-04-30 21:01:23 +01:00
|
|
|
static Framework::CStdStream* m_aotBlockOutputStream;
|
|
|
|
static std::mutex m_aotBlockOutputStreamMutex;
|
2013-04-14 06:35:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef AOT_USE_CACHE
|
2018-04-30 21:01:23 +01:00
|
|
|
CMemoryFunction m_function;
|
2013-04-14 06:35:40 +00:00
|
|
|
#else
|
2018-04-30 21:01:23 +01:00
|
|
|
void (*m_function)(void*);
|
2013-04-14 06:35:40 +00:00
|
|
|
#endif
|
2019-12-20 21:25:33 -05:00
|
|
|
uint32 m_recycleCount = 0;
|
2020-08-03 12:39:24 -04:00
|
|
|
BlockOutLinkPointer m_outLinks[LINK_SLOT_MAX];
|
2018-06-27 08:20:55 -04:00
|
|
|
uint32 m_linkBlockTrampolineOffset[LINK_SLOT_MAX];
|
2018-06-29 20:34:04 -04:00
|
|
|
#ifdef _DEBUG
|
|
|
|
CBasicBlock* m_linkBlock[LINK_SLOT_MAX];
|
|
|
|
#endif
|
2007-12-01 04:08:34 +00:00
|
|
|
};
|