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
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 #ifdef USE_PCH
00083 #include "opt_pch.h"
00084 #endif // USE_PCH
00085 #pragma hdrstop
00086
00087
00088 #include "defs.h"
00089 #include "errors.h"
00090 #include "erglob.h"
00091 #include "glob.h"
00092 #include "mempool.h"
00093 #include "tracing.h"
00094 #include "cxx_memory.h"
00095
00096 #include "opt_defs.h"
00097 #include "opt_cfg.h"
00098 #include "opt_main.h"
00099 #include "opt_htable.h"
00100
00101
00102 class OPT_MTYPE_B {
00103 private:
00104 CFG *_cfg;
00105 CODEMAP *_htable;
00106
00107 CODEREP *Do_mtype_b_cr(CODEREP *cr);
00108 CODEREP *Create_BCVT(MTYPE to_type, CODEREP *x);
00109
00110 OPT_MTYPE_B(void);
00111 OPT_MTYPE_B(const OPT_MTYPE_B&);
00112 OPT_MTYPE_B& operator = (const OPT_MTYPE_B&);
00113
00114 public:
00115 OPT_MTYPE_B( CODEMAP *htable, CFG *cfg): _htable(htable), _cfg(cfg) { }
00116 ~OPT_MTYPE_B(void) {}
00117
00118 void Do_mtype_b(void);
00119 };
00120
00121
00122
00123
00124
00125 CODEREP *
00126 OPT_MTYPE_B::Create_BCVT(MTYPE to_type, CODEREP *x)
00127 {
00128 CODEREP stack_cr;
00129 stack_cr.Init_expr(OPCODE_make_op(OPR_CVT, to_type, MTYPE_B), x);
00130 return _htable->Rehash(&stack_cr);
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140 CODEREP *
00141 OPT_MTYPE_B::Do_mtype_b_cr(CODEREP *cr)
00142 {
00143 CODEREP *x;
00144 CODEREP *new_cr = Alloc_stack_cr(cr->Extra_ptrs_used());
00145 BOOL need_rehash;
00146 INT32 i;
00147 MTYPE dtyp;
00148 OPERATOR opr;
00149 switch (cr->Kind()) {
00150 case CK_CONST:
00151 case CK_RCONST:
00152 case CK_LDA:
00153 case CK_VAR:
00154 return NULL;
00155 case CK_IVAR:
00156 need_rehash = FALSE;
00157 new_cr->Copy(*cr);
00158 x = Do_mtype_b_cr(cr->Ilod_base());
00159 if (x) {
00160 need_rehash = TRUE;
00161 if (x->Dtyp() == MTYPE_B) {
00162 Is_True(cr->Opr() == OPR_PARM,
00163 ("OPT_MTYPE_B::Do_mtype_b_cr: iload base cannot be MTYPE_B"));
00164 x = Create_BCVT(cr->Ilod_base()->Dtyp(), x);
00165 }
00166 new_cr->Set_ilod_base(x);
00167 }
00168 if (cr->Opr() == OPR_MLOAD) {
00169 x = Do_mtype_b_cr(cr->Mload_size());
00170 if (x) {
00171 need_rehash = TRUE;
00172 new_cr->Set_mload_size(x);
00173 Is_True(x->Dtyp() != MTYPE_B,
00174 ("OPT_MTYPE_B::Do_mtype_b_cr: mload size cannot be MTYPE_B"));
00175 }
00176 }
00177 else if (cr->Opr() == OPR_ILOADX) {
00178 x = Do_mtype_b_cr(cr->Index());
00179 if (x) {
00180 need_rehash = TRUE;
00181 new_cr->Set_index(x);
00182 Is_True(x->Dtyp() != MTYPE_B,
00183 ("OPT_MTYPE_B::Do_mtype_b_cr: mload size cannot be MTYPE_B"));
00184 }
00185 }
00186 if (need_rehash) {
00187 new_cr->Set_istr_base(NULL);
00188 new_cr->Set_usecnt(0);
00189 new_cr->Set_ivar_occ(cr->Ivar_occ());
00190 cr->DecUsecnt();
00191 return _htable->Rehash(new_cr);
00192 }
00193 return NULL;
00194 case CK_OP:
00195 #if defined(TARG_NVISA)
00196
00197
00198
00199
00200
00201
00202
00203 if (cr->Is_isop_flag_set(ISOP_MTYPE_B_CR_VISITED))
00204 {
00205 CODEREP *cached_cr = cr->Get_ISOP_mtype_b_cache();
00206 return (cached_cr);
00207 }
00208 else
00209 {
00210 cr->Set_isop_flag(ISOP_MTYPE_B_CR_VISITED);
00211 cr->Set_ISOP_mtype_b_cache(NULL);
00212 }
00213 #endif
00214 need_rehash = FALSE;
00215 new_cr->Copy(*cr);
00216 new_cr->Set_usecnt(0);
00217 opr = cr->Opr();
00218
00219 for (i = 0; i < cr->Kid_count(); i++) {
00220 dtyp = cr->Opnd(i)->Dtyp();
00221 x = Do_mtype_b_cr(cr->Opnd(i));
00222 if (x) {
00223 need_rehash = TRUE;
00224 new_cr->Set_opnd(i, x);
00225 }
00226 else new_cr->Set_opnd(i, cr->Opnd(i));
00227 if (new_cr->Opnd(i)->Dtyp() == MTYPE_B) {
00228 need_rehash = TRUE;
00229 if (opr == OPR_LNOT || opr == OPR_EQ || opr == OPR_NE ||
00230 (opr == OPR_SELECT && i == 0)) {
00231
00232 new_cr->Set_dsctyp(MTYPE_B);
00233 }
00234 else new_cr->Set_opnd(i, Create_BCVT(dtyp, new_cr->Opnd(i)));
00235 }
00236 }
00237 if (opr == OPR_EQ || opr == OPR_NE) {
00238 if (new_cr->Opnd(0)->Dtyp() == MTYPE_B &&
00239 new_cr->Opnd(1)->Dtyp() != MTYPE_B) {
00240 if (new_cr->Opnd(1)->Kind() != CK_CONST) {
00241 new_cr->Set_dsctyp(cr->Dsctyp());
00242 new_cr->Set_opnd(0, Create_BCVT(cr->Dsctyp(), new_cr->Opnd(0)));
00243 }
00244 else {
00245 cr->DecUsecnt();
00246 if (opr == OPR_NE && new_cr->Opnd(1)->Const_val() == 0 ||
00247 opr == OPR_EQ && new_cr->Opnd(1)->Const_val() == 1)
00248 {
00249 #if defined(TARG_NVISA)
00250
00251 return (cr->Set_ISOP_mtype_b_cache(new_cr->Opnd(0)));
00252 #else
00253 return new_cr->Opnd(0);
00254 #endif
00255 }
00256 else if (opr == OPR_EQ && new_cr->Opnd(1)->Const_val() == 0 ||
00257 opr == OPR_NE && new_cr->Opnd(1)->Const_val() == 1) {
00258 new_cr->Set_opr(OPR_LNOT);
00259 opr = OPR_LNOT;
00260 new_cr->Set_kid_count(1);
00261 }
00262 else {
00263 cr->DecUsecnt_rec();
00264 #if defined(TARG_NVISA)
00265 return (cr->Set_ISOP_mtype_b_cache (_htable->Add_const(cr->Dtyp(), opr == OPR_EQ ? 0 : 1)));
00266 #else
00267 return _htable->Add_const(cr->Dtyp(), opr == OPR_EQ ? 0 : 1);
00268 #endif
00269 }
00270 }
00271 }
00272 else if (new_cr->Opnd(0)->Dtyp() != MTYPE_B &&
00273 new_cr->Opnd(1)->Dtyp() == MTYPE_B) {
00274 if (new_cr->Opnd(0)->Kind() != CK_CONST) {
00275 new_cr->Set_dsctyp(cr->Dsctyp());
00276 new_cr->Set_opnd(1, Create_BCVT(cr->Dsctyp(), new_cr->Opnd(1)));
00277 }
00278 else {
00279 cr->DecUsecnt();
00280 if (opr == OPR_NE && new_cr->Opnd(0)->Const_val() == 0 ||
00281 opr == OPR_EQ && new_cr->Opnd(0)->Const_val() == 1)
00282 {
00283 #if defined(TARG_NVISA)
00284 return (cr->Set_ISOP_mtype_b_cache(new_cr->Opnd(1)));
00285 #else
00286 return new_cr->Opnd(1);
00287 #endif
00288 }
00289 else if (opr == OPR_EQ && new_cr->Opnd(0)->Const_val() == 0 ||
00290 opr == OPR_NE && new_cr->Opnd(0)->Const_val() == 1) {
00291 new_cr->Set_opr(OPR_LNOT);
00292 opr = OPR_LNOT;
00293 new_cr->Set_kid_count(1);
00294 new_cr->Set_opnd(0, new_cr->Opnd(1));
00295 }
00296 else {
00297 cr->DecUsecnt_rec();
00298 #if defined(TARG_NVISA)
00299 return (cr->Set_ISOP_mtype_b_cache (_htable->Add_const(MTYPE_B, opr == OPR_EQ ? 0 : 1)));
00300 #else
00301 return _htable->Add_const(MTYPE_B, opr == OPR_EQ ? 0 : 1);
00302 #endif
00303 }
00304 }
00305 }
00306 }
00307
00308 switch (opr) {
00309 case OPR_LNOT:
00310 case OPR_EQ: case OPR_NE:
00311 case OPR_LT: case OPR_LE: case OPR_GT: case OPR_GE:
00312 need_rehash = TRUE;
00313 new_cr->Set_dtyp(MTYPE_B);
00314 break;
00315 default: ;
00316 }
00317
00318 if (need_rehash) {
00319 cr->DecUsecnt();
00320 #if defined(TARG_NVISA)
00321
00322 Is_True(cr->Kind() == CK_OP,
00323 ("OPT_MTYPE_B::Do_mtype_b_cr: Expecting CK_OP - mtypeb cache not valid otherwise"));
00324 return (cr->Set_ISOP_mtype_b_cache (_htable->Rehash(new_cr)));
00325 #else
00326 return _htable->Rehash(new_cr);
00327 #endif
00328 }
00329 return NULL;
00330 }
00331
00332 Fail_FmtAssertion("OPT_MTYPE_B::Do_mtype_b_cr should not get here");
00333 return NULL;
00334 }
00335
00336
00337
00338
00339
00340
00341 void
00342 OPT_MTYPE_B::Do_mtype_b(void)
00343 {
00344 CFG_ITER cfg_iter(_cfg);
00345 BB_NODE *bb;
00346 INT32 i;
00347
00348 FOR_ALL_NODE( bb, cfg_iter, Init() ) {
00349 STMTREP_ITER stmt_iter(bb->Stmtlist());
00350 STMTREP *stmt;
00351 FOR_ALL_NODE(stmt, stmt_iter, Init()) {
00352 OPERATOR opr = stmt->Opr();
00353 CODEREP *rhs = stmt->Rhs();
00354 CODEREP *x;
00355 MTYPE dtyp;
00356 if (OPERATOR_is_call(opr) || opr == OPR_ASM_STMT) {
00357 for (i = 0; i < rhs->Kid_count(); i++) {
00358 dtyp = rhs->Opnd(i)->Dtyp();
00359 x = Do_mtype_b_cr(rhs->Opnd(i));
00360 if (x)
00361 rhs->Set_opnd(i, x);
00362 if (rhs->Opnd(i)->Dtyp() == MTYPE_B)
00363 rhs->Set_opnd(i, Create_BCVT(dtyp, rhs->Opnd(i)));
00364 }
00365 continue;
00366 }
00367 if (rhs) {
00368 if (opr == OPR_PREFETCH) {
00369 x = Do_mtype_b_cr(rhs->Ilod_base());
00370 if (x)
00371 rhs->Set_ilod_base(x);
00372
00373 Is_True(rhs->Ilod_base()->Dtyp() != MTYPE_B,
00374 ("OPT_MTYPE_B::Do_mtype_b: iload base cannot be MTYPE_B"));
00375 }
00376 else {
00377 dtyp = rhs->Dtyp();
00378 x = Do_mtype_b_cr(rhs);
00379 if (x) {
00380 stmt->Set_rhs(x);
00381 rhs = x;
00382 }
00383 if (opr != OPR_FALSEBR && opr != OPR_TRUEBR && opr != OPR_ASSERT &&
00384 rhs->Dtyp() == MTYPE_B)
00385 stmt->Set_rhs(Create_BCVT(dtyp, rhs));
00386 }
00387 }
00388 if (OPERATOR_is_store(opr)) {
00389 CODEREP *lhs = stmt->Lhs();
00390 switch (opr) {
00391 case OPR_MSTORE:
00392 x = Do_mtype_b_cr(lhs->Mstore_size());
00393 if (x)
00394 lhs->Set_mstore_size(x);
00395 Is_True(lhs->Mstore_size()->Dtyp() != MTYPE_B,
00396 ("OPT_MTYPE_B::Do_mtype_b: mstore size cannot be MTYPE_B"));
00397
00398 case OPR_ISTORE:
00399 case OPR_ISTBITS:
00400 x = Do_mtype_b_cr(lhs->Istr_base());
00401 if (x)
00402 lhs->Set_istr_base(x);
00403
00404 Is_True(lhs->Istr_base()->Dtyp() != MTYPE_B,
00405 ("OPT_MTYPE_B::Do_mtype_b: istore base cannot be MTYPE_B"));
00406 break;
00407 default: ;
00408 }
00409 }
00410 }
00411 }
00412 }
00413
00414
00415
00416
00417
00418 void
00419 COMP_UNIT::Introduce_mtype_bool(void)
00420 {
00421 OPT_MTYPE_B opt_mtype_b(Htable(), Cfg());
00422
00423 opt_mtype_b.Do_mtype_b();
00424
00425 if ( Get_Trace(TP_GLOBOPT, BOOL_SIMP_FLAG)) {
00426 fprintf( TFile, "%sAfter COMP_UNIT::Introduce_mtype_bool\n%s",
00427 DBar, DBar );
00428 Cfg()->Print(TFile);
00429 }
00430 }