Mercurial > hg > CbC > CbC_llvm
comparison lib/Bitcode/Writer/ValueEnumerator.cpp @ 100:7d135dc70f03 LLVM 3.9
LLVM 3.9
author | Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Jan 2016 22:53:40 +0900 |
parents | afa8332a0e37 |
children | 1172e4bd9c6f |
comparison
equal
deleted
inserted
replaced
96:6418606d0ead | 100:7d135dc70f03 |
---|---|
85 orderValue(G.getInitializer(), OM); | 85 orderValue(G.getInitializer(), OM); |
86 for (const GlobalAlias &A : M.aliases()) | 86 for (const GlobalAlias &A : M.aliases()) |
87 if (!isa<GlobalValue>(A.getAliasee())) | 87 if (!isa<GlobalValue>(A.getAliasee())) |
88 orderValue(A.getAliasee(), OM); | 88 orderValue(A.getAliasee(), OM); |
89 for (const Function &F : M) { | 89 for (const Function &F : M) { |
90 if (F.hasPrefixData()) | 90 for (const Use &U : F.operands()) |
91 if (!isa<GlobalValue>(F.getPrefixData())) | 91 if (!isa<GlobalValue>(U.get())) |
92 orderValue(F.getPrefixData(), OM); | 92 orderValue(U.get(), OM); |
93 if (F.hasPrologueData()) | |
94 if (!isa<GlobalValue>(F.getPrologueData())) | |
95 orderValue(F.getPrologueData(), OM); | |
96 if (F.hasPersonalityFn()) | |
97 if (!isa<GlobalValue>(F.getPersonalityFn())) | |
98 orderValue(F.getPersonalityFn(), OM); | |
99 } | 93 } |
100 OM.LastGlobalConstantID = OM.size(); | 94 OM.LastGlobalConstantID = OM.size(); |
101 | 95 |
102 // Initializers of GlobalValues are processed in | 96 // Initializers of GlobalValues are processed in |
103 // BitcodeReader::ResolveGlobalAndAliasInits(). Match the order there rather | 97 // BitcodeReader::ResolveGlobalAndAliasInits(). Match the order there rather |
271 if (G.hasInitializer()) | 265 if (G.hasInitializer()) |
272 predictValueUseListOrder(G.getInitializer(), nullptr, OM, Stack); | 266 predictValueUseListOrder(G.getInitializer(), nullptr, OM, Stack); |
273 for (const GlobalAlias &A : M.aliases()) | 267 for (const GlobalAlias &A : M.aliases()) |
274 predictValueUseListOrder(A.getAliasee(), nullptr, OM, Stack); | 268 predictValueUseListOrder(A.getAliasee(), nullptr, OM, Stack); |
275 for (const Function &F : M) { | 269 for (const Function &F : M) { |
276 if (F.hasPrefixData()) | 270 for (const Use &U : F.operands()) |
277 predictValueUseListOrder(F.getPrefixData(), nullptr, OM, Stack); | 271 predictValueUseListOrder(U.get(), nullptr, OM, Stack); |
278 if (F.hasPrologueData()) | |
279 predictValueUseListOrder(F.getPrologueData(), nullptr, OM, Stack); | |
280 if (F.hasPersonalityFn()) | |
281 predictValueUseListOrder(F.getPersonalityFn(), nullptr, OM, Stack); | |
282 } | 272 } |
283 | 273 |
284 return Stack; | 274 return Stack; |
285 } | 275 } |
286 | 276 |
319 | 309 |
320 // Enumerate the aliasees. | 310 // Enumerate the aliasees. |
321 for (const GlobalAlias &GA : M.aliases()) | 311 for (const GlobalAlias &GA : M.aliases()) |
322 EnumerateValue(GA.getAliasee()); | 312 EnumerateValue(GA.getAliasee()); |
323 | 313 |
324 // Enumerate the prefix data constants. | 314 // Enumerate any optional Function data. |
325 for (const Function &F : M) | 315 for (const Function &F : M) |
326 if (F.hasPrefixData()) | 316 for (const Use &U : F.operands()) |
327 EnumerateValue(F.getPrefixData()); | 317 EnumerateValue(U.get()); |
328 | |
329 // Enumerate the prologue data constants. | |
330 for (const Function &F : M) | |
331 if (F.hasPrologueData()) | |
332 EnumerateValue(F.getPrologueData()); | |
333 | |
334 // Enumerate the personality functions. | |
335 for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) | |
336 if (I->hasPersonalityFn()) | |
337 EnumerateValue(I->getPersonalityFn()); | |
338 | 318 |
339 // Enumerate the metadata type. | 319 // Enumerate the metadata type. |
340 // | 320 // |
341 // TODO: Move this to ValueEnumerator::EnumerateOperandType() once bitcode | 321 // TODO: Move this to ValueEnumerator::EnumerateOperandType() once bitcode |
342 // only encodes the metadata type when it's used as a value. | 322 // only encodes the metadata type when it's used as a value. |
423 } | 403 } |
424 | 404 |
425 void ValueEnumerator::dump() const { | 405 void ValueEnumerator::dump() const { |
426 print(dbgs(), ValueMap, "Default"); | 406 print(dbgs(), ValueMap, "Default"); |
427 dbgs() << '\n'; | 407 dbgs() << '\n'; |
428 print(dbgs(), MDValueMap, "MetaData"); | 408 print(dbgs(), MetadataMap, "MetaData"); |
429 dbgs() << '\n'; | 409 dbgs() << '\n'; |
430 } | 410 } |
431 | 411 |
432 void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map, | 412 void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map, |
433 const char *Name) const { | 413 const char *Name) const { |
540 | 520 |
541 // Insert a dummy ID to block the co-recursive call to | 521 // Insert a dummy ID to block the co-recursive call to |
542 // EnumerateMDNodeOperands() from re-visiting MD in a cyclic graph. | 522 // EnumerateMDNodeOperands() from re-visiting MD in a cyclic graph. |
543 // | 523 // |
544 // Return early if there's already an ID. | 524 // Return early if there's already an ID. |
545 if (!MDValueMap.insert(std::make_pair(MD, 0)).second) | 525 if (!MetadataMap.insert(std::make_pair(MD, 0)).second) |
546 return; | 526 return; |
547 | 527 |
548 // Visit operands first to minimize RAUW. | 528 // Visit operands first to minimize RAUW. |
549 if (auto *N = dyn_cast<MDNode>(MD)) | 529 if (auto *N = dyn_cast<MDNode>(MD)) |
550 EnumerateMDNodeOperands(N); | 530 EnumerateMDNodeOperands(N); |
553 | 533 |
554 HasMDString |= isa<MDString>(MD); | 534 HasMDString |= isa<MDString>(MD); |
555 HasDILocation |= isa<DILocation>(MD); | 535 HasDILocation |= isa<DILocation>(MD); |
556 HasGenericDINode |= isa<GenericDINode>(MD); | 536 HasGenericDINode |= isa<GenericDINode>(MD); |
557 | 537 |
558 // Replace the dummy ID inserted above with the correct one. MDValueMap may | 538 // Replace the dummy ID inserted above with the correct one. MetadataMap may |
559 // have changed by inserting operands, so we need a fresh lookup here. | 539 // have changed by inserting operands, so we need a fresh lookup here. |
560 MDs.push_back(MD); | 540 MDs.push_back(MD); |
561 MDValueMap[MD] = MDs.size(); | 541 MetadataMap[MD] = MDs.size(); |
562 } | 542 } |
563 | 543 |
564 /// EnumerateFunctionLocalMetadataa - Incorporate function-local metadata | 544 /// EnumerateFunctionLocalMetadataa - Incorporate function-local metadata |
565 /// information reachable from the metadata. | 545 /// information reachable from the metadata. |
566 void ValueEnumerator::EnumerateFunctionLocalMetadata( | 546 void ValueEnumerator::EnumerateFunctionLocalMetadata( |
567 const LocalAsMetadata *Local) { | 547 const LocalAsMetadata *Local) { |
568 // Check to see if it's already in! | 548 // Check to see if it's already in! |
569 unsigned &MDValueID = MDValueMap[Local]; | 549 unsigned &MetadataID = MetadataMap[Local]; |
570 if (MDValueID) | 550 if (MetadataID) |
571 return; | 551 return; |
572 | 552 |
573 MDs.push_back(Local); | 553 MDs.push_back(Local); |
574 MDValueID = MDs.size(); | 554 MetadataID = MDs.size(); |
575 | 555 |
576 EnumerateValue(Local->getValue()); | 556 EnumerateValue(Local->getValue()); |
577 | 557 |
578 // Also, collect all function-local metadata for easy access. | 558 // Also, collect all function-local metadata for easy access. |
579 FunctionLocalMDs.push_back(Local); | 559 FunctionLocalMDs.push_back(Local); |
776 void ValueEnumerator::purgeFunction() { | 756 void ValueEnumerator::purgeFunction() { |
777 /// Remove purged values from the ValueMap. | 757 /// Remove purged values from the ValueMap. |
778 for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i) | 758 for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i) |
779 ValueMap.erase(Values[i].first); | 759 ValueMap.erase(Values[i].first); |
780 for (unsigned i = NumModuleMDs, e = MDs.size(); i != e; ++i) | 760 for (unsigned i = NumModuleMDs, e = MDs.size(); i != e; ++i) |
781 MDValueMap.erase(MDs[i]); | 761 MetadataMap.erase(MDs[i]); |
782 for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i) | 762 for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i) |
783 ValueMap.erase(BasicBlocks[i]); | 763 ValueMap.erase(BasicBlocks[i]); |
784 | 764 |
785 Values.resize(NumModuleValues); | 765 Values.resize(NumModuleValues); |
786 MDs.resize(NumModuleMDs); | 766 MDs.resize(NumModuleMDs); |