LLVM: lib/Transforms/Utils/BasicBlockUtils.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
45#include
46#include
47#include
48#include
49#include
50
51using namespace llvm;
52
53#define DEBUG_TYPE "basicblock-utils"
54
57 cl::desc("Set the maximum path length when checking whether a basic block "
58 "is followed by a block that either has a terminating "
59 "deoptimizing call or is terminated with an unreachable"));
60
61
62
63
64static void
67 bool KeepOneInputPHIs) {
68
69
72 Succ->removePredecessor(BB, KeepOneInputPHIs);
73 if (Updates && UniqueSuccessors.insert(Succ).second)
75 }
76
77
78 while (!BB->empty()) {
80
81
82
83
84
85 if (.use_empty())
88 }
91 "The successor list of BB isn't empty before "
92 "applying corresponding DTU updates.");
93}
94
99 return true;
100 }
101 return false;
102}
103
106 bool KeepOneInputPHIs) {
108 for (auto *BB : BBs) {
109 auto NonFirstPhiIt = BB->getFirstNonPHIIt();
110 if (NonFirstPhiIt != BB->end()) {
112
113
114
115
116
117
119 UniqueEHRetBlocksToDelete.clear();
120
123
124
125
129 UniqueEHRetBlocksToDelete.insert(ReturnInstrBB);
130 }
131 }
132
133 for (BasicBlock *EHRetBB : UniqueEHRetBlocksToDelete)
135 }
136 }
137
138 UniqueEHRetBlocksToDelete.clear();
139
140
142 }
143}
144
146 bool KeepOneInputPHIs) {
148}
149
151 bool KeepOneInputPHIs) {
152#ifndef NDEBUG
153
155 assert(Dead.size() == BBs.size() && "Duplicating blocks?");
156 for (auto *BB : Dead)
158 assert(Dead.count(Pred) && "All predecessors must be dead!");
159#endif
160
162 detachDeadBlocks(BBs, DTU ? &Updates : nullptr, KeepOneInputPHIs);
163
164 if (DTU)
166
168 if (DTU)
170 else
171 BB->eraseFromParent();
172}
173
175 bool KeepOneInputPHIs) {
177
178
180 (void)BB;
181
182
183 std::vector<BasicBlock*> DeadBlocks;
185 if (!Reachable.count(&BB))
186 DeadBlocks.push_back(&BB);
187
188
190
191 return !DeadBlocks.empty();
192}
193
197 return false;
198
200 if (PN->getIncomingValue(0) != PN)
201 PN->replaceAllUsesWith(PN->getIncomingValue(0));
202 else
204
205 if (MemDep)
207
208 PN->eraseFromParent();
209 }
210 return true;
211}
212
215
216
218
220 for (const auto &PHI : PHIs)
223
225}
226
230 bool PredecessorWithTwoSuccessors,
233 return false;
234
235
237 if (!PredBB) return false;
238
239
240 if (PredBB == BB) return false;
241
242
245 return false;
246
247
248 if (!PredecessorWithTwoSuccessors && PredBB->getUniqueSuccessor() != BB)
249 return false;
250
251
252
255 unsigned FallThruPath;
256 if (PredecessorWithTwoSuccessors) {
258 return false;
261 return false;
263 FallThruPath = PredBB_BI->getSuccessor(0) == BB ? 0 : 1;
264 }
265
266
269 return false;
270
271
272
273
276 return false;
277
279 << PredBB->getName() << "\n");
280
281
286 cast(PN.getIncomingValue(0))->getParent() != BB)
287 IncomingValues.push_back(PN.getIncomingValue(0));
289 }
290
291 if (DT) {
292 assert(!DTU && "cannot use both DT and DTU for updates");
295 if (PredNode) {
296 assert(BBNode && "PredNode unreachable but BBNode reachable?");
298 C->setIDom(PredNode);
299 }
300 }
301
302
303 std::vectorDominatorTree::UpdateType Updates;
304 if (DTU) {
305 assert(!DT && "cannot use both DT and DTU for updates");
306
310 Updates.reserve(Updates.size() + 2 * succ_size(BB) + 1);
311
312
313
314
315
316
318
319 if (!SuccsOfPredBB.contains(SuccOfBB))
320 if (SeenSuccs.insert(SuccOfBB).second)
322 SeenSuccs.clear();
324 if (SeenSuccs.insert(SuccOfBB).second)
327 }
328
331
332
333 if (Start == STI)
334 Start = PTI;
335
336
338
339 if (MSSAU)
341
342
343
345
346 if (PredecessorWithTwoSuccessors) {
347
349
350
351 PredBB_BI->setSuccessor(FallThruPath, NewSucc);
352 } else {
353
355
356
358
359
360 if (MSSAU)
364 }
365
367
368
371
372 if (LI)
374
375 if (MemDep)
377
378 if (DTU)
380
381 if (DT) {
383 "successors should have been transferred to PredBB");
385 }
386
387
389
390 return true;
391}
392
396 assert(!MergeBlocks.empty() && "MergeBlocks should not be empty");
397
398 bool BlocksHaveBeenMerged = false;
399 while (!MergeBlocks.empty()) {
402 if (Dest && (!L || L->contains(Dest))) {
404 (void)Fold;
407 "Expecting BB to be unique predecessor of the Dest block");
408 MergeBlocks.erase(Dest);
409 BlocksHaveBeenMerged = true;
410 } else
411 MergeBlocks.erase(BB);
412 } else
413 MergeBlocks.erase(BB);
414 }
415 return BlocksHaveBeenMerged;
416}
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
440 for (auto &I : reverse(*BB)) {
444 DVR.getDebugLoc()->getInlinedAt());
445 auto R = VariableSet.insert(Key);
446
447
448
449 if (R.second)
450 continue;
451
452 if (DVR.isDbgAssign()) {
453
455 continue;
456
457 }
458
460 }
461
462
463
464 VariableSet.clear();
465 }
466
467 for (auto &DVR : ToBeRemoved)
468 DVR->eraseFromParent();
469
470 return !ToBeRemoved.empty();
471}
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
493 bool RemovedAny = false;
495 std::pair<SmallVector<Value *, 4>, DIExpression *>, 4>
496 VariableMap;
497 for (auto &I : *BB) {
501 continue;
503 DVR.getDebugLoc()->getInlinedAt());
505
506
507 bool IsDbgValueKind =
509
510
511
513 if (Inserted || VMI->second.first != Values ||
514 VMI->second.second != DVR.getExpression()) {
515 if (IsDbgValueKind)
516 VMI->second = {Values, DVR.getExpression()};
517 else
518 VMI->second = {Values, nullptr};
519 continue;
520 }
521
522 if (!IsDbgValueKind)
523 continue;
524
525 DVR.eraseFromParent();
526 RemovedAny = true;
527 }
528 }
529
530 return RemovedAny;
531}
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
554 bool RemovedAny = false;
556
557
558
559 for (auto &I : *BB) {
562 if (!DVR.isDbgValue() && !DVR.isDbgAssign())
563 continue;
564 bool IsDbgValueKind =
566
568 if (!SeenDefForAggregate.contains(Aggregate)) {
569 bool IsKill = DVR.isKillLocation() && IsDbgValueKind;
570 if (!IsKill) {
571 SeenDefForAggregate.insert(Aggregate);
572 } else if (DVR.isDbgAssign()) {
573 DVR.eraseFromParent();
574 RemovedAny = true;
575 }
576 }
577 }
578 }
579
580 return RemovedAny;
581}
582
584 bool MadeChanges = false;
585
586
587
588
589
590
591
592
593
594
595
601
602 if (MadeChanges)
603 LLVM_DEBUG(dbgs() << "Removed redundant dbg instrs from: "
604 << BB->getName() << "\n");
605 return MadeChanges;
606}
607
610
611 I.replaceAllUsesWith(V);
612
613
614 if (I.hasName() && !V->hasName())
615 V->takeName(&I);
616
617
618 BI = BI->eraseFromParent();
619}
620
623 assert(I->getParent() == nullptr &&
624 "ReplaceInstWithInst: Instruction already inserted into basic block!");
625
626
627
628 if (->getDebugLoc())
629 I->setDebugLoc(BI->getDebugLoc());
630
631
633
634
636
637
638 BI = New;
639}
640
642
644 unsigned Depth = 0;
649 return true;
651 }
652 return false;
653}
654
659
662 const Twine &BBName) {
664
666
669
671
673 }
674
675
676
678
679
680 assert(SP == BB && "CFG broken");
681 (void)SP;
682 return SplitBlock(Succ, &Succ->front(), DT, LI, MSSAU, BBName,
683 true);
684 }
685
686
687
689 "Should have a single succ!");
691}
692
693
694
695
696
697
698
699
700
701template <typename TI, typename T>
704 static_assert(std::is_same_v<TI, CycleInfo> || std::is_same_v<TI, LoopInfo>,
705 "type must be CycleInfo or LoopInfo");
706 if (!LCI)
707 return false;
708
709 T *LC;
710 if constexpr (std::is_same_v<TI, CycleInfo>)
711 LC = LCI->getSmallestCommonCycle(CallBrBlock, Succ);
712 else
713 LC = LCI->getSmallestCommonLoop(CallBrBlock, Succ);
714 if (!LC)
715 return false;
716
717 if constexpr (std::is_same_v<TI, CycleInfo>)
718 LCI->addBlockToCycle(CallBrTarget, LC);
719 else
720 LC->addBasicBlockToLoop(CallBrTarget, *LCI);
721
722 return true;
723}
724
728 bool *UpdatedLI) {
730 assert(CallBr && "expected callbr terminator");
731 assert(SuccIdx < CallBr->getNumSuccessors() &&
732 Succ == CallBr->getSuccessor(SuccIdx) && "invalid successor index");
733
734
735
736
737
738
739
742 CallBrBlock->getName() + ".target." + Succ->getName(),
744
746
748
750
751 bool Updated =
753 if (UpdatedLI)
754 *UpdatedLI = Updated;
756 if (DTU) {
762 }
763 }
764
765 return CallBrTarget;
766}
767
770 II->setUnwindDest(Succ);
772 CS->setUnwindDest(Succ);
774 CR->setUnwindDest(Succ);
775 else
777}
778
781 int BBIdx = 0;
783
784
785 if (Until == &PN)
786 break;
787
788
789
790
791
792
793 if (PN.getIncomingBlock(BBIdx) != OldPred)
794 BBIdx = PN.getBasicBlockIndex(OldPred);
795
796 assert(BBIdx != -1 && "Invalid PHI Index!");
797 PN.setIncomingBlock(BBIdx, NewPred);
798 }
799}
800
803 PHINode *LandingPadReplacement,
805 const Twine &BBName) {
806
808 if (!LandingPadReplacement && !PadInst->isEHPad())
810
813
814
815
816 if (Options.PreserveLoopSimplify && LI) {
817 if (Loop *BBLoop = LI->getLoopFor(BB)) {
818
819
820
821
822
823
824
825
826
827
829 if (P == BB)
830 continue;
831 if (LI->getLoopFor(P) != BBLoop) {
832
833
834 LoopPreds.clear();
835 break;
836 }
838 }
839
840
843 })) {
844 return nullptr;
845 }
846 }
847 }
848
849 auto *NewBB =
852 updatePhiNodes(Succ, BB, NewBB, LandingPadReplacement);
853
854 if (LandingPadReplacement) {
855 auto *NewLP = OriginalPad->clone();
857 NewLP->insertBefore(Terminator->getIterator());
858 LandingPadReplacement->addIncoming(NewLP, NewBB);
859 } else {
860 Value *ParentPad = nullptr;
862 ParentPad = FuncletPad->getParentPad();
864 ParentPad = CatchSwitch->getParentPad();
866 ParentPad = CleanupPad->getParentPad();
868 ParentPad = LandingPad->getParent();
869 else
870 llvm_unreachable("handling for other EHPads not implemented yet");
871
874 }
875
877 auto *MSSAU = Options.MSSAU;
878 if (!DT && !LI)
879 return NewBB;
880
881 if (DT) {
882 DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
884
888
891
892 if (MSSAU) {
893 MSSAU->applyUpdates(Updates, *DT);
895 MSSAU->getMemorySSA()->verifyMemorySSA();
896 }
897 }
898
899 if (LI) {
900 if (Loop *BBLoop = LI->getLoopFor(BB)) {
901
902
903 if (Loop *SuccLoop = LI->getLoopFor(Succ)) {
904 if (BBLoop == SuccLoop) {
905
906 SuccLoop->addBasicBlockToLoop(NewBB, *LI);
907 } else if (BBLoop->contains(SuccLoop)) {
908
909 BBLoop->addBasicBlockToLoop(NewBB, *LI);
910 } else if (SuccLoop->contains(BBLoop)) {
911
912 SuccLoop->addBasicBlockToLoop(NewBB, *LI);
913 } else {
914
915
916
917
918 assert(SuccLoop->getHeader() == Succ &&
919 "Should not create irreducible loops!");
920 if (Loop *P = SuccLoop->getParentLoop())
921 P->addBasicBlockToLoop(NewBB, *LI);
922 }
923 }
924
925
926
927 if (!BBLoop->contains(Succ)) {
928 assert(!BBLoop->contains(NewBB) &&
929 "Split point for loop exit is contained in loop!");
930
931
932 if (Options.PreserveLCSSA) {
934 }
935
936 if (!LoopPreds.empty()) {
938 Succ, LoopPreds, "split", DT, LI, MSSAU, Options.PreserveLCSSA);
939 if (Options.PreserveLCSSA)
941 }
942 }
943 }
944 }
945
946 return NewBB;
947}
948
951
954 "SplitBB has non-PHI nodes!");
955
956
958 int Idx = PN.getBasicBlockIndex(SplitBB);
959 assert(Idx >= 0 && "Invalid Block Index");
960 Value *V = PN.getIncomingValue(Idx);
961
962
963
965 if (VP->getParent() == SplitBB)
966 continue;
967
968
976
977
978 PN.setIncomingValue(Idx, NewPN);
979 }
980}
981
982unsigned
985 unsigned NumBroken = 0;
989 for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
991 ++NumBroken;
992 }
993 return NumBroken;
994}
995
999 const Twine &BBName, bool Before) {
1000 if (Before) {
1001 DomTreeUpdater LocalDTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
1003 DTU ? DTU : (DT ? &LocalDTU : nullptr), LI, MSSAU,
1004 BBName);
1005 }
1007 while (isa(SplitIt) || SplitIt->isEHPad()) {
1008 ++SplitIt;
1009 assert(SplitIt != SplitPt->getParent()->end());
1010 }
1011 std::string Name = BBName.str();
1013 SplitIt, Name.empty() ? Old->getName() + ".split" : Name);
1014
1015
1016
1017 if (LI)
1019 L->addBasicBlockToLoop(New, *LI);
1020
1021 if (DTU) {
1023
1028 if (UniqueSuccessorsOfOld.insert(SuccessorOfOld).second) {
1031 }
1032
1034 } else if (DT)
1035
1037 std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end());
1038
1042 }
1043
1044
1045
1046 if (MSSAU)
1048
1049 return New;
1050}
1051
1055 bool Before) {
1056 return SplitBlockImpl(Old, SplitPt, nullptr, DT, LI, MSSAU, BBName,
1057 Before);
1058}
1062 bool Before) {
1063 return SplitBlockImpl(Old, SplitPt, DTU, nullptr, LI, MSSAU, BBName,
1064 Before);
1065}
1066
1070 const Twine &BBName) {
1071
1073 while (isa(SplitIt) || SplitIt->isEHPad())
1074 ++SplitIt;
1075 std::string Name = BBName.str();
1077 SplitIt, Name.empty() ? Old->getName() + ".split" : Name,
1078 true);
1079
1080
1081
1082 if (LI)
1084 L->addBasicBlockToLoop(New, *LI);
1085
1086 if (DTU) {
1088
1089
1094 if (UniquePredecessorsOfOld.insert(PredecessorOfOld).second) {
1097 }
1098
1100
1101
1102
1103 if (MSSAU) {
1107 }
1108 }
1109 return New;
1110}
1111
1112
1113
1118 bool PreserveLCSSA, bool &HasLoopExit) {
1119
1120 if (DTU) {
1121
1122
1124
1125
1126
1128 } else {
1129
1134 for (auto *Pred : Preds)
1135 if (UniquePreds.insert(Pred).second) {
1138 }
1140 }
1141 } else if (DT) {
1145 } else {
1146
1148 }
1149 }
1150
1151
1152 if (MSSAU)
1154
1155
1156 if (!LI)
1157 return;
1158
1161 assert(DT && "DT should be available to update LoopInfo!");
1163
1164
1165
1166 bool IsLoopEntry = !!L;
1167 bool SplitMakesNewLoopHeader = false;
1169
1170
1171
1172
1174 continue;
1175
1176
1177 if (PreserveLCSSA)
1179 if (!PL->contains(OldBB))
1180 HasLoopExit = true;
1181
1182
1183
1184 if (!L)
1185 continue;
1186 if (L->contains(Pred))
1187 IsLoopEntry = false;
1188 else
1189 SplitMakesNewLoopHeader = true;
1190 }
1191
1192
1193 if (!L)
1194 return;
1195
1196 if (IsLoopEntry) {
1197
1198
1199
1200
1201 Loop *InnermostPredLoop = nullptr;
1204
1205
1206 while (PredLoop && !PredLoop->contains(OldBB))
1207 PredLoop = PredLoop->getParentLoop();
1208
1209
1210 if (PredLoop && PredLoop->contains(OldBB) &&
1211 (!InnermostPredLoop ||
1212 InnermostPredLoop->getLoopDepth() < PredLoop->getLoopDepth()))
1213 InnermostPredLoop = PredLoop;
1214 }
1215 }
1216
1217 if (InnermostPredLoop)
1219 } else {
1220 L->addBasicBlockToLoop(NewBB, *LI);
1221 if (SplitMakesNewLoopHeader)
1222 L->moveToHeader(NewBB);
1223 }
1224}
1225
1226
1227
1230 bool HasLoopExit) {
1231
1235
1236
1237
1238 Value *InVal = nullptr;
1239 if (!HasLoopExit) {
1243 continue;
1244 if (!InVal)
1247 InVal = nullptr;
1248 break;
1249 }
1250 }
1251 }
1252
1253 if (InVal) {
1254
1255
1256
1258 [&](unsigned Idx) {
1260 },
1261 false);
1262
1263
1264
1266 continue;
1267 }
1268
1269
1270
1271
1274
1275
1276
1277
1278
1281 if (PredSet.count(IncomingBB)) {
1284 }
1285 }
1286
1288 }
1289}
1290
1296
1302
1304 return nullptr;
1305
1306
1307
1310 std::string NewName = std::string(Suffix) + ".split-lp";
1311
1313 DTU, DT, LI, MSSAU, PreserveLCSSA);
1314 return NewBBs[0];
1315 }
1316
1317
1320
1321
1323
1324 Loop *L = nullptr;
1326
1329
1330
1332
1333
1334
1335
1336
1337 OldLatch = L->getLoopLatch();
1338 } else
1340
1341
1343
1344
1345
1347 "Cannot split an edge from an IndirectBrInst");
1348 Pred->getTerminator()->replaceSuccessorWith(BB, NewBB);
1349 }
1350
1351
1352
1353
1354
1355 if (Preds.empty()) {
1356
1359 }
1360
1361
1362 bool HasLoopExit = false;
1364 HasLoopExit);
1365
1366 if (!Preds.empty()) {
1367
1369 }
1370
1371 if (OldLatch) {
1372 BasicBlock *NewLatch = L->getLoopLatch();
1373 if (NewLatch != OldLatch) {
1376
1377
1381 }
1382 }
1383
1384 return NewBB;
1385}
1386
1391 bool PreserveLCSSA) {
1393 MSSAU, PreserveLCSSA);
1394}
1397 const char *Suffix,
1400 bool PreserveLCSSA) {
1402 nullptr, LI, MSSAU, PreserveLCSSA);
1403}
1404
1410 assert(OrigBB->isLandingPad() && "Trying to split a non-landing pad!");
1411
1412
1413
1415 OrigBB->getName() + Suffix1,
1418
1419
1422
1423
1425
1426
1427
1429 "Cannot split an edge from an IndirectBrInst");
1430 Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB1);
1431 }
1432
1433 bool HasLoopExit = false;
1435 PreserveLCSSA, HasLoopExit);
1436
1437
1438 UpdatePHINodes(OrigBB, NewBB1, Preds, BI1, HasLoopExit);
1439
1440
1443 i != e; ) {
1445 if (Pred == NewBB1) continue;
1447 "Cannot split an edge from an IndirectBrInst");
1450 }
1451
1453 if (!NewBB2Preds.empty()) {
1454
1456 OrigBB->getName() + Suffix2,
1459
1460
1463
1464
1465 for (BasicBlock *NewBB2Pred : NewBB2Preds)
1466 NewBB2Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB2);
1467
1468
1469 HasLoopExit = false;
1471 PreserveLCSSA, HasLoopExit);
1472
1473
1474 UpdatePHINodes(OrigBB, NewBB2, NewBB2Preds, BI2, HasLoopExit);
1475 }
1476
1481
1482 if (NewBB2) {
1486
1487
1488
1491 "Split cannot be applied if LPad is token type. Otherwise an "
1492 "invalid PHINode of token type would be created.");
1497 }
1499 } else {
1500
1501
1504 }
1505}
1506
1509 const char *Suffix1, const char *Suffix2,
1513 bool PreserveLCSSA) {
1515 NewBBs, DTU, nullptr, LI, MSSAU,
1516 PreserveLCSSA);
1517}
1518
1522 Instruction *UncondBranch = Pred->getTerminator();
1523
1525 NewRet->insertInto(Pred, Pred->end());
1526
1527
1528
1533
1534
1535 V = BCI->getOperand(0);
1536 NewBC = BCI->clone();
1538 Op = NewBC;
1539 }
1540
1543 V = EVI->getOperand(0);
1544 NewEV = EVI->clone();
1545 if (NewBC) {
1548 } else {
1550 Op = NewEV;
1551 }
1552 }
1553
1555 if (PN->getParent() == BB) {
1556 if (NewEV) {
1557 NewEV->setOperand(0, PN->getIncomingValueForBlock(Pred));
1558 } else if (NewBC)
1559 NewBC->setOperand(0, PN->getIncomingValueForBlock(Pred));
1560 else
1561 Op = PN->getIncomingValueForBlock(Pred);
1562 }
1563 }
1564 }
1565
1566
1567
1570
1571 if (DTU)
1573
1575}
1576
1579 bool Unreachable,
1580 MDNode *BranchWeights,
1584 Cond, SplitBefore, &ThenBlock, nullptr,
1585 Unreachable,
1586 false, BranchWeights, DTU, LI);
1588}
1589
1592 bool Unreachable,
1593 MDNode *BranchWeights,
1597 Cond, SplitBefore, nullptr, &ElseBlock,
1598 false,
1599 Unreachable, BranchWeights, DTU, LI);
1601}
1602
1606 MDNode *BranchWeights,
1611 Cond, SplitBefore, &ThenBlock, &ElseBlock, false,
1612 false, BranchWeights, DTU, LI);
1613
1616}
1617
1620 BasicBlock **ElseBlock, bool UnreachableThen, bool UnreachableElse,
1622 assert((ThenBlock || ElseBlock) &&
1623 "At least one branch block must be created");
1624 assert((!UnreachableThen || !UnreachableElse) &&
1625 "Split block tail must be reachable");
1626
1630 if (DTU) {
1632 Updates.reserve(4 + 2 * UniqueOrigSuccessors.size());
1633 }
1634
1639 bool ThenToTailEdge = false;
1640 bool ElseToTailEdge = false;
1641
1642
1644 bool &ToTailEdge) {
1645 if (PBB == nullptr)
1646 return;
1647
1648 if (*PBB)
1649 BB = *PBB;
1650 else {
1651
1653 if (Unreachable)
1655 else {
1657 ToTailEdge = true;
1658 }
1659 BB->getTerminator()->setDebugLoc(SplitBefore->getDebugLoc());
1660
1661 *PBB = BB;
1662 }
1663 };
1664
1665 handleBlock(ThenBlock, UnreachableThen, TrueBlock, ThenToTailEdge);
1666 handleBlock(ElseBlock, UnreachableElse, FalseBlock, ElseToTailEdge);
1667
1671 HeadNewTerm->setMetadata(LLVMContext::MD_prof, BranchWeights);
1673
1674 if (DTU) {
1677 if (ThenToTailEdge)
1679 if (ElseToTailEdge)
1681 for (BasicBlock *UniqueOrigSuccessor : UniqueOrigSuccessors)
1683 for (BasicBlock *UniqueOrigSuccessor : UniqueOrigSuccessors)
1686 }
1687
1688 if (LI) {
1690 if (ThenToTailEdge)
1691 L->addBasicBlockToLoop(TrueBlock, *LI);
1692 if (ElseToTailEdge)
1693 L->addBasicBlockToLoop(FalseBlock, *LI);
1694 L->addBasicBlockToLoop(Tail, *LI);
1695 }
1696 }
1697}
1698
1699std::pair<Instruction *, Value *>
1705
1706 auto *Ty = End->getType();
1707 auto &DL = SplitBefore->getDataLayout();
1708 const unsigned Bitwidth = DL.getTypeSizeInBits(Ty);
1709
1711 auto *IV = Builder.CreatePHI(Ty, 2, "iv");
1712 auto *IVNext =
1713 Builder.CreateAdd(IV, ConstantInt::get(Ty, 1), IV->getName() + ".next",
1714 true, Bitwidth != 2);
1715 auto *IVCheck = Builder.CreateICmpEQ(IVNext, End,
1716 IV->getName() + ".check");
1717 Builder.CreateCondBr(IVCheck, LoopExit, LoopBody);
1719
1720
1721 IV->addIncoming(ConstantInt::get(Ty, 0), LoopPred);
1722 IV->addIncoming(IVNext, LoopBody);
1723
1725}
1726
1730
1731 IRBuilder<> IRB(InsertBefore->getParent(), InsertBefore);
1732
1733 if (EC.isScalable()) {
1735
1736 auto [BodyIP, Index] =
1738
1740 Func(IRB, Index);
1741 return;
1742 }
1743
1744 unsigned Num = EC.getFixedValue();
1745 for (unsigned Idx = 0; Idx < Num; ++Idx) {
1747 Func(IRB, ConstantInt::get(IndexTy, Idx));
1748 }
1749}
1750
1754
1755 IRBuilder<> IRB(InsertBefore->getParent(), InsertBefore);
1757
1761 Func(IRB, Index);
1762 return;
1763 }
1764
1766 for (unsigned Idx = 0; Idx < Num; ++Idx) {
1768 Func(IRB, ConstantInt::get(Ty, Idx));
1769 }
1770}
1771
1777
1778 if (SomePHI) {
1780 return nullptr;
1783 } else {
1785 if (PI == PE)
1786 return nullptr;
1787 Pred1 = *PI++;
1788 if (PI == PE)
1789 return nullptr;
1790 Pred2 = *PI++;
1791 if (PI != PE)
1792 return nullptr;
1793 }
1794
1795
1796
1799 if (!Pred1Br || !Pred2Br)
1800 return nullptr;
1801
1802
1803
1805
1806
1807
1808
1810 return nullptr;
1811
1814 }
1815
1817
1818
1819
1821 return nullptr;
1822
1823
1824
1827 IfTrue = Pred1;
1828 IfFalse = Pred2;
1829 } else if (Pred1Br->getSuccessor(0) == Pred2 &&
1831 IfTrue = Pred2;
1832 IfFalse = Pred1;
1833 } else {
1834
1835
1836 return nullptr;
1837 }
1838
1839 return Pred1Br;
1840 }
1841
1842
1843
1844
1847 return nullptr;
1848
1849
1851 if (!BI) return nullptr;
1852
1855 IfTrue = Pred1;
1856 IfFalse = Pred2;
1857 } else {
1858 IfTrue = Pred2;
1859 IfFalse = Pred1;
1860 }
1861 return BI;
1862}
1863
1866
1867
1871 } else
1872 NewCond = Builder.CreateNot(NewCond, NewCond->getName() + ".not");
1873
1876}
1877
1879 for (auto &BB : F) {
1880 auto *Term = BB.getTerminator();
1883 return false;
1884 }
1885 return true;
1886}
1887
1890 if (!BB) {
1891 OS << "";
1892 return;
1893 }
1895 });
1896}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static BasicBlock * SplitBlockPredecessorsImpl(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
Definition BasicBlockUtils.cpp:1298
static bool removeRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB)
Remove redundant instructions within sequences of consecutive dbg.value instructions.
Definition BasicBlockUtils.cpp:437
static BasicBlock * SplitBlockImpl(BasicBlock *Old, BasicBlock::iterator SplitPt, DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, const Twine &BBName, bool Before)
Definition BasicBlockUtils.cpp:996
static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB, ArrayRef< BasicBlock * > Preds, BranchInst *BI, bool HasLoopExit)
Update the PHI nodes in OrigBB to include the values coming from NewBB.
Definition BasicBlockUtils.cpp:1228
static bool removeUndefDbgAssignsFromEntryBlock(BasicBlock *BB)
Remove redundant undef dbg.assign intrinsic from an entry block using a forward scan.
Definition BasicBlockUtils.cpp:552
static bool updateCycleLoopInfo(TI *LCI, BasicBlock *CallBrBlock, BasicBlock *CallBrTarget, BasicBlock *Succ)
Helper function to update the cycle or loop information after inserting a new block between a callbr ...
Definition BasicBlockUtils.cpp:702
static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB, ArrayRef< BasicBlock * > Preds, DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA, bool &HasLoopExit)
Update DominatorTree, LoopInfo, and LCCSA analysis information.
Definition BasicBlockUtils.cpp:1114
static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB)
Remove redundant dbg.value instructions using a forward scan.
Definition BasicBlockUtils.cpp:492
static void SplitLandingPadPredecessorsImpl(BasicBlock *OrigBB, ArrayRef< BasicBlock * > Preds, const char *Suffix1, const char *Suffix2, SmallVectorImpl< BasicBlock * > &NewBBs, DomTreeUpdater *DTU, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
Definition BasicBlockUtils.cpp:1405
static cl::opt< unsigned > MaxDeoptOrUnreachableSuccessorCheckDepth("max-deopt-or-unreachable-succ-check-depth", cl::init(8), cl::Hidden, cl::desc("Set the maximum path length when checking whether a basic block " "is followed by a block that either has a terminating " "deoptimizing call or is terminated with an unreachable"))
static void emptyAndDetachBlock(BasicBlock *BB, SmallVectorImpl< DominatorTree::UpdateType > *Updates, bool KeepOneInputPHIs)
Zap all the instructions in the block and replace them with an unreachable instruction and notify the...
Definition BasicBlockUtils.cpp:65
This file contains the declarations for the subclasses of Constant, which represent the different fla...
SmallPtrSet< const BasicBlock *, 8 > VisitedBlocks
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
uint64_t IntrinsicInst * II
const SmallVectorImpl< MachineOperand > & Cond
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static const uint32_t IV[8]
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
LLVM_ABI const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & back() const
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
LLVM_ABI bool isEntryBlock() const
Return true if this is the entry block of the containing function.
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
LLVM_ABI BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
LLVM_ABI const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
LLVM_ABI const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
const Instruction & front() const
LLVM_ABI const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
LLVM_ABI void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old.
LLVM_ABI const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
LLVM_ABI const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
InstListType::iterator iterator
Instruction iterators...
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
LLVM_ABI bool isLandingPad() const
Return true if this basic block is a landing pad.
LLVM_ABI bool canSplitPredecessors() const
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
LLVM_ABI void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
This class represents a no-op cast from one type to another.
Conditional or Unconditional Branch instruction.
void setCondition(Value *V)
LLVM_ABI void swapSuccessors()
Swap the successors of this branch instruction.
bool isConditional() const
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
BasicBlock * getSuccessor(unsigned i) const
bool isUnconditional() const
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
Value * getCondition() const
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
void setSuccessor(unsigned i, BasicBlock *NewSucc)
BasicBlock * getSuccessor(unsigned i) const
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, InsertPosition InsertBefore=nullptr)
This class is the base class for the comparison instructions.
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Represents calls to the llvm.experimintal.convergence.* intrinsics.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
Identifies a unique instance of a whole variable (discards/ignores fragment information).
Identifies a unique instance of a variable.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Implements a dense probed hash-table based set.
iterator_range< iterator > children()
LLVM_ABI void deleteBB(BasicBlock *DelBB)
Delete DelBB.
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
void splitBlock(NodeT *NewBB)
splitBlock - BB is split and now it has one successor.
static constexpr UpdateKind Delete
DomTreeNodeBase< NodeT > * setNewRoot(NodeT *BB)
Add a new node to the forward dominator tree and make it a new root.
static constexpr UpdateKind Insert
void eraseNode(NodeT *BB)
eraseNode - Removes a node from the dominator tree.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
DomTreeT & getDomTree()
Flush DomTree updates and return DomTree.
void applyUpdates(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
void flush()
Apply all pending updates to available trees and flush all BasicBlocks awaiting deletion.
bool hasDomTree() const
Returns true if it holds a DomTreeT.
void recalculate(FuncT &F)
Notify DTU that the entry block was replaced.
Module * getParent()
Get the module that this global value is contained inside of...
Common base class shared among various IRBuilders.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
LLVM_ABI Value * CreateElementCount(Type *Ty, ElementCount EC)
Create an expression which evaluates to the number of elements in EC at runtime.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM_ABI void moveBeforePreserving(InstListType::iterator MovePos)
Perform a moveBefore operation, while signalling that the caller intends to preserve the original ord...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
bool isSpecialTerminator() const
LLVM_ABI InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
unsigned getLoopDepth() const
Return the nesting level of this loop.
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
void removeBlock(BlockT *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
bool isLoopHeader(const BlockT *BB) const
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
Provides a lazy, caching interface for making common memory aliasing information queries,...
void invalidateCachedPredecessors()
Clears the PredIteratorCache info.
void removeInstruction(Instruction *InstToRemove)
Removes an instruction from the dependence analysis, updating the dependence of instructions that pre...
MemorySSA * getMemorySSA() const
Get handle on MemorySSA.
LLVM_ABI void moveAllAfterSpliceBlocks(BasicBlock *From, BasicBlock *To, Instruction *Start)
From block was spliced into From and To.
LLVM_ABI void applyUpdates(ArrayRef< CFGUpdate > Updates, DominatorTree &DT, bool UpdateDTFirst=false)
Apply CFG updates, analogous with the DT edge updates.
LLVM_ABI void moveAllAfterMergeBlocks(BasicBlock *From, BasicBlock *To, Instruction *Start)
From block was merged into To.
LLVM_ABI void moveToPlace(MemoryUseOrDef *What, BasicBlock *BB, MemorySSA::InsertionPlace Where)
LLVM_ABI void wireOldPredecessorsToNewImmediatePredecessor(BasicBlock *Old, BasicBlock *New, ArrayRef< BasicBlock * > Preds, bool IdenticalEdgesWereMerged=true)
A new empty BasicBlock (New) now branches directly to Old.
LLVM_ABI void verifyMemorySSA(VerificationLevel=VerificationLevel::Fast) const
Verify that MemorySSA is self consistent (IE definitions dominate all uses, uses appear in the right ...
MemoryUseOrDef * getMemoryAccess(const Instruction *I) const
Given a memory Mod/Ref'ing instruction, get the MemorySSA access associated with it.
Class that has the common methods + fields of memory uses/defs.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
LLVM_ABI void removeIncomingValueIf(function_ref< bool(unsigned)> Predicate, bool DeletePHIIfEmpty=true)
Remove all incoming values for which the predicate returns true.
LLVM_ABI Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Simple wrapper around std::function<void(raw_ostream&)>.
Return a value (possibly void), from a function.
Implements a dense probed hash-table based set with some number of buckets stored inline.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool erase(PtrType Ptr)
Remove pointer from the set.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
void insert_range(Range &&R)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Provides information about what library functions are available for the current target.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isTokenTy() const
Return true if this is 'token'.
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
void setOperand(unsigned i, Value *Val)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
const ParentTy * getParent() const
self_iterator getIterator()
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI AssignmentInstRange getAssignmentInsts(DIAssignID *ID)
Return a range of instructions (typically just one) that have ID as an attachment.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI, Instruction *I)
Replace the instruction specified by BI with the instruction specified by I.
Definition BasicBlockUtils.cpp:621
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
LLVM_ABI bool RemoveRedundantDbgInstrs(BasicBlock *BB)
Try to remove redundant dbg.value instructions from given basic block.
Definition BasicBlockUtils.cpp:583
bool succ_empty(const Instruction *I)
LLVM_ABI bool IsBlockFollowedByDeoptOrUnreachable(const BasicBlock *BB)
Check if we can prove that all paths starting from this block converge to a block that either has a @...
Definition BasicBlockUtils.cpp:641
LLVM_ABI BranchInst * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)
Check whether BB is the merge point of a if-region.
Definition BasicBlockUtils.cpp:1772
LLVM_ABI unsigned GetSuccessorNumber(const BasicBlock *BB, const BasicBlock *Succ)
Search for the specified successor of basic block BB and return its position in the terminator instru...
auto pred_end(const MachineBasicBlock *BB)
LLVM_ABI void detachDeadBlocks(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< DominatorTree::UpdateType > *Updates, bool KeepOneInputPHIs=false)
Replace contents of every block in BBs with single unreachable instruction.
Definition BasicBlockUtils.cpp:104
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI bool hasOnlySimpleTerminator(const Function &F)
Definition BasicBlockUtils.cpp:1878
auto successors(const MachineBasicBlock *BB)
LLVM_ABI ReturnInst * FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB, BasicBlock *Pred, DomTreeUpdater *DTU=nullptr)
This method duplicates the specified return instruction into a predecessor which ends in an unconditi...
Definition BasicBlockUtils.cpp:1519
constexpr from_range_t from_range
LLVM_ABI std::pair< Instruction *, Value * > SplitBlockAndInsertSimpleForLoop(Value *End, BasicBlock::iterator SplitBefore)
Insert a for (int i = 0; i < End; i++) loop structure (with the exception that End is assumed > 0,...
Definition BasicBlockUtils.cpp:1700
LLVM_ABI BasicBlock * splitBlockBefore(BasicBlock *Old, BasicBlock::iterator SplitPt, DomTreeUpdater *DTU, LoopInfo *LI, MemorySSAUpdater *MSSAU, const Twine &BBName="")
Split the specified block at the specified instruction SplitPt.
Definition BasicBlockUtils.cpp:1067
LLVM_ABI Instruction * SplitBlockAndInsertIfElse(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ElseBlock=nullptr)
Similar to SplitBlockAndInsertIfThen, but the inserted block is on the false path of the branch.
Definition BasicBlockUtils.cpp:1590
LLVM_ABI BasicBlock * SplitCallBrEdge(BasicBlock *CallBrBlock, BasicBlock *Succ, unsigned SuccIdx, DomTreeUpdater *DTU=nullptr, CycleInfo *CI=nullptr, LoopInfo *LI=nullptr, bool *UpdatedLI=nullptr)
Create a new intermediate target block for a callbr edge.
Definition BasicBlockUtils.cpp:725
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
auto cast_or_null(const Y &Val)
auto pred_size(const MachineBasicBlock *BB)
LLVM_ABI void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified block, which must have no predecessors.
Definition BasicBlockUtils.cpp:145
LLVM_ABI void ReplaceInstWithValue(BasicBlock::iterator &BI, Value *V)
Replace all uses of an instruction (specified by BI) with a value, then remove and delete the origina...
Definition BasicBlockUtils.cpp:608
LLVM_ABI BasicBlock * SplitKnownCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
If it is known that an edge is critical, SplitKnownCriticalEdge can be called directly,...
DomTreeNodeBase< BasicBlock > DomTreeNode
auto dyn_cast_or_null(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Examine each PHI in the given block and delete it if it is dead.
Definition BasicBlockUtils.cpp:213
LLVM_ABI bool HasLoopOrEntryConvergenceToken(const BasicBlock *BB)
Check if the given basic block contains any loop or entry convergent intrinsic instructions.
Definition BasicBlockUtils.cpp:95
auto reverse(ContainerTy &&C)
LLVM_ABI void InvertBranch(BranchInst *PBI, IRBuilderBase &Builder)
Definition BasicBlockUtils.cpp:1864
LLVM_ABI bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete all basic blocks from F that are not reachable from its entry node.
Definition BasicBlockUtils.cpp:174
LLVM_ABI bool MergeBlockSuccessorsIntoGivenBlocks(SmallPtrSetImpl< BasicBlock * > &MergeBlocks, Loop *L=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)
Merge block(s) sucessors, if possible.
Definition BasicBlockUtils.cpp:393
LLVM_ABI void SplitBlockAndInsertIfThenElse(Value *Cond, BasicBlock::iterator SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
Definition BasicBlockUtils.cpp:1603
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI BasicBlock * ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ, LandingPadInst *OriginalPad=nullptr, PHINode *LandingPadReplacement=nullptr, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
Split the edge connect the specficed blocks in the case that Succ is an Exception Handling Block.
Definition BasicBlockUtils.cpp:801
auto succ_size(const MachineBasicBlock *BB)
SmallVector< ValueTypeFromRangeType< R >, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI void SplitLandingPadPredecessors(BasicBlock *OrigBB, ArrayRef< BasicBlock * > Preds, const char *Suffix, const char *Suffix2, SmallVectorImpl< BasicBlock * > &NewBBs, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method transforms the landing pad, OrigBB, by introducing two new basic blocks into the function...
Definition BasicBlockUtils.cpp:1507
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
LLVM_ABI BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
Definition BasicBlockUtils.cpp:1387
LLVM_ABI bool VerifyMemorySSA
Enables verification of MemorySSA.
LLVM_ABI void createPHIsForSplitLoopExit(ArrayRef< BasicBlock * > Preds, BasicBlock *SplitBB, BasicBlock *DestBB)
When a loop exit edge is split, LCSSA form may require new PHIs in the new exit block.
Definition BasicBlockUtils.cpp:949
LLVM_ABI bool MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, MemoryDependenceResults *MemDep=nullptr, bool PredecessorWithTwoSuccessors=false, DominatorTree *DT=nullptr)
Attempts to merge a block into its predecessor, if possible.
Definition BasicBlockUtils.cpp:227
LLVM_ABI bool isAssignmentTrackingEnabled(const Module &M)
Return true if assignment tracking is enabled for module M.
DWARFExpression::Operation Op
PredIterator< BasicBlock, Value::user_iterator > pred_iterator
LLVM_ABI BasicBlock * SplitCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
If this edge is a critical edge, insert a new node to split the critical edge.
LLVM_ABI bool FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep=nullptr)
We know that BB has one predecessor.
Definition BasicBlockUtils.cpp:194
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI bool isCriticalEdge(const Instruction *TI, unsigned SuccNum, bool AllowIdenticalEdges=false)
Return true if the specified edge is a critical edge.
LLVM_ABI unsigned SplitAllCriticalEdges(Function &F, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
Loop over all of the edges in the CFG, breaking critical edges as they are found.
Definition BasicBlockUtils.cpp:983
LLVM_ABI void updatePhiNodes(BasicBlock *DestBB, BasicBlock *OldPred, BasicBlock *NewPred, PHINode *Until=nullptr)
Replaces all uses of OldPred with the NewPred block in all PHINodes in a block.
Definition BasicBlockUtils.cpp:779
LLVM_ABI Printable printBasicBlock(const BasicBlock *BB)
Print BasicBlock BB as an operand or print "" if BB is a nullptr.
auto pred_begin(const MachineBasicBlock *BB)
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
LLVM_ABI BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
Definition BasicBlockUtils.cpp:1052
auto predecessors(const MachineBasicBlock *BB)
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
LLVM_ABI Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
Definition BasicBlockUtils.cpp:1577
LLVM_ABI void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified blocks from BB.
Definition BasicBlockUtils.cpp:150
LLVM_ABI BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the edge connecting the specified blocks, and return the newly created basic block between From...
Definition BasicBlockUtils.cpp:660
LLVM_ABI void setUnwindEdgeTo(Instruction *TI, BasicBlock *Succ)
Sets the unwind edge of an instruction to a particular successor.
Definition BasicBlockUtils.cpp:768
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
LLVM_ABI void SplitBlockAndInsertForEachLane(ElementCount EC, Type *IndexTy, BasicBlock::iterator InsertBefore, std::function< void(IRBuilderBase &, Value *)> Func)
Utility function for performing a given action on each lane of a vector with EC elements.
Definition BasicBlockUtils.cpp:1727
GenericCycleInfo< SSAContext > CycleInfo
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Option class for critical edge splitting.
CriticalEdgeSplittingOptions & setPreserveLCSSA()