LLVM: lib/IR/LegacyPassManager.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
30#include
31
32using namespace llvm;
33
35
36
37
38
39
40
41
42
43
44namespace {
45
46enum PassDebugLevel {
48};
49}
50
53 cl::desc("Print legacy PassManager debugging information"),
56 clEnumVal(Structure, "print pass structure before run()"),
57 clEnumVal(Executions, "print pass name before it is executed"),
58 clEnumVal(Details, "print pass details when it is executed")));
59
60
61
64}
65
67 Module &M, StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount) {
68
70
71
72
74 unsigned FCount = F.getInstructionCount();
75
76
77
78
79
80
81 FunctionToInstrCount[F.getName().str()] =
82 std::pair<unsigned, unsigned>(FCount, 0);
84 }
86}
87
89 Pass *P, Module &M, int64_t Delta, unsigned CountBefore,
90 StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount,
92
93
94
95
96 if (P->getAsPMDataManager())
97 return;
98
99
100 bool CouldOnlyImpactOneFunction = (F != nullptr);
101
102
103 auto UpdateFunctionChanges =
104 [&FunctionToInstrCount](Function &MaybeChangedFn) {
105
106 unsigned FnSize = MaybeChangedFn.getInstructionCount();
107
108
109
110 auto [It, Inserted] = FunctionToInstrCount.try_emplace(
111 MaybeChangedFn.getName(), 0, FnSize);
112 if (Inserted)
113 return;
114
115
116 It->second.second = FnSize;
117 };
118
119
120
121
122 if (!CouldOnlyImpactOneFunction)
123 std::for_each(M.begin(), M.end(), UpdateFunctionChanges);
124 else
125 UpdateFunctionChanges(*F);
126
127
128 if (!CouldOnlyImpactOneFunction) {
129
130
131
132
134
135
136 if (It == M.end())
137 return;
138
139
140 F = &*It;
141 }
142 int64_t CountAfter = static_cast<int64_t>(CountBefore) + Delta;
146
147
149 << ": IR instruction count changed from "
151 << " to "
153 << "; Delta: "
155 F->getContext().diagnose(R);
156
157
158 std::string PassName = P->getPassName().str();
159
160
161 auto EmitFunctionSizeChangedRemark = [&FunctionToInstrCount, &F, &BB,
163 unsigned FnCountBefore, FnCountAfter;
164 std::pair<unsigned, unsigned> &Change = FunctionToInstrCount[Fname];
165 std::tie(FnCountBefore, FnCountAfter) = Change;
166 int64_t FnDelta = static_cast<int64_t>(FnCountAfter) -
167 static_cast<int64_t>(FnCountBefore);
168
169 if (FnDelta == 0)
170 return;
171
172
173
174
175
176
177
181 << ": Function: "
183 << ": IR instruction count changed from "
185 FnCountBefore)
186 << " to "
188 FnCountAfter)
189 << "; Delta: "
191 F->getContext().diagnose(FR);
192
193
194 Change.first = FnCountAfter;
195 };
196
197
198
199 if (!CouldOnlyImpactOneFunction)
200 std::for_each(FunctionToInstrCount.keys().begin(),
201 FunctionToInstrCount.keys().end(),
202 EmitFunctionSizeChangedRemark);
203 else
204 EmitFunctionSizeChangedRemark(F->getName().str());
205}
206
208 if (!V && !M)
209 OS << "Releasing pass '";
210 else
211 OS << "Running pass '";
212
214
215 if (M) {
217 return;
218 }
219 if (!V) {
220 OS << '\n';
221 return;
222 }
223
224 OS << " on ";
225 if (isa(V))
226 OS << "function";
227 else if (isa(V))
228 OS << "basic block";
229 else
230 OS << "value";
231
232 OS << " '";
234 OS << "'\n";
235}
236
237namespace llvm {
238namespace legacy {
240
241
242
243
244
248 virtual void anchor();
249private:
250 bool wasRun;
251public:
256
257
260 }
261
262
264 const std::string &Banner) const override {
266 }
267
268
269
271
272
273
275
276
277
279
280
281
283
284
289 }
290
291
293 Info.setPreservesAll();
294 }
295
299 return FP;
300 }
301
305 }
306};
307
308void FunctionPassManagerImpl::anchor() {}
309
311
312
313
314
316 bool Changed = false;
317
320
322 Changed |= ImPass->doInitialization(M);
323
326
327 return Changed;
328}
329
331 bool Changed = false;
332
335
337 Changed |= ImPass->doFinalization(M);
338
339 return Changed;
340}
341
343 if (!wasRun)
344 return;
349 }
350 }
351 wasRun = false;
352}
353
354
355
357 bool Changed = false;
358
362 F.getContext().yield();
363 }
364
367
368 wasRun = true;
369 return Changed;
370}
371}
372}
373
374namespace {
375
376
377
378
379
380
382public:
383 static char ID;
385
386
387 ~MPPassManager() override {
388 for (auto &OnTheFlyManager : OnTheFlyManagers) {
390 delete FPP;
391 }
392 }
393
394
396 const std::string &Banner) const override {
398 }
399
400
401
402 bool runOnModule(Module &M);
403
406
407
409 Info.setPreservesAll();
410 }
411
412
413
414
416
417
418
419
422
424
427
428
432 ModulePass *MP = getContainedPass(Index);
435 OnTheFlyManagers.find(MP);
436 if (I != OnTheFlyManagers.end())
437 I->second->dumpPassStructure(Offset + 2);
439 }
440 }
441
442 ModulePass *getContainedPass(unsigned N) {
443 assert(N < PassVector.size() && "Pass number out of range!");
444 return static_cast<ModulePass *>(PassVector[N]);
445 }
446
449 }
450
451 private:
452
453
455};
456
457char MPPassManager::ID = 0;
458}
459
460namespace llvm {
461namespace legacy {
462
463
464
465
466
470 virtual void anchor();
471
472public:
476
477
480 }
481
482
484 const std::string &Banner) const override {
486 }
487
488
489
491
494
495
497 Info.setPreservesAll();
498 }
499
504 }
505
508 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
509 return MP;
510 }
511};
512
513void PassManagerImpl::anchor() {}
514
516
517
518
519
520
521
522
524 bool Changed = false;
525
528
529
530
531
533
535 Changed |= ImPass->doInitialization(M);
536
540 M.getContext().yield();
541 }
542
544 Changed |= ImPass->doFinalization(M);
545
546 return Changed;
547}
548}
549}
550
551
552
553
554
559}
560
561
562void
564 unsigned PDepth = 0;
565 if (P->getResolver())
566 PDepth = P->getResolver()->getPMDataManager().getDepth();
567
568 for (Pass *AP : AnalysisPasses) {
569
570 auto &LastUserOfAP = LastUser[AP];
571 if (LastUserOfAP)
572 InversedLastUser[LastUserOfAP].erase(AP);
573 LastUserOfAP = P;
574 InversedLastUser[P].insert(AP);
575
576 if (P == AP)
577 continue;
578
579
586 assert(AnalysisPass && "Expected analysis pass to exist.");
588 assert(AR && "Expected analysis resolver to exist.");
590
591 if (PDepth == APDepth)
592 LastUses.push_back(AnalysisPass);
593 else if (PDepth > APDepth)
594 LastPMUses.push_back(AnalysisPass);
595 }
596
598
599
600
601 if (P->getResolver())
602 setLastUser(LastPMUses, P->getResolver()->getPMDataManager().getAsPass());
603
604
605
606 auto &LastUsedByAP = InversedLastUser[AP];
607 for (Pass *L : LastUsedByAP)
608 LastUser[L] = P;
609 InversedLastUser[P].insert(LastUsedByAP.begin(), LastUsedByAP.end());
610 LastUsedByAP.clear();
611 }
612}
613
614
617 auto DMI = InversedLastUser.find(P);
618 if (DMI == InversedLastUser.end())
619 return;
620
621 auto &LU = DMI->second;
622 LastUses.append(LU.begin(), LU.end());
623}
624
627 auto DMI = AnUsageMap.find(P);
628 if (DMI != AnUsageMap.end())
629 AnUsage = DMI->second;
630 else {
631
632
633
634
635
636
638 P->getAnalysisUsage(AU);
639
640 AUFoldingSetNode* Node = nullptr;
642 AUFoldingSetNode::Profile(ID, AU);
643 void *IP = nullptr;
645 Node = N;
646 else {
647 Node = new (AUFoldingSetNodeAllocator.Allocate()) AUFoldingSetNode(AU);
648 UniqueAnalysisUsages.InsertNode(Node, IP);
649 }
650 assert(Node && "cached analysis usage must be non null");
651
652 AnUsageMap[P] = &Node->AU;
653 AnUsage = &Node->AU;
654 }
655 return AnUsage;
656}
657
658
659
660
662
663
664
665
666
668
669
670
671
674
675 AnUsageMap.erase(P);
676 delete P;
677 return;
678 }
679
681
682 bool checkAnalysis = true;
683 while (checkAnalysis) {
684 checkAnalysis = false;
685
688
690 if (!AnalysisPass) {
692
693 if (!PI) {
694
695 dbgs() << "Pass '" << P->getPassName() << "' is not initialized." << "\n";
696 dbgs() << "Verify if there is a pass dependency cycle." << "\n";
697 dbgs() << "Required Passes:" << "\n";
698 for (const AnalysisID ID2 : RequiredSet) {
699 if (ID == ID2)
700 break;
702 if (AnalysisPass2) {
704 } else {
705 dbgs() << "\t" << "Error: Required pass not found! Possible causes:" << "\n";
706 dbgs() << "\t\t" << "- Pass misconfiguration (e.g.: missing macros)" << "\n";
707 dbgs() << "\t\t" << "- Corruption of the global PassRegistry" << "\n";
708 }
709 }
710 }
711
712 assert(PI && "Expected required passes to be initialized");
714 if (P->getPotentialPassManagerType () ==
716
718 else if (P->getPotentialPassManagerType () >
720
722
723
724 checkAnalysis = true;
725 } else
726
727
728 delete AnalysisPass;
729 }
730 }
731 }
732
733
735
736
739 P->setResolver(AR);
740 DM->initializeAnalysisImpl(P);
742 DM->recordAvailableAnalysis(IP);
743 return;
744 }
745
748 P->createPrinterPass(dbgs(), ("*** IR Dump Before " + P->getPassName() +
750 .str());
752 }
753
754
755 P->assignPassManager(activeStack, getTopLevelPassManagerType());
756
759 P->createPrinterPass(dbgs(), ("*** IR Dump After " + P->getPassName() +
761 .str());
763 }
764}
765
766
767
768
770
771
772 if (Pass *P = ImmutablePassMap.lookup(AID))
773 return P;
774
775
778 return P;
779
780
781 for (PMDataManager *IndirectPassManager : IndirectPassManagers)
782 if (Pass *P = IndirectPassManager->findAnalysisPass(AID, false))
783 return P;
784
785 return nullptr;
786}
787
789 const PassInfo *&PI = AnalysisPassInfos[AID];
790 if (!PI)
792 else
794 "The pass info pointer changed for an analysis ID!");
795
796 return PI;
797}
798
800 P->initializePass();
801 ImmutablePasses.push_back(P);
802
803
804
805
807 ImmutablePassMap[AID] = P;
808}
809
810
812
814 return;
815
816
819
820
821
822
823
825 Manager->getAsPass()->dumpPassStructure(1);
826}
827
829
831 return;
832
833 dbgs() << "Pass Arguments: ";
836 assert(PI && "Expected all immutable passes to be initialized");
837 dbgs() << " -" << PI->getPassArgument();
838 }
840 PM->dumpPassArguments();
841 dbgs() << "\n";
842}
843
846 PM->initializeAnalysisInfo();
847
848
850 IPM->initializeAnalysisInfo();
851}
852
853
856 delete PM;
857
859 delete P;
860}
861
862
863
864
865
868
869 AvailableAnalysis[PI] = P;
870}
871
872
873
877 return true;
878
880 for (Pass *P1 : HigherLevelAnalysis) {
881 if (P1->getAsImmutablePass() == nullptr &&
882 (PreservedSet, P1->getPassID()))
883 return false;
884 }
885
886 return true;
887}
888
889
891
892#ifdef NDEBUG
893 return;
894#endif
897
898
899 for (AnalysisID AID : PreservedSet) {
902 AP->verifyAnalysis();
903 }
904 }
905}
906
907
911 return;
912
915 E = AvailableAnalysis.end(); I != E; ) {
917 if (Info->second->getAsImmutablePass() == nullptr &&
919
922 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
924 }
925 AvailableAnalysis.erase(Info);
926 }
927 }
928
929
930
932 if (!IA)
933 continue;
934
936 E = IA->end();
937 I != E;) {
939 if (Info->second->getAsImmutablePass() == nullptr &&
941
944 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
946 }
947 IA->erase(Info);
948 }
949 }
950 }
951}
952
953
956
958
959
960 if ()
961 return;
962
964
966 dbgs() << " -*- '" << P->getPassName();
967 dbgs() << "' is the last user of following pass instances.";
968 dbgs() << " Free these instances\n";
969 }
970
971 for (Pass *P : DeadPasses)
973}
974
978
979 {
980
983
984 P->releaseMemory();
985 }
986
987
988 AvailableAnalysis.erase(P->getPassID());
989}
990
991
992
994
995
997 P->setResolver(AR);
998
999
1000
1002
1003 if (!ProcessAnalysis) {
1004
1006 return;
1007 }
1008
1009
1013
1014 unsigned PDepth = this->getDepth();
1015
1017 for (Pass *PUsed : UsedPasses) {
1018 unsigned RDepth = 0;
1019
1020 assert(PUsed->getResolver() && "Analysis Resolver is not set");
1021 PMDataManager &DM = PUsed->getResolver()->getPMDataManager();
1022 RDepth = DM.getDepth();
1023
1024 if (PDepth == RDepth)
1026 else if (PDepth > RDepth) {
1027
1028 TransferLastUses.push_back(PUsed);
1029
1030 HigherLevelAnalysis.push_back(PUsed);
1031 } else
1033 }
1034
1035
1036
1037
1038 if (->getAsPMDataManager())
1041
1042 if (!TransferLastUses.empty()) {
1045 TransferLastUses.clear();
1046 }
1047
1048
1049 for (AnalysisID ID : ReqAnalysisNotAvailable) {
1053 }
1054
1055
1056
1059
1060
1062}
1063
1064
1065
1066
1067
1072
1073 for (const auto &UsedID : AnUsage->getUsedSet())
1076
1077 for (const auto &RequiredID : AnUsage->getRequiredSet())
1080 else
1081 RP_NotAvail.push_back(RequiredID);
1082}
1083
1084
1085
1086
1087
1088
1091
1094 if (!Impl)
1095
1096
1097 continue;
1099 assert(AR && "Analysis Resolver is not set");
1101 }
1102}
1103
1104
1105
1107
1108
1110
1111 if (I != AvailableAnalysis.end())
1112 return I->second;
1113
1114
1115 if (SearchParent)
1117
1118 return nullptr;
1119}
1120
1121
1124 return;
1125
1127
1128
1129 if ()
1130 return;
1131
1133
1135 dbgs() << "--" << std::string(Offset*2, ' ');
1136 P->dumpPassStructure(0);
1137 }
1138}
1139
1143 PMD->dumpPassArguments();
1145 dbgs() << " -" << PI->getPassArgument();
1146 }
1147}
1148
1153 return;
1154 dbgs() << "[" << std::chrono::system_clock::now() << "] " << (void *)this
1155 << std::string(getDepth() * 2 + 1, ' ');
1156 switch (S1) {
1158 dbgs() << "Executing Pass '" << P->getPassName();
1159 break;
1161 dbgs() << "Made Modification '" << P->getPassName();
1162 break;
1164 dbgs() << " Freeing Pass '" << P->getPassName();
1165 break;
1166 default:
1167 break;
1168 }
1169 switch (S2) {
1171 dbgs() << "' on Function '" << Msg << "'...\n";
1172 break;
1174 dbgs() << "' on Module '" << Msg << "'...\n";
1175 break;
1177 dbgs() << "' on Region '" << Msg << "'...\n";
1178 break;
1180 dbgs() << "' on Loop '" << Msg << "'...\n";
1181 break;
1183 dbgs() << "' on Call Graph Nodes '" << Msg << "'...\n";
1184 break;
1185 default:
1186 break;
1187 }
1188}
1189
1192 return;
1193
1195 P->getAnalysisUsage(analysisUsage);
1196 dumpAnalysisUsage("Required", P, analysisUsage.getRequiredSet());
1197}
1198
1201 return;
1202
1204 P->getAnalysisUsage(analysisUsage);
1205 dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
1206}
1207
1210 return;
1211
1213 P->getAnalysisUsage(analysisUsage);
1214 dumpAnalysisUsage("Used", P, analysisUsage.getUsedSet());
1215}
1216
1217void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
1220 if (Set.empty())
1221 return;
1222 dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
1223 for (unsigned i = 0; i != Set.size(); ++i) {
1224 if (i) dbgs() << ',';
1226 if (!PInf) {
1227
1228
1229 dbgs() << " Uninitialized Pass";
1230 continue;
1231 }
1233 }
1234 dbgs() << '\n';
1235}
1236
1237
1238
1239
1240
1242 if (TPM) {
1245 }
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256#ifndef NDEBUG
1257 dbgs() << "Unable to schedule '" << RequiredPass->getPassName();
1258 dbgs() << "' required by '" << P->getPassName() << "'\n";
1259#endif
1261}
1262
1266}
1267
1268
1271 delete P;
1272}
1273
1274
1275
1276
1279}
1280
1281std::tuple<Pass *, bool>
1284}
1285
1286namespace llvm {
1287namespace legacy {
1288
1289
1290
1291
1292
1293FunctionPassManager::FunctionPassManager(Module *m) : M(m) {
1295
1297
1300}
1301
1302FunctionPassManager::~FunctionPassManager() {
1303 delete FPM;
1304}
1305
1306void FunctionPassManager::add(Pass *P) {
1308}
1309
1310
1311
1312
1313
1316 report_fatal_error(Twine("Error reading bitcode file: ") + EIB.message());
1317 });
1319}
1320
1321
1322
1323
1324bool FunctionPassManager::doInitialization() {
1326}
1327
1328
1329
1330bool FunctionPassManager::doFinalization() {
1332}
1333}
1334}
1335
1336
1341 assert(AR && "Analysis Resolver is not set");
1343 }
1344}
1345
1346
1347
1348
1349
1351
1356 FP->dumpPassStructure(Offset + 1);
1358 }
1359}
1360
1361
1362
1363
1365 if (F.isDeclaration())
1366 return false;
1367
1368 bool Changed = false;
1369 Module &M = *F.getParent();
1370
1372
1373 unsigned InstrCount, FunctionSize = 0;
1375 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
1376
1377 if (EmitICRemark) {
1379 FunctionSize = F.getInstructionCount();
1380 }
1381
1382
1385
1388 bool LocalChanged = false;
1389
1390
1391
1393 "RunPass", [FP]() { return std::string(FP->getPassName()); });
1394
1397
1399
1400 {
1403#ifdef EXPENSIVE_CHECKS
1404 uint64_t RefHash = FP->structuralHash(F);
1405#endif
1406 LocalChanged |= FP->runOnFunction(F);
1407
1408#if defined(EXPENSIVE_CHECKS) && !defined(NDEBUG)
1409 if (!LocalChanged && (RefHash != FP->structuralHash(F))) {
1410 llvm::errs() << "Pass modifies its input and doesn't report it: "
1411 << FP->getPassName() << "\n";
1412 llvm_unreachable("Pass modifies its input and doesn't report it");
1413 }
1414#endif
1415
1416 if (EmitICRemark) {
1417 unsigned NewSize = F.getInstructionCount();
1418
1419
1420
1421 if (NewSize != FunctionSize) {
1422 int64_t Delta = static_cast<int64_t>(NewSize) -
1423 static_cast<int64_t>(FunctionSize);
1425 FunctionToInstrCount, &F);
1427 FunctionSize = NewSize;
1428 }
1429 }
1430 }
1431
1432 Changed |= LocalChanged;
1433 if (LocalChanged)
1437
1439 if (LocalChanged)
1443 }
1444
1445 return Changed;
1446}
1447
1449 bool Changed = false;
1450
1453
1454 return Changed;
1455}
1456
1458 bool Changed = false;
1459
1462
1463 return Changed;
1464}
1465
1467 bool Changed = false;
1468
1471
1472 return Changed;
1473}
1474
1475
1476
1477
1478
1479
1480
1481bool
1482MPPassManager::runOnModule(Module &M) {
1484
1485 bool Changed = false;
1486
1487
1488 for (auto &OnTheFlyManager : OnTheFlyManagers) {
1491 }
1492
1493
1494 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1495 Changed |= getContainedPass(Index)->doInitialization(M);
1496
1499 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
1500
1501 if (EmitICRemark)
1502 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1503
1504 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1505 ModulePass *MP = getContainedPass(Index);
1506 bool LocalChanged = false;
1507
1509 dumpRequiredSet(MP);
1510
1511 initializeAnalysisImpl(MP);
1512
1513 {
1516
1517#ifdef EXPENSIVE_CHECKS
1518 uint64_t RefHash = MP->structuralHash(M);
1519#endif
1520
1522
1523#ifdef EXPENSIVE_CHECKS
1524 assert((LocalChanged || (RefHash == MP->structuralHash(M))) &&
1525 "Pass modifies its input and doesn't report it.");
1526#endif
1527
1528 if (EmitICRemark) {
1529
1530 unsigned ModuleCount = M.getInstructionCount();
1532 int64_t Delta = static_cast<int64_t>(ModuleCount) -
1534 emitInstrCountChangedRemark(MP, M, Delta, InstrCount,
1535 FunctionToInstrCount);
1537 }
1538 }
1539 }
1540
1541 Changed |= LocalChanged;
1542 if (LocalChanged)
1544 M.getModuleIdentifier());
1545 dumpPreservedSet(MP);
1546 dumpUsedSet(MP);
1547
1548 verifyPreservedAnalysis(MP);
1549 if (LocalChanged)
1550 removeNotPreservedAnalysis(MP);
1551 recordAvailableAnalysis(MP);
1552 removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
1553 }
1554
1555
1556 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
1557 Changed |= getContainedPass(Index)->doFinalization(M);
1558
1559
1560 for (auto &OnTheFlyManager : OnTheFlyManagers) {
1562
1563
1566 }
1567
1568 return Changed;
1569}
1570
1571
1572
1573
1574void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1575 assert(RequiredPass && "No required pass?");
1577 "Unable to handle Pass that requires lower level Analysis pass");
1578 assert((P->getPotentialPassManagerType() <
1580 "Unable to handle Pass that requires lower level Analysis pass");
1581
1583 if (!FPP) {
1585
1587
1588 OnTheFlyManagers[P] = FPP;
1589 }
1590 const PassInfo *RequiredPassPI =
1591 TPM->findAnalysisPassInfo(RequiredPass->getPassID());
1592
1593 Pass *FoundPass = nullptr;
1594 if (RequiredPassPI && RequiredPassPI->isAnalysis()) {
1595 FoundPass =
1597 }
1598 if (!FoundPass) {
1599 FoundPass = RequiredPass;
1600
1601
1602 FPP->add(RequiredPass);
1603 }
1604
1608}
1609
1610
1611
1612
1613std::tuple<Pass *, bool> MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI,
1616 assert(FPP && "Unable to find on the fly pass");
1617
1619 bool Changed = FPP->run(F);
1620 return std::make_tuple(((PMTopLevelManager *)FPP)->findAnalysisPass(PI),
1621 Changed);
1622}
1623
1624namespace llvm {
1625namespace legacy {
1626
1627
1628
1629
1630
1633
1635}
1636
1638 delete PM;
1639}
1640
1643}
1644
1645
1646
1648 return PM->run(M);
1649}
1650}
1651}
1652
1653
1654
1655
1656
1657
1659
1662
1663 S.pop_back();
1664}
1665
1666
1668 assert(PM && "Unable to push. Pass Manager expected");
1669 assert(PM->getDepth()==0 && "Pass Manager depth set too early");
1670
1671 if (!this->empty()) {
1673 && "pushing bad pass manager to PMStack");
1675
1676 assert(TPM && "Unable to find top level manager");
1679 PM->setDepth(this->top()->getDepth()+1);
1680 } else {
1683 && "pushing bad pass manager to PMStack");
1685 }
1686
1687 S.push_back(PM);
1688}
1689
1690
1693 dbgs() << Manager->getAsPass()->getPassName() << ' ';
1694
1695 if (!S.empty())
1696 dbgs() << '\n';
1697}
1698
1699
1700
1703
1706 T != PreferredType)
1707 PMS.pop();
1709}
1710
1711
1712
1715
1718 PMS.pop();
1719
1720
1722
1725
1726
1728
1729
1730
1732
1733
1734 PMS.push(FPP);
1735 PM = FPP;
1736 }
1737
1738
1739 PM->add(this);
1740}
1741
AMDGPU Lower Kernel Arguments
Analysis containing CSE Info
#define clEnumVal(ENUMVAL, DESC)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static unsigned InstrCount
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file contains an interface for creating legacy passes to print out IR in various granularities.
Module.h This file contains the declarations for the Module class.
cl::opt< bool > UseNewDbgInfoFormat
static cl::opt< enum PassDebugLevel > PassDebugging("debug-pass", cl::Hidden, cl::desc("Print legacy PassManager debugging information"), cl::values(clEnumVal(Disabled, "disable debug output"), clEnumVal(Arguments, "print pass arguments to pass to 'opt'"), clEnumVal(Structure, "print pass structure before run()"), clEnumVal(Executions, "print pass name before it is executed"), clEnumVal(Details, "print pass details when it is executed")))
This file implements a map that provides insertion order iteration.
llvm:🆑:opt< bool > UseNewDbgInfoFormat
This header defines classes/functions to handle pass execution timing information with interfaces for...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const PassInfo * getPassInfo(StringRef PassName)
static const char PassName[]
AnalysisResolver - Simple interface used by Pass objects to pull all analysis information out of pass...
void addAnalysisImplsPair(AnalysisID PI, Pass *P)
Pass * findImplPass(AnalysisID PI)
Find pass that is implementing PI.
PMDataManager & getPMDataManager()
void clearAnalysisImpls()
Clear cache that is used to connect a pass to the analysis (PassInfo).
Pass * getAnalysisIfAvailable(AnalysisID ID) const
Return analysis result or null if it doesn't exist.
Represent the analysis usage information of a pass.
const VectorType & getRequiredSet() const
const VectorType & getRequiredTransitiveSet() const
const VectorType & getUsedSet() const
bool getPreservesAll() const
Determine whether a pass said it does not transform its input at all.
const VectorType & getPreservedSet() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
Base class for error info classes.
FPPassManager manages BBPassManagers and FunctionPasses.
bool runOnFunction(Function &F)
run - Execute all of the passes scheduled for execution.
bool doInitialization(Module &M) override
doInitialization - Run all of the initializers for the function passes.
bool doFinalization(Module &M) override
doFinalization - Run all of the finalizers for the function passes.
FunctionPass * getContainedPass(unsigned N)
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
void cleanup()
cleanup - After running all passes, clean up pass manager cache.
void InsertNode(T *N, void *InsertPos)
InsertNode - Insert the specified node into the folding set, knowing that it is not already in the fo...
T * FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos)
FindNodeOrInsertPos - Look up the node specified by ID.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
FunctionPass class - This class is used to implement most global optimizations.
void assignPassManager(PMStack &PMS, PassManagerType T) override
Find appropriate Function Pass Manager or Call Graph Pass Manager in the PM Stack and add self into t...
ImmutablePass class - This class is used to provide information that does not need to be run.
This class implements a map that also provides access to all stored values in a deterministic order.
typename VectorType::const_iterator const_iterator
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
void assignPassManager(PMStack &PMS, PassManagerType T) override
Find appropriate Module Pass Manager in the PM Stack and add self into that manager.
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
PMDataManager provides the common place to manage the analysis data used by pass managers.
void dumpPassArguments() const
void removeDeadPasses(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove dead passes used by P.
void dumpLastUses(Pass *P, unsigned Offset) const
virtual Pass * getAsPass()=0
virtual std::tuple< Pass *, bool > getOnTheFlyPass(Pass *P, AnalysisID PI, Function &F)
void setDepth(unsigned newDepth)
void recordAvailableAnalysis(Pass *P)
Augment AvailableAnalysis by adding analysis made available by pass P.
Pass * findAnalysisPass(AnalysisID AID, bool Direction)
Find the pass that implements Analysis AID.
bool isPassDebuggingExecutionsOrMore() const
isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions or higher is specified.
unsigned getDepth() const
SmallVector< Pass *, 16 > PassVector
DenseMap< AnalysisID, Pass * > * InheritedAnalysis[PMT_Last]
virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass)
Add RequiredPass into list of lower level passes required by pass P.
PMTopLevelManager * getTopLevelManager()
unsigned initSizeRemarkInfo(Module &M, StringMap< std::pair< unsigned, unsigned > > &FunctionToInstrCount)
Set the initial size of the module if the user has specified that they want remarks for size.
void setTopLevelManager(PMTopLevelManager *T)
void dumpRequiredSet(const Pass *P) const
void initializeAnalysisImpl(Pass *P)
All Required analyses should be available to the pass as it runs! Here we fill in the AnalysisImpls m...
void verifyPreservedAnalysis(Pass *P)
verifyPreservedAnalysis – Verify analysis presreved by pass P.
void initializeAnalysisInfo()
Initialize available analysis information.
void freePass(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove P.
bool preserveHigherLevelAnalysis(Pass *P)
unsigned getNumContainedPasses() const
virtual PassManagerType getPassManagerType() const
void emitInstrCountChangedRemark(Pass *P, Module &M, int64_t Delta, unsigned CountBefore, StringMap< std::pair< unsigned, unsigned > > &FunctionToInstrCount, Function *F=nullptr)
Emit a remark signifying that the number of IR instructions in the module changed.
void add(Pass *P, bool ProcessAnalysis=true)
Add pass P into the PassVector.
void collectRequiredAndUsedAnalyses(SmallVectorImpl< Pass * > &UsedPasses, SmallVectorImpl< AnalysisID > &ReqPassNotAvailable, Pass *P)
Populate UsedPasses with analysis pass that are used or required by pass P and are available.
void populateInheritedAnalysis(PMStack &PMS)
void dumpPreservedSet(const Pass *P) const
void dumpUsedSet(const Pass *P) const
void removeNotPreservedAnalysis(Pass *P)
Remove Analysis that is not preserved by the pass.
void dumpPassInfo(Pass *P, enum PassDebuggingString S1, enum PassDebuggingString S2, StringRef Msg)
PMStack - This class implements a stack data structure of PMDataManager pointers.
PMDataManager * top() const
void push(PMDataManager *PM)
PMTopLevelManager manages LastUser info and collects common APIs used by top level pass managers.
void addIndirectPassManager(PMDataManager *Manager)
void addImmutablePass(ImmutablePass *P)
Add immutable pass and initialize it.
const PassInfo * findAnalysisPassInfo(AnalysisID AID) const
Retrieve the PassInfo for an analysis.
void setLastUser(ArrayRef< Pass * > AnalysisPasses, Pass *P)
Set pass P as the last user of the given analysis passes.
virtual ~PMTopLevelManager()
Destructor.
void schedulePass(Pass *P)
Schedule pass P for execution.
SmallVector< PMDataManager *, 8 > PassManagers
Collection of pass managers.
Pass * findAnalysisPass(AnalysisID AID)
Find the pass that implements Analysis AID.
void dumpArguments() const
AnalysisUsage * findAnalysisUsage(Pass *P)
Find analysis usage information for the pass P.
void addPassManager(PMDataManager *Manager)
unsigned getNumContainedManagers() const
void initializeAllAnalysisInfo()
SmallVectorImpl< ImmutablePass * > & getImmutablePasses()
PMTopLevelManager(PMDataManager *PMDM)
Initialize top level manager. Create first pass manager.
void collectLastUses(SmallVectorImpl< Pass * > &LastUses, Pass *P)
Collect passes whose last user is P.
PassInfo class - An instance of this class exists for every pass known by the system,...
StringRef getPassArgument() const
getPassArgument - Return the command line option that may be passed to 'opt' that will cause this pas...
StringRef getPassName() const
getPassName - Return the friendly name for the pass, never returns null
Pass * createPass() const
createPass() - Use this method to create an instance of this pass.
PassManagerPrettyStackEntry - This is used to print informative information about what pass is runnin...
void print(raw_ostream &OS) const override
print - Emit information about this stack frame to OS.
Manages a sequence of passes over a particular unit of IR.
PreservedAnalyses run(Function &IR, AnalysisManager< Function > &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const PassInfo * getPassInfo(const void *TI) const
getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass' type identifier (&MyPass::...
Pass interface - Implemented by all 'passes'.
virtual PassManagerType getPotentialPassManagerType() const
Return what kind of Pass Manager can manage this pass.
void setResolver(AnalysisResolver *AR)
virtual PMDataManager * getAsPMDataManager()
AnalysisID getPassID() const
getPassID - Return the PassID number that corresponds to this pass.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
virtual void assignPassManager(PMStack &, PassManagerType)
Each pass is responsible for assigning a pass manager to itself.
AnalysisResolver * getResolver() const
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
virtual Pass * createPrinterPass(raw_ostream &OS, const std::string &Banner) const =0
createPrinterPass - Get a Pass appropriate to print the IR this pass operates on (Module,...
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
virtual void dumpPassStructure(unsigned Offset=0)
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
virtual void releaseMemory()
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Used to temporarily set the debug info format of a function, module, or basic block for the duration ...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
T * Allocate(size_t num=1)
Allocate space for an array of objects without constructing them.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
The TimeRegion class is used as a helper class to call the startTimer() and stopTimer() methods of th...
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
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.
FunctionPassManagerImpl manages FPPassManagers.
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
createPrinterPass - Get a function printer pass.
FPPassManager * getContainedManager(unsigned N)
FunctionPassManagerImpl()
void releaseMemoryOnTheFly()
bool doInitialization(Module &M) override
doInitialization - Run all of the initializers for the function passes.
PMDataManager * getAsPMDataManager() override
void dumpPassStructure(unsigned Offset) override
Pass * getAsPass() override
bool run(Function &F)
run - Execute all of the passes scheduled for execution.
bool doFinalization(Module &M) override
doFinalization - Run all of the finalizers for the function passes.
PassManagerType getTopLevelPassManagerType() override
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
virtual ~PassManagerBase()
PassManagerImpl manages MPPassManagers.
PassManagerType getTopLevelPassManagerType() override
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
void add(Pass *P)
Add a pass to the queue of passes to run.
Pass * getAsPass() override
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
PMDataManager * getAsPMDataManager() override
MPPassManager * getContainedManager(unsigned N)
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
createPrinterPass - Get a module printer pass.
void add(Pass *P) override
Add a pass to the queue of passes to run.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
PassManager()
Create new pass manager.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
#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.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
bool debugPassSpecified()
This is an optimization pass for GlobalISel generic memory operations.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
PassManagerType
Different types of internal pass managers.
@ PMT_ModulePassManager
MPPassManager.
@ PMT_FunctionPassManager
FPPassManager.
Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
ModulePass * createPrintModulePass(raw_ostream &OS, const std::string &Banner="", bool ShouldPreserveUseListOrder=false)
Create and return a pass that writes the module to the specified raw_ostream.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool shouldPrintBeforePass(StringRef PassID)
bool shouldPrintAfterPass(StringRef PassID)
FunctionPass * createPrintFunctionPass(raw_ostream &OS, const std::string &Banner="")
Create and return a pass that prints functions to the specified raw_ostream as they are processed.
Used in the streaming interface as the general argument type.