source: src/router/php7/ext/opcache/Optimizer/zend_worklist.h @ 31874

Last change on this file since 31874 was 31874, checked in by brainslayer, 3 months ago

update php

File size: 4.0 KB
Line 
1/*
2   +----------------------------------------------------------------------+
3   | Zend Engine                                                          |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1998-2017 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   | http://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: Andy Wingo <wingo@igalia.com>                               |
16   +----------------------------------------------------------------------+
17*/
18
19/* $Id:$ */
20
21#ifndef _ZEND_WORKLIST_H_
22#define _ZEND_WORKLIST_H_
23
24#include "zend_arena.h"
25#include "zend_bitset.h"
26
27typedef struct _zend_worklist_stack {
28        int *buf;
29        int len;
30        int capacity;
31} zend_worklist_stack;
32
33#define ZEND_WORKLIST_STACK_ALLOCA(s, _len, use_heap) do { \
34                (s)->buf = (int*)do_alloca(sizeof(int) * _len, use_heap); \
35                (s)->len = 0; \
36                (s)->capacity = _len; \
37        } while (0)
38
39#define ZEND_WORKLIST_STACK_FREE_ALLOCA(s, use_heap) \
40        free_alloca((s)->buf, use_heap)
41
42static inline int zend_worklist_stack_prepare(zend_arena **arena, zend_worklist_stack *stack, int len)
43{
44        ZEND_ASSERT(len >= 0);
45
46        stack->buf = (int*)zend_arena_calloc(arena, sizeof(*stack->buf), len);
47        if (!stack->buf) {
48                return FAILURE;
49        }
50        stack->len = 0;
51        stack->capacity = len;
52
53        return SUCCESS;
54}
55
56static inline void zend_worklist_stack_push(zend_worklist_stack *stack, int i)
57{
58        ZEND_ASSERT(stack->len < stack->capacity);
59        stack->buf[stack->len++] = i;
60}
61
62static inline int zend_worklist_stack_peek(zend_worklist_stack *stack)
63{
64        ZEND_ASSERT(stack->len);
65        return stack->buf[stack->len - 1];
66}
67
68static inline int zend_worklist_stack_pop(zend_worklist_stack *stack)
69{
70        ZEND_ASSERT(stack->len);
71        return stack->buf[--stack->len];
72}
73
74typedef struct _zend_worklist {
75        zend_bitset visited;
76        zend_worklist_stack stack;
77} zend_worklist;
78
79#define ZEND_WORKLIST_ALLOCA(w, _len, use_heap) do { \
80                (w)->stack.buf = (int*)do_alloca(ZEND_MM_ALIGNED_SIZE(sizeof(int) * _len) + sizeof(zend_ulong) * zend_bitset_len(_len), use_heap); \
81                (w)->stack.len = 0; \
82                (w)->stack.capacity = _len; \
83                (w)->visited = (zend_bitset)((char*)(w)->stack.buf + ZEND_MM_ALIGNED_SIZE(sizeof(int) * _len)); \
84                memset((w)->visited, 0, sizeof(zend_ulong) * zend_bitset_len(_len)); \
85        } while (0)
86
87#define ZEND_WORKLIST_FREE_ALLOCA(w, use_heap) \
88        free_alloca((w)->stack.buf, use_heap)
89
90static inline int zend_worklist_prepare(zend_arena **arena, zend_worklist *worklist, int len)
91{
92        ZEND_ASSERT(len >= 0);
93        worklist->visited = (zend_bitset)zend_arena_calloc(arena, sizeof(zend_ulong), zend_bitset_len(len));
94        if (!worklist->visited) {
95                return FAILURE;
96        }
97        return zend_worklist_stack_prepare(arena, &worklist->stack, len);
98}
99
100static inline int zend_worklist_len(zend_worklist *worklist)
101{
102        return worklist->stack.len;
103}
104
105static inline int zend_worklist_push(zend_worklist *worklist, int i)
106{
107        ZEND_ASSERT(i >= 0 && i < worklist->stack.capacity);
108
109        if (zend_bitset_in(worklist->visited, i)) {
110                return 0;
111        }
112
113        zend_bitset_incl(worklist->visited, i);
114        zend_worklist_stack_push(&worklist->stack, i);
115        return 1;
116}
117
118static inline int zend_worklist_peek(zend_worklist *worklist)
119{
120        return zend_worklist_stack_peek(&worklist->stack);
121}
122
123static inline int zend_worklist_pop(zend_worklist *worklist)
124{
125        /* Does not clear visited flag */
126        return zend_worklist_stack_pop(&worklist->stack);
127}
128
129#endif /* _ZEND_WORKLIST_H_ */
130
131/*
132 * Local variables:
133 * tab-width: 4
134 * c-basic-offset: 4
135 * indent-tabs-mode: t
136 * End:
137 */
Note: See TracBrowser for help on using the repository browser.