Skip to content

Commit c7c534f

Browse files
committed
Move llvm_target_features back to llvm_util
1 parent 6797436 commit c7c534f

File tree

4 files changed

+118
-133
lines changed

4 files changed

+118
-133
lines changed

src/librustc_codegen_llvm/llvm_util.rs

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ use syntax::feature_gate::UnstableFeatures;
2020
use std::sync::atomic::{AtomicBool, Ordering};
2121
use std::sync::Once;
2222

23-
pub use rustc_codegen_utils::llvm_target_features::*;
24-
2523
static POISONED: AtomicBool = AtomicBool::new(false);
2624
static INIT: Once = Once::new();
2725

@@ -81,6 +79,108 @@ unsafe fn configure_llvm(sess: &Session) {
8179
llvm_args.as_ptr());
8280
}
8381

82+
// WARNING: the features after applying `to_llvm_feature` must be known
83+
// to LLVM or the feature detection code will walk past the end of the feature
84+
// array, leading to crashes.
85+
86+
const ARM_WHITELIST: &[(&str, Option<&str>)] = &[
87+
("mclass", Some("arm_target_feature")),
88+
("neon", Some("arm_target_feature")),
89+
("v7", Some("arm_target_feature")),
90+
("vfp2", Some("arm_target_feature")),
91+
("vfp3", Some("arm_target_feature")),
92+
("vfp4", Some("arm_target_feature")),
93+
];
94+
95+
const AARCH64_WHITELIST: &[(&str, Option<&str>)] = &[
96+
("fp", Some("aarch64_target_feature")),
97+
("neon", Some("aarch64_target_feature")),
98+
("sve", Some("aarch64_target_feature")),
99+
("crc", Some("aarch64_target_feature")),
100+
("crypto", Some("aarch64_target_feature")),
101+
("ras", Some("aarch64_target_feature")),
102+
("lse", Some("aarch64_target_feature")),
103+
("rdm", Some("aarch64_target_feature")),
104+
("fp16", Some("aarch64_target_feature")),
105+
("rcpc", Some("aarch64_target_feature")),
106+
("dotprod", Some("aarch64_target_feature")),
107+
("v8.1a", Some("aarch64_target_feature")),
108+
("v8.2a", Some("aarch64_target_feature")),
109+
("v8.3a", Some("aarch64_target_feature")),
110+
];
111+
112+
const X86_WHITELIST: &[(&str, Option<&str>)] = &[
113+
("aes", None),
114+
("avx", None),
115+
("avx2", None),
116+
("avx512bw", Some("avx512_target_feature")),
117+
("avx512cd", Some("avx512_target_feature")),
118+
("avx512dq", Some("avx512_target_feature")),
119+
("avx512er", Some("avx512_target_feature")),
120+
("avx512f", Some("avx512_target_feature")),
121+
("avx512ifma", Some("avx512_target_feature")),
122+
("avx512pf", Some("avx512_target_feature")),
123+
("avx512vbmi", Some("avx512_target_feature")),
124+
("avx512vl", Some("avx512_target_feature")),
125+
("avx512vpopcntdq", Some("avx512_target_feature")),
126+
("bmi1", None),
127+
("bmi2", None),
128+
("fma", None),
129+
("fxsr", None),
130+
("lzcnt", None),
131+
("mmx", Some("mmx_target_feature")),
132+
("pclmulqdq", None),
133+
("popcnt", None),
134+
("rdrand", None),
135+
("rdseed", None),
136+
("sha", None),
137+
("sse", None),
138+
("sse2", None),
139+
("sse3", None),
140+
("sse4.1", None),
141+
("sse4.2", None),
142+
("sse4a", Some("sse4a_target_feature")),
143+
("ssse3", None),
144+
("tbm", Some("tbm_target_feature")),
145+
("xsave", None),
146+
("xsavec", None),
147+
("xsaveopt", None),
148+
("xsaves", None),
149+
];
150+
151+
const HEXAGON_WHITELIST: &[(&str, Option<&str>)] = &[
152+
("hvx", Some("hexagon_target_feature")),
153+
("hvx-double", Some("hexagon_target_feature")),
154+
];
155+
156+
const POWERPC_WHITELIST: &[(&str, Option<&str>)] = &[
157+
("altivec", Some("powerpc_target_feature")),
158+
("power8-altivec", Some("powerpc_target_feature")),
159+
("power9-altivec", Some("powerpc_target_feature")),
160+
("power8-vector", Some("powerpc_target_feature")),
161+
("power9-vector", Some("powerpc_target_feature")),
162+
("vsx", Some("powerpc_target_feature")),
163+
];
164+
165+
const MIPS_WHITELIST: &[(&str, Option<&str>)] = &[
166+
("fp64", Some("mips_target_feature")),
167+
("msa", Some("mips_target_feature")),
168+
];
169+
170+
/// When rustdoc is running, provide a list of all known features so that all their respective
171+
/// primtives may be documented.
172+
///
173+
/// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this
174+
/// iterator!
175+
pub fn all_known_features() -> impl Iterator<Item=(&'static str, Option<&'static str>)> {
176+
ARM_WHITELIST.iter().cloned()
177+
.chain(AARCH64_WHITELIST.iter().cloned())
178+
.chain(X86_WHITELIST.iter().cloned())
179+
.chain(HEXAGON_WHITELIST.iter().cloned())
180+
.chain(POWERPC_WHITELIST.iter().cloned())
181+
.chain(MIPS_WHITELIST.iter().cloned())
182+
}
183+
84184
pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> &'a str {
85185
let arch = if sess.target.target.arch == "x86_64" {
86186
"x86"
@@ -116,6 +216,20 @@ pub fn target_features(sess: &Session) -> Vec<Symbol> {
116216
.map(|feature| Symbol::intern(feature)).collect()
117217
}
118218

219+
pub fn target_feature_whitelist(sess: &Session)
220+
-> &'static [(&'static str, Option<&'static str>)]
221+
{
222+
match &*sess.target.target.arch {
223+
"arm" => ARM_WHITELIST,
224+
"aarch64" => AARCH64_WHITELIST,
225+
"x86" | "x86_64" => X86_WHITELIST,
226+
"hexagon" => HEXAGON_WHITELIST,
227+
"mips" | "mips64" => MIPS_WHITELIST,
228+
"powerpc" | "powerpc64" => POWERPC_WHITELIST,
229+
_ => &[],
230+
}
231+
}
232+
119233
pub fn print_version() {
120234
// Can be called without initializing LLVM
121235
unsafe {

src/librustc_codegen_utils/codegen_backend.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use rustc::middle::cstore::EncodedMetadata;
4242
use rustc::middle::cstore::MetadataLoader;
4343
use rustc::dep_graph::DepGraph;
4444
use rustc_target::spec::Target;
45+
use rustc_data_structures::fx::FxHashMap;
4546
use rustc_mir::monomorphize::collector;
4647
use link::{build_link_meta, out_filename};
4748

@@ -132,9 +133,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
132133
::symbol_names::provide(providers);
133134

134135
providers.target_features_whitelist = |_tcx, _cnum| {
135-
Lrc::new(::llvm_target_features::all_known_features()
136-
.map(|(a, b)| (a.to_string(), b.map(|s| s.to_string())))
137-
.collect())
136+
Lrc::new(FxHashMap()) // Just a dummy
138137
};
139138
providers.is_reachable_non_generic = |_tcx, _defid| true;
140139
providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new());

src/librustc_codegen_utils/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub mod link;
4444
pub mod codegen_backend;
4545
pub mod symbol_names;
4646
pub mod symbol_names_test;
47-
pub mod llvm_target_features;
4847

4948
/// check for the #[rustc_error] annotation, which forces an
5049
/// error in codegen. This is used to write compile-fail tests

src/librustc_codegen_utils/llvm_target_features.rs

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)