00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifdef USE_PCH
00048 #include "opt_pch.h"
00049 #endif // USE_PCH
00050 #pragma hdrstop
00051
00052
00053 #include "opt_etable.h"
00054 #include "opt_dfs.h"
00055 #include "tracing.h"
00056
00057 class REPLACING_OCCUR_SEARCH {
00058 private:
00059 static BOOL _tracing;
00060 static EXP_WORKLST *_worklst;
00061
00062 EXP_PHI *const _cur_node;
00063
00064 EXP_WORKLST *Worklst(void) const { return _worklst; }
00065
00066 public:
00067 static void Set_tracing(const BOOL tracing) { _tracing = tracing; }
00068 static void Set_worklst(EXP_WORKLST *const worklst)
00069 { _worklst = worklst; }
00070
00071 BOOL Tracing(void) const { return _tracing; }
00072
00073 typedef EXP_PHI node_type;
00074 typedef USE_LIST_ENTRY adj_list_type;
00075 typedef USE_LIST_ITER adj_list_iter_type;
00076 typedef EXP_PHI_OCC_ITER node_iterator;
00077
00078 REPLACING_OCCUR_SEARCH(node_type *const cur_node) : _cur_node(cur_node)
00079 {
00080 Is_True(Worklst() != NULL,
00081 ("REPLACING_OCCUR_SEARCH: must not construct "
00082 "with NULL worklist"));
00083 }
00084
00085 void Set_seen(node_type *const phi) const
00086 {
00087 Is_True(phi->Will_b_avail(),
00088 ("REPLACING_OCCUR_SEARCH: searched nodes must be Will_b_avail"));
00089
00090 #if !Is_True_On
00091
00092
00093 if (phi->Identical_to() == NULL) {
00094 #endif
00095 for (INT i = 0; i < phi->Opnd_count(); i++) {
00096 EXP_OCCURS *identical_to = phi->Opnd(i)->Occ_identical_to();
00097
00098 if (identical_to != NULL) {
00099 if (phi->Identical_to() == NULL) {
00100 phi->Set_identical_to(identical_to);
00101 if (phi->Injured(i)) {
00102 phi->Set_identity_injured();
00103 }
00104 }
00105 else {
00106 Is_True(phi->Identical_to() == identical_to,
00107 ("REPLACING_OCCUR_SEARCH: Identity must be "
00108 "identical to only one occurrence"));
00109 Is_True(phi->Identity_injured() || !phi->Injured(i),
00110 ("REPLACING_OCCUR_SEARCH: Identity must be "
00111 "either injured or not"));
00112 }
00113 }
00114 }
00115 #if !Is_True_On
00116 }
00117 #endif
00118 FmtAssert(phi->Identical_to() != NULL,
00119 ("REPLACING_OCCUR_SEARCH: replacing occurrence must be "
00120 "known"));
00121 phi->Set_replacing_occur_known();
00122 }
00123
00124 BOOL Seen(const node_type *const phi) const
00125 { return phi->Replacing_occur_known(); }
00126
00127
00128 void Reach_from_to(const node_type *const def_phi,
00129 const INT opnd_idx,
00130 node_type *const use_phi) const
00131 {
00132 if (use_phi->Will_b_avail() &&
00133 use_phi->Identity() &&
00134 use_phi->Identical_to() == NULL) {
00135 use_phi->Set_identical_to(def_phi->Identical_to());
00136 if (def_phi->Identity_injured() ||
00137 use_phi->Any_opnd_injured()) {
00138 use_phi->Set_identity_injured();
00139 }
00140 }
00141 else {
00142 Is_True(!use_phi->Will_b_avail() || !use_phi->Identity() ||
00143 use_phi->Identical_to() == def_phi->Identical_to(),
00144 ("REPLACING_OCCUR_SEARCH: Identity must be identical "
00145 "to only one occurrence"));
00146 }
00147 }
00148
00149 BOOL Start_from(const node_type *const phi) const
00150 {
00151 if (phi->Will_b_avail() && phi->Identity()) {
00152 for (INT i = 0; i < phi->Opnd_count(); i++) {
00153 if (phi->Opnd(i)->Occ_identical_to() != NULL) {
00154 return TRUE;
00155 }
00156 }
00157 }
00158 return FALSE;
00159 }
00160
00161
00162 BOOL Continue_from_to(const node_type *const def_phi,
00163 const INT opnd_idx,
00164 const node_type *const use_phi) const
00165 { return use_phi->Will_b_avail() && use_phi->Identity(); }
00166
00167
00168 void Postorder_processing(node_type *const phi) const
00169 { }
00170
00171 node_type *Current_node(void) const { return _cur_node; }
00172
00173 adj_list_type *Neighbors(node_type *def_phi) const
00174 { return def_phi->Uses(); }
00175
00176 EXP_OCCURS_CONTAINER &Nodes(void) const
00177 { return Worklst()->Phi_occurs(); }
00178
00179 const char *Search_name(void) const
00180 { return "REPLACING_OCCUR_SEARCH"; }
00181 };
00182
00183 BOOL REPLACING_OCCUR_SEARCH::_tracing = FALSE;
00184 EXP_WORKLST *REPLACING_OCCUR_SEARCH::_worklst = NULL;
00185
00186 static void
00187 Require_phi(const ETABLE *const etable,
00188 const BB_NODE *const bb,
00189 const CODEREP *const expr,
00190 const BOOL tracing)
00191 {
00192 BB_NODE_SET_ITER bns_iter;
00193 BB_NODE *df_bb;
00194
00195 Is_Trace(tracing, (TFile, "Defining occurrence in BB%d\n",
00196 bb->Id()));
00197 Is_Trace(tracing, (TFile, "Dominance frontier: "));
00198 Is_Trace_cmd(tracing, bb->Dom_frontier()->Print(TFile));
00199 Is_Trace(tracing, (TFile, "\n"));
00200
00201 FOR_ALL_ELEM (df_bb, bns_iter, Init(bb->Dom_frontier())) {
00202 EXP_PHI *phi = etable->Lookup_exp_phi(df_bb, expr);
00203
00204
00205
00206 if (phi != NULL && phi->Will_b_avail() && phi->Identity()) {
00207 phi->Reset_identity();
00208
00209 Is_Trace(tracing, (TFile, " -- required phi in BB%d:\n",
00210 df_bb->Id()));
00211 Is_Trace_cmd(tracing, phi->Print(TFile));
00212
00213 Require_phi(etable, df_bb, expr, tracing);
00214 }
00215 }
00216 }
00217
00218 void
00219 EXP_WORKLST::Minimize_temp_ssa(const ETABLE *const etable,
00220 const BOOL tracing)
00221 {
00222 EXP_PHI_OCC_ITER exp_phi_iter;
00223 EXP_PHI *phi;
00224
00225
00226
00227
00228
00229 FOR_ALL_NODE(phi, exp_phi_iter, Init(Phi_occurs())) {
00230 if (phi->Will_b_avail()) {
00231 for (INT i = 0; i < phi->Opnd_count(); i++) {
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 if (phi->Injured(i)) {
00243 Is_Trace(tracing, (TFile, "EXP_PHI with non-identity operand:\n"));
00244 Is_Trace_cmd(tracing, phi->Print(TFile));
00245
00246 Require_phi(etable, phi->Pred(i)->Bb(), Exp(), tracing);
00247 }
00248 else if (phi->Opnd(i)->Is_real_avail_def()) {
00249 Is_Trace(tracing, (TFile, "EXP_PHI with non-identity operand:\n"));
00250 Is_Trace_cmd(tracing, phi->Print(TFile));
00251
00252 Require_phi(etable, phi->Opnd(i)->Bb(), Exp(), tracing);
00253 }
00254 }
00255 }
00256 }
00257
00258 Is_Trace(tracing, (TFile, "==== After required-phi analysis\n"));
00259 Is_Trace_cmd(tracing, Print(TFile));
00260
00261 REPLACING_OCCUR_SEARCH::Set_tracing(tracing);
00262 REPLACING_OCCUR_SEARCH::Set_worklst(this);
00263
00264 REPLACING_OCCUR_SEARCH repl_srch(NULL);
00265
00266 Perform_dfs(repl_srch);
00267
00268 Is_Trace(tracing, (TFile, "==== After EXP_WORKLST::Minimize_temp_ssa\n"));
00269 Is_Trace_cmd(tracing, Print(TFile));
00270 }