#include "optimise.h" #include "blocks.h" //#include "collections.h" void intraBlock2(Block b); extern ArrayList getPairs(Block b); typedef struct node_pair *NodePair; static char* xxxx() { flow_applyToBlocks(intraBlock2); // Check flowgraph is OK. return NULL; } extern void removeDeadStores(Block b); extern void applyPair(Block b, NodePair pair); extern int pairID(NodePair n); static int compare(const void* v1, const void* v2) { const NodePair n1 = *(NodePair*)v1; const NodePair n2 = *(NodePair*)v2; return pairID(n1) - pairID(n2); } void intraBlock2(Block b) { if (local_variable_count == 0) return; ArrayList pairs = getPairs(b); int i, size = list_size(pairs); list_sort(pairs, &compare); for (i = 0; i < size; i++) { applyPair(b, (NodePair)list_item(pairs, i)); } removeDeadStores(b); } optimiser intra2 = { "intra2", "Intra block 2 - Optimises locals in order of their index.", 0, &xxxx };