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:
parent
cbce0aa341
commit
c4710203c0
@ -181,20 +181,14 @@ extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
|
||||
TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const FeatureBitset &Bits = MCInfo->getFeatureBits();
|
||||
const llvm::SubtargetFeatureKV *FeatureEntry;
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
|
||||
|
||||
#define SUBTARGET(x) \
|
||||
if (MCInfo->isCPUStringValid(x##SubTypeKV[0].Key)) { \
|
||||
FeatureEntry = x##FeatureKV; \
|
||||
} else
|
||||
|
||||
GEN_SUBTARGETS { return false; }
|
||||
#undef SUBTARGET
|
||||
|
||||
while (strcmp(Feature, FeatureEntry->Key) != 0)
|
||||
FeatureEntry++;
|
||||
|
||||
return (Bits & FeatureEntry->Value) == FeatureEntry->Value;
|
||||
for (auto &FeatureEntry : FeatTable)
|
||||
if (!strcmp(FeatureEntry.Key, Feature))
|
||||
return (Bits & FeatureEntry.Value) == FeatureEntry.Value;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
enum class LLVMRustCodeModel {
|
||||
|
@ -5,7 +5,7 @@ all: default
|
||||
$(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-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
|
||||
default:
|
||||
|
@ -7,6 +7,7 @@
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
// min-llvm-version 4.0
|
||||
|
||||
#![feature(cfg_target_feature)]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user