@@ -168,9 +168,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
168
168
// Loop over all of the basic blocks in the function, cloning them as
169
169
// appropriate. Note that we save BE this way in order to handle cloning of
170
170
// recursive functions into themselves.
171
- for (Function::const_iterator BI = OldFunc->begin (), BE = OldFunc->end ();
172
- BI != BE; ++BI) {
173
- const BasicBlock &BB = *BI;
171
+ for (const BasicBlock &BB : *OldFunc) {
174
172
175
173
// Create a new basic block and copy instructions into it!
176
174
BasicBlock *CBB = CloneBasicBlock (&BB, VMap, NameSuffix, NewFunc, CodeInfo,
@@ -225,17 +223,15 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
225
223
" Subprogram should be in DIFinder->subprogram_count()..." );
226
224
}
227
225
226
+ const auto RemapFlag = ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges;
228
227
// Duplicate the metadata that is attached to the cloned function.
229
228
// Subprograms/CUs/types that were already mapped to themselves won't be
230
229
// duplicated.
231
230
SmallVector<std::pair<unsigned , MDNode *>, 1 > MDs;
232
231
OldFunc->getAllMetadata (MDs);
233
232
for (auto MD : MDs) {
234
- NewFunc->addMetadata (
235
- MD.first ,
236
- *MapMetadata (MD.second , VMap,
237
- ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
238
- TypeMapper, Materializer));
233
+ NewFunc->addMetadata (MD.first , *MapMetadata (MD.second , VMap, RemapFlag,
234
+ TypeMapper, Materializer));
239
235
}
240
236
241
237
// Loop over all of the instructions in the function, fixing up operand
@@ -246,9 +242,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
246
242
BB != BE; ++BB)
247
243
// Loop over all instructions, fixing each one as we find it...
248
244
for (Instruction &II : *BB)
249
- RemapInstruction (&II, VMap,
250
- ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
251
- TypeMapper, Materializer);
245
+ RemapInstruction (&II, VMap, RemapFlag, TypeMapper, Materializer);
252
246
253
247
// Only update !llvm.dbg.cu for DifferentModule (not CloneModule). In the
254
248
// same module, the compile unit will already be listed (or not). When
0 commit comments