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