Commit b9c18f56585ab146c6a25084bce00e4c52eefcc6

Authored by aurel32
1 parent 34d5a9ff

tcg: add a CONST flag to TCG helpers

A const function only reads its arguments and does not use TCG
globals variables. Hence a call to such a function does not
save TCG globals variabes back to their canonical location.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7008 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 12 additions and 4 deletions
tcg/tcg.c
... ... @@ -1122,9 +1122,11 @@ static void tcg_liveness_analysis(TCGContext *s)
1122 1122 dead_temps[arg] = 1;
1123 1123 }
1124 1124  
1125   - /* globals are live (they may be used by the call) */
1126   - memset(dead_temps, 0, s->nb_globals);
1127   -
  1125 + if (!(call_flags & TCG_CALL_CONST)) {
  1126 + /* globals are live (they may be used by the call) */
  1127 + memset(dead_temps, 0, s->nb_globals);
  1128 + }
  1129 +
1128 1130 /* input args are live */
1129 1131 dead_iargs = 0;
1130 1132 for(i = 0; i < nb_iargs; i++) {
... ... @@ -1821,7 +1823,9 @@ static int tcg_reg_alloc_call(TCGContext *s, const TCGOpDef *def,
1821 1823  
1822 1824 /* store globals and free associated registers (we assume the call
1823 1825 can modify any global. */
1824   - save_globals(s, allocated_regs);
  1826 + if (!(flags & TCG_CALL_CONST)) {
  1827 + save_globals(s, allocated_regs);
  1828 + }
1825 1829  
1826 1830 tcg_out_op(s, opc, &func_arg, &const_func_arg);
1827 1831  
... ...
tcg/tcg.h
... ... @@ -178,6 +178,10 @@ typedef int TCGv_i64;
178 178 and cannot raise exceptions. Hence a call to a pure function can be
179 179 safely suppressed if the return value is not used. */
180 180 #define TCG_CALL_PURE 0x0010
  181 +/* A const function only reads its arguments and does not use TCG
  182 + globals variables. Hence a call to such a function does not
  183 + save TCG globals variabes back to their canonical location. */
  184 +#define TCG_CALL_CONST 0x0020
181 185  
182 186 /* used to align parameters */
183 187 #define TCG_CALL_DUMMY_TCGV MAKE_TCGV_I32(-1)
... ...