llvm.org GIT mirror llvm / b7c4c99
This is a disgusting hack that improves code substantially, by making callgraphSCC passes more effective. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9384 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 15 years ago
1 changed file(s) with 122 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
4949 #include "llvm/iOther.h"
5050 #include "llvm/iTerminators.h"
5151 #include "Support/STLExtras.h"
52 #include
5352
5453 static RegisterAnalysis X("callgraph", "Call Graph Construction");
54
55 static const char * const KnownExternalFunctions[] = {
56 // Low-level system calls
57 "open",
58 "read",
59 "write",
60 "writev",
61 "lseek",
62 "poll",
63 "ioctl",
64
65 // Low-level stdc library functions
66 "abort",
67 "getenv",
68 "putenv",
69
70 // Standard IO functions
71 "printf",
72 "sprintf",
73 "fopen",
74 "freopen",
75 "fclose",
76 "fwrite",
77 "puts",
78 "fputs",
79 "getc",
80 "ungetc",
81 "putc",
82 "putchar",
83 "fread",
84 "fileno",
85 "ftell",
86 "fflush",
87 "fseek",
88 "fileno",
89 "ferror",
90 "feof",
91 "fdopen",
92 "__fxstat",
93 "setbuf",
94 "setbuffer",
95 "etlinebuf",
96 "setvbuf",
97
98 // Memory functions
99 "malloc",
100 "free",
101 "realloc",
102 "calloc",
103 "memalign",
104
105 // String functions
106 "atoi",
107 "memmove",
108 "memset",
109 "memchr",
110 "memcmp",
111 "strchr",
112 "strncpy",
113 "strncmp",
114 "strcmp",
115 "__strcoll_l",
116 "__strxfrm_l",
117 "__strftime_l",
118 "__strtol_l",
119 "__strtoul_l",
120 "__strtoll_l",
121 "__strtoull_l",
122 "__strtof_l",
123 "__strtod_l",
124 "__strtold_l",
125
126 // Locale functions
127 "__uselocale",
128 "__newlocale",
129 "__freelocale",
130 "__duplocale",
131 "__nl_langinfo_l",
132
133 // gettext functions used by libstdc++
134 "gettext",
135 "dgettext",
136 "dcgettext",
137 "textdomain",
138 "bindtextdomain",
139
140 // Random stuff
141 "__assert_fail",
142 "__errno_location",
143 };
144
145
146 /// ExternalFunctionDoesntCallIntoProgram - This hack is used to indicate to the
147 /// call graph that the specified external function is _KNOWN_ to not call back
148 /// into the program. This is important, because otherwise functions which call
149 /// "printf" for example, end up in a great big SCC that goes from the function
150 /// through main.
151 ///
152 static bool ExternalFunctionDoesntCallIntoProgram(const std::string &Name) {
153 static std::vector Funcs;
154
155 // First time this is called?
156 if (Funcs.empty()) {
157 // Add a whole bunch of functions which are often used...
158 Funcs.insert(Funcs.end(), KnownExternalFunctions,
159 KnownExternalFunctions+
160 sizeof(KnownExternalFunctions)/sizeof(KnownExternalFunctions[0]));
161 // Sort the list for efficient access
162 std::sort(Funcs.begin(), Funcs.end());
163 }
164
165 // Binary search for the function name...
166 std::vector::iterator I =
167 std::lower_bound(Funcs.begin(), Funcs.end(), Name);
168
169 // Found it?
170 return I != Funcs.end() && *I == Name;
171 }
172
173
55174
56175 // getNodeFor - Return the node for the specified function or create one if it
57176 // does not already exist.
85204
86205 // If this function is not defined in this translation unit, it could call
87206 // anything.
88 if (F->isExternal())
207 if (F->isExternal() && !F->getIntrinsicID() &&
208 !ExternalFunctionDoesntCallIntoProgram(F->getName()))
89209 Node->addCalledFunction(ExternalNode);
90210
91211 // Loop over all of the users of the function... looking for callers...