#include "optimise.h" #include "blocks.h" #define CHAINED 1 << 31 #define ALL -1 static char* lower() { flow_applyToBlocks(lowerBlock); return NULL; } static void lowerBlock(Block b) { Node p, end = block_lastnode(b)->x.next; for (p = block_firstNode(b); p!= end; p = p->x.next) { costTree(p); lowerTree(p); } } static int costTree(Node node) { if (node == NULL) return 0; else if (node->op == VREG + P) return 1; else return node->x.scratch = costTree(node->kids[0] + node->kids[1]); } static void lowerTree(Node node) { Node a,b, first, second, third; if (cummative(node->op)) { Node right = node->kids[1] Node left = node->kids[1] lowerTree(left); lowerTree(right); if (right->op == node->op) { a = right->kids[0]; b = right->kids[1]; if (left->x.scratch < a->x.scratch) { if (a->x.scratch < b->x.scratch) { right->kids[0] = b; right->kids[1] = a; } else { right->kids[0] = a; right->kids[1] = b; } else { } node->kids[0] = right; node->kids[1] = c; if (a->x.scratch < b->x.scratch) { right->kids[0] = b; right->kids[1] = a; } else { right->kids[0] = a; right->kids[1] = b; } } else if (right->op == node->op) { } else { a = node->kids[0]; b = node->kids[1]; if (a->x.scratch < b->x.scratch) { node->kids[0] = a; node->kids[1] = b; } } } } static optimiser tree_lowering = { "lowering", "Permutes trees so that e-depths are reduced, assisting subsequent optimisations.", 0, &lower };