1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00
llvm-mirror/test/TableGen/name-resolution-consistency.td
Nicolai Haehnle 29fbaf4ec4 TableGen: Streamline how defs are instantiated
Summary:
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

Reviewers: arsenm, craig.topper, tra, MartinO

Subscribers: wdng, llvm-commits

Differential Revision: https://reviews.llvm.org/D44478

llvm-svn: 328117
2018-03-21 17:12:53 +00:00

85 lines
1.8 KiB
TableGen

// RUN: llvm-tblgen %s | FileCheck %s
// XFAIL: vg_leak
// This test demonstrates a number of inconsistencies in how NAME is resolved
// and record names are constructed.
//
// The TODO lines describe a suggested consistent behavior that would result
// from:
// (1) Treating NAME as an implicit multiclass template argument and
// (2) always storing the name of (non-anonymous) prototype records in
// multiclasses with at least one explicit reference to NAME.
//
// Unfortunately, several backends (including X86) rely quite heavily on the
// current inconsistent behavior and would have to be fixed.
// CHECK: def B0a {
// CHECK: string e = "B0";
// CHECK: }
// CHECK: def B0ba {
// TODO: expect "B0b" here
// CHECK: string a = "B0";
// CHECK: string b = "B0";
// CHECK: }
// CHECK: def B0cza {
// TODO: expect "B0cz" here
// CHECK: string a = "B0";
// CHECK: string b = "B0";
// CHECK: }
// TODO: expect this to be named 'xB0b'
// CHECK: def B0xb {
// TODO: expect "B0b" here
// CHECK: string c = "b";
// CHECK: string d = "b";
// CHECK: }
// TODO: expect this to be named B0bys
// CHECK: def B0ys {
// TODO: expect "B0b" here
// CHECK: string f = "b";
// CHECK: string g = "b";
// CHECK: }
// CHECK: def xB0cz {
// CHECK: string c = "B0cz";
// CHECK: string d = "B0cz";
// CHECK: }
// TODO: expect this to be named B0czyt
// CHECK: def yt {
// CHECK: string f = "B0cz";
// CHECK: string g = "B0cz";
// CHECK: }
multiclass A<string p, string q> {
def a {
string a = NAME;
string b = p;
}
def x # NAME {
string c = NAME;
string d = p;
}
def y # q {
string f = NAME;
string g = p;
}
}
multiclass B<string name, string t> {
def a {
string e = NAME;
}
defm b : A<NAME, "s">;
defm NAME # c # name : A<NAME, t>;
}
defm B0 : B<"z", "t">;