@@ -72,7 +72,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,
72
72
}
73
73
74
74
if (CodeInfo) {
75
- CodeInfo->ContainsCalls |= hasCalls;
75
+ CodeInfo->ContainsCalls |= hasCalls;
76
76
CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas;
77
77
}
78
78
return NewBB;
@@ -184,8 +184,8 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
184
184
// implementation, which generates an invalid blockaddress when
185
185
// cloning a function.)
186
186
if (BB.hasAddressTaken ()) {
187
- Constant *OldBBAddr = BlockAddress::get (const_cast <Function*>(OldFunc),
188
- const_cast <BasicBlock*>(&BB));
187
+ Constant *OldBBAddr = BlockAddress::get (const_cast <Function *>(OldFunc),
188
+ const_cast <BasicBlock *>(&BB));
189
189
VMap[OldBBAddr] = BlockAddress::get (NewFunc, CBB);
190
190
}
191
191
@@ -234,11 +234,11 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
234
234
TypeMapper, Materializer));
235
235
}
236
236
237
- // Loop over all of the instructions in the function, fixing up operand
238
- // references as we go. This uses VMap to do all the hard work.
239
- for (Function::iterator BB =
240
- cast<BasicBlock>(VMap[&OldFunc->front ()])->getIterator (),
241
- BE = NewFunc->end ();
237
+ // Loop over all of the instructions in the new function, fixing up operand
238
+ // references as we go. This uses VMap to do all the hard work.
239
+ for (Function::iterator
240
+ BB = cast<BasicBlock>(VMap[&OldFunc->front ()])->getIterator (),
241
+ BE = NewFunc->end ();
242
242
BB != BE; ++BB)
243
243
// Loop over all instructions, fixing each one as we find it...
244
244
for (Instruction &II : *BB)
@@ -260,7 +260,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
260
260
// visiting the metadata attached to global values, which would allow this
261
261
// code to be deleted. Alternatively, perhaps give responsibility for this
262
262
// update to CloneFunctionInto's callers.
263
- auto * NewModule = NewFunc->getParent ();
263
+ auto * NewModule = NewFunc->getParent ();
264
264
auto *NMD = NewModule->getOrInsertNamedMetadata (" llvm.dbg.cu" );
265
265
// Avoid multiple insertions of the same DICompileUnit to NMD.
266
266
SmallPtrSet<const void *, 8 > Visited;
@@ -283,7 +283,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
283
283
// /
284
284
Function *llvm::CloneFunction (Function *F, ValueToValueMapTy &VMap,
285
285
ClonedCodeInfo *CodeInfo) {
286
- std::vector<Type*> ArgTypes;
286
+ std::vector<Type *> ArgTypes;
287
287
288
288
// The user might be deleting arguments to the function by specifying them in
289
289
// the VMap. If so, we need to not add the arguments to the arg ty vector
@@ -293,70 +293,70 @@ Function *llvm::CloneFunction(Function *F, ValueToValueMapTy &VMap,
293
293
ArgTypes.push_back (I.getType ());
294
294
295
295
// Create a new function type...
296
- FunctionType *FTy = FunctionType::get (F->getFunctionType ()->getReturnType (),
297
- ArgTypes, F->getFunctionType ()->isVarArg ());
296
+ FunctionType *FTy =
297
+ FunctionType::get (F->getFunctionType ()->getReturnType (), ArgTypes,
298
+ F->getFunctionType ()->isVarArg ());
298
299
299
300
// Create the new function...
300
301
Function *NewF = Function::Create (FTy, F->getLinkage (), F->getAddressSpace (),
301
302
F->getName (), F->getParent ());
302
303
303
304
// Loop over the arguments, copying the names of the mapped arguments over...
304
305
Function::arg_iterator DestI = NewF->arg_begin ();
305
- for (const Argument & I : F->args ())
306
+ for (const Argument &I : F->args ())
306
307
if (VMap.count (&I) == 0 ) { // Is this argument preserved?
307
308
DestI->setName (I.getName ()); // Copy the name over...
308
309
VMap[&I] = &*DestI++; // Add mapping to VMap
309
310
}
310
311
311
- SmallVector<ReturnInst*, 8 > Returns; // Ignore returns cloned.
312
+ SmallVector<ReturnInst *, 8 > Returns; // Ignore returns cloned.
312
313
CloneFunctionInto (NewF, F, VMap, CloneFunctionChangeType::LocalChangesOnly,
313
314
Returns, " " , CodeInfo);
314
315
315
316
return NewF;
316
317
}
317
318
318
-
319
-
320
319
namespace {
321
- // / This is a private class used to implement CloneAndPruneFunctionInto.
322
- struct PruningFunctionCloner {
323
- Function *NewFunc;
324
- const Function *OldFunc;
325
- ValueToValueMapTy &VMap;
326
- bool ModuleLevelChanges;
327
- const char *NameSuffix;
328
- ClonedCodeInfo *CodeInfo;
329
-
330
- public:
331
- PruningFunctionCloner (Function *newFunc, const Function *oldFunc,
332
- ValueToValueMapTy &valueMap, bool moduleLevelChanges,
333
- const char *nameSuffix, ClonedCodeInfo *codeInfo)
334
- : NewFunc(newFunc), OldFunc(oldFunc), VMap(valueMap),
335
- ModuleLevelChanges (moduleLevelChanges), NameSuffix(nameSuffix),
336
- CodeInfo(codeInfo) {}
337
-
338
- // / The specified block is found to be reachable, clone it and
339
- // / anything that it can reach.
340
- void CloneBlock (const BasicBlock *BB,
341
- BasicBlock::const_iterator StartingInst,
342
- std::vector<const BasicBlock*> &ToClone);
343
- };
344
- }
320
+ // / This is a private class used to implement CloneAndPruneFunctionInto.
321
+ struct PruningFunctionCloner {
322
+ Function *NewFunc;
323
+ const Function *OldFunc;
324
+ ValueToValueMapTy &VMap;
325
+ bool ModuleLevelChanges;
326
+ const char *NameSuffix;
327
+ ClonedCodeInfo *CodeInfo;
328
+
329
+ public:
330
+ PruningFunctionCloner (Function *newFunc, const Function *oldFunc,
331
+ ValueToValueMapTy &valueMap, bool moduleLevelChanges,
332
+ const char *nameSuffix, ClonedCodeInfo *codeInfo)
333
+ : NewFunc(newFunc), OldFunc(oldFunc), VMap(valueMap),
334
+ ModuleLevelChanges (moduleLevelChanges), NameSuffix(nameSuffix),
335
+ CodeInfo(codeInfo) {}
336
+
337
+ // / The specified block is found to be reachable, clone it and
338
+ // / anything that it can reach.
339
+ void CloneBlock (const BasicBlock *BB, BasicBlock::const_iterator StartingInst,
340
+ std::vector<const BasicBlock *> &ToClone);
341
+ };
342
+ } // namespace
345
343
346
344
// / The specified block is found to be reachable, clone it and
347
345
// / anything that it can reach.
348
- void PruningFunctionCloner::CloneBlock (const BasicBlock *BB,
349
- BasicBlock::const_iterator StartingInst,
350
- std::vector<const BasicBlock*> &ToClone){
346
+ void PruningFunctionCloner::CloneBlock (
347
+ const BasicBlock *BB, BasicBlock::const_iterator StartingInst,
348
+ std::vector<const BasicBlock *> &ToClone) {
351
349
WeakTrackingVH &BBEntry = VMap[BB];
352
350
353
351
// Have we already cloned this block?
354
- if (BBEntry) return ;
352
+ if (BBEntry)
353
+ return ;
355
354
356
355
// Nope, clone it now.
357
356
BasicBlock *NewBB;
358
357
BBEntry = NewBB = BasicBlock::Create (BB->getContext ());
359
- if (BB->hasName ()) NewBB->setName (BB->getName ()+NameSuffix);
358
+ if (BB->hasName ())
359
+ NewBB->setName (BB->getName () + NameSuffix);
360
360
361
361
// It is only legal to clone a function if a block address within that
362
362
// function is never referenced outside of the function. Given that, we
@@ -368,17 +368,17 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
368
368
// Note that we don't need to fix the mapping for unreachable blocks;
369
369
// the default mapping there is safe.
370
370
if (BB->hasAddressTaken ()) {
371
- Constant *OldBBAddr = BlockAddress::get (const_cast <Function*>(OldFunc),
372
- const_cast <BasicBlock*>(BB));
371
+ Constant *OldBBAddr = BlockAddress::get (const_cast <Function *>(OldFunc),
372
+ const_cast <BasicBlock *>(BB));
373
373
VMap[OldBBAddr] = BlockAddress::get (NewFunc, NewBB);
374
374
}
375
375
376
376
bool hasCalls = false , hasDynamicAllocas = false , hasStaticAllocas = false ;
377
377
378
378
// Loop over all instructions, and copy them over, DCE'ing as we go. This
379
379
// loop doesn't include the terminator.
380
- for (BasicBlock::const_iterator II = StartingInst, IE = --BB->end ();
381
- II != IE; ++II) {
380
+ for (BasicBlock::const_iterator II = StartingInst, IE = --BB->end (); II != IE;
381
+ ++II) {
382
382
383
383
Instruction *NewInst = II->clone ();
384
384
@@ -408,7 +408,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
408
408
}
409
409
410
410
if (II->hasName ())
411
- NewInst->setName (II->getName ()+ NameSuffix);
411
+ NewInst->setName (II->getName () + NameSuffix);
412
412
VMap[&*II] = NewInst; // Add instruction map to value.
413
413
NewBB->getInstList ().push_back (NewInst);
414
414
hasCalls |= (isa<CallInst>(II) && !isa<DbgInfoIntrinsic>(II));
@@ -454,9 +454,9 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
454
454
Value *V = VMap.lookup (SI->getCondition ());
455
455
Cond = dyn_cast_or_null<ConstantInt>(V);
456
456
}
457
- if (Cond) { // Constant fold to uncond branch!
457
+ if (Cond) { // Constant fold to uncond branch!
458
458
SwitchInst::ConstCaseHandle Case = *SI->findCaseValue (Cond);
459
- BasicBlock *Dest = const_cast <BasicBlock*>(Case.getCaseSuccessor ());
459
+ BasicBlock *Dest = const_cast <BasicBlock *>(Case.getCaseSuccessor ());
460
460
VMap[OldTI] = BranchInst::Create (Dest, NewBB);
461
461
ToClone.push_back (Dest);
462
462
TerminatorDone = true ;
@@ -466,9 +466,9 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
466
466
if (!TerminatorDone) {
467
467
Instruction *NewInst = OldTI->clone ();
468
468
if (OldTI->hasName ())
469
- NewInst->setName (OldTI->getName ()+ NameSuffix);
469
+ NewInst->setName (OldTI->getName () + NameSuffix);
470
470
NewBB->getInstList ().push_back (NewInst);
471
- VMap[OldTI] = NewInst; // Add instruction map to value.
471
+ VMap[OldTI] = NewInst; // Add instruction map to value.
472
472
473
473
if (CodeInfo)
474
474
if (auto *CB = dyn_cast<CallBase>(OldTI))
@@ -480,10 +480,10 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
480
480
}
481
481
482
482
if (CodeInfo) {
483
- CodeInfo->ContainsCalls |= hasCalls;
483
+ CodeInfo->ContainsCalls |= hasCalls;
484
484
CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas;
485
- CodeInfo->ContainsDynamicAllocas |= hasStaticAllocas &&
486
- BB != &BB->getParent ()->front ();
485
+ CodeInfo->ContainsDynamicAllocas |=
486
+ hasStaticAllocas && BB != &BB->getParent ()->front ();
487
487
}
488
488
}
489
489
@@ -521,7 +521,7 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
521
521
}
522
522
523
523
// Clone the entry block, and anything recursively reachable from it.
524
- std::vector<const BasicBlock*> CloneWorklist;
524
+ std::vector<const BasicBlock *> CloneWorklist;
525
525
PFC.CloneBlock (StartingBB, StartingInst->getIterator (), CloneWorklist);
526
526
while (!CloneWorklist.empty ()) {
527
527
const BasicBlock *BB = CloneWorklist.back ();
@@ -534,11 +534,12 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
534
534
// insert it into the new function in the right order. If not, ignore it.
535
535
//
536
536
// Defer PHI resolution until rest of function is resolved.
537
- SmallVector<const PHINode*, 16 > PHIToResolve;
537
+ SmallVector<const PHINode *, 16 > PHIToResolve;
538
538
for (const BasicBlock &BI : *OldFunc) {
539
539
Value *V = VMap.lookup (&BI);
540
540
BasicBlock *NewBB = cast_or_null<BasicBlock>(V);
541
- if (!NewBB) continue ; // Dead block.
541
+ if (!NewBB)
542
+ continue ; // Dead block.
542
543
543
544
// Add the new block to the new function.
544
545
NewFunc->getBasicBlockList ().push_back (NewBB);
@@ -563,7 +564,7 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
563
564
564
565
// Defer PHI resolution until rest of function is resolved, PHI resolution
565
566
// requires the CFG to be up-to-date.
566
- for (unsigned phino = 0 , e = PHIToResolve.size (); phino != e; ) {
567
+ for (unsigned phino = 0 , e = PHIToResolve.size (); phino != e;) {
567
568
const PHINode *OPN = PHIToResolve[phino];
568
569
unsigned NumPreds = OPN->getNumIncomingValues ();
569
570
const BasicBlock *OldBB = OPN->getParent ();
@@ -572,21 +573,22 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
572
573
// Map operands for blocks that are live and remove operands for blocks
573
574
// that are dead.
574
575
for (; phino != PHIToResolve.size () &&
575
- PHIToResolve[phino]->getParent () == OldBB; ++phino) {
576
+ PHIToResolve[phino]->getParent () == OldBB;
577
+ ++phino) {
576
578
OPN = PHIToResolve[phino];
577
579
PHINode *PN = cast<PHINode>(VMap[OPN]);
578
580
for (unsigned pred = 0 , e = NumPreds; pred != e; ++pred) {
579
581
Value *V = VMap.lookup (PN->getIncomingBlock (pred));
580
582
if (BasicBlock *MappedBlock = cast_or_null<BasicBlock>(V)) {
581
- Value *InVal = MapValue (PN-> getIncomingValue (pred),
582
- VMap,
583
- ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges);
583
+ Value *InVal =
584
+ MapValue (PN-> getIncomingValue (pred), VMap,
585
+ ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges);
584
586
assert (InVal && " Unknown input value?" );
585
587
PN->setIncomingValue (pred, InVal);
586
588
PN->setIncomingBlock (pred, MappedBlock);
587
589
} else {
588
590
PN->removeIncomingValue (pred, false );
589
- --pred; // Revisit the next entry.
591
+ --pred; // Revisit the next entry.
590
592
--e;
591
593
}
592
594
}
@@ -602,7 +604,7 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
602
604
if (NumPreds != PN->getNumIncomingValues ()) {
603
605
assert (NumPreds < PN->getNumIncomingValues ());
604
606
// Count how many times each predecessor comes to this block.
605
- std::map<BasicBlock*, unsigned > PredCount;
607
+ std::map<BasicBlock *, unsigned > PredCount;
606
608
for (BasicBlock *Pred : predecessors (NewBB))
607
609
--PredCount[Pred];
608
610
@@ -722,11 +724,15 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
722
724
}
723
725
724
726
BranchInst *BI = dyn_cast<BranchInst>(I->getTerminator ());
725
- if (!BI || BI->isConditional ()) { ++I; continue ; }
727
+ if (!BI || BI->isConditional ()) {
728
+ ++I;
729
+ continue ;
730
+ }
726
731
727
732
BasicBlock *Dest = BI->getSuccessor (0 );
728
733
if (!Dest->getSinglePredecessor ()) {
729
- ++I; continue ;
734
+ ++I;
735
+ continue ;
730
736
}
731
737
732
738
// We shouldn't be able to get single-entry PHI nodes here, as instsimplify
@@ -759,21 +765,17 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
759
765
Returns.push_back (RI);
760
766
}
761
767
762
-
763
768
// / This works exactly like CloneFunctionInto,
764
769
// / except that it does some simple constant prop and DCE on the fly. The
765
770
// / effect of this is to copy significantly less code in cases where (for
766
771
// / example) a function call with constant arguments is inlined, and those
767
772
// / constant arguments cause a significant amount of code in the callee to be
768
773
// / dead. Since this doesn't produce an exact copy of the input, it can't be
769
774
// / used for things like CloneFunction or CloneModule.
770
- void llvm::CloneAndPruneFunctionInto (Function *NewFunc, const Function *OldFunc,
771
- ValueToValueMapTy &VMap,
772
- bool ModuleLevelChanges,
773
- SmallVectorImpl<ReturnInst*> &Returns,
774
- const char *NameSuffix,
775
- ClonedCodeInfo *CodeInfo,
776
- Instruction *TheCall) {
775
+ void llvm::CloneAndPruneFunctionInto (
776
+ Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap,
777
+ bool ModuleLevelChanges, SmallVectorImpl<ReturnInst *> &Returns,
778
+ const char *NameSuffix, ClonedCodeInfo *CodeInfo, Instruction *TheCall) {
777
779
CloneAndPruneIntoFromInst (NewFunc, OldFunc, &OldFunc->front ().front (), VMap,
778
780
ModuleLevelChanges, Returns, NameSuffix, CodeInfo);
779
781
}
@@ -924,10 +926,9 @@ BasicBlock *llvm::DuplicateInstructionsInSplitBetween(
924
926
return NewBB;
925
927
}
926
928
927
- void llvm::cloneNoAliasScopes (
928
- ArrayRef<MDNode *> NoAliasDeclScopes,
929
- DenseMap<MDNode *, MDNode *> &ClonedScopes,
930
- StringRef Ext, LLVMContext &Context) {
929
+ void llvm::cloneNoAliasScopes (ArrayRef<MDNode *> NoAliasDeclScopes,
930
+ DenseMap<MDNode *, MDNode *> &ClonedScopes,
931
+ StringRef Ext, LLVMContext &Context) {
931
932
MDBuilder MDB (Context);
932
933
933
934
for (auto *ScopeList : NoAliasDeclScopes) {
@@ -950,9 +951,9 @@ void llvm::cloneNoAliasScopes(
950
951
}
951
952
}
952
953
953
- void llvm::adaptNoAliasScopes (
954
- Instruction *I, const DenseMap<MDNode *, MDNode *> &ClonedScopes,
955
- LLVMContext &Context) {
954
+ void llvm::adaptNoAliasScopes (Instruction *I,
955
+ const DenseMap<MDNode *, MDNode *> &ClonedScopes,
956
+ LLVMContext &Context) {
956
957
auto CloneScopeList = [&](const MDNode *ScopeList) -> MDNode * {
957
958
bool NeedsReplacement = false ;
958
959
SmallVector<Metadata *, 8 > NewScopeList;
@@ -984,9 +985,9 @@ void llvm::adaptNoAliasScopes(
984
985
replaceWhenNeeded (LLVMContext::MD_alias_scope);
985
986
}
986
987
987
- void llvm::cloneAndAdaptNoAliasScopes (
988
- ArrayRef<MDNode *> NoAliasDeclScopes ,
989
- ArrayRef<BasicBlock *> NewBlocks, LLVMContext &Context, StringRef Ext) {
988
+ void llvm::cloneAndAdaptNoAliasScopes (ArrayRef<MDNode *> NoAliasDeclScopes,
989
+ ArrayRef<BasicBlock *> NewBlocks ,
990
+ LLVMContext &Context, StringRef Ext) {
990
991
if (NoAliasDeclScopes.empty ())
991
992
return ;
992
993
@@ -1001,9 +1002,9 @@ void llvm::cloneAndAdaptNoAliasScopes(
1001
1002
adaptNoAliasScopes (&I, ClonedScopes, Context);
1002
1003
}
1003
1004
1004
- void llvm::cloneAndAdaptNoAliasScopes (
1005
- ArrayRef<MDNode *> NoAliasDeclScopes, Instruction *IStart,
1006
- Instruction *IEnd, LLVMContext &Context, StringRef Ext) {
1005
+ void llvm::cloneAndAdaptNoAliasScopes (ArrayRef<MDNode *> NoAliasDeclScopes,
1006
+ Instruction *IStart, Instruction *IEnd ,
1007
+ LLVMContext &Context, StringRef Ext) {
1007
1008
if (NoAliasDeclScopes.empty ())
1008
1009
return ;
1009
1010
0 commit comments