[TableGen] Use the same anonymous name as the prefix on all multiclass defs
authorHal Finkel <hfinkel@anl.gov>
Thu, 2 Jan 2014 19:35:33 +0000 (19:35 +0000)
committerHal Finkel <hfinkel@anl.gov>
Thu, 2 Jan 2014 19:35:33 +0000 (19:35 +0000)
TableGen had been generating a different name for an anonymous multiclass's
NAME for every def in the multiclass. This had an unfortunate side effect: it
was impossible to reference one def within the multiclass from another (in the
parameter list, for example). By making sure we only generate an anonymous name
once per multiclass (which, as it turns out, requires only changing the name
parameter to reference type), we can now concatenate NAME within the multiclass
with a def name in order to generate a reference to that def.

This does not matter so much, in and of itself, but is necessary for a
follow-up commit that will fix variable capturing in implicit anonymous
multiclass defs (and that is important).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198340 91177308-0d34-0410-b5e6-96231b3b80d8

lib/TableGen/TGParser.cpp
lib/TableGen/TGParser.h
test/TableGen/MultiClassDefName.td

index 38ab71184aac60694d6d3bc19cfdd324eb8d0014..be5a5242518ee70e1610182452a2b21291f78370 100644 (file)
@@ -2269,7 +2269,7 @@ bool TGParser::ParseMultiClass() {
 Record *TGParser::
 InstantiateMulticlassDef(MultiClass &MC,
                          Record *DefProto,
-                         Init *DefmPrefix,
+                         Init *&DefmPrefix,
                          SMRange DefmPrefixRange) {
   // We need to preserve DefProto so it can be reused for later
   // instantiations, so create a new Record to inherit from it.
index a5753458108e3d94b6c4e72e8d951bd6d8d4053a..e5559a33e386e9c62a27cfb2a50fd2da1e685a22 100644 (file)
@@ -137,7 +137,7 @@ private:  // Parser methods.
   bool ParseMultiClass();
   Record *InstantiateMulticlassDef(MultiClass &MC,
                                    Record *DefProto,
-                                   Init *DefmPrefix,
+                                   Init *&DefmPrefix,
                                    SMRange DefmPrefixRange);
   bool ResolveMulticlassDefArgs(MultiClass &MC,
                                 Record *DefProto,
index d3c6de7e842106a0dbc717fd1054bd0227f34fbf..69b951d378a19c2424471674e4fe1b067066fbb2 100644 (file)
@@ -14,3 +14,18 @@ multiclass Names<string n, string m> {
 }
 
 defm Hello : Names<"hello", "world">;
+
+// 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">;
+