X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbepeephole.h;h=26a53c33730e32cc6935f5ce8159801e64b17a09;hb=493edb72be97161f5c8762e4589631a6e7083a29;hp=86fe44f129673499b425ab23d5a4f3a883f72aee;hpb=b70b1794d3fe3c289fd988aacbb567761186cd16;p=libfirm diff --git a/ir/be/bepeephole.h b/ir/be/bepeephole.h index 86fe44f12..26a53c337 100644 --- a/ir/be/bepeephole.h +++ b/ir/be/bepeephole.h @@ -1,65 +1,77 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. + * Copyright (C) 2012 University of Karlsruhe. */ /** * @file * @brief peephole optimisation framework * @author Matthias Braun - * @version $Id$ */ - #ifndef BEPEEPHOLE_H #define BEPEEPHOLE_H -#include "beirg.h" -#include "bearch_t.h" +#include "bearch.h" -extern ir_node ***register_values; +extern ir_node **register_values; -static INLINE ir_node *be_peephole_get_value(unsigned regclass_idx, - unsigned register_idx) +static inline ir_node *be_peephole_get_value(unsigned register_idx) { - return register_values[regclass_idx][register_idx]; + return register_values[register_idx]; } -static INLINE ir_node *be_peephole_get_reg_value(const arch_register_t *reg) +static inline ir_node *be_peephole_get_reg_value(const arch_register_t *reg) { - unsigned regclass_idx = arch_register_class_index(arch_register_get_class(reg)); - unsigned register_idx = arch_register_get_index(reg); - - return be_peephole_get_value(regclass_idx, register_idx); + unsigned register_idx = reg->global_index; + return be_peephole_get_value(register_idx); } /** - * Datatype of the generic op handler for optimisation. If it exchanged node - * with something else, then it must return the new node, otherwise NULL. + * Datatype of the generic op handler for optimisation. + */ +typedef void (*peephole_opt_func) (ir_node *node); + +/** + * When doing peephole optimisation use this function instead of plain + * exchange(), so it can update its internal state. This function also removes + * the old node from the schedule. + */ +void be_peephole_exchange(ir_node *old, ir_node *nw); + +/** + * Tries to optimize a beIncSp node with its previous IncSP node. + * Must be run from a be_peephole_opt() context. + * + * @param node a be_IncSP node + * + * @return the new IncSP node or node itself + */ +ir_node *be_peephole_IncSP_IncSP(ir_node *node); + +bool be_has_only_one_user(ir_node *node); + +/** + * In a scheduled program with registers assigned, + * checks whether @p node can be moved before @p before without changing program + * semantics. + * + * Note: It is allowed to use this function without being in a peephole + * optimization phase. */ -typedef ir_node*(*peephole_opt_func) (ir_node *node); +bool be_can_move_down(ir_heights_t *heights, const ir_node *node, + const ir_node *before); + +bool be_can_move_up(ir_heights_t *heights, const ir_node *node, + const ir_node *after); /** * Do peephole optimisations. It traverses the schedule of all blocks in * backward direction. The register_values variable indicates which (live) * values are stored in which register. * The generic op handler is called for each node if it exists. That's where - * backedn specific optimisations should be performed based on the + * backend specific optimisations should be performed based on the * register-liveness information. */ -void be_peephole_opt(be_irg_t *birg); +void be_peephole_opt(ir_graph *irg); #endif