LLVM: lib/IR/LegacyPassManager.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
31
32using namespace llvm;
33
34
35
36
37
38
39
40
41
42
43namespace {
44
45enum PassDebugLevel {
47};
48}
49
52 cl::desc("Print legacy PassManager debugging information"),
55 clEnumVal(Structure, "print pass structure before run()"),
56 clEnumVal(Executions, "print pass name before it is executed"),
57 clEnumVal(Details, "print pass details when it is executed")));
58
59
60
64
66 Module &M, StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount) {
67
69
70
71
73 unsigned FCount = F.getInstructionCount();
74
75
76
77
78
79
80 FunctionToInstrCount[F.getName().str()] =
81 std::pair<unsigned, unsigned>(FCount, 0);
83 }
85}
86
88 Pass *P, Module &M, int64_t Delta, unsigned CountBefore,
89 StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount,
91
92
93
94
95 if (P->getAsPMDataManager())
96 return;
97
98
99 bool CouldOnlyImpactOneFunction = (F != nullptr);
100
101
102 auto UpdateFunctionChanges =
103 [&FunctionToInstrCount](Function &MaybeChangedFn) {
104
105 unsigned FnSize = MaybeChangedFn.getInstructionCount();
106
107
108
109 auto [It, Inserted] = FunctionToInstrCount.try_emplace(
110 MaybeChangedFn.getName(), 0, FnSize);
111 if (Inserted)
112 return;
113
114
115 It->second.second = FnSize;
116 };
117
118
119
120
121 if (!CouldOnlyImpactOneFunction)
123 else
124 UpdateFunctionChanges(*F);
125
126
127 if (!CouldOnlyImpactOneFunction) {
128
129
130
131
133
134
135 if (It == M.end())
136 return;
137
138
139 F = &*It;
140 }
141 int64_t CountAfter = static_cast<int64_t>(CountBefore) + Delta;
145
146
148 << ": IR instruction count changed from "
150 << " to "
152 << "; Delta: "
154 F->getContext().diagnose(R);
155
156
157 std::string PassName = P->getPassName().str();
158
159
160 auto EmitFunctionSizeChangedRemark = [&FunctionToInstrCount, &F, &BB,
162 unsigned FnCountBefore, FnCountAfter;
163 std::pair<unsigned, unsigned> &Change = FunctionToInstrCount[Fname];
164 std::tie(FnCountBefore, FnCountAfter) = Change;
165 int64_t FnDelta = static_cast<int64_t>(FnCountAfter) -
166 static_cast<int64_t>(FnCountBefore);
167
168 if (FnDelta == 0)
169 return;
170
171
172
173
174
175
176
180 << ": Function: "
182 << ": IR instruction count changed from "
184 FnCountBefore)
185 << " to "
187 FnCountAfter)
188 << "; Delta: "
190 F->getContext().diagnose(FR);
191
192
193 Change.first = FnCountAfter;
194 };
195
196
197
198 if (!CouldOnlyImpactOneFunction)
199 llvm::for_each(FunctionToInstrCount.keys(), EmitFunctionSizeChangedRemark);
200 else
201 EmitFunctionSizeChangedRemark(F->getName().str());
202}
203
205 if (!V && !M)
206 OS << "Releasing pass '";
207 else
208 OS << "Running pass '";
209
210 OS << P->getPassName() << "'";
211
212 if (M) {
213 OS << " on module '" << M->getModuleIdentifier() << "'.\n";
214 return;
215 }
216 if (!V) {
217 OS << '\n';
218 return;
219 }
220
221 OS << " on ";
223 OS << "function";
225 OS << "basic block";
226 else
227 OS << "value";
228
229 OS << " '";
230 V->printAsOperand(OS, false, M);
231 OS << "'\n";
232}
233
234namespace llvm {
237
238
239
240
241
245 virtual void anchor();
246private:
247 bool wasRun;
248public:
253
254
258
259
261 const std::string &Banner) const override {
263 }
264
265
266
268
269
270
272
273
274
276
277
278
280
281
287
288
290 Info.setPreservesAll();
291 }
292
298
303};
304
305void FunctionPassManagerImpl::anchor() {}
306
308
309
310
311
314
317
319 Changed |= ImPass->doInitialization(M);
320
323
325}
326
329
332
334 Changed |= ImPass->doFinalization(M);
335
337}
338
340 if (!wasRun)
341 return;
346 }
347 }
348 wasRun = false;
349}
350
351
352
355
359 F.getContext().yield();
360 }
361
364
365 wasRun = true;
367}
368}
369}
370
371namespace {
372
373
374
375
376
377
379public:
380 static char ID;
382
383
384 ~MPPassManager() override {
385 for (auto &OnTheFlyManager : OnTheFlyManagers) {
386 legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
387 delete FPP;
388 }
389 }
390
391
392 Pass *createPrinterPass(raw_ostream &O,
393 const std::string &Banner) const override {
395 }
396
397
398
399 bool runOnModule(Module &M);
400
403
404
405 void getAnalysisUsage(AnalysisUsage &Info) const override {
406 Info.setPreservesAll();
407 }
408
409
410
411
412 void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) override;
413
414
415
416
417 std::tuple<Pass *, bool> getOnTheFlyPass(Pass *MP, AnalysisID PI,
418 Function &F) override;
419
420 StringRef getPassName() const override { return "Module Pass Manager"; }
421
422 PMDataManager *getAsPMDataManager() override { return this; }
423 Pass *getAsPass() override { return this; }
424
425
426 void dumpPassStructure(unsigned Offset) override {
428 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
429 ModulePass *MP = getContainedPass(Index);
432 OnTheFlyManagers.find(MP);
433 if (I != OnTheFlyManagers.end())
434 I->second->dumpPassStructure(Offset + 2);
435 dumpLastUses(MP, Offset+1);
436 }
437 }
438
439 ModulePass *getContainedPass(unsigned N) {
440 assert(N < PassVector.size() && "Pass number out of range!");
441 return static_cast<ModulePass *>(PassVector[N]);
442 }
443
446 }
447
448 private:
449
450
451 MapVector<Pass *, legacy::FunctionPassManagerImpl *> OnTheFlyManagers;
452};
453
454char MPPassManager::ID = 0;
455}
456
457namespace llvm {
459
460
461
462
463
467 virtual void anchor();
468
469public:
473
474
478
479
481 const std::string &Banner) const override {
483 }
484
485
486
488
491
492
494 Info.setPreservesAll();
495 }
496
502
505 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
506 return MP;
507 }
508};
509
510void PassManagerImpl::anchor() {}
511
513
514
515
516
517
518
519
522
525
527 Changed |= ImPass->doInitialization(M);
528
532 M.getContext().yield();
533 }
534
536 Changed |= ImPass->doFinalization(M);
537
539}
540}
541}
542
543
544
545
546
552
553
554void
556 unsigned PDepth = 0;
557 if (P->getResolver())
558 PDepth = P->getResolver()->getPMDataManager().getDepth();
559
560 for (Pass *AP : AnalysisPasses) {
561
562 auto &LastUserOfAP = LastUser[AP];
563 if (LastUserOfAP)
564 InversedLastUser[LastUserOfAP].erase(AP);
565 LastUserOfAP = P;
566 InversedLastUser[P].insert(AP);
567
568 if (P == AP)
569 continue;
570
571
578 assert(AnalysisPass && "Expected analysis pass to exist.");
580 assert(AR && "Expected analysis resolver to exist.");
582
583 if (PDepth == APDepth)
584 LastUses.push_back(AnalysisPass);
585 else if (PDepth > APDepth)
586 LastPMUses.push_back(AnalysisPass);
587 }
588
590
591
592
593 if (P->getResolver())
594 setLastUser(LastPMUses, P->getResolver()->getPMDataManager().getAsPass());
595
596
597
598 auto &LastUsedByAP = InversedLastUser[AP];
599 for (Pass *L : LastUsedByAP)
600 LastUser[L] = P;
601 InversedLastUser[P].insert_range(LastUsedByAP);
602 LastUsedByAP.clear();
603 }
604}
605
606
609 auto DMI = InversedLastUser.find(P);
610 if (DMI == InversedLastUser.end())
611 return;
612
613 auto &LU = DMI->second;
614 LastUses.append(LU.begin(), LU.end());
615}
616
619 auto DMI = AnUsageMap.find(P);
620 if (DMI != AnUsageMap.end())
621 AnUsage = DMI->second;
622 else {
623
624
625
626
627
628
630 P->getAnalysisUsage(AU);
631
632 AUFoldingSetNode* Node = nullptr;
634 AUFoldingSetNode::Profile(ID, AU);
635 void *IP = nullptr;
636 if (auto *N = UniqueAnalysisUsages.FindNodeOrInsertPos(ID, IP))
638 else {
639 Node = new (AUFoldingSetNodeAllocator.Allocate()) AUFoldingSetNode(AU);
640 UniqueAnalysisUsages.InsertNode(Node, IP);
641 }
642 assert(Node && "cached analysis usage must be non null");
643
644 AnUsageMap[P] = &Node->AU;
645 AnUsage = &Node->AU;
646 }
647 return AnUsage;
648}
649
650
651
652
654
655
656
657
658
660
661
662
663
666
667 AnUsageMap.erase(P);
668 delete P;
669 return;
670 }
671
673
674 bool checkAnalysis = true;
675 while (checkAnalysis) {
676 checkAnalysis = false;
677
680
682 if (!AnalysisPass) {
684
685 if (!PI) {
686
687 dbgs() << "Pass '" << P->getPassName() << "' is not initialized." << "\n";
688 dbgs() << "Verify if there is a pass dependency cycle." << "\n";
689 dbgs() << "Required Passes:" << "\n";
690 for (const AnalysisID ID2 : RequiredSet) {
691 if (ID == ID2)
692 break;
694 if (AnalysisPass2) {
696 } else {
697 dbgs() << "\t" << "Error: Required pass not found! Possible causes:" << "\n";
698 dbgs() << "\t\t" << "- Pass misconfiguration (e.g.: missing macros)" << "\n";
699 dbgs() << "\t\t" << "- Corruption of the global PassRegistry" << "\n";
700 }
701 }
702 }
703
704 assert(PI && "Expected required passes to be initialized");
706 if (P->getPotentialPassManagerType () ==
708
710 else if (P->getPotentialPassManagerType () >
712
714
715
716 checkAnalysis = true;
717 } else
718
719
720 delete AnalysisPass;
721 }
722 }
723 }
724
725
727
728
731 P->setResolver(AR);
732 DM->initializeAnalysisImpl(P);
734 DM->recordAvailableAnalysis(IP);
735 return;
736 }
737
740 P->createPrinterPass(dbgs(), ("*** IR Dump Before " + P->getPassName() +
742 .str());
744 }
745
746
747 P->assignPassManager(activeStack, getTopLevelPassManagerType());
748
751 P->createPrinterPass(dbgs(), ("*** IR Dump After " + P->getPassName() +
753 .str());
755 }
756}
757
758
759
760
762
763
764 if (Pass *P = ImmutablePassMap.lookup(AID))
765 return P;
766
767
770 return P;
771
772
773 for (PMDataManager *IndirectPassManager : IndirectPassManagers)
774 if (Pass *P = IndirectPassManager->findAnalysisPass(AID, false))
775 return P;
776
777 return nullptr;
778}
779
781 const PassInfo *&PI = AnalysisPassInfos[AID];
782 if (!PI)
784 else
786 "The pass info pointer changed for an analysis ID!");
787
788 return PI;
789}
790
792 P->initializePass();
793 ImmutablePasses.push_back(P);
794
795
796
797
799 ImmutablePassMap[AID] = P;
800}
801
802
804
806 return;
807
808
811
812
813
814
815
817 Manager->getAsPass()->dumpPassStructure(1);
818}
819
821
823 return;
824
825 dbgs() << "Pass Arguments: ";
828 assert(PI && "Expected all immutable passes to be initialized");
829 dbgs() << " -" << PI->getPassArgument();
830 }
832 PM->dumpPassArguments();
833 dbgs() << "\n";
834}
835
838 PM->initializeAnalysisInfo();
839
840
842 IPM->initializeAnalysisInfo();
843}
844
845
848 delete PM;
849
851 delete P;
852}
853
854
855
856
857
860
861 AvailableAnalysis[PI] = P;
862}
863
864
865
869 return true;
870
872 for (Pass *P1 : HigherLevelAnalysis) {
873 if (P1->getAsImmutablePass() == nullptr &&
874 (PreservedSet, P1->getPassID()))
875 return false;
876 }
877
878 return true;
879}
880
881
883
884#ifdef NDEBUG
885 return;
886#endif
889
890
891 for (AnalysisID AID : PreservedSet) {
894 AP->verifyAnalysis();
895 }
896 }
897}
898
899
903 return;
904
907 E = AvailableAnalysis.end(); I != E; ) {
909 if (Info->second->getAsImmutablePass() == nullptr &&
911
913 Pass *S = Info->second;
914 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
916 }
917 AvailableAnalysis.erase(Info);
918 }
919 }
920
921
922
924 if (!IA)
925 continue;
926
928 E = IA->end();
929 I != E;) {
931 if (Info->second->getAsImmutablePass() == nullptr &&
933
935 Pass *S = Info->second;
936 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
938 }
939 IA->erase(Info);
940 }
941 }
942 }
943}
944
945
948
950
951
952 if ()
953 return;
954
955 TPM->collectLastUses(DeadPasses, P);
956
958 dbgs() << " -*- '" << P->getPassName();
959 dbgs() << "' is the last user of following pass instances.";
960 dbgs() << " Free these instances\n";
961 }
962
963 for (Pass *P : DeadPasses)
965}
966
970
971 {
972
975
976 P->releaseMemory();
977 }
978
979
980 AvailableAnalysis.erase(P->getPassID());
981}
982
983
984
986
987
989 P->setResolver(AR);
990
991
992
994
995 if (!ProcessAnalysis) {
996
998 return;
999 }
1000
1001
1005
1006 unsigned PDepth = this->getDepth();
1007
1009 for (Pass *PUsed : UsedPasses) {
1010 unsigned RDepth = 0;
1011
1012 assert(PUsed->getResolver() && "Analysis Resolver is not set");
1013 PMDataManager &DM = PUsed->getResolver()->getPMDataManager();
1014 RDepth = DM.getDepth();
1015
1016 if (PDepth == RDepth)
1018 else if (PDepth > RDepth) {
1019
1020 TransferLastUses.push_back(PUsed);
1021
1022 HigherLevelAnalysis.push_back(PUsed);
1023 } else
1025 }
1026
1027
1028
1029
1030 if (->getAsPMDataManager())
1032 TPM->setLastUser(LastUses, P);
1033
1034 if (!TransferLastUses.empty()) {
1036 TPM->setLastUser(TransferLastUses, My_PM);
1037 TransferLastUses.clear();
1038 }
1039
1040
1041 for (AnalysisID ID : ReqAnalysisNotAvailable) {
1042 const PassInfo *PI = TPM->findAnalysisPassInfo(ID);
1045 }
1046
1047
1048
1051
1052
1054}
1055
1056
1057
1058
1059
1064
1065 for (const auto &UsedID : AnUsage->getUsedSet())
1068
1069 for (const auto &RequiredID : AnUsage->getRequiredSet())
1072 else
1073 RP_NotAvail.push_back(RequiredID);
1074}
1075
1076
1077
1078
1079
1080
1083
1086 if (!Impl)
1087
1088
1089 continue;
1091 assert(AR && "Analysis Resolver is not set");
1093 }
1094}
1095
1096
1097
1099
1100
1102
1103 if (I != AvailableAnalysis.end())
1104 return I->second;
1105
1106
1107 if (SearchParent)
1108 return TPM->findAnalysisPass(AID);
1109
1110 return nullptr;
1111}
1112
1113
1116 return;
1117
1119
1120
1121 if ()
1122 return;
1123
1124 TPM->collectLastUses(LUses, P);
1125
1127 dbgs() << "--" << std::string(Offset*2, ' ');
1128 P->dumpPassStructure(0);
1129 }
1130}
1131
1135 PMD->dumpPassArguments();
1136 else if (const PassInfo *PI = TPM->findAnalysisPassInfo(P->getPassID()))
1137 dbgs() << " -" << PI->getPassArgument();
1138 }
1139}
1140
1145 return;
1146 dbgs() << "[" << std::chrono::system_clock::now() << "] " << (void *)this
1147 << std::string(getDepth() * 2 + 1, ' ');
1148 switch (S1) {
1150 dbgs() << "Executing Pass '" << P->getPassName();
1151 break;
1153 dbgs() << "Made Modification '" << P->getPassName();
1154 break;
1156 dbgs() << " Freeing Pass '" << P->getPassName();
1157 break;
1158 default:
1159 break;
1160 }
1161 switch (S2) {
1163 dbgs() << "' on Function '" << Msg << "'...\n";
1164 break;
1166 dbgs() << "' on Module '" << Msg << "'...\n";
1167 break;
1169 dbgs() << "' on Region '" << Msg << "'...\n";
1170 break;
1172 dbgs() << "' on Loop '" << Msg << "'...\n";
1173 break;
1175 dbgs() << "' on Call Graph Nodes '" << Msg << "'...\n";
1176 break;
1177 default:
1178 break;
1179 }
1180}
1181
1184 return;
1185
1187 P->getAnalysisUsage(analysisUsage);
1188 dumpAnalysisUsage("Required", P, analysisUsage.getRequiredSet());
1189}
1190
1193 return;
1194
1196 P->getAnalysisUsage(analysisUsage);
1197 dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
1198}
1199
1202 return;
1203
1205 P->getAnalysisUsage(analysisUsage);
1206 dumpAnalysisUsage("Used", P, analysisUsage.getUsedSet());
1207}
1208
1209void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
1212 if (Set.empty())
1213 return;
1214 dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
1215 for (unsigned i = 0; i != Set.size(); ++i) {
1216 if (i) dbgs() << ',';
1218 if (!PInf) {
1219
1220
1221 dbgs() << " Uninitialized Pass";
1222 continue;
1223 }
1225 }
1226 dbgs() << '\n';
1227}
1228
1229
1230
1231
1232
1234 if (TPM) {
1235 TPM->dumpArguments();
1236 TPM->dumpPasses();
1237 }
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248#ifndef NDEBUG
1249 dbgs() << "Unable to schedule '" << RequiredPass->getPassName();
1250 dbgs() << "' required by '" << P->getPassName() << "'\n";
1251#endif
1253}
1254
1259
1260
1265
1266
1267
1268
1270 return PM.findAnalysisPass(ID, true);
1271}
1272
1273std::tuple<Pass *, bool>
1275 return PM.getOnTheFlyPass(P, AnalysisPI, F);
1276}
1277
1278namespace llvm {
1280
1281
1282
1283
1284
1285FunctionPassManager::FunctionPassManager(Module *m) : M(m) {
1287
1288 FPM->setTopLevelManager(FPM);
1289
1291 FPM->setResolver(AR);
1292}
1293
1294FunctionPassManager::~FunctionPassManager() {
1295 delete FPM;
1296}
1297
1298void FunctionPassManager::add(Pass *P) {
1299 FPM->add(P);
1300}
1301
1302
1303
1304
1305
1308 report_fatal_error(Twine("Error reading bitcode file: ") + EIB.message());
1309 });
1310 return FPM->run(F);
1311}
1312
1313
1314
1315
1316bool FunctionPassManager::doInitialization() {
1317 return FPM->doInitialization(*M);
1318}
1319
1320
1321
1322bool FunctionPassManager::doFinalization() {
1323 return FPM->doFinalization(*M);
1324}
1325}
1326}
1327
1328
1333 assert(AR && "Analysis Resolver is not set");
1335 }
1336}
1337
1338
1339
1340
1341
1343
1348 FP->dumpPassStructure(Offset + 1);
1350 }
1351}
1352
1353
1354
1355
1357 if (F.isDeclaration())
1358 return false;
1359
1361 Module &M = *F.getParent();
1362
1364
1365 unsigned InstrCount, FunctionSize = 0;
1367 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
1368
1369 if (EmitICRemark) {
1371 FunctionSize = F.getInstructionCount();
1372 }
1373
1374
1377
1380 bool LocalChanged = false;
1381
1382
1383
1385 "RunPass", [FP]() { return std::string(FP->getPassName()); });
1386
1389
1391
1392 {
1395#ifdef EXPENSIVE_CHECKS
1396 uint64_t RefHash = FP->structuralHash(F);
1397#endif
1398 LocalChanged |= FP->runOnFunction(F);
1399
1400#if defined(EXPENSIVE_CHECKS) && !defined(NDEBUG)
1401 if (!LocalChanged && (RefHash != FP->structuralHash(F))) {
1402 llvm::errs() << "Pass modifies its input and doesn't report it: "
1403 << FP->getPassName() << "\n";
1404 llvm_unreachable("Pass modifies its input and doesn't report it");
1405 }
1406#endif
1407
1408 if (EmitICRemark) {
1409 unsigned NewSize = F.getInstructionCount();
1410
1411
1412
1413 if (NewSize != FunctionSize) {
1414 int64_t Delta = static_cast<int64_t>(NewSize) -
1415 static_cast<int64_t>(FunctionSize);
1417 FunctionToInstrCount, &F);
1419 FunctionSize = NewSize;
1420 }
1421 }
1422 }
1423
1424 Changed |= LocalChanged;
1425 if (LocalChanged)
1429
1431 if (LocalChanged)
1435 }
1436
1438}
1439
1448
1457
1466
1467
1468
1469
1470
1471
1472
1473bool
1474MPPassManager::runOnModule(Module &M) {
1476
1478
1479
1480 for (auto &OnTheFlyManager : OnTheFlyManagers) {
1483 }
1484
1485
1486 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1487 Changed |= getContainedPass(Index)->doInitialization(M);
1488
1491 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
1492
1493 if (EmitICRemark)
1494 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
1495
1496 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1497 ModulePass *MP = getContainedPass(Index);
1498 bool LocalChanged = false;
1499
1501 dumpRequiredSet(MP);
1502
1503 initializeAnalysisImpl(MP);
1504
1505 {
1508
1509#ifdef EXPENSIVE_CHECKS
1510 uint64_t RefHash = MP->structuralHash(M);
1511#endif
1512
1514
1515#ifdef EXPENSIVE_CHECKS
1516 assert((LocalChanged || (RefHash == MP->structuralHash(M))) &&
1517 "Pass modifies its input and doesn't report it.");
1518#endif
1519
1520 if (EmitICRemark) {
1521
1522 unsigned ModuleCount = M.getInstructionCount();
1524 int64_t Delta = static_cast<int64_t>(ModuleCount) -
1526 emitInstrCountChangedRemark(MP, M, Delta, InstrCount,
1527 FunctionToInstrCount);
1529 }
1530 }
1531 }
1532
1533 Changed |= LocalChanged;
1534 if (LocalChanged)
1536 M.getModuleIdentifier());
1537 dumpPreservedSet(MP);
1538 dumpUsedSet(MP);
1539
1540 verifyPreservedAnalysis(MP);
1541 if (LocalChanged)
1542 removeNotPreservedAnalysis(MP);
1543 recordAvailableAnalysis(MP);
1544 removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
1545 }
1546
1547
1548 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
1549 Changed |= getContainedPass(Index)->doFinalization(M);
1550
1551
1552 for (auto &OnTheFlyManager : OnTheFlyManagers) {
1554
1555
1558 }
1559
1561}
1562
1563
1564
1565
1566void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1567 assert(RequiredPass && "No required pass?");
1569 "Unable to handle Pass that requires lower level Analysis pass");
1570 assert((P->getPotentialPassManagerType() <
1572 "Unable to handle Pass that requires lower level Analysis pass");
1573
1575 if (!FPP) {
1577
1579
1580 OnTheFlyManagers[P] = FPP;
1581 }
1582 const PassInfo *RequiredPassPI =
1583 TPM->findAnalysisPassInfo(RequiredPass->getPassID());
1584
1585 Pass *FoundPass = nullptr;
1586 if (RequiredPassPI && RequiredPassPI->isAnalysis()) {
1587 FoundPass =
1589 }
1590 if (!FoundPass) {
1591 FoundPass = RequiredPass;
1592
1593
1594 FPP->add(RequiredPass);
1595 }
1596
1600}
1601
1602
1603
1604
1605std::tuple<Pass *, bool> MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI,
1608 assert(FPP && "Unable to find on the fly pass");
1609
1612 return std::make_tuple(((PMTopLevelManager *)FPP)->findAnalysisPass(PI),
1614}
1615
1616namespace llvm {
1618
1619
1620
1621
1622
1625
1626 PM->setTopLevelManager(PM);
1627}
1628
1632
1636
1637
1638
1640 return PM->run(M);
1641}
1642}
1643}
1644
1645
1646
1647
1648
1649
1651
1654
1655 S.pop_back();
1656}
1657
1658
1660 assert(PM && "Unable to push. Pass Manager expected");
1661 assert(PM->getDepth()==0 && "Pass Manager depth set too early");
1662
1663 if (!this->empty()) {
1665 && "pushing bad pass manager to PMStack");
1667
1668 assert(TPM && "Unable to find top level manager");
1671 PM->setDepth(this->top()->getDepth()+1);
1672 } else {
1675 && "pushing bad pass manager to PMStack");
1677 }
1678
1679 S.push_back(PM);
1680}
1681
1682
1685 dbgs() << Manager->getAsPass()->getPassName() << ' ';
1686
1687 if (!S.empty())
1688 dbgs() << '\n';
1689}
1690
1691
1692
1695
1698 T != PreferredType)
1699 PMS.pop();
1701}
1702
1703
1704
1707
1710 PMS.pop();
1711
1712
1714
1717
1718
1720
1721
1722
1724
1725
1726 PMS.push(FPP);
1727 PM = FPP;
1728 }
1729
1730
1731 PM->add(this);
1732}
1733
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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")
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.
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")))
print mir2vec MIR2Vec Vocabulary Printer Pass
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
This header defines classes/functions to handle pass execution timing information with interfaces for...
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
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).
LLVM_ABI Pass * getAnalysisIfAvailable(AnalysisID ID) const
Return analysis result or null if it doesn't exist.
Definition LegacyPassManager.cpp:1269
Represent the analysis usage information of a pass.
const VectorType & getRequiredSet() const
const VectorType & getRequiredTransitiveSet() const
SmallVectorImpl< AnalysisID > VectorType
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.
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Base class for error info classes.
FPPassManager manages BBPassManagers and FunctionPasses.
bool runOnFunction(Function &F)
run - Execute all of the passes scheduled for execution.
Definition LegacyPassManager.cpp:1356
bool doInitialization(Module &M) override
doInitialization - Run all of the initializers for the function passes.
Definition LegacyPassManager.cpp:1449
bool doFinalization(Module &M) override
doFinalization - Run all of the finalizers for the function passes.
Definition LegacyPassManager.cpp:1458
FunctionPass * getContainedPass(unsigned N)
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
Definition LegacyPassManager.cpp:1344
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
Definition LegacyPassManager.cpp:1440
void cleanup()
cleanup - After running all passes, clean up pass manager cache.
Definition LegacyPassManager.cpp:1329
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...
Definition LegacyPassManager.cpp:1705
ImmutablePass class - This class is used to provide information that does not need to be run.
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.
Definition LegacyPassManager.cpp:1693
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.
PMDataManager provides the common place to manage the analysis data used by pass managers.
void dumpPassArguments() const
Definition LegacyPassManager.cpp:1132
void removeDeadPasses(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove dead passes used by P.
Definition LegacyPassManager.cpp:946
void dumpLastUses(Pass *P, unsigned Offset) const
Definition LegacyPassManager.cpp:1114
virtual Pass * getAsPass()=0
virtual std::tuple< Pass *, bool > getOnTheFlyPass(Pass *P, AnalysisID PI, Function &F)
Definition LegacyPassManager.cpp:1255
void setDepth(unsigned newDepth)
void recordAvailableAnalysis(Pass *P)
Augment AvailableAnalysis by adding analysis made available by pass P.
Definition LegacyPassManager.cpp:858
Pass * findAnalysisPass(AnalysisID AID, bool Direction)
Find the pass that implements Analysis AID.
Definition LegacyPassManager.cpp:1098
bool isPassDebuggingExecutionsOrMore() const
isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions or higher is specified.
Definition LegacyPassManager.cpp:61
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.
Definition LegacyPassManager.cpp:1233
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.
Definition LegacyPassManager.cpp:65
void setTopLevelManager(PMTopLevelManager *T)
void dumpRequiredSet(const Pass *P) const
Definition LegacyPassManager.cpp:1182
void initializeAnalysisImpl(Pass *P)
All Required analyses should be available to the pass as it runs!
Definition LegacyPassManager.cpp:1081
void verifyPreservedAnalysis(Pass *P)
verifyPreservedAnalysis – Verify analysis presreved by pass P.
Definition LegacyPassManager.cpp:882
virtual ~PMDataManager()
Definition LegacyPassManager.cpp:1261
void initializeAnalysisInfo()
Initialize available analysis information.
void freePass(Pass *P, StringRef Msg, enum PassDebuggingString)
Remove P.
Definition LegacyPassManager.cpp:967
bool preserveHigherLevelAnalysis(Pass *P)
Definition LegacyPassManager.cpp:866
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.
Definition LegacyPassManager.cpp:87
void add(Pass *P, bool ProcessAnalysis=true)
Add pass P into the PassVector.
Definition LegacyPassManager.cpp:985
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.
Definition LegacyPassManager.cpp:1060
void populateInheritedAnalysis(PMStack &PMS)
void dumpPreservedSet(const Pass *P) const
Definition LegacyPassManager.cpp:1191
void dumpUsedSet(const Pass *P) const
Definition LegacyPassManager.cpp:1200
void removeNotPreservedAnalysis(Pass *P)
Remove Analysis that is not preserved by the pass.
Definition LegacyPassManager.cpp:900
void dumpPassInfo(Pass *P, enum PassDebuggingString S1, enum PassDebuggingString S2, StringRef Msg)
Definition LegacyPassManager.cpp:1141
PMStack - This class implements a stack data structure of PMDataManager pointers.
LLVM_ABI void pop()
Definition LegacyPassManager.cpp:1650
PMDataManager * top() const
LLVM_ABI void dump() const
Definition LegacyPassManager.cpp:1683
LLVM_ABI void push(PMDataManager *PM)
Definition LegacyPassManager.cpp:1659
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.
Definition LegacyPassManager.cpp:791
const PassInfo * findAnalysisPassInfo(AnalysisID AID) const
Retrieve the PassInfo for an analysis.
Definition LegacyPassManager.cpp:780
void setLastUser(ArrayRef< Pass * > AnalysisPasses, Pass *P)
Set pass P as the last user of the given analysis passes.
Definition LegacyPassManager.cpp:555
virtual ~PMTopLevelManager()
Destructor.
Definition LegacyPassManager.cpp:846
void schedulePass(Pass *P)
Schedule pass P for execution.
Definition LegacyPassManager.cpp:653
SmallVector< PMDataManager *, 8 > PassManagers
Collection of pass managers.
Pass * findAnalysisPass(AnalysisID AID)
Find the pass that implements Analysis AID.
Definition LegacyPassManager.cpp:761
void dumpArguments() const
Definition LegacyPassManager.cpp:820
AnalysisUsage * findAnalysisUsage(Pass *P)
Find analysis usage information for the pass P.
Definition LegacyPassManager.cpp:617
void dumpPasses() const
Definition LegacyPassManager.cpp:803
void addPassManager(PMDataManager *Manager)
unsigned getNumContainedManagers() const
void initializeAllAnalysisInfo()
Definition LegacyPassManager.cpp:836
SmallVectorImpl< ImmutablePass * > & getImmutablePasses()
PMTopLevelManager(PMDataManager *PMDM)
Initialize top level manager. Create first pass manager.
Definition LegacyPassManager.cpp:547
void collectLastUses(SmallVectorImpl< Pass * > &LastUses, Pass *P)
Collect passes whose last user is P.
Definition LegacyPassManager.cpp:607
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.
Definition LegacyPassManager.cpp:204
Manages a sequence of passes over a particular unit of IR.
PreservedAnalyses run(Function &IR, AnalysisManager< Function > &AM, ExtraArgTs... ExtraArgs)
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVM_ABI 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.
Pass(PassKind K, char &pid)
AnalysisID getPassID() const
getPassID - Return the PassID number that corresponds to this pass.
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 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...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
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.
FunctionPassManagerImpl manages FPPassManagers.
Definition LegacyPassManager.cpp:244
void add(Pass *P)
Definition LegacyPassManager.cpp:255
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
createPrinterPass - Get a function printer pass.
Definition LegacyPassManager.cpp:260
FPPassManager * getContainedManager(unsigned N)
Definition LegacyPassManager.cpp:293
FunctionPassManagerImpl()
Definition LegacyPassManager.cpp:250
void releaseMemoryOnTheFly()
Definition LegacyPassManager.cpp:339
bool doInitialization(Module &M) override
doInitialization - Run all of the initializers for the function passes.
Definition LegacyPassManager.cpp:312
PMDataManager * getAsPMDataManager() override
Definition LegacyPassManager.cpp:282
void dumpPassStructure(unsigned Offset) override
Definition LegacyPassManager.cpp:299
static char ID
Definition LegacyPassManager.cpp:249
Pass * getAsPass() override
Definition LegacyPassManager.cpp:283
bool run(Function &F)
run - Execute all of the passes scheduled for execution.
Definition LegacyPassManager.cpp:353
bool doFinalization(Module &M) override
doFinalization - Run all of the finalizers for the function passes.
Definition LegacyPassManager.cpp:327
PassManagerType getTopLevelPassManagerType() override
Definition LegacyPassManager.cpp:284
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
Definition LegacyPassManager.cpp:289
virtual ~PassManagerBase()
PassManagerImpl manages MPPassManagers.
Definition LegacyPassManager.cpp:466
PassManagerType getTopLevelPassManagerType() override
Definition LegacyPassManager.cpp:499
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
Definition LegacyPassManager.cpp:493
void add(Pass *P)
Add a pass to the queue of passes to run.
Definition LegacyPassManager.cpp:475
Pass * getAsPass() override
Definition LegacyPassManager.cpp:498
static char ID
Definition LegacyPassManager.cpp:470
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
Definition LegacyPassManager.cpp:520
PMDataManager * getAsPMDataManager() override
Definition LegacyPassManager.cpp:497
PassManagerImpl()
Definition LegacyPassManager.cpp:471
MPPassManager * getContainedManager(unsigned N)
Definition LegacyPassManager.cpp:503
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
createPrinterPass - Get a module printer pass.
Definition LegacyPassManager.cpp:480
void add(Pass *P) override
Add a pass to the queue of passes to run.
Definition LegacyPassManager.cpp:1633
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
Definition LegacyPassManager.cpp:1639
PassManager()
Create new pass manager.
Definition LegacyPassManager.cpp:1623
~PassManager() override
Definition LegacyPassManager.cpp:1629
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 ...
LLVM_ABI bool debugPassSpecified()
Definition LegacyPassManager.cpp:236
This is an optimization pass for GlobalISel generic memory operations.
UnaryFunction for_each(R &&Range, UnaryFunction F)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly.
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.
LLVM_ABI Timer * getPassTimer(Pass *)
Request the timer for this legacy-pass-manager's pass instance.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI 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.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool shouldPrintBeforePass(StringRef PassID)
bool shouldPrintAfterPass(StringRef PassID)
@ Disabled
Don't do any conversion of .debug_str_offsets tables.
LLVM_ABI 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.