00001 //-*-c++-*- 00002 00003 /* 00004 * Copyright (C) 2007. QLogic Corporation. All Rights Reserved. 00005 */ 00006 00007 /* 00008 * Copyright 2005, 2006 PathScale, Inc. All Rights Reserved. 00009 */ 00010 00011 // ==================================================================== 00012 // ==================================================================== 00013 // 00014 // Module: opt_estr.h 00015 // $Revision: 1.1.1.1 $ 00016 // $Date: 2005/10/21 19:00:00 $ 00017 // $Author: marcel $ 00018 // $Source: /proj/osprey/CVS/open64/osprey1.0/be/opt/opt_estr.h,v $ 00019 // 00020 // ==================================================================== 00021 // 00022 // Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00023 // 00024 // This program is free software; you can redistribute it and/or modify 00025 // it under the terms of version 2 of the GNU General Public License as 00026 // published by the Free Software Foundation. 00027 // 00028 // This program is distributed in the hope that it would be useful, but 00029 // WITHOUT ANY WARRANTY; without even the implied warranty of 00030 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00031 // 00032 // Further, this software is distributed without any warranty that it 00033 // is free of the rightful claim of any third person regarding 00034 // infringement or the like. Any license provided herein, whether 00035 // implied or otherwise, applies only to this software file. Patent 00036 // licenses, if any, provided herein do not apply to combinations of 00037 // this program with other software, or any other product whatsoever. 00038 // 00039 // You should have received a copy of the GNU General Public License 00040 // along with this program; if not, write the Free Software Foundation, 00041 // Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00042 // 00043 // Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00044 // Mountain View, CA 94043, or: 00045 // 00046 // http://www.sgi.com 00047 // 00048 // For further information regarding this notice, see: 00049 // 00050 // http://oss.sgi.com/projects/GenInfo/NoticeExplan 00051 // 00052 // ==================================================================== 00053 // 00054 // Description: 00055 // 00056 // Data structures and functions for Strength Reduction based on SSA. 00057 // 00058 // ==================================================================== 00059 // ==================================================================== 00060 00061 00062 #ifndef opt_estr_INCLUDED 00063 #define opt_estr_INCLUDED "opt_estr.h" 00064 00065 class BB_NODE; 00066 class CFG; 00067 class EXP_OCCURS; 00068 class PHI_NODE; 00069 00070 #include "opt_htable.h" 00071 00072 class STR_RED { 00073 private: 00074 CFG *_cfg; 00075 CODEMAP *_htable; 00076 BOOL _tracing; 00077 STACK<STMTREP *> _repaired_statements; 00078 00079 CFG *Cfg(void) const 00080 { return _cfg; } 00081 CODEMAP *Htable(void) const 00082 { return _htable; } 00083 BOOL Tracing(void) const 00084 { return _tracing; } 00085 00086 // Determine if the coderep is a variable defined by an IV-update 00087 BOOL Defined_by_iv_update(const CODEREP *use_cr, const CODEREP *def_cr, 00088 CODEREP *invar, BB_NODE *use_bb, 00089 const CODEREP *cand_expr, 00090 BOOL aggstr_cand = FALSE) const; 00091 00092 // Determine if the coderep is a variable defined by an IV-update 00093 // (or chain of updates), and that the final rhs of the iv-update is 00094 // defined in a block that dominates def_bb. 00095 BOOL Defined_by_iv_update_no_def(CODEREP *use_cr, 00096 BB_NODE *def_bb, CODEREP **def_cr, 00097 CODEREP *invar, BB_NODE *use_bb, 00098 const CODEREP *cand_expr, 00099 BOOL aggstr_cand = FALSE) const; 00100 00101 // Return the induction variable in this candidate that we are 00102 // strength-reducing, as well as the multiplier (null if 1). 00103 // Called only when the def occur is phi-result. 00104 void Find_iv_and_mult_phi_res(const EXP_OCCURS *def, CODEREP **iv_def, 00105 const EXP_OCCURS *use, CODEREP **iv_use, 00106 CODEREP **multiplier) const; 00107 00108 // Determine if "last" is defined by a chain of IV updates, one of 00109 // which has "first" on its RHS. 00110 BOOL Updated_by_iv_update(const CODEREP *first, 00111 const CODEREP *last, 00112 CODEREP *invar, 00113 BB_NODE *innermost_use_bb, 00114 const CODEREP *cand_expr, 00115 BOOL aggstr_cand) const; 00116 00117 // Determine if an expression is loop-invariant for its occurrence 00118 // in BB. 00119 BOOL Is_const_or_loop_invar(CODEREP *expr, BB_NODE *bb) const; 00120 00121 // Determine if the CVT is a linear function, and the value being 00122 // converted can thus be used as an iv. 00123 BOOL Is_cvt_linear(const CODEREP *cr) const; 00124 BOOL Is_implicit_cvt_linear (MTYPE, MTYPE) const; 00125 00126 // Does the lhs var match the rhs var/expr? If so, return the 00127 // rhs var, else return NULL. May strip off CVTs, etc. 00128 CODEREP *Matches_lhs( const CODEREP *lhs, const CODEREP *rhs )const; 00129 00130 // Determine if bb1 is in the same loop as bb2, or if bb1 is in a 00131 // loop enclosed by bb2's loop (if any) 00132 BOOL In_same_or_lower_nesting( BB_NODE *bb1, BB_NODE *bb2 ) const; 00133 00134 // private functions so they cannot be used incorrectly. 00135 STR_RED(const STR_RED&); 00136 STR_RED& operator = (const STR_RED&); 00137 00138 public: 00139 // NOTE: if adding any parameters, create a private version of 00140 // this constructor with void parameter so it can't be used. 00141 STR_RED(CFG *cfg, CODEMAP *htable, MEM_POOL *pool, BOOL tracing) : 00142 _cfg(cfg), _htable(htable), _tracing(tracing), 00143 _repaired_statements(pool) 00144 { }; 00145 00146 ~STR_RED(void) 00147 { }; 00148 00149 // Determine if the opcode is strength-reducible 00150 BOOL Candidate_opc(const OPCODE opc) const 00151 { 00152 switch ( OPCODE_operator(opc) ) { 00153 case OPR_MPY: 00154 case OPR_ADD: 00155 case OPR_SUB: 00156 case OPR_NEG: 00157 case OPR_CVT: 00158 return MTYPE_is_integral(OPCODE_rtype(opc)) && 00159 ! MTYPE_is_vector(OPCODE_rtype(opc)); 00160 default: 00161 return FALSE; 00162 } 00163 } 00164 00165 // Determine if the use occurrence is a strength-reduction candidate 00166 BOOL Candidate(const CODEREP *cr, 00167 const CODEREP *def_opnd0, const CODEREP *def_opnd1, 00168 BB_NODE *def_bb, 00169 CODEREP *use_opnd0, CODEREP *use_opnd1, 00170 BB_NODE *use_bb) const; 00171 00172 // Determine if the use occurrence is a strength-reduction candidate 00173 // but assume that the def occurrence is in a phi result in the 00174 // def_bb. 00175 BOOL Candidate_phi_res(const CODEREP *cr, 00176 BB_NODE *def_bb, 00177 CODEREP *use_opnd0, CODEREP *use_opnd1, 00178 BB_NODE *use_bb) const; 00179 00180 // Determine if the statement is an IV update; 00181 // Called during Phi-Insertion step. 00182 BOOL Determine_iv_update(STMTREP *stmt, CODEREP **updated) const; 00183 00184 // Determine if one of the phi opnds is defined by an IV update; 00185 // Called during Phi-Insertion step. 00186 BOOL Determine_iv_update_phi(PHI_NODE *phi, const CODEREP *cand_expr) const; 00187 00188 // Return the induction variable in this candidate that we are 00189 // strength-reducing, as well as the multiplier (null if 1) 00190 void Find_iv_and_mult(const EXP_OCCURS *def, CODEREP **iv_def, 00191 const EXP_OCCURS *use, CODEREP **iv_use, 00192 CODEREP **multiplier) const; 00193 00194 00195 // Returns the threshold adjusted by taking into account the content of the 00196 // innermost loop that bb belongs to 00197 INT Local_autoaggstr_reduction_threshold(BB_NODE *bb) const; 00198 00199 // Determine if the statement updates an induction variable, and 00200 // return the induction variable being updated (one on rhs), the 00201 // increment amount, and whether or not it's an increment or 00202 // decrement 00203 BOOL Find_iv_and_incr(STMTREP *stmt, CODEREP **updated_iv, 00204 CODEREP **incr_amt, BOOL *is_add, 00205 BOOL aggstr_cand = FALSE) const; 00206 00207 // Find the definition of the variable, following the u-d chain 00208 // until we get a real store to the variable, and return its rhs. 00209 // Used if the rhs of an iv-update has been CSE'd 00210 CODEREP *Find_real_defs_rhs(const CODEREP *var) const; 00211 00212 // Functions to keep track of whether an injury caused by this 00213 // statement has been repaired. The corresponding STMTREP member 00214 // functions should be called only from here, nowhere else. 00215 void Set_repaired(STMTREP *); 00216 BOOL Repaired(const STMTREP *stmt) const { return stmt->Repaired(); } 00217 00218 void Perform_per_expr_cleanup(void); 00219 00220 BOOL Update_happens_rarely_enough( BB_NODE *update_bb, 00221 BB_NODE *innermost_use_bb, 00222 const CODEREP *use_expr) const; 00223 00224 }; 00225 00226 #endif // opt_estr_INCLUDED
1.5.6