llvm-mirror/test/TableGen/foreach.td
Nicolai Haehnle 44c4846682 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 15:21:04 +00:00

54 lines
1.1 KiB
TableGen

// RUN: llvm-tblgen %s | FileCheck %s
// XFAIL: vg_leak
// CHECK: Classes
// CHECK: Sr
// CHECK: Jr
// CHECK: "NAME"
// CHECK: Defs
// CHECK: def DX {
// CHECK: list<string> x = ["0", "1", "2"];
// CHECK: }
// CHECK: def DY {
// CHECK: list<int> y = [5, 7];
// CHECK: }
// CHECK: Jr
// CHECK: Sr
class A<list<string> names> {
list<string> Names = names;
}
class B<list<string> names> : A<!foreach(name, names, !strconcat(name, ", Sr."))>;
class C<list<string> names> : A<!foreach(name, names, !strconcat(name, ", Jr."))>;
class D<list<string> names> : A<!foreach(name, names, !subst("NAME", "John Smith", name))>;
class Names {
list<string> values = ["Ken Griffey", "Seymour Cray"];
}
def People : Names;
def Seniors : B<People.values>;
def Juniors : C<People.values>;
def Smiths : D<["NAME", "Jane Smith"]>;
def Unprocessed : D<People.values>;
class X<list<int> a> {
list<string> x = !foreach(num, a, !cast<string>(num));
}
def DX : X<[0, 1, 2]>;
class Y<list<int> a> {
list<int> y = !foreach(num, a, !add(!add(4, num), !add(1, num)));
}
def DY: Y<[0, 1]>;