From 6c003d68cd70f1885faf2312fbd0aa36266e2b3b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 31 May 2018 11:21:26 -0700 Subject: [PATCH] Factor out pointer_bits() and pointer_bytes() helper functions. --- lib/codegen/src/isa/mod.rs | 14 ++++++++++++-- lib/codegen/src/isa/x86/abi.rs | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/codegen/src/isa/mod.rs b/lib/codegen/src/isa/mod.rs index fc7c166bac..b68f9fecb7 100644 --- a/lib/codegen/src/isa/mod.rs +++ b/lib/codegen/src/isa/mod.rs @@ -176,7 +176,17 @@ pub trait TargetIsa: fmt::Display { /// Get the pointer type of this ISA. fn pointer_type(&self) -> ir::Type { - ir::Type::int(u16::from(self.triple().pointer_width().unwrap().bits())).unwrap() + ir::Type::int(u16::from(self.pointer_bits())).unwrap() + } + + /// Get the width of pointers on this ISA, in units of bits. + fn pointer_bits(&self) -> u8 { + self.triple().pointer_width().unwrap().bits() + } + + /// Get the width of pointers on this ISA, in units of bytes. + fn pointer_bytes(&self) -> u8 { + self.triple().pointer_width().unwrap().bytes() } /// Does the CPU implement scalar comparisons using a CPU flags register? @@ -277,7 +287,7 @@ pub trait TargetIsa: fmt::Display { use ir::stackslot::{StackOffset, StackSize}; use stack_layout::layout_stack; - let word_size = StackSize::from(self.triple().pointer_width().unwrap().bytes()); + let word_size = StackSize::from(self.pointer_bytes()); // Account for the SpiderMonkey standard prologue pushes. if func.signature.call_conv == CallConv::Baldrdash { diff --git a/lib/codegen/src/isa/x86/abi.rs b/lib/codegen/src/isa/x86/abi.rs index 89c5c30549..d10f406ab3 100644 --- a/lib/codegen/src/isa/x86/abi.rs +++ b/lib/codegen/src/isa/x86/abi.rs @@ -277,7 +277,7 @@ pub fn baldrdash_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> // Baldrdash on 32-bit x86 always aligns its stack pointer to 16 bytes. let stack_align = 16; - let word_size = StackSize::from(isa.triple().pointer_width().unwrap().bytes()); + let word_size = StackSize::from(isa.pointer_bytes()); let bytes = StackSize::from(isa.flags().baldrdash_prologue_words()) * word_size; let mut ss = ir::StackSlotData::new(ir::StackSlotKind::IncomingArg, bytes); @@ -299,7 +299,7 @@ pub fn fastcall_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> r // which are aligned to 16 bytes in order to aid performance" let stack_align = 16; - let word_size = isa.triple().pointer_width().unwrap().bytes() as usize; + let word_size = isa.pointer_bytes() as usize; let reg_type = isa.pointer_type(); let csrs = callee_saved_gprs_used(isa, func);