|
| 1 | +use syntax::symbol::{sym, Symbol}; |
| 2 | + |
| 3 | +use rustc::session::Session; |
| 4 | + |
| 5 | +// Copied from https://github.com/rust-lang/rust/blob/f69b07144a151f46aaee1b6230ba4160e9394562/src/librustc_codegen_llvm/llvm_util.rs#L93-L264 |
| 6 | + |
| 7 | +// WARNING: the features after applying `to_llvm_feature` must be known |
| 8 | +// to LLVM or the feature detection code will walk past the end of the feature |
| 9 | +// array, leading to crashes. |
| 10 | + |
| 11 | +const ARM_WHITELIST: &[(&str, Option<Symbol>)] = &[ |
| 12 | + ("aclass", Some(sym::arm_target_feature)), |
| 13 | + ("mclass", Some(sym::arm_target_feature)), |
| 14 | + ("rclass", Some(sym::arm_target_feature)), |
| 15 | + ("dsp", Some(sym::arm_target_feature)), |
| 16 | + ("neon", Some(sym::arm_target_feature)), |
| 17 | + ("v5te", Some(sym::arm_target_feature)), |
| 18 | + ("v6", Some(sym::arm_target_feature)), |
| 19 | + ("v6k", Some(sym::arm_target_feature)), |
| 20 | + ("v6t2", Some(sym::arm_target_feature)), |
| 21 | + ("v7", Some(sym::arm_target_feature)), |
| 22 | + ("v8", Some(sym::arm_target_feature)), |
| 23 | + ("vfp2", Some(sym::arm_target_feature)), |
| 24 | + ("vfp3", Some(sym::arm_target_feature)), |
| 25 | + ("vfp4", Some(sym::arm_target_feature)), |
| 26 | +]; |
| 27 | + |
| 28 | +const AARCH64_WHITELIST: &[(&str, Option<Symbol>)] = &[ |
| 29 | + ("fp", Some(sym::aarch64_target_feature)), |
| 30 | + ("neon", Some(sym::aarch64_target_feature)), |
| 31 | + ("sve", Some(sym::aarch64_target_feature)), |
| 32 | + ("crc", Some(sym::aarch64_target_feature)), |
| 33 | + ("crypto", Some(sym::aarch64_target_feature)), |
| 34 | + ("ras", Some(sym::aarch64_target_feature)), |
| 35 | + ("lse", Some(sym::aarch64_target_feature)), |
| 36 | + ("rdm", Some(sym::aarch64_target_feature)), |
| 37 | + ("fp16", Some(sym::aarch64_target_feature)), |
| 38 | + ("rcpc", Some(sym::aarch64_target_feature)), |
| 39 | + ("dotprod", Some(sym::aarch64_target_feature)), |
| 40 | + ("v8.1a", Some(sym::aarch64_target_feature)), |
| 41 | + ("v8.2a", Some(sym::aarch64_target_feature)), |
| 42 | + ("v8.3a", Some(sym::aarch64_target_feature)), |
| 43 | +]; |
| 44 | + |
| 45 | +const X86_WHITELIST: &[(&str, Option<Symbol>)] = &[ |
| 46 | + ("adx", Some(sym::adx_target_feature)), |
| 47 | + ("aes", None), |
| 48 | + ("avx", None), |
| 49 | + ("avx2", None), |
| 50 | + ("avx512bw", Some(sym::avx512_target_feature)), |
| 51 | + ("avx512cd", Some(sym::avx512_target_feature)), |
| 52 | + ("avx512dq", Some(sym::avx512_target_feature)), |
| 53 | + ("avx512er", Some(sym::avx512_target_feature)), |
| 54 | + ("avx512f", Some(sym::avx512_target_feature)), |
| 55 | + ("avx512ifma", Some(sym::avx512_target_feature)), |
| 56 | + ("avx512pf", Some(sym::avx512_target_feature)), |
| 57 | + ("avx512vbmi", Some(sym::avx512_target_feature)), |
| 58 | + ("avx512vl", Some(sym::avx512_target_feature)), |
| 59 | + ("avx512vpopcntdq", Some(sym::avx512_target_feature)), |
| 60 | + ("bmi1", None), |
| 61 | + ("bmi2", None), |
| 62 | + ("cmpxchg16b", Some(sym::cmpxchg16b_target_feature)), |
| 63 | + ("f16c", Some(sym::f16c_target_feature)), |
| 64 | + ("fma", None), |
| 65 | + ("fxsr", None), |
| 66 | + ("lzcnt", None), |
| 67 | + ("mmx", Some(sym::mmx_target_feature)), |
| 68 | + ("movbe", Some(sym::movbe_target_feature)), |
| 69 | + ("pclmulqdq", None), |
| 70 | + ("popcnt", None), |
| 71 | + ("rdrand", None), |
| 72 | + ("rdseed", None), |
| 73 | + ("rtm", Some(sym::rtm_target_feature)), |
| 74 | + ("sha", None), |
| 75 | + ("sse", None), |
| 76 | + ("sse2", None), |
| 77 | + ("sse3", None), |
| 78 | + ("sse4.1", None), |
| 79 | + ("sse4.2", None), |
| 80 | + ("sse4a", Some(sym::sse4a_target_feature)), |
| 81 | + ("ssse3", None), |
| 82 | + ("tbm", Some(sym::tbm_target_feature)), |
| 83 | + ("xsave", None), |
| 84 | + ("xsavec", None), |
| 85 | + ("xsaveopt", None), |
| 86 | + ("xsaves", None), |
| 87 | +]; |
| 88 | + |
| 89 | +const HEXAGON_WHITELIST: &[(&str, Option<Symbol>)] = &[ |
| 90 | + ("hvx", Some(sym::hexagon_target_feature)), |
| 91 | + ("hvx-double", Some(sym::hexagon_target_feature)), |
| 92 | +]; |
| 93 | + |
| 94 | +const POWERPC_WHITELIST: &[(&str, Option<Symbol>)] = &[ |
| 95 | + ("altivec", Some(sym::powerpc_target_feature)), |
| 96 | + ("power8-altivec", Some(sym::powerpc_target_feature)), |
| 97 | + ("power9-altivec", Some(sym::powerpc_target_feature)), |
| 98 | + ("power8-vector", Some(sym::powerpc_target_feature)), |
| 99 | + ("power9-vector", Some(sym::powerpc_target_feature)), |
| 100 | + ("vsx", Some(sym::powerpc_target_feature)), |
| 101 | +]; |
| 102 | + |
| 103 | +const MIPS_WHITELIST: &[(&str, Option<Symbol>)] = &[ |
| 104 | + ("fp64", Some(sym::mips_target_feature)), |
| 105 | + ("msa", Some(sym::mips_target_feature)), |
| 106 | +]; |
| 107 | + |
| 108 | +const WASM_WHITELIST: &[(&str, Option<Symbol>)] = &[ |
| 109 | + ("simd128", Some(sym::wasm_target_feature)), |
| 110 | + ("atomics", Some(sym::wasm_target_feature)), |
| 111 | +]; |
| 112 | + |
| 113 | +/// When rustdoc is running, provide a list of all known features so that all their respective |
| 114 | +/// primitives may be documented. |
| 115 | +/// |
| 116 | +/// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this |
| 117 | +/// iterator! |
| 118 | +pub fn all_known_features() -> impl Iterator<Item=(&'static str, Option<Symbol>)> { |
| 119 | + ARM_WHITELIST.iter().cloned() |
| 120 | + .chain(AARCH64_WHITELIST.iter().cloned()) |
| 121 | + .chain(X86_WHITELIST.iter().cloned()) |
| 122 | + .chain(HEXAGON_WHITELIST.iter().cloned()) |
| 123 | + .chain(POWERPC_WHITELIST.iter().cloned()) |
| 124 | + .chain(MIPS_WHITELIST.iter().cloned()) |
| 125 | + .chain(WASM_WHITELIST.iter().cloned()) |
| 126 | +} |
| 127 | + |
| 128 | +pub fn target_feature_whitelist(sess: &Session) |
| 129 | + -> &'static [(&'static str, Option<Symbol>)] |
| 130 | +{ |
| 131 | + match &*sess.target.target.arch { |
| 132 | + "arm" => ARM_WHITELIST, |
| 133 | + "aarch64" => AARCH64_WHITELIST, |
| 134 | + "x86" | "x86_64" => X86_WHITELIST, |
| 135 | + "hexagon" => HEXAGON_WHITELIST, |
| 136 | + "mips" | "mips64" => MIPS_WHITELIST, |
| 137 | + "powerpc" | "powerpc64" => POWERPC_WHITELIST, |
| 138 | + // wasm32 on emscripten does not support these target features |
| 139 | + "wasm32" if !sess.target.target.options.is_like_emscripten => WASM_WHITELIST, |
| 140 | + _ => &[], |
| 141 | + } |
| 142 | +} |
0 commit comments