All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, cota@braap.org
Subject: [PATCH 27/27] tcg: Update docs/devel/tcg-ops.rst for temporary changes
Date: Mon, 30 Jan 2023 10:59:35 -1000	[thread overview]
Message-ID: <20230130205935.1157347-29-richard.henderson@linaro.org> (raw)
In-Reply-To: <20230130205935.1157347-1-richard.henderson@linaro.org>

Rewrite the sections which talked about 'local temporaries'.
Remove some assumptions which no longer hold.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 docs/devel/tcg-ops.rst | 103 +++++++++++++++++++++--------------------
 1 file changed, 54 insertions(+), 49 deletions(-)

diff --git a/docs/devel/tcg-ops.rst b/docs/devel/tcg-ops.rst
index 9adc0c9b6c..53b7b6c93b 100644
--- a/docs/devel/tcg-ops.rst
+++ b/docs/devel/tcg-ops.rst
@@ -29,21 +29,42 @@ In this document, we use *guest* to specify what architecture we are
 emulating; *target* always means the TCG target, the machine on which
 we are running QEMU.
 
-A TCG *function* corresponds to a QEMU Translated Block (TB).
+A TCG *basic block* is a single entry, multiple exit region which
+corresponds to a list of instructions terminated by a label, or
+any branch instruction.
 
-A TCG *temporary* is a variable only live in a basic block. Temporaries are allocated explicitly in each function.
+A TCG *extended basic block* is a single entry, multiple exit region
+which corresponds to a list of instructions terminated by a label or
+an unconditional branch.  Specifically, an extended basic block is
+a sequence of basic blocks connected by the fall-through paths of
+zero or more conditional branch instructions.
 
-A TCG *local temporary* is a variable only live in a function. Local temporaries are allocated explicitly in each function.
+There is one TCG *fixed global* (``TEMP_FIXED``) variable, ``cpu_env``
+which is live in all translation blocks, and holds a pointer to ``CPUArchState``.
+This fixed global is held in a host cpu register at all times in all
+translation blocks.
 
-A TCG *global* is a variable which is live in all the functions
-(equivalent of a C global variable). They are defined before the
-functions defined. A TCG global can be a memory location (e.g. a QEMU
-CPU register), a fixed host register (e.g. the QEMU CPU state pointer)
-or a memory location which is stored in a register outside QEMU TBs
-(not implemented yet).
+A TCG *global* (``TEMP_GLOBAL``) is a variable which is live in all
+translation blocks, and correspond to memory locations that are within
+``CPUArchState``.  These may be specified as an offset from ``cpu_env``,
+in which case they are called *direct globals*, or may be specified as
+an offset from a direct global, in which case they are called
+*indirect globals*.  Even indirect globals should still reference memory
+within ``CPUArchState``.  All TCG globals are defined during
+``TCGCPUOps.initialize``, before any translation blocks are generated.
 
-A TCG *basic block* corresponds to a list of instructions terminated
-by a branch instruction.
+A TCG *constant* (``TEMP_CONST``) is a variable which is live throughout
+the entire translation block, and contains a constant value.
+These temporaries are allocated explicitly during translation and are
+hashed so that there is exactly one variable holding a given value.
+
+A TCG *translation block temporary* (``TEMP_TB``) is a variable which is
+live throughout the entire translation block, but dies on any exit.
+These temporaries are allocated explicitly during translation.
+
+A TCG *extended basic block temporary* (``TEMP_EBB``) is a variable which
+is live throughout an extended basic block, but dies on any exit.
+These temporaries are allocated explicitly during translation.
 
 An operation with *undefined behavior* may result in a crash.
 
@@ -57,11 +78,11 @@ Intermediate representation
 Introduction
 ------------
 
-TCG instructions operate on variables which are temporaries, local
-temporaries or globals. TCG instructions and variables are strongly
-typed. Two types are supported: 32 bit integers and 64 bit
-integers. Pointers are defined as an alias to 32 bit or 64 bit
-integers depending on the TCG target word size.
+TCG instructions operate on variables which are temporaries.
+TCG instructions and variables are strongly typed.
+Two types are supported: 32 bit integers and 64 bit integers.
+Pointers are defined as an alias to 32 bit or 64 bit integers
+depending on the TCG target word size.
 
 Each instruction has a fixed number of output variable operands, input
 variable operands and always constant operands.
@@ -81,17 +102,19 @@ included in the instruction name. Constants are prefixed with a '$'.
 Assumptions
 -----------
 
-Basic blocks
+Basic Blocks
 ^^^^^^^^^^^^
 
-* Basic blocks end after branches (e.g. brcond_i32 instruction),
-  goto_tb and exit_tb instructions.
+* Basic blocks end after conditional branches (e.g. brcond_i32),
+  br, goto_tb, exit_tb, goto_ptr, set_label instructions,
+  and calls that are defined to not return (``TCG_CALL_NO_RETURN``).
 
-* Basic blocks start after the end of a previous basic block, or at a
-  set_label instruction.
+* Basic blocks start after the end of a previous basic block,
+  or at a set_label instruction.
 
-After the end of a basic block, the content of temporaries is
-destroyed, but local temporaries and globals are preserved.
+* Extended basic blocks are a sequence of basic blocks that are
+  connected by the fall through of conditional branches.  Thus they end
+  at br, goto_tb, exit_tb, goto_ptr, set_label, and noreturn calls.
 
 Floating point types
 ^^^^^^^^^^^^^^^^^^^^
@@ -120,18 +143,15 @@ Helpers
     either directly or via an exception. They will not be saved to their
     canonical locations before calling the helper.
 
-  - ``TCG_CALL_NO_WRITE_GLOBALS`` means that the helper does not modify any globals.
-    They will only be saved to their canonical location before calling helpers,
-    but they won't be reloaded afterwards.
+  - ``TCG_CALL_NO_WRITE_GLOBALS`` means that the helper does not modify
+    any globals, but may read them.  Globals will be saved to their canonical
+    location before calling helpers, but won't be reloaded afterwards.
 
-  - ``TCG_CALL_NO_SIDE_EFFECTS`` means that the call to the function is removed if
-    the return value is not used.
+  - ``TCG_CALL_NO_SIDE_EFFECTS`` means that the call to the function is
+    removed if the return value is not used.
 
   Note that ``TCG_CALL_NO_READ_GLOBALS`` implies ``TCG_CALL_NO_WRITE_GLOBALS``.
 
-  On some TCG targets (e.g. x86), several calling conventions are
-  supported.
-
 Branches
 ^^^^^^^^
 
@@ -908,20 +928,9 @@ Recommended coding rules for best performance
   often modified, e.g. the integer registers and the condition
   codes. TCG will be able to use host registers to store them.
 
-- Avoid globals stored in fixed registers. They must be used only to
-  store the pointer to the CPU state and possibly to store a pointer
-  to a register window.
-
-- Use temporaries. Use local temporaries only when really needed,
-  e.g. when you need to use a value after a jump. Local temporaries
-  introduce a performance hit in the current TCG implementation: their
-  content is saved to memory at end of each basic block.
-
-- Free temporaries and local temporaries when they are no longer used
-  (tcg_temp_free). Since tcg_const_x() also creates a temporary, you
-  should free it after it is used. Freeing temporaries does not yield
-  a better generated code, but it reduces the memory usage of TCG and
-  the speed of the translation.
+- Free temporaries when they are no longer used (``tcg_temp_free``).
+  Since ``tcg_const_x`` also creates a temporary, you should free it
+  after it is used.
 
 - Don't hesitate to use helpers for complicated or seldom used guest
   instructions. There is little performance advantage in using TCG to
@@ -932,10 +941,6 @@ Recommended coding rules for best performance
   the instruction is mostly doing loads and stores, and in those cases
   inline TCG may still be faster for longer sequences.
 
-- The hard limit on the number of TCG instructions you can generate
-  per guest instruction is set by ``MAX_OP_PER_INSTR`` in ``exec-all.h`` --
-  you cannot exceed this without risking a buffer overrun.
-
 - Use the 'discard' instruction if you know that TCG won't be able to
   prove that a given global is "dead" at a given program point. The
   x86 guest uses it to improve the condition codes optimisation.
-- 
2.34.1



  parent reply	other threads:[~2023-01-30 21:06 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-30 20:59 [PATCH 00/27] tcg: Simplify temporary usage Richard Henderson
2023-01-30 20:59 ` [PATCH] target/arm: Fix physical address resolution for Stage2 Richard Henderson
2023-01-30 21:00   ` Richard Henderson
2023-01-30 20:59 ` [PATCH 01/27] tcg: Adjust TCGContext.temps_in_use check Richard Henderson
2023-01-30 23:30   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 02/27] accel/tcg: Pass max_insn to gen_intermediate_code by pointer Richard Henderson
2023-02-16  7:24   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 03/27] accel/tcg: Use more accurate max_insns for tb_overflow Richard Henderson
2023-01-30 20:59 ` [PATCH 04/27] tcg: Remove branch-to-next regardless of reference count Richard Henderson
2023-01-30 20:59 ` [PATCH 05/27] tcg: Rename TEMP_LOCAL to TEMP_TB Richard Henderson
2023-01-30 23:34   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 06/27] tcg: Add liveness_pass_0 Richard Henderson
2023-01-30 20:59 ` [PATCH 07/27] tcg: Remove TEMP_NORMAL Richard Henderson
2023-01-30 23:36   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 08/27] tcg: Pass TCGTempKind to tcg_temp_new_internal Richard Henderson
2023-01-30 23:36   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 09/27] tcg: Add tcg_temp_ebb_new_{i32,i64,ptr} Richard Henderson
2023-01-30 23:59   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 10/27] tcg: Add tcg_gen_movi_ptr Richard Henderson
2023-02-16  7:15   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 11/27] tcg: Use tcg_temp_ebb_new_* in tcg/ Richard Henderson
2023-01-30 23:59   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 12/27] accel/tcg/plugin: Use tcg_temp_ebb_* Richard Henderson
2023-02-16  7:22   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 13/27] accel/tcg/plugin: Tidy plugin_gen_disable_mem_helpers Richard Henderson
2023-01-30 23:39   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 14/27] tcg: Don't re-use TEMP_TB temporaries Richard Henderson
2023-01-30 20:59 ` [PATCH 15/27] tcg: Change default temp lifetime to TEMP_TB Richard Henderson
2023-01-30 23:52   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 16/27] target/arm: Drop copies in gen_sve_{ldr,str} Richard Henderson
2023-01-30 20:59 ` [PATCH 17/27] target/arm: Don't use tcg_temp_local_new_* Richard Henderson
2023-01-30 23:44   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 18/27] target/cris: Don't use tcg_temp_local_new Richard Henderson
2023-01-30 23:43   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 19/27] target/hexagon: Don't use tcg_temp_local_new_* Richard Henderson
2023-01-30 23:43   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 20/27] target/hppa: Don't use tcg_temp_local_new Richard Henderson
2023-01-30 23:41   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 21/27] target/i386: " Richard Henderson
2023-02-16  7:13   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 22/27] target/mips: " Richard Henderson
2023-01-30 23:42   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 23/27] target/ppc: " Richard Henderson
2023-01-30 23:43   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 24/27] target/xtensa: Don't use tcg_temp_local_new_* Richard Henderson
2023-01-30 23:44   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 25/27] exec/gen-icount: Don't use tcg_temp_local_new_i32 Richard Henderson
2023-01-30 23:45   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` [PATCH 26/27] tcg: Remove tcg_temp_local_new_*, tcg_const_local_* Richard Henderson
2023-01-30 23:45   ` Philippe Mathieu-Daudé
2023-01-30 20:59 ` Richard Henderson [this message]
2023-02-10 12:35 ` [PATCH 00/27] tcg: Simplify temporary usage Emilio Cota
2023-02-16  6:15   ` Richard Henderson
2023-03-01 12:11     ` Emilio Cota
2023-02-16  6:11 ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230130205935.1157347-29-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=cota@braap.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.