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 #include "xstats.h"
00041 #include "wn_tree_util.h"
00042
00043 #include "ipc_pu_size.h"
00044 #include "ipl_outline.h"
00045
00046
00047 static BOOL
00048 block_ends_with_return (const WN* wn)
00049 {
00050 Is_True (WN_operator (wn) == OPR_BLOCK, ("Expected an OPR_BLOCK"));
00051
00052 const WN* last = WN_last (wn);
00053
00054 return (last != NULL && (WN_operator (last) == OPR_RETURN ||
00055 WN_operator (last) == OPR_RETURN_VAL));
00056 }
00057
00058
00059 namespace {
00060
00061 struct SPLIT_CANDIDATE {
00062 UINT32 PU_size;
00063 UINT32 max_size;
00064 UINT32 min_size;
00065
00066 SPLIT_CANDIDATE (UINT32 _pu, UINT32 _max, UINT32 _min) :
00067 PU_size (_pu), max_size (_max), min_size (_min) {}
00068
00069 BOOL operator() (UINT32 block_size) const {
00070
00071 if (block_size <= min_size)
00072 return FALSE;
00073
00074
00075
00076
00077 return (PU_size - block_size + PU_Weight (1, 1, 1) < max_size);
00078 }
00079 };
00080
00081 }
00082
00083
00084
00085
00086
00087 typedef pair<const WN*, UINT32> SPLIT_POINT;
00088
00089
00090 static void
00091 Count_Loop_Size (CONST_TREE_ITER& iter, INT32& bb_cnt, INT32& stmt_cnt,
00092 INT32& call_cnt)
00093 {
00094 Is_True (OPERATOR_is_scf (WN_operator (iter.Wn ())),
00095 ("Expecting a SCF WHIRL node"));
00096
00097 CONST_TREE_ITER next (iter);
00098 next.Skip ();
00099
00100 const WN* last = next.Wn ();
00101 ++iter;
00102 while (iter.Wn () != last) {
00103 const WN* wn = iter.Wn ();
00104 Count_WN_Operator (WN_operator (wn), WN_rtype (wn), bb_cnt,
00105 stmt_cnt, call_cnt);
00106 ++iter;
00107 }
00108
00109 }
00110
00111
00112
00113
00114 static SPLIT_POINT
00115 Find_Split_Point (CONST_TREE_ITER& iter, const WN* last,
00116 const SPLIT_CANDIDATE& split_candidate)
00117 {
00118 INT32 bb_cnt = 0;
00119 INT32 stmt_cnt = 0;
00120 INT32 call_cnt = 0;
00121
00122 UINT32 size_under_OPR_IF = 0;
00123
00124 while (iter.Wn () != last) {
00125 const WN* wn = iter.Wn ();
00126 Is_True (wn != NULL, ("Deferencing iterator past end of tree"));
00127 OPERATOR opr = WN_operator (wn);
00128 Count_WN_Operator (opr, WN_rtype (wn), bb_cnt, stmt_cnt, call_cnt);
00129 if (opr == OPR_IF) {
00130
00131
00132 CONST_TREE_ITER expr (WN_kid0 (wn));
00133 while (expr.Wn () != NULL) {
00134 const WN* expr_wn = expr.Wn ();
00135 Count_WN_Operator (WN_operator (expr_wn), WN_rtype (expr_wn),
00136 bb_cnt, stmt_cnt, call_cnt);
00137 ++expr;
00138 }
00139
00140
00141 CONST_TREE_ITER then_iter (WN_kid1(wn));
00142 SPLIT_POINT then_block =
00143 Find_Split_Point (then_iter, NULL, split_candidate);
00144
00145 if (then_block.first != NULL)
00146
00147 return then_block;
00148 else if (split_candidate (then_block.second)) {
00149 then_block.first = wn;
00150 return then_block;
00151 }
00152
00153
00154 CONST_TREE_ITER else_iter (WN_kid2 (wn));
00155 SPLIT_POINT else_block =
00156 Find_Split_Point (else_iter, NULL, split_candidate);
00157 if (else_block.first != NULL)
00158 return else_block;
00159 else if (split_candidate (else_block.second)) {
00160 else_block.first = wn;
00161 return else_block;
00162 }
00163
00164 size_under_OPR_IF += then_block.second + else_block.second;
00165
00166 const WN* parent = iter.Get_parent_wn ();
00167 iter.Skip ();
00168
00169 if (parent == NULL || WN_operator (parent) != OPR_BLOCK)
00170 continue;
00171
00172 if (iter.Get_parent_wn () != parent)
00173 continue;
00174
00175
00176
00177
00178 BOOL return_in_then_block = block_ends_with_return (WN_kid1 (wn));
00179 BOOL return_in_else_block = block_ends_with_return (WN_kid2 (wn));
00180 if (return_in_then_block || return_in_else_block) {
00181
00182
00183
00184 CONST_TREE_ITER next_stmt (iter);
00185 next_stmt.Skip (1);
00186
00187 SPLIT_POINT split_pt =
00188 Find_Split_Point (iter, next_stmt.Wn (), split_candidate);
00189 if (split_pt.first != NULL)
00190 return split_pt;
00191 else if (split_candidate (split_pt.second +
00192 (return_in_then_block ?
00193 else_block.second :
00194 then_block.second))) {
00195 split_pt.first = wn;
00196 return split_pt;
00197 } else
00198 size_under_OPR_IF += split_pt.second;
00199 }
00200 } else if (OPERATOR_is_scf (opr)) {
00201 switch (opr) {
00202 case OPR_BLOCK:
00203 case OPR_REGION:
00204 case OPR_FUNC_ENTRY:
00205 case OPR_WHERE:
00206 ++iter;
00207 break;
00208 default:
00209 Count_Loop_Size (iter, bb_cnt, stmt_cnt, call_cnt);
00210 break;
00211 }
00212 } else
00213 ++iter;
00214 }
00215
00216 return std::make_pair ((const WN*) NULL,
00217 size_under_OPR_IF + PU_Weight (bb_cnt, stmt_cnt,
00218 call_cnt));
00219 }
00220
00221
00222
00223
00224
00225 const WN*
00226 Outline_Split_Point (const WN* tree_root, UINT32 max_size, UINT32 min_size)
00227 {
00228
00229 if (PU_Weight (PU_WN_BB_Cnt, PU_WN_Stmt_Cnt, PU_WN_Call_Cnt) < min_size)
00230 return NULL;
00231
00232
00233
00234
00235
00236 CONST_TREE_ITER iter (tree_root);
00237
00238 PU_WN_BB_Cnt = PU_WN_Stmt_Cnt = PU_WN_Call_Cnt = 0;
00239 while (iter.Wn () != NULL) {
00240 Count_WN_Operator (WN_operator (iter.Wn ()), WN_rtype (iter.Wn()),
00241 PU_WN_BB_Cnt, PU_WN_Stmt_Cnt, PU_WN_Call_Cnt);
00242 ++iter;
00243 }
00244
00245 UINT32 pu_size = PU_Weight (PU_WN_BB_Cnt, PU_WN_Stmt_Cnt, PU_WN_Call_Cnt);
00246
00247 CONST_TREE_ITER tree_iter (tree_root);
00248
00249 SPLIT_POINT split_pt =
00250 Find_Split_Point (tree_iter, (const WN*) NULL,
00251 SPLIT_CANDIDATE (pu_size, max_size, min_size));
00252
00253 return split_pt.first;
00254 }
00255
00256