/*
* 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 use liveness analysis (better code) */
#define USE_LIVENESS_ANALYSIS
#include "config.h"
#if !defined(CONFIG_DEBUG_TCG) && !defined(NDEBUG)
/* define it to suppress various consistency checks (faster) */
#define NDEBUG
#endif
#ifndef VBOX
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#ifdef _WIN32
#include <malloc.h>
#endif
#ifdef _AIX
#include <alloca.h>
#endif
#else /* VBOX */
# include <stdio.h>
# include "osdep.h"
#endif /* VBOX */
#include "qemu-common.h"
#include "cache-utils.h"
#include "host-utils.h"
#include "qemu-timer.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"
#if defined(CONFIG_USE_GUEST_BASE) && !defined(TCG_TARGET_HAS_GUEST_BASE)
#endif
#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 re-test this */
# endif
#endif /* VBOX */
static void tcg_target_init(TCGContext *s);
static void tcg_target_qemu_prologue(TCGContext *s);
#define DEF(s, oargs, iargs, cargs, flags) { #s, oargs, iargs, cargs, iargs + oargs + cargs, flags },
#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 */
{
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;
}
{
s->pool_current = NULL;
}
{
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;
}
{
s->frame_start = start;
}
{
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;
}
{
if (n > TCG_MAX_TEMPS)
tcg_abort();
}
const char *name)
{
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++;
return idx;
}
{
int idx;
return MAKE_TCGV_I32(idx);
}
{
int idx;
return MAKE_TCGV_I64(idx);
}
const char *name)
{
TCGContext *s = &tcg_ctx;
int idx;
idx = s->nb_globals;
#if TCG_TARGET_REG_BITS == 32
if (type == TCG_TYPE_I64) {
#ifdef TCG_TARGET_WORDS_BIGENDIAN
#else
#endif
ts++;
#ifdef TCG_TARGET_WORDS_BIGENDIAN
#else
#endif
s->nb_globals += 2;
} else
#endif
{
s->nb_globals++;
}
return idx;
}
const char *name)
{
int idx;
return MAKE_TCGV_I32(idx);
}
const char *name)
{
int idx;
return MAKE_TCGV_I64(idx);
}
{
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++;
}
}
return idx;
}
{
int idx;
return MAKE_TCGV_I32(idx);
}
{
int idx;
return MAKE_TCGV_I64(idx);
}
{
TCGContext *s = &tcg_ctx;
int k;
ts->temp_allocated = 0;
if (ts->temp_local)
k += TCG_TYPE_COUNT;
s->first_free_temp[k] = idx;
}
{
}
{
}
{
t0 = tcg_temp_new_i32();
return t0;
}
{
t0 = tcg_temp_new_i64();
return t0;
}
{
t0 = tcg_temp_local_new_i32();
return t0;
}
{
t0 = tcg_temp_local_new_i64();
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++;
}
/* 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(). */
{
#ifdef TCG_TARGET_I386
int call_type;
#endif
int i;
int real_args;
int nb_rets;
for (i = 0; i < nargs; ++i) {
if (!is_64bit) {
if (is_signed) {
} else {
}
}
}
#endif /* TCG_TARGET_EXTEND_ARGS */
*gen_opc_ptr++ = INDEX_op_call;
nparam = gen_opparam_ptr++;
#ifdef TCG_TARGET_I386
#endif
if (ret != TCG_CALL_DUMMY_ARG) {
#if TCG_TARGET_REG_BITS < 64
if (sizemask & 1) {
#ifdef TCG_TARGET_WORDS_BIGENDIAN
*gen_opparam_ptr++ = ret;
#else
*gen_opparam_ptr++ = ret;
#endif
nb_rets = 2;
} else
#endif
{
*gen_opparam_ptr++ = ret;
nb_rets = 1;
}
} else {
nb_rets = 0;
}
real_args = 0;
for (i = 0; i < nargs; i++) {
#if TCG_TARGET_REG_BITS < 64
if (is_64bit) {
#ifdef TCG_TARGET_I386
/* REGPARM case: if the third parameter is 64 bit, it is
allocated on the stack */
}
#endif
#ifdef TCG_TARGET_CALL_ALIGN_ARGS
/* some targets want aligned 64 bit args */
if (real_args & 1) {
real_args++;
}
#endif
/* If stack grows up, then we will be placing successive
arguments at lower addresses, which means we need to
reverse the order compared to how we would normally
treat either big or little-endian. For those arguments
that will wind up in registers, this still works for
HPPA (the only current STACK_GROWSUP target) since the
argument registers are *also* allocated in decreasing
order. If another such target is added, this logic may
have to get more complicated to differentiate between
stack arguments and register arguments. */
#if defined(TCG_TARGET_WORDS_BIGENDIAN) != defined(TCG_TARGET_STACK_GROWSUP)
*gen_opparam_ptr++ = args[i];
#else
*gen_opparam_ptr++ = args[i];
#endif
real_args += 2;
continue;
}
#endif /* TCG_TARGET_REG_BITS < 64 */
*gen_opparam_ptr++ = args[i];
real_args++;
}
*gen_opparam_ptr++ = flags;
/* total parameters, needed to go backward in the instruction stream */
for (i = 0; i < nargs; ++i) {
if (!is_64bit) {
}
}
#endif /* TCG_TARGET_EXTEND_ARGS */
}
#if TCG_TARGET_REG_BITS == 32
{
if (c == 0) {
} else if (c >= 32) {
c -= 32;
if (right) {
if (arith) {
} else {
}
} else {
}
} else {
t0 = tcg_temp_new_i32();
t1 = tcg_temp_new_i32();
if (right) {
if (arith)
else
} else {
/* Note: ret can be the same as arg1, so we use t1 */
}
}
}
#endif
{
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"
};
{
TCGOpcode c;
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)
}
switch (c) {
case INDEX_op_brcond_i32:
#if TCG_TARGET_REG_BITS == 32
case INDEX_op_brcond2_i32:
case INDEX_op_brcond_i64:
#endif
case INDEX_op_setcond_i32:
#if TCG_TARGET_REG_BITS == 32
case INDEX_op_setcond2_i32:
case INDEX_op_setcond_i64:
#endif
else
i = 1;
break;
default:
i = 0;
break;
}
for(; i < nb_cargs; i++) {
if (k != 0)
}
}
}
}
/* we give more priority to constraints with less registers */
{
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++) {
}
}
}
}
{
const char *ct_str;
int i, nb_args;
for(;;) {
break;
#if defined(CONFIG_DEBUG_TCG)
/* Duplicate entry in op definitions? */
#endif
for(i = 0; i < nb_args; i++) {
/* Incomplete TCGTargetOpDef entry? */
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:
#ifndef VBOX
exit(1);
#else
tcg_exit(1);
#endif
}
}
}
}
}
/* TCGTargetOpDef entry with too much information? */
/* sort the constraints (XXX: this is just an heuristic) */
#if 0
{
int i;
printf("\n");
}
#endif
tdefs++;
}
#if defined(CONFIG_DEBUG_TCG)
i = 0;
/* Wrong entry in op definitions? */
i = 1;
}
} else {
/* Missing entry in op definitions? */
i = 1;
}
}
}
if (i == 1) {
tcg_abort();
}
#endif
}
#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. */
{
unsigned int dead_iargs;
gen_opc_ptr++; /* skip end */
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++) {
}
if (!(call_flags & TCG_CALL_CONST)) {
/* 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:
/* 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;
}
}
break;
}
op_index--;
}
if (args != gen_opparam_buf)
tcg_abort();
}
#else
/* dummy liveness analysis */
{
int nb_ops;
}
#endif
#ifndef NDEBUG
{
int i;
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",
}
}
}
{
int reg, k;
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;
/* 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;
}
unsigned int dead_iargs)
{
/* 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)
{
/* 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 (!(flags & TCG_CALL_CONST)) {
}
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
static void dump_op_count(void)
{
int i;
FILE *f;
for(i = INDEX_op_end; i < NB_OPS; i++) {
}
fclose(f);
}
#endif
{
int op_index;
unsigned int dead_iargs;
#ifdef DEBUG_DISAS
qemu_log("OP:\n");
tcg_dump_ops(s, logfile);
qemu_log("\n");
}
#endif
#ifdef CONFIG_PROFILER
s->la_time -= profile_getclock();
#endif
#ifdef CONFIG_PROFILER
s->la_time += profile_getclock();
#endif
#ifdef DEBUG_DISAS
# ifdef USE_LIVENESS_ANALYSIS /* vbox */
qemu_log("OP after liveness analysis:\n");
tcg_dump_ops(s, logfile);
qemu_log("\n");
}
# endif /* USE_LIVENESS_ANALYSIS - vbox */
#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;
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 */
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
{
TCGContext *s = &tcg_ctx;
s->tb_count,
cpu_fprintf(f, "avg ops/TB %0.1f max=%d\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",
}
#else
{
cpu_fprintf(f, "[TCG profiler not compiled]\n");
}
#endif