[PATCH] D44478: TableGen: Streamline how defs are instantiated

Nicolai Hähnle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 14 08:24:57 PDT 2018


nhaehnle created this revision.
nhaehnle added reviewers: arsenm, craig.topper, tra, MartinO.
Herald added a subscriber: wdng.

Instantiating def's and defm's needs to perform the following steps:

- for defm's, clone multiclass def prototypes and subsitute template args
- for def's and defm's, add subclass definitions, substituting template args
- clone the record based on foreach loops and substitute loop iteration variables
- override record variables based on the global 'let' stack
- resolve the record name (this should be simple, but unfortunately it's not due to existing .td files relying on rather silly implementation details)
- for def(m)s in multiclasses, add the unresolved record as a multiclass prototype
- for top-level def(m)s, resolve all internal variable references and add them to the record keeper and any active defsets

This change streamlines how we go through these steps, by having both
def's and defm's feed into a single addDef() method that handles foreach,
final resolve, and routing the record to the right place.

This happens to make foreach inside of multiclasses work, as the new
test case demonstrates. Previously, foreach inside multiclasses was not
forbidden by the parser, but it was de facto broken.

Another side effect is that the order of "instantiated from" notes in error
messages is reversed, as the modified test case shows. This is arguably
clearer, since the initial error message ends up pointing directly to
whatever triggered the error, and subsequent notes will point to increasingly
outer layers of multiclasses. This is consistent with how C++ compilers
report nested #includes and nested template instantiations.

Change-Id: Ica146d0db2bc133dd7ed88054371becf24320447


Repository:
  rL LLVM

https://reviews.llvm.org/D44478

Files:
  include/llvm/TableGen/Record.h
  lib/TableGen/Record.cpp
  lib/TableGen/TGParser.cpp
  lib/TableGen/TGParser.h
  test/TableGen/MultiClass-defm-fail.td
  test/TableGen/foreach-multiclass.td
  test/TableGen/self-reference.td

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44478.138369.patch
Type: text/x-patch
Size: 32849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180314/4ef0d60e/attachment.bin>


More information about the llvm-commits mailing list