llvm.org GIT mirror llvm / ecb26a7
[CodeGen] Fix formatting and comments (NFC) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363947 91177308-0d34-0410-b5e6-96231b3b80d8 Evandro Menezes 28 days ago
5 changed file(s) with 95 addition(s) and 93 deletion(s). Raw diff Collapse all Expand all
198198 Cases(std::move(C)), Prob(Pr) {}
199199 };
200200
201 /// Return the range of value in [First..Last].
201 /// Return the range of value within a range.
202202 uint64_t getJumpTableRange(const CaseClusterVector &Clusters, unsigned First,
203203 unsigned Last);
204204
205 /// Return the number of cases in [First..Last].
205 /// Return the number of cases within a range.
206206 uint64_t getJumpTableNumCases(const SmallVectorImpl &TotalCases,
207207 unsigned First, unsigned Last);
208208
982982 const unsigned MinDensity = getMinimumJumpTableDensity(OptForSize);
983983 const unsigned MaxJumpTableSize =
984984 OptForSize ? UINT_MAX : getMaximumJumpTableSize();
985
985986 // Check whether a range of clusters is dense enough for a jump table.
986987 if (Range <= MaxJumpTableSize &&
987988 (NumCases * 100 >= Range * MinDensity)) {
2626 // FIXME: A range of consecutive cases has 100% density, but only requires one
2727 // comparison to lower. We should discriminate against such consecutive ranges
2828 // in jump tables.
29
3029 return (HighCase - LowCase).getLimitedValue((UINT64_MAX - 1) / 100) + 1;
3130 }
3231
5554 if (!TLI->areJTsAllowed(SI->getParent()->getParent()))
5655 return;
5756
58 const int64_t N = Clusters.size();
5957 const unsigned MinJumpTableEntries = TLI->getMinimumJumpTableEntries();
6058 const unsigned SmallNumberOfEntries = MinJumpTableEntries / 2;
6159
60 // Bail if not enough cases.
61 const int64_t N = Clusters.size();
6262 if (N < 2 || N < MinJumpTableEntries)
6363 return;
6464
65 // TotalCases[i]: Total nbr of cases in Clusters[0..i].
65 // Accumulated number of cases in each cluster and those prior to it.
6666 SmallVector TotalCases(N);
6767 for (unsigned i = 0; i < N; ++i) {
6868 const APInt &Hi = Clusters[i].High->getValue();
7272 TotalCases[i] += TotalCases[i - 1];
7373 }
7474
75 // Cheap case: the whole range may be suitable for jump table.
7675 uint64_t Range = getJumpTableRange(Clusters,0, N - 1);
7776 uint64_t NumCases = getJumpTableNumCases(TotalCases, 0, N - 1);
7877 assert(NumCases < UINT64_MAX / 100);
7978 assert(Range >= NumCases);
79
80 // Cheap case: the whole range may be suitable for jump table.
8081 if (TLI->isSuitableForJumpTable(SI, NumCases, Range)) {
8182 CaseCluster JTCluster;
8283 if (buildJumpTable(Clusters, 0, N - 1, SI, DefaultMBB, JTCluster)) {
130131 // Search for a solution that results in fewer partitions.
131132 for (int64_t j = N - 1; j > i; j--) {
132133 // Try building a partition from Clusters[i..j].
133 uint64_t Range = getJumpTableRange(Clusters, i, j);
134 uint64_t NumCases = getJumpTableNumCases(TotalCases, i, j);
134 Range = getJumpTableRange(Clusters, i, j);
135 NumCases = getJumpTableNumCases(TotalCases, i, j);
135136 assert(NumCases < UINT64_MAX / 100);
136137 assert(Range >= NumCases);
138
137139 if (TLI->isSuitableForJumpTable(SI, NumCases, Range)) {
138140 unsigned NumPartitions = 1 + (j == N - 1 ? 0 : MinPartitions[j + 1]);
139141 unsigned Score = j == N - 1 ? 0 : PartitionsScore[j + 1];
99 define i32 @jt1(i32 %a, i32 %b) {
1010 entry:
1111 switch i32 %a, label %return [
12 i32 1, label %bb1
13 i32 2, label %bb2
14 i32 3, label %bb3
15 i32 4, label %bb4
16 i32 5, label %bb5
17 i32 6, label %bb6
18 i32 7, label %bb7
19 i32 8, label %bb8
20 i32 9, label %bb9
12 i32 1, label %bb1
13 i32 2, label %bb2
14 i32 3, label %bb3
15 i32 4, label %bb4
16 i32 5, label %bb5
17 i32 6, label %bb6
18 i32 7, label %bb7
19 i32 8, label %bb8
20 i32 9, label %bb9
2121 i32 10, label %bb10
2222 i32 11, label %bb11
2323 i32 12, label %bb12
2929 ]
3030 ; CHECK-LABEL: function jt1:
3131 ; CHECK-NEXT: Jump Tables:
32 ; CHECK0-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
33 ; CHECK0-NOT: %jump-table.1:
34 ; CHECK4-NEXT: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5
35 ; CHECK4-SAME: %jump-table.1: %bb.6 %bb.7 %bb.8 %bb.9
36 ; CHECK4-SAME: %jump-table.2: %bb.10 %bb.11 %bb.12 %bb.13
37 ; CHECK4-SAME: %jump-table.3: %bb.14 %bb.15 %bb.16 %bb.17
38 ; CHECK4-NOT: %jump-table.4:
39 ; CHECK8-NEXT: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9
40 ; CHECK8-SAME: %jump-table.1: %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
41 ; CHECK8-NOT: %jump-table.2:
42 ; CHECK16-NEXT: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
43 ; CHECK16-NOT: %jump-table.1:
44 ; CHECKM1-NEXT: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9
45 ; CHECKM1-SAME: %jump-table.1: %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
46 ; CHECKM1-NOT: %jump-table.2:
47 ; CHECKM3-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
48 ; CHECKM3-NOT: %jump-table.1:
49
50 bb1: tail call void @ext(i32 1, i32 0) br label %return
51 bb2: tail call void @ext(i32 2, i32 2) br label %return
52 bb3: tail call void @ext(i32 3, i32 4) br label %return
53 bb4: tail call void @ext(i32 4, i32 6) br label %return
54 bb5: tail call void @ext(i32 5, i32 8) br label %return
55 bb6: tail call void @ext(i32 6, i32 10) br label %return
56 bb7: tail call void @ext(i32 7, i32 12) br label %return
57 bb8: tail call void @ext(i32 8, i32 14) br label %return
58 bb9: tail call void @ext(i32 9, i32 16) br label %return
32 ; CHECK0-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
33 ; CHECK0-NOT: %jump-table.1:
34 ; CHECK4-NEXT: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5
35 ; CHECK4-SAME: %jump-table.1: %bb.6 %bb.7 %bb.8 %bb.9
36 ; CHECK4-SAME: %jump-table.2: %bb.10 %bb.11 %bb.12 %bb.13
37 ; CHECK4-SAME: %jump-table.3: %bb.14 %bb.15 %bb.16 %bb.17
38 ; CHECK4-NOT: %jump-table.4:
39 ; CHECK8-NEXT: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9
40 ; CHECK8-SAME: %jump-table.1: %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
41 ; CHECK8-NOT: %jump-table.2:
42 ; CHECK16-NEXT: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
43 ; CHECK16-NOT: %jump-table.1:
44 ; CHECKM1-NEXT: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9
45 ; CHECKM1-SAME: %jump-table.1: %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
46 ; CHECKM1-NOT: %jump-table.2:
47 ; CHECKM3-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
48 ; CHECKM3-NOT: %jump-table.1:
49
50 bb1: tail call void @ext(i32 1, i32 0) br label %return
51 bb2: tail call void @ext(i32 2, i32 2) br label %return
52 bb3: tail call void @ext(i32 3, i32 4) br label %return
53 bb4: tail call void @ext(i32 4, i32 6) br label %return
54 bb5: tail call void @ext(i32 5, i32 8) br label %return
55 bb6: tail call void @ext(i32 6, i32 10) br label %return
56 bb7: tail call void @ext(i32 7, i32 12) br label %return
57 bb8: tail call void @ext(i32 8, i32 14) br label %return
58 bb9: tail call void @ext(i32 9, i32 16) br label %return
5959 bb10: tail call void @ext(i32 1, i32 18) br label %return
6060 bb11: tail call void @ext(i32 2, i32 20) br label %return
6161 bb12: tail call void @ext(i32 3, i32 22) br label %return
7171 define void @jt2(i32 %x) {
7272 entry:
7373 switch i32 %x, label %return [
74 i32 1, label %bb1
75 i32 2, label %bb2
76 i32 3, label %bb3
77 i32 4, label %bb4
74 i32 1, label %bb1
75 i32 2, label %bb2
76 i32 3, label %bb3
77 i32 4, label %bb4
7878
7979 i32 14, label %bb5
8080 i32 15, label %bb6
8181 ]
8282 ; CHECK-LABEL: function jt2:
8383 ; CHECK-NEXT: Jump Tables:
84 ; CHECK0-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
85 ; CHECK0-NOT: %jump-table.1
86 ; CHECK4-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
87 ; CHECK4-NOT: %jump-table.1
88 ; CHECK8-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
89 ; CHECK8-NOT: %jump-table.1
90 ; CHECK16-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
91 ; CHECK16-NOT: %jump-table.1:
92 ; CHECKM1-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
93 ; CHECKM1-NOT: %jump-table.1
94 ; CHECKM3-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
95 ; CHECKM3-NOT: %jump-table.1
84 ; CHECK0-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
85 ; CHECK0-NOT: %jump-table.1
86 ; CHECK4-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
87 ; CHECK4-NOT: %jump-table.1
88 ; CHECK8-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
89 ; CHECK8-NOT: %jump-table.1
90 ; CHECK16-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
91 ; CHECK16-NOT: %jump-table.1:
92 ; CHECKM1-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
93 ; CHECKM1-NOT: %jump-table.1
94 ; CHECKM3-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
95 ; CHECKM3-NOT: %jump-table.1
9696 ; CHECK-DAG: End machine code for function jt2.
9797
9898 bb1: tail call void @ext(i32 6, i32 1) br label %return
107107 define void @jt3(i32 %x) {
108108 entry:
109109 switch i32 %x, label %return [
110 i32 1, label %bb1
111 i32 2, label %bb2
112 i32 3, label %bb3
113 i32 4, label %bb4
110 i32 1, label %bb1
111 i32 2, label %bb2
112 i32 3, label %bb3
113 i32 4, label %bb4
114114
115115 i32 14, label %bb5
116116 i32 15, label %bb6
143143 ; CHECKM3-NOT: %jump-table.1
144144 ; CHECK-DAG: End machine code for function jt3.
145145
146 bb1: tail call void @ext(i32 1, i32 12) br label %return
147 bb2: tail call void @ext(i32 2, i32 11) br label %return
148 bb3: tail call void @ext(i32 3, i32 10) br label %return
149 bb4: tail call void @ext(i32 4, i32 9) br label %return
150 bb5: tail call void @ext(i32 5, i32 8) br label %return
151 bb6: tail call void @ext(i32 6, i32 7) br label %return
152 bb7: tail call void @ext(i32 7, i32 6) br label %return
153 bb8: tail call void @ext(i32 8, i32 5) br label %return
154 bb9: tail call void @ext(i32 9, i32 4) br label %return
155 bb10: tail call void @ext(i32 10, i32 3) br label %return
156 bb11: tail call void @ext(i32 11, i32 2) br label %return
157 bb12: tail call void @ext(i32 12, i32 1) br label %return
146 bb1: tail call void @ext(i32 1, i32 12) br label %return
147 bb2: tail call void @ext(i32 2, i32 11) br label %return
148 bb3: tail call void @ext(i32 3, i32 10) br label %return
149 bb4: tail call void @ext(i32 4, i32 9) br label %return
150 bb5: tail call void @ext(i32 5, i32 8) br label %return
151 bb6: tail call void @ext(i32 6, i32 7) br label %return
152 bb7: tail call void @ext(i32 7, i32 6) br label %return
153 bb8: tail call void @ext(i32 8, i32 5) br label %return
154 bb9: tail call void @ext(i32 9, i32 4) br label %return
155 bb10: tail call void @ext(i32 10, i32 3) br label %return
156 bb11: tail call void @ext(i32 11, i32 2) br label %return
157 bb12: tail call void @ext(i32 12, i32 1) br label %return
158158
159159 return: ret void
160160 }
162162 define void @jt4(i32 %x) {
163163 entry:
164164 switch i32 %x, label %default [
165 i32 1, label %bb1
166 i32 2, label %bb2
167 i32 3, label %bb3
168 i32 4, label %bb4
165 i32 1, label %bb1
166 i32 2, label %bb2
167 i32 3, label %bb3
168 i32 4, label %bb4
169169
170170 i32 14, label %bb5
171171 i32 15, label %bb6
198198 ; CHECKM3-NOT: %jump-table.1
199199 ; CHECK-DAG: End machine code for function jt4.
200200
201 bb1: tail call void @ext(i32 1, i32 12) br label %return
202 bb2: tail call void @ext(i32 2, i32 11) br label %return
203 bb3: tail call void @ext(i32 3, i32 10) br label %return
204 bb4: tail call void @ext(i32 4, i32 9) br label %return
205 bb5: tail call void @ext(i32 5, i32 8) br label %return
206 bb6: tail call void @ext(i32 6, i32 7) br label %return
207 bb7: tail call void @ext(i32 7, i32 6) br label %return
208 bb8: tail call void @ext(i32 8, i32 5) br label %return
209 bb9: tail call void @ext(i32 9, i32 4) br label %return
210 bb10: tail call void @ext(i32 10, i32 3) br label %return
211 bb11: tail call void @ext(i32 11, i32 2) br label %return
212 bb12: tail call void @ext(i32 12, i32 1) br label %return
201 bb1: tail call void @ext(i32 1, i32 12) br label %return
202 bb2: tail call void @ext(i32 2, i32 11) br label %return
203 bb3: tail call void @ext(i32 3, i32 10) br label %return
204 bb4: tail call void @ext(i32 4, i32 9) br label %return
205 bb5: tail call void @ext(i32 5, i32 8) br label %return
206 bb6: tail call void @ext(i32 6, i32 7) br label %return
207 bb7: tail call void @ext(i32 7, i32 6) br label %return
208 bb8: tail call void @ext(i32 8, i32 5) br label %return
209 bb9: tail call void @ext(i32 9, i32 4) br label %return
210 bb10: tail call void @ext(i32 10, i32 3) br label %return
211 bb11: tail call void @ext(i32 11, i32 2) br label %return
212 bb12: tail call void @ext(i32 12, i32 1) br label %return
213213 default: unreachable
214214
215215 return: ret void