@@ -210,34 +210,6 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
210
210
DISubprogram *SPClonedWithinModule =
211
211
CollectDebugInfoForCloning (*OldFunc, Changes, DIFinder);
212
212
213
- // Loop over all of the basic blocks in the function, cloning them as
214
- // appropriate. Note that we save BE this way in order to handle cloning of
215
- // recursive functions into themselves.
216
- for (const BasicBlock &BB : *OldFunc) {
217
-
218
- // Create a new basic block and copy instructions into it!
219
- BasicBlock *CBB = CloneBasicBlock (&BB, VMap, NameSuffix, NewFunc, CodeInfo);
220
-
221
- // Add basic block mapping.
222
- VMap[&BB] = CBB;
223
-
224
- // It is only legal to clone a function if a block address within that
225
- // function is never referenced outside of the function. Given that, we
226
- // want to map block addresses from the old function to block addresses in
227
- // the clone. (This is different from the generic ValueMapper
228
- // implementation, which generates an invalid blockaddress when
229
- // cloning a function.)
230
- if (BB.hasAddressTaken ()) {
231
- Constant *OldBBAddr = BlockAddress::get (const_cast <Function *>(OldFunc),
232
- const_cast <BasicBlock *>(&BB));
233
- VMap[OldBBAddr] = BlockAddress::get (NewFunc, CBB);
234
- }
235
-
236
- // Note return instructions for the caller.
237
- if (ReturnInst *RI = dyn_cast<ReturnInst>(CBB->getTerminator ()))
238
- Returns.push_back (RI);
239
- }
240
-
241
213
if (Changes < CloneFunctionChangeType::DifferentModule &&
242
214
DIFinder.subprogram_count () > 0 ) {
243
215
// Turn on module-level changes, since we need to clone (some of) the
@@ -289,6 +261,34 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
289
261
TypeMapper, Materializer));
290
262
}
291
263
264
+ // Loop over all of the basic blocks in the function, cloning them as
265
+ // appropriate. Note that we save BE this way in order to handle cloning of
266
+ // recursive functions into themselves.
267
+ for (const BasicBlock &BB : *OldFunc) {
268
+
269
+ // Create a new basic block and copy instructions into it!
270
+ BasicBlock *CBB = CloneBasicBlock (&BB, VMap, NameSuffix, NewFunc, CodeInfo);
271
+
272
+ // Add basic block mapping.
273
+ VMap[&BB] = CBB;
274
+
275
+ // It is only legal to clone a function if a block address within that
276
+ // function is never referenced outside of the function. Given that, we
277
+ // want to map block addresses from the old function to block addresses in
278
+ // the clone. (This is different from the generic ValueMapper
279
+ // implementation, which generates an invalid blockaddress when
280
+ // cloning a function.)
281
+ if (BB.hasAddressTaken ()) {
282
+ Constant *OldBBAddr = BlockAddress::get (const_cast <Function *>(OldFunc),
283
+ const_cast <BasicBlock *>(&BB));
284
+ VMap[OldBBAddr] = BlockAddress::get (NewFunc, CBB);
285
+ }
286
+
287
+ // Note return instructions for the caller.
288
+ if (ReturnInst *RI = dyn_cast<ReturnInst>(CBB->getTerminator ()))
289
+ Returns.push_back (RI);
290
+ }
291
+
292
292
// Loop over all of the instructions in the new function, fixing up operand
293
293
// references as we go. This uses VMap to do all the hard work.
294
294
for (Function::iterator
0 commit comments