Skip to content

Commit f9e5fd7

Browse files
committed
Avoid heavy repetition in llvm/ffi.rs.
Through judicious use of `use` and `Self`.
1 parent b4f755b commit f9e5fd7

File tree

1 file changed

+67
-70
lines changed
  • compiler/rustc_codegen_llvm/src/llvm

1 file changed

+67
-70
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+67-70
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,18 @@ pub enum IntPredicate {
220220

221221
impl IntPredicate {
222222
pub fn from_generic(intpre: rustc_codegen_ssa::common::IntPredicate) -> Self {
223+
use rustc_codegen_ssa::common::IntPredicate as Common;
223224
match intpre {
224-
rustc_codegen_ssa::common::IntPredicate::IntEQ => IntPredicate::IntEQ,
225-
rustc_codegen_ssa::common::IntPredicate::IntNE => IntPredicate::IntNE,
226-
rustc_codegen_ssa::common::IntPredicate::IntUGT => IntPredicate::IntUGT,
227-
rustc_codegen_ssa::common::IntPredicate::IntUGE => IntPredicate::IntUGE,
228-
rustc_codegen_ssa::common::IntPredicate::IntULT => IntPredicate::IntULT,
229-
rustc_codegen_ssa::common::IntPredicate::IntULE => IntPredicate::IntULE,
230-
rustc_codegen_ssa::common::IntPredicate::IntSGT => IntPredicate::IntSGT,
231-
rustc_codegen_ssa::common::IntPredicate::IntSGE => IntPredicate::IntSGE,
232-
rustc_codegen_ssa::common::IntPredicate::IntSLT => IntPredicate::IntSLT,
233-
rustc_codegen_ssa::common::IntPredicate::IntSLE => IntPredicate::IntSLE,
225+
Common::IntEQ => Self::IntEQ,
226+
Common::IntNE => Self::IntNE,
227+
Common::IntUGT => Self::IntUGT,
228+
Common::IntUGE => Self::IntUGE,
229+
Common::IntULT => Self::IntULT,
230+
Common::IntULE => Self::IntULE,
231+
Common::IntSGT => Self::IntSGT,
232+
Common::IntSGE => Self::IntSGE,
233+
Common::IntSLT => Self::IntSLT,
234+
Common::IntSLE => Self::IntSLE,
234235
}
235236
}
236237
}
@@ -259,27 +260,24 @@ pub enum RealPredicate {
259260

260261
impl RealPredicate {
261262
pub fn from_generic(realp: rustc_codegen_ssa::common::RealPredicate) -> Self {
263+
use rustc_codegen_ssa::common::RealPredicate as Common;
262264
match realp {
263-
rustc_codegen_ssa::common::RealPredicate::RealPredicateFalse => {
264-
RealPredicate::RealPredicateFalse
265-
}
266-
rustc_codegen_ssa::common::RealPredicate::RealOEQ => RealPredicate::RealOEQ,
267-
rustc_codegen_ssa::common::RealPredicate::RealOGT => RealPredicate::RealOGT,
268-
rustc_codegen_ssa::common::RealPredicate::RealOGE => RealPredicate::RealOGE,
269-
rustc_codegen_ssa::common::RealPredicate::RealOLT => RealPredicate::RealOLT,
270-
rustc_codegen_ssa::common::RealPredicate::RealOLE => RealPredicate::RealOLE,
271-
rustc_codegen_ssa::common::RealPredicate::RealONE => RealPredicate::RealONE,
272-
rustc_codegen_ssa::common::RealPredicate::RealORD => RealPredicate::RealORD,
273-
rustc_codegen_ssa::common::RealPredicate::RealUNO => RealPredicate::RealUNO,
274-
rustc_codegen_ssa::common::RealPredicate::RealUEQ => RealPredicate::RealUEQ,
275-
rustc_codegen_ssa::common::RealPredicate::RealUGT => RealPredicate::RealUGT,
276-
rustc_codegen_ssa::common::RealPredicate::RealUGE => RealPredicate::RealUGE,
277-
rustc_codegen_ssa::common::RealPredicate::RealULT => RealPredicate::RealULT,
278-
rustc_codegen_ssa::common::RealPredicate::RealULE => RealPredicate::RealULE,
279-
rustc_codegen_ssa::common::RealPredicate::RealUNE => RealPredicate::RealUNE,
280-
rustc_codegen_ssa::common::RealPredicate::RealPredicateTrue => {
281-
RealPredicate::RealPredicateTrue
282-
}
265+
Common::RealPredicateFalse => Self::RealPredicateFalse,
266+
Common::RealOEQ => Self::RealOEQ,
267+
Common::RealOGT => Self::RealOGT,
268+
Common::RealOGE => Self::RealOGE,
269+
Common::RealOLT => Self::RealOLT,
270+
Common::RealOLE => Self::RealOLE,
271+
Common::RealONE => Self::RealONE,
272+
Common::RealORD => Self::RealORD,
273+
Common::RealUNO => Self::RealUNO,
274+
Common::RealUEQ => Self::RealUEQ,
275+
Common::RealUGT => Self::RealUGT,
276+
Common::RealUGE => Self::RealUGE,
277+
Common::RealULT => Self::RealULT,
278+
Common::RealULE => Self::RealULE,
279+
Common::RealUNE => Self::RealUNE,
280+
Common::RealPredicateTrue => Self::RealPredicateTrue,
283281
}
284282
}
285283
}
@@ -311,26 +309,27 @@ pub enum TypeKind {
311309

312310
impl TypeKind {
313311
pub fn to_generic(self) -> rustc_codegen_ssa::common::TypeKind {
312+
use rustc_codegen_ssa::common::TypeKind as Common;
314313
match self {
315-
TypeKind::Void => rustc_codegen_ssa::common::TypeKind::Void,
316-
TypeKind::Half => rustc_codegen_ssa::common::TypeKind::Half,
317-
TypeKind::Float => rustc_codegen_ssa::common::TypeKind::Float,
318-
TypeKind::Double => rustc_codegen_ssa::common::TypeKind::Double,
319-
TypeKind::X86_FP80 => rustc_codegen_ssa::common::TypeKind::X86_FP80,
320-
TypeKind::FP128 => rustc_codegen_ssa::common::TypeKind::FP128,
321-
TypeKind::PPC_FP128 => rustc_codegen_ssa::common::TypeKind::PPC_FP128,
322-
TypeKind::Label => rustc_codegen_ssa::common::TypeKind::Label,
323-
TypeKind::Integer => rustc_codegen_ssa::common::TypeKind::Integer,
324-
TypeKind::Function => rustc_codegen_ssa::common::TypeKind::Function,
325-
TypeKind::Struct => rustc_codegen_ssa::common::TypeKind::Struct,
326-
TypeKind::Array => rustc_codegen_ssa::common::TypeKind::Array,
327-
TypeKind::Pointer => rustc_codegen_ssa::common::TypeKind::Pointer,
328-
TypeKind::Vector => rustc_codegen_ssa::common::TypeKind::Vector,
329-
TypeKind::Metadata => rustc_codegen_ssa::common::TypeKind::Metadata,
330-
TypeKind::Token => rustc_codegen_ssa::common::TypeKind::Token,
331-
TypeKind::ScalableVector => rustc_codegen_ssa::common::TypeKind::ScalableVector,
332-
TypeKind::BFloat => rustc_codegen_ssa::common::TypeKind::BFloat,
333-
TypeKind::X86_AMX => rustc_codegen_ssa::common::TypeKind::X86_AMX,
314+
Self::Void => Common::Void,
315+
Self::Half => Common::Half,
316+
Self::Float => Common::Float,
317+
Self::Double => Common::Double,
318+
Self::X86_FP80 => Common::X86_FP80,
319+
Self::FP128 => Common::FP128,
320+
Self::PPC_FP128 => Common::PPC_FP128,
321+
Self::Label => Common::Label,
322+
Self::Integer => Common::Integer,
323+
Self::Function => Common::Function,
324+
Self::Struct => Common::Struct,
325+
Self::Array => Common::Array,
326+
Self::Pointer => Common::Pointer,
327+
Self::Vector => Common::Vector,
328+
Self::Metadata => Common::Metadata,
329+
Self::Token => Common::Token,
330+
Self::ScalableVector => Common::ScalableVector,
331+
Self::BFloat => Common::BFloat,
332+
Self::X86_AMX => Common::X86_AMX,
334333
}
335334
}
336335
}
@@ -354,18 +353,19 @@ pub enum AtomicRmwBinOp {
354353

355354
impl AtomicRmwBinOp {
356355
pub fn from_generic(op: rustc_codegen_ssa::common::AtomicRmwBinOp) -> Self {
356+
use rustc_codegen_ssa::common::AtomicRmwBinOp as Common;
357357
match op {
358-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg => AtomicRmwBinOp::AtomicXchg,
359-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicAdd => AtomicRmwBinOp::AtomicAdd,
360-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicSub => AtomicRmwBinOp::AtomicSub,
361-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicAnd => AtomicRmwBinOp::AtomicAnd,
362-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicNand => AtomicRmwBinOp::AtomicNand,
363-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicOr => AtomicRmwBinOp::AtomicOr,
364-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXor => AtomicRmwBinOp::AtomicXor,
365-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicMax => AtomicRmwBinOp::AtomicMax,
366-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicMin => AtomicRmwBinOp::AtomicMin,
367-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMax => AtomicRmwBinOp::AtomicUMax,
368-
rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMin => AtomicRmwBinOp::AtomicUMin,
358+
Common::AtomicXchg => Self::AtomicXchg,
359+
Common::AtomicAdd => Self::AtomicAdd,
360+
Common::AtomicSub => Self::AtomicSub,
361+
Common::AtomicAnd => Self::AtomicAnd,
362+
Common::AtomicNand => Self::AtomicNand,
363+
Common::AtomicOr => Self::AtomicOr,
364+
Common::AtomicXor => Self::AtomicXor,
365+
Common::AtomicMax => Self::AtomicMax,
366+
Common::AtomicMin => Self::AtomicMin,
367+
Common::AtomicUMax => Self::AtomicUMax,
368+
Common::AtomicUMin => Self::AtomicUMin,
369369
}
370370
}
371371
}
@@ -387,17 +387,14 @@ pub enum AtomicOrdering {
387387

388388
impl AtomicOrdering {
389389
pub fn from_generic(ao: rustc_codegen_ssa::common::AtomicOrdering) -> Self {
390+
use rustc_codegen_ssa::common::AtomicOrdering as Common;
390391
match ao {
391-
rustc_codegen_ssa::common::AtomicOrdering::Unordered => AtomicOrdering::Unordered,
392-
rustc_codegen_ssa::common::AtomicOrdering::Relaxed => AtomicOrdering::Monotonic,
393-
rustc_codegen_ssa::common::AtomicOrdering::Acquire => AtomicOrdering::Acquire,
394-
rustc_codegen_ssa::common::AtomicOrdering::Release => AtomicOrdering::Release,
395-
rustc_codegen_ssa::common::AtomicOrdering::AcquireRelease => {
396-
AtomicOrdering::AcquireRelease
397-
}
398-
rustc_codegen_ssa::common::AtomicOrdering::SequentiallyConsistent => {
399-
AtomicOrdering::SequentiallyConsistent
400-
}
392+
Common::Unordered => Self::Unordered,
393+
Common::Relaxed => Self::Monotonic,
394+
Common::Acquire => Self::Acquire,
395+
Common::Release => Self::Release,
396+
Common::AcquireRelease => Self::AcquireRelease,
397+
Common::SequentiallyConsistent => Self::SequentiallyConsistent,
401398
}
402399
}
403400
}

0 commit comments

Comments
 (0)