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 // ==================================================================== 00042 // 00043 // Module: ipa_feedback.cxx 00044 // 00045 // Revision history: 00046 // 03-Sep-97 - Original Version 00047 // 00048 // Description: 00049 // 00050 // Create an output file(s) containing useful information derived during 00051 // various phases of Interprocedural Analysis. These files contain very 00052 // helpful IPA-derived info such as: 00053 // 00054 // o global variable and function names whose access can be optimized 00055 // via compiler directives (e.g. #pragma section_gp, #pragma hidden, 00056 // #pragma internal, #pragma inline, #pragma noinline ). 00057 // 00058 // o names of functions that IPA analysis found to be 'dead' ( but not 00059 // due to inlining ). Such functions are never called or they are 00060 // called within other functions which are in turn never called, etc 00061 // 00062 // o names of global variables that IPA analysis found to be unused, 00063 // e.g. written but not read, etc. 00064 // 00065 // ==================================================================== 00066 // ==================================================================== 00067 00068 00069 #include "defs.h" 00070 #include "cxx_memory.h" 00071 #include "cxx_hash.h" 00072 #include "erglob.h" 00073 #include "glob.h" 00074 #include "mempool.h" 00075 #include "tracing.h" 00076 #include "strtab.h" 00077 #include "stab.h" 00078 #include "ipa_feedback.h" 00079 00080 extern IPA_FEEDBACK_STRINGS *IPA_Fbk_Strings; 00081 00082 // Wrapper routine to allow C programs in ipa/common to access string hashing 00083 extern "C" INT32 C_Emit_id_string( const char *name ); 00084 00085 00086 // ==================================================================== 00087 // 00088 // Hash table for strings in the feedback string table. 00089 // 00090 // ==================================================================== 00091 00092 // We avoid all duplicates: 00093 typedef class USER_HASH_TABLE < char*, INT32, String_Hash, String_Equal > 00094 IPA_FEEDBACK_HASH_TBL; 00095 IPA_FEEDBACK_HASH_TBL *IPA_Feedback_Hash_Tbl; 00096 00097 // ==================================================================== 00098 // 00099 // IPA_FEEDBACK_STRINGS::IPA_FEEDBACK_STRINGS 00100 // 00101 // Constructor: Initialize to reflect a new string pool 00102 // 00103 // ==================================================================== 00104 00105 IPA_FEEDBACK_STRINGS::IPA_FEEDBACK_STRINGS ( MEM_POOL* str_pool ) 00106 { 00107 _str_pool_max = FBK_STR_POOL_INIT_SIZE; 00108 _str_pool_size = 0; 00109 _str_pool = str_pool; 00110 _str_pool_base = MEM_POOL_Alloc ( _str_pool, 00111 sizeof(char)*FBK_STR_POOL_INIT_SIZE ); 00112 if( _str_pool_base == NULL ) { 00113 ErrMsg ( EC_No_Mem, "IPA Feedback string pool unavail" ); 00114 } 00115 } 00116 00117 // ==================================================================== 00118 // 00119 // IPA_FEEDBACK_HASHES::IPA_FEEDBACK_HASHES 00120 // 00121 // Constructor: Initialize to reflect a string hash table 00122 // 00123 // ==================================================================== 00124 00125 IPA_FEEDBACK_HASHES::IPA_FEEDBACK_HASHES ( MEM_POOL* str_hash_tbl ) 00126 { 00127 // Initialize the string hash table: 00128 00129 IPA_Feedback_Hash_Tbl = 00130 CXX_NEW ( IPA_FEEDBACK_HASH_TBL ( FBK_HASH_TAB_SIZE, str_hash_tbl ), 00131 str_hash_tbl ); 00132 } 00133 00134 // ==================================================================== 00135 // 00136 // IPA_FEEDBACK_STRINGS::Add_string 00137 // 00138 // Add a string to an IPA feedback string pool. The string has been 00139 // previously checked for duplication. 00140 // 00141 // ==================================================================== 00142 00143 INT32 00144 IPA_FEEDBACK_STRINGS::Add_id_string ( const char *s ) 00145 { 00146 INT32 len = strlen(s); 00147 INT32 loc; 00148 00149 // Expand the string pool if required 00150 00151 if ( _str_pool_size == 0 ) _str_pool_size = 1; 00152 if ( _str_pool_max <= _str_pool_size + len+1 ) { 00153 _str_pool_base = MEM_POOL_Realloc ( _str_pool, _str_pool_base, 00154 sizeof(char)*_str_pool_max, 00155 sizeof(char)*(_str_pool_size + len+1+FBK_STR_POOL_INIT_SIZE) ); 00156 if ( _str_pool_base == NULL ) { 00157 ErrMsg ( EC_No_Mem, "IPA Feedback string pool realloc fails " ); 00158 } 00159 _str_pool_max = _str_pool_size + len+1+FBK_STR_POOL_INIT_SIZE; 00160 } 00161 00162 // Add the new string: 00163 strcpy ( ((char *)_str_pool_base)+_str_pool_size, s ); 00164 loc = _str_pool_size; 00165 _str_pool_size += len+1; 00166 00167 return loc; 00168 } 00169 00170 // ==================================================================== 00171 // 00172 // IPA_FEEDBACK_STRINGS::Emit_id_string 00173 // 00174 // Emit a name to an IPA feedback string pool and returns its index. 00175 // A hash table (above) is used to avoid any duplication. 00176 // 00177 // WARNING: The hash table implementation used stores the string 00178 // pointer as the key rather than the string itself. So the name 00179 // entered must not be a string which will be overwritten before being 00180 // done with the hash table. 00181 // 00182 // ==================================================================== 00183 00184 INT32 00185 IPA_FEEDBACK_STRINGS::Emit_id_string ( const char *name ) 00186 { 00187 // check 1st for duplicate and recycle index if found 00188 INT32 index = IPA_Feedback_Hash_Tbl->Find ( (char *)name ); 00189 00190 if ( index == 0 ) { 00191 // no duplicate found - add a new string 00192 index = IPA_FEEDBACK_STRINGS::Add_id_string ( (char *)name ); 00193 IPA_Feedback_Hash_Tbl->Enter ( (char *)name, index ); 00194 return index; 00195 } 00196 else { 00197 return -index; 00198 } 00199 } 00200 00201 // ==================================================================== 00202 // 00203 // C_Emit_id_string 00204 // 00205 // A wrapper routine to allow the C programs in /common portion of ipa 00206 // source tree to call the string hashing mechanisms to eliminate dups. 00207 // 00208 // WARNING: The hash table implementation used stores the string 00209 // pointer as the key rather than the string itself. So the name 00210 // entered must not be a string which will be overwritten before being 00211 // done with the hash table. Separate phases of IPA do free up memory so 00212 // this is a problem if trying to extend hash tables/string pools across 00213 // phases. 00214 // 00215 // ==================================================================== 00216 #ifdef TODO 00217 00218 INT32 00219 C_Emit_id_string ( const char *name ) 00220 { 00221 return ( IPA_Fbk_Strings->Emit_id_string( name ) ); 00222 } 00223 00224 #endif
1.5.6