Use PHP memory manager

This commit is contained in:
Dmitry Stogov 2022-08-10 17:41:14 +03:00
parent 17c567f591
commit 1820972a21
6 changed files with 65 additions and 9 deletions

29
ir.h
View File

@ -593,10 +593,31 @@ void ir_check(ir_ctx *ctx);
void ir_consistency_check(void);
/* IR Memmory Allocation */
#define ir_mem_malloc(size) malloc(size)
#define ir_mem_calloc(n, size) calloc(n, size)
#define ir_mem_realloc(ptr, size) realloc(ptr, size)
#define ir_mem_free(ptr) free(ptr)
#ifndef ir_mem_malloc
# define ir_mem_malloc malloc
#endif
#ifndef ir_mem_calloc
# define ir_mem_calloc calloc
#endif
#ifndef ir_mem_realloc
# define ir_mem_realloc realloc
#endif
#ifndef ir_mem_free
# define ir_mem_free free
#endif
#ifndef ir_mem_pmalloc
# define ir_mem_pmalloc malloc
#endif
#ifndef ir_mem_pcalloc
# define ir_mem_pcalloc calloc
#endif
#ifndef ir_mem_prealloc
# define ir_mem_prealloc realloc
#endif
#ifndef ir_mem_pfree
# define ir_mem_pfree free
#endif
void *ir_mem_mmap(size_t size);
int ir_mem_unmap(void *ptr, size_t size);

View File

@ -10,6 +10,19 @@
# define IR_SET_ALIGNED(alignment, decl) decl
#endif
#define DASM_M_GROW(ctx, t, p, sz, need) \
do { \
size_t _sz = (sz), _need = (need); \
if (_sz < _need) { \
if (_sz < 16) _sz = 16; \
while (_sz < _need) _sz += _sz; \
(p) = (t *)ir_mem_realloc((p), _sz); \
(sz) = _sz; \
} \
} while(0)
#define DASM_M_FREE(ctx, p, sz) ir_mem_free(p)
#if IR_DEBUG
# define DASM_CHECKS
#endif

View File

@ -74,7 +74,7 @@ void ir_disasm_add_symbol(const char *name,
ir_sym_node *sym;
size_t len = strlen(name);
sym = ir_mem_malloc(sizeof(ir_sym_node) + len + 1);
sym = ir_mem_pmalloc(sizeof(ir_sym_node) + len + 1);
if (!sym) {
return;
}
@ -111,7 +111,7 @@ void ir_disasm_add_symbol(const char *name,
/* reduce size of the existing symbol */
node->end = sym->end;
}
free(sym);
ir_mem_pfree(sym);
return;
}
} while (1);
@ -167,7 +167,7 @@ static void ir_disasm_destroy_symbols(ir_sym_node *n)
if (n->child[1]) {
ir_disasm_destroy_symbols(n->child[1]);
}
free(n);
ir_mem_pfree(n);
}
}

View File

@ -1,6 +1,13 @@
#ifndef IR_PHP_H
#define IR_PHP_H
#include "zend.h"
#define IR_PHP_OPS(_)
#define ir_mem_malloc emalloc
#define ir_mem_calloc ecalloc
#define ir_mem_realloc erealloc
#define ir_mem_free efree
#endif /* IR_PHP_H */

View File

@ -615,13 +615,13 @@ void ir_free_live_ranges(ir_live_range *live_range)
void ir_free_live_intervals(ir_live_interval **live_intervals, int count)
{
uint32_t i;
ir_live_interval *ival;
ir_live_interval *ival, *next;
ir_use_pos *use_pos;
count += IR_REG_NUM;
for (i = 0; i <= count; i++) {
ival = live_intervals[i];
if (ival) {
while (ival) {
if (ival->range.next) {
ir_free_live_ranges(ival->range.next);
}
@ -631,7 +631,9 @@ void ir_free_live_intervals(ir_live_interval **live_intervals, int count)
use_pos = p->next;
ir_mem_free(p);
}
next = ival->next;
ir_mem_free(ival);
ival = next;
}
}
ir_mem_free(live_intervals);

View File

@ -10,6 +10,19 @@
# define IR_SET_ALIGNED(alignment, decl) decl
#endif
#define DASM_M_GROW(ctx, t, p, sz, need) \
do { \
size_t _sz = (sz), _need = (need); \
if (_sz < _need) { \
if (_sz < 16) _sz = 16; \
while (_sz < _need) _sz += _sz; \
(p) = (t *)ir_mem_realloc((p), _sz); \
(sz) = _sz; \
} \
} while(0)
#define DASM_M_FREE(ctx, p, sz) ir_mem_free(p)
#if IR_DEBUG
# define DASM_CHECKS
#endif