2 * Optimizations for Tiny Code Generator for QEMU
4 * Copyright (c) 2010 Samsung Electronics.
5 * Contributed by Kirill Batuzov <batuzovk@ispras.ru>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 #include "qemu-common.h"
34 #define CASE_OP_32_64(x) \
35 glue(glue(case INDEX_op_, x), _i32): \
36 glue(glue(case INDEX_op_, x), _i64)
44 struct tcg_temp_info
{
51 static struct tcg_temp_info temps
[TCG_MAX_TEMPS
];
53 /* Reset TEMP's state to TCG_TEMP_UNDEF. If TEMP only had one copy, remove
54 the copy flag from the left temp. */
55 static void reset_temp(TCGArg temp
)
57 if (temps
[temp
].state
== TCG_TEMP_COPY
) {
58 if (temps
[temp
].prev_copy
== temps
[temp
].next_copy
) {
59 temps
[temps
[temp
].next_copy
].state
= TCG_TEMP_UNDEF
;
61 temps
[temps
[temp
].next_copy
].prev_copy
= temps
[temp
].prev_copy
;
62 temps
[temps
[temp
].prev_copy
].next_copy
= temps
[temp
].next_copy
;
65 temps
[temp
].state
= TCG_TEMP_UNDEF
;
68 /* Reset all temporaries, given that there are NB_TEMPS of them. */
69 static void reset_all_temps(int nb_temps
)
72 for (i
= 0; i
< nb_temps
; i
++) {
73 temps
[i
].state
= TCG_TEMP_UNDEF
;
77 static int op_bits(TCGOpcode op
)
79 const TCGOpDef
*def
= &tcg_op_defs
[op
];
80 return def
->flags
& TCG_OPF_64BIT
? 64 : 32;
83 static TCGOpcode
op_to_movi(TCGOpcode op
)
85 switch (op_bits(op
)) {
87 return INDEX_op_movi_i32
;
89 return INDEX_op_movi_i64
;
91 fprintf(stderr
, "op_to_movi: unexpected return value of "
92 "function op_bits.\n");
97 static TCGArg
find_better_copy(TCGContext
*s
, TCGArg temp
)
101 /* If this is already a global, we can't do better. */
102 if (temp
< s
->nb_globals
) {
106 /* Search for a global first. */
107 for (i
= temps
[temp
].next_copy
; i
!= temp
; i
= temps
[i
].next_copy
) {
108 if (i
< s
->nb_globals
) {
113 /* If it is a temp, search for a temp local. */
114 if (!s
->temps
[temp
].temp_local
) {
115 for (i
= temps
[temp
].next_copy
; i
!= temp
; i
= temps
[i
].next_copy
) {
116 if (s
->temps
[i
].temp_local
) {
122 /* Failure to find a better representation, return the same temp. */
126 static bool temps_are_copies(TCGArg arg1
, TCGArg arg2
)
134 if (temps
[arg1
].state
!= TCG_TEMP_COPY
135 || temps
[arg2
].state
!= TCG_TEMP_COPY
) {
139 for (i
= temps
[arg1
].next_copy
; i
!= arg1
; i
= temps
[i
].next_copy
) {
148 static void tcg_opt_gen_mov(TCGContext
*s
, TCGArg
*gen_args
,
149 TCGArg dst
, TCGArg src
)
152 assert(temps
[src
].state
!= TCG_TEMP_CONST
);
154 if (s
->temps
[src
].type
== s
->temps
[dst
].type
) {
155 if (temps
[src
].state
!= TCG_TEMP_COPY
) {
156 temps
[src
].state
= TCG_TEMP_COPY
;
157 temps
[src
].next_copy
= src
;
158 temps
[src
].prev_copy
= src
;
160 temps
[dst
].state
= TCG_TEMP_COPY
;
161 temps
[dst
].next_copy
= temps
[src
].next_copy
;
162 temps
[dst
].prev_copy
= src
;
163 temps
[temps
[dst
].next_copy
].prev_copy
= dst
;
164 temps
[src
].next_copy
= dst
;
171 static void tcg_opt_gen_movi(TCGArg
*gen_args
, TCGArg dst
, TCGArg val
)
174 temps
[dst
].state
= TCG_TEMP_CONST
;
175 temps
[dst
].val
= val
;
180 static TCGOpcode
op_to_mov(TCGOpcode op
)
182 switch (op_bits(op
)) {
184 return INDEX_op_mov_i32
;
186 return INDEX_op_mov_i64
;
188 fprintf(stderr
, "op_to_mov: unexpected return value of "
189 "function op_bits.\n");
194 static TCGArg
do_constant_folding_2(TCGOpcode op
, TCGArg x
, TCGArg y
)
215 case INDEX_op_shl_i32
:
216 return (uint32_t)x
<< (uint32_t)y
;
218 case INDEX_op_shl_i64
:
219 return (uint64_t)x
<< (uint64_t)y
;
221 case INDEX_op_shr_i32
:
222 return (uint32_t)x
>> (uint32_t)y
;
224 case INDEX_op_shr_i64
:
225 return (uint64_t)x
>> (uint64_t)y
;
227 case INDEX_op_sar_i32
:
228 return (int32_t)x
>> (int32_t)y
;
230 case INDEX_op_sar_i64
:
231 return (int64_t)x
>> (int64_t)y
;
233 case INDEX_op_rotr_i32
:
234 x
= ((uint32_t)x
<< (32 - y
)) | ((uint32_t)x
>> y
);
237 case INDEX_op_rotr_i64
:
238 x
= ((uint64_t)x
<< (64 - y
)) | ((uint64_t)x
>> y
);
241 case INDEX_op_rotl_i32
:
242 x
= ((uint32_t)x
<< y
) | ((uint32_t)x
>> (32 - y
));
245 case INDEX_op_rotl_i64
:
246 x
= ((uint64_t)x
<< y
) | ((uint64_t)x
>> (64 - y
));
270 CASE_OP_32_64(ext8s
):
273 CASE_OP_32_64(ext16s
):
276 CASE_OP_32_64(ext8u
):
279 CASE_OP_32_64(ext16u
):
282 case INDEX_op_ext32s_i64
:
285 case INDEX_op_ext32u_i64
:
290 "Unrecognized operation %d in do_constant_folding.\n", op
);
295 static TCGArg
do_constant_folding(TCGOpcode op
, TCGArg x
, TCGArg y
)
297 TCGArg res
= do_constant_folding_2(op
, x
, y
);
298 if (op_bits(op
) == 32) {
304 static bool do_constant_folding_cond_32(uint32_t x
, uint32_t y
, TCGCond c
)
312 return (int32_t)x
< (int32_t)y
;
314 return (int32_t)x
>= (int32_t)y
;
316 return (int32_t)x
<= (int32_t)y
;
318 return (int32_t)x
> (int32_t)y
;
332 static bool do_constant_folding_cond_64(uint64_t x
, uint64_t y
, TCGCond c
)
340 return (int64_t)x
< (int64_t)y
;
342 return (int64_t)x
>= (int64_t)y
;
344 return (int64_t)x
<= (int64_t)y
;
346 return (int64_t)x
> (int64_t)y
;
360 static bool do_constant_folding_cond_eq(TCGCond c
)
380 /* Return 2 if the condition can't be simplified, and the result
381 of the condition (0 or 1) if it can */
382 static TCGArg
do_constant_folding_cond(TCGOpcode op
, TCGArg x
,
385 if (temps
[x
].state
== TCG_TEMP_CONST
&& temps
[y
].state
== TCG_TEMP_CONST
) {
386 switch (op_bits(op
)) {
388 return do_constant_folding_cond_32(temps
[x
].val
, temps
[y
].val
, c
);
390 return do_constant_folding_cond_64(temps
[x
].val
, temps
[y
].val
, c
);
394 } else if (temps_are_copies(x
, y
)) {
395 return do_constant_folding_cond_eq(c
);
396 } else if (temps
[y
].state
== TCG_TEMP_CONST
&& temps
[y
].val
== 0) {
410 /* Return 2 if the condition can't be simplified, and the result
411 of the condition (0 or 1) if it can */
412 static TCGArg
do_constant_folding_cond2(TCGArg
*p1
, TCGArg
*p2
, TCGCond c
)
414 TCGArg al
= p1
[0], ah
= p1
[1];
415 TCGArg bl
= p2
[0], bh
= p2
[1];
417 if (temps
[bl
].state
== TCG_TEMP_CONST
418 && temps
[bh
].state
== TCG_TEMP_CONST
) {
419 uint64_t b
= ((uint64_t)temps
[bh
].val
<< 32) | (uint32_t)temps
[bl
].val
;
421 if (temps
[al
].state
== TCG_TEMP_CONST
422 && temps
[ah
].state
== TCG_TEMP_CONST
) {
424 a
= ((uint64_t)temps
[ah
].val
<< 32) | (uint32_t)temps
[al
].val
;
425 return do_constant_folding_cond_64(a
, b
, c
);
438 if (temps_are_copies(al
, bl
) && temps_are_copies(ah
, bh
)) {
439 return do_constant_folding_cond_eq(c
);
444 static bool swap_commutative(TCGArg dest
, TCGArg
*p1
, TCGArg
*p2
)
446 TCGArg a1
= *p1
, a2
= *p2
;
448 sum
+= temps
[a1
].state
== TCG_TEMP_CONST
;
449 sum
-= temps
[a2
].state
== TCG_TEMP_CONST
;
451 /* Prefer the constant in second argument, and then the form
452 op a, a, b, which is better handled on non-RISC hosts. */
453 if (sum
> 0 || (sum
== 0 && dest
== a2
)) {
461 static bool swap_commutative2(TCGArg
*p1
, TCGArg
*p2
)
464 sum
+= temps
[p1
[0]].state
== TCG_TEMP_CONST
;
465 sum
+= temps
[p1
[1]].state
== TCG_TEMP_CONST
;
466 sum
-= temps
[p2
[0]].state
== TCG_TEMP_CONST
;
467 sum
-= temps
[p2
[1]].state
== TCG_TEMP_CONST
;
470 t
= p1
[0], p1
[0] = p2
[0], p2
[0] = t
;
471 t
= p1
[1], p1
[1] = p2
[1], p2
[1] = t
;
477 /* Propagate constants and copies, fold constant expressions. */
478 static TCGArg
*tcg_constant_folding(TCGContext
*s
, uint16_t *tcg_opc_ptr
,
479 TCGArg
*args
, TCGOpDef
*tcg_op_defs
)
481 int i
, nb_ops
, op_index
, nb_temps
, nb_globals
, nb_call_args
;
487 /* Array VALS has an element for each temp.
488 If this temp holds a constant then its value is kept in VALS' element.
489 If this temp is a copy of other ones then the other copies are
490 available through the doubly linked circular list. */
492 nb_temps
= s
->nb_temps
;
493 nb_globals
= s
->nb_globals
;
494 reset_all_temps(nb_temps
);
496 nb_ops
= tcg_opc_ptr
- s
->gen_opc_buf
;
498 for (op_index
= 0; op_index
< nb_ops
; op_index
++) {
499 op
= s
->gen_opc_buf
[op_index
];
500 def
= &tcg_op_defs
[op
];
501 /* Do copy propagation */
502 if (op
== INDEX_op_call
) {
503 int nb_oargs
= args
[0] >> 16;
504 int nb_iargs
= args
[0] & 0xffff;
505 for (i
= nb_oargs
+ 1; i
< nb_oargs
+ nb_iargs
+ 1; i
++) {
506 if (temps
[args
[i
]].state
== TCG_TEMP_COPY
) {
507 args
[i
] = find_better_copy(s
, args
[i
]);
511 for (i
= def
->nb_oargs
; i
< def
->nb_oargs
+ def
->nb_iargs
; i
++) {
512 if (temps
[args
[i
]].state
== TCG_TEMP_COPY
) {
513 args
[i
] = find_better_copy(s
, args
[i
]);
518 /* For commutative operations make constant second argument */
528 swap_commutative(args
[0], &args
[1], &args
[2]);
530 CASE_OP_32_64(brcond
):
531 if (swap_commutative(-1, &args
[0], &args
[1])) {
532 args
[2] = tcg_swap_cond(args
[2]);
535 CASE_OP_32_64(setcond
):
536 if (swap_commutative(args
[0], &args
[1], &args
[2])) {
537 args
[3] = tcg_swap_cond(args
[3]);
540 CASE_OP_32_64(movcond
):
541 if (swap_commutative(-1, &args
[1], &args
[2])) {
542 args
[5] = tcg_swap_cond(args
[5]);
544 /* For movcond, we canonicalize the "false" input reg to match
545 the destination reg so that the tcg backend can implement
546 a "move if true" operation. */
547 if (swap_commutative(args
[0], &args
[4], &args
[3])) {
548 args
[5] = tcg_invert_cond(args
[5]);
551 case INDEX_op_add2_i32
:
552 swap_commutative(args
[0], &args
[2], &args
[4]);
553 swap_commutative(args
[1], &args
[3], &args
[5]);
555 case INDEX_op_mulu2_i32
:
556 swap_commutative(args
[0], &args
[2], &args
[3]);
558 case INDEX_op_brcond2_i32
:
559 if (swap_commutative2(&args
[0], &args
[2])) {
560 args
[4] = tcg_swap_cond(args
[4]);
563 case INDEX_op_setcond2_i32
:
564 if (swap_commutative2(&args
[1], &args
[3])) {
565 args
[5] = tcg_swap_cond(args
[5]);
572 /* Simplify expressions for "shift/rot r, 0, a => movi r, 0" */
579 if (temps
[args
[1]].state
== TCG_TEMP_CONST
580 && temps
[args
[1]].val
== 0) {
581 s
->gen_opc_buf
[op_index
] = op_to_movi(op
);
582 tcg_opt_gen_movi(gen_args
, args
[0], 0);
592 /* Simplify expression for "op r, a, 0 => mov r, a" cases */
603 if (temps
[args
[1]].state
== TCG_TEMP_CONST
) {
604 /* Proceed with possible constant folding. */
607 if (temps
[args
[2]].state
== TCG_TEMP_CONST
608 && temps
[args
[2]].val
== 0) {
609 if (temps_are_copies(args
[0], args
[1])) {
610 s
->gen_opc_buf
[op_index
] = INDEX_op_nop
;
612 s
->gen_opc_buf
[op_index
] = op_to_mov(op
);
613 tcg_opt_gen_mov(s
, gen_args
, args
[0], args
[1]);
624 /* Simplify expression for "op r, a, 0 => movi r, 0" cases */
628 if ((temps
[args
[2]].state
== TCG_TEMP_CONST
629 && temps
[args
[2]].val
== 0)) {
630 s
->gen_opc_buf
[op_index
] = op_to_movi(op
);
631 tcg_opt_gen_movi(gen_args
, args
[0], 0);
641 /* Simplify expression for "op r, a, a => mov r, a" cases */
645 if (temps_are_copies(args
[1], args
[2])) {
646 if (temps_are_copies(args
[0], args
[1])) {
647 s
->gen_opc_buf
[op_index
] = INDEX_op_nop
;
649 s
->gen_opc_buf
[op_index
] = op_to_mov(op
);
650 tcg_opt_gen_mov(s
, gen_args
, args
[0], args
[1]);
661 /* Simplify expression for "op r, a, a => movi r, 0" cases */
665 if (temps_are_copies(args
[1], args
[2])) {
666 s
->gen_opc_buf
[op_index
] = op_to_movi(op
);
667 tcg_opt_gen_movi(gen_args
, args
[0], 0);
677 /* Propagate constants through copy operations and do constant
678 folding. Constants will be substituted to arguments by register
679 allocator where needed and possible. Also detect copies. */
682 if (temps_are_copies(args
[0], args
[1])) {
684 s
->gen_opc_buf
[op_index
] = INDEX_op_nop
;
687 if (temps
[args
[1]].state
!= TCG_TEMP_CONST
) {
688 tcg_opt_gen_mov(s
, gen_args
, args
[0], args
[1]);
693 /* Source argument is constant. Rewrite the operation and
694 let movi case handle it. */
696 s
->gen_opc_buf
[op_index
] = op
;
697 args
[1] = temps
[args
[1]].val
;
700 tcg_opt_gen_movi(gen_args
, args
[0], args
[1]);
707 CASE_OP_32_64(ext8s
):
708 CASE_OP_32_64(ext8u
):
709 CASE_OP_32_64(ext16s
):
710 CASE_OP_32_64(ext16u
):
711 case INDEX_op_ext32s_i64
:
712 case INDEX_op_ext32u_i64
:
713 if (temps
[args
[1]].state
== TCG_TEMP_CONST
) {
714 s
->gen_opc_buf
[op_index
] = op_to_movi(op
);
715 tmp
= do_constant_folding(op
, temps
[args
[1]].val
, 0);
716 tcg_opt_gen_movi(gen_args
, args
[0], tmp
);
739 if (temps
[args
[1]].state
== TCG_TEMP_CONST
740 && temps
[args
[2]].state
== TCG_TEMP_CONST
) {
741 s
->gen_opc_buf
[op_index
] = op_to_movi(op
);
742 tmp
= do_constant_folding(op
, temps
[args
[1]].val
,
744 tcg_opt_gen_movi(gen_args
, args
[0], tmp
);
751 CASE_OP_32_64(deposit
):
752 if (temps
[args
[1]].state
== TCG_TEMP_CONST
753 && temps
[args
[2]].state
== TCG_TEMP_CONST
) {
754 s
->gen_opc_buf
[op_index
] = op_to_movi(op
);
755 tmp
= ((1ull << args
[4]) - 1);
756 tmp
= (temps
[args
[1]].val
& ~(tmp
<< args
[3]))
757 | ((temps
[args
[2]].val
& tmp
) << args
[3]);
758 tcg_opt_gen_movi(gen_args
, args
[0], tmp
);
765 CASE_OP_32_64(setcond
):
766 tmp
= do_constant_folding_cond(op
, args
[1], args
[2], args
[3]);
768 s
->gen_opc_buf
[op_index
] = op_to_movi(op
);
769 tcg_opt_gen_movi(gen_args
, args
[0], tmp
);
776 CASE_OP_32_64(brcond
):
777 tmp
= do_constant_folding_cond(op
, args
[0], args
[1], args
[2]);
780 reset_all_temps(nb_temps
);
781 s
->gen_opc_buf
[op_index
] = INDEX_op_br
;
782 gen_args
[0] = args
[3];
785 s
->gen_opc_buf
[op_index
] = INDEX_op_nop
;
792 CASE_OP_32_64(movcond
):
793 tmp
= do_constant_folding_cond(op
, args
[1], args
[2], args
[5]);
795 if (temps_are_copies(args
[0], args
[4-tmp
])) {
796 s
->gen_opc_buf
[op_index
] = INDEX_op_nop
;
797 } else if (temps
[args
[4-tmp
]].state
== TCG_TEMP_CONST
) {
798 s
->gen_opc_buf
[op_index
] = op_to_movi(op
);
799 tcg_opt_gen_movi(gen_args
, args
[0], temps
[args
[4-tmp
]].val
);
802 s
->gen_opc_buf
[op_index
] = op_to_mov(op
);
803 tcg_opt_gen_mov(s
, gen_args
, args
[0], args
[4-tmp
]);
811 case INDEX_op_add2_i32
:
812 case INDEX_op_sub2_i32
:
813 if (temps
[args
[2]].state
== TCG_TEMP_CONST
814 && temps
[args
[3]].state
== TCG_TEMP_CONST
815 && temps
[args
[4]].state
== TCG_TEMP_CONST
816 && temps
[args
[5]].state
== TCG_TEMP_CONST
) {
817 uint32_t al
= temps
[args
[2]].val
;
818 uint32_t ah
= temps
[args
[3]].val
;
819 uint32_t bl
= temps
[args
[4]].val
;
820 uint32_t bh
= temps
[args
[5]].val
;
821 uint64_t a
= ((uint64_t)ah
<< 32) | al
;
822 uint64_t b
= ((uint64_t)bh
<< 32) | bl
;
825 if (op
== INDEX_op_add2_i32
) {
831 /* We emit the extra nop when we emit the add2/sub2. */
832 assert(s
->gen_opc_buf
[op_index
+ 1] == INDEX_op_nop
);
836 s
->gen_opc_buf
[op_index
] = INDEX_op_movi_i32
;
837 s
->gen_opc_buf
[++op_index
] = INDEX_op_movi_i32
;
838 tcg_opt_gen_movi(&gen_args
[0], rl
, (uint32_t)a
);
839 tcg_opt_gen_movi(&gen_args
[2], rh
, (uint32_t)(a
>> 32));
846 case INDEX_op_mulu2_i32
:
847 if (temps
[args
[2]].state
== TCG_TEMP_CONST
848 && temps
[args
[3]].state
== TCG_TEMP_CONST
) {
849 uint32_t a
= temps
[args
[2]].val
;
850 uint32_t b
= temps
[args
[3]].val
;
851 uint64_t r
= (uint64_t)a
* b
;
854 /* We emit the extra nop when we emit the mulu2. */
855 assert(s
->gen_opc_buf
[op_index
+ 1] == INDEX_op_nop
);
859 s
->gen_opc_buf
[op_index
] = INDEX_op_movi_i32
;
860 s
->gen_opc_buf
[++op_index
] = INDEX_op_movi_i32
;
861 tcg_opt_gen_movi(&gen_args
[0], rl
, (uint32_t)r
);
862 tcg_opt_gen_movi(&gen_args
[2], rh
, (uint32_t)(r
>> 32));
869 case INDEX_op_brcond2_i32
:
870 tmp
= do_constant_folding_cond2(&args
[0], &args
[2], args
[4]);
873 reset_all_temps(nb_temps
);
874 s
->gen_opc_buf
[op_index
] = INDEX_op_br
;
875 gen_args
[0] = args
[5];
878 s
->gen_opc_buf
[op_index
] = INDEX_op_nop
;
880 } else if ((args
[4] == TCG_COND_LT
|| args
[4] == TCG_COND_GE
)
881 && temps
[args
[2]].state
== TCG_TEMP_CONST
882 && temps
[args
[3]].state
== TCG_TEMP_CONST
883 && temps
[args
[2]].val
== 0
884 && temps
[args
[3]].val
== 0) {
885 /* Simplify LT/GE comparisons vs zero to a single compare
886 vs the high word of the input. */
887 reset_all_temps(nb_temps
);
888 s
->gen_opc_buf
[op_index
] = INDEX_op_brcond_i32
;
889 gen_args
[0] = args
[1];
890 gen_args
[1] = args
[3];
891 gen_args
[2] = args
[4];
892 gen_args
[3] = args
[5];
900 case INDEX_op_setcond2_i32
:
901 tmp
= do_constant_folding_cond2(&args
[1], &args
[3], args
[5]);
903 s
->gen_opc_buf
[op_index
] = INDEX_op_movi_i32
;
904 tcg_opt_gen_movi(gen_args
, args
[0], tmp
);
906 } else if ((args
[5] == TCG_COND_LT
|| args
[5] == TCG_COND_GE
)
907 && temps
[args
[3]].state
== TCG_TEMP_CONST
908 && temps
[args
[4]].state
== TCG_TEMP_CONST
909 && temps
[args
[3]].val
== 0
910 && temps
[args
[4]].val
== 0) {
911 /* Simplify LT/GE comparisons vs zero to a single compare
912 vs the high word of the input. */
913 s
->gen_opc_buf
[op_index
] = INDEX_op_setcond_i32
;
914 gen_args
[0] = args
[0];
915 gen_args
[1] = args
[2];
916 gen_args
[2] = args
[4];
917 gen_args
[3] = args
[5];
926 nb_call_args
= (args
[0] >> 16) + (args
[0] & 0xffff);
927 if (!(args
[nb_call_args
+ 1] & (TCG_CALL_NO_READ_GLOBALS
|
928 TCG_CALL_NO_WRITE_GLOBALS
))) {
929 for (i
= 0; i
< nb_globals
; i
++) {
933 for (i
= 0; i
< (args
[0] >> 16); i
++) {
934 reset_temp(args
[i
+ 1]);
936 i
= nb_call_args
+ 3;
947 /* Default case: we know nothing about operation (or were unable
948 to compute the operation result) so no propagation is done.
949 We trash everything if the operation is the end of a basic
950 block, otherwise we only trash the output args. */
951 if (def
->flags
& TCG_OPF_BB_END
) {
952 reset_all_temps(nb_temps
);
954 for (i
= 0; i
< def
->nb_oargs
; i
++) {
958 for (i
= 0; i
< def
->nb_args
; i
++) {
959 gen_args
[i
] = args
[i
];
961 args
+= def
->nb_args
;
962 gen_args
+= def
->nb_args
;
970 TCGArg
*tcg_optimize(TCGContext
*s
, uint16_t *tcg_opc_ptr
,
971 TCGArg
*args
, TCGOpDef
*tcg_op_defs
)
974 res
= tcg_constant_folding(s
, tcg_opc_ptr
, args
, tcg_op_defs
);