#include <stdbool.h>
#include <errno.h>
+#include "util/ralloc.h"
+
#include "freedreno_util.h"
#include "instr-a3xx.h"
-#define CHUNK_SZ 1020
-
-struct ir3_heap_chunk {
- struct ir3_heap_chunk *next;
- uint32_t heap[CHUNK_SZ];
-};
-
-static void grow_heap(struct ir3 *shader)
-{
- struct ir3_heap_chunk *chunk = calloc(1, sizeof(*chunk));
- chunk->next = shader->chunk;
- shader->chunk = chunk;
- shader->heap_idx = 0;
-}
-
/* simple allocator to carve allocations out of an up-front allocated heap,
* so that we can free everything easily in one shot.
*/
void * ir3_alloc(struct ir3 *shader, int sz)
{
- void *ptr;
-
- sz = align(sz, 4) / 4;
-
- if ((shader->heap_idx + sz) > CHUNK_SZ)
- grow_heap(shader);
-
- ptr = &shader->chunk->heap[shader->heap_idx];
- shader->heap_idx += sz;
-
- return ptr;
+ return ralloc_size(shader, sz);
}
struct ir3 * ir3_create(struct ir3_compiler *compiler,
unsigned nin, unsigned nout)
{
- struct ir3 *shader = calloc(1, sizeof(struct ir3));
-
- grow_heap(shader);
+ struct ir3 *shader = ralloc(compiler, struct ir3);
shader->compiler = compiler;
shader->ninputs = nin;
void ir3_destroy(struct ir3 *shader)
{
- while (shader->chunk) {
- struct ir3_heap_chunk *chunk = shader->chunk;
- shader->chunk = chunk->next;
- free(chunk);
- }
+ /* TODO convert the dynamic array to ralloc too: */
free(shader->indirects);
free(shader->predicates);
free(shader->baryfs);
free(shader->keeps);
free(shader->astc_srgb);
- free(shader);
+ ralloc_free(shader);
}
#define iassert(cond) do { \