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