summaryrefslogtreecommitdiff
path: root/ir.c
diff options
context:
space:
mode:
Diffstat (limited to 'ir.c')
-rw-r--r--ir.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/ir.c b/ir.c
index a91db1b..c4aa16f 100644
--- a/ir.c
+++ b/ir.c
@@ -1,4 +1,5 @@
#include <stdarg.h>
+#include <stdbit.h>
#include <assert.h>
#include "ir.h"
@@ -10,20 +11,16 @@
void nodelist_fit(NodeList *l, u32 sz, Arena *a) {
if (l->cap) {
if (sz > l->cap) {
- u32 c = l->cap;
- while (sz > c) c <<= 1;
- l->data = resize(a, l->data, l->cap, c);
- l->cap = c;
- }
- } else {
- if (sz > 1) {
- u32 cap = 2;
- while (cap < sz) cap <<= 1;
- Node **data = new_arr(a, Node *, cap);
- data[0] = l->sbo;
- l->data = data;
+ u32 cap = stdc_bit_ceil(sz);
+ l->data = resize(a, l->data, l->cap, cap);
l->cap = cap;
}
+ } else if (sz > 1) {
+ u32 cap = stdc_bit_ceil(sz);
+ Node **data = new_arr(a, Node *, cap);
+ data[0] = l->sbo;
+ l->data = data;
+ l->cap = cap;
}
}
@@ -163,14 +160,26 @@ Node *node_new_empty(Graph *p, NodeType t) {
Node *node_newv(Graph *p, NodeType t, Node *ctrl, ...) {
Node *node = node_new_empty(p, t);
va_list ap;
+ /* do inputs all at once to decrease chance of arena_realloc() fragmenting */
+
va_start(ap, ctrl);
- node_add(p, ctrl, node);
+ node_add_in(p, node, ctrl);
for (;;) {
Node *n = va_arg(ap, Node *);
if (!n) break;
- node_add(p, n, node);
+ node_add_in(p, node, n);
}
va_end(ap);
+
+ va_start(ap, ctrl);
+ if (ctrl) node_add_out(p, ctrl, node);
+ for (;;) {
+ Node *n = va_arg(ap, Node *);
+ if (!n) break;
+ node_add_out(p, n, node);
+ }
+ va_end(ap);
+
return node;
}