[llvm-dev] Compute CPU features available on a TargetMachine

Andrea Canciani via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 8 02:37:12 PST 2016


The Rust compiler needs to expose some compile-time flags that describe
what features are available on the target (so far this is mostly for SIMD
extensions).

What is the best way to query LLVM about the features that are available on
a given target?
I would love if it was possible to extract them from MCSubtargetInfo, but
even though the features are exposed through getFeatureBits(), it is
nontrivial to associate this bitset with the actual features.

So far I only managed to find a hackish way to do it: since the FeatureKV
tables are public, I scan through them to find out what feature is
associated with each enabled bit in the feature bitset.
This approach is implemented as part of
https://github.com/rust-lang/rust/pull/31709
It looks brittle, because the FeatureKV tables are public, but it is not
obvious whether they are meant to be accessed from outside of LLVM, and
more complicated than it should be.

I believe it would become very easy and more robust if the ProcFeatures
field of MCSubtargetInfo was exposed in some way, but I did not find any
way to access it.
Did I miss something obvious?

Thank you
Andrea
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160308/0b42eb07/attachment.html>


More information about the llvm-dev mailing list