aboutsummaryrefslogtreecommitdiffstats
path: root/yjit/src/backend/ir.rs
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-09-14 15:49:40 -0700
committerGitHub <noreply@github.com>2023-09-14 15:49:40 -0700
commit982d6503b9715d8b2fe07ab6b94b08601a34426d (patch)
tree61554a2b30dcbfc6469c0c81ecec186cf8fcc062 /yjit/src/backend/ir.rs
parent0ba6c603bca195064c5530009d72dd42ad42d153 (diff)
downloadruby-982d6503b9715d8b2fe07ab6b94b08601a34426d.tar.gz
YJIT: Skip Insn::Comment and format! if disasm is disabled (#8441)
* YJIT: Skip Insn::Comment and format! if disasm is disabled Co-authored-by: Alan Wu <alansi.xingwu@shopify.com> * YJIT: Get rid of asm.comment --------- Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
Diffstat (limited to 'yjit/src/backend/ir.rs')
-rw-r--r--yjit/src/backend/ir.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/yjit/src/backend/ir.rs b/yjit/src/backend/ir.rs
index 7477f375ac..c61a4e059b 100644
--- a/yjit/src/backend/ir.rs
+++ b/yjit/src/backend/ir.rs
@@ -1051,7 +1051,7 @@ impl Assembler
/// Append an instruction onto the current list of instructions and update
/// the live ranges of any instructions whose outputs are being used as
/// operands to this instruction.
- pub(super) fn push_insn(&mut self, insn: Insn) {
+ pub fn push_insn(&mut self, insn: Insn) {
// Index of this instruction
let insn_idx = self.insns.len();
@@ -1187,7 +1187,7 @@ impl Assembler
// Spill live stack temps
if self.ctx.get_reg_temps() != RegTemps::default() {
- self.comment(&format!("spill_temps: {:08b} -> {:08b}", self.ctx.get_reg_temps().as_u8(), RegTemps::default().as_u8()));
+ asm_comment!(self, "spill_temps: {:08b} -> {:08b}", self.ctx.get_reg_temps().as_u8(), RegTemps::default().as_u8());
for stack_idx in 0..u8::min(MAX_REG_TEMPS, self.ctx.get_stack_size()) {
if self.ctx.get_reg_temps().get(stack_idx) {
let idx = self.ctx.get_stack_size() - 1 - stack_idx;
@@ -1227,7 +1227,7 @@ impl Assembler
/// Update which stack temps are in a register
pub fn set_reg_temps(&mut self, reg_temps: RegTemps) {
if self.ctx.get_reg_temps() != reg_temps {
- self.comment(&format!("reg_temps: {:08b} -> {:08b}", self.ctx.get_reg_temps().as_u8(), reg_temps.as_u8()));
+ asm_comment!(self, "reg_temps: {:08b} -> {:08b}", self.ctx.get_reg_temps().as_u8(), reg_temps.as_u8());
self.ctx.set_reg_temps(reg_temps);
self.verify_reg_temps();
}
@@ -1723,10 +1723,6 @@ impl Assembler {
self.push_insn(Insn::Cmp { left, right });
}
- pub fn comment(&mut self, text: &str) {
- self.push_insn(Insn::Comment(text.to_string()));
- }
-
#[must_use]
pub fn cpop(&mut self) -> Opnd {
let out = self.next_opnd_out(Opnd::DEFAULT_NUM_BITS);
@@ -2002,6 +1998,17 @@ impl Assembler {
}
}
+/// Macro to use format! for Insn::Comment, which skips a format! call
+/// when disasm is not supported.
+macro_rules! asm_comment {
+ ($asm:expr, $($fmt:tt)*) => {
+ if cfg!(feature = "disasm") {
+ $asm.push_insn(Insn::Comment(format!($($fmt)*)));
+ }
+ };
+}
+pub(crate) use asm_comment;
+
#[cfg(test)]
mod tests {
use super::*;