Skip to content

Commit ab44ec1

Browse files
committed
[NFC] Minor refactor
- Give unwieldy repeated expression a name - Use a ranged `for` basic block iterator Reviewed by: nikic, dexonsmith Differential Revisision: https://reviews.llvm.org/D98957
1 parent 0448ddd commit ab44ec1

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

llvm/lib/Transforms/Utils/CloneFunction.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
168168
// Loop over all of the basic blocks in the function, cloning them as
169169
// appropriate. Note that we save BE this way in order to handle cloning of
170170
// 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) {
174172

175173
// Create a new basic block and copy instructions into it!
176174
BasicBlock *CBB = CloneBasicBlock(&BB, VMap, NameSuffix, NewFunc, CodeInfo,
@@ -225,17 +223,15 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
225223
"Subprogram should be in DIFinder->subprogram_count()...");
226224
}
227225

226+
const auto RemapFlag = ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges;
228227
// Duplicate the metadata that is attached to the cloned function.
229228
// Subprograms/CUs/types that were already mapped to themselves won't be
230229
// duplicated.
231230
SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
232231
OldFunc->getAllMetadata(MDs);
233232
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));
239235
}
240236

241237
// Loop over all of the instructions in the function, fixing up operand
@@ -246,9 +242,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
246242
BB != BE; ++BB)
247243
// Loop over all instructions, fixing each one as we find it...
248244
for (Instruction &II : *BB)
249-
RemapInstruction(&II, VMap,
250-
ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
251-
TypeMapper, Materializer);
245+
RemapInstruction(&II, VMap, RemapFlag, TypeMapper, Materializer);
252246

253247
// Only update !llvm.dbg.cu for DifferentModule (not CloneModule). In the
254248
// same module, the compile unit will already be listed (or not). When

0 commit comments

Comments
 (0)