Mercurial > projects > ldc
comparison gen/passes/SimplifyDRuntimeCalls.cpp @ 1286:23b23b74e326
Remove calls to some runtime functions if their results are unused
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sat, 02 May 2009 11:58:50 +0200 |
parents | bedf0bfb8fdb |
children | c32e27f9a61d |
comparison
equal
deleted
inserted
replaced
1285:91d9386d4a5a | 1286:23b23b74e326 |
---|---|
143 } | 143 } |
144 return 0; | 144 return 0; |
145 } | 145 } |
146 }; | 146 }; |
147 | 147 |
148 /// DeleteUnusedOpt - remove libcall if the return value is unused. | |
149 struct VISIBILITY_HIDDEN DeleteUnusedOpt : public LibCallOptimization { | |
150 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { | |
151 if (CI->use_empty()) | |
152 return CI; | |
153 return 0; | |
154 } | |
155 }; | |
156 | |
148 // TODO: More optimizations! :) | 157 // TODO: More optimizations! :) |
149 | 158 |
150 } // end anonymous namespace. | 159 } // end anonymous namespace. |
151 | 160 |
152 //===----------------------------------------------------------------------===// | 161 //===----------------------------------------------------------------------===// |
161 | 170 |
162 // Array operations | 171 // Array operations |
163 ArraySetLengthOpt ArraySetLength; | 172 ArraySetLengthOpt ArraySetLength; |
164 ArrayCastLenOpt ArrayCastLen; | 173 ArrayCastLenOpt ArrayCastLen; |
165 | 174 |
175 // GC allocations | |
176 DeleteUnusedOpt DeleteUnused; | |
177 | |
166 public: | 178 public: |
167 static char ID; // Pass identification | 179 static char ID; // Pass identification |
168 SimplifyDRuntimeCalls() : FunctionPass(&ID) {} | 180 SimplifyDRuntimeCalls() : FunctionPass(&ID) {} |
169 | 181 |
170 void InitOptimizations(); | 182 void InitOptimizations(); |
186 } | 198 } |
187 | 199 |
188 /// Optimizations - Populate the Optimizations map with all the optimizations | 200 /// Optimizations - Populate the Optimizations map with all the optimizations |
189 /// we know. | 201 /// we know. |
190 void SimplifyDRuntimeCalls::InitOptimizations() { | 202 void SimplifyDRuntimeCalls::InitOptimizations() { |
203 // Some array-related optimizations | |
191 Optimizations["_d_arraysetlengthT"] = &ArraySetLength; | 204 Optimizations["_d_arraysetlengthT"] = &ArraySetLength; |
192 Optimizations["_d_arraysetlengthiT"] = &ArraySetLength; | 205 Optimizations["_d_arraysetlengthiT"] = &ArraySetLength; |
193 Optimizations["_d_array_cast_len"] = &ArrayCastLen; | 206 Optimizations["_d_array_cast_len"] = &ArrayCastLen; |
207 | |
208 /* Delete calls to runtime functions which aren't needed if their result is | |
209 * unused. That comes down to functions that don't do anything but | |
210 * GC-allocate and initialize some memory. | |
211 * We don't need to do this for functions which are marked 'readnone' or | |
212 * 'readonly', since LLVM doesn't need our help figuring out when those can | |
213 * be deleted. | |
214 * (We can't mark allocating calls as readonly/readnone because they don't | |
215 * return the same pointer every time when called with the same arguments) | |
216 */ | |
217 Optimizations["_d_allocmemoryT"] = &DeleteUnused; | |
218 Optimizations["_d_newarrayT"] = &DeleteUnused; | |
219 Optimizations["_d_newarrayiT"] = &DeleteUnused; | |
220 Optimizations["_d_newarrayvT"] = &DeleteUnused; | |
221 Optimizations["_d_newarraymT"] = &DeleteUnused; | |
222 Optimizations["_d_newarraymiT"] = &DeleteUnused; | |
223 Optimizations["_d_newarraymvT"] = &DeleteUnused; | |
224 Optimizations["_d_allocclass"] = &DeleteUnused; | |
194 } | 225 } |
195 | 226 |
196 | 227 |
197 /// runOnFunction - Top level algorithm. | 228 /// runOnFunction - Top level algorithm. |
198 /// | 229 /// |