summaryrefslogtreecommitdiffstats
path: root/llvm/test/TableGen
diff options
context:
space:
mode:
authorNicolai Haehnle <nhaehnle@gmail.com>2018-03-06 13:49:16 +0000
committerNicolai Haehnle <nhaehnle@gmail.com>2018-03-06 13:49:16 +0000
commitd34f6843aaffc6a8f6929cce5b589032fd55ede0 (patch)
tree4de1aaea018b4bc54a57c76241d3ac61d02e94d5 /llvm/test/TableGen
parent616635022a7a15bf097e6c23fe2d2f5678491419 (diff)
downloadbcm5719-llvm-d34f6843aaffc6a8f6929cce5b589032fd55ede0.tar.gz
bcm5719-llvm-d34f6843aaffc6a8f6929cce5b589032fd55ede0.zip
TableGen: Add !foldl operation
Change-Id: I63d67bf6e0b315e2d3360e47e3b62c9517f38987 llvm-svn: 326790
Diffstat (limited to 'llvm/test/TableGen')
-rw-r--r--llvm/test/TableGen/foldl.td71
1 files changed, 71 insertions, 0 deletions
diff --git a/llvm/test/TableGen/foldl.td b/llvm/test/TableGen/foldl.td
new file mode 100644
index 00000000000..879092470cc
--- /dev/null
+++ b/llvm/test/TableGen/foldl.td
@@ -0,0 +1,71 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+// XFAIL: vg_leak
+
+// CHECK: --- Defs ---
+
+// CHECK: def A1 {
+// CHECK: int ret = 0;
+// CHECK: }
+
+// CHECK: def A2 {
+// CHECK: int ret = 5;
+// CHECK: }
+
+// CHECK: def A3 {
+// CHECK: int ret = 10;
+// CHECK: }
+
+// CHECK: def B1 {
+// CHECK: list<string> ret = [];
+// CHECK: }
+
+// CHECK: def B2 {
+// CHECK: list<string> ret = [];
+// CHECK: }
+
+// CHECK: def B3 {
+// CHECK: list<string> ret = ["a"];
+// CHECK: }
+
+// CHECK: def B4 {
+// CHECK: list<string> ret = ["a", "b", "c", "d"];
+// CHECK: }
+
+// CHECK: def E0 {
+// CHECK: list<int> ret = [45, 45, 45, 45];
+// CHECK: }
+
+class Sum<list<int> lst> {
+ int ret = !foldl(0, lst, a, b, !add(a, b));
+}
+
+class Flatten<list<list<string>> lst> {
+ list<string> ret = !foldl([]<string>, lst, a, b, !listconcat(a, b));
+}
+
+def A1 : Sum<[]>;
+def A2 : Sum<[5]>;
+def A3 : Sum<[1, 2, 3, 4]>;
+
+def B1 : Flatten<[]>;
+def B2 : Flatten<[[]]>;
+def B3 : Flatten<[["a"]]>;
+def B4 : Flatten<[["a", "b"], [], ["c"], ["d"]]>;
+
+// The variables a and b are declared both in the "inner" foldl and in the
+// other foreach. The test checks that they don't "leak".
+class C<list<int> lst> {
+ int ret = !foldl(0, lst, a, b, !add(a, b));
+}
+
+class D<list<int> lst1, list<int> lst2> {
+ list<int> x = !foreach(a, lst1, C<lst2>.ret);
+ list<int> y = !foreach(b, lst1, C<lst2>.ret);
+ list<int> z = !listconcat(x, y);
+}
+
+class E<list<int> lst2> {
+ list<int> ret = D<[0, 1], lst2>.z;
+}
+
+def E0 : E<[10, 15, 20]>;
OpenPOWER on IntegriCloud