+/**
+ * binary search of sorted nodes.
+ *
+ * @return the position where n is found in the array arr or ~pos
+ * if the nodes is not here.
+ */
+static INLINE int nodes_bsearch(const ir_node **arr, const ir_node *n) {
+ int hi = ARR_LEN(arr);
+ int lo = 0;
+
+ while (lo < hi) {
+ int md = lo + ((hi - lo) >> 1);
+
+ if (arr[md] == n)
+ return md;
+ if (arr[md] < n)
+ lo = md + 1;
+ else
+ hi = md;
+ }
+
+ return ~lo;
+}
+
+/** Check if a node n can be found inside arr. */
+static int node_contains(const ir_node **arr, const ir_node *n) {
+ int i = nodes_bsearch(arr, n);
+ return i >= 0;
+}
+
+/**
+ * Insert a node into the sorted nodes list.
+ *
+ * @return 1 if the node was inserted, 0 else
+ */
+static int nodes_insert(const ir_node ***arr, const ir_node *irn) {
+ int idx = nodes_bsearch(*arr, irn);
+
+ if (idx < 0) {
+ int i, n = ARR_LEN(*arr);
+ const ir_node **l;
+
+ ARR_APP1(const ir_node *, *arr, irn);
+
+ /* move it */
+ idx = ~idx;
+ l = *arr;
+ for (i = n - 1; i >= idx; --i)
+ l[i + 1] = l[i];
+ l[idx] = irn;
+ return 1;
+ }
+ return 0;
+}
+