1
Fork 0

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);
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 {