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 #include "defs.h"
00049 #include "tracing.h"
00050 #include "errors.h"
00051 #include "wn.h"
00052 #include "mempool.h"
00053 #include "bb.h"
00054 #include "op.h"
00055 #include "tn.h"
00056 #include "cg.h"
00057 #include "cgtarget.h"
00058 #include "reg_live.h"
00059
00060 static BOOL tracing = FALSE;
00061 #define Trace(msg) if (tracing) fprintf(TFile, msg "\n");
00062
00063 static MEM_POOL tn_copy_pool;
00064 static TN_MAP tn_copy_src_op;
00065
00066 void
00067 Optimize_Copy_Usage (void)
00068 {
00069 BB *bb;
00070 OP *op;
00071 OP *copy_op;
00072 OP *def_op;
00073 TN *tn;
00074 TN *copy_tn;
00075
00076 tracing = Get_Trace(TP_EBO, 0x800);
00077 MEM_POOL_Initialize (&tn_copy_pool, "tn_copy_pool", FALSE);
00078 MEM_POOL_Push(&tn_copy_pool);
00079 tn_copy_src_op = TN_MAP_Create();
00080
00081 for (bb = REGION_First_BB; bb != NULL; bb = BB_next(bb)) {
00082 FOR_ALL_BB_OPs (bb, op) {
00083 if (OP_copy(op)) {
00084
00085
00086
00087 TN_MAP_Set (tn_copy_src_op, OP_opnd(op,0), op);
00088 continue;
00089 }
00090 for (INT i = 0; i < OP_opnds(op); ++i) {
00091 tn = OP_opnd(op,i);
00092 if (!TN_is_register(tn))
00093 continue;
00094 copy_op = (OP*) TN_MAP_Get (tn_copy_src_op, tn);
00095 if (copy_op && tn == OP_opnd(copy_op,0)) {
00096
00097 copy_tn = OP_result(copy_op,0);
00098 def_op = Find_Reaching_Def (copy_tn, op);
00099 if (def_op == copy_op) {
00100
00101 def_op = Find_Reaching_Def (tn, op);
00102 if (def_op && def_op == Find_Reaching_Def (tn, copy_op)) {
00103
00104 DevWarn("found src copy of tn%d in BB%d, replace with TN%d", TN_number(tn), BB_id(bb), TN_number(copy_tn));
00105 Set_OP_opnd(op,i, copy_tn);
00106 }
00107 }
00108 }
00109 }
00110 }
00111 }
00112
00113 tn_copy_src_op = TN_MAP_Create();
00114 TN_MAP_Delete (tn_copy_src_op);
00115 MEM_POOL_Pop(&tn_copy_pool);
00116 MEM_POOL_Delete (&tn_copy_pool);
00117 }
00118