]> git.proxmox.com Git - qemu.git/blame - tcg/optimize.c
Add TCG optimizations stub
[qemu.git] / tcg / optimize.c
CommitLineData
8f2e8c07
KB
1/*
2 * Optimizations for Tiny Code Generator for QEMU
3 *
4 * Copyright (c) 2010 Samsung Electronics.
5 * Contributed by Kirill Batuzov <batuzovk@ispras.ru>
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
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
23 * THE SOFTWARE.
24 */
25
26#include "config.h"
27
28#include <stdlib.h>
29#include <stdio.h>
30
31#include "qemu-common.h"
32#include "tcg-op.h"
33
34#if TCG_TARGET_REG_BITS == 64
35#define CASE_OP_32_64(x) \
36 glue(glue(case INDEX_op_, x), _i32): \
37 glue(glue(case INDEX_op_, x), _i64)
38#else
39#define CASE_OP_32_64(x) \
40 glue(glue(case INDEX_op_, x), _i32)
41#endif
42
43static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
44 TCGArg *args, TCGOpDef *tcg_op_defs)
45{
46 int i, nb_ops, op_index, op, nb_temps, nb_globals;
47 const TCGOpDef *def;
48 TCGArg *gen_args;
49
50 nb_temps = s->nb_temps;
51 nb_globals = s->nb_globals;
52
53 nb_ops = tcg_opc_ptr - gen_opc_buf;
54 gen_args = args;
55 for (op_index = 0; op_index < nb_ops; op_index++) {
56 op = gen_opc_buf[op_index];
57 def = &tcg_op_defs[op];
58 switch (op) {
59 case INDEX_op_call:
60 i = (args[0] >> 16) + (args[0] & 0xffff) + 3;
61 while (i) {
62 *gen_args = *args;
63 args++;
64 gen_args++;
65 i--;
66 }
67 break;
68 case INDEX_op_set_label:
69 case INDEX_op_jmp:
70 case INDEX_op_br:
71 CASE_OP_32_64(brcond):
72 for (i = 0; i < def->nb_args; i++) {
73 *gen_args = *args;
74 args++;
75 gen_args++;
76 }
77 break;
78 default:
79 for (i = 0; i < def->nb_args; i++) {
80 gen_args[i] = args[i];
81 }
82 args += def->nb_args;
83 gen_args += def->nb_args;
84 break;
85 }
86 }
87
88 return gen_args;
89}
90
91TCGArg *tcg_optimize(TCGContext *s, uint16_t *tcg_opc_ptr,
92 TCGArg *args, TCGOpDef *tcg_op_defs)
93{
94 TCGArg *res;
95 res = tcg_constant_folding(s, tcg_opc_ptr, args, tcg_op_defs);
96 return res;
97}