TableGen: Resolve all template args simultaneously in AddSubClass

Summary:
Use the new resolver interface more explicitly, and avoid traversing
all the initializers multiple times.

Add a test case for a pattern that was broken by an earlier version
of this change.

An additional change is that we now remove *all* template arguments
after resolving them.

Change-Id: I86c828c8cc84c18b052dfe0f64c0d5cbf3c4e13c

Reviewers: arsenm, craig.topper, tra, MartinO

Subscribers: wdng, llvm-commits

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

llvm-svn: 326706
diff --git a/llvm/test/TableGen/template-arg-dependency.td b/llvm/test/TableGen/template-arg-dependency.td
new file mode 100644
index 0000000..04eba7c
--- /dev/null
+++ b/llvm/test/TableGen/template-arg-dependency.td
@@ -0,0 +1,16 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+// XFAIL: vg_leak
+
+// CHECK: --- Defs ---
+
+// CHECK: def A0 {
+// CHECK:   int ret = 3;
+// CHECK: }
+
+class A<int a,
+        int b = !add(a, 1),
+        int sum = !add(a, b)> {
+  int ret = sum;
+}
+
+def A0 : A<1>;