about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2018-03-27 12:27:45 -0700
committerJosh Stone <jistone@redhat.com>2018-03-27 12:27:45 -0700
commita93a4d259ae3670d748859f430aba94f065ea6df (patch)
tree255366011c8f4b7d758b6adadb9724190926658d
parent9c9424de51da41fd3d1077ac7810276f8dc746fa (diff)
downloadrust-a93a4d259ae3670d748859f430aba94f065ea6df.tar.gz
rust-a93a4d259ae3670d748859f430aba94f065ea6df.zip
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`.
-rw-r--r--src/rustllvm/PassWrapper.cpp12
-rw-r--r--src/test/run-pass/sse2.rs6
2 files changed, 9 insertions, 9 deletions
diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp
index 3d5cce81278..382ef2cc407 100644
--- a/src/rustllvm/PassWrapper.cpp
+++ b/src/rustllvm/PassWrapper.cpp
@@ -205,17 +205,13 @@ GEN_SUBTARGETS
 
 extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
                                    const char *Feature) {
-#if LLVM_RUSTLLVM
+#if LLVM_VERSION_GE(6, 0)
   TargetMachine *Target = unwrap(TM);
   const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
-  const FeatureBitset &Bits = MCInfo->getFeatureBits();
-  const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
-
-  for (auto &FeatureEntry : FeatTable)
-    if (!strcmp(FeatureEntry.Key, Feature))
-      return (Bits & FeatureEntry.Value) == FeatureEntry.Value;
-#endif
+  return MCInfo->checkFeatures(std::string("+") + Feature);
+#else
   return false;
+#endif
 }
 
 enum class LLVMRustCodeModel {
diff --git a/src/test/run-pass/sse2.rs b/src/test/run-pass/sse2.rs
index 22469b2fde0..b1d7e5435c4 100644
--- a/src/test/run-pass/sse2.rs
+++ b/src/test/run-pass/sse2.rs
@@ -8,7 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// no-system-llvm -- needs MCSubtargetInfo::getFeatureTable()
+// min-llvm-version 6.0
+// ^ needs MCSubtargetInfo::checkFeatures()
 // ignore-cloudabi no std::env
 
 #![feature(cfg_target_feature)]
@@ -29,4 +30,7 @@ fn main() {
         assert!(cfg!(target_feature = "sse2"),
                 "SSE2 was not detected as available on an x86 platform");
     }
+    // check a negative case too -- whitelisted on x86, but not enabled by default
+    assert!(cfg!(not(target_feature = "avx2")),
+            "AVX2 shouldn't be detected as available by default on any platform");
 }