[PATCH] D19189: Expose the list of available features in MCSubtargetInfo
Johan Engelen via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 16 05:19:35 PDT 2016
johanengelen created this revision.
johanengelen added reviewers: grosbach, mkuper.
johanengelen added a subscriber: llvm-commits.
I have not found a way to obtain a list of features available for the target machine. MCSubtargetInfo provides the getFeatureBits() method, but I have not found a way to translate the FeatureBitset to feature names (e.g. "sse2", "avx") or their description. MCSubtargetInfo does contain a reference to that information but does not expose that to the user.
This patch exposes the private ProcFeatures list to user code, similar to exposing the FeatureBits.
I intend to use this in our front-end (LDC) to check whether a feature is enabled or not:
```
auto *mcinfo = gTargetMachine->getMCSubtargetInfo();
auto featbits = mcinfo->getFeatureBits();
auto featTable = mcinfo->getProcFeatures();
for (auto &feat : featTable) {
if ((featbits & feat.Value) == feat.Value)
//check if feat.Key is equal to the feature we seek
}
```
Thanks for reviewing.
http://reviews.llvm.org/D19189
Files:
include/llvm/MC/MCSubtargetInfo.h
Index: include/llvm/MC/MCSubtargetInfo.h
===================================================================
--- include/llvm/MC/MCSubtargetInfo.h
+++ include/llvm/MC/MCSubtargetInfo.h
@@ -78,6 +78,14 @@
FeatureBits = FeatureBits_;
}
+ /// getProcFeatures - Return the subtarget feature list.
+ ///
+ /// Use this list in conjunction with getFeatureBits() to get which features
+ /// are enabled for the current CPU.
+ ArrayRef<SubtargetFeatureKV> getProcFeatures() const {
+ return ProcFeatures;
+ }
+
protected:
/// Initialize the scheduling model and feature bits.
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19189.53985.patch
Type: text/x-patch
Size: 598 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160416/ce21f4ca/attachment.bin>
More information about the llvm-commits
mailing list