From 4179f4026410314bee17461bc33de47943494d48 Mon Sep 17 00:00:00 2001 From: lzkk <956449176@qq.com> Date: Thu, 28 May 2026 13:16:24 +0800 Subject: [PATCH] =?UTF-8?q?perf(mir):=20leaf=20=E5=87=BD=E6=95=B0=E7=9C=81?= =?UTF-8?q?=E7=95=A5=E5=B8=A7=E6=8C=87=E9=92=88=E2=80=94=E2=80=94=E6=97=A0?= =?UTF-8?q?=E8=B0=83=E7=94=A8+=E6=97=A0=E6=A0=88=E5=B8=A7=E6=97=B6?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=20stp/ldp=20x29,x30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit crypto 1482→1458(-24 指令),crc 306→303。 --- src/mir/AsmPrinter.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/mir/AsmPrinter.cpp b/src/mir/AsmPrinter.cpp index ab451cd0..a29d65d1 100644 --- a/src/mir/AsmPrinter.cpp +++ b/src/mir/AsmPrinter.cpp @@ -422,6 +422,18 @@ namespace mir case Opcode::Prologue: { const auto &cs_regs = function.GetCalleeSavedRegs(); + // 若函数无需帧(leaf + 无栈槽 + 无被调用者保存寄存器),跳过帧设置 + bool has_frame = function.GetFrameSize() > 0 || !cs_regs.empty(); + if (!has_frame) { + // 检查是否有 Call 指令,若有则需要保存 LR + for (const auto &blk : function.GetBlocks()) { + for (const auto &i : blk->GetInstructions()) { + if (i.GetOpcode() == Opcode::Call) { has_frame = true; break; } + } + if (has_frame) break; + } + } + if (!has_frame) return; // leaf 函数,无需帧 os << " stp x29, x30, [sp, #-16]!\n"; os << " mov x29, sp\n"; if (function.GetFrameSize() > 0) @@ -448,6 +460,16 @@ namespace mir case Opcode::Epilogue: { const auto &cs_regs = function.GetCalleeSavedRegs(); + bool has_frame = function.GetFrameSize() > 0 || !cs_regs.empty(); + if (!has_frame) { + for (const auto &blk : function.GetBlocks()) { + for (const auto &i : blk->GetInstructions()) { + if (i.GetOpcode() == Opcode::Call) { has_frame = true; break; } + } + if (has_frame) break; + } + } + if (!has_frame) { os << " ret\n"; return; } int cs_offset = 0; for (auto r : cs_regs) {