[PATCH] D106503: MCSubtargetInfo: Add debugging 'features' that dump current CPU bit state

George Burgess IV via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 21 15:27:30 PDT 2021


george.burgess.iv created this revision.
george.burgess.iv added a reviewer: arsenm.
Herald added subscribers: JDevlieghere, hiraditya.
george.burgess.iv requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

It's quite useful to know which feature bits are on/off when trying to
figure out how to translate strings of `clang`
`-march`/`-mfpu`/`-mcpu`/... arguments to other compilers (e.g.,
`rustc`). This support doesn't seem to exist, but there's precedent for
having 'special' target strings that translate to printing to stderr.
This builds on that precedent.

I don't know how much testing *should* go into this, since it's
focused on LLVM development more than anything. It's notable that
this also breaks from existing precedent in this file -- namely, it doesn't
have a `static bool` that only lets us print things once. This enables
users to do things like:

  "target-features" = "+foo,+dump-enabled,-bar,+dump-enabled"

So they can easily tell what effect `-bar` has on features enabled in
the backend.


https://reviews.llvm.org/D106503

Files:
  llvm/lib/MC/MCSubtargetInfo.cpp


Index: llvm/lib/MC/MCSubtargetInfo.cpp
===================================================================
--- llvm/lib/MC/MCSubtargetInfo.cpp
+++ llvm/lib/MC/MCSubtargetInfo.cpp
@@ -147,6 +147,20 @@
   PrintOnce = true;
 }
 
+/// Display help for feature and mcpu choices.
+static void PrintFullFeatureList(const FeatureBitset &FeatBits,
+                                 ArrayRef<SubtargetFeatureKV> FeatTable,
+                                 bool EnabledOnly) {
+  errs() << "Current full feature list:\n";
+  for (const SubtargetFeatureKV &Feat : FeatTable) {
+    bool IsSet = FeatBits.test(Feat.Value);
+    if (EnabledOnly && !IsSet)
+      continue;
+    errs() << "\t" << (IsSet ? '+' : '-') << Feat.Key << ":\t" << Feat.Desc
+           << '\n';
+  }
+}
+
 static FeatureBitset getFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS,
                                  ArrayRef<SubtargetSubTypeKV> ProcDesc,
                                  ArrayRef<SubtargetFeatureKV> ProcFeatures) {
@@ -198,6 +212,10 @@
       Help(ProcDesc, ProcFeatures);
     else if (Feature == "+cpuhelp")
       cpuHelp(ProcDesc);
+    else if (Feature == "+dump-all")
+      PrintFullFeatureList(Bits, ProcFeatures, /*EnabledOnly=*/false);
+    else if (Feature == "+dump-enabled")
+      PrintFullFeatureList(Bits, ProcFeatures, /*EnabledOnly=*/true);
     else
       ApplyFeatureFlag(Bits, Feature, ProcFeatures);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106503.360618.patch
Type: text/x-patch
Size: 1415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210721/219f019d/attachment.bin>


More information about the llvm-commits mailing list