mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-13 19:00:43 +02:00
Creates a pool allocator for OpcodeDispatcher and IRCompaction that shares memory allocations between threads in a pool and supports reclaiming stale allocations from participating threads. A thread will use a heuristic to keep its claimed memory allocation around if it is allocating a lot of code. If it slows down then it will start putting the memory allocation back in to the thread pool. Additionally if the allocation has been "disowned" and gone to sleep while still retaining the allocation, then another thread can inspect these stale allocations and reclaim it from the idling thread. Saving further memory. This needs some more work and cleanup but this is an interesting concept that saves a decent amount of memory even in a basic test. Causes teeworlds' title screen to go from 754MB to 599MB in my simple test. 79.4% the memory usage is a good start.
84 lines
2.5 KiB
C++
84 lines
2.5 KiB
C++
/*
|
|
$info$
|
|
meta: ir|opts ~ IR to IR Optimization
|
|
tags: ir|opts
|
|
desc: Defines which passes are run, and runs them
|
|
$end_info$
|
|
*/
|
|
|
|
#include "Interface/Context/Context.h"
|
|
#include "Interface/IR/PassManager.h"
|
|
#include "Interface/IR/Passes.h"
|
|
#include "Interface/IR/Passes/RegisterAllocationPass.h"
|
|
|
|
#include <FEXCore/Config/Config.h>
|
|
|
|
namespace FEXCore::IR {
|
|
class IREmitter;
|
|
|
|
void PassManager::AddDefaultPasses(FEXCore::Context::Context *ctx, bool InlineConstants, bool StaticRegisterAllocation) {
|
|
FEX_CONFIG_OPT(DisablePasses, O0);
|
|
|
|
if (!DisablePasses()) {
|
|
InsertPass(CreateContextLoadStoreElimination());
|
|
|
|
if (Is64BitMode()) {
|
|
// This needs to run after RCLSE
|
|
// This only matters for 64-bit code since these instructions don't exist in 32-bit
|
|
InsertPass(CreateLongDivideEliminationPass());
|
|
}
|
|
|
|
InsertPass(CreateDeadStoreElimination());
|
|
InsertPass(CreatePassDeadCodeElimination());
|
|
InsertPass(CreateConstProp(InlineConstants));
|
|
|
|
////// InsertPass(CreateDeadFlagCalculationEliminination());
|
|
|
|
InsertPass(CreateSyscallOptimization());
|
|
InsertPass(CreatePassDeadCodeElimination());
|
|
|
|
// only do SRA if enabled and JIT
|
|
if (InlineConstants && StaticRegisterAllocation)
|
|
InsertPass(CreateStaticRegisterAllocationPass());
|
|
}
|
|
else {
|
|
// only do SRA if enabled and JIT
|
|
if (InlineConstants && StaticRegisterAllocation)
|
|
InsertPass(CreateStaticRegisterAllocationPass());
|
|
}
|
|
|
|
// If the IR is compacted post-RA then the node indexing gets messed up and the backend isn't able to find the register assigned to a node
|
|
// Compact before IR, don't worry about RA generating spills/fills
|
|
InsertPass(CreateIRCompaction(ctx->OpDispatcherAllocator), "Compaction");
|
|
}
|
|
|
|
void PassManager::AddDefaultValidationPasses() {
|
|
#if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED
|
|
InsertValidationPass(Validation::CreatePhiValidation());
|
|
InsertValidationPass(Validation::CreateIRValidation(), "IRValidation");
|
|
InsertValidationPass(Validation::CreateRAValidation());
|
|
InsertValidationPass(Validation::CreateValueDominanceValidation());
|
|
#endif
|
|
}
|
|
|
|
void PassManager::InsertRegisterAllocationPass(bool OptimizeSRA) {
|
|
InsertPass(IR::CreateRegisterAllocationPass(GetPass("Compaction"), OptimizeSRA), "RA");
|
|
}
|
|
|
|
bool PassManager::Run(IREmitter *IREmit) {
|
|
bool Changed = false;
|
|
for (auto const &Pass : Passes) {
|
|
Changed |= Pass->Run(IREmit);
|
|
}
|
|
|
|
#if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED
|
|
for (auto const &Pass : ValidationPasses) {
|
|
Changed |= Pass->Run(IREmit);
|
|
}
|
|
#endif
|
|
|
|
return Changed;
|
|
}
|
|
|
|
}
|