[PATCH] D63374: [TableGen] Add "MCInstValidatorEmitter" TableGen backend

Nicolas Guillemot via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 15 01:19:15 PDT 2019


nlguillemot created this revision.
nlguillemot added reviewers: t.yomitch, sabuasal.
Herald added a subscriber: mgorny.

There are many places in the compiler that generate `MCInst`s, and these different places generally impose similar rules on their generated `MCInst`s. For example, an operand in a given ISA might represent a special flag that only supports a certain set of possible values, and all places that create `MCInst`s (parser, disassembler, etc) should respect the restrictions of that flag. If we can ensure that the `MCInst`s outputted by various parts of the compiler respect their restrictions, we might be able to catch bugs more easily.

At first glance, the pre-existing `MCOperandPredicate` member of TableGen's base `Operand` class looks like it should be the one to fill the role of a convenient place to describe the restrictions on operands. However, this `MCOperandPredicate` member is currently mostly unused by LLVM. As a step towards making it easier to implement validation of `MCInst`s in various places of the compiler, this patch adds a new TableGen backend called `MCInstValidatorEmitter`. This backend exposes a function called `validateMCOperand`, which can be used to conveniently check the validity of an operand of an `MCInst`.

As future work, this backend could be enhanced with more functions to validate `MCInst`s. For example, we could add another function to check the validity of an `MCInst` as a whole, by giving `MCInst`s a `MCInstPredicate` (or similar.)

A note about the many "predicate"s in LLVM:
The word "predicate" is quite overloaded, since it is also used to describe parts of the functionality of the scheduler, parser, decoder, etc. For this backend, the "predicate" is not related to a specific part of the compiler. It's just a general purpose function that can be used to validate that a given MCInst respects the rules of its operands. By being general-purpose, it becomes possible to use this API to validate the `MCInst`s produced in any given part in the compiler. Being able to describe the validity of the values of an operand type in just one place is what makes this interesting.


https://reviews.llvm.org/D63374

Files:
  test/TableGen/validate-operand.td
  utils/TableGen/CMakeLists.txt
  utils/TableGen/MCInstValidatorEmitter.cpp
  utils/TableGen/TableGen.cpp
  utils/TableGen/TableGenBackends.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63374.204905.patch
Type: text/x-patch
Size: 8810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190615/5b210734/attachment.bin>


More information about the llvm-commits mailing list