LLVM: lib/Transforms/Utils/Local.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
58#include "llvm/IR/IntrinsicsWebAssembly.h"
80#include
81#include
82#include
83#include
84#include
85#include
86#include
87
88using namespace llvm;
90
91#define DEBUG_TYPE "local"
92
93STATISTIC(NumRemoved, "Number of unreachable basic blocks removed");
94STATISTIC(NumPHICSEs, "Number of PHI's that got CSE'd");
95
97 "phicse-debug-hash",
98#ifdef EXPENSIVE_CHECKS
100#else
102#endif
104 cl::desc("Perform extra assertion checking to verify that PHINodes's hash "
105 "function is well-behaved w.r.t. its isEqual predicate"));
106
110 "When the basic block contains not more than this number of PHI nodes, "
111 "perform a (faster!) exhaustive search instead of set-driven one."));
112
114 "max-phi-entries-increase-after-removing-empty-block", cl::init(1000),
116 cl::desc("Stop removing an empty block if removing it will introduce more "
117 "than this number of phi entries in its successor"));
118
119
120
122
123
124
125
126
127
128
129
130
131
132
133
139
140
142 if (BI->isUnconditional()) return false;
143
144 BasicBlock *Dest1 = BI->getSuccessor(0);
145 BasicBlock *Dest2 = BI->getSuccessor(1);
146
147 if (Dest2 == Dest1) {
148
149
150
151
152
153 assert(BI->getParent() && "Terminator not inserted in block!");
155
156
157 BranchInst *NewBI = Builder.CreateBr(Dest1);
158
159
160 NewBI->copyMetadata(*BI, {LLVMContext::MD_loop, LLVMContext::MD_dbg,
161 LLVMContext::MD_annotation});
162
163 Value *Cond = BI->getCondition();
164 BI->eraseFromParent();
165 if (DeleteDeadConditions)
167 return true;
168 }
169
171
172
173 BasicBlock *Destination = Cond->getZExtValue() ? Dest1 : Dest2;
174 BasicBlock *OldDest = Cond->getZExtValue() ? Dest2 : Dest1;
175
176
177
179
180
181 BranchInst *NewBI = Builder.CreateBr(Destination);
182
183
184 NewBI->copyMetadata(*BI, {LLVMContext::MD_loop, LLVMContext::MD_dbg,
185 LLVMContext::MD_annotation});
186
187 BI->eraseFromParent();
188 if (DTU)
190 return true;
191 }
192
193 return false;
194 }
195
197
198
200 BasicBlock *DefaultDest = SI->getDefaultDest();
201 BasicBlock *TheOnlyDest = DefaultDest;
202
203
204 if (SI->defaultDestUnreachable() && SI->getNumCases() > 0)
205 TheOnlyDest = SI->case_begin()->getCaseSuccessor();
206
208
209
210 for (auto It = SI->case_begin(), End = SI->case_end(); It != End;) {
211
212 if (It->getCaseValue() == CI) {
213 TheOnlyDest = It->getCaseSuccessor();
214 break;
215 }
216
217
218
219 if (It->getCaseSuccessor() == DefaultDest) {
221 unsigned NCases = SI->getNumCases();
222
223
224 if (NCases > 1 && MD) {
225
228
229
230 unsigned Idx = It->getCaseIndex();
231
232 Weights[0] += Weights[Idx + 1];
233
237 }
238
241 It = SI->removeCase(It);
242 End = SI->case_end();
243
244
245
247 CI = NewCI;
248 It = SI->case_begin();
249 }
250
252 continue;
253 }
254
255
256
257
258 if (It->getCaseSuccessor() != TheOnlyDest)
259 TheOnlyDest = nullptr;
260
261
262 ++It;
263 }
264
265 if (CI && !TheOnlyDest) {
266
267
268 TheOnlyDest = SI->getDefaultDest();
269 }
270
271
272
273 if (TheOnlyDest) {
274
275 Builder.CreateBr(TheOnlyDest);
277
279
280
281 BasicBlock *SuccToKeep = TheOnlyDest;
283 if (DTU && Succ != TheOnlyDest)
284 RemovedSuccessors.insert(Succ);
285
286 if (Succ == SuccToKeep) {
287 SuccToKeep = nullptr;
288 } else {
289 Succ->removePredecessor(BB);
290 }
291 }
292
293
295 SI->eraseFromParent();
296 if (DeleteDeadConditions)
298 if (DTU) {
299 std::vectorDominatorTree::UpdateType Updates;
300 Updates.reserve(RemovedSuccessors.size());
301 for (auto *RemovedSuccessor : RemovedSuccessors)
304 }
305 return true;
306 }
307
308 if (SI->getNumCases() == 1) {
309
310
311 auto FirstCase = *SI->case_begin();
312 Value *Cond = Builder.CreateICmpEQ(SI->getCondition(),
313 FirstCase.getCaseValue(), "cond");
314
315
317 FirstCase.getCaseSuccessor(),
318 SI->getDefaultDest());
321 uint32_t DefWeight = Weights[0];
322 uint32_t CaseWeight = Weights[1];
323
327 }
328
329
330 MDNode *MakeImplicitMD = SI->getMetadata(LLVMContext::MD_make_implicit);
331 if (MakeImplicitMD)
332 NewBr->setMetadata(LLVMContext::MD_make_implicit, MakeImplicitMD);
333
334
335 SI->eraseFromParent();
336 return true;
337 }
339 }
340
342
343 if (auto *BA =
345 BasicBlock *TheOnlyDest = BA->getBasicBlock();
347
348
349 Builder.CreateBr(TheOnlyDest);
350
351 BasicBlock *SuccToKeep = TheOnlyDest;
352 for (unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
353 BasicBlock *DestBB = IBI->getDestination(i);
354 if (DTU && DestBB != TheOnlyDest)
355 RemovedSuccessors.insert(DestBB);
356 if (IBI->getDestination(i) == SuccToKeep) {
357 SuccToKeep = nullptr;
358 } else {
360 }
361 }
363 IBI->eraseFromParent();
364 if (DeleteDeadConditions)
365
367
368
369
370 if (BA->use_empty())
371 BA->destroyConstant();
372
373
374
375
376 if (SuccToKeep) {
379 }
380
381 if (DTU) {
382 std::vectorDominatorTree::UpdateType Updates;
383 Updates.reserve(RemovedSuccessors.size());
384 for (auto *RemovedSuccessor : RemovedSuccessors)
387 }
388 return true;
389 }
390 }
391
392 return false;
393}
394
395
396
397
398
399
400
401
404 if (->use_empty())
405 return false;
407}
408
411
412
414 if (II->getIntrinsicID() == Intrinsic::stacksave ||
415 II->getIntrinsicID() == Intrinsic::launder_invariant_group ||
416 II->isLifetimeStartOrEnd())
417 return false;
419}
420
423 if (I->isTerminator())
424 return false;
425
426
427
428 if (I->isEHPad())
429 return false;
430
432 if (DLI->getLabel())
433 return false;
434 return true;
435 }
436
439 return true;
440
441 if (->willReturn()) {
443 if ()
444 return false;
445
446 switch (II->getIntrinsicID()) {
447 case Intrinsic::experimental_guard: {
448
449
450
452 return Cond && Cond->isOne();
453 }
454
455
456 case Intrinsic::wasm_trunc_signed:
457 case Intrinsic::wasm_trunc_unsigned:
458 case Intrinsic::ptrauth_auth:
459 case Intrinsic::ptrauth_resign:
460 return true;
461 default:
462 return false;
463 }
464 }
465
466 if (->mayHaveSideEffects())
467 return true;
468
469
470
472
473 if (II->getIntrinsicID() == Intrinsic::stacksave ||
474 II->getIntrinsicID() == Intrinsic::launder_invariant_group)
475 return true;
476
477
478
479 if (II->getIntrinsicID() == Intrinsic::allow_runtime_check ||
480 II->getIntrinsicID() == Intrinsic::allow_ubsan_check)
481 return true;
482
483 if (II->isLifetimeStartOrEnd()) {
484 auto *Arg = II->getArgOperand(0);
486 return true;
487
488
489
491 return isa(Use.getUser());
492 });
493 }
494
495
496 if (II->getIntrinsicID() == Intrinsic::assume &&
499 return ->isZero();
500
501 return false;
502 }
503
505 std::optionalfp::ExceptionBehavior ExBehavior =
506 FPI->getExceptionBehavior();
508 }
509 }
510
516 return true;
517 }
518
519
522 LI->getPointerOperand()->stripPointerCasts()))
523 if (!LI->isVolatile() && GV->isConstant())
524 return true;
525
526 return false;
527}
528
529
530
531
532
535 std::function<void(Value *)> AboutToDeleteCallback) {
538 return false;
539
543 AboutToDeleteCallback);
544
545 return true;
546}
547
551 std::function<void(Value *)> AboutToDeleteCallback) {
552 unsigned S = 0, E = DeadInsts.size(), Alive = 0;
553 for (; S != E; ++S) {
556 DeadInsts[S] = nullptr;
557 ++Alive;
558 }
559 }
560 if (Alive == E)
561 return false;
563 AboutToDeleteCallback);
564 return true;
565}
566
570 std::function<void(Value *)> AboutToDeleteCallback) {
571
572 while (!DeadInsts.empty()) {
575 if ()
576 continue;
578 "Live instruction found in dead worklist!");
579 assert(I->use_empty() && "Instructions with uses are not dead.");
580
581
583
584 if (AboutToDeleteCallback)
585 AboutToDeleteCallback(I);
586
587
588
589 for (Use &OpU : I->operands()) {
590 Value *OpV = OpU.get();
591 OpU.set(nullptr);
592
594 continue;
595
596
597
598
602 }
603 if (MSSAU)
605
606 I->eraseFromParent();
607 }
608}
609
613 for (auto *DVR : DPUsers)
614 DVR->setKillLocation();
615 return !DPUsers.empty();
616}
617
618
619
620
621
625 if (UI == UE)
626 return true;
627
628 User *TheUse = *UI;
629 for (++UI; UI != UE; ++UI) {
630 if (*UI != TheUse)
631 return false;
632 }
633 return true;
634}
635
636
637
638
639
640
647 if (I->use_empty())
649
650
651
652 if (!Visited.insert(I).second) {
653
656 return true;
657 }
658 }
659 return false;
660}
661
662static bool
669
670
671
672 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
673 Value *OpV = I->getOperand(i);
674 I->setOperand(i, nullptr);
675
677 continue;
678
679
680
681
684 WorkList.insert(OpI);
685 }
686
687 I->eraseFromParent();
688
689 return true;
690 }
691
693
694
695 for (User *U : I->users()) {
696 if (U != I) {
698 }
699 }
700
701
703 if (->use_empty()) {
704 I->replaceAllUsesWith(SimpleV);
706 }
708 I->eraseFromParent();
710 }
712 }
713 return false;
714}
715
716
717
718
719
720
723 bool MadeChange = false;
725
726#ifndef NDEBUG
727
728
729
730
732#endif
733
735
736
737
739 BI != E;) {
740 assert(!BI->isTerminator());
742 ++BI;
743
744
745
748 }
749
750 while (!WorkList.empty()) {
753 }
754 return MadeChange;
755}
756
757
758
759
760
763
764
766 Value *NewVal = PN->getIncomingValue(0);
767
769 PN->replaceAllUsesWith(NewVal);
770 PN->eraseFromParent();
771 }
772
774 assert(PredBB && "Block doesn't have a single predecessor!");
775
776 bool ReplaceEntryBB = PredBB->isEntryBlock();
777
778
779
781
782 if (DTU) {
783
787
788 if (PredOfPredBB != PredBB)
789 if (SeenPreds.insert(PredOfPredBB).second)
791 SeenPreds.clear();
793 if (SeenPreds.insert(PredOfPredBB).second)
796 }
797
798
799
807 }
808
809
811
812
816
817
818
819 if (ReplaceEntryBB)
821
822 if (DTU) {
825 "The successor list of PredBB isn't empty before "
826 "applying corresponding DTU updates.");
829
830
831 if (ReplaceEntryBB && DTU->hasDomTree()) {
832
833
834
836 }
837 }
838
839 else {
841 }
842}
843
844
845
849
850
851
852
853
854static bool
857 assert(*succ_begin(BB) == Succ && "Succ is not successor of BB!");
858
860 << Succ->getName() << "\n");
861
862
864 return true;
865
866
867
870
871
872
873
875 if (BBPN && BBPN->getParent() == BB) {
878 if (BBPreds.count(IBB) &&
882 << "Can't fold, phi node " << PN->getName() << " in "
883 << Succ->getName() << " is conflicting with "
884 << BBPN->getName() << " with regard to common predecessor "
885 << IBB->getName() << "\n");
886 return false;
887 }
888 }
889 } else {
892
893
894
896 if (BBPreds.count(IBB) &&
899 << " in " << Succ->getName()
900 << " is conflicting with regard to common "
901 << "predecessor " << IBB->getName() << "\n");
902 return false;
903 }
904 }
905 }
906 }
907
908 return true;
909}
910
913
914
915
916
917
918
919
920
921
922
923
924
925
930 IncomingValues.find(BB)->second == OldVal) &&
931 "Expected OldVal to match incoming value from BB!");
932
933 IncomingValues.insert(std::make_pair(BB, OldVal));
934 return OldVal;
935 }
936
938 if (It != IncomingValues.end()) return It->second;
939
940 return OldVal;
941}
942
943
944
945
946
947
948
949
950
956
958 IncomingValues.insert(std::make_pair(BB, V));
959 }
960}
961
962
963
964
965
966
972
974
977
978
979
980
981
982 if (It == IncomingValues.end()) {
984 continue;
985 }
986
987
988
990 }
991
992
993
994
995 unsigned PoisonCount = count_if(TrueUndefOps, [&](unsigned i) {
997 });
998 if (PoisonCount != 0 && PoisonCount != TrueUndefOps.size()) {
999 for (unsigned i : TrueUndefOps)
1001 }
1002}
1003
1004
1005
1006
1007static bool
1011
1012
1013 if (BB->phis().empty() || Succ->phis().empty())
1014 return false;
1015
1016
1018 return false;
1019
1022 }))
1023 return false;
1024
1025
1026
1028 if (BBPreds.count(SuccPred)) {
1029 if (CommonPred)
1030 return false;
1031 CommonPred = SuccPred;
1032 }
1033 }
1034
1035 return true;
1036}
1037
1038
1039
1040
1042
1043
1045 return false;
1046 unsigned NumPreds = pred_size(BB);
1047 unsigned NumChangedPhi = 0;
1048 for (auto &Phi : Succ->phis()) {
1049
1050
1051 if (auto *IncomingPhi = dyn_cast(Phi.getIncomingValueForBlock(BB)))
1052 if (IncomingPhi->getParent() == BB)
1053 continue;
1054
1055 NumChangedPhi++;
1056 }
1057
1058
1059
1060
1061 return (NumPreds - 1) * NumChangedPhi >
1063}
1064
1065
1066
1067
1068
1069
1070
1071
1072
1078 assert(OldVal && "No entry in PHI for Pred BB!");
1079
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1092
1093
1094
1098
1099
1100
1101
1102
1104
1105 if (PredBB == CommonPred)
1106 continue;
1107
1109 Value *Selected =
1111
1112
1113
1115 }
1116 if (CommonPred)
1118
1119 } else {
1120 for (BasicBlock *PredBB : BBPreds) {
1121
1122
1123 if (PredBB == CommonPred)
1124 continue;
1125
1126 Value *Selected =
1128
1129
1130
1132 }
1133 if (CommonPred)
1135 }
1136
1138}
1139
1143 "TryToSimplifyUncondBranchFromEmptyBlock called on entry block!");
1144
1145
1147 if (BB == Succ)
1148 return false;
1149
1151
1152
1154
1156
1157
1158
1160 BB, Succ, BBPreds, CommonPred);
1161
1163 return false;
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1183 for (Use &U : BBI->uses()) {
1185 if (PN->getIncomingBlock(U) != BB)
1186 return false;
1187 } else {
1188 return false;
1189 }
1190 }
1191 ++BBI;
1192 }
1193 }
1194
1195 if (BBPhisMergeable && CommonPred)
1197 << " and " << Succ->getName() << " : "
1198 << CommonPred->getName() << "\n");
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1266 if (TI->hasNonDebugLocLoopMetadata())
1268 if (Instruction *PredTI = Pred->getTerminator())
1269 if (PredTI->hasNonDebugLocLoopMetadata())
1270 return false;
1271
1272 if (BBKillable)
1273 LLVM_DEBUG(dbgs() << "Killing Trivial BB: \n" << *BB);
1274 else if (BBPhisMergeable)
1275 LLVM_DEBUG(dbgs() << "Merge Phis in Trivial BB: \n" << *BB);
1276
1278
1279 if (DTU) {
1280
1282
1283
1288
1289 if (!SuccPreds.contains(PredOfBB))
1290 if (SeenPreds.insert(PredOfBB).second)
1292 }
1293
1294 SeenPreds.clear();
1295
1297
1298
1299 if (SeenPreds.insert(PredOfBB).second && PredOfBB != CommonPred)
1301
1302 if (BBKillable)
1304 }
1305
1307
1308
1309
1311
1312
1316 }
1317 }
1318
1320
1321
1322
1325 } else {
1327
1328 assert(PN->use_empty() && "There shouldn't be any uses here!");
1329 PN->eraseFromParent();
1330 }
1331 }
1332
1333
1334
1335
1337 if (TI->hasNonDebugLocLoopMetadata()) {
1338 MDNode *LoopMD = TI->getMetadata(LLVMContext::MD_loop);
1340 Pred->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopMD);
1341 }
1342
1343 if (BBKillable) {
1344
1346
1349
1350
1353
1355 assert(succ_empty(BB) && "The successor list of BB isn't empty before "
1356 "applying corresponding DTU updates.");
1357 } else if (BBPhisMergeable) {
1358
1361 return UseInst->getParent() != CommonPred &&
1362 BBPreds.contains(UseInst->getParent());
1363 return false;
1364 });
1365 }
1366
1367 if (DTU)
1369
1370 if (BBKillable)
1372
1373 return true;
1374}
1375
1376static bool
1379
1380
1381
1382
1384
1385
1386
1387
1389 ++I;
1390
1391
1392
1394 if (ToRemove.contains(DuplicatePN))
1395 continue;
1397 continue;
1398
1399 ++NumPHICSEs;
1401 ToRemove.insert(DuplicatePN);
1403
1404
1406 break;
1407 }
1408 }
1410}
1411
1412static bool
1415
1416
1417
1418
1419 struct PHIDenseMapInfo {
1420 static PHINode *getEmptyKey() {
1422 }
1423
1424 static PHINode *getTombstoneKey() {
1426 }
1427
1429 return PN == getEmptyKey() || PN == getTombstoneKey();
1430 }
1431
1432
1433
1435
1436
1437
1438 return static_cast<unsigned>(
1441 }
1442
1443 static unsigned getHashValue(PHINode *PN) {
1444#ifndef NDEBUG
1445
1446
1447
1448
1450 return 0;
1451#endif
1453 }
1454
1458 return LHS->isIdenticalTo(RHS);
1459 }
1460
1462
1463
1467 return Result;
1468 }
1469 };
1470
1471
1474
1475
1479 continue;
1480 auto Inserted = PHISet.insert(PN);
1481 if (!Inserted.second) {
1482
1483 ++NumPHICSEs;
1484 PN->replaceAllUsesWith(*Inserted.first);
1487
1488
1489
1492 }
1493 }
1494
1496}
1497
1500 if (
1503#endif
1507}
1508
1513 PN->eraseFromParent();
1515}
1516
1519 V = V->stripPointerCasts();
1520
1522
1523
1524
1525
1526
1527 Align CurrentAlign = AI->getAlign();
1528 if (PrefAlign <= CurrentAlign)
1529 return CurrentAlign;
1530
1531
1532
1533 MaybeAlign StackAlign = DL.getStackAlignment();
1534 if (StackAlign && PrefAlign > *StackAlign)
1535 return CurrentAlign;
1536 AI->setAlignment(PrefAlign);
1537 return PrefAlign;
1538 }
1539
1541
1542 Align CurrentAlign = GV->getPointerAlignment(DL);
1543 if (PrefAlign <= CurrentAlign)
1544 return CurrentAlign;
1545
1546
1547
1548
1549
1550 if (!GV->canIncreaseAlignment())
1551 return CurrentAlign;
1552
1553 if (GV->isThreadLocal()) {
1554 unsigned MaxTLSAlign = GV->getParent()->getMaxTLSAlignment() / CHAR_BIT;
1555 if (MaxTLSAlign && PrefAlign > Align(MaxTLSAlign))
1556 PrefAlign = Align(MaxTLSAlign);
1557 }
1558
1559 GV->setAlignment(PrefAlign);
1560 return PrefAlign;
1561 }
1562
1563 return Align(1);
1564}
1565
1571 assert(V->getType()->isPointerTy() &&
1572 "getOrEnforceKnownAlignment expects a pointer!");
1573
1576
1577
1578
1579
1581
1583
1584 if (PrefAlign && *PrefAlign > Alignment)
1586
1587
1588 return Alignment;
1589}
1590
1591
1592
1593
1594
1595
1599
1600
1601
1606 if ((DVR->getVariable() == DIVar) && (DVR->getExpression() == DIExpr))
1607 return true;
1608 }
1609 return false;
1610}
1611
1612
1613
1614
1615
1616
1617
1618
1619
1622 TypeSize ValueSize = DL.getTypeAllocSizeInBits(ValTy);
1623 if (std::optional<uint64_t> FragmentSize =
1626
1627
1628
1629
1631
1633 "address of variable must have exactly 1 location operand.");
1634 if (auto *AI =
1636 if (std::optional FragmentSize = AI->getAllocationSizeInBits(DL)) {
1638 }
1639 }
1640 }
1641
1642 return false;
1643}
1644
1653 Instr->getParent()->insertDbgRecordBefore(DVRec, Instr);
1654}
1655
1661
1666 assert(DIVar && "Missing variable");
1668 Value *DV = SI->getValueOperand();
1669
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684 bool CanConvert =
1685 DIExpr->isDeref() || (!DIExpr->startsWithDeref() &&
1687 if (CanConvert) {
1689 SI->getIterator());
1690 return;
1691 }
1692
1693
1694
1695 LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to dbg.value: " << *DVR
1696 << '\n');
1697
1698
1699
1700
1705 SI->getParent()->insertDbgRecordBefore(NewDVR, SI->getIterator());
1706}
1707
1711 assert(DIVar && "Missing variable");
1714 Value *DV = SI->getValueOperand();
1715
1717
1719 SI->getIterator());
1720}
1721
1726 assert(DIVar && "Missing variable");
1727
1729
1730
1731
1732 LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to DbgVariableRecord: "
1733 << *DVR << '\n');
1734 return;
1735 }
1736
1738
1739
1740
1741
1742
1743
1744
1748 LI->getParent()->insertDbgRecordAfter(DV, LI);
1749}
1750
1751
1756
1757
1765 assert(DIVar && "Missing variable");
1766
1768 return;
1769
1771
1772
1773
1774 LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to DbgVariableRecord: "
1775 << *DVR << '\n');
1776 return;
1777 }
1778
1781
1783
1784
1785
1786
1787 if (InsertionPt != BB->end()) {
1789 InsertionPt);
1790 }
1791}
1792
1793
1794
1797 DIBuilder DIB(*F.getParent(), false);
1800 for (auto &FI : F) {
1807 }
1808 }
1809 }
1810
1813
1817
1818
1819
1820
1821
1822
1824 return;
1825
1826
1828 if (LoadInst *LI = dyn_cast(U))
1829 return LI->isVolatile();
1830 if (StoreInst *SI = dyn_cast(U))
1831 return SI->isVolatile();
1832 return false;
1833 }))
1834 return;
1835
1838 while (!WorkList.empty()) {
1840 for (const auto &AIUse : V->uses()) {
1841 User *U = AIUse.getUser();
1843 if (AIUse.getOperandNo() == 1)
1848
1849
1850
1851 if (!CI->isLifetimeStartOrEnd()) {
1853 auto *DerefExpr =
1856 DerefExpr, NewLoc,
1857 CI->getIterator());
1858 }
1860 if (BI->getType()->isPointerTy())
1862 }
1863 }
1864 }
1865 DDI->eraseFromParent();
1867 };
1868
1870
1874
1876}
1877
1878
1881 assert(BB && "No BasicBlock to clone DbgVariableRecord(s) from.");
1882 if (InsertedPHIs.size() == 0)
1883 return;
1884
1885
1887 for (auto &I : *BB) {
1889 for (Value *V : DVR.location_ops())
1891 DbgValueMap.insert({Loc, &DVR});
1892 }
1893 }
1894 if (DbgValueMap.size() == 0)
1895 return;
1896
1897
1898
1899
1900
1901
1903 NewDbgValueMap;
1904
1905
1906
1907
1908
1909 for (auto PHI : InsertedPHIs) {
1911
1913 continue;
1914 for (auto VI : PHI->operand_values()) {
1915 auto V = DbgValueMap.find(VI);
1916 if (V != DbgValueMap.end()) {
1918 auto NewDI = NewDbgValueMap.find({Parent, DbgII});
1919 if (NewDI == NewDbgValueMap.end()) {
1921 NewDI = NewDbgValueMap.insert({{Parent, DbgII}, NewDbgII}).first;
1922 }
1924
1925
1928 }
1929 }
1930 }
1931
1932 for (auto DI : NewDbgValueMap) {
1933 BasicBlock *Parent = DI.first.first;
1936 assert(InsertionPt != Parent->end() && "Ill-formed basic block");
1937
1939 }
1940}
1941
1946
1948 assert(DII->getVariable() && "Missing variable");
1949 auto *DIExpr = DII->getExpression();
1951 DII->setExpression(DIExpr);
1952 DII->replaceVariableLocationOp(Address, NewAddress);
1953 };
1954
1955 for_each(DVRDeclares, ReplaceOne);
1956
1957 return !DVRDeclares.empty();
1958}
1959
1965 assert(DIVar && "Missing variable");
1966
1967
1968
1969
1971 DIExpr->getElement(0) != dwarf::DW_OP_deref)
1972 return;
1973
1974
1977
1980}
1981
1986
1987
1990 DVR->getExpression(), NewAllocaAddress, DVR,
1992}
1993
1994
1995
2001
2004
2005 if ()
2006 return;
2007
2008 assert(!Assign->getAddressExpression()->getFragmentInfo().has_value() &&
2009 "address-expression shouldn't have fragment info");
2010
2011
2016
2017
2018 if (!NewV)
2019 return;
2020
2022 Assign->getAddressExpression(), Ops, 0, false);
2024 "address-expression shouldn't have fragment info");
2025
2027
2028
2029 if (AdditionalValues.empty()) {
2030 Assign->setAddress(NewV);
2031 Assign->setAddressExpression(SalvagedExpr);
2032 } else {
2033 Assign->setKillAddress();
2034 }
2035}
2036
2039
2040
2041
2042 const unsigned MaxDebugArgs = 16;
2043 const unsigned MaxExpressionSize = 128;
2044 bool Salvaged = false;
2045
2046 for (auto *DVR : DPUsers) {
2047 if (DVR->isDbgAssign()) {
2048 if (DVR->getAddress() == &I) {
2050 Salvaged = true;
2051 }
2052 if (DVR->getValue() != &I)
2053 continue;
2054 }
2055
2056
2057
2058
2059 bool StackValue =
2061 auto DVRLocation = DVR->location_ops();
2064 "DbgVariableIntrinsic must use salvaged instruction as its location");
2066
2067
2068
2069
2070 Value *Op0 = nullptr;
2071 DIExpression *SalvagedExpr = DVR->getExpression();
2072 auto LocItr = find(DVRLocation, &I);
2073 while (SalvagedExpr && LocItr != DVRLocation.end()) {
2075 unsigned LocNo = std::distance(DVRLocation.begin(), LocItr);
2078 if (!Op0)
2079 break;
2080 SalvagedExpr =
2082 LocItr = std::find(++LocItr, DVRLocation.end(), &I);
2083 }
2084
2085
2086 if (!Op0)
2087 break;
2088
2090 DVR->replaceVariableLocationOp(&I, Op0);
2091 bool IsValidSalvageExpr =
2092 SalvagedExpr->getNumElements() <= MaxExpressionSize;
2093 if (AdditionalValues.empty() && IsValidSalvageExpr) {
2094 DVR->setExpression(SalvagedExpr);
2096 IsValidSalvageExpr &&
2097 DVR->getNumVariableLocationOps() + AdditionalValues.size() <=
2098 MaxDebugArgs) {
2099 DVR->addVariableLocationOps(AdditionalValues, SalvagedExpr);
2100 } else {
2101
2102
2103
2104
2105 DVR->setKillLocation();
2106 }
2108 Salvaged = true;
2109 }
2110
2111 if (Salvaged)
2112 return;
2113
2114 for (auto *DVR : DPUsers)
2115 DVR->setKillLocation();
2116}
2117
2122 unsigned BitWidth = DL.getIndexSizeInBits(GEP->getPointerAddressSpace());
2123
2126 if (->collectOffset(DL, BitWidth, VariableOffsets, ConstantOffset))
2127 return nullptr;
2128 if (!VariableOffsets.empty() && !CurrentLocOps) {
2129 Opcodes.insert(Opcodes.begin(), {dwarf::DW_OP_LLVM_arg, 0});
2130 CurrentLocOps = 1;
2131 }
2132 for (const auto &Offset : VariableOffsets) {
2134 assert(Offset.second.isStrictlyPositive() &&
2135 "Expected strictly positive multiplier for offset.");
2137 Offset.second.getZExtValue(), dwarf::DW_OP_mul,
2138 dwarf::DW_OP_plus});
2139 }
2141 return GEP->getOperand(0);
2142}
2143
2145 switch (Opcode) {
2146 case Instruction::Add:
2147 return dwarf::DW_OP_plus;
2148 case Instruction::Sub:
2149 return dwarf::DW_OP_minus;
2150 case Instruction::Mul:
2151 return dwarf::DW_OP_mul;
2152 case Instruction::SDiv:
2153 return dwarf::DW_OP_div;
2154 case Instruction::SRem:
2155 return dwarf::DW_OP_mod;
2156 case Instruction::Or:
2157 return dwarf::DW_OP_or;
2158 case Instruction::And:
2159 return dwarf::DW_OP_and;
2160 case Instruction::Xor:
2161 return dwarf::DW_OP_xor;
2162 case Instruction::Shl:
2163 return dwarf::DW_OP_shl;
2164 case Instruction::LShr:
2165 return dwarf::DW_OP_shr;
2166 case Instruction::AShr:
2167 return dwarf::DW_OP_shra;
2168 default:
2169
2170 return 0;
2171 }
2172}
2173
2178 if (!CurrentLocOps) {
2180 CurrentLocOps = 1;
2181 }
2183 AdditionalValues.push_back(I->getOperand(1));
2184}
2185
2189
2191
2192 if (ConstInt && ConstInt->getBitWidth() > 64)
2193 return nullptr;
2194
2196
2197 if (ConstInt) {
2198 uint64_t Val = ConstInt->getSExtValue();
2199
2200
2201 if (BinOpcode == Instruction::Add || BinOpcode == Instruction::Sub) {
2202 uint64_t Offset = BinOpcode == Instruction::Add ? Val : -int64_t(Val);
2205 }
2206 Opcodes.append({dwarf::DW_OP_constu, Val});
2207 } else {
2209 }
2210
2211
2212
2214 if (!DwarfBinOp)
2215 return nullptr;
2218}
2219
2221
2222
2223 switch (Pred) {
2225 return dwarf::DW_OP_eq;
2227 return dwarf::DW_OP_ne;
2230 return dwarf::DW_OP_gt;
2233 return dwarf::DW_OP_ge;
2236 return dwarf::DW_OP_lt;
2239 return dwarf::DW_OP_le;
2240 default:
2241 return 0;
2242 }
2243}
2244
2248
2250
2251 if (ConstInt && ConstInt->getBitWidth() > 64)
2252 return nullptr;
2253
2254 if (ConstInt) {
2256 Opcodes.push_back(dwarf::DW_OP_consts);
2257 else
2258 Opcodes.push_back(dwarf::DW_OP_constu);
2259 uint64_t Val = ConstInt->getSExtValue();
2261 } else {
2263 }
2264
2265
2266
2268 if (!DwarfIcmpOp)
2269 return nullptr;
2272}
2273
2277 auto &M = *I.getModule();
2278 auto &DL = M.getDataLayout();
2279
2281 Value *FromValue = CI->getOperand(0);
2282
2283 if (CI->isNoopCast(DL)) {
2284 return FromValue;
2285 }
2286
2290
2294 return nullptr;
2295
2297 if (FromType->isPointerTy())
2298 FromType = DL.getIntPtrType(FromType);
2299
2300 unsigned FromTypeBitSize = FromType->getScalarSizeInBits();
2302
2305 Ops.append(ExtOps.begin(), ExtOps.end());
2306 return FromValue;
2307 }
2308
2315
2316
2317
2318
2319 return nullptr;
2320}
2321
2322
2324
2325
2326
2327
2331
2334 if (DPUsers.empty())
2335 return false;
2336
2337
2339
2342 bool DomPointAfterFrom = From.getNextNode() == &DomPoint;
2343
2344
2345 for (auto *DVR : DPUsers) {
2347 Instruction *NextNonDebug = MarkedInstr;
2348
2349
2350
2351 if (DomPointAfterFrom && NextNonDebug == &DomPoint) {
2354 DomPoint.getParent()->insertDbgRecordAfter(DVR, &DomPoint);
2356
2357
2358
2359 } else if (!DT.dominates(&DomPoint, MarkedInstr)) {
2360 UndefOrSalvageDVR.insert(DVR);
2361 }
2362 }
2363 }
2364
2365
2366 for (auto *DVR : DPUsers) {
2367 if (UndefOrSalvageDVR.count(DVR))
2368 continue;
2369
2371 if (!DVRepl)
2372 continue;
2373
2378 }
2379
2380 if (!UndefOrSalvageDVR.empty()) {
2381
2384 }
2385
2387}
2388
2389
2390
2391
2392
2393
2394
2395
2397 Type *ToTy) {
2398
2399 if (FromTy == ToTy)
2400 return true;
2401
2402
2404 bool SameSize = DL.getTypeSizeInBits(FromTy) == DL.getTypeSizeInBits(ToTy);
2405 bool LosslessConversion = .isNonIntegralPointerType(FromTy) &&
2406 .isNonIntegralPointerType(ToTy);
2407 return SameSize && LosslessConversion;
2408 }
2409
2410
2411 return false;
2412}
2413
2416
2418 return false;
2419
2420 assert(&From != &To && "Can't replace something with itself");
2421
2424
2426 return DVR.getExpression();
2427 };
2428
2429
2434
2435
2436
2440 assert(FromBits != ToBits && "Unexpected no-op conversion");
2441
2442
2443
2444 if (FromBits < ToBits)
2446
2447
2448
2451
2452
2454 if (!Signedness)
2455 return std::nullopt;
2456
2460 };
2461 return rewriteDebugUsers(From, To, DomPoint, DT, SignOrZeroExtDVR);
2462 }
2463
2464
2465 return false;
2466}
2467
2471
2472 I->dropDbgRecords();
2473 for (Use &U : I->operands()) {
2479 }
2480 }
2481
2483}
2484
2486 unsigned NumDeadInst = 0;
2487
2488
2492
2493 while (EndInst != &BB->front()) {
2494
2499
2500
2502 EndInst = Inst;
2503 continue;
2504 }
2505 ++NumDeadInst;
2506
2509 }
2510 return NumDeadInst;
2511}
2512
2517
2518 if (MSSAU)
2520
2522
2523
2524
2526 Successor->removePredecessor(BB, PreserveLCSSA);
2527 if (DTU)
2529 }
2530 auto *UI = new UnreachableInst(I->getContext(), I->getIterator());
2531 UI->setDebugLoc(I->getDebugLoc());
2532
2533
2534 unsigned NumInstrsRemoved = 0;
2536 while (BBI != BBE) {
2537 if (!BBI->use_empty())
2539 BBI++->eraseFromParent();
2540 ++NumInstrsRemoved;
2541 }
2542 if (DTU) {
2544 Updates.reserve(UniqueSuccessors.size());
2545 for (BasicBlock *UniqueSuccessor : UniqueSuccessors)
2548 }
2550 return NumInstrsRemoved;
2551}
2552
2556 II->getOperandBundlesAsDefs(OpBundles);
2558 II->getCalledOperand(), Args, OpBundles);
2563
2564
2567
2569 auto NewWeights = uint32_t(TotalWeight) != TotalWeight
2570 ? nullptr
2572 NewCall->setMetadata(LLVMContext::MD_prof, NewWeights);
2573 }
2574
2575 return NewCall;
2576}
2577
2578
2583 II->replaceAllUsesWith(NewCall);
2584
2585
2586 BasicBlock *NormalDestBB = II->getNormalDest();
2588
2589
2590
2591 BI->setDebugLoc(II->getDebugLoc());
2592
2593
2595 BasicBlock *UnwindDestBB = II->getUnwindDest();
2597 II->eraseFromParent();
2598 if (DTU)
2600 return NewCall;
2601}
2602
2607
2608
2609
2610 BasicBlock *Split = SplitBlock(BB, CI, DTU, nullptr, nullptr,
2611 CI->getName() + ".noexc");
2612
2613
2615
2616
2619
2621
2622
2623
2624
2625
2628 UnwindEdge, InvokeArgs, OpBundles, CI->getName(), BB);
2632 II->setMetadata(LLVMContext::MD_prof, CI->getMetadata(LLVMContext::MD_prof));
2633
2634 if (DTU)
2636
2637
2638
2640
2641
2642 Split->front().eraseFromParent();
2643 return Split;
2644}
2645
2652 Reachable.insert(BB);
2654 do {
2656
2657
2658
2659
2662 Value *Callee = CI->getCalledOperand();
2663
2665 auto IntrinsicID = F->getIntrinsicID();
2666
2667
2668
2669
2670 if (IntrinsicID == Intrinsic::assume) {
2672
2675 break;
2676 }
2677 } else if (IntrinsicID == Intrinsic::experimental_guard) {
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687 if (match(CI->getArgOperand(0), m_Zero()))
2691 break;
2692 }
2693 }
2697 ->getAddressSpace())) ||
2701 break;
2702 }
2703 if (CI->doesNotReturn() && !CI->isMustTailCall()) {
2704
2705
2706
2708
2711 }
2712 break;
2713 }
2715
2716
2717
2718
2719
2720 if (SI->isVolatile()) continue;
2721
2723
2727 SI->getPointerAddressSpace()))) {
2730 break;
2731 }
2732 }
2733 }
2734
2735 Instruction *Terminator = BB->getTerminator();
2737
2738 Value *Callee = II->getCalledOperand();
2744 } else {
2745 if (II->doesNotReturn() &&
2747
2748
2749
2750
2751
2752 BasicBlock *OrigNormalDest = II->getNormalDest();
2756 Ctx, OrigNormalDest->getName() + ".unreachable",
2757 II->getFunction(), OrigNormalDest);
2758 auto *UI = new UnreachableInst(Ctx, UnreachableNormalDest);
2760 II->setNormalDest(UnreachableNormalDest);
2761 if (DTU)
2762 DTU->applyUpdates(
2766 }
2768 if (II->use_empty() && ->mayHaveSideEffects()) {
2769
2770 BasicBlock *NormalDestBB = II->getNormalDest();
2771 BasicBlock *UnwindDestBB = II->getUnwindDest();
2774 II->eraseFromParent();
2775 if (DTU)
2777 } else
2780 }
2781 }
2783
2784 struct CatchPadDenseMapInfo {
2787 }
2788
2791 }
2792
2793 static unsigned getHashValue(CatchPadInst *CatchPad) {
2796 }
2797
2799 if (LHS == getEmptyKey() || LHS == getTombstoneKey() ||
2800 RHS == getEmptyKey() || RHS == getTombstoneKey())
2802 return LHS->isIdenticalTo(RHS);
2803 }
2804 };
2805
2807
2810 HandlerSet;
2813 E = CatchSwitch->handler_end();
2816 if (DTU)
2817 ++NumPerSuccessorCases[HandlerBB];
2819 if (!HandlerSet.insert({CatchPad, Empty}).second) {
2820 if (DTU)
2821 --NumPerSuccessorCases[HandlerBB];
2822 CatchSwitch->removeHandler(I);
2823 --I;
2824 --E;
2826 }
2827 }
2828 if (DTU) {
2829 std::vectorDominatorTree::UpdateType Updates;
2830 for (const std::pair<BasicBlock *, int> &I : NumPerSuccessorCases)
2831 if (I.second == 0)
2833 DTU->applyUpdates(Updates);
2834 }
2835 }
2836
2839 if (Reachable.insert(Successor).second)
2841 } while (!Worklist.empty());
2843}
2844
2847
2850
2853
2856 UnwindDest = CRI->getUnwindDest();
2859 CatchSwitch->getParentPad(), nullptr, CatchSwitch->getNumHandlers(),
2860 CatchSwitch->getName(), CatchSwitch->getIterator());
2861 for (BasicBlock *PadBB : CatchSwitch->handlers())
2862 NewCatchSwitch->addHandler(PadBB);
2863
2864 NewTI = NewCatchSwitch;
2865 UnwindDest = CatchSwitch->getUnwindDest();
2866 } else {
2868 }
2869
2875 if (DTU)
2877 return NewTI;
2878}
2879
2880
2881
2882
2887
2888
2889 if (Reachable.size() == F.size())
2891
2892 assert(Reachable.size() < F.size());
2893
2894
2897
2898 if (Reachable.count(&BB))
2899 continue;
2900
2902 continue;
2903 BlocksToRemove.insert(&BB);
2904 }
2905
2906 if (BlocksToRemove.empty())
2908
2910 NumRemoved += BlocksToRemove.size();
2911
2912 if (MSSAU)
2914
2916
2918}
2919
2920
2921
2923 bool DoesKMove, bool AAOnly = false) {
2925 K->getAllMetadataOtherThanDebugLoc(Metadata);
2926 for (const auto &MD : Metadata) {
2927 unsigned Kind = MD.first;
2929 MDNode *KMD = MD.second;
2930
2931
2932 switch (Kind) {
2933 default:
2934 K->setMetadata(Kind, nullptr);
2935 break;
2936 case LLVMContext::MD_dbg:
2937 llvm_unreachable("getAllMetadataOtherThanDebugLoc returned a MD_dbg");
2938 case LLVMContext::MD_DIAssignID:
2939 if (!AAOnly)
2940 K->mergeDIAssignID(J);
2941 break;
2942 case LLVMContext::MD_tbaa:
2943 if (DoesKMove)
2945 break;
2946 case LLVMContext::MD_alias_scope:
2947 if (DoesKMove)
2949 break;
2950 case LLVMContext::MD_noalias:
2951 case LLVMContext::MD_mem_parallel_loop_access:
2952 if (DoesKMove)
2954 break;
2955 case LLVMContext::MD_access_group:
2956 if (DoesKMove)
2957 K->setMetadata(LLVMContext::MD_access_group,
2959 break;
2960 case LLVMContext::MD_range:
2961 if (!AAOnly && (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef)))
2963 break;
2964 case LLVMContext::MD_fpmath:
2965 if (!AAOnly)
2967 break;
2968 case LLVMContext::MD_invariant_load:
2969
2970
2971 if (DoesKMove)
2972 K->setMetadata(Kind, JMD);
2973 break;
2974 case LLVMContext::MD_nonnull:
2975 if (!AAOnly && (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef)))
2976 K->setMetadata(Kind, JMD);
2977 break;
2978 case LLVMContext::MD_invariant_group:
2979
2980 break;
2981
2982
2983
2984 case LLVMContext::MD_prof:
2985 case LLVMContext::MD_mmra:
2986 case LLVMContext::MD_memprof:
2987 case LLVMContext::MD_callsite:
2988 break;
2989 case LLVMContext::MD_callee_type:
2990 if (!AAOnly) {
2991 K->setMetadata(LLVMContext::MD_callee_type,
2993 }
2994 break;
2995 case LLVMContext::MD_align:
2996 if (!AAOnly && (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef)))
2997 K->setMetadata(
2999 break;
3000 case LLVMContext::MD_dereferenceable:
3001 case LLVMContext::MD_dereferenceable_or_null:
3002 if (!AAOnly && DoesKMove)
3003 K->setMetadata(Kind,
3005 break;
3006 case LLVMContext::MD_preserve_access_index:
3007
3008 break;
3009 case LLVMContext::MD_noundef:
3010
3011 if (!AAOnly && DoesKMove)
3012 K->setMetadata(Kind, JMD);
3013 break;
3014 case LLVMContext::MD_nontemporal:
3015
3016 if (!AAOnly)
3017 K->setMetadata(Kind, JMD);
3018 break;
3019 case LLVMContext::MD_noalias_addrspace:
3020 if (DoesKMove)
3021 K->setMetadata(Kind,
3023 break;
3024 case LLVMContext::MD_nosanitize:
3025
3026 K->setMetadata(Kind, JMD);
3027 break;
3028 }
3029 }
3030
3031
3032
3033
3034
3035
3036 if (auto *JMD = J->getMetadata(LLVMContext::MD_invariant_group))
3038 K->setMetadata(LLVMContext::MD_invariant_group, JMD);
3039
3040
3041
3042
3043 auto JMMRA = J->getMetadata(LLVMContext::MD_mmra);
3044 auto KMMRA = K->getMetadata(LLVMContext::MD_mmra);
3045 if (JMMRA || KMMRA) {
3046 K->setMetadata(LLVMContext::MD_mmra,
3048 }
3049
3050
3051
3052
3053 auto *JMemProf = J->getMetadata(LLVMContext::MD_memprof);
3054 auto *KMemProf = K->getMetadata(LLVMContext::MD_memprof);
3055 if (!AAOnly && (JMemProf || KMemProf)) {
3056 K->setMetadata(LLVMContext::MD_memprof,
3058 }
3059
3060
3061
3062
3063 auto *JCallSite = J->getMetadata(LLVMContext::MD_callsite);
3064 auto *KCallSite = K->getMetadata(LLVMContext::MD_callsite);
3065 if (!AAOnly && (JCallSite || KCallSite)) {
3066 K->setMetadata(LLVMContext::MD_callsite,
3068 }
3069
3070
3071
3072
3073 auto *JProf = J->getMetadata(LLVMContext::MD_prof);
3074 auto *KProf = K->getMetadata(LLVMContext::MD_prof);
3075 if (!AAOnly && (JProf || KProf)) {
3076 K->setMetadata(LLVMContext::MD_prof,
3078 }
3079}
3080
3082 bool DoesKMove) {
3084}
3085
3089
3092 Source.getAllMetadata(MD);
3095 const DataLayout &DL = Source.getDataLayout();
3096 for (const auto &MDPair : MD) {
3097 unsigned ID = MDPair.first;
3098 MDNode *N = MDPair.second;
3099
3100
3101
3102
3103
3104
3105
3106 switch (ID) {
3107 case LLVMContext::MD_dbg:
3108 case LLVMContext::MD_tbaa:
3109 case LLVMContext::MD_prof:
3110 case LLVMContext::MD_fpmath:
3111 case LLVMContext::MD_tbaa_struct:
3112 case LLVMContext::MD_invariant_load:
3113 case LLVMContext::MD_alias_scope:
3114 case LLVMContext::MD_noalias:
3115 case LLVMContext::MD_nontemporal:
3116 case LLVMContext::MD_mem_parallel_loop_access:
3117 case LLVMContext::MD_access_group:
3118 case LLVMContext::MD_noundef:
3119 case LLVMContext::MD_noalias_addrspace:
3120
3122 break;
3123
3124 case LLVMContext::MD_nonnull:
3126 break;
3127
3128 case LLVMContext::MD_align:
3129 case LLVMContext::MD_dereferenceable:
3130 case LLVMContext::MD_dereferenceable_or_null:
3131
3134 break;
3135
3136 case LLVMContext::MD_range:
3138 break;
3139 }
3140 }
3141}
3142
3145 if (!ReplInst)
3146 return;
3147
3148
3149
3151
3152
3156
3157
3158
3159
3161 ReplInst->andIRFlags(I);
3162
3163
3166 bool Success = CB1->tryIntersectAttributes(CB2);
3167 assert(Success && "We should not be trying to sink callbases "
3168 "with non-intersectable attributes");
3169
3171 }
3172 }
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3184}
3185
3186template
3188 const ShouldReplaceFn &ShouldReplace) {
3190
3191 unsigned Count = 0;
3194 if (II && II->getIntrinsicID() == Intrinsic::fake_use)
3195 continue;
3196 if (!ShouldReplace(U))
3197 continue;
3200 dbgs() << "' with " << *To << " in " << *U.getUser() << "\n");
3201 U.set(To);
3203 }
3205}
3206
3210 unsigned Count = 0;
3211
3214 if (I->getParent() == BB)
3215 continue;
3216 U.set(To);
3218 }
3220}
3221
3225 auto Dominates = [&](const Use &U) { return DT.dominates(Root, U); };
3226 return ::replaceDominatedUsesWith(From, To, Dominates);
3227}
3228
3232 auto Dominates = [&](const Use &U) { return DT.dominates(BB, U); };
3233 return ::replaceDominatedUsesWith(From, To, Dominates);
3234}
3235
3239 auto DominatesAndShouldReplace = [&](const Use &U) {
3240 return DT.dominates(Root, U) && ShouldReplace(U, To);
3241 };
3242 return ::replaceDominatedUsesWith(From, To, DominatesAndShouldReplace);
3243}
3244
3248 auto DominatesAndShouldReplace = [&](const Use &U) {
3249 return DT.dominates(BB, U) && ShouldReplace(U, To);
3250 };
3251 return ::replaceDominatedUsesWith(From, To, DominatesAndShouldReplace);
3252}
3253
3256
3257 if (Call->hasFnAttr("gc-leaf-function"))
3258 return true;
3259 if (const Function *F = Call->getCalledFunction()) {
3260 if (F->hasFnAttribute("gc-leaf-function"))
3261 return true;
3262
3263 if (auto IID = F->getIntrinsicID()) {
3264
3265 return IID != Intrinsic::experimental_gc_statepoint &&
3266 IID != Intrinsic::experimental_deoptimize &&
3267 IID != Intrinsic::memcpy_element_unordered_atomic &&
3268 IID != Intrinsic::memmove_element_unordered_atomic;
3269 }
3270 }
3271
3272
3273
3274
3277 return TLI.has(LF);
3278 }
3279
3280 return false;
3281}
3282
3285 auto *NewTy = NewLI.getType();
3286
3287
3288 if (NewTy->isPointerTy()) {
3289 NewLI.setMetadata(LLVMContext::MD_nonnull, N);
3290 return;
3291 }
3292
3293
3294
3295 if (!NewTy->isIntegerTy())
3296 return;
3297
3304 NewLI.setMetadata(LLVMContext::MD_range,
3306}
3307
3310 auto *NewTy = NewLI.getType();
3311
3312 if (NewTy == OldLI.getType()) {
3313 NewLI.setMetadata(LLVMContext::MD_range, N);
3314 return;
3315 }
3316
3317
3318
3319
3320
3321 if (!NewTy->isPointerTy())
3322 return;
3323
3324 unsigned BitWidth = DL.getPointerTypeSizeInBits(NewTy);
3328 NewLI.setMetadata(LLVMContext::MD_nonnull, NN);
3329 }
3330}
3331
3335 for (auto *DVR : DPUsers)
3336 DVR->eraseFromParent();
3337}
3338
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3368 I->dropUBImplyingAttrsAndMetadata();
3369 if (I->isUsedByMetadata())
3371
3372 I->dropDbgRecords();
3373 if (I->isDebugOrPseudoInst()) {
3374
3375 II = I->eraseFromParent();
3376 continue;
3377 }
3379 ++II;
3380 }
3383}
3384
3387
3388 auto createIntegerExpression = [&DIB](const Constant &CV) -> DIExpression * {
3390 std::optional<int64_t> InitIntOpt = API.trySExtValue();
3392 static_cast<uint64_t>(*InitIntOpt))
3393 : nullptr;
3394 };
3395
3397 return createIntegerExpression(C);
3398
3400 if (FP && Ty.isFloatingPointTy() && Ty.getScalarSizeInBits() <= 64) {
3401 const APFloat &APF = FP->getValueAPF();
3406 }
3407
3408 if (!Ty.isPointerTy())
3409 return nullptr;
3410
3413
3415 if (CE->getOpcode() == Instruction::IntToPtr) {
3416 const Value *V = CE->getOperand(0);
3418 return createIntegerExpression(*CI);
3419 }
3420 return nullptr;
3421}
3422
3424 auto RemapDebugOperands = [&Mapping](auto *DV, auto Set) {
3425 for (auto *Op : Set) {
3426 auto I = Mapping.find(Op);
3428 DV->replaceVariableLocationOp(Op, I->second, true);
3429 }
3430 };
3431 auto RemapAssignAddress = [&Mapping](auto *DA) {
3432 auto I = Mapping.find(DA->getAddress());
3434 DA->setAddress(I->second);
3435 };
3437 RemapDebugOperands(&DVR, DVR.location_ops());
3438 if (DVR.isDbgAssign())
3439 RemapAssignAddress(&DVR);
3440 }
3441}
3442
3443namespace {
3444
3445
3446
3447struct BitPart {
3448 BitPart(Value *P, unsigned BW) : Provider(P) {
3450 }
3451
3452
3453 Value *Provider;
3454
3455
3456
3458
3459 enum { Unset = -1 };
3460};
3461
3462}
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491static const std::optional &
3493 std::map<Value *, std::optional> &BPS, int Depth,
3494 bool &FoundRoot) {
3495 auto [I, Inserted] = BPS.try_emplace(V);
3496 if (!Inserted)
3497 return I->second;
3498
3499 auto &Result = I->second;
3500 auto BitWidth = V->getType()->getScalarSizeInBits();
3501
3502
3504 return Result;
3505
3506
3508 LLVM_DEBUG(dbgs() << "collectBitParts max recursion depth reached.\n");
3509 return Result;
3510 }
3511
3515
3516
3518
3519 const auto &A = collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS,
3520 Depth + 1, FoundRoot);
3521 if ( ||
->Provider)
3522 return Result;
3523
3524 const auto &B = collectBitParts(Y, MatchBSwaps, MatchBitReversals, BPS,
3525 Depth + 1, FoundRoot);
3526 if ( || A->Provider != B->Provider)
3527 return Result;
3528
3529
3530 Result = BitPart(A->Provider, BitWidth);
3531 for (unsigned BitIdx = 0; BitIdx < BitWidth; ++BitIdx) {
3532 if (A->Provenance[BitIdx] != BitPart::Unset &&
3533 B->Provenance[BitIdx] != BitPart::Unset &&
3534 A->Provenance[BitIdx] != B->Provenance[BitIdx])
3535 return Result = std::nullopt;
3536
3537 if (A->Provenance[BitIdx] == BitPart::Unset)
3538 Result->Provenance[BitIdx] = B->Provenance[BitIdx];
3539 else
3540 Result->Provenance[BitIdx] = A->Provenance[BitIdx];
3541 }
3542
3543 return Result;
3544 }
3545
3546
3548 const APInt &BitShift = *C;
3549
3550
3552 return Result;
3553
3554
3555 if (!MatchBitReversals && (BitShift.getZExtValue() % 8) != 0)
3556 return Result;
3557
3558 const auto &Res = collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS,
3559 Depth + 1, FoundRoot);
3560 if (!Res)
3561 return Result;
3562 Result = Res;
3563
3564
3565 auto &P = Result->Provenance;
3566 if (I->getOpcode() == Instruction::Shl) {
3567 P.erase(std::prev(P.end(), BitShift.getZExtValue()), P.end());
3568 P.insert(P.begin(), BitShift.getZExtValue(), BitPart::Unset);
3569 } else {
3570 P.erase(P.begin(), std::next(P.begin(), BitShift.getZExtValue()));
3571 P.insert(P.end(), BitShift.getZExtValue(), BitPart::Unset);
3572 }
3573
3574 return Result;
3575 }
3576
3577
3578
3580 const APInt &AndMask = *C;
3581
3582
3583
3584 unsigned NumMaskedBits = AndMask.popcount();
3585 if (!MatchBitReversals && (NumMaskedBits % 8) != 0)
3586 return Result;
3587
3588 const auto &Res = collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS,
3589 Depth + 1, FoundRoot);
3590 if (!Res)
3591 return Result;
3592 Result = Res;
3593
3594 for (unsigned BitIdx = 0; BitIdx < BitWidth; ++BitIdx)
3595
3596 if (AndMask[BitIdx] == 0)
3597 Result->Provenance[BitIdx] = BitPart::Unset;
3598 return Result;
3599 }
3600
3601
3603 const auto &Res = collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS,
3604 Depth + 1, FoundRoot);
3605 if (!Res)
3606 return Result;
3607
3608 Result = BitPart(Res->Provider, BitWidth);
3609 auto NarrowBitWidth = X->getType()->getScalarSizeInBits();
3610 for (unsigned BitIdx = 0; BitIdx < NarrowBitWidth; ++BitIdx)
3611 Result->Provenance[BitIdx] = Res->Provenance[BitIdx];
3612 for (unsigned BitIdx = NarrowBitWidth; BitIdx < BitWidth; ++BitIdx)
3613 Result->Provenance[BitIdx] = BitPart::Unset;
3614 return Result;
3615 }
3616
3617
3619 const auto &Res = collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS,
3620 Depth + 1, FoundRoot);
3621 if (!Res)
3622 return Result;
3623
3624 Result = BitPart(Res->Provider, BitWidth);
3625 for (unsigned BitIdx = 0; BitIdx < BitWidth; ++BitIdx)
3626 Result->Provenance[BitIdx] = Res->Provenance[BitIdx];
3627 return Result;
3628 }
3629
3630
3631
3633 const auto &Res = collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS,
3634 Depth + 1, FoundRoot);
3635 if (!Res)
3636 return Result;
3637
3638 Result = BitPart(Res->Provider, BitWidth);
3639 for (unsigned BitIdx = 0; BitIdx < BitWidth; ++BitIdx)
3640 Result->Provenance[(BitWidth - 1) - BitIdx] = Res->Provenance[BitIdx];
3641 return Result;
3642 }
3643
3644
3646 const auto &Res = collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS,
3647 Depth + 1, FoundRoot);
3648 if (!Res)
3649 return Result;
3650
3651 unsigned ByteWidth = BitWidth / 8;
3652 Result = BitPart(Res->Provider, BitWidth);
3653 for (unsigned ByteIdx = 0; ByteIdx < ByteWidth; ++ByteIdx) {
3654 unsigned ByteBitOfs = ByteIdx * 8;
3655 for (unsigned BitIdx = 0; BitIdx < 8; ++BitIdx)
3656 Result->Provenance[(BitWidth - 8 - ByteBitOfs) + BitIdx] =
3657 Res->Provenance[ByteBitOfs + BitIdx];
3658 }
3659 return Result;
3660 }
3661
3662
3663
3664
3665
3668
3669 unsigned ModAmt = C->urem(BitWidth);
3672
3673
3674 if (!MatchBitReversals && (ModAmt % 8) != 0)
3675 return Result;
3676
3677
3678 const auto &LHS = collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS,
3679 Depth + 1, FoundRoot);
3680 if ( ||
->Provider)
3681 return Result;
3682
3683 const auto &RHS = collectBitParts(Y, MatchBSwaps, MatchBitReversals, BPS,
3684 Depth + 1, FoundRoot);
3685 if ( || LHS->Provider != RHS->Provider)
3686 return Result;
3687
3688 unsigned StartBitRHS = BitWidth - ModAmt;
3689 Result = BitPart(LHS->Provider, BitWidth);
3690 for (unsigned BitIdx = 0; BitIdx < StartBitRHS; ++BitIdx)
3691 Result->Provenance[BitIdx + ModAmt] = LHS->Provenance[BitIdx];
3692 for (unsigned BitIdx = 0; BitIdx < ModAmt; ++BitIdx)
3693 Result->Provenance[BitIdx] = RHS->Provenance[BitIdx + StartBitRHS];
3694 return Result;
3695 }
3696 }
3697
3698
3699
3700 if (FoundRoot)
3701 return Result;
3702
3703
3704
3705 FoundRoot = true;
3706 Result = BitPart(V, BitWidth);
3707 for (unsigned BitIdx = 0; BitIdx < BitWidth; ++BitIdx)
3708 Result->Provenance[BitIdx] = BitIdx;
3709 return Result;
3710}
3711
3714 if (From % 8 != To % 8)
3715 return false;
3716
3717 From >>= 3;
3718 To >>= 3;
3720 return From == BitWidth - To - 1;
3721}
3722
3725 return From == BitWidth - To - 1;
3726}
3727
3729 Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
3735 return false;
3736 if (!MatchBSwaps && !MatchBitReversals)
3737 return false;
3738 Type *ITy = I->getType();
3741 return false;
3742
3743
3744 bool FoundRoot = false;
3745 std::map<Value *, std::optional> BPS;
3746 const auto &Res =
3747 collectBitParts(I, MatchBSwaps, MatchBitReversals, BPS, 0, FoundRoot);
3748 if (!Res)
3749 return false;
3752 [](int8_t I) { return I == BitPart::Unset || 0 <= I; }) &&
3753 "Illegal bit provenance index");
3754
3755
3756 Type *DemandedTy = ITy;
3757 if (BitProvenance.back() == BitPart::Unset) {
3758 while (!BitProvenance.empty() && BitProvenance.back() == BitPart::Unset)
3759 BitProvenance = BitProvenance.drop_back();
3760 if (BitProvenance.empty())
3761 return false;
3765 }
3766
3767
3770 return false;
3771
3772
3773
3775 bool OKForBSwap = MatchBSwaps && (DemandedBW % 16) == 0;
3776 bool OKForBitReverse = MatchBitReversals;
3777 for (unsigned BitIdx = 0;
3778 (BitIdx < DemandedBW) && (OKForBSwap || OKForBitReverse); ++BitIdx) {
3779 if (BitProvenance[BitIdx] == BitPart::Unset) {
3780 DemandedMask.clearBit(BitIdx);
3781 continue;
3782 }
3784 DemandedBW);
3786 BitIdx, DemandedBW);
3787 }
3788
3790 if (OKForBSwap)
3791 Intrin = Intrinsic::bswap;
3792 else if (OKForBitReverse)
3793 Intrin = Intrinsic::bitreverse;
3794 else
3795 return false;
3796
3799 Value *Provider = Res->Provider;
3800
3801
3802 if (DemandedTy != Provider->getType()) {
3803 auto *Trunc =
3806 Provider = Trunc;
3807 }
3808
3810 InsertedInsts.push_back(Result);
3811
3812 if (!DemandedMask.isAllOnes()) {
3813 auto *Mask = ConstantInt::get(DemandedTy, DemandedMask);
3814 Result = BinaryOperator::Create(Instruction::And, Result, Mask, "mask", I->getIterator());
3815 InsertedInsts.push_back(Result);
3816 }
3817
3818
3819 if (ITy != Result->getType()) {
3821 InsertedInsts.push_back(ExtInst);
3822 }
3823
3824 return true;
3825}
3826
3827
3828
3829
3830
3831
3836 if (F && ->hasLocalLinkage() && F->hasName() &&
3838 ->doesNotAccessMemory())
3839 CI->addFnAttr(Attribute::NoBuiltin);
3840}
3841
3843 const auto *Op = I->getOperand(OpIdx);
3844
3845 if (Op->getType()->isMetadataTy() || Op->getType()->isTokenLikeTy())
3846 return false;
3847
3848
3849
3850
3851 if (Op->isSwiftError())
3852 return false;
3853
3854
3855 if (I->isLifetimeStartOrEnd())
3856 return false;
3857
3858
3860 return true;
3861
3862 switch (I->getOpcode()) {
3863 default:
3864 return true;
3865 case Instruction::Call:
3866 case Instruction::Invoke: {
3868
3869
3870 if (CB.isInlineAsm())
3871 return false;
3872
3873
3874
3875 if (CB.isBundleOperand(OpIdx))
3876 return false;
3877
3878 if (OpIdx < CB.arg_size()) {
3879
3880
3882 OpIdx >= CB.getFunctionType()->getNumParams()) {
3883
3884 return CB.getIntrinsicID() == Intrinsic::experimental_stackmap;
3885 }
3886
3887
3888
3889 if (CB.getIntrinsicID() == Intrinsic::gcroot)
3890 return false;
3891
3892
3893 return !CB.paramHasAttr(OpIdx, Attribute::ImmArg);
3894 }
3895
3896
3897
3899 }
3900 case Instruction::ShuffleVector:
3901
3902 return OpIdx != 2;
3903 case Instruction::Switch:
3904 case Instruction::ExtractValue:
3905
3906 return OpIdx == 0;
3907 case Instruction::InsertValue:
3908
3909 return OpIdx < 2;
3910 case Instruction::Alloca:
3911
3912
3913
3915 case Instruction::GetElementPtr:
3917 return true;
3919 for (auto E = std::next(It, OpIdx); It != E; ++It)
3921 return false;
3922 return true;
3923 }
3924}
3925
3927
3930
3931
3932 Value *NotCondition;
3934 return NotCondition;
3935
3938 if (Inst)
3942 assert(Parent && "Unsupported condition to invert");
3943
3944
3945 for (User *U : Condition->users())
3948 return I;
3949
3950
3951 auto *Inverted =
3954 Inverted->insertAfter(Inst->getIterator());
3955 else
3957 return Inverted;
3958}
3959
3961
3962
3963
3965
3966 if (.hasFnAttribute(Attribute::NoSync) &&
3967 F.doesNotAccessMemory() && .isConvergent()) {
3968 F.setNoSync();
3970 }
3971
3972
3973 if (.hasFnAttribute(Attribute::NoFree) && F.onlyReadsMemory()) {
3974 F.setDoesNotFreeMemory();
3976 }
3977
3978
3979 if (.hasFnAttribute(Attribute::MustProgress) && F.willReturn()) {
3980 F.setMustProgress();
3982 }
3983
3984
3985
3986
3988}
3989
3991#ifndef NDEBUG
3994 "can only use mergeFlags on instructions with matching opcodes");
3995 else
3997#endif
3999 HasNUW &= I.hasNoUnsignedWrap();
4000 HasNSW &= I.hasNoSignedWrap();
4001 }
4003 IsDisjoint &= DisjointOp->isDisjoint();
4004}
4005
4007 I.clearSubclassOptionalData();
4008 if (I.getOpcode() == Instruction::Add ||
4011 I.setHasNoUnsignedWrap();
4013 I.setHasNoSignedWrap();
4014 }
4016 DisjointOp->setIsDisjoint(IsDisjoint);
4017}
static unsigned getIntrinsicID(const SDNode *N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
ReachingDefAnalysis InstSet & ToRemove
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool isEqual(const Function &Caller, const Function &Callee)
This file contains the simple types necessary to represent the attributes associated with functions a...
static const Function * getParent(const Value *V)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool isSentinel(const DWARFDebugNames::AttributeEncoding &AE)
This file defines DenseMapInfo traits for DenseMap.
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This file contains constants used for implementing Dwarf debug support.
static unsigned getHashValueImpl(SimpleValue Val)
static bool isEqualImpl(SimpleValue LHS, SimpleValue RHS)
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Module.h This file contains the declarations for the Module class.
This defines the Use class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
Remove Loads Into Fake Uses
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
SmallDenseMap< BasicBlock *, Value *, 16 > IncomingValueMap
Definition Local.cpp:912
static bool valueCoversEntireFragment(Type *ValTy, DbgVariableRecord *DVR)
Check if the alloc size of ValTy is large enough to cover the variable (or fragment of the variable) ...
Definition Local.cpp:1620
static bool markAliveBlocks(Function &F, SmallPtrSetImpl< BasicBlock * > &Reachable, DomTreeUpdater *DTU=nullptr)
Definition Local.cpp:2646
static bool isBitCastSemanticsPreserving(const DataLayout &DL, Type *FromTy, Type *ToTy)
Check if a bitcast between a value of type FromTy to type ToTy would losslessly preserve the bits and...
Definition Local.cpp:2396
static bool isStructure(AllocaInst *AI)
Determine whether this alloca is a structure.
Definition Local.cpp:1758
uint64_t getDwarfOpForBinOp(Instruction::BinaryOps Opcode)
Definition Local.cpp:2144
static bool PhiHasDebugValue(DILocalVariable *DIVar, DIExpression *DIExpr, PHINode *APN)
===------------------------------------------------------------------—===// Dbg Intrinsic utilities
Definition Local.cpp:1596
static void gatherIncomingValuesToPhi(PHINode *PN, IncomingValueMap &IncomingValues)
Create a map from block to value for the operands of a given phi.
Definition Local.cpp:951
static void combineMetadata(Instruction *K, const Instruction *J, bool DoesKMove, bool AAOnly=false)
If AAOnly is set, only intersect alias analysis metadata and preserve other known metadata.
Definition Local.cpp:2922
static void handleSSAValueOperands(uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Opcodes, SmallVectorImpl< Value * > &AdditionalValues, Instruction *I)
Definition Local.cpp:2174
std::optional< DIExpression * > DbgValReplacement
A replacement for a dbg.value expression.
Definition Local.cpp:2323
static bool rewriteDebugUsers(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT, function_ref< DbgValReplacement(DbgVariableRecord &DVR)> RewriteDVRExpr)
Point debug users of From to To using exprs given by RewriteExpr, possibly moving/undefing users to p...
Definition Local.cpp:2328
Value * getSalvageOpsForBinOp(BinaryOperator *BI, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Opcodes, SmallVectorImpl< Value * > &AdditionalValues)
Definition Local.cpp:2186
static DIExpression * dropInitialDeref(const DIExpression *DIExpr)
Definition Local.cpp:1656
static void replaceUndefValuesInPhi(PHINode *PN, const IncomingValueMap &IncomingValues)
Replace the incoming undef values to a phi with the values from a block-to-value map.
Definition Local.cpp:967
Value * getSalvageOpsForGEP(GetElementPtrInst *GEP, const DataLayout &DL, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Opcodes, SmallVectorImpl< Value * > &AdditionalValues)
Definition Local.cpp:2118
static bool CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ, const SmallPtrSetImpl< BasicBlock * > &BBPreds, BasicBlock *&CommonPred)
Definition Local.cpp:1008
Value * getSalvageOpsForIcmpOp(ICmpInst *Icmp, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Opcodes, SmallVectorImpl< Value * > &AdditionalValues)
Definition Local.cpp:2245
static bool CanMergeValues(Value *First, Value *Second)
Return true if we can choose one of these values to use in place of the other.
Definition Local.cpp:846
static bool simplifyAndDCEInstruction(Instruction *I, SmallSetVector< Instruction *, 16 > &WorkList, const DataLayout &DL, const TargetLibraryInfo *TLI)
Definition Local.cpp:663
static bool isArray(AllocaInst *AI)
Determine whether this alloca is either a VLA or an array.
Definition Local.cpp:1752
static bool areAllUsesEqual(Instruction *I)
areAllUsesEqual - Check whether the uses of a value are all the same.
Definition Local.cpp:622
static cl::opt< bool > PHICSEDebugHash("phicse-debug-hash", cl::init(false), cl::Hidden, cl::desc("Perform extra assertion checking to verify that PHINodes's hash " "function is well-behaved w.r.t. its isEqual predicate"))
uint64_t getDwarfOpForIcmpPred(CmpInst::Predicate Pred)
Definition Local.cpp:2220
static bool bitTransformIsCorrectForBSwap(unsigned From, unsigned To, unsigned BitWidth)
Definition Local.cpp:3712
static const std::optional< BitPart > & collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals, std::map< Value *, std::optional< BitPart > > &BPS, int Depth, bool &FoundRoot)
Analyze the specified subexpression and see if it is capable of providing pieces of a bswap or bitrev...
Definition Local.cpp:3492
static bool EliminateDuplicatePHINodesNaiveImpl(BasicBlock *BB, SmallPtrSetImpl< PHINode * > &ToRemove)
Definition Local.cpp:1377
static bool CanPropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ, const SmallPtrSetImpl< BasicBlock * > &BBPreds)
Return true if we can fold BB, an almost-empty BB ending in an unconditional branch to Succ,...
Definition Local.cpp:855
static cl::opt< unsigned > PHICSENumPHISmallSize("phicse-num-phi-smallsize", cl::init(32), cl::Hidden, cl::desc("When the basic block contains not more than this number of PHI nodes, " "perform a (faster!) exhaustive search instead of set-driven one."))
static void updateOneDbgValueForAlloca(const DebugLoc &Loc, DILocalVariable *DIVar, DIExpression *DIExpr, Value *NewAddress, DbgVariableRecord *DVR, DIBuilder &Builder, int Offset)
Definition Local.cpp:1960
static bool EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB, SmallPtrSetImpl< PHINode * > &ToRemove)
Definition Local.cpp:1413
SmallVector< BasicBlock *, 16 > PredBlockVector
Definition Local.cpp:911
static void insertDbgValueOrDbgVariableRecord(DIBuilder &Builder, Value *DV, DILocalVariable *DIVar, DIExpression *DIExpr, const DebugLoc &NewLoc, BasicBlock::iterator Instr)
Definition Local.cpp:1645
static bool introduceTooManyPhiEntries(BasicBlock *BB, BasicBlock *Succ)
Check whether removing BB will make the phis in its Succ have too many incoming entries.
Definition Local.cpp:1041
static Value * selectIncomingValueForBlock(Value *OldVal, BasicBlock *BB, IncomingValueMap &IncomingValues)
Determines the value to use as the phi node input for a block.
Definition Local.cpp:926
static const unsigned BitPartRecursionMaxDepth
Definition Local.cpp:121
static void redirectValuesFromPredecessorsToPhi(BasicBlock *BB, const PredBlockVector &BBPreds, PHINode *PN, BasicBlock *CommonPred)
Replace a value flowing from a block to a phi with potentially multiple instances of that value flowi...
Definition Local.cpp:1073
static cl::opt< unsigned > MaxPhiEntriesIncreaseAfterRemovingEmptyBlock("max-phi-entries-increase-after-removing-empty-block", cl::init(1000), cl::Hidden, cl::desc("Stop removing an empty block if removing it will introduce more " "than this number of phi entries in its successor"))
static bool bitTransformIsCorrectForBitReverse(unsigned From, unsigned To, unsigned BitWidth)
Definition Local.cpp:3723
static void salvageDbgAssignAddress(T *Assign)
Definition Local.cpp:2002
LocallyHashedType DenseMapInfo< LocallyHashedType >::Empty
APInt bitcastToAPInt() const
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
uint64_t getZExtValue() const
Get zero extended value.
unsigned popcount() const
Count the number of bits set.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
std::optional< int64_t > trySExtValue() const
Get sign extended value if possible.
int64_t getSExtValue() const
Get sign extended value.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
an instruction to allocate memory on the stack
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
LLVM_ABI bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & back() const
back - Get the last element.
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
size_t size() const
size - Get the array size.
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
bool empty() const
empty - Check if the array is empty.
Value handle that asserts if the Value is deleted.
A cache of @llvm.assume calls within a function.
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_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.
LLVM_ABI void insertDbgRecordBefore(DbgRecord *DR, InstListType::iterator Here)
Insert a DbgRecord into a block at the position given by Here.
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 void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
LLVM_ABI bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
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 void flushTerminatorDbgRecords()
Eject any debug-info trailing at the end of a block.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
LLVM_ABI SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
InstListType::iterator iterator
Instruction iterators...
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
LLVM_ABI bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
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.
BinaryOps getOpcode() const
static LLVM_ABI BinaryOperator * CreateNot(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
This class represents a no-op cast from one type to another.
The address of a basic block.
static LLVM_ABI BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
void setCallingConv(CallingConv::ID CC)
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
LLVM_ABI void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
void setAttributes(AttributeList A)
Set the attributes for this call.
FunctionType * getFunctionType() const
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
AttributeList getAttributes() const
Return the attributes for this call.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
mapped_iterator< op_iterator, DerefFnTy > handler_iterator
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, InsertPosition InsertBefore=nullptr)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ ICMP_ULT
unsigned less than
@ ICMP_SGE
signed greater or equal
@ ICMP_ULE
unsigned less or equal
Predicate getPredicate() const
Return the predicate for this instruction.
A constant value that is initialized with an expression using other constant values.
static LLVM_ABI Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getNot(Constant *C)
static LLVM_ABI Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
This is the shared class of boolean and integer constants.
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
This is an important base class in LLVM.
LLVM_ABI void destroyConstant()
Called if some element of this constant is no longer valid.
DIExpression * createConstantValueExpression(uint64_t Val)
Create an expression for a variable that does not have an address, but does have a constant value.
static LLVM_ABI DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
unsigned getNumElements() const
static LLVM_ABI ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed)
Returns the ops for a zero- or sign-extension in a DIExpression.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
static LLVM_ABI DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
static LLVM_ABI std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
LLVM_ABI DIExpression * foldConstantMath()
Try to shorten an expression with constant math operations that can be evaluated at compile time.
LLVM_ABI uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
ArrayRef< uint64_t > getElements() const
LLVM_ABI std::optional< uint64_t > getActiveBits(DIVariable *Var)
Return the number of bits that have an active value, i.e.
uint64_t getElement(unsigned I) const
static LLVM_ABI DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
static LLVM_ABI DIExpression * appendExt(const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
Append a zero- or sign-extension to Expr.
std::optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable's type, or std::nullopt if this type is neither signed nor uns...
A parsed version of the target data layout string in and methods for querying it.
This represents the llvm.dbg.label instruction.
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
LLVM_ABI void removeFromParent()
LLVM_ABI Module * getModule()
Record of a variable value-assignment, aka a non instruction representation of the dbg....
bool isAddressOfVariable() const
Does this describe the address of a local variable.
LLVM_ABI DbgVariableRecord * clone() const
void setExpression(DIExpression *NewExpr)
DIExpression * getExpression() const
LLVM_ABI Value * getVariableLocationOp(unsigned OpIdx) const
DILocalVariable * getVariable() const
LLVM_ABI unsigned getNumVariableLocationOps() const
LLVM_ABI void replaceVariableLocationOp(Value *OldValue, Value *NewValue, bool AllowEmpty=false)
LLVM_ABI iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
LLVM_ABI DILocation * get() const
Get the underlying DILocation.
static DebugLoc getTemporary()
iterator find(const_arg_type_t< KeyT > Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
LLVM_ABI void deleteBB(BasicBlock *DelBB)
Delete DelBB.
static constexpr UpdateKind Delete
static constexpr UpdateKind Insert
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
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.
const BasicBlock & getEntryBlock() const
void applyUpdatesPermissive(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
void applyUpdates(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
bool hasDomTree() const
Returns true if it holds a DomTreeT.
void recalculate(FuncT &F)
Notify DTU that the entry block was replaced.
bool isBBPendingDeletion(BasicBlockT *DelBB) const
Returns true if DelBB is awaiting deletion.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
This instruction compares its operands according to the predicate given to the constructor.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange() const
Return a range over the DbgRecords attached to this instruction.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
LLVM_ABI bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
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.
LLVM_ABI bool isIdenticalToWhenDefined(const Instruction *I, bool IntersectAttrs=false) const LLVM_READONLY
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM_ABI void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM_ABI void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
LLVM_ABI void dropDbgRecords()
Erase any DbgRecords attached to this instruction.
A wrapper class for inspecting calls to intrinsic functions.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
Value * getPointerOperand()
LLVM_ABI MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
LLVM_ABI MDNode * createRange(const APInt &Lo, const APInt &Hi)
Return metadata describing the range [Lo, Hi).
static LLVM_ABI MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
static LLVM_ABI MDNode * getMergedCallsiteMetadata(MDNode *A, MDNode *B)
static LLVM_ABI MDNode * getMergedCalleeTypeMetadata(const MDNode *A, const MDNode *B)
static LLVM_ABI MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
static LLVM_ABI MDNode * getMostGenericNoaliasAddrspace(MDNode *A, MDNode *B)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static LLVM_ABI MDNode * getMergedProfMetadata(MDNode *A, MDNode *B, const Instruction *AInstr, const Instruction *BInstr)
Merge !prof metadata from two instructions.
static LLVM_ABI MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
static LLVM_ABI MDNode * getMostGenericRange(MDNode *A, MDNode *B)
static LLVM_ABI MDNode * getMergedMemProfMetadata(MDNode *A, MDNode *B)
static LLVM_ABI MDNode * intersect(MDNode *A, MDNode *B)
LLVMContext & getContext() const
static LLVM_ABI MDNode * getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B)
This class implements a map that also provides access to all stored values in a deterministic order.
iterator find(const KeyT &Key)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
LLVM_ABI void changeToUnreachable(const Instruction *I)
Instruction I will be changed to an unreachable.
LLVM_ABI void removeBlocks(const SmallSetVector< BasicBlock *, 8 > &DeadBlocks)
Remove all MemoryAcceses in a set of BasicBlocks about to be deleted.
LLVM_ABI void removeMemoryAccess(MemoryAccess *, bool OptimizePhis=false)
Remove a MemoryAccess from MemorySSA, including updating all definitions and uses.
A Module instance is used to store all the information related to an LLVM module.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
iterator_range< const_block_iterator > blocks() const
LLVM_ABI Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
void setIncomingValue(unsigned i, Value *V)
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 LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
size_type size() const
Determine the number of elements in the SetVector.
Vector takeVector()
Clear the SetVector and return the underlying vector.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
value_type pop_back_val()
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
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.
A SetVector that performs no allocations if smaller than a certain size.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Provides information about what library functions are available for the current target.
bool hasOptimizedCodeGen(LibFunc F) const
Tests if the function is both available and a candidate for optimized code generation.
bool has(LibFunc F) const
Tests whether a library function is available.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
static constexpr TypeSize getFixed(ScalarTy ExactSize)
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
bool isArrayTy() const
True if this is an instance of ArrayType.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isStructTy() const
True if this is an instance of StructType.
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isTokenTy() const
Return true if this is 'token'.
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
value_op_iterator value_op_end()
Value * getOperand(unsigned i) const
value_op_iterator value_op_begin()
iterator_range< value_op_iterator > operand_values()
iterator find(const KeyT &Val)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
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.
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
LLVM_ABI void replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
iterator_range< use_iterator > uses()
user_iterator_impl< User > user_iterator
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.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Represents an op.with.overflow intrinsic.
std::pair< iterator, bool > insert(const ValueT &V)
void reserve(size_t Size)
Grow the DenseSet so that it can contain at least NumEntries items before resizing again.
static constexpr bool isKnownGE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
self_iterator getIterator()
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
bool match(Val *V, const Pattern &P)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
ExtractValue_match< Ind, Val_t > m_ExtractValue(const Val_t &V)
Match a single index ExtractValue instruction.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
bind_ty< WithOverflowInst > m_WithOverflowInst(WithOverflowInst *&I)
Match a with overflow intrinsic, capturing it if we match.
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
auto m_Undef()
Match an arbitrary undef constant.
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
initializer< Ty > init(const Ty &Val)
@ DW_OP_LLVM_arg
Only used in LLVM metadata.
@ ebStrict
This corresponds to "fpexcept.strict".
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool RemoveRedundantDbgInstrs(BasicBlock *BB)
Try to remove redundant dbg.value instructions from given basic block.
UnaryFunction for_each(R &&Range, UnaryFunction F)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB)
Remove all instructions from a basic block other than its terminator and any present EH pad instructi...
Definition Local.cpp:2485
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
Definition Local.cpp:533
bool succ_empty(const Instruction *I)
LLVM_ABI BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge, DomTreeUpdater *DTU=nullptr)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
Definition Local.cpp:2603
LLVM_ABI bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DomTreeUpdater *DTU=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
Definition Local.cpp:134
LLVM_ABI unsigned replaceDominatedUsesWithIf(Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge, function_ref< bool(const Use &U, const Value *To)> ShouldReplace)
Replace each use of 'From' with 'To' if that use is dominated by the given edge and the callback Shou...
Definition Local.cpp:3236
LLVM_ABI void findDbgValues(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)
Finds the dbg.values describing a value.
LLVM_ABI unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Definition Local.cpp:3207
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
auto successors(const MachineBasicBlock *BB)
LLVM_ABI bool isRemovableAlloc(const CallBase *V, const TargetLibraryInfo *TLI)
Return true if this is a call to an allocation function that does not have side effects that we are r...
LLVM_ABI CallInst * changeToCall(InvokeInst *II, DomTreeUpdater *DTU=nullptr)
This function converts the specified invoke into a normal call.
Definition Local.cpp:2579
LLVM_ABI bool isMathLibCallNoop(const CallBase *Call, const TargetLibraryInfo *TLI)
Check whether the given call has no side-effects.
LLVM_ABI void copyMetadataForLoad(LoadInst &Dest, const LoadInst &Source)
Copy the metadata from the source instruction to the destination (the replacement for the source inst...
Definition Local.cpp:3090
LLVM_ABI void InsertDebugValueAtStoreLoc(DbgVariableRecord *DVR, StoreInst *SI, DIBuilder &Builder)
===------------------------------------------------------------------—===// Dbg Intrinsic utilities
Definition Local.cpp:1708
constexpr from_range_t from_range
bool hasNItemsOrLess(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;})
Returns true if the sequence [Begin, End) has N or less items.
LLVM_ABI void remapDebugVariable(ValueToValueMapTy &Mapping, Instruction *Inst)
Remap the operands of the debug records attached to Inst, and the operands of Inst itself if it's a d...
Definition Local.cpp:3423
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 bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Scan the specified basic block and try to simplify any instructions in it and recursively delete dead...
Definition Local.cpp:721
LLVM_ABI bool isAssumeWithEmptyBundle(const AssumeInst &Assume)
Return true iff the operand bundles of the provided llvm.assume doesn't contain any valuable informat...
LLVM_ABI void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified block, which must have no predecessors.
LLVM_ABI bool hasBranchWeightOrigin(const Instruction &I)
Check if Branch Weight Metadata has an "expected" field from an llvm.expect* intrinsic.
LLVM_ABI void insertDebugValuesForPHIs(BasicBlock *BB, SmallVectorImpl< PHINode * > &InsertedPHIs)
Propagate dbg.value intrinsics through the newly inserted PHIs.
Definition Local.cpp:1879
LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
LLVM_ABI MDNode * intersectAccessGroups(const Instruction *Inst1, const Instruction *Inst2)
Compute the access-group list of access groups that Inst1 and Inst2 are both in.
LLVM_ABI bool handleUnreachableTerminator(Instruction *I, SmallVectorImpl< Value * > &PoisonedValues)
If a terminator in an unreachable basic block has an operand of type Instruction, transform it into p...
Definition Local.cpp:2468
LLVM_ABI bool canSimplifyInvokeNoUnwind(const Function *F)
LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
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 isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
Definition Local.cpp:402
LLVM_ABI bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes,...
Definition Local.cpp:1140
LLVM_ABI bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction * > &InsertedInsts)
Try to match a bswap or bitreverse idiom.
Definition Local.cpp:3728
LLVM_ABI void setBranchWeights(Instruction &I, ArrayRef< uint32_t > Weights, bool IsExpected)
Create a new branch_weights metadata node and add or overwrite a prof metadata reference to instructi...
LLVM_ABI MDNode * getValidBranchWeightMDNode(const Instruction &I)
Get the valid branch weights metadata node.
LLVM_ABI Align getOrEnforceKnownAlignment(Value *V, MaybeAlign PrefAlign, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
Definition Local.cpp:1566
LLVM_ABI bool wouldInstructionBeTriviallyDeadOnUnusedPaths(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction has no side effects on any paths other than whe...
Definition Local.cpp:409
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
LLVM_ABI bool LowerDbgDeclare(Function &F)
Lowers dbg.declare records into appropriate set of dbg.value records.
Definition Local.cpp:1795
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
LLVM_ABI DIExpression * getExpressionForConstant(DIBuilder &DIB, const Constant &C, Type &Ty)
Given a constant, create a debug information expression.
Definition Local.cpp:3385
LLVM_ABI CallInst * createCallMatchingInvoke(InvokeInst *II)
Create a call that matches the invoke II in terms of arguments, attributes, debug information,...
Definition Local.cpp:2553
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
generic_gep_type_iterator<> gep_type_iterator
LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, StoreInst *SI, DIBuilder &Builder)
Inserts a dbg.value record before a store to an alloca'd value that has an associated dbg....
Definition Local.cpp:1662
LLVM_ABI Instruction * removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
Replace 'BB's terminator with one that does not have an unwind successor block.
Definition Local.cpp:2845
LLVM_ABI bool wouldInstructionBeTriviallyDead(const Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction would have no side effects if it was not used.
Definition Local.cpp:421
FunctionAddr VTableAddr Count
LLVM_ABI void patchReplacementInstruction(Instruction *I, Value *Repl)
Patch the replacement so that it is not more restrictive than the value being replaced.
Definition Local.cpp:3143
LLVM_ABI void salvageDebugInfoForDbgValues(Instruction &I, ArrayRef< DbgVariableRecord * > DPInsns)
Implementation of salvageDebugInfo, applying only to instructions in Insns, rather than all debug use...
Definition Local.cpp:2037
LLVM_ABI unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge)
Replace each use of 'From' with 'To' if that use is dominated by the given edge.
Definition Local.cpp:3222
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
@ Success
The lock was released successfully.
LLVM_ABI unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
Definition Local.cpp:2513
LLVM_ABI bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT)
Point debug users of From to To or salvage them.
Definition Local.cpp:2414
LLVM_ABI Value * salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Ops, SmallVectorImpl< Value * > &AdditionalValues)
Definition Local.cpp:2274
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
LLVM_ABI void combineMetadataForCSE(Instruction *K, const Instruction *J, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
Definition Local.cpp:3081
LLVM_ABI void dropDebugUsers(Instruction &I)
Remove the debug intrinsic instructions for the given instruction.
Definition Local.cpp:3332
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
LLVM_ABI void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!...
Definition Local.cpp:761
LLVM_ABI bool replaceDbgUsesWithUndef(Instruction *I)
Replace all the uses of an SSA value in @llvm.dbg intrinsics with undef.
Definition Local.cpp:610
LLVM_ABI void hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt, BasicBlock *BB)
Hoist all of the instructions in the IfBlock to the dominant block DomBlock, by moving its instructio...
Definition Local.cpp:3339
LLVM_ABI void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a range metadata node to a new load instruction.
Definition Local.cpp:3308
LLVM_ABI DebugLoc getDebugValueLoc(DbgVariableRecord *DVR)
Produce a DebugLoc to use for each dbg.declare that is promoted to a dbg.value.
LLVM_ABI void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
Definition Local.cpp:3283
LLVM_ABI bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx)
Given an instruction, is it legal to set operand OpIdx to a non-constant value?
Definition Local.cpp:3842
DWARFExpression::Operation Op
LLVM_ABI void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, int Offset=0)
Replaces multiple dbg.value records when the alloca it describes is replaced with a new value.
Definition Local.cpp:1982
LLVM_ABI Align tryEnforceAlignment(Value *V, Align PrefAlign, const DataLayout &DL)
If the specified pointer points to an object that we control, try to modify the object's alignment to...
Definition Local.cpp:1517
LLVM_ABI Value * getFreedOperand(const CallBase *CB, const TargetLibraryInfo *TLI)
If this if a call to a free function, return the freed operand.
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructionsPermissive(SmallVectorImpl< WeakTrackingVH > &DeadInsts, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
Same functionality as RecursivelyDeleteTriviallyDeadInstructions, but allow instructions that are not...
Definition Local.cpp:548
constexpr unsigned BitWidth
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
LLVM_ABI bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
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.
gep_type_iterator gep_type_begin(const User *GEP)
LLVM_ABI TinyPtrVector< DbgVariableRecord * > findDVRDeclares(Value *V)
Finds dbg.declare records declaring local variables as living in the memory that 'V' points to.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI void combineAAMetadata(Instruction *K, const Instruction *J)
Combine metadata of two instructions, where instruction J is a memory access that has been merged int...
Definition Local.cpp:3086
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...
Definition Local.cpp:641
LLVM_ABI bool inferAttributesFromOthers(Function &F)
If we can infer one attribute from another on the declaration of a function, explicitly materialize t...
Definition Local.cpp:3960
LLVM_ABI Value * invertCondition(Value *Condition)
Invert the given true/false value, possibly reusing an existing copy.
Definition Local.cpp:3926
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
LLVM_ABI void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified blocks from BB.
LLVM_ABI void maybeMarkSanitizerLibraryCallNoBuiltin(CallInst *CI, const TargetLibraryInfo *TLI)
Given a CallInst, check if it calls a string function known to CodeGen, and mark it with NoBuiltin if...
Definition Local.cpp:3832
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
LLVM_ABI bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Remove all blocks that can not be reached from the function's entry.
Definition Local.cpp:2883
LLVM_ABI bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
Definition Local.cpp:1509
LLVM_ABI void findDbgUsers(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)
Finds the debug info records describing a value.
LLVM_ABI bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI)
Return true if this call calls a gc leaf function.
Definition Local.cpp:3254
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
LLVM_ABI bool replaceDbgDeclare(Value *Address, Value *NewAddress, DIBuilder &Builder, uint8_t DIExprFlags, int Offset)
Replaces dbg.declare record when the address it describes is replaced with a new value.
Definition Local.cpp:1942
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
An information struct used to provide DenseMap with the various necessary components for a given valu...
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
unsigned getBitWidth() const
Get the bit width of this value.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
std::optional< unsigned > Opcode
Opcode of merged instructions.
LLVM_ABI void mergeFlags(Instruction &I)
Merge in the no-wrap flags from I.
Definition Local.cpp:3990
LLVM_ABI void applyFlags(Instruction &I)
Apply the no-wrap flags to I if applicable.
Definition Local.cpp:4006
A MapVector that performs no allocations if smaller than a certain size.