From 57123e8f9e17cf96995a644fdebaf6abbce016c0 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 19 Aug 2023 22:36:35 -0700 Subject: [PATCH] irjit: Reserve some arrays that churn. Improves IR compile time by around 20-30%. --- Core/MIPS/IR/IRInst.h | 3 +++ Core/MIPS/IR/IRJit.cpp | 1 + Core/MIPS/IR/IRPassSimplify.cpp | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/Core/MIPS/IR/IRInst.h b/Core/MIPS/IR/IRInst.h index 2b192a6890..f9131152af 100644 --- a/Core/MIPS/IR/IRInst.h +++ b/Core/MIPS/IR/IRInst.h @@ -375,6 +375,9 @@ public: int AddConstant(u32 value); int AddConstantFloat(float value); + void Reserve(size_t s) { + insts_.reserve(s); + } void Clear() { insts_.clear(); } diff --git a/Core/MIPS/IR/IRJit.cpp b/Core/MIPS/IR/IRJit.cpp index 44621c2dd5..e64dcf3ecd 100644 --- a/Core/MIPS/IR/IRJit.cpp +++ b/Core/MIPS/IR/IRJit.cpp @@ -168,6 +168,7 @@ void IRJit::CompileFunction(u32 start_address, u32 length) { // We may go up and down from branches, so track all block starts done here. std::set doneAddresses; std::vector pendingAddresses; + pendingAddresses.reserve(16); pendingAddresses.push_back(start_address); while (!pendingAddresses.empty()) { u32 em_address = pendingAddresses.back(); diff --git a/Core/MIPS/IR/IRPassSimplify.cpp b/Core/MIPS/IR/IRPassSimplify.cpp index 3c020edd4f..8f9485c11d 100644 --- a/Core/MIPS/IR/IRPassSimplify.cpp +++ b/Core/MIPS/IR/IRPassSimplify.cpp @@ -86,6 +86,8 @@ IROp ShiftToShiftImm(IROp op) { } bool IRApplyPasses(const IRPassFunc *passes, size_t c, const IRWriter &in, IRWriter &out, const IROptions &opts) { + out.Reserve(in.GetInstructions().size()); + if (c == 1) { return passes[0](in, out, opts); } @@ -95,6 +97,7 @@ bool IRApplyPasses(const IRPassFunc *passes, size_t c, const IRWriter &in, IRWri IRWriter temp[2]; const IRWriter *nextIn = ∈ IRWriter *nextOut = &temp[1]; + temp[1].Reserve(nextIn->GetInstructions().size()); for (size_t i = 0; i < c - 1; ++i) { if (passes[i](*nextIn, *nextOut, opts)) { logBlocks = true; @@ -102,8 +105,12 @@ bool IRApplyPasses(const IRPassFunc *passes, size_t c, const IRWriter &in, IRWri temp[0] = std::move(temp[1]); nextIn = &temp[0]; + + temp[1].Clear(); + temp[1].Reserve(nextIn->GetInstructions().size()); } + out.Reserve(nextIn->GetInstructions().size()); if (passes[c - 1](*nextIn, out, opts)) { logBlocks = true; } @@ -947,6 +954,8 @@ bool PurgeTemps(const IRWriter &in, IRWriter &out, const IROptions &opts) { int8_t fplen = 0; }; std::vector checks; + checks.reserve(insts.size() / 2); + // This tracks the last index at which each reg was modified. int lastWrittenTo[256]; int lastReadFrom[256];