00001 /* 00002 * Copyright 2003, 2004, 2005, 2006 PathScale, Inc. All Rights Reserved. 00003 */ 00004 00005 /* 00006 00007 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00008 00009 This program is free software; you can redistribute it and/or modify it 00010 under the terms of version 2 of the GNU General Public License as 00011 published by the Free Software Foundation. 00012 00013 This program is distributed in the hope that it would be useful, but 00014 WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 00017 Further, this software is distributed without any warranty that it is 00018 free of the rightful claim of any third person regarding infringement 00019 or the like. Any license provided herein, whether implied or 00020 otherwise, applies only to this software file. Patent licenses, if 00021 any, provided herein do not apply to combinations of this program with 00022 other software, or any other product whatsoever. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with this program; if not, write the Free Software Foundation, Inc., 59 00026 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00027 00028 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00029 Mountain View, CA 94043, or: 00030 00031 http://www.sgi.com 00032 00033 For further information regarding this notice, see: 00034 00035 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00036 00037 */ 00038 00039 00040 00041 /* -*-Mode: c++;-*- (Tell emacs to use c++ mode) */ 00042 // ==================================================================== 00043 // ==================================================================== 00044 // 00045 // Module: ipa_cg.cxx 00046 // 00047 // Revision history: 00048 // 19-Oct-94 - Original Version 00049 // 00050 // Description: 00051 // 00052 // Implementation of the callgraph used in IPA's analysis and 00053 // optimization phases. 00054 // 00055 // ==================================================================== 00056 // ==================================================================== 00057 00058 #define __STDC_LIMIT_MACROS 00059 #include <stdint.h> 00060 #if defined(BUILD_OS_DARWIN) 00061 #include <darwin_elf.h> 00062 #else /* defined(BUILD_OS_DARWIN) */ 00063 #include <elf.h> 00064 #endif /* defined(BUILD_OS_DARWIN) */ 00065 #include <sys/elf_whirl.h> 00066 #include <alloca.h> 00067 00068 #include <ext/hash_map> 00069 00070 #include <sys/types.h> 00071 00072 #include "defs.h" 00073 #include "erglob.h" // error message strings 00074 #include "mempool.h" // memory pools 00075 #include "cxx_memory.h" // CXX_NEW, etc. 00076 #include "wn.h" // whirl definitions 00077 #include "wn_util.h" // WN_ITER 00078 #include "pu_info.h" // PU_Info 00079 #include "ir_bread.h" // WN_get_section_base () 00080 #include "ipc_file.h" // file header defs. 00081 #include "ipc_symtab_merge.h" // Aux_XX_Tables 00082 #include "ipa_cg.h" 00083 #include "ipa_nested_pu.h" 00084 00085 typedef hash_map<PU_IDX, PU_IDX> IPA_NESTED_PU_PARENT_MAP; 00086 00087 static IPA_NESTED_PU_PARENT_MAP* nested_pu_parent_map; 00088 00089 static void 00090 Build_Parent_Child_Relations_For_One_Parent(PU_Info *parent) 00091 { 00092 PU_Info* child = PU_Info_child(parent); 00093 while (child) { 00094 (*nested_pu_parent_map)[ST_pu(St_Table[PU_Info_proc_sym(child)])] = 00095 ST_pu(St_Table[PU_Info_proc_sym(parent)]); 00096 PU_Info *grandchild = PU_Info_child(child); 00097 if (grandchild) 00098 Build_Parent_Child_Relations_For_One_Parent(child); 00099 00100 child = PU_Info_next(child); 00101 } 00102 } 00103 00104 static void 00105 Build_Parent_Child_Relations(IP_FILE_HDR& hdr) 00106 { 00107 PU_Info* parent = IP_FILE_HDR_pu_list(hdr); 00108 00109 while (parent) { 00110 Build_Parent_Child_Relations_For_One_Parent(parent); 00111 parent = PU_Info_next(parent); 00112 } 00113 } 00114 00115 IPA_NODE* 00116 Get_Parent_Of_Nested_PU(IPA_NODE* child) 00117 { 00118 if ((child->Lexical_Level()-1) == GLOBAL_SYMTAB) 00119 return NULL; 00120 00121 PU_IDX child_pu_idx = ST_pu(child->Func_ST()); 00122 PU_IDX parent_pu_idx = (*nested_pu_parent_map)[child_pu_idx]; 00123 00124 Is_True(parent_pu_idx > PU_IDX_ZERO && parent_pu_idx < PU_Table_Size(), 00125 ("Get_Parent_Of_Nested_PU: bad pu index %d, not in range 0 <= idx < %d", 00126 parent_pu_idx, PU_Table_Size())); 00127 00128 NODE_INDEX node_idx = AUX_PU_node(Aux_Pu_Table[parent_pu_idx]); 00129 IPA_NODE* result = IPA_Call_Graph->Graph()->Node_User(node_idx); 00130 00131 Is_True(result != NULL, ("Get_Parent_Of_Nested_PU: Bad parent IPA_NODE\n")); 00132 00133 return result; 00134 } 00135 00136 00137 void 00138 Build_Nested_Pu_Relations() 00139 { 00140 00141 if (nested_pu_parent_map == NULL) 00142 nested_pu_parent_map = CXX_NEW(IPA_NESTED_PU_PARENT_MAP(), Malloc_Mem_Pool); 00143 00144 for (UINT i = 0; i < IP_File_header.size(); ++i) { 00145 if (IP_FILE_HDR_has_nested_pu(IP_File_header[i])) 00146 Build_Parent_Child_Relations (IP_File_header[i]); 00147 } 00148 } 00149
1.5.6