TableGen: Reimplement !foreach using the resolving mechanism
Summary:
This changes the syntax of !foreach so that the first "parameter" is
a new syntactic variable: !foreach(x, lst, expr) will define the
variable x within the scope of expr, and evaluation of the !foreach
will substitute elements of the given list (or dag) for x in expr.
Aside from leading to a nicer syntax, this allows more complex
expressions where x is deeply nested, or even constant expressions
in which x does not occur at all.
!foreach is currently not actually used anywhere in trunk, but I
plan to use it in the AMDGPU backend. If out-of-tree targets are
using it, they can adjust to the new syntax very easily.
Change-Id: Ib966694d8ab6542279d6bc358b6f4d767945a805
Reviewers: arsenm, craig.topper, tra, MartinO
Subscribers: wdng, llvm-commits, tpr
Differential Revision: https://reviews.llvm.org/D43651
llvm-svn: 326705
2018-03-05 23:21:04 +08:00
|
|
|
// RUN: llvm-tblgen %s | FileCheck %s
|
|
|
|
// XFAIL: vg_leak
|
|
|
|
|
2018-05-02 21:17:26 +08:00
|
|
|
// CHECK: --- Classes ---
|
|
|
|
// CHECK: list<int> ret = !foreach(a,
|
|
|
|
|
TableGen: Reimplement !foreach using the resolving mechanism
Summary:
This changes the syntax of !foreach so that the first "parameter" is
a new syntactic variable: !foreach(x, lst, expr) will define the
variable x within the scope of expr, and evaluation of the !foreach
will substitute elements of the given list (or dag) for x in expr.
Aside from leading to a nicer syntax, this allows more complex
expressions where x is deeply nested, or even constant expressions
in which x does not occur at all.
!foreach is currently not actually used anywhere in trunk, but I
plan to use it in the AMDGPU backend. If out-of-tree targets are
using it, they can adjust to the new syntax very easily.
Change-Id: Ib966694d8ab6542279d6bc358b6f4d767945a805
Reviewers: arsenm, craig.topper, tra, MartinO
Subscribers: wdng, llvm-commits, tpr
Differential Revision: https://reviews.llvm.org/D43651
llvm-svn: 326705
2018-03-05 23:21:04 +08:00
|
|
|
// CHECK: --- Defs ---
|
|
|
|
|
|
|
|
// CHECK: def C0 {
|
|
|
|
// CHECK: list<list<int>> ret = {{\[}}[1, 2, 3], [1, 2, 3]];
|
|
|
|
// CHECK: }
|
|
|
|
|
|
|
|
// The variable name 'a' is used both in the "inner" and in the "outer" foreach.
|
|
|
|
// The test ensure that the inner declaration of 'a' properly shadows the outer
|
|
|
|
// one.
|
|
|
|
class A<list<int> lst> {
|
|
|
|
list<int> ret = !foreach(a, lst, !add(a, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
class B<list<int> lst1, list<int> lst2> {
|
|
|
|
list<list<int>> ret = !foreach(a, lst1, A<lst2>.ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
class C<list<int> lst2> {
|
|
|
|
list<list<int>> ret = B<[0, 1], lst2>.ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
def C0 : C<[0, 1, 2]>;
|