diff --git a/lib/codegen/src/ir/types.rs b/lib/codegen/src/ir/types.rs index c7f6d12f23..ceffe04e9c 100644 --- a/lib/codegen/src/ir/types.rs +++ b/lib/codegen/src/ir/types.rs @@ -2,6 +2,7 @@ use std::default::Default; use std::fmt::{self, Debug, Display, Formatter}; +use target_lexicon::{PointerWidth, Triple}; /// The type of an SSA value. /// @@ -271,6 +272,16 @@ impl Type { pub fn wider_or_equal(self, other: Self) -> bool { self.lane_count() == other.lane_count() && self.lane_bits() >= other.lane_bits() } + + /// Return the pointer type for the given target triple. + pub fn triple_pointer_type(triple: &Triple) -> Self { + match triple.pointer_width() { + Ok(PointerWidth::U16) => I16, + Ok(PointerWidth::U32) => I32, + Ok(PointerWidth::U64) => I64, + Err(()) => panic!("unable to determine architecture pointer width"), + } + } } impl Display for Type { diff --git a/lib/codegen/src/isa/call_conv.rs b/lib/codegen/src/isa/call_conv.rs index 0fe242b958..9caff3ebaa 100644 --- a/lib/codegen/src/isa/call_conv.rs +++ b/lib/codegen/src/isa/call_conv.rs @@ -21,7 +21,7 @@ pub enum CallConv { impl CallConv { /// Return the default calling convention for the given target triple. - pub fn default_for_triple(triple: &Triple) -> Self { + pub fn triple_default(triple: &Triple) -> Self { match triple.default_calling_convention() { // Default to System V for unknown targets because most everything // uses System V. diff --git a/lib/codegen/src/isa/mod.rs b/lib/codegen/src/isa/mod.rs index b4bf97d334..d8eba6ccc3 100644 --- a/lib/codegen/src/isa/mod.rs +++ b/lib/codegen/src/isa/mod.rs @@ -208,7 +208,7 @@ pub trait TargetIsa: fmt::Display + Sync { /// Get the default calling convention of this target. fn default_call_conv(&self) -> CallConv { - CallConv::default_for_triple(self.triple()) + CallConv::triple_default(self.triple()) } /// Get the pointer type of this ISA.