Author: ycwu Date: 2011-09-09 01:30:40 -0400 (Fri, 09 Sep 2011) New Revision: 3734
Modified: trunk/osprey/wgen/wgen_decl.cxx trunk/osprey/wgen/wgen_expr.cxx Log: fixed for bug 826 The fix is to partially undo the change for revision 3659. The change for revision 3659 includes other fix in addition to the one for removing 'structure copies'. This fix undoes only the part for optimization of removing structure copies. Code review by Lai Jianxin Modified: trunk/osprey/wgen/wgen_decl.cxx =================================================================== --- trunk/osprey/wgen/wgen_decl.cxx 2011-09-09 02:32:43 UTC (rev 3733) +++ trunk/osprey/wgen/wgen_decl.cxx 2011-09-09 05:30:40 UTC (rev 3734) @@ -2813,61 +2813,14 @@ Is_True( (WN_operator(target) == OPR_LDID || WN_operator(target) == OPR_LDA), ("Invalid operator for target")); - // handle struct init by a return value of a call, - // remove redundant temp variable copy - - // if return type is struct type, and the result is used in lhs, - // then the Mreturn temp variable is not needed, the address of lhs - // should be passed as hidden parameter - bool return_val_transformed = false; - WN *block = NULL; - if (WN_operator(init_wn) == OPR_COMMA && - WN_rtype(init_wn) == MTYPE_M) { - WN *block = WN_kid0(init_wn); - WN *ldidTemp = WN_kid1(init_wn); - if (WN_operator(ldidTemp) == OPR_LDID && - WN_operator(block) == OPR_BLOCK) { - - // replace MSTID _temp_.Mreturn.1 - // with MSTID lhs - WN *stidTemp = WN_last(block); - if (WN_operator(stidTemp) == OPR_STID) { - // remove block from the init_wn - WN_kid0(init_wn) = 0; - WN_DELETE_Tree(init_wn); - init_wn = block; - - WN *kid = WN_kid0(stidTemp); - WN_kid0(stidTemp) = 0; - WN_DELETE_FromBlock(block, stidTemp); - - if( WN_operator(target) == OPR_LDID ) { - TY_IDX ptr_ty = Make_Pointer_Type(ty); - wn = WN_Istore(mtype, offset, ptr_ty, target, kid, field_id); - } - else { // OPR_LDA - ST *st = WN_st(target); - wn = WN_Stid (mtype, WN_lda_offset(target) + offset, st, - ty, kid, field_id); - } - WN_INSERT_BlockLast(block, wn); - wn = block; - return_val_transformed = true; - } - } - else - block = NULL; // not a block - } - if (!return_val_transformed) { - if( WN_operator(target) == OPR_LDID ) { + if( WN_operator(target) == OPR_LDID ) { TY_IDX ptr_ty = Make_Pointer_Type(ty); wn = WN_Istore(mtype, offset, ptr_ty, target, init_wn, field_id); - } - else { // OPR_LDA + } + else { // OPR_LDA ST *st = WN_st(target); wn = WN_Stid (mtype, WN_lda_offset(target) + offset, st, ty, init_wn, field_id); - } } #else WN *wn = WN_Stid (mtype, ST_ofst(st) + offset, st, Modified: trunk/osprey/wgen/wgen_expr.cxx =================================================================== --- trunk/osprey/wgen/wgen_expr.cxx 2011-09-09 02:32:43 UTC (rev 3733) +++ trunk/osprey/wgen/wgen_expr.cxx 2011-09-09 05:30:40 UTC (rev 3734) @@ -1645,51 +1645,9 @@ if (volt) Set_TY_is_volatile(hi_ty_idx); #endif - // if return type is struct type, and the result is used in lhs, - // then the Mreturn temp variable is not needed, the address of lhs - // should be passed as hidden parameter - - // the same pattern match is used in different places - // to handle return struct value, init struct value and - // assign struct value from a function call, if anything - // changed in the pattern in future, we need to change all - // these places, just look for return_val_transformed. - bool return_val_transformed = false; - if (WN_operator(rhs_wn) == OPR_COMMA && - WN_rtype(rhs_wn) == MTYPE_M) { - WN *block = WN_kid0(rhs_wn); - WN *ldidTemp = WN_kid1(rhs_wn); - if (WN_operator(ldidTemp) == OPR_LDID && - WN_operator(block) == OPR_BLOCK) { - - // replace MSTID _temp_.Mreturn.1 - // with MSTID lhs - WN *stidTemp = WN_last(block); - if (WN_operator(stidTemp) == OPR_STID ) { - // remove block from the rhs_wn - WN_kid0(rhs_wn) = 0; - WN_DELETE_Tree(rhs_wn); - rhs_wn = block; - - WN *kid = WN_kid0(stidTemp); - WN_kid0(stidTemp) = 0; - WN_DELETE_FromBlock(block, stidTemp); - - WN *stid = WN_Stid (desc, - ST_ofst(st) + component_offset + lhs_preg_num, - st, hi_ty_idx, kid, field_id); - WN_INSERT_BlockLast(block, stid); - WGEN_Stmt_Append(block, Get_Srcpos()); - wn = block; - return_val_transformed = true; - } - } - } - if (!return_val_transformed) { - wn = WN_Stid (desc, ST_ofst(st) + component_offset + lhs_preg_num, st, - hi_ty_idx, rhs_wn, field_id); - WGEN_Stmt_Append(wn, Get_Srcpos()); - } + wn = WN_Stid (desc, ST_ofst(st) + component_offset + lhs_preg_num, st, + hi_ty_idx, rhs_wn, field_id); + WGEN_Stmt_Append(wn, Get_Srcpos()); #if defined(TARG_SL) if (need_append) { WN *ldid_wn; @@ -1930,66 +1888,30 @@ if (Current_Entry_WN() != NULL) { first_formal = WN_formal(Current_Entry_WN(), 0); } - // if return type is struct type, and the result is used in lhs, - // then the Mreturn temp variable is not needed, the address of lhs - // should be passed as hidden parameter - bool return_val_transformed = false; - if (WN_operator(rhs_wn) == OPR_COMMA && - WN_rtype(rhs_wn) == MTYPE_M) { - WN *block = WN_kid0(rhs_wn); - WN *ldidTemp = WN_kid1(rhs_wn); - if (WN_operator(ldidTemp) == OPR_LDID && - WN_operator(block) == OPR_BLOCK) { - - // replace MSTID _temp_.Mreturn.1 - // with MISTORE lhs - WN *stidTemp = WN_last(block); - if (WN_operator(stidTemp) == OPR_STID) { - // remove block from the rhs_wn - WN_kid0(rhs_wn) = 0; - WN_DELETE_Tree(rhs_wn); - rhs_wn = block; - - WN *kid = WN_kid0(stidTemp); - WN_kid0(stidTemp) = 0; - WN_DELETE_FromBlock(block, stidTemp); - - WN *istore = - WN_CreateIstore(OPR_ISTORE, MTYPE_V, desc, component_offset, - Make_Pointer_Type (hi_ty_idx, FALSE), - kid, addr_wn, field_id); - WN_INSERT_BlockLast(block, istore); - wn = block; - return_val_transformed = true; - } - } + if (TY_return_in_mem(hi_ty_idx) && + field_id == 0 && + // See if it is an indirect ref of the fake first parm. + // bug fix for OSP_314 + // + first_formal != NULL && (WN_operator(first_formal) != OPR_BLOCK) && + gs_tree_code(addr) == GS_VAR_DECL && + DECL_ST(addr) == WN_st(first_formal)) { + FmtAssert(TY_mtype(hi_ty_idx) == MTYPE_M, + ("WGEN_Lhs_Of_Modify_Expr: return_in_mem type not MTYPE_M")); + gs_t ptr_type = gs_tree_type(gs_tree_operand(lhs, 0)); + gs_t type = gs_tree_type(ptr_type); + FmtAssert(gs_tree_code(ptr_type) == GS_POINTER_TYPE, + ("WGEN_Lhs_Of_Modify_Expr: INDIRECT_REF opnd0 is not POINTER_TYPE")); + FmtAssert(component_offset == 0, + ("WGEN_Lhs_Of_Modify_Expr: component_offset nonzero")); + TY_IDX tidx = Get_TY(ptr_type); + // Check object has no copy constructor. + FmtAssert(!WGEN_has_copy_constructor(type), + ("WGEN_Lhs_Of_Modify_Expr: object needs copy constructor")); } - if (!return_val_transformed) { - if (TY_return_in_mem(hi_ty_idx) && - field_id == 0 && - // See if it is an indirect ref of the fake first parm. - // bug fix for OSP_314 - // - first_formal != NULL && (WN_operator(first_formal) != OPR_BLOCK) && - gs_tree_code(addr) == GS_VAR_DECL && - DECL_ST(addr) == WN_st(first_formal)) { - FmtAssert(TY_mtype(hi_ty_idx) == MTYPE_M, - ("WGEN_Lhs_Of_Modify_Expr: return_in_mem type not MTYPE_M")); - gs_t ptr_type = gs_tree_type(gs_tree_operand(lhs, 0)); - gs_t type = gs_tree_type(ptr_type); - FmtAssert(gs_tree_code(ptr_type) == GS_POINTER_TYPE, - ("WGEN_Lhs_Of_Modify_Expr: INDIRECT_REF opnd0 is not POINTER_TYPE")); - FmtAssert(component_offset == 0, - ("WGEN_Lhs_Of_Modify_Expr: component_offset nonzero")); - TY_IDX tidx = Get_TY(ptr_type); - // Check object has no copy constructor. - FmtAssert(!WGEN_has_copy_constructor(type), - ("WGEN_Lhs_Of_Modify_Expr: object needs copy constructor")); - } - wn = WN_CreateIstore(OPR_ISTORE, MTYPE_V, desc, component_offset, - Make_Pointer_Type (hi_ty_idx, FALSE), - rhs_wn, addr_wn, field_id); - } + wn = WN_CreateIstore(OPR_ISTORE, MTYPE_V, desc, component_offset, + Make_Pointer_Type (hi_ty_idx, FALSE), + rhs_wn, addr_wn, field_id); #ifdef TARG_SL /* so far I only handle *p++=... cases, change this case to * *p = ... ; ------------------------------------------------------------------------------ Why Cloud-Based Security and Archiving Make Sense Osterman Research conducted this study that outlines how and why cloud computing security and archiving is rapidly being adopted across the IT space for its ease of implementation, lower cost, and increased reliability. Learn more. http://www.accelacomm.com/jaw/sfnl/114/51425301/ _______________________________________________ Open64-devel mailing list Open64-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/open64-devel