Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:20:58

0001 #ifndef Py_INTERNAL_CFG_H
0002 #define Py_INTERNAL_CFG_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006 
0007 #ifndef Py_BUILD_CORE
0008 #  error "this header requires Py_BUILD_CORE define"
0009 #endif
0010 
0011 #include "pycore_opcode_utils.h"
0012 #include "pycore_compile.h"
0013 
0014 
0015 typedef struct {
0016     int i_opcode;
0017     int i_oparg;
0018     _PyCompilerSrcLocation i_loc;
0019     struct _PyCfgBasicblock_ *i_target; /* target block (if jump instruction) */
0020     struct _PyCfgBasicblock_ *i_except; /* target block when exception is raised */
0021 } _PyCfgInstruction;
0022 
0023 typedef struct {
0024     int id;
0025 } _PyCfgJumpTargetLabel;
0026 
0027 
0028 typedef struct {
0029     struct _PyCfgBasicblock_ *handlers[CO_MAXBLOCKS+2];
0030     int depth;
0031 } _PyCfgExceptStack;
0032 
0033 typedef struct _PyCfgBasicblock_ {
0034     /* Each basicblock in a compilation unit is linked via b_list in the
0035        reverse order that the block are allocated.  b_list points to the next
0036        block in this list, not to be confused with b_next, which is next by
0037        control flow. */
0038     struct _PyCfgBasicblock_ *b_list;
0039     /* The label of this block if it is a jump target, -1 otherwise */
0040     _PyCfgJumpTargetLabel b_label;
0041     /* Exception stack at start of block, used by assembler to create the exception handling table */
0042     _PyCfgExceptStack *b_exceptstack;
0043     /* pointer to an array of instructions, initially NULL */
0044     _PyCfgInstruction *b_instr;
0045     /* If b_next is non-NULL, it is a pointer to the next
0046        block reached by normal control flow. */
0047     struct _PyCfgBasicblock_ *b_next;
0048     /* number of instructions used */
0049     int b_iused;
0050     /* length of instruction array (b_instr) */
0051     int b_ialloc;
0052     /* Used by add_checks_for_loads_of_unknown_variables */
0053     uint64_t b_unsafe_locals_mask;
0054     /* Number of predecessors that a block has. */
0055     int b_predecessors;
0056     /* depth of stack upon entry of block, computed by stackdepth() */
0057     int b_startdepth;
0058     /* instruction offset for block, computed by assemble_jump_offsets() */
0059     int b_offset;
0060     /* Basic block is an exception handler that preserves lasti */
0061     unsigned b_preserve_lasti : 1;
0062     /* Used by compiler passes to mark whether they have visited a basic block. */
0063     unsigned b_visited : 1;
0064     /* b_except_handler is used by the cold-detection algorithm to mark exception targets */
0065     unsigned b_except_handler : 1;
0066     /* b_cold is true if this block is not perf critical (like an exception handler) */
0067     unsigned b_cold : 1;
0068     /* b_warm is used by the cold-detection algorithm to mark blocks which are definitely not cold */
0069     unsigned b_warm : 1;
0070 } _PyCfgBasicblock;
0071 
0072 int _PyBasicblock_InsertInstruction(_PyCfgBasicblock *block, int pos, _PyCfgInstruction *instr);
0073 
0074 typedef struct cfg_builder_ {
0075     /* The entryblock, at which control flow begins. All blocks of the
0076        CFG are reachable through the b_next links */
0077     _PyCfgBasicblock *g_entryblock;
0078     /* Pointer to the most recently allocated block.  By following
0079        b_list links, you can reach all allocated blocks. */
0080     _PyCfgBasicblock *g_block_list;
0081     /* pointer to the block currently being constructed */
0082     _PyCfgBasicblock *g_curblock;
0083     /* label for the next instruction to be placed */
0084     _PyCfgJumpTargetLabel g_current_label;
0085 } _PyCfgBuilder;
0086 
0087 int _PyCfgBuilder_UseLabel(_PyCfgBuilder *g, _PyCfgJumpTargetLabel lbl);
0088 int _PyCfgBuilder_Addop(_PyCfgBuilder *g, int opcode, int oparg, _PyCompilerSrcLocation loc);
0089 
0090 int _PyCfgBuilder_Init(_PyCfgBuilder *g);
0091 void _PyCfgBuilder_Fini(_PyCfgBuilder *g);
0092 
0093 _PyCfgInstruction* _PyCfg_BasicblockLastInstr(const _PyCfgBasicblock *b);
0094 int _PyCfg_OptimizeCodeUnit(_PyCfgBuilder *g, PyObject *consts, PyObject *const_cache,
0095                             int code_flags, int nlocals, int nparams, int firstlineno);
0096 int _PyCfg_Stackdepth(_PyCfgBasicblock *entryblock, int code_flags);
0097 void _PyCfg_ConvertPseudoOps(_PyCfgBasicblock *entryblock);
0098 int _PyCfg_ResolveJumps(_PyCfgBuilder *g);
0099 
0100 
0101 static inline int
0102 basicblock_nofallthrough(const _PyCfgBasicblock *b) {
0103     _PyCfgInstruction *last = _PyCfg_BasicblockLastInstr(b);
0104     return (last &&
0105             (IS_SCOPE_EXIT_OPCODE(last->i_opcode) ||
0106              IS_UNCONDITIONAL_JUMP_OPCODE(last->i_opcode)));
0107 }
0108 
0109 #define BB_NO_FALLTHROUGH(B) (basicblock_nofallthrough(B))
0110 #define BB_HAS_FALLTHROUGH(B) (!basicblock_nofallthrough(B))
0111 
0112 PyCodeObject *
0113 _PyAssemble_MakeCodeObject(_PyCompile_CodeUnitMetadata *u, PyObject *const_cache,
0114                            PyObject *consts, int maxdepth, _PyCompile_InstructionSequence *instrs,
0115                            int nlocalsplus, int code_flags, PyObject *filename);
0116 
0117 #ifdef __cplusplus
0118 }
0119 #endif
0120 #endif /* !Py_INTERNAL_CFG_H */