2013-08-22 22:46:05 +02:00
|
|
|
// RUN: llvm-tblgen %s | FileCheck %s
|
2013-11-10 15:26:08 +01:00
|
|
|
// XFAIL: vg_leak
|
2013-08-22 22:46:05 +02:00
|
|
|
|
|
|
|
// CHECK: WorldHelloCC
|
|
|
|
// CHECK-NOT: WorldHelloCC
|
2009-05-05 18:28:25 +02:00
|
|
|
|
|
|
|
class C<string n> {
|
|
|
|
string name = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
multiclass Names<string n, string m> {
|
|
|
|
def CC : C<n>;
|
|
|
|
def World#NAME#CC : C<m>;
|
|
|
|
}
|
|
|
|
|
|
|
|
defm Hello : Names<"hello", "world">;
|
2014-01-02 20:35:33 +01:00
|
|
|
|
|
|
|
// Ensure that the same anonymous name is used as the prefix for all defs in an
|
|
|
|
// anonymous multiclass.
|
|
|
|
|
|
|
|
class Outer<C i> {
|
|
|
|
C Inner = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
multiclass MC<string name> {
|
|
|
|
def hi : C<name>;
|
|
|
|
def there : Outer<!cast<C>(!strconcat(NAME, "hi"))>;
|
|
|
|
}
|
|
|
|
|
|
|
|
defm : MC<"foo">;
|
|
|
|
|
[TableGen] Correctly generate implicit anonymous prototype defs in multiclasses
Even within a multiclass, we had been generating concrete implicit anonymous
defs when parsing values (generally in value lists). This behavior was
incorrect, and led to errors when multiclass parameters were used in the
parameter list of the implicit anonymous def.
If we had some multiclass:
multiclass mc<string n> {
... : SomeClass<SomeOtherClass<n> >
The capture of the multiclass parameter 'n' would not work correctly, and
depending on how the implicit SomeOtherClass was used, either TableGen would
ignore something it shouldn't, or would crash.
To fix this problem, when inside a multiclass, we generate prototype anonymous
defs for implicit anonymous defs (just as we do for explicit anonymous defs).
Within the multiclass, the current record prototype is populated with a node
that is essentially: !cast<SomeOtherClass>(!strconcat(NAME, anon_value_name)).
This is then resolved to the correct concrete anonymous def, in the usual way,
when NAME is resolved during multiclass instantiation.
llvm-svn: 198348
2014-01-02 21:47:09 +01:00
|
|
|
multiclass MC2<string name> {
|
|
|
|
def there : Outer<C<name> >;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that we've correctly captured the reference to name from the implicit
|
|
|
|
// anonymous C def in the template parameter list of Outer.
|
|
|
|
// CHECK-NOT: MC2::name
|
|
|
|
|
|
|
|
defm : MC2<"bar">;
|
|
|
|
|
2015-05-21 06:32:56 +02:00
|
|
|
multiclass MC3<string s> {
|
|
|
|
def ZFizz#s : C<s>;
|
|
|
|
}
|
|
|
|
|
TableGen: Streamline the semantics of NAME
Summary:
The new rules are straightforward. The main rules to keep in mind
are:
1. NAME is an implicit template argument of class and multiclass,
and will be substituted by the name of the instantiating def/defm.
2. The name of a def/defm in a multiclass must contain a reference
to NAME. If such a reference is not present, it is automatically
prepended.
And for some additional subtleties, consider these:
3. defm with no name generates a unique name but has no special
behavior otherwise.
4. def with no name generates an anonymous record, whose name is
unique but undefined. In particular, the name won't contain a
reference to NAME.
Keeping rules 1&2 in mind should allow a predictable behavior of
name resolution that is simple to follow.
The old "rules" were rather surprising: sometimes (but not always),
NAME would correspond to the name of the toplevel defm. They were
also plain bonkers when you pushed them to their limits, as the old
version of the TableGen test case shows.
Having NAME correspond to the name of the toplevel defm introduces
"spooky action at a distance" and breaks composability:
refactoring the upper layers of a hierarchy of nested multiclass
instantiations can cause unexpected breakage by changing the value
of NAME at a lower level of the hierarchy. The new rules don't
suffer from this problem.
Some existing .td files have to be adjusted because they ended up
depending on the details of the old implementation.
Change-Id: I694095231565b30f563e6fd0417b41ee01a12589
Reviewers: tra, simon_tatham, craig.topper, MartinO, arsenm, javed.absar
Subscribers: wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D47430
llvm-svn: 333900
2018-06-04 16:26:05 +02:00
|
|
|
defm "" : MC3<"Buzz">;
|
2015-05-21 06:32:56 +02:00
|
|
|
|
|
|
|
// CHECK: def ZFizzBuzz
|
|
|
|
// CHECK: string name = "Buzz";
|
|
|
|
// CHECK-NOT: MC3::s
|
|
|
|
|
|
|
|
multiclass MC4<string s> {
|
|
|
|
def NAME#s : C<s>;
|
|
|
|
}
|
|
|
|
|
|
|
|
defm ZTagazok : MC4<"AToi">;
|
|
|
|
|
|
|
|
// CHECK: def ZTagazokAToi
|
|
|
|
// CHECK: string name = "AToi";
|
|
|
|
// CHECK-NOT: MC4::s
|
|
|
|
|
|
|
|
multiclass MC5<C c> {
|
|
|
|
def NAME#c.name : C<c.name>;
|
|
|
|
}
|
|
|
|
|
|
|
|
def CTiger : C<"Tiger">;
|
|
|
|
defm Zebra : MC5<CTiger>;
|
|
|
|
|
|
|
|
// CHECK: def ZebraTiger
|
|
|
|
// CHECK: string name = "Tiger";
|
|
|
|
// CHECK-NOT: MC5::c
|
|
|
|
|
|
|
|
multiclass MC6<C c> {
|
|
|
|
def NAME#Tiger#c.name : C<c.name>;
|
|
|
|
}
|
|
|
|
|
|
|
|
def CAligator : C<"Aligator">;
|
|
|
|
defm Zebra : MC6<CAligator>;
|
|
|
|
|
|
|
|
// CHECK: def ZebraTigerAligator
|
|
|
|
// CHECK: string name = "Aligator";
|
|
|
|
// CHECK-NOT: MC6::c
|
|
|
|
|