[PATCH] D19189: Expose the list of available features in MCSubtargetInfo
Johan Engelen via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 24 01:50:50 PDT 2016
johanengelen added a comment.
I want to know whether a certain feature (say, "avx") is enabled for the current target.
This works for us though:
bool traitsTargetHasFeature(Dstring feature) {
auto feat = llvm::StringRef(feature.ptr, feature.len);
// Copy MCSubtargetInfo so we can modify it.
llvm::MCSubtargetInfo mcinfo = *gTargetMachine->getMCSubtargetInfo();
auto savedFeatbits = mcinfo.getFeatureBits();
// Nothing will change if the feature string is not recognized or if the
// feature is disabled.
{
auto newFeatbits = mcinfo.ApplyFeatureFlag(("-" + feat).str());
if (savedFeatbits == newFeatbits) {
return false;
}
mcinfo.setFeatureBits(savedFeatbits);
}
{
// Now that unrecognized feature strings are excluded,
// nothing will change iff the feature and its implied features are enabled.
auto newFeatbits = mcinfo.ApplyFeatureFlag(("+" + feat).str());
return savedFeatbits == newFeatbits;
}
}
http://reviews.llvm.org/D19189
More information about the llvm-commits
mailing list