1#ifndef HALIDE_RUNTIME_POINTER_TABLE_H
2#define HALIDE_RUNTIME_POINTER_TABLE_H
4#include "../HalideRuntime.h"
29 void resize(
void *user_context,
size_t entry_count,
bool realloc =
true);
35 void remove(
void *user_context,
size_t index);
37 void fill(
void *user_context,
const void **array,
size_t array_size);
38 void insert(
void *user_context,
size_t index,
const void **array,
size_t array_size);
39 void replace(
void *user_context,
size_t index,
const void **array,
size_t array_size);
40 void prepend(
void *user_context,
const void **array,
size_t array_size);
41 void append(
void *user_context,
const void **array,
size_t array_size);
42 void remove(
void *user_context,
size_t index,
size_t entry_count);
47 void clear(
void *user_context);
48 void destroy(
void *user_context);
57 const void **
data()
const;
66 void allocate(
void *user_context,
size_t capacity);
78 if (initial_capacity) {
79 reserve(user_context, initial_capacity);
86 ptr =
static_cast<void **
>(allocator.
allocate(
nullptr,
other.capacity *
sizeof(
void *)));
87 capacity =
other.capacity;
89 if (ptr &&
other.count != 0) {
91 memcpy(this->ptr,
other.ptr, count *
sizeof(
void *));
101 if (ptr !=
nullptr) {
104 capacity = count = 0;
110 capacity = count = 0;
112 if (initial_capacity) {
113 reserve(user_context, initial_capacity);
118 if (&
other !=
this) {
120 if (count != 0 &&
other.ptr !=
nullptr) {
128 if (count !=
other.count) {
131 return memcmp(this->ptr,
other.ptr,
this->size() *
sizeof(
void *)) == 0;
135 return !(*
this ==
other);
139 if (array_size != 0) {
140 resize(user_context, array_size);
141 memcpy(this->ptr, array, array_size *
sizeof(
void *));
148 ptr[index] =
const_cast<void *
>(
entry_ptr);
188#ifdef DEBUG_RUNTIME_INTERNAL
189 debug(user_context) <<
"PointerTable: Resize ("
193 <<
"sizeof(void*)=" << (
int32_t)
sizeof(
void *) <<
" "
194 <<
"realloc=" << (
realloc ?
"true" :
"false") <<
")...\n";
208 if (capacity > count) {
211 size_t bytes = count *
sizeof(
void *);
217 ptr =
static_cast<void **
>(
new_ptr);
222 const void *addr =
reinterpret_cast<const void *
>(
entry_ptr);
223 insert(user_context, index, &addr, 1);
227 remove(user_context, index, 1);
235 size_t src_offset = (index + entry_count) *
sizeof(
void *);
236 size_t bytes = (
last_index - index - entry_count) *
sizeof(
void *);
238#ifdef DEBUG_RUNTIME_INTERNAL
239 debug(user_context) <<
"PointerTable: Remove ("
240 <<
"index=" << (
int32_t)index <<
" "
241 <<
"entry_count=" << (
int32_t)entry_count <<
" "
245 <<
"bytes=" << (
int32_t)bytes <<
")...\n";
257#ifdef DEBUG_RUNTIME_INTERNAL
258 debug(user_context) <<
"PointerTable: Replace ("
259 <<
"index=" << (
int32_t)index <<
" "
260 <<
"array_size=" << (
int32_t)array_size <<
" "
263 <<
"capacity=" << (
int32_t)capacity <<
")...\n";
277 size_t dst_offset = (index + array_size) *
sizeof(
void *);
278 size_t bytes = (
last_index - index) *
sizeof(
void *);
281 replace(user_context, index, array, array_size);
285 insert(user_context, 0, array, array_size);
322 size_t index = count - 1;
327 return const_cast<const void **
>(ptr);
330void PointerTable::allocate(
void *user_context,
size_t new_capacity) {
335#ifdef DEBUG_RUNTIME_INTERNAL
336 debug(user_context) <<
"PointerTable: Allocating (bytes=" << (
int32_t)bytes <<
" allocator=" << (
void *)allocator.
allocate <<
")...\n";
339 void *
new_ptr = bytes ? allocator.
allocate(user_context, bytes) :
nullptr;
340 if (count != 0 && ptr !=
nullptr &&
new_ptr !=
nullptr) {
343 if (ptr !=
nullptr) {
348 ptr =
static_cast<void **
>(
new_ptr);
352const SystemMemoryAllocatorFns &
354 return this->allocator;
const SystemMemoryAllocatorFns & current_allocator() const
void pop_front(void *user_context)
void fill(void *user_context, const void **array, size_t array_size)
PointerTable(void *user_context, size_t initial_capacity=0, const SystemMemoryAllocatorFns &sma=default_allocator())
void remove(void *user_context, size_t index)
void initialize(void *user_context, size_t initial_capacity=0, const SystemMemoryAllocatorFns &sma=default_allocator())
static const SystemMemoryAllocatorFns & default_allocator()
void shrink_to_fit(void *user_context)
bool operator==(const PointerTable &other) const
void clear(void *user_context)
void prepend(void *user_context, const void *entry_ptr)
static constexpr size_t default_capacity
void replace(void *user_context, size_t index, const void **array, size_t array_size)
void reserve(void *user_context, size_t capacity, bool free_existing=false)
PointerTable & operator=(const PointerTable &other)
void * operator[](size_t index)
void pop_back(void *user_context)
void destroy(void *user_context)
void resize(void *user_context, size_t entry_count, bool realloc=true)
void append(void *user_context, const void *entry_ptr)
void insert(void *user_context, size_t index, const void *entry_ptr)
bool operator!=(const PointerTable &other) const
void assign(void *user_context, size_t index, const void *entry_ptr)
ALWAYS_INLINE void * native_system_malloc(void *user_context, size_t bytes)
ALWAYS_INLINE void native_system_free(void *user_context, void *ptr)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
void * memmove(void *dest, const void *src, size_t n)
#define halide_debug_assert(user_context, cond)
halide_debug_assert() is like halide_assert(), but only expands into a check when DEBUG_RUNTIME is de...
signed __INT32_TYPE__ int32_t
void * memcpy(void *s1, const void *s2, size_t n)
int memcmp(const void *s1, const void *s2, size_t n)
DeallocateSystemFn deallocate
AllocateSystemFn allocate