SetTheory.td 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // Test evaluation of set operations in dags.
  2. // RUN: llvm-tblgen -print-sets %s | FileCheck %s
  3. // XFAIL: vg_leak
  4. //
  5. // The -print-sets driver configures a primitive SetTheory instance that
  6. // understands these sets:
  7. class Set<dag d> {
  8. dag Elements = d;
  9. }
  10. // It prints all Set instances and their ordered set interpretation.
  11. // Define some elements.
  12. def a;
  13. def b;
  14. def c;
  15. def d;
  16. // The 'add' operator evaluates and concatenates its arguments.
  17. def add;
  18. def S0a : Set<(add)>;
  19. def S0b : Set<(add a)>;
  20. def S0c : Set<(add a, b)>;
  21. def S0d : Set<(add b, a)>;
  22. def S0e : Set<(add a, a)>;
  23. def S0f : Set<(add a, a, b, a, c, b, d, a)>;
  24. def S0g : Set<(add b, a, b)>;
  25. // CHECK: S0a = [ ]
  26. // CHECK: S0b = [ a ]
  27. // CHECK: S0c = [ a b ]
  28. // CHECK: S0d = [ b a ]
  29. // CHECK: S0e = [ a ]
  30. // CHECK: S0f = [ a b c d ]
  31. // CHECK: S0g = [ b a ]
  32. // Defs of Set class expand into their elements.
  33. // Mixed sets and elements are flattened.
  34. def S1a : Set<(add S0a)>;
  35. def S1b : Set<(add S0a, S0a)>;
  36. def S1c : Set<(add S0d, S0f)>;
  37. def S1d : Set<(add d, S0d, S0f)>;
  38. // CHECK: S1a = [ ]
  39. // CHECK: S1b = [ ]
  40. // CHECK: S1c = [ b a c d ]
  41. // CHECK: S1d = [ d b a c ]
  42. // The 'sub' operator returns the first argument with the following arguments
  43. // removed.
  44. def sub;
  45. def S2a : Set<(sub S1a, S1c)>;
  46. def S2b : Set<(sub S1c, S1d)>;
  47. def S2c : Set<(sub S1c, b)>;
  48. def S2d : Set<(sub S1c, S0c)>;
  49. def S2e : Set<(sub S1c, S2d)>;
  50. // CHECK: S2a = [ ]
  51. // CHECK: S2b = [ ]
  52. // CHECK: S2c = [ a c d ]
  53. // CHECK: S2d = [ c d ]
  54. // CHECK: S2e = [ b a ]
  55. // The 'and' operator intersects two sets. The result has the same order as the
  56. // first argument.
  57. def and;
  58. def S3a : Set<(and S2d, S2e)>;
  59. def S3b : Set<(and S2d, S1d)>;
  60. // CHECK: S3a = [ ]
  61. // CHECK: S3b = [ c d ]
  62. // The 'shl' operator removes the first N elements.
  63. def shl;
  64. def S4a : Set<(shl S0f, 0)>;
  65. def S4b : Set<(shl S0f, 1)>;
  66. def S4c : Set<(shl S0f, 3)>;
  67. def S4d : Set<(shl S0f, 4)>;
  68. def S4e : Set<(shl S0f, 5)>;
  69. // CHECK: S4a = [ a b c d ]
  70. // CHECK: S4b = [ b c d ]
  71. // CHECK: S4c = [ d ]
  72. // CHECK: S4d = [ ]
  73. // CHECK: S4e = [ ]
  74. // The 'trunc' operator truncates after the first N elements.
  75. def trunc;
  76. def S5a : Set<(trunc S0f, 0)>;
  77. def S5b : Set<(trunc S0f, 1)>;
  78. def S5c : Set<(trunc S0f, 3)>;
  79. def S5d : Set<(trunc S0f, 4)>;
  80. def S5e : Set<(trunc S0f, 5)>;
  81. // CHECK: S5a = [ ]
  82. // CHECK: S5b = [ a ]
  83. // CHECK: S5c = [ a b c ]
  84. // CHECK: S5d = [ a b c d ]
  85. // CHECK: S5e = [ a b c d ]
  86. // The 'rotl' operator rotates left, but also accepts a negative shift.
  87. def rotl;
  88. def S6a : Set<(rotl S0f, 0)>;
  89. def S6b : Set<(rotl S0f, 1)>;
  90. def S6c : Set<(rotl S0f, 3)>;
  91. def S6d : Set<(rotl S0f, 4)>;
  92. def S6e : Set<(rotl S0f, 5)>;
  93. def S6f : Set<(rotl S0f, -1)>;
  94. def S6g : Set<(rotl S0f, -4)>;
  95. def S6h : Set<(rotl S0f, -5)>;
  96. // CHECK: S6a = [ a b c d ]
  97. // CHECK: S6b = [ b c d a ]
  98. // CHECK: S6c = [ d a b c ]
  99. // CHECK: S6d = [ a b c d ]
  100. // CHECK: S6e = [ b c d a ]
  101. // CHECK: S6f = [ d a b c ]
  102. // CHECK: S6g = [ a b c d ]
  103. // CHECK: S6h = [ d a b c ]
  104. // The 'rotr' operator rotates right, but also accepts a negative shift.
  105. def rotr;
  106. def S7a : Set<(rotr S0f, 0)>;
  107. def S7b : Set<(rotr S0f, 1)>;
  108. def S7c : Set<(rotr S0f, 3)>;
  109. def S7d : Set<(rotr S0f, 4)>;
  110. def S7e : Set<(rotr S0f, 5)>;
  111. def S7f : Set<(rotr S0f, -1)>;
  112. def S7g : Set<(rotr S0f, -4)>;
  113. def S7h : Set<(rotr S0f, -5)>;
  114. // CHECK: S7a = [ a b c d ]
  115. // CHECK: S7b = [ d a b c ]
  116. // CHECK: S7c = [ b c d a ]
  117. // CHECK: S7d = [ a b c d ]
  118. // CHECK: S7e = [ d a b c ]
  119. // CHECK: S7f = [ b c d a ]
  120. // CHECK: S7g = [ a b c d ]
  121. // CHECK: S7h = [ b c d a ]
  122. // The 'decimate' operator picks every N'th element.
  123. def decimate;
  124. def e0;
  125. def e1;
  126. def e2;
  127. def e3;
  128. def e4;
  129. def e5;
  130. def e6;
  131. def e7;
  132. def e8;
  133. def e9;
  134. def E : Set<(add e0, e1, e2, e3, e4, e5, e6, e7, e8, e9)>;
  135. def S8a : Set<(decimate E, 3)>;
  136. def S8b : Set<(decimate E, 9)>;
  137. def S8c : Set<(decimate E, 10)>;
  138. def S8d : Set<(decimate (rotl E, 1), 2)>;
  139. def S8e : Set<(add (decimate E, 2), (decimate (rotl E, 1), 2))>;
  140. // CHECK: S8a = [ e0 e3 e6 e9 ]
  141. // CHECK: S8b = [ e0 e9 ]
  142. // CHECK: S8c = [ e0 ]
  143. // CHECK: S8d = [ e1 e3 e5 e7 e9 ]
  144. // CHECK: S8e = [ e0 e2 e4 e6 e8 e1 e3 e5 e7 e9 ]
  145. // The 'sequence' operator finds a sequence of records from their name.
  146. def sequence;
  147. def S9a : Set<(sequence "e%u", 3, 7)>;
  148. def S9b : Set<(sequence "e%u", 7, 3)>;
  149. def S9c : Set<(sequence "e%u", 0, 0)>;
  150. def S9d : Set<(sequence "S%ua", 7, 9)>;
  151. def S9e : Set<(sequence "e%u", 3, 6, 2)>;
  152. // CHECK: S9a = [ e3 e4 e5 e6 e7 ]
  153. // CHECK: S9b = [ e7 e6 e5 e4 e3 ]
  154. // CHECK: S9c = [ e0 ]
  155. // CHECK: S9d = [ a b c d e0 e3 e6 e9 e4 e5 e7 ]
  156. // CHECK: S9e = [ e3 e5 ]
  157. // The 'interleave' operator is almost the inverse of 'decimate'.
  158. def interleave;
  159. def T0a : Set<(interleave S9a, S9b)>;
  160. def T0b : Set<(interleave S8e, S8d)>;
  161. // CHECK: T0a = [ e3 e7 e4 e6 e5 ]
  162. // CHECK: T0b = [ e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ]