Make LLVMRustHasFeature more robust

The function should accept feature strings that old LLVM might not
support.

Simplify the code using the same approach used by
LLVMRustPrintTargetFeatures.

Dummify the function for non 4.0 LLVM and update the tests accordingly.
This commit is contained in:
Luca Barbato 2017-07-28 02:03:23 +00:00
parent cbce0aa341
commit c4710203c0
3 changed files with 9 additions and 14 deletions

View file

@ -181,20 +181,14 @@ extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
TargetMachine *Target = unwrap(TM); TargetMachine *Target = unwrap(TM);
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo(); const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
const FeatureBitset &Bits = MCInfo->getFeatureBits(); const FeatureBitset &Bits = MCInfo->getFeatureBits();
const llvm::SubtargetFeatureKV *FeatureEntry; #if LLVM_VERSION_GE(4, 0)
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
#define SUBTARGET(x) \ for (auto &FeatureEntry : FeatTable)
if (MCInfo->isCPUStringValid(x##SubTypeKV[0].Key)) { \ if (!strcmp(FeatureEntry.Key, Feature))
FeatureEntry = x##FeatureKV; \ return (Bits & FeatureEntry.Value) == FeatureEntry.Value;
} else #endif
return false;
GEN_SUBTARGETS { return false; }
#undef SUBTARGET
while (strcmp(Feature, FeatureEntry->Key) != 0)
FeatureEntry++;
return (Bits & FeatureEntry->Value) == FeatureEntry->Value;
} }
enum class LLVMRustCodeModel { enum class LLVMRustCodeModel {

View file

@ -5,7 +5,7 @@ all: default
$(RUSTC) --target x86_64-pc-windows-gnu --print cfg | grep x86_64 $(RUSTC) --target x86_64-pc-windows-gnu --print cfg | grep x86_64
$(RUSTC) --target i686-pc-windows-msvc --print cfg | grep msvc $(RUSTC) --target i686-pc-windows-msvc --print cfg | grep msvc
$(RUSTC) --target i686-apple-darwin --print cfg | grep macos $(RUSTC) --target i686-apple-darwin --print cfg | grep macos
$(RUSTC) --target i686-unknown-linux-gnu --print cfg | grep sse2 $(RUSTC) --target i686-unknown-linux-gnu --print cfg | grep gnu
ifdef IS_WINDOWS ifdef IS_WINDOWS
default: default:

View file

@ -7,6 +7,7 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// min-llvm-version 4.0
#![feature(cfg_target_feature)] #![feature(cfg_target_feature)]