[PATCH] D70650: [MC] Rewrite tablegen for printInstrAlias to comiple faster, NFC

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 24 19:29:43 PST 2019


rnk created this revision.
rnk added a reviewer: RKSimon.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: LLVM.

Before this change, the *InstPrinter.cpp files of each target where some
of the slowest objects to compile in all of LLVM. See this snippet produced by
ClangBuildAnalyzer:
https://reviews.llvm.org/P8171$96
Search for "InstPrinter", and see that it shows up in a few places.

Tablegen was emitting a large switch containing a sequence of operand checks,
each of which created many conditions and many BBs. Register allocation and
jump threading both did not scale well with such a large repetitive sequence of
basic blocks.

So, this change essentially turns those control flow structures into
data. The previous structure looked like:

  switch (Opc) {
  case TGT::ADD:
    // check alias 1
    if (MI->getOperandCount() == N && // check num opnds
        MI->getOperand(0).isReg() && // check opnd 0
        ...
        MI->getOperand(1).isImm() && // check opnd 1
     AsmString = "foo";
     break;
   }
   // check alias 2
   if (...)
     ...
   return false;

The new structure looks like:

  OpToPatterns: Sorted table of opcodes mapping to pattern indices.
   \->
     Patterns: List of patterns. Previous table points to subrange of
               patterns to match.
      \->
        Conds: The if conditions above encoded as a kind and 32-bit value.

See MCInstPrinter.cpp for the details of how the new data structures are
interpreted.

Here are some before and after metrics.
Time to compile AArch64InstPrinter.cpp:

  0m29.062s vs. 0m2.203s

size of the obj:

  3.9M vs. 676K

size of clang.exe:

  97M vs. 96M

I have not benchmarked disassembly performance, but typically
disassemblers are bottlenecked on IO and string processing, not alias
matching, so I'm not sure it's interesting enough to be worth doing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70650

Files:
  llvm/include/llvm/MC/MCInstPrinter.h
  llvm/lib/MC/MCInstPrinter.cpp
  llvm/utils/TableGen/AsmWriterEmitter.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70650.230830.patch
Type: text/x-patch
Size: 22504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191125/5ce6886d/attachment.bin>


More information about the llvm-commits mailing list