tcg.c revision 178d85b8274f9ac82fb553c80760bbbb4044401c
/*
* Tiny Code Generator for QEMU
*
* Copyright (c) 2008 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/* define it to suppress various consistency checks (faster) */
#define NDEBUG
/* define it to use liveness analysis (better code) */
#define USE_LIVENESS_ANALYSIS
#ifndef VBOX
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#else /* VBOX */
# include <stdio.h>
# include "osdep.h"
#endif /* VBOX */
#ifdef _WIN32
#include <malloc.h>
#endif
#include "config.h"
#include "qemu-common.h"
/* Note: the long term plan is to reduce the dependancies on the QEMU
instructions */
#define NO_CPU_IO_DEFS
#include "cpu.h"
#include "exec-all.h"
#include "tcg-op.h"
#include "elf.h"
#ifdef VBOX
/*
* Liveness analysis doesn't work well with 32-bit hosts and 64-bit targets,
* second element of the register pair to store 64-bit value is considered
* dead, it seems.
* @todo: fix it in compiler
*/
# endif
#endif /* VBOX */
TCGOpDef tcg_op_defs[] = {
#ifndef VBOX
#define DEF2(s, iargs, oargs, cargs, flags) { #s, iargs, oargs, cargs, iargs + oargs + cargs, flags, 0 },
#else /* VBOX */
# define DEF2(s, iargs, oargs, cargs, flags) { #s, iargs, oargs, cargs, iargs + oargs + cargs, flags, 0, 0, 0 },
#endif /* VBOX */
#include "tcg-opc.h"
};
/* XXX: move that inside the context */
{
*s->code_ptr++ = v;
}
{
s->code_ptr += 2;
}
{
s->code_ptr += 4;
}
/* label relocation processing */
int label_index, long addend)
{
TCGLabel *l;
TCGRelocation *r;
l = &s->labels[label_index];
if (l->has_value) {
/* FIXME: This may break relocations on RISC targets that
modify instruction fields in place. The caller may not have
written the initial value. */
} else {
/* add a new relocation entry */
r = tcg_malloc(sizeof(TCGRelocation));
r->next = l->u.first_reloc;
l->u.first_reloc = r;
}
}
{
TCGLabel *l;
TCGRelocation *r;
l = &s->labels[label_index];
if (l->has_value)
tcg_abort();
r = l->u.first_reloc;
while (r != NULL) {
r = r->next;
}
l->has_value = 1;
}
int gen_new_label(void)
{
TCGContext *s = &tcg_ctx;
int idx;
TCGLabel *l;
if (s->nb_labels >= TCG_MAX_LABELS)
tcg_abort();
l->has_value = 0;
l->u.first_reloc = NULL;
return idx;
}
#include "tcg-target.c"
/* pool based memory allocation */
{
TCGPool *p;
int pool_size;
if (size > TCG_POOL_CHUNK_SIZE) {
/* big malloc: insert a new pool (XXX: could optimize) */
if (s->pool_current)
s->pool_current->next = p;
else
s->pool_first = p;
p->next = s->pool_current;
} else {
p = s->pool_current;
if (!p) {
p = s->pool_first;
if (!p)
goto new_pool;
} else {
if (!p->next) {
if (s->pool_current)
s->pool_current->next = p;
else
s->pool_first = p;
} else {
p = p->next;
}
}
}
s->pool_current = p;
return p->data;
}
void tcg_pool_reset(TCGContext *s)
{
s->pool_current = NULL;
}
void tcg_context_init(TCGContext *s)
{
int op, total_args, n;
int *sorted_args;
memset(s, 0, sizeof(*s));
s->temps = s->static_temps;
s->nb_globals = 0;
/* Count total number of arguments and allocate the corresponding
space */
total_args = 0;
total_args += n;
}
sorted_args += n;
args_ct += n;
}
tcg_target_init(s);
/* init global prologue and epilogue */
s->code_buf = code_gen_prologue;
flush_icache_range((unsigned long)s->code_buf,
(unsigned long)s->code_ptr);
}
{
s->frame_start = start;
}
void tcg_func_start(TCGContext *s)
{
int i;
tcg_pool_reset(s);
s->nb_temps = s->nb_globals;
for(i = 0; i < (TCG_TYPE_COUNT * 2); i++)
s->first_free_temp[i] = -1;
s->nb_labels = 0;
s->current_frame_offset = s->frame_start;
}
static inline void tcg_temp_alloc(TCGContext *s, int n)
{
if (n > TCG_MAX_TEMPS)
tcg_abort();
}
{
TCGContext *s = &tcg_ctx;
int idx;
#if TCG_TARGET_REG_BITS == 32
if (type != TCG_TYPE_I32)
tcg_abort();
#endif
tcg_abort();
idx = s->nb_globals;
s->nb_globals++;
}
#if TCG_TARGET_REG_BITS == 32
/* temporary hack to avoid register shortage for tcg_qemu_st64() */
const char *name)
{
TCGContext *s = &tcg_ctx;
int idx;
char buf[64];
if (type != TCG_TYPE_I64)
tcg_abort();
idx = s->nb_globals;
ts++;
s->nb_globals += 2;
}
#endif
const char *name)
{
TCGContext *s = &tcg_ctx;
int idx;
idx = s->nb_globals;
#if TCG_TARGET_REG_BITS == 32
if (type == TCG_TYPE_I64) {
char buf[64];
#ifdef TCG_TARGET_WORDS_BIGENDIAN
#else
#endif
ts++;
#ifdef TCG_TARGET_WORDS_BIGENDIAN
#else
#endif
s->nb_globals += 2;
} else
#endif
{
s->nb_globals++;
}
}
{
TCGContext *s = &tcg_ctx;
int idx, k;
k = type;
if (temp_local)
k += TCG_TYPE_COUNT;
idx = s->first_free_temp[k];
if (idx != -1) {
/* There is already an available temp with the
right type */
} else {
#if TCG_TARGET_REG_BITS == 32
if (type == TCG_TYPE_I64) {
ts++;
s->nb_temps += 2;
} else
#endif
{
s->nb_temps++;
}
}
}
{
TCGContext *s = &tcg_ctx;
int k;
ts->temp_allocated = 0;
if (ts->temp_local)
k += TCG_TYPE_COUNT;
s->first_free_temp[k] = idx;
}
{
return t0;
}
{
return t0;
}
{
TCGContext *s = &tcg_ctx;
int n;
n = s->allocated_helpers;
if (n == 0) {
n = 4;
} else {
n *= 2;
}
#ifdef VBOX
#else
#endif
s->allocated_helpers = n;
}
s->nb_helpers++;
}
{
}
unsigned int flags,
{
#ifndef VBOX
int i;
#else
unsigned int i;
#endif
*gen_opc_ptr++ = INDEX_op_call;
for(i = 0; i < nb_rets; i++) {
}
for(i = 0; i < nb_params; i++) {
}
*gen_opparam_ptr++ = flags;
/* total parameters, needed to go backward in the instruction stream */
}
#if TCG_TARGET_REG_BITS < 64
/* Note: we convert the 64 bit args to 32 bit and do some alignment
and endian swap. Maybe it would be better to do the alignment
and endian swap in tcg_reg_alloc_call(). */
{
int j, i, call_type;
if (nb_rets == 1) {
nb_rets = 2;
#ifdef TCG_TARGET_WORDS_BIGENDIAN
#else
#endif
}
}
j = 0;
for(i = 0; i < nb_params; i++) {
#ifdef TCG_TARGET_I386
/* REGPARM case: if the third parameter is 64 bit, it is
allocated on the stack */
}
#else
#ifdef TCG_TARGET_CALL_ALIGN_ARGS
/* some targets want aligned 64 bit args */
if (j & 1) {
args2[j++] = TCG_CALL_DUMMY_ARG;
}
#endif
#ifdef TCG_TARGET_WORDS_BIGENDIAN
#else
#endif
#endif
} else {
}
}
}
#else
{
}
#endif
#if TCG_TARGET_REG_BITS == 32
{
if (c == 0) {
} else if (c >= 32) {
c -= 32;
if (right) {
if (arith) {
} else {
}
} else {
tcg_gen_movi_i32(ret, 0);
}
} else {
if (right) {
if (arith)
else
} else {
/* Note: ret can be the same as arg1, so we use t1 */
}
}
}
#endif
static void tcg_reg_alloc_start(TCGContext *s)
{
int i;
for(i = 0; i < s->nb_globals; i++) {
} else {
}
}
for(i = s->nb_globals; i < s->nb_temps; i++) {
ts->mem_allocated = 0;
}
for(i = 0; i < TCG_TARGET_NB_REGS; i++) {
s->reg_to_temp[i] = -1;
}
}
int idx)
{
if (idx < s->nb_globals) {
} else {
if (ts->temp_local)
else
}
return buf;
}
{
}
{
return -1;
return 0;
else
return 1;
}
/* find helper definition (Note: A hash table would be better) */
{
if (unlikely(!s->helpers_sorted)) {
#ifdef VBOX
#else
#endif
s->helpers_sorted = 1;
}
/* binary search */
m_min = 0;
if (v == val)
return th;
else if (val < v) {
m_max = m - 1;
} else {
m_min = m + 1;
}
}
return NULL;
}
static const char * const cond_name[] =
{
[TCG_COND_EQ] = "eq",
[TCG_COND_NE] = "ne",
[TCG_COND_LT] = "lt",
[TCG_COND_GE] = "ge",
[TCG_COND_LE] = "le",
[TCG_COND_GT] = "gt",
[TCG_COND_LTU] = "ltu",
[TCG_COND_GEU] = "geu",
[TCG_COND_LEU] = "leu",
[TCG_COND_GTU] = "gtu"
};
{
char buf[128];
first_insn = 1;
while (opc_ptr < gen_opc_ptr) {
c = *opc_ptr++;
def = &tcg_op_defs[c];
if (c == INDEX_op_debug_insn_start) {
#else
#endif
if (!first_insn)
first_insn = 0;
} else if (c == INDEX_op_call) {
/* variable number of arguments */
/* function name */
/* flags */
/* nb out args */
for(i = 0; i < nb_oargs; i++) {
}
for(i = 0; i < (nb_iargs - 1); i++) {
} else {
}
}
} else if (c == INDEX_op_movi_i32
#if TCG_TARGET_REG_BITS == 64
|| c == INDEX_op_movi_i64
#endif
) {
if (th) {
} else {
if (c == INDEX_op_movi_i32)
else
}
} else {
if (c == INDEX_op_nopn) {
/* variable number of arguments */
nb_oargs = 0;
nb_iargs = 0;
} else {
}
k = 0;
for(i = 0; i < nb_oargs; i++) {
if (k != 0)
}
for(i = 0; i < nb_iargs; i++) {
if (k != 0)
}
if (c == INDEX_op_brcond_i32
#if TCG_TARGET_REG_BITS == 32
|| c == INDEX_op_brcond2_i32
|| c == INDEX_op_brcond_i64
#endif
) {
else
i = 1;
}
else
i = 0;
for(; i < nb_cargs; i++) {
if (k != 0)
}
}
}
}
/* we give more priority to constraints with less registers */
{
const TCGArgConstraint *arg_ct;
int i, n;
/* an alias is equivalent to a single register */
n = 1;
} else {
return 0;
n = 0;
for(i = 0; i < TCG_TARGET_NB_REGS; i++) {
n++;
}
}
return TCG_TARGET_NB_REGS - n + 1;
}
/* sort from highest priority to lowest */
{
for(i = 0; i < n; i++)
if (n <= 1)
return;
for(i = 0; i < n - 1; i++) {
for(j = i + 1; j < n; j++) {
}
}
}
}
{
int op;
const char *ct_str;
int i, nb_args;
for(;;) {
break;
for(i = 0; i < nb_args; i++) {
int oarg;
/* TCG_CT_ALIAS is for the output arguments. The input
argument is tagged with TCG_CT_IALIAS. */
} else {
for(;;) {
if (*ct_str == '\0')
break;
switch(*ct_str) {
case 'i':
ct_str++;
break;
default:
#ifdef VBOX
tcg_exit(1);
#else
exit(1);
#endif
}
}
}
}
}
/* sort the constraints (XXX: this is just an heuristic) */
#if 0
{
int i;
printf("\n");
}
#endif
tdefs++;
}
}
#ifdef USE_LIVENESS_ANALYSIS
/* set a nop for an operation using 'nb_args' */
{
if (nb_args == 0) {
*opc_ptr = INDEX_op_nop;
} else {
*opc_ptr = INDEX_op_nopn;
}
}
/* liveness analysis: end of function: globals are live, temps are
dead. */
/* XXX: at this stage, not used as there would be little gains because
most TBs end with a conditional jump. */
{
}
/* liveness analysis: end of basic block: globals are live, temps are
dead, local temps are live. */
{
int i;
for(i = s->nb_globals; i < s->nb_temps; i++) {
if (ts->temp_local)
dead_temps[i] = 0;
else
dead_temps[i] = 1;
ts++;
}
}
/* Liveness analysis : update the opc_dead_iargs array to tell if a
given input arguments is dead. Instructions updating dead
temporaries are removed. */
static void tcg_liveness_analysis(TCGContext *s)
{
unsigned int dead_iargs;
gen_opc_ptr++; /* skip end */
/* XXX: make it really dynamic */
while (op_index >= 0) {
switch(op) {
case INDEX_op_call:
{
int call_flags;
args++;
/* pure functions can be removed if their result is not
used */
if (call_flags & TCG_CALL_PURE) {
for(i = 0; i < nb_oargs; i++) {
if (!dead_temps[arg])
goto do_not_remove_call;
}
} else {
/* output args are dead */
for(i = 0; i < nb_oargs; i++) {
}
/* globals are live (they may be used by the call) */
/* input args are live */
dead_iargs = 0;
for(i = 0; i < nb_iargs; i++) {
if (arg != TCG_CALL_DUMMY_ARG) {
if (dead_temps[arg]) {
dead_iargs |= (1 << i);
}
dead_temps[arg] = 0;
}
}
}
args--;
}
break;
case INDEX_op_set_label:
args--;
/* mark end of basic block */
tcg_la_bb_end(s, dead_temps);
break;
break;
case INDEX_op_nopn:
break;
case INDEX_op_discard:
args--;
/* mark the temporary as dead */
break;
case INDEX_op_end:
break;
/* XXX: optimize by hardcoding common cases (e.g. triadic ops) */
default:
if (op > INDEX_op_end) {
/* Test if the operation can be removed because all
its outputs are dead. We assume that nb_oargs == 0
implies side effects */
for(i = 0; i < nb_oargs; i++) {
if (!dead_temps[arg])
goto do_not_remove;
}
#ifdef CONFIG_PROFILER
s->del_op_count++;
#endif
} else {
/* output args are dead */
for(i = 0; i < nb_oargs; i++) {
}
/* if end of basic block, update */
tcg_la_bb_end(s, dead_temps);
/* globals are live */
}
/* input args are live */
dead_iargs = 0;
for(i = 0; i < nb_iargs; i++) {
if (dead_temps[arg]) {
dead_iargs |= (1 << i);
}
dead_temps[arg] = 0;
}
}
} else {
/* legacy dyngen operations */
/* mark end of basic block */
tcg_la_bb_end(s, dead_temps);
}
break;
}
op_index--;
}
if (args != gen_opparam_buf)
tcg_abort();
}
#else
/* dummy liveness analysis */
void tcg_liveness_analysis(TCGContext *s)
{
int nb_ops;
}
#endif
#ifndef NDEBUG
static void dump_regs(TCGContext *s)
{
int i;
char buf[64];
for(i = 0; i < s->nb_temps; i++) {
case TEMP_VAL_REG:
break;
case TEMP_VAL_MEM:
break;
case TEMP_VAL_CONST:
break;
case TEMP_VAL_DEAD:
printf("D");
break;
default:
printf("???");
break;
}
printf("\n");
}
for(i = 0; i < TCG_TARGET_NB_REGS; i++) {
if (s->reg_to_temp[i] >= 0) {
printf("%s: %s\n",
}
}
}
static void check_regs(TCGContext *s)
{
int reg, k;
char buf[64];
k = s->reg_to_temp[reg];
if (k >= 0) {
printf("Inconsistency for register %s:\n",
goto fail;
}
}
}
for(k = 0; k < s->nb_temps; k++) {
printf("Inconsistency for temp %s:\n",
fail:
printf("reg state:\n");
dump_regs(s);
tcg_abort();
}
}
}
#endif
{
s->current_frame_offset = (s->current_frame_offset + sizeof(tcg_target_long) - 1) & ~(sizeof(tcg_target_long) - 1);
#ifndef VBOX
#else
#endif
tcg_abort();
s->current_frame_offset += sizeof(tcg_target_long);
}
/* free register 'reg' by spilling the corresponding temporary if necessary */
{
int temp;
if (temp != -1) {
if (!ts->mem_coherent) {
if (!ts->mem_allocated)
temp_allocate_frame(s, temp);
}
}
}
/* Allocate a register belonging to reg1 & ~reg2 */
{
int i, reg;
/* first try free registers */
for(i = 0; i < ARRAY_SIZE(tcg_target_reg_alloc_order); i++) {
return reg;
}
/* XXX: do better spill choice */
for(i = 0; i < ARRAY_SIZE(tcg_target_reg_alloc_order); i++) {
tcg_reg_free(s, reg);
return reg;
}
}
tcg_abort();
}
/* save a temporary to memory. 'allocated_regs' is used in case a
temporary registers needs to be allocated to store a constant. */
{
int reg;
case TEMP_VAL_REG:
break;
case TEMP_VAL_DEAD:
break;
case TEMP_VAL_CONST:
if (!ts->mem_allocated)
temp_allocate_frame(s, temp);
break;
case TEMP_VAL_MEM:
break;
default:
tcg_abort();
}
}
}
/* save globals to their cannonical location and assume they can be
modified be the following code. 'allocated_regs' is used in case a
temporary registers needs to be allocated to store a constant. */
{
int i;
for(i = 0; i < s->nb_globals; i++) {
temp_save(s, i, allocated_regs);
}
}
/* at the end of a basic block, we assume all temporaries are dead and
all globals are stored at their canonical location. */
{
int i;
for(i = s->nb_globals; i < s->nb_temps; i++) {
if (ts->temp_local) {
temp_save(s, i, allocated_regs);
} else {
}
}
}
}
{
/* for fixed registers, we do not do any constant
propagation */
} else {
/* The movi is not explicitly generated here */
}
}
unsigned int dead_iargs)
{
int reg;
const TCGArgConstraint *arg_ct;
/* XXX: always mark arg dead if IS_DEAD_IARG(0) */
/* the mov can be suppressed */
} else {
} else {
}
}
}
} else {
}
} else {
/* propagate constant */
return;
}
} else {
tcg_abort();
}
ots->mem_coherent = 0;
}
static void tcg_reg_alloc_op(TCGContext *s,
unsigned int dead_iargs)
{
const TCGArgConstraint *arg_ct;
int const_args[TCG_MAX_OP_ARGS];
/* copy constants */
/* satisfy input constraints */
for(k = 0; k < nb_iargs; k++) {
/* constant is OK for instruction */
const_args[i] = 1;
goto iarg_end;
} else {
/* need to move to a register */
ts->mem_coherent = 0;
}
}
/* if fixed register, we must allocate a new register
if the alias is not the same register */
goto allocate_in_reg;
} else {
/* if the input is aliased to an output and if it is
not dead after the instruction, we must allocate
a new register and move it */
if (!IS_DEAD_IARG(i - nb_oargs))
goto allocate_in_reg;
}
}
/* nothing to do : the constraint is satisfied */
} else {
/* allocate a new register matching the constraint
and move the temporary register into it */
}
const_args[i] = 0;
iarg_end: ;
}
} else {
/* mark dead temporaries and free the associated registers */
for(i = 0; i < nb_iargs; i++) {
if (IS_DEAD_IARG(i)) {
}
}
}
/* XXX: permit generic clobber register list ? */
tcg_reg_free(s, reg);
}
}
(i.e. when a memory callback is called) */
/* store globals and free associated registers (we assume the insn
can modify any global. */
}
/* satisfy the output constraints */
for(k = 0; k < nb_oargs; k++) {
i = def->sorted_args[k];
} else {
/* if fixed register, we try to use it */
goto oarg_end;
}
}
/* if a fixed register is used, then a move will be done afterwards */
/* temp value is modified, so the value kept in memory is
potentially not the same */
ts->mem_coherent = 0;
}
}
}
/* emit instruction */
/* move the outputs in the correct register if needed */
for(i = 0; i < nb_oargs; i++) {
}
}
}
#ifdef TCG_TARGET_STACK_GROWSUP
#define STACK_DIR(x) (-(x))
#else
#define STACK_DIR(x) (x)
#endif
unsigned int dead_iargs)
{
int const_func_arg, allocate_args;
const TCGArgConstraint *arg_ct;
/* assign stack slots first */
/* XXX: preallocate call stack */
~(TCG_TARGET_STACK_ALIGN - 1);
if (allocate_args) {
}
#ifdef TCG_TARGET_STACK_GROWSUP
stack_offset -= sizeof(tcg_target_long);
#endif
if (arg != TCG_CALL_DUMMY_ARG) {
s->reserved_regs);
/* XXX: not correct if reading values from the stack */
s->reserved_regs);
/* XXX: sign extend may be needed on some targets */
} else {
tcg_abort();
}
}
#ifndef TCG_TARGET_STACK_GROWSUP
stack_offset += sizeof(tcg_target_long);
#endif
}
/* assign input registers */
for(i = 0; i < nb_regs; i++) {
if (arg != TCG_CALL_DUMMY_ARG) {
reg = tcg_target_call_iarg_regs[i];
tcg_reg_free(s, reg);
}
/* XXX: sign extend ? */
} else {
tcg_abort();
}
}
}
/* assign function address */
const_func_arg = 0;
}
const_func_arg = 1;
} else {
}
} else {
tcg_abort();
}
/* mark dead temporaries and free the associated registers */
for(i = 0; i < nb_iargs; i++) {
if (IS_DEAD_IARG(i)) {
}
}
}
/* clobber call registers */
tcg_reg_free(s, reg);
}
}
/* store globals and free associated registers (we assume the call
can modify any global. */
if (allocate_args) {
}
/* assign output registers and emit moves if needed */
for(i = 0; i < nb_oargs; i++) {
reg = tcg_target_call_oarg_regs[i];
}
} else {
ts->mem_coherent = 0;
}
}
}
#ifdef CONFIG_PROFILER
void dump_op_count(void)
{
int i;
FILE *f;
for(i = 0; i < INDEX_op_end; i++) {
}
fclose(f);
for(i = INDEX_op_end; i < NB_OPS; i++) {
}
fclose(f);
}
#endif
long search_pc)
{
unsigned int dead_iargs;
#ifdef DEBUG_DISAS
tcg_dump_ops(s, logfile);
}
#endif
#ifdef CONFIG_PROFILER
s->la_time -= profile_getclock();
#endif
#ifdef CONFIG_PROFILER
s->la_time += profile_getclock();
#endif
#ifdef DEBUG_DISAS
tcg_dump_ops(s, logfile);
}
#endif
s->code_buf = gen_code_buf;
s->code_ptr = gen_code_buf;
op_index = 0;
for(;;) {
#ifdef CONFIG_PROFILER
#endif
#if 0
// dump_regs(s);
#endif
switch(opc) {
case INDEX_op_mov_i32:
#if TCG_TARGET_REG_BITS == 64
case INDEX_op_mov_i64:
#endif
break;
case INDEX_op_movi_i32:
#if TCG_TARGET_REG_BITS == 64
case INDEX_op_movi_i64:
#endif
tcg_reg_alloc_movi(s, args);
break;
/* debug instruction */
break;
case INDEX_op_nop:
case INDEX_op_nop1:
case INDEX_op_nop2:
case INDEX_op_nop3:
break;
case INDEX_op_nopn:
goto next;
case INDEX_op_discard:
{
/* mark the temporary as dead */
}
}
break;
case INDEX_op_set_label:
tcg_reg_alloc_bb_end(s, s->reserved_regs);
break;
case INDEX_op_call:
goto next;
case INDEX_op_end:
goto the_end;
#ifdef CONFIG_DYNGEN_OP
case 0 ... INDEX_op_end - 1:
/* legacy dyngen ops */
#ifdef CONFIG_PROFILER
s->old_op_count++;
#endif
tcg_reg_alloc_bb_end(s, s->reserved_regs);
if (search_pc >= 0) {
} else {
}
goto next;
#endif
default:
/* Note: in order to speed up the code, it would be much
faster to have specialized register allocator functions for
some common argument patterns */
break;
}
next:
return op_index;
}
op_index++;
#ifndef NDEBUG
check_regs(s);
#endif
}
return -1;
}
{
#ifdef CONFIG_PROFILER
{
int n;
n = (gen_opc_ptr - gen_opc_buf);
s->op_count += n;
if (n > s->op_count_max)
s->op_count_max = n;
s->temp_count += s->nb_temps;
if (s->nb_temps > s->temp_count_max)
s->temp_count_max = s->nb_temps;
}
#endif
/* flush instruction cache */
flush_icache_range((unsigned long)gen_code_buf,
(unsigned long)s->code_ptr);
return s->code_ptr - gen_code_buf;
}
/* Return the index of the micro operation such as the pc after is <
offset bytes from the start of the TB. The contents of gen_code_buf must
not be changed, though writing the same values is ok.
Return -1 if not found. */
{
}
#ifdef CONFIG_PROFILER
void tcg_dump_info(FILE *f,
{
TCGContext *s = &tcg_ctx;
s->tb_count,
cpu_fprintf(f, "avg ops/TB %0.1f max=%d\n",
cpu_fprintf(f, "old ops/total ops %0.1f%%\n",
cpu_fprintf(f, "deleted ops/TB %0.2f\n",
s->tb_count ?
(double)s->del_op_count / s->tb_count : 0);
cpu_fprintf(f, "avg temps/TB %0.2f max=%d\n",
s->tb_count ?
(double)s->temp_count / s->tb_count : 0,
s->temp_count_max);
cpu_fprintf(f, "cycles/op %0.1f\n",
cpu_fprintf(f, "cycles/in byte %0.1f\n",
cpu_fprintf(f, "cycles/out byte %0.1f\n",
if (tot == 0)
tot = 1;
cpu_fprintf(f, " gen_interm time %0.1f%%\n",
cpu_fprintf(f, " gen_code time %0.1f%%\n",
cpu_fprintf(f, "liveness/code time %0.1f%%\n",
s->restore_count);
cpu_fprintf(f, " avg cycles %0.1f\n",
{
extern void dump_op_count(void);
}
}
#else
void tcg_dump_info(FILE *f,
{
cpu_fprintf(f, "[TCG profiler not compiled]\n");
}
#endif