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
00048
00049
00050
00051
00052
00053
00054
00055
00056 #ifdef USE_PCH
00057 #include "opt_pch.h"
00058 #endif // USE_PCH
00059 #pragma hdrstop
00060
00061
00062 #ifdef _KEEP_RCS_ID
00063 #define opt_exc_CXX "opt_exc.cxx"
00064 static char *rcs_id = opt_exc_CXX"$Revision: 1.5 $";
00065 #endif
00066
00067 #include "defs.h"
00068 #include "opt_bb.h"
00069 #include "opt_cfg.h"
00070 #include "opt_exc.h"
00071 #include "opt_htable.h"
00072
00073 EXC_SCOPE::EXC_SCOPE(WN *begin_wn, EXC *exc)
00074 {
00075 _exc = exc;
00076 _parent = NULL;
00077 _begin_wn = begin_wn;
00078 _vcall = NULL;
00079 _call_list = CXX_NEW(DYN_ARRAY<WN*>(exc->Mem_pool()), exc->Mem_pool());
00080 }
00081
00082
00083
00084 BOOL
00085 EXC_SCOPE::Is_try_region(void) const
00086 {
00087 Is_True(WN_operator(_begin_wn) == OPR_REGION && REGION_is_EH(_begin_wn),
00088 ("EXC_SCOPE::Is_try_region, invalid input"));
00089 WN *stmt, *pragmas = WN_region_pragmas(_begin_wn);
00090 STMT_ITER stmt_iter;
00091 FOR_ALL_ELEM(stmt, stmt_iter, Init(WN_first(pragmas),WN_last(pragmas))) {
00092 if (WN_operator(stmt) == OPR_GOTO)
00093 return TRUE;
00094 }
00095 return FALSE;
00096 }
00097
00098 EXC_SCOPE_TRY_ITER::EXC_SCOPE_TRY_ITER(EXC_SCOPE *exc_scope)
00099 {
00100 INT32 goto_label;
00101 BB_NODE *handler_bb;
00102 WN *optchi;
00103
00104 _exc_scope = exc_scope;
00105
00106 OPT_POOL_Initialize(&_mem_pool, "EXC_SCOPE_TRY_ITER mem pool",
00107 FALSE, EXC_TRACE_FLAG);
00108 OPT_POOL_Push(&_mem_pool, EXC_TRACE_FLAG);
00109
00110 _chi_list = NULL;
00111
00112 if (_exc_scope->Is_try_region()) {
00113
00114
00115 WN *pragmas = WN_region_pragmas(_exc_scope->Begin_wn());
00116 WN *stmt;
00117 STMT_ITER stmt_iter;
00118 FOR_ALL_ELEM(stmt, stmt_iter, Init(WN_first(pragmas),WN_last(pragmas))) {
00119 if (WN_opcode(stmt) == OPC_GOTO) {
00120 goto_label = WN_label_number(stmt);
00121 handler_bb = _exc_scope->Exc()->Cfg()->Get_bb_from_label(goto_label);
00122 Is_True(handler_bb != NULL,
00123 ("EXC_SCOPE_TRY_ITER::EXC_SCOPE_TRY_ITER NULL label BB"));
00124 optchi = handler_bb->Firststmt();
00125 Is_True(WN_operator(optchi) == OPR_OPT_CHI,
00126 ("EXC_SCOPE_TRY_ITER::EXC_SCOPE_TRY_ITER: cannot find chi-list"));
00127 CHI_LIST *chi =_exc_scope->Exc()->Opt_stab()->Get_stmt_chi_list(optchi);
00128 Is_True(chi != NULL,
00129 ("EXC_SCOPE_TRY_ITER::EXC_SCOPE_TRY_ITER, NULL chi"));
00130
00131
00132 CHI_NODE *cnode;
00133 if (_chi_list == NULL)
00134 _chi_list = CXX_NEW(CHI_LIST, &_mem_pool);
00135 FOR_ALL_NODE(cnode, _chi_iter, Init(chi))
00136 _chi_list->Append(cnode->Copy_chi_node(&_mem_pool));
00137 }
00138 }
00139 }
00140 else if (WN_operator(_exc_scope->Begin_wn()) == OPR_REGION &&
00141 REGION_is_EH(_exc_scope->Begin_wn())) {
00142 WN *region_wn = _exc_scope->Begin_wn();
00143 INITO_IDX iidx = WN_ereg_supp(region_wn);
00144 INITV_IDX iv_idx = INITO_val(iidx);
00145 if (iv_idx != 0 && INITV_kind(iv_idx) == INITVKIND_BLOCK) {
00146 iv_idx = INITV_blk(iv_idx);
00147 if (INITV_kind(iv_idx) == INITVKIND_LABEL) {
00148 goto_label = INITV_lab(iv_idx);
00149 handler_bb = _exc_scope->Exc()->Cfg()->Get_bb_from_label(goto_label);
00150 Is_True(handler_bb != NULL,
00151 ("EXC_SCOPE_TRY_ITER::EXC_SCOPE_TRY_ITER NULL label BB"));
00152 optchi = handler_bb->Firststmt();
00153 Is_True(WN_operator(optchi) == OPR_OPT_CHI,
00154 ("EXC_SCOPE_TRY_ITER::EXC_SCOPE_TRY_ITER: cannot find chi-list"));
00155 CHI_LIST *chi =_exc_scope->Exc()->Opt_stab()->Get_stmt_chi_list(optchi);
00156 Is_True(chi != NULL,
00157 ("EXC_SCOPE_TRY_ITER::EXC_SCOPE_TRY_ITER, NULL chi"));
00158
00159
00160 CHI_NODE *cnode;
00161 if (_chi_list == NULL)
00162 _chi_list = CXX_NEW(CHI_LIST, &_mem_pool);
00163 FOR_ALL_NODE(cnode, _chi_iter, Init(chi))
00164 _chi_list->Append(cnode->Copy_chi_node(&_mem_pool));
00165 }
00166 }
00167 }
00168
00169
00170 _chi_iter.Init(_chi_list);
00171 }
00172
00173 AUX_ID
00174 EXC_SCOPE_TRY_ITER::Elem(CHI_NODE *chi)
00175 {
00176 if (chi == NULL) return 0;
00177 if (!chi->Live()) return 0;
00178 AUX_ID aux_id = chi->Aux_id();
00179 POINTS_TO *pt = _exc_scope->Exc()->Opt_stab()->Points_to(aux_id);
00180 if (pt->Local())
00181 return aux_id;
00182 return 0;
00183 }
00184
00185 EXC_SCOPE*
00186 EXC::Push_exc_scope(WN *scope_begin)
00187 {
00188 if (_exc_scope == NULL)
00189 return NULL;
00190 EXC_SCOPE *exc_scope = CXX_NEW( EXC_SCOPE(scope_begin, this), _mem_pool);
00191 EXC_SCOPE *top = (NULL_exc_scope()) ? NULL : Top_exc_scope();
00192 exc_scope->Set_parent(top);
00193 Push_exc_scope(exc_scope);
00194 _exc_scope_list->AddElement(exc_scope);
00195 return exc_scope;
00196 }
00197
00198
00199 void
00200 EXC::Link_top_es(WN *wn)
00201 {
00202 if (_exc_scope == NULL || NULL_exc_scope())
00203 return;
00204 EXC_SCOPE *es = Top_exc_scope();
00205 Link_wn_es(wn, es);
00206 }
00207