CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/MIPS/IR/IRNativeCommon.h
Views: 1401
// Copyright (c) 2023- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <unordered_map>20#include "Core/MIPS/IR/IRJit.h"21#include "Core/MIPS/JitCommon/JitBlockCache.h"2223namespace MIPSComp {2425typedef void (*IRNativeFuncNoArg)();2627enum class IRProfilerStatus : int32_t {28NOT_RUNNING,29IN_JIT,30TIMER_ADVANCE,31COMPILING,32MATH_HELPER,33REPLACEMENT,34SYSCALL,35INTERPRET,36IR_INTERPRET,37};3839struct IRNativeHooks {40IRNativeFuncNoArg enterDispatcher = nullptr;4142const uint8_t *dispatcher = nullptr;43const uint8_t *dispatchFetch = nullptr;44const uint8_t *crashHandler = nullptr;4546uint32_t *profilerPC = nullptr;47IRProfilerStatus *profilerStatus = nullptr;48};4950struct IRNativeBlockExit {51int offset;52int len;53uint32_t dest;54};5556struct IRNativeBlock {57int checkedOffset = 0;58std::vector<IRNativeBlockExit> exits;59};6061class IRNativeBackend {62public:63IRNativeBackend(IRBlockCache &blocks);64virtual ~IRNativeBackend();6566void CompileIRInst(IRInst inst);6768virtual bool DescribeCodePtr(const u8 *ptr, std::string &name) const;69bool CodeInRange(const u8 *ptr) const;70int OffsetFromCodePtr(const u8 *ptr);7172virtual void GenerateFixedCode(MIPSState *mipsState) = 0;73virtual bool CompileBlock(IRBlockCache *irBlockCache, int block_num, bool preload) = 0;74virtual void ClearAllBlocks() = 0;75virtual void InvalidateBlock(IRBlockCache *irBlockCache, int block_num) = 0;76void FinalizeBlock(IRBlockCache *irBlockCache, int block_num, const JitOptions &jo);7778virtual void UpdateFCR31(MIPSState *mipsState) {}7980const IRNativeHooks &GetNativeHooks() const {81return hooks_;82}8384const IRNativeBlock *GetNativeBlock(int block_num) const;85void SetBlockCheckedOffset(int block_num, int offset);8687virtual const CodeBlockCommon &CodeBlock() const = 0;8889protected:90virtual void CompIR_Arith(IRInst inst) = 0;91virtual void CompIR_Assign(IRInst inst) = 0;92virtual void CompIR_Basic(IRInst inst) = 0;93virtual void CompIR_Bits(IRInst inst) = 0;94virtual void CompIR_Breakpoint(IRInst inst) = 0;95virtual void CompIR_Compare(IRInst inst) = 0;96virtual void CompIR_CondAssign(IRInst inst) = 0;97virtual void CompIR_CondStore(IRInst inst) = 0;98virtual void CompIR_Div(IRInst inst) = 0;99virtual void CompIR_Exit(IRInst inst) = 0;100virtual void CompIR_ExitIf(IRInst inst) = 0;101virtual void CompIR_FArith(IRInst inst) = 0;102virtual void CompIR_FAssign(IRInst inst) = 0;103virtual void CompIR_FCompare(IRInst inst) = 0;104virtual void CompIR_FCondAssign(IRInst inst) = 0;105virtual void CompIR_FCvt(IRInst inst) = 0;106virtual void CompIR_FLoad(IRInst inst) = 0;107virtual void CompIR_FRound(IRInst inst) = 0;108virtual void CompIR_FSat(IRInst inst) = 0;109virtual void CompIR_FSpecial(IRInst inst) = 0;110virtual void CompIR_FStore(IRInst inst) = 0;111virtual void CompIR_Generic(IRInst inst) = 0;112virtual void CompIR_HiLo(IRInst inst) = 0;113virtual void CompIR_Interpret(IRInst inst) = 0;114virtual void CompIR_Load(IRInst inst) = 0;115virtual void CompIR_LoadShift(IRInst inst) = 0;116virtual void CompIR_Logic(IRInst inst) = 0;117virtual void CompIR_Mult(IRInst inst) = 0;118virtual void CompIR_RoundingMode(IRInst inst) = 0;119virtual void CompIR_Shift(IRInst inst) = 0;120virtual void CompIR_Store(IRInst inst) = 0;121virtual void CompIR_StoreShift(IRInst inst) = 0;122virtual void CompIR_System(IRInst inst) = 0;123virtual void CompIR_Transfer(IRInst inst) = 0;124virtual void CompIR_VecArith(IRInst inst) = 0;125virtual void CompIR_VecAssign(IRInst inst) = 0;126virtual void CompIR_VecClamp(IRInst inst) = 0;127virtual void CompIR_VecHoriz(IRInst inst) = 0;128virtual void CompIR_VecLoad(IRInst inst) = 0;129virtual void CompIR_VecPack(IRInst inst) = 0;130virtual void CompIR_VecStore(IRInst inst) = 0;131virtual void CompIR_ValidateAddress(IRInst inst) = 0;132133virtual void OverwriteExit(int srcOffset, int len, int block_num) = 0;134135// Returns true when debugging statistics should be compiled in.136bool DebugStatsEnabled() const;137bool DebugProfilerEnabled() const;138139// Callback (compile when DebugStatsEnabled()) to log a base interpreter hit.140// Call the func returned by MIPSGetInterpretFunc(op) directly for interpret.141static void NotifyMIPSInterpret(const char *name);142143// Callback to log AND perform a base interpreter op. Alternative to NotifyMIPSInterpret().144static void DoMIPSInst(uint32_t op);145146// Callback to log AND perform an IR interpreter inst. Returns 0 or a PC to jump to.147static uint32_t DoIRInst(uint64_t inst);148149static int ReportBadAddress(uint32_t addr, uint32_t alignment, uint32_t isWrite);150151void AddLinkableExit(int block_num, uint32_t pc, int exitStartOffset, int exitLen);152void EraseAllLinks(int block_num);153154IRNativeHooks hooks_;155IRBlockCache &blocks_;156std::vector<IRNativeBlock> nativeBlocks_;157std::unordered_multimap<uint32_t, int> linksTo_;158};159160class IRNativeBlockCacheDebugInterface : public JitBlockCacheDebugInterface {161public:162IRNativeBlockCacheDebugInterface(const MIPSComp::IRBlockCache &irBlocks);163void Init(const IRNativeBackend *backend);164int GetNumBlocks() const override;165int GetBlockNumberFromStartAddress(u32 em_address, bool realBlocksOnly = true) const override;166JitBlockDebugInfo GetBlockDebugInfo(int blockNum) const override;167JitBlockMeta GetBlockMeta(int blockNum) const override;168JitBlockProfileStats GetBlockProfileStats(int blockNum) const override;169void ComputeStats(BlockCacheStats &bcStats) const override;170bool IsValidBlock(int blockNum) const override;171172private:173void GetBlockCodeRange(int blockNum, int *startOffset, int *size) const;174175const MIPSComp::IRBlockCache &irBlocks_;176const CodeBlockCommon *codeBlock_ = nullptr;177const IRNativeBackend *backend_ = nullptr;178};179180class IRNativeJit : public IRJit {181public:182IRNativeJit(MIPSState *mipsState);183184void RunLoopUntil(u64 globalticks) override;185186void ClearCache() override;187188bool DescribeCodePtr(const u8 *ptr, std::string &name) override;189bool CodeInRange(const u8 *ptr) const override;190bool IsAtDispatchFetch(const u8 *ptr) const override;191const u8 *GetDispatcher() const override;192const u8 *GetCrashHandler() const override;193194void UpdateFCR31() override;195196JitBlockCacheDebugInterface *GetBlockCacheDebugInterface() override;197198protected:199void Init(IRNativeBackend &backend);200bool CompileNativeBlock(IRBlockCache *irBlockCache, int block_num, bool preload) override;201void FinalizeNativeBlock(IRBlockCache *irBlockCache, int block_num) override;202203IRNativeBackend *backend_ = nullptr;204IRNativeHooks hooks_;205IRNativeBlockCacheDebugInterface debugInterface_;206};207208} // namespace MIPSComp209210211