[PATCH] D100285: [llvm-mc] List available options for -mcpu=help or -mattr=help more convenience

eric tang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 11 22:37:18 PDT 2021


tangxingxin1008 created this revision.
tangxingxin1008 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

  If user just wants to list the available options for -mcpu=help or
  -mattr=help, return the results directly.

Signed-off-by: tangxingxin <tangxingxin1008 at gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100285

Files:
  llvm/tools/llvm-mc/llvm-mc.cpp


Index: llvm/tools/llvm-mc/llvm-mc.cpp
===================================================================
--- llvm/tools/llvm-mc/llvm-mc.cpp
+++ llvm/tools/llvm-mc/llvm-mc.cpp
@@ -337,6 +337,26 @@
   // construct the Triple object.
   Triple TheTriple(TripleName);
 
+  // Package up features to be passed to target/subtarget
+  std::string FeaturesStr;
+  if (MAttrs.size()) {
+    SubtargetFeatures Features;
+    for (unsigned i = 0; i != MAttrs.size(); ++i)
+      Features.AddFeature(MAttrs[i]);
+    FeaturesStr = Features.getString();
+  }
+
+  // List available options for -mcpu=help or -mattr=help and then exit.
+  bool isHelp = std::string(MCPU) == "help" ||
+                (MAttrs.size() && std::string(MAttrs[0]) == "help");
+  if (isHelp) {
+    // We do this down here since the CPU/Feature help is underneath
+    // the target machine creation.
+    TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr);
+
+    return 0;
+  }
+
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
       MemoryBuffer::getFileOrSTDIN(InputFilename);
   if (std::error_code EC = BufferPtr.getError()) {
@@ -438,15 +458,6 @@
   if (GenDwarfForAssembly)
     Ctx.setGenDwarfRootFile(InputFilename, Buffer->getBuffer());
 
-  // Package up features to be passed to target/subtarget
-  std::string FeaturesStr;
-  if (MAttrs.size()) {
-    SubtargetFeatures Features;
-    for (unsigned i = 0; i != MAttrs.size(); ++i)
-      Features.AddFeature(MAttrs[i]);
-    FeaturesStr = Features.getString();
-  }
-
   sys::fs::OpenFlags Flags = (FileType == OFT_AssemblyFile) ? sys::fs::OF_Text
                                                             : sys::fs::OF_None;
   std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename, Flags);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100285.336745.patch
Type: text/x-patch
Size: 1758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210412/830c19f1/attachment.bin>


More information about the llvm-commits mailing list