static void reduce_topology_x(int gnx, atom_id index[], gmx_mtop_t *mtop, rvec x[], rvec v[]) { t_topology top; gmx_bool *bKeep; atom_id *invindex; int i; top = gmx_mtop_t_to_t_topology(mtop); bKeep = bKeepIt(gnx, top.atoms.nr, index); invindex = invind(gnx, top.atoms.nr, index); reduce_block(bKeep, &(top.cgs), "cgs"); reduce_block(bKeep, &(top.mols), "mols"); reduce_blocka(invindex, bKeep, &(top.excls), "excls"); reduce_rvec(gnx, index, x); reduce_rvec(gnx, index, v); reduce_atom(gnx, index, top.atoms.atom, top.atoms.atomname, &(top.atoms.nres), top.atoms.resinfo); for (i = 0; (i < F_NRE); i++) { reduce_ilist(invindex, bKeep, &(top.idef.il[i]), interaction_function[i].nratoms, interaction_function[i].name); } top.atoms.nr = gnx; mtop->nmoltype = 1; snew(mtop->moltype, mtop->nmoltype); mtop->moltype[0].name = mtop->name; mtop->moltype[0].atoms = top.atoms; for (i = 0; i < F_NRE; i++) { mtop->moltype[0].ilist[i] = top.idef.il[i]; } mtop->moltype[0].atoms = top.atoms; mtop->moltype[0].cgs = top.cgs; mtop->moltype[0].excls = top.excls; mtop->nmolblock = 1; snew(mtop->molblock, mtop->nmolblock); mtop->molblock[0].type = 0; mtop->molblock[0].nmol = 1; mtop->molblock[0].natoms_mol = top.atoms.nr; mtop->molblock[0].nposres_xA = 0; mtop->molblock[0].nposres_xB = 0; mtop->natoms = top.atoms.nr; }
static STATEMENT *reduce_statement(MODULE *module, FUNCTION *func, BLOCK *block, STATEMENT *stmt) { if (stmt == NULL) return stmt; if (tree_is_type(stmt, STMT_ASSIGN)) { EXPRESSION *expr = tree_get_child(stmt, 1); expr = simplify_expression(module, func, block, expr, stmt); tree_get_child(stmt, 1) = expr; } else if (tree_is_type(stmt, STMT_IF)) { EXPRESSION *cond = tree_get_child(stmt, 0); cond = simplify_expression(module, func, block, cond, stmt); tree_get_child(stmt, 0) = cond; reduce_block(module, func, tree_get_child(stmt, 1)); reduce_block(module, func, tree_get_child(stmt, 2)); } else if (tree_is_type(stmt, STMT_WHILE)) { EXPRESSION *cond = tree_get_child(stmt, 0); BLOCK *body = tree_get_child(stmt, 1); if (!is_atomic(cond)) { EXPRESSION *old_cond = cond; cond = atomise_expression(module, func, block, cond, stmt); tree_get_child(stmt, 0) = cond; STATEMENT *new_assign = make_assignment(cond, CAST_TO_EXPRESSION(tree_copy(old_cond)), CAST_TO_AST(cond)->source_line); tree_add_child(body, new_assign); } reduce_block(module, func, body); } else if (tree_is_type(stmt, STMT_RETURN)) { EXPRESSION *expr = tree_get_child(stmt, 0); expr = atomise_expression(module, func, block, expr, stmt); tree_get_child(stmt, 0) = expr; } else if (tree_is_type(stmt, STMT_RESTART)) { /* Do nothing. */ } else error("Not sure how to reduce statement of type %d\n", tree_type(stmt)); return stmt; }
static int reduce_block(MODULE *module, FUNCTION *func, BLOCK *block) { int i; int size; if (block == NULL) return 0; size = tree_num_children(block); for (i = 0; i < tree_num_children(block); i++) { STATEMENT *stmt = tree_get_child(block, i); if (tree_is_type(stmt, STMT_BLOCK)) reduce_block(module, func, CAST_TO_BLOCK(stmt)); else reduce_statement(module, func, block, stmt); if (size != tree_num_children(block)) { size = tree_num_children(block); i--; } } return 1; }
int reduce(MODULE *module, FUNCTION *func) { int changed; if (has_graph(func)) changed = reduce_graph(module, func, func->graph); else changed = reduce_block(module, func, tree_get_child(func, 0)); return changed; }