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 #define __STDC_LIMIT_MACROS
00053 #include <stdint.h>
00054 #include <alloca.h>
00055 #if defined(BUILD_OS_DARWIN)
00056 #include <darwin_elf.h>
00057 #else
00058 #include <elf.h>
00059 #endif
00060
00061 #include "defs.h"
00062 #include "wn.h"
00063 #include "cxx_memory.h"
00064 #define USE_DST_INTERNALS
00065 #include "dwarf_DST.h"
00066 #include "dwarf_DST_producer.h"
00067 #include "dwarf_DST_mem.h"
00068 #include "pu_info.h"
00069 #include "ipc_file.h"
00070 #include "ipc_bread.h"
00071 #include "ipc_symtab_merge.h"
00072 #include "config_ipa.h"
00073 #include "ipa_cg.h"
00074 #include "clone_DST_utils.h"
00075 #include "ipo_defs.h"
00076
00077 #include "ipo_clone.h"
00078
00079
00080
00081
00082
00083
00084 void
00085 IPO_Clone (IPA_NODE* orig_node, IPA_NODE* clone_node)
00086 {
00087 IP_FILE_HDR& file_hdr = orig_node->File_Header();
00088
00089 ST* orig_st = orig_node->Func_ST();
00090
00091
00092 PU_IDX clone_pu_idx;
00093 PU& clone_pu = New_PU (clone_pu_idx);
00094 Pu_Table[clone_pu_idx] = Pu_Table[ST_pu(orig_st)];
00095
00096
00097 UINT32 clone_aux_idx;
00098 AUX_PU& clone_aux_pu = Aux_Pu_Table.New_entry (clone_aux_idx);
00099 Set_AUX_PU_node (clone_aux_pu, clone_node->Node_Index());
00100 Set_AUX_PU_file_hdr (clone_aux_pu, &file_hdr);
00101
00102 Is_True (clone_aux_idx == clone_pu_idx,
00103 ("IPO_Clone: Aux_Pu_Table index (%u) != Pu_Table index (%u)",
00104 clone_aux_idx, clone_pu_idx));
00105
00106
00107 IPA_CLONE_ARRAY* clone_array = IPA_Call_Graph->Clone_Array (orig_node);
00108 Is_True (clone_array,
00109 ("IPO_CLONE: clone_array for node %s is NULL", ST_name(orig_st)));
00110
00111 INT32 clone_num;
00112 for (clone_num = 0; clone_num < clone_array->Elements(); ++clone_num) {
00113 if ((*clone_array)[clone_num] == clone_node) {
00114 break;
00115 }
00116 }
00117 Is_True(clone_num < clone_array->Elements(),
00118 ("IPO_CLONE: clone_node not found in clone_array for node %s",
00119 ST_name(orig_st)));
00120
00121
00122 char* clone_name = (char*) alloca(strlen(orig_node->Name())+15);
00123 sprintf(clone_name, "%s..clone..%u", ST_name(orig_st), clone_num);
00124 ST* clone_st = New_ST (ST_level(orig_st));
00125 ST_Init (clone_st,
00126 Save_Str(clone_name),
00127 CLASS_FUNC,
00128 SCLASS_TEXT,
00129 ST_export(orig_st),
00130 clone_pu_idx);
00131
00132 clone_node->Set_Func_ST (clone_st);
00133
00134
00135 PU_Info* clone_pu_info = IP_FILE_HDR_Add_New_PU (file_hdr);
00136 clone_node->Set_Proc_Info_Index (IP_FILE_HDR_num_procs(file_hdr)-1);
00137
00138 IPO_CLONE clone (orig_node->Whirl_Tree(),
00139 orig_node->Scope(),
00140 orig_node->Lexical_Level(),
00141 orig_node->Map_Table(),
00142 clone_node->Mem_Pool(),
00143 clone_node->Mem_Pool());
00144
00145 #if 0
00146
00147 IP_READ_file_info (orig_node->File_Header());
00148 #endif
00149
00150
00151 MEM_POOL* save_pu_pool_ptr = MEM_pu_pool_ptr;
00152 MEM_POOL* save_wn_pool_ptr = WN_mem_pool_ptr;
00153
00154
00155 MEM_pu_pool_ptr = clone_node->Mem_Pool();
00156 WN_mem_pool_ptr = clone_node->Mem_Pool();
00157
00158
00159 clone.New_Clone (clone_st);
00160
00161 clone_node->Set_Scope (clone.Get_Cloned_Symtab());
00162 clone_node->Set_Whirl_Tree (clone.Get_Cloned_PU());
00163 clone_node->Set_Parent_Map (clone.Get_parent_map ());
00164
00165 clone_node->Scope()[orig_node->Lexical_Level()].st = clone_st;
00166
00167
00168 Set_PU_Info_tree_ptr (clone_pu_info, clone.Get_Cloned_PU());
00169 PU_Info_maptab (clone_pu_info) = clone.Get_Cloned_maptab ();
00170 PU_Info_proc_sym (clone_pu_info) = ST_st_idx (clone_st);
00171
00172 Set_PU_Info_state (clone_pu_info, WT_TREE, Subsect_InMem);
00173 Set_PU_Info_state (clone_pu_info, WT_SYMTAB, Subsect_InMem);
00174 Set_PU_Info_state (clone_pu_info, WT_PROC_SYM, Subsect_InMem);
00175
00176
00177 #ifdef KEY
00178 if (orig_node->Has_Feedback () && clone_node->Has_Feedback ())
00179 {
00180 IP_PROC_INFO& info = IP_FILE_HDR_proc_info (file_hdr)[orig_node->Proc_Info_Index()];
00181 const PU_Info * pu = IP_PROC_INFO_pu_info (info);
00182 const Pu_Hdr* orig_fb = (const Pu_Hdr*) PU_Info_feedback_ptr (pu);
00183 FEEDBACK * fb = CXX_NEW (FEEDBACK (PU_Info_tree_ptr (clone_pu_info),
00184 clone_node->Mem_Pool(),
00185 orig_fb->pu_num_inv_entries,
00186 orig_fb->pu_num_br_entries,
00187 orig_fb->pu_num_loop_entries,
00188 orig_fb->pu_num_scircuit_entries,
00189 orig_fb->pu_num_call_entries,
00190 orig_fb->pu_num_icall_entries,
00191 orig_fb->pu_num_switch_entries,
00192 orig_fb->pu_num_value_entries,
00193 orig_fb->pu_num_value_fp_bin_entries,
00194 orig_fb->runtime_fun_address),
00195 clone_node->Mem_Pool());
00196 clone_node->Set_Feedback_Info (fb);
00197
00198
00199
00200 FB_FREQ orig_freq = orig_node->Has_frequency() ?
00201 orig_node->Get_frequency() : FB_FREQ_UNKNOWN;
00202 FB_FREQ clone_freq (0.0, TRUE);
00203 IPA_PRED_ITER preds (IPA_Call_Graph, clone_node);
00204 for (preds.First(); !preds.Is_Empty(); preds.Next())
00205 {
00206 IPA_EDGE * e = preds.Current_Edge();
00207 if (e && e->Has_frequency())
00208 clone_freq += e->Get_frequency();
00209 }
00210 FB_IPA_Clone(orig_node->Feedback_Info(), clone_node->Feedback_Info(),
00211 orig_node->Whirl_Tree (FALSE), clone.Get_Cloned_PU(),
00212 clone_freq/orig_freq);
00213 }
00214 #endif
00215
00216 DST_IDX clone_dst = DST_INVALID_IDX;
00217
00218
00219 Set_FILE_INFO_has_inlines(File_info);
00220 clone_dst = DST_enter_cloned_subroutine (DST_get_compile_unit(),
00221 orig_node->Dst_Index(),
00222 clone.Get_Func_ST(),
00223 orig_node->File_Dst(),
00224 clone.Get_sym());
00225 Set_PU_Info_pu_dst (clone_pu_info, clone_dst);
00226
00227
00228 MEM_pu_pool_ptr = save_pu_pool_ptr;
00229 WN_mem_pool_ptr = save_wn_pool_ptr;
00230
00231 }
00232
00233
00234
00235
00236
00237 WN *
00238 IPO_Copy_Tree (WN *wn)
00239 {
00240 extern WN_MAP Parent_Map;
00241
00242 IPO_CLONE copy (Current_Map_Tab, Current_Map_Tab, Parent_Map);
00243
00244 WN* result = copy.Clone_Tree (wn);
00245
00246 return result;
00247 }
00248
00249
00250
00251
00252
00253
00254 CLONED_NODE::CLONED_NODE(ST* orig, ST* copy) : _st(orig), _copy_st(copy)
00255 {
00256 }
00257
00258
00259
00260
00261 void
00262 CLONED_LIST::Append(ST* orig_st, ST* copy_st, MEM_POOL *m)
00263 {
00264
00265 CLONED_NODE *clone_node;
00266
00267 clone_node = (CLONED_NODE*)CXX_NEW(CLONED_NODE(orig_st, copy_st),
00268 m);
00269
00270 SLIST::Append((SLIST_NODE*)clone_node);
00271 }
00272
00273
00274
00275
00276 ST*
00277 CLONED_LIST::Lookup(ST* orig_st)
00278 {
00279 CLONED_LIST_ITER list_iter(this);
00280 for (list_iter.First(); !list_iter.Is_Empty();
00281 list_iter.Next())
00282 {
00283 CLONED_NODE *tmp = list_iter.Cur();
00284 if (tmp->Get_orig_st() == orig_st)
00285 return tmp->Get_copy_st();
00286 }
00287 return NULL;
00288 }
00289
00290 #if (!defined(_STANDALONE_INLINER) && !defined(_LIGHTWEIGHT_INLINER))
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 extern void
00301 Clone_update_st(WN *w, ST_IDX s, SYMTAB_IDX callee_sym_idx,
00302 MEM_POOL*m,
00303 IPA_NODE *callee)
00304 {
00305 IPO_SYMTAB *symtab;
00306
00307 MEM_POOL_Push (m);
00308
00309 symtab = (IPO_SYMTAB*) CXX_NEW (IPO_SYMTAB (callee->Scope(), callee_sym_idx, m), m);
00310
00311 ST *cp = symtab->Get_Cloned_ST (ST_ptr(s));
00312 WN_st_idx(w) = ST_st_idx(cp);
00313
00314 MEM_POOL_Pop (m);
00315
00316 }
00317
00318 #endif