[PATCH] D92378: [llvm-objdump] Only print unrecognized CPU warning once

David Spickett via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 1 03:28:29 PST 2020


DavidSpickett created this revision.
Herald added subscribers: llvm-commits, pengfei, rupprecht, hiraditya, kristof.beyls.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
Herald added a project: LLVM.
DavidSpickett requested review of this revision.

This would print the warning twice:
$ ./bin/llvm-objdump -d /tmp/test.o --mcpu=not-a-cpu
'not-a-cpu' is not a recognized processor for this target (ignoring processor)
'not-a-cpu' is not a recognized processor for this target (ignoring processor)

/tmp/test.o:    file format elf64-x86-64
<...>

This is due to warnings printed from InitMCProcessorInfo.
First it calls getFeatures, which warns for an invalid CPU name.
Then it calls getSchedModelForCPU which warns again for the
same reason.

To fix this, don't print a warning in getSchedModelForCPU.

With one exception, this function is only called from
InitMCProcessorInfo so there's already been a warning printed.

The exception is ARMSubtarget::initSubtargetFeatures.
However, this function first calls ParseSubtargetFeatures,
which always calls InitMCProcessorInfo. So again we will
have already printed a warning by the time we call
getSchedModelForCPU.

This actually affects many llvm tools. llvm-objdump, llvm-mc,
llc, lli, llvm-mca and exegis to my knowledge.

However they are all calling the same code so I'm adding
tests just to llvm-objdump which will catch any regression.

`--mattr` doesn't have this issue and a test is added to
check this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92378

Files:
  llvm/lib/MC/MCSubtargetInfo.cpp
  llvm/test/tools/llvm-objdump/warn-mattr-unrecognized.test
  llvm/test/tools/llvm-objdump/warn-mcpu-unrecognized.test


Index: llvm/test/tools/llvm-objdump/warn-mcpu-unrecognized.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/warn-mcpu-unrecognized.test
@@ -0,0 +1,15 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objdump -d %t --mcpu=not-a-cpu 2>&1 | FileCheck %s
+# REQUIRES: x86-registered-target
+
+# CHECK: 'not-a-cpu' is not a recognized processor for this target (ignoring processor)
+# CHECK-EMPTY:
+## To check we still disassemble the file
+# CHECK-NEXT: file format elf64-x86-64
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_EXEC
+  Machine:         EM_X86_64
Index: llvm/test/tools/llvm-objdump/warn-mattr-unrecognized.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/warn-mattr-unrecognized.test
@@ -0,0 +1,15 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objdump -d %t --mcpu=alderlake --mattr=not-an-attr 2>&1 | FileCheck %s
+# REQUIRES: x86-registered-target
+
+# CHECK: '+not-an-attr' is not a recognized feature for this target (ignoring feature)
+# CHECK-EMPTY:
+## To check we still disassemble the file
+# CHECK-NEXT: file format elf64-x86-64
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_EXEC
+  Machine:         EM_X86_64
Index: llvm/lib/MC/MCSubtargetInfo.cpp
===================================================================
--- llvm/lib/MC/MCSubtargetInfo.cpp
+++ llvm/lib/MC/MCSubtargetInfo.cpp
@@ -311,10 +311,7 @@
   const SubtargetSubTypeKV *CPUEntry = Find(CPU, ProcDesc);
 
   if (!CPUEntry) {
-    if (CPU != "help") // Don't error if the user asked for help.
-      errs() << "'" << CPU
-             << "' is not a recognized processor for this target"
-             << " (ignoring processor)\n";
+    // A warning for this was already printed in getFeatures()
     return MCSchedModel::GetDefaultSchedModel();
   }
   assert(CPUEntry->SchedModel && "Missing processor SchedModel value");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92378.308605.patch
Type: text/x-patch
Size: 2072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201201/7b786c2c/attachment.bin>


More information about the llvm-commits mailing list