Skip to content

Commit a93a4d2

Browse files
committed
Enable target_feature on any LLVM 6+
In `LLVMRustHasFeature()`, rather than using `MCInfo->getFeatureTable()` that is specific to Rust's LLVM fork, we can use this in LLVM 6: /// Check whether the subtarget features are enabled/disabled as per /// the provided string, ignoring all other features. bool checkFeatures(StringRef FS) const; Now rustc using external LLVM can also have `target_feature`.
1 parent 9c9424d commit a93a4d2

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/rustllvm/PassWrapper.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,13 @@ GEN_SUBTARGETS
205205

206206
extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
207207
const char *Feature) {
208-
#if LLVM_RUSTLLVM
208+
#if LLVM_VERSION_GE(6, 0)
209209
TargetMachine *Target = unwrap(TM);
210210
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
211-
const FeatureBitset &Bits = MCInfo->getFeatureBits();
212-
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
213-
214-
for (auto &FeatureEntry : FeatTable)
215-
if (!strcmp(FeatureEntry.Key, Feature))
216-
return (Bits & FeatureEntry.Value) == FeatureEntry.Value;
217-
#endif
211+
return MCInfo->checkFeatures(std::string("+") + Feature);
212+
#else
218213
return false;
214+
#endif
219215
}
220216

221217
enum class LLVMRustCodeModel {

src/test/run-pass/sse2.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// no-system-llvm -- needs MCSubtargetInfo::getFeatureTable()
11+
// min-llvm-version 6.0
12+
// ^ needs MCSubtargetInfo::checkFeatures()
1213
// ignore-cloudabi no std::env
1314

1415
#![feature(cfg_target_feature)]
@@ -29,4 +30,7 @@ fn main() {
2930
assert!(cfg!(target_feature = "sse2"),
3031
"SSE2 was not detected as available on an x86 platform");
3132
}
33+
// check a negative case too -- whitelisted on x86, but not enabled by default
34+
assert!(cfg!(not(target_feature = "avx2")),
35+
"AVX2 shouldn't be detected as available by default on any platform");
3236
}

0 commit comments

Comments
 (0)