rustc_codegen_llvm/llvm/
conversions.rs1use rustc_codegen_ssa::common::{AtomicRmwBinOp, IntPredicate, RealPredicate};
4use rustc_middle::ty::AtomicOrdering;
5use rustc_session::config::DebugInfo;
6use rustc_target::spec::SymbolVisibility;
7
8use crate::llvm;
9
10pub(crate) trait FromGeneric<T> {
13 fn from_generic(other: T) -> Self;
14}
15
16impl FromGeneric<SymbolVisibility> for llvm::Visibility {
17 fn from_generic(visibility: SymbolVisibility) -> Self {
18 match visibility {
19 SymbolVisibility::Hidden => Self::Hidden,
20 SymbolVisibility::Protected => Self::Protected,
21 SymbolVisibility::Interposable => Self::Default,
22 }
23 }
24}
25
26impl FromGeneric<IntPredicate> for llvm::IntPredicate {
27 fn from_generic(int_pred: IntPredicate) -> Self {
28 match int_pred {
29 IntPredicate::IntEQ => Self::IntEQ,
30 IntPredicate::IntNE => Self::IntNE,
31 IntPredicate::IntUGT => Self::IntUGT,
32 IntPredicate::IntUGE => Self::IntUGE,
33 IntPredicate::IntULT => Self::IntULT,
34 IntPredicate::IntULE => Self::IntULE,
35 IntPredicate::IntSGT => Self::IntSGT,
36 IntPredicate::IntSGE => Self::IntSGE,
37 IntPredicate::IntSLT => Self::IntSLT,
38 IntPredicate::IntSLE => Self::IntSLE,
39 }
40 }
41}
42
43impl FromGeneric<RealPredicate> for llvm::RealPredicate {
44 fn from_generic(real_pred: RealPredicate) -> Self {
45 match real_pred {
46 RealPredicate::RealPredicateFalse => Self::RealPredicateFalse,
47 RealPredicate::RealOEQ => Self::RealOEQ,
48 RealPredicate::RealOGT => Self::RealOGT,
49 RealPredicate::RealOGE => Self::RealOGE,
50 RealPredicate::RealOLT => Self::RealOLT,
51 RealPredicate::RealOLE => Self::RealOLE,
52 RealPredicate::RealONE => Self::RealONE,
53 RealPredicate::RealORD => Self::RealORD,
54 RealPredicate::RealUNO => Self::RealUNO,
55 RealPredicate::RealUEQ => Self::RealUEQ,
56 RealPredicate::RealUGT => Self::RealUGT,
57 RealPredicate::RealUGE => Self::RealUGE,
58 RealPredicate::RealULT => Self::RealULT,
59 RealPredicate::RealULE => Self::RealULE,
60 RealPredicate::RealUNE => Self::RealUNE,
61 RealPredicate::RealPredicateTrue => Self::RealPredicateTrue,
62 }
63 }
64}
65
66impl FromGeneric<AtomicRmwBinOp> for llvm::AtomicRmwBinOp {
67 fn from_generic(op: AtomicRmwBinOp) -> Self {
68 match op {
69 AtomicRmwBinOp::AtomicXchg => Self::AtomicXchg,
70 AtomicRmwBinOp::AtomicAdd => Self::AtomicAdd,
71 AtomicRmwBinOp::AtomicSub => Self::AtomicSub,
72 AtomicRmwBinOp::AtomicAnd => Self::AtomicAnd,
73 AtomicRmwBinOp::AtomicNand => Self::AtomicNand,
74 AtomicRmwBinOp::AtomicOr => Self::AtomicOr,
75 AtomicRmwBinOp::AtomicXor => Self::AtomicXor,
76 AtomicRmwBinOp::AtomicMax => Self::AtomicMax,
77 AtomicRmwBinOp::AtomicMin => Self::AtomicMin,
78 AtomicRmwBinOp::AtomicUMax => Self::AtomicUMax,
79 AtomicRmwBinOp::AtomicUMin => Self::AtomicUMin,
80 }
81 }
82}
83
84impl FromGeneric<AtomicOrdering> for llvm::AtomicOrdering {
85 fn from_generic(ordering: AtomicOrdering) -> Self {
86 match ordering {
87 AtomicOrdering::Relaxed => Self::Monotonic,
88 AtomicOrdering::Acquire => Self::Acquire,
89 AtomicOrdering::Release => Self::Release,
90 AtomicOrdering::AcqRel => Self::AcquireRelease,
91 AtomicOrdering::SeqCst => Self::SequentiallyConsistent,
92 }
93 }
94}
95
96impl FromGeneric<DebugInfo> for llvm::debuginfo::DebugEmissionKind {
97 fn from_generic(kind: DebugInfo) -> Self {
98 match kind {
109 DebugInfo::None => Self::NoDebug,
110 DebugInfo::LineDirectivesOnly => Self::DebugDirectivesOnly,
111 DebugInfo::LineTablesOnly => Self::LineTablesOnly,
112 DebugInfo::Limited | DebugInfo::Full => Self::FullDebug,
113 }
114 }
115}