php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
scdf.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Zend Engine, Call Graph |
4 +----------------------------------------------------------------------+
5 | Copyright (c) The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | https://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Nikita Popov <nikic@php.net> |
16 +----------------------------------------------------------------------+
17*/
18
19#ifndef _SCDF_H
20#define _SCDF_H
21
22#include "zend_bitset.h"
23
24typedef struct _scdf_ctx {
28 /* Represent phi-instructions through the defining var */
32 /* 1 bit per edge, see scdf_edge(cfg, from, to) */
37
38 struct {
40 struct _scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_op);
42 struct _scdf_ctx *scdf, zend_ssa_phi *phi);
44 struct _scdf_ctx *scdf, int block_num, zend_basic_block *block,
45 zend_op *opline, zend_ssa_op *ssa_op);
48
50void scdf_solve(scdf_ctx *scdf, const char *name);
51
53
54/* Add uses to worklist */
55static inline void scdf_add_to_worklist(scdf_ctx *scdf, int var_num) {
56 const zend_ssa *ssa = scdf->ssa;
57 const zend_ssa_var *var = &ssa->vars[var_num];
58 int use;
59 zend_ssa_phi *phi;
60 FOREACH_USE(var, use) {
61 zend_bitset_incl(scdf->instr_worklist, use);
63 FOREACH_PHI_USE(var, phi) {
64 zend_bitset_incl(scdf->phi_var_worklist, phi->ssa_var);
66}
67
68/* This should usually not be necessary, however it's used for type narrowing. */
69static inline void scdf_add_def_to_worklist(scdf_ctx *scdf, int var_num) {
70 const zend_ssa_var *var = &scdf->ssa->vars[var_num];
71 if (var->definition >= 0) {
72 zend_bitset_incl(scdf->instr_worklist, var->definition);
73 } else if (var->definition_phi) {
74 zend_bitset_incl(scdf->phi_var_worklist, var_num);
75 }
76}
77
78static inline uint32_t scdf_edge(const zend_cfg *cfg, int from, int to) {
79 const zend_basic_block *to_block = cfg->blocks + to;
80 int i;
81
82 for (i = 0; i < to_block->predecessors_count; i++) {
83 uint32_t edge = to_block->predecessor_offset + i;
84
85 if (cfg->predecessors[edge] == from) {
86 return edge;
87 }
88 }
90}
91
92static inline bool scdf_is_edge_feasible(const scdf_ctx *scdf, int from, int to) {
93 uint32_t edge = scdf_edge(&scdf->ssa->cfg, from, to);
94 return zend_bitset_in(scdf->feasible_edges, edge);
95}
96
97void scdf_mark_edge_feasible(scdf_ctx *scdf, int from, int to);
98
99#endif
zend_stack handlers
Definition php_output.h:139
struct _scdf_ctx scdf_ctx
void scdf_init(zend_optimizer_ctx *ctx, scdf_ctx *scdf, zend_op_array *op_array, zend_ssa *ssa)
Definition scdf.c:82
void scdf_solve(scdf_ctx *scdf, const char *name)
Definition scdf.c:103
uint32_t scdf_remove_unreachable_blocks(scdf_ctx *scdf)
Definition scdf.c:259
void scdf_mark_edge_feasible(scdf_ctx *scdf, int from, int to)
Definition scdf.c:54
zend_bitset executable_blocks
Definition scdf.h:31
zend_bitset instr_worklist
Definition scdf.h:27
void(* visit_phi)(struct _scdf_ctx *scdf, zend_ssa_phi *phi)
Definition scdf.h:41
void(* mark_feasible_successors)(struct _scdf_ctx *scdf, int block_num, zend_basic_block *block, zend_op *opline, zend_ssa_op *ssa_op)
Definition scdf.h:43
uint32_t instr_worklist_len
Definition scdf.h:34
uint32_t phi_var_worklist_len
Definition scdf.h:35
zend_op_array * op_array
Definition scdf.h:25
void(* visit_instr)(struct _scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_op)
Definition scdf.h:39
zend_bitset feasible_edges
Definition scdf.h:33
zend_ssa * ssa
Definition scdf.h:26
uint32_t block_worklist_len
Definition scdf.h:36
zend_bitset block_worklist
Definition scdf.h:30
zend_bitset phi_var_worklist
Definition scdf.h:29
int * predecessors
Definition zend_cfg.h:88
zend_basic_block * blocks
Definition zend_cfg.h:87
zend_ssa_phi * definition_phi
Definition zend_ssa.h:112
zend_ssa_var * vars
Definition zend_ssa.h:141
zend_cfg cfg
Definition zend_ssa.h:136
zend_ulong * zend_bitset
Definition zend_bitset.h:29
struct _zend_basic_block zend_basic_block
struct _zend_cfg zend_cfg
struct _zend_op zend_op
struct _zend_op_array zend_op_array
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
struct _zend_optimizer_ctx zend_optimizer_ctx
#define ZEND_UNREACHABLE()
#define FOREACH_USE_END()
Definition zend_ssa.h:273
#define FOREACH_PHI_USE_END()
Definition zend_ssa.h:282
#define FOREACH_PHI_USE(var, phi)
Definition zend_ssa.h:277
struct _zend_ssa zend_ssa
struct _zend_ssa_var zend_ssa_var
#define FOREACH_USE(var, use)
Definition zend_ssa.h:269
struct _zend_ssa_phi zend_ssa_phi
Definition zend_ssa.h:62
struct _zend_ssa_op zend_ssa_op
zend_string * name