@@ -387,11 +387,16 @@ class LandingPadInliningInfo {
387
387
388
388
// / Dominator tree to update.
389
389
DominatorTree *DT = nullptr ;
390
+
391
+ // / TaskInfo to update.
392
+ TaskInfo *TI = nullptr ;
393
+
390
394
public:
391
395
LandingPadInliningInfo (DetachInst *DI, BasicBlock *EHContinue,
392
396
Value *LPadValInEHContinue,
393
- DominatorTree *DT = nullptr )
394
- : OuterResumeDest(EHContinue), SpawnerLPad(LPadValInEHContinue), DT(DT) {
397
+ DominatorTree *DT = nullptr , TaskInfo *TI = nullptr )
398
+ : OuterResumeDest(EHContinue), SpawnerLPad(LPadValInEHContinue), DT(DT),
399
+ TI (TI) {
395
400
// Find the predecessor block of OuterResumeDest.
396
401
BasicBlock *DetachBB = DI->getParent ();
397
402
BasicBlock *DetachUnwind = DI->getUnwindDest ();
@@ -414,9 +419,9 @@ class LandingPadInliningInfo {
414
419
}
415
420
416
421
LandingPadInliningInfo (InvokeInst *TaskFrameResume,
417
- DominatorTree *DT = nullptr )
422
+ DominatorTree *DT = nullptr , TaskInfo *TI = nullptr )
418
423
: OuterResumeDest(TaskFrameResume->getUnwindDest ()),
419
- SpawnerLPad(TaskFrameResume->getLandingPadInst ()), DT(DT) {
424
+ SpawnerLPad(TaskFrameResume->getLandingPadInst ()), DT(DT), TI(TI) {
420
425
// If there are PHI nodes in the unwind destination block, we need to keep
421
426
// track of which values came into them from the detach before removing the
422
427
// edge from this block.
@@ -484,6 +489,8 @@ BasicBlock *LandingPadInliningInfo::getInnerResumeDest() {
484
489
for (DomTreeNode *I : Children)
485
490
DT->changeImmediateDominator (I, NewNode);
486
491
}
492
+ if (TI)
493
+ TI->addBlockToSpindle (*InnerResumeDest, TI->getSpindleFor (OuterResumeDest));
487
494
488
495
// The number of incoming edges we expect to the inner landing pad.
489
496
const unsigned PHICapacity = 2 ;
@@ -571,11 +578,15 @@ void LandingPadInliningInfo::forwardTaskResume(InvokeInst *TR) {
571
578
if (NormalDest) {
572
579
for (BasicBlock *Succ : successors (NormalDest))
573
580
maybeRemovePredecessor (Succ, NormalDest);
581
+ if (TI)
582
+ TI->removeBlock (*NormalDest);
574
583
NormalDest->eraseFromParent ();
575
584
}
576
585
if (UnwindDest) {
577
586
for (BasicBlock *Succ : successors (UnwindDest))
578
587
maybeRemovePredecessor (Succ, UnwindDest);
588
+ if (TI)
589
+ TI->removeBlock (*UnwindDest);
579
590
UnwindDest->eraseFromParent ();
580
591
}
581
592
}
@@ -584,8 +595,8 @@ static void handleDetachedLandingPads(
584
595
DetachInst *DI, BasicBlock *EHContinue, Value *LPadValInEHContinue,
585
596
SmallPtrSetImpl<LandingPadInst *> &InlinedLPads,
586
597
SmallVectorImpl<Instruction *> &DetachedRethrows,
587
- DominatorTree *DT = nullptr ) {
588
- LandingPadInliningInfo DetUnwind (DI, EHContinue, LPadValInEHContinue, DT);
598
+ DominatorTree *DT = nullptr , TaskInfo *TI = nullptr ) {
599
+ LandingPadInliningInfo DetUnwind (DI, EHContinue, LPadValInEHContinue, DT, TI );
589
600
590
601
// Append the clauses from the outer landing pad instruction into the inlined
591
602
// landing pad instructions.
@@ -815,13 +826,14 @@ static void getTaskFrameLandingPads(
815
826
// Helper method to handle a given taskframe.resume.
816
827
static void handleTaskFrameResume (Value *TaskFrame,
817
828
Instruction *TaskFrameResume,
818
- DominatorTree *DT = nullptr ) {
829
+ DominatorTree *DT = nullptr ,
830
+ TaskInfo *TI = nullptr ) {
819
831
// Get landingpads to inline.
820
832
SmallPtrSet<LandingPadInst *, 1 > InlinedLPads;
821
833
getTaskFrameLandingPads (TaskFrame, TaskFrameResume, InlinedLPads);
822
834
823
835
InvokeInst *TFR = cast<InvokeInst>(TaskFrameResume);
824
- LandingPadInliningInfo TFResumeDest (TFR, DT);
836
+ LandingPadInliningInfo TFResumeDest (TFR, DT, TI );
825
837
826
838
// Append the clauses from the outer landing pad instruction into the inlined
827
839
// landing pad instructions.
@@ -839,7 +851,8 @@ static void handleTaskFrameResume(Value *TaskFrame,
839
851
TFResumeDest.forwardTaskResume (TFR);
840
852
}
841
853
842
- void llvm::InlineTaskFrameResumes (Value *TaskFrame, DominatorTree *DT) {
854
+ void llvm::InlineTaskFrameResumes (Value *TaskFrame, DominatorTree *DT,
855
+ TaskInfo *TI) {
843
856
SmallVector<Instruction *, 1 > TaskFrameResumes;
844
857
// Record all taskframe.resume markers that use TaskFrame.
845
858
for (User *U : TaskFrame->users ())
@@ -849,20 +862,20 @@ void llvm::InlineTaskFrameResumes(Value *TaskFrame, DominatorTree *DT) {
849
862
850
863
// Handle all taskframe.resume markers.
851
864
for (Instruction *TFR : TaskFrameResumes)
852
- handleTaskFrameResume (TaskFrame, TFR, DT);
865
+ handleTaskFrameResume (TaskFrame, TFR, DT, TI );
853
866
}
854
867
855
868
static void startSerializingTaskFrame (Value *TaskFrame,
856
869
SmallVectorImpl<Instruction *> &ToErase,
857
- DominatorTree *DT,
870
+ DominatorTree *DT, TaskInfo *TI,
858
871
bool PreserveTaskFrame) {
859
872
for (User *U : TaskFrame->users ())
860
873
if (Instruction *UI = dyn_cast<Instruction>(U))
861
874
if (isTapirIntrinsic (Intrinsic::taskframe_use, UI))
862
875
ToErase.push_back (UI);
863
876
864
877
if (!PreserveTaskFrame)
865
- InlineTaskFrameResumes (TaskFrame, DT);
878
+ InlineTaskFrameResumes (TaskFrame, DT, TI );
866
879
}
867
880
868
881
void llvm::SerializeDetach (DetachInst *DI, BasicBlock *ParentEntry,
@@ -873,7 +886,9 @@ void llvm::SerializeDetach(DetachInst *DI, BasicBlock *ParentEntry,
873
886
SmallPtrSetImpl<LandingPadInst *> *InlinedLPads,
874
887
SmallVectorImpl<Instruction *> *DetachedRethrows,
875
888
bool ReplaceWithTaskFrame, DominatorTree *DT,
876
- LoopInfo *LI) {
889
+ TaskInfo *TI, LoopInfo *LI) {
890
+ LLVM_DEBUG (dbgs () << " Serializing detach " << *DI << " \n " );
891
+
877
892
BasicBlock *Spawner = DI->getParent ();
878
893
BasicBlock *TaskEntry = DI->getDetached ();
879
894
BasicBlock *Continue = DI->getContinue ();
@@ -885,7 +900,7 @@ void llvm::SerializeDetach(DetachInst *DI, BasicBlock *ParentEntry,
885
900
SmallVector<Instruction *, 8 > ToErase;
886
901
Value *TaskFrame = getTaskFrameUsed (TaskEntry);
887
902
if (TaskFrame)
888
- startSerializingTaskFrame (TaskFrame, ToErase, DT, ReplaceWithTaskFrame);
903
+ startSerializingTaskFrame (TaskFrame, ToErase, DT, TI, ReplaceWithTaskFrame);
889
904
890
905
// Clone any EH blocks that need cloning.
891
906
if (EHBlocksToClone) {
@@ -952,7 +967,7 @@ void llvm::SerializeDetach(DetachInst *DI, BasicBlock *ParentEntry,
952
967
} else {
953
968
// Otherwise, "inline" the detached landingpads.
954
969
handleDetachedLandingPads (DI, EHContinue, LPadValInEHContinue,
955
- *InlinedLPads, *DetachedRethrows, DT);
970
+ *InlinedLPads, *DetachedRethrows, DT, TI );
956
971
}
957
972
}
958
973
@@ -1059,7 +1074,7 @@ void llvm::AnalyzeTaskForSerialization(
1059
1074
// / Serialize the detach DI that spawns task T. If provided, the dominator tree
1060
1075
// / DT will be updated to reflect the serialization.
1061
1076
void llvm::SerializeDetach (DetachInst *DI, Task *T, bool ReplaceWithTaskFrame,
1062
- DominatorTree *DT) {
1077
+ DominatorTree *DT, TaskInfo *TI ) {
1063
1078
assert (DI && " SerializeDetach given nullptr for detach." );
1064
1079
assert (DI == T->getDetach () && " Task and detach arguments do not match." );
1065
1080
SmallVector<BasicBlock *, 4 > EHBlocksToClone;
@@ -1078,7 +1093,9 @@ void llvm::SerializeDetach(DetachInst *DI, Task *T, bool ReplaceWithTaskFrame,
1078
1093
}
1079
1094
SerializeDetach (DI, T->getParentTask ()->getEntry (), EHContinue, LPadVal,
1080
1095
Reattaches, &EHBlocksToClone, &EHBlockPreds, &InlinedLPads,
1081
- &DetachedRethrows, ReplaceWithTaskFrame, DT);
1096
+ &DetachedRethrows, ReplaceWithTaskFrame, DT, TI);
1097
+ if (TI)
1098
+ TI->moveSpindlesToParent (T);
1082
1099
}
1083
1100
1084
1101
static bool isCanonicalTaskFrameEnd (const Instruction *TFEnd) {
0 commit comments