diff options
| author | Nicolai Haehnle <nhaehnle@gmail.com> | 2018-03-05 15:21:04 +0000 |
|---|---|---|
| committer | Nicolai Haehnle <nhaehnle@gmail.com> | 2018-03-05 15:21:04 +0000 |
| commit | 8ebf7e4dfa222ae04e063f1c1e0bb5c945331ac7 (patch) | |
| tree | e2e97ea9e1484e355a5569bca9534813c4dee71e /llvm/test/TableGen/foreach-eval.td | |
| parent | 0b0eaf7ee2bc86108ae0628cb4fbdb5e52c25cfb (diff) | |
| download | bcm5719-llvm-8ebf7e4dfa222ae04e063f1c1e0bb5c945331ac7.tar.gz bcm5719-llvm-8ebf7e4dfa222ae04e063f1c1e0bb5c945331ac7.zip | |
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
Diffstat (limited to 'llvm/test/TableGen/foreach-eval.td')
| -rw-r--r-- | llvm/test/TableGen/foreach-eval.td | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/llvm/test/TableGen/foreach-eval.td b/llvm/test/TableGen/foreach-eval.td index 5bef51e49d5..227475f9df4 100644 --- a/llvm/test/TableGen/foreach-eval.td +++ b/llvm/test/TableGen/foreach-eval.td @@ -10,11 +10,9 @@ def d3; def d4; class D<dag d> { - int tmp; dag r1 = !foreach(tmp, d, !subst(d1, d0, !subst(d2, d0, !subst(d3, d0, !subst(d4, d0, tmp))))); - dag tmp2; list<dag> dl = [d]; list<dag> r2 = !foreach(tmp2, dl, !foreach(tmp, tmp2, !subst(d1, d0, @@ -29,10 +27,8 @@ class D<dag d> { def d : D <(d0 d1, d2, d3, d4)>; class I<list<int> i> { - int tmp; list<int> r1 = !foreach(tmp, i, !add(3, !add(4, tmp))); - list<int> tmp2; list<list<int>> li = [i]; list<list<int>> r2 = !foreach(tmp2, li, !foreach(tmp, tmp2, !add(3, !add(4, tmp)))); @@ -43,26 +39,20 @@ class I<list<int> i> { // CHECK: list<list<int>> r2 = [{{[[]}}8, 9, 10]]; def i : I<[1,2,3]>; -class Tmp { - dag t0; - int t1; -} -def tmp: Tmp; - class J0<list<dag> pattern> { list<dag> Pattern = pattern; } class J1<dag pattern> - : J0<[!foreach(tmp.t1, pattern, !subst(d1, d0, - !subst(d2, d0, - !subst(d3, d0, - !subst(d4, d0, tmp.t1)))))]>; + : J0<[!foreach(tmp, pattern, !subst(d1, d0, + !subst(d2, d0, + !subst(d3, d0, + !subst(d4, d0, tmp)))))]>; class J2<list<dag> patterns> - : J0<!foreach(tmp.t0, patterns, - !foreach(tmp.t1, tmp.t0, !subst(d1, d0, - !subst(d2, d0, - !subst(d3, d0, - !subst(d4, d0, tmp.t1))))))>; + : J0<!foreach(t0, patterns, + !foreach(t1, t0, !subst(d1, d0, + !subst(d2, d0, + !subst(d3, d0, + !subst(d4, d0, t1))))))>; // CHECK-LABEL: def j1 // CHECK: list<dag> Pattern = [(d0 d0:$dst, (d0 d0:$src1))]; def j1 : J1< (d1 d2:$dst, (d3 d4:$src1))>; |

