• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16//! CHECKER       AOT IR Builder, check String Builders merging
17//! SKIP_IF       @architecture == "arm32"
18//! RUN           entry: "ETSGLOBAL::main"
19//! RUN_PAOC      options: "--compiler-regex='.*chain_concat[0-9]*' --compiler-inlining=false"
20//!
21//! METHOD        "ETSGLOBAL::chain_concat0"
22//! PASS_BEFORE   "BranchElimination"
23//! INST_COUNT    "StringBuilder::<ctor>",5
24//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",10
25//! INST_COUNT    "Intrinsic.StdCoreSbToString",5
26//! PASS_AFTER    "SimplifyStringBuilder"
27//! INST_COUNT    "StringBuilder::<ctor>",1
28//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
29//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",4
30//! PASS_AFTER    "Codegen"
31//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
32//!
33//! METHOD        "ETSGLOBAL::chain_concat1"
34//! PASS_BEFORE   "BranchElimination"
35//! INST_COUNT    "StringBuilder::<ctor>",7
36//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",14
37//! INST_COUNT    "Intrinsic.StdCoreSbToString",7
38//! PASS_AFTER    "SimplifyStringBuilder"
39//! INST_COUNT    "StringBuilder::<ctor>",1
40//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
41//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",6
42//! PASS_AFTER    "Codegen"
43//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
44//!
45//! METHOD        "ETSGLOBAL::chain_concat2"
46//! PASS_BEFORE   "BranchElimination"
47//! INST_COUNT    "StringBuilder::<ctor>",9
48//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",18
49//! INST_COUNT    "Intrinsic.StdCoreSbToString",9
50//! PASS_AFTER    "SimplifyStringBuilder"
51//! INST_COUNT    "StringBuilder::<ctor>",1
52//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
53//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",8
54//! PASS_AFTER    "Codegen"
55//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
56//!
57//! METHOD        "ETSGLOBAL::chain_concat3"
58//! PASS_BEFORE   "BranchElimination"
59//! INST_COUNT    "StringBuilder::<ctor>",14
60//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",28
61//! INST_COUNT    "Intrinsic.StdCoreSbToString",14
62//! PASS_AFTER    "SimplifyStringBuilder"
63//! INST_COUNT    "StringBuilder::<ctor>",2
64//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",2
65//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",12
66//! PASS_AFTER    "Codegen"
67//! INST_COUNT    "Intrinsic.StdCoreSbToString",2
68//!
69//! METHOD        "ETSGLOBAL::supported_chain_concat5"
70//! PASS_BEFORE   "BranchElimination"
71//! INST_COUNT    "StringBuilder::<ctor>",2
72//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",4
73//! INST_COUNT    "Intrinsic.StdCoreSbAppendChar",2
74//! INST_COUNT    "Intrinsic.StdCoreSbAppendInt",2
75//! INST_COUNT    "Intrinsic.StdCoreSbToString",2
76//! PASS_AFTER    "SimplifyStringBuilder"
77//! INST_COUNT    "StringBuilder::<ctor>",1
78//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",3
79//! INST_COUNT    "Intrinsic.StdCoreSbAppendChar",2
80//! INST_COUNT    "Intrinsic.StdCoreSbAppendInt",2
81//! PASS_AFTER    "Codegen"
82//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
83//!
84//! METHOD        "ETSGLOBAL::supported_chain_concat6"
85//! PASS_BEFORE   "BranchElimination"
86//! INST_COUNT    "StringBuilder::<ctor>",2
87//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",37
88//! INST_COUNT    "Intrinsic.StdCoreSbAppendBool",4
89//! INST_COUNT    "Intrinsic.StdCoreSbAppendChar",2
90//! INST_COUNT    "Intrinsic.StdCoreSbAppendByte",4
91//! INST_COUNT    "Intrinsic.StdCoreSbAppendShort",2
92//! INST_COUNT    "Intrinsic.StdCoreSbAppendInt",2
93//! INST_COUNT    "Intrinsic.StdCoreSbAppendLong",2
94//! INST_COUNT    "std.core.StringBuilder::append",8
95//! INST_COUNT    "Intrinsic.StdCoreSbToString",2
96//! PASS_AFTER    "SimplifyStringBuilder"
97//! INST_COUNT    "StringBuilder::<ctor>",1
98//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",22
99//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",0
100//! INST_COUNT    "Intrinsic.StdCoreSbAppendString3",2
101//! INST_COUNT    "Intrinsic.StdCoreSbAppendString4",2
102//! PASS_AFTER    "Codegen"
103//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
104//!
105//! METHOD        "ETSGLOBAL::unsupported_append_chain_concat7"
106//! PASS_BEFORE   "BranchElimination"
107//! INST_COUNT    "StringBuilder::<ctor>",2
108//! PASS_AFTER    "SimplifyStringBuilder"
109//! INST_COUNT    "StringBuilder::<ctor>",2
110//!
111//! METHOD        "ETSGLOBAL::unsupported_constructor_chain_concat8"
112//! PASS_BEFORE   "BranchElimination"
113//! INST_COUNT    "StringBuilder::<ctor>",2
114//! PASS_AFTER    "SimplifyStringBuilder"
115//! INST_COUNT    "StringBuilder::<ctor>",2
116//!
117//! METHOD        "ETSGLOBAL::unsupported_usage_chain_concat9"
118//! PASS_BEFORE   "BranchElimination"
119//! INST_COUNT    "StringBuilder::<ctor>",2
120//! PASS_AFTER    "SimplifyStringBuilder"
121//! INST_COUNT    "StringBuilder::<ctor>",2
122//!
123//! METHOD        "ETSGLOBAL::unsupported_chain_concat10"
124//! PASS_BEFORE   "BranchElimination"
125//! INST_COUNT    "StringBuilder::<ctor>",2
126//! PASS_AFTER    "SimplifyStringBuilder"
127//! INST_COUNT    "StringBuilder::<ctor>",2
128//!
129//! METHOD        "ETSGLOBAL::unsupported_chain_concat11"
130//! PASS_BEFORE   "BranchElimination"
131//! INST_COUNT    "StringBuilder::<ctor>",3
132//! PASS_AFTER    "SimplifyStringBuilder"
133//! INST_COUNT    "StringBuilder::<ctor>",3
134//!
135//! METHOD        "ETSGLOBAL::unsupported_chain_concat12"
136//! PASS_BEFORE   "BranchElimination"
137//! INST_COUNT    "StringBuilder::<ctor>",2
138//! PASS_AFTER    "SimplifyStringBuilder"
139//! INST_COUNT    "StringBuilder::<ctor>",2
140//!
141//! METHOD        "ETSGLOBAL::unsupported_chain_concat13"
142//! PASS_BEFORE   "BranchElimination"
143//! INST_COUNT    "StringBuilder::<ctor>",1
144//! PASS_AFTER    "SimplifyStringBuilder"
145//! INST_COUNT    "StringBuilder::<ctor>",1
146//!
147//! METHOD        "ETSGLOBAL::partially_supported_chain_concat14"
148//! PASS_BEFORE   "BranchElimination"
149//! INST_COUNT    "StringBuilder::<ctor>",3
150//! INST_COUNT    "Intrinsic.StdCoreSbAppendString",6
151//! INST_COUNT    "Intrinsic.StdCoreSbToString",3
152//! PASS_AFTER    "SimplifyStringBuilder"
153//! INST_COUNT    "StringBuilder::<ctor>",1
154//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
155//! INST_COUNT    "Intrinsic.StdCoreStringConcat2",1
156//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",1
157//! PASS_AFTER    "Codegen"
158//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
159//!
160//! METHOD        "ETSGLOBAL::supported_chain_concat15"
161//! PASS_BEFORE   "BranchElimination"
162//! INST_COUNT    "StringBuilder::<ctor>",3
163//! INST_COUNT    "Intrinsic.StdCoreSbAppendString",6
164//! INST_COUNT    "Intrinsic.StdCoreSbToString",3
165//! PASS_AFTER    "SimplifyStringBuilder"
166//! INST_COUNT    "StringBuilder::<ctor>",1
167//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
168//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",2
169//! PASS_AFTER    "Codegen"
170//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
171//!
172//! METHOD        "ETSGLOBAL::partially_supported_chain_concat16"
173//! PASS_BEFORE   "BranchElimination"
174//! INST_COUNT    "StringBuilder::<ctor>",3
175//! INST_COUNT    "Intrinsic.StdCoreSbAppendString",6
176//! INST_COUNT    "Intrinsic.StdCoreSbToString",3
177//! PASS_AFTER    "SimplifyStringBuilder"
178//! INST_COUNT    "StringBuilder::<ctor>",1
179//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
180//! INST_COUNT    "Intrinsic.StdCoreStringConcat2",1
181//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",1
182//! PASS_AFTER    "Codegen"
183//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
184//!
185//! METHOD        "ETSGLOBAL::unsupported_usage_chain_concat17"
186//! PASS_BEFORE   "BranchElimination"
187//! INST_COUNT    "StringBuilder::<ctor>",1
188//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",2
189//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
190//! PASS_AFTER    "SimplifyStringBuilder"
191//! INST_COUNT    "StringBuilder::<ctor>",1
192//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",2
193//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
194//!
195//! METHOD        "ETSGLOBAL::unsupported_usage_chain_concat18"
196//! PASS_BEFORE   "BranchElimination"
197//! INST_COUNT    "StringBuilder::<ctor>",1
198//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",2
199//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
200//! PASS_AFTER    "SimplifyStringBuilder"
201//! INST_COUNT    "StringBuilder::<ctor>",1
202//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",2
203//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
204
205//! CHECKER       JIT IR Builder, check String Builders merging
206//! SKIP_IF       @architecture == "arm32"
207//! RUN           force_jit: true, options: "--compiler-regex='.*chain_concat[0-9]+.*' --compiler-inlining=false", entry: "ETSGLOBAL::main"
208//!
209//! METHOD        "ETSGLOBAL::chain_concat0"
210//! PASS_BEFORE   "BranchElimination"
211//! INST_COUNT    "StringBuilder::<ctor>",5
212//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",10
213//! INST_COUNT    "Intrinsic.StdCoreSbToString",5
214//! PASS_AFTER    "SimplifyStringBuilder"
215//! INST_COUNT    "StringBuilder::<ctor>",1
216//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
217//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",4
218//! PASS_AFTER    "Codegen"
219//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
220//!
221//! METHOD        "ETSGLOBAL::chain_concat1"
222//! PASS_BEFORE   "BranchElimination"
223//! INST_COUNT    "StringBuilder::<ctor>",7
224//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",14
225//! INST_COUNT    "Intrinsic.StdCoreSbToString",7
226//! PASS_AFTER    "SimplifyStringBuilder"
227//! INST_COUNT    "StringBuilder::<ctor>",1
228//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
229//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",6
230//! PASS_AFTER    "Codegen"
231//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
232//!
233//! METHOD        "ETSGLOBAL::chain_concat2"
234//! PASS_BEFORE   "BranchElimination"
235//! INST_COUNT    "StringBuilder::<ctor>",9
236//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",18
237//! INST_COUNT    "Intrinsic.StdCoreSbToString",9
238//! PASS_AFTER    "SimplifyStringBuilder"
239//! INST_COUNT    "StringBuilder::<ctor>",1
240//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
241//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",8
242//! PASS_AFTER    "Codegen"
243//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
244//!
245//! METHOD        "ETSGLOBAL::chain_concat3"
246//! PASS_BEFORE   "BranchElimination"
247//! INST_COUNT    "StringBuilder::<ctor>",14
248//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",28
249//! INST_COUNT    "Intrinsic.StdCoreSbToString",14
250//! PASS_AFTER    "SimplifyStringBuilder"
251//! INST_COUNT    "StringBuilder::<ctor>",2
252//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",2
253//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",12
254//! PASS_AFTER    "Codegen"
255//! INST_COUNT    "Intrinsic.StdCoreSbToString",2
256//!
257//! METHOD        "ETSGLOBAL::supported_chain_concat5"
258//! PASS_BEFORE   "BranchElimination"
259//! INST_COUNT    "StringBuilder::<ctor>",2
260//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",4
261//! INST_COUNT    "Intrinsic.StdCoreSbAppendChar",2
262//! INST_COUNT    "Intrinsic.StdCoreSbAppendInt",2
263//! INST_COUNT    "Intrinsic.StdCoreSbToString",2
264//! PASS_AFTER    "SimplifyStringBuilder"
265//! INST_COUNT    "StringBuilder::<ctor>",1
266//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",3
267//! INST_COUNT    "Intrinsic.StdCoreSbAppendChar",2
268//! INST_COUNT    "Intrinsic.StdCoreSbAppendInt",2
269//! PASS_AFTER    "Codegen"
270//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
271//!
272//! METHOD        "ETSGLOBAL::supported_chain_concat6"
273//! PASS_BEFORE   "BranchElimination"
274//! INST_COUNT    "StringBuilder::<ctor>",2
275//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",37
276//! INST_COUNT    "Intrinsic.StdCoreSbAppendBool",4
277//! INST_COUNT    "Intrinsic.StdCoreSbAppendChar",2
278//! INST_COUNT    "Intrinsic.StdCoreSbAppendByte",4
279//! INST_COUNT    "Intrinsic.StdCoreSbAppendShort",2
280//! INST_COUNT    "Intrinsic.StdCoreSbAppendInt",2
281//! INST_COUNT    "Intrinsic.StdCoreSbAppendLong",2
282//! INST_COUNT    "std.core.StringBuilder::append",8
283//! INST_COUNT    "Intrinsic.StdCoreSbToString",2
284//! PASS_AFTER    "SimplifyStringBuilder"
285//! INST_COUNT    "StringBuilder::<ctor>",1
286//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",22
287//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",0
288//! INST_COUNT    "Intrinsic.StdCoreSbAppendString3",2
289//! INST_COUNT    "Intrinsic.StdCoreSbAppendString4",2
290//! PASS_AFTER    "Codegen"
291//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
292//!
293//! METHOD        "ETSGLOBAL::unsupported_append_chain_concat7"
294//! PASS_BEFORE   "BranchElimination"
295//! INST_COUNT    "StringBuilder::<ctor>",2
296//! PASS_AFTER    "SimplifyStringBuilder"
297//! INST_COUNT    "StringBuilder::<ctor>",2
298//!
299//! METHOD        "ETSGLOBAL::unsupported_constructor_chain_concat8"
300//! PASS_BEFORE   "BranchElimination"
301//! INST_COUNT    "StringBuilder::<ctor>",2
302//! PASS_AFTER    "SimplifyStringBuilder"
303//! INST_COUNT    "StringBuilder::<ctor>",2
304//!
305//! METHOD        "ETSGLOBAL::unsupported_usage_chain_concat9"
306//! PASS_BEFORE   "BranchElimination"
307//! INST_COUNT    "StringBuilder::<ctor>",2
308//! PASS_AFTER    "SimplifyStringBuilder"
309//! INST_COUNT    "StringBuilder::<ctor>",2
310//!
311//! METHOD        "ETSGLOBAL::unsupported_chain_concat10"
312//! PASS_BEFORE   "BranchElimination"
313//! INST_COUNT    "StringBuilder::<ctor>",2
314//! PASS_AFTER    "SimplifyStringBuilder"
315//! INST_COUNT    "StringBuilder::<ctor>",2
316//!
317//! METHOD        "ETSGLOBAL::unsupported_chain_concat11"
318//! PASS_BEFORE   "BranchElimination"
319//! INST_COUNT    "StringBuilder::<ctor>",3
320//! PASS_AFTER    "SimplifyStringBuilder"
321//! INST_COUNT    "StringBuilder::<ctor>",3
322//!
323//! METHOD        "ETSGLOBAL::unsupported_chain_concat12"
324//! PASS_BEFORE   "BranchElimination"
325//! INST_COUNT    "StringBuilder::<ctor>",2
326//! PASS_AFTER    "SimplifyStringBuilder"
327//! INST_COUNT    "StringBuilder::<ctor>",2
328//!
329//! METHOD        "ETSGLOBAL::unsupported_chain_concat13"
330//! PASS_BEFORE   "BranchElimination"
331//! INST_COUNT    "StringBuilder::<ctor>",1
332//! PASS_AFTER    "SimplifyStringBuilder"
333//! INST_COUNT    "StringBuilder::<ctor>",1
334//!
335//! METHOD        "ETSGLOBAL::partially_supported_chain_concat14"
336//! PASS_BEFORE   "BranchElimination"
337//! INST_COUNT    "StringBuilder::<ctor>",3
338//! INST_COUNT    "Intrinsic.StdCoreSbAppendString",6
339//! INST_COUNT    "Intrinsic.StdCoreSbToString",3
340//! PASS_AFTER    "SimplifyStringBuilder"
341//! INST_COUNT    "StringBuilder::<ctor>",1
342//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
343//! INST_COUNT    "Intrinsic.StdCoreStringConcat2",1
344//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",1
345//! PASS_AFTER    "Codegen"
346//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
347//!
348//! METHOD        "ETSGLOBAL::supported_chain_concat15"
349//! PASS_BEFORE   "BranchElimination"
350//! INST_COUNT    "StringBuilder::<ctor>",3
351//! INST_COUNT    "Intrinsic.StdCoreSbAppendString",6
352//! INST_COUNT    "Intrinsic.StdCoreSbToString",3
353//! PASS_AFTER    "SimplifyStringBuilder"
354//! INST_COUNT    "StringBuilder::<ctor>",1
355//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
356//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",2
357//! PASS_AFTER    "Codegen"
358//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
359//!
360//! METHOD        "ETSGLOBAL::partially_supported_chain_concat16"
361//! PASS_BEFORE   "BranchElimination"
362//! INST_COUNT    "StringBuilder::<ctor>",3
363//! INST_COUNT    "Intrinsic.StdCoreSbAppendString",6
364//! INST_COUNT    "Intrinsic.StdCoreSbToString",3
365//! PASS_AFTER    "SimplifyStringBuilder"
366//! INST_COUNT    "StringBuilder::<ctor>",1
367//! INST_COUNT    "Intrinsic.StdCoreSbAppendString2",1
368//! INST_COUNT    "Intrinsic.StdCoreStringConcat2",1
369//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",1
370//! PASS_AFTER    "Codegen"
371//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
372//!
373//! METHOD        "ETSGLOBAL::unsupported_usage_chain_concat17"
374//! PASS_BEFORE   "BranchElimination"
375//! INST_COUNT    "StringBuilder::<ctor>",1
376//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",2
377//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
378//! PASS_AFTER    "SimplifyStringBuilder"
379//! INST_COUNT    "StringBuilder::<ctor>",1
380//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",2
381//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
382//!
383//! METHOD        "ETSGLOBAL::unsupported_usage_chain_concat18"
384//! PASS_BEFORE   "BranchElimination"
385//! INST_COUNT    "StringBuilder::<ctor>",1
386//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",2
387//! INST_COUNT    "Intrinsic.StdCoreSbToString",1
388//! INST_COUNT    "String::concat",1
389//! PASS_AFTER    "SimplifyStringBuilder"
390//! INST_COUNT    "StringBuilder::<ctor>",2
391//! INST_COUNT    "Intrinsic.StdCoreSbAppendString ",3
392//! INST_COUNT    "Intrinsic.StdCoreSbToString",2
393//! INST_NOT      "String::concat"
394
395// Each '+=' operation on strings in tests below is translated into StringBuilder + 2 append calls by frontend
396
397function chain_concat0(a: String, n: int, b: String, m: int): String {
398    let str: String = "";
399    str += "_";
400    for (let i = 0; i < n; ++i)
401        str += a;
402    str += "_";
403    for (let i = 0; i < m; ++i)
404        str += b;
405    str += "_";
406    return str;                                 // applied, 5 SBs merged into 1
407}
408
409function chain_concat1(a: String, n: int, b: String, m: int, c: String, l: int): String {
410    let str: String = "";
411    str += "_";
412    for (let i = 0; i < n; ++i)
413        str += a;
414    str += "_";
415    for (let i = 0; i < m; ++i)
416        str += b;
417    str += "_";
418    for (let i = 0; i < l; ++i)
419        str += c;
420    str += "_";
421    return str;                                 // applied, 7 SBs merged into 1
422}
423
424function chain_concat2(a: String, n: int, b: String, m: int, c: String, l: int, d: String, k: int): String {
425    let str: String = "";
426    str += "_";
427    for (let i = 0; i < n; ++i)
428        str += a;
429    str += "_";
430    for (let i = 0; i < m; ++i)
431        str += b;
432    str += "_";
433    for (let i = 0; i < l; ++i)
434        str += c;
435    str += "_";
436    for (let i = 0; i < k; ++i)
437        str += d;
438    str += "_";
439    return str;                                 // applied, 9 SBs merged into 1
440}
441
442function chain_concat3(a: String, n: int, b: String, m: int, c: String, l: int, d: String, k: int): String {
443    let str0: String = "";                      // two SBs chains '0' and '1'
444    let str1: String = "";                      // for each string accumulator variable
445    str0 += "_";                                //  0
446    str1 += "_";                                //  |     1
447    for (let i = 0; i < n; ++i) {               //  |     |
448        str0 += a;                              //  0     |
449        str1 += a;                              //  |     1
450    }                                           //  |     |
451    str0 += "_";                                //  0     |
452    str1 += "_";                                //  |     1
453    for (let i = 0; i < m; ++i) {               //  |    /
454        str0 += b;                              //  0   /
455        str1 += b;                              //  |  1
456    }                                           //  | /
457                                                //  |/
458    str0 += str1;                               //  0 <- 'chain 1' connects to 'chain 0' here
459    str0 += "_";                                //  0
460                                                //  |
461    for (let i = 0; i < l; ++i)                 //  |
462        str0 += c;                              //  0
463    str0 += "_";                                //  0
464    for (let i = 0; i < k; ++i)                 //  |
465        str0 += d;                              //  0
466    str0 += "_";                                //  0
467    return str0;    // applied, 14 SBs (10 from 'chain 0', and 4 from 'chain 1') merged into 2 SBs
468}
469
470// Set of SB based tests
471
472const empty = "";
473const space = " ";
474
475function supported_chain_concat5(): String {
476    let sb0 = new StringBuilder();
477    sb0.append(0)
478       .append("1")
479       .append(c'2');
480
481    let sb1 = new StringBuilder();
482    sb1.append(sb0.toString())
483       .append(space)
484       .append(0)
485       .append("1")
486       .append(c'2');
487
488    return sb1.toString();                  // applied
489}
490
491function supported_chain_concat6(): String {
492    let sb0 = new StringBuilder();
493    sb0.append(space)
494       .append("abcΣΨΩ0123456789")
495       .append(space)
496       .append(true)
497       .append(space)
498       .append(false)
499       .append(space)
500       .append(c'A' as char)
501       .append(space)
502       .append(57 as byte)
503       .append(space)
504       .append(127 as byte)
505       .append(space)
506       .append(32767 as short)
507       .append(space)
508       .append(128934675 as int)
509       .append(space)
510       .append(701234987654321 as long)
511       .append(space)
512       .append(empty)
513       .append("string")
514       .append(space)
515       .append(new Object())
516       .append(space)
517       .append(1.0 as Float)
518       .append(space)
519       .append(1.0 as Double)
520       .append(space)
521       .append(1.0 as Number)
522       .append(space);
523
524    let sb1 = new StringBuilder();
525    sb1.append(sb0.toString())
526       .append(space)
527       .append("abcΣΨΩ0123456789")
528       .append(space)
529       .append(true)
530       .append(space)
531       .append(false)
532       .append(space)
533       .append(c'A' as char)
534       .append(space)
535       .append(57 as byte)
536       .append(space)
537       .append(127 as byte)
538       .append(space)
539       .append(32767 as short)
540       .append(space)
541       .append(128934675 as int)
542       .append(space)
543       .append(701234987654321 as long)
544       .append(space)
545       .append(empty)
546       .append("string")
547       .append(space)
548       .append(new Object())
549       .append(space)
550       .append(1.0 as Float)
551       .append(space)
552       .append(1.0 as Double)
553       .append(space)
554       .append(1.0 as Number)
555       .append(space);
556
557    return sb1.toString();                  // applied
558}
559
560function unsupported_append_chain_concat7(): String {
561    let sb0 = new StringBuilder();
562    sb0.append(0);
563
564    let sb1 = new StringBuilder();
565    sb1.append(0)
566       .append(space)
567       .append(sb0.toString());
568
569    return sb1.toString();                  // not applied, sb0.toString() must be appended first
570}
571
572function unsupported_constructor_chain_concat8(): String {
573    let sb0 = new StringBuilder();
574    sb0.append(0);
575
576    let sb1 = new StringBuilder("0");
577    sb1.append(sb0.toString());
578
579    return sb1.toString();                  // not applied, sb1 must be constructed via default constructor
580}
581
582function unsupported_usage_chain_concat9(): String {
583    let sb0 = new StringBuilder();
584    sb0.append(0);
585
586    let sb1 = new StringBuilder();
587    sb1.append(sb0.toString());
588
589    sb0.append(space);
590
591    return sb1.toString();                  // not applied, sb0 must not be used after sb0.toString() appended
592}
593
594function unsupported_chain_concat10(cond: boolean): String {
595    let sb0 = new StringBuilder();
596    sb0.append(0)
597       .append("1")
598       .append(c'2');
599
600    let sb1 = new StringBuilder();
601    if (cond)
602        sb1.append(sb0.toString());
603    else
604        sb1.append("210");
605
606    sb1.append(space)
607       .append(0)
608       .append("1")
609       .append(c'2');
610
611    return sb1.toString();                  // not applied, sb1 constructor and sb1.append(sb0.toString()) are not in the same BB
612}
613
614function unsupported_chain_concat11(cond: boolean): String {
615    let sb0 = new StringBuilder("0");
616    let sb1 = new StringBuilder("1");
617
618    let sb = cond ? sb1 : sb0;
619
620    let sb2 = new StringBuilder();
621    sb2.append(sb.toString())
622       .append(space)
623       .append(2);
624
625    return sb2.toString();                  // not applied, sb is Phi instruction
626}
627
628function __noinline__consume(obj: Object): void {}
629
630function unsupported_chain_concat12(cond: boolean): String {
631    let sb0 = new StringBuilder("0");
632    let sb1 = new StringBuilder();
633    let sb = cond ? sb1 : sb0;
634
635    sb1.append(sb0.toString())
636       .append(space)
637       .append(1);
638
639    __noinline__consume(sb);
640
641    return sb1.toString();                  // not applied, sb0 must not be used after sb0.toString() appended
642}
643
644let sb0_global = new StringBuilder("0");
645function unsupported_chain_concat13(): String {
646    let sb1 = new StringBuilder();
647    sb1.append(sb0_global.toString())
648       .append(space)
649       .append(1);
650
651    return sb1.toString();                  // not applied, sb0 must be local instance
652}
653
654function partially_supported_chain_concat14(a: String, b: String, c: String, d: String): String {
655    let ab = a + b;
656    let cd = c + d;                                 // not applied, due to 'cd' appended to result is not the first append
657    return ab + cd;                                 // applied, 3 SBs merged into 1 SB + concat2
658}
659
660function supported_chain_concat15(a: String, b: String, c: String, d: String): String {
661    let str = a + b;
662    str += c;
663    str += d;                                       // applied, 3 SBs merged into 1 SB
664    return str;
665}
666
667function partially_supported_chain_concat16(a: String, b: String, c: String, d: String): String {
668    let abcd = a + b;
669    abcd += c + d;                                  // not applied, due to 'c+d' appended to result is not the first append
670    return abcd;                                    // applied, 3 SBs merged into 1 SB + concat2
671}
672
673function unsupported_usage_chain_concat17(a: String): String {
674    let sb = new StringBuilder();
675    sb.append(a);
676    let result = sb.toString();
677    sb.append(a);
678    return result;                                  // not applied, sb must not be used after sb.toString() appended
679}
680
681function unsupported_usage_chain_concat18(a: String): String {
682    let sb = new StringBuilder();
683    sb.append(a);
684    let result = sb.toString();
685    sb.append(a);
686    return result.concat();                         // not applied, sb must not be used after sb.toString() appended
687}
688
689//! CHECKER       AOT IR Builder, check String Builders merging (chain_concat19 only, with --compiler-inlining=true)
690//! SKIP_IF       @architecture == "arm32"
691//! RUN_PAOC      options: "--compiler-regex='.*chain_concat19' --compiler-inlining=true"
692
693function chain_concat19(): void {
694    const _ = "_";
695    const a = "a";
696    const b = "b";
697    const c = "c";
698
699    let sb_a = new StringBuilder();
700    sb_a.append(_)
701    sb_a.append(a)
702    let _a = sb_a.toString()
703
704    let sb_ab = new StringBuilder();
705    sb_ab.append(_a)
706    sb_ab.append(b)
707    let _ab = sb_ab.toString()
708
709    let sb_abc = new StringBuilder();
710    sb_abc.append(_ab)
711    sb_abc.append(c)
712    let _abc = sb_abc.toString()
713
714    assert _a == "_a";
715    assert _ab == "_ab";
716    assert _abc == "_abc";
717}
718
719function main() {
720    assert chain_concat0("a", 4, "b", 3) == "_aaaa_bbb_": "Wrong result at chain_concat0"
721    assert chain_concat1("a", 4, "b", 3, "c", 5) == "_aaaa_bbb_ccccc_": "Wrong result at chain_concat1"
722    assert chain_concat2("a", 4, "b", 3, "c", 5, "d", 2) == "_aaaa_bbb_ccccc_dd_": "Wrong result at chain_concat2"
723    assert chain_concat3("a", 4, "b", 3, "c", 5, "d", 2) == "_aaaa_bbb_aaaa_bbb_ccccc_dd_": "Wrong result at chain_concat3"
724
725    assert supported_chain_concat5() == "012 012": "Wrong result at supported_chain_concat5"
726    assert supported_chain_concat6() == " abcΣΨΩ0123456789 true false A 57 127 32767 128934675 701234987654321 string [object Object] 1 1 1  abcΣΨΩ0123456789 true false A 57 127 32767 128934675 701234987654321 string [object Object] 1 1 1 ": "Wrong result at supported_chain_concat6"
727
728    assert unsupported_append_chain_concat7() == "0 0": "Wrong result at unsupported_append_chain_concat7"
729    assert unsupported_constructor_chain_concat8() == "00": "Wrong result at unsupported_constructor_chain_concat8"
730    assert unsupported_usage_chain_concat9() == "0": "Wrong result at unsupported_usage_chain_concat9"
731
732    assert unsupported_chain_concat10(false) == "210 012": "Wrong result at unsupported_chain_concat10(false)"
733    assert unsupported_chain_concat10(true) == "012 012": "Wrong result at unsupported_chain_concat10(true)"
734
735    assert unsupported_chain_concat11(false) == "0 2": "Wrong result at unsupported_chain_concat11(false)"
736    assert unsupported_chain_concat11(true) == "1 2": "Wrong result at unsupported_chain_concat11(true)"
737
738    assert unsupported_chain_concat12(false) == "0 1": "Wrong result at unsupported_chain_concat12(false)"
739    assert unsupported_chain_concat12(true) == "0 1": "Wrong result at unsupported_chain_concat12(true)"
740
741    assert unsupported_chain_concat13() == "0 1": "Wrong result at unsupported_chain_concat13()"
742
743    assert partially_supported_chain_concat14("ab", "c", "d", "e") == "abcde": "Wrong result at partially_supported_chain_concat14";
744    assert supported_chain_concat15("ab", "c", "d", "e") == "abcde": "Wrong result at supported_chain_concat15";
745    assert partially_supported_chain_concat16("ab", "c", "d", "e") == "abcde": "Wrong result at partially_supported_chain_concat16";
746    assert unsupported_usage_chain_concat17("abc") == "abc": "Wrong result at unsupported_usage_chain_concat17";
747    assert unsupported_usage_chain_concat18("abc") == "abc": "Wrong result at unsupported_usage_chain_concat18";
748
749    chain_concat19();
750}
751