Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- ConvertToPSO.cpp - Convert module to a PNaCl PSO--------------------===// | 1 //===- ConvertToPSO.cpp - Convert module to a PNaCl PSO--------------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // The ConvertToPSO pass is part of an implementation of dynamic | 10 // The ConvertToPSO pass is part of an implementation of dynamic |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 // | 55 // |
| 56 // For the time being, this is intended only as a convenience for making | 56 // For the time being, this is intended only as a convenience for making |
| 57 // cross-repo changes, because the PSO format is interpreted by code in | 57 // cross-repo changes, because the PSO format is interpreted by code in |
| 58 // the native_client repo. The PSO format is not intended to be stable | 58 // the native_client repo. The PSO format is not intended to be stable |
| 59 // yet. | 59 // yet. |
| 60 // | 60 // |
| 61 // If the format is changed in a compatible way, an alternative is to | 61 // If the format is changed in a compatible way, an alternative is to |
| 62 // increment TOOLCHAIN_FEATURE_VERSION instead. | 62 // increment TOOLCHAIN_FEATURE_VERSION instead. |
| 63 const int PSOFormatVersion = 2; | 63 const int PSOFormatVersion = 2; |
| 64 | 64 |
| 65 // Command line arguments consist of a list of PLL dependencies. | |
| 66 static cl::list<std::string> | |
| 67 LibraryDependencies("deps", | |
|
Mark Seaborn
2016/03/29 15:29:39
Remember that this is an option for the 'opt' tool
Sean Klein
2016/03/29 17:58:29
Done.
| |
| 68 cl::CommaSeparated, | |
| 69 cl::desc("The dependencies of the PLL being built"), | |
| 70 cl::value_desc("PLL to list as dependency")); | |
| 71 | |
| 65 // This is a ModulePass because it inherently operates on a whole module. | 72 // This is a ModulePass because it inherently operates on a whole module. |
| 66 class ConvertToPSO : public ModulePass { | 73 class ConvertToPSO : public ModulePass { |
| 67 public: | 74 public: |
| 68 static char ID; // Pass identification, replacement for typeid | 75 static char ID; // Pass identification, replacement for typeid |
| 69 ConvertToPSO() : ModulePass(ID) { | 76 ConvertToPSO() : ModulePass(ID) { |
| 70 initializeConvertToPSOPass(*PassRegistry::getPassRegistry()); | 77 initializeConvertToPSOPass(*PassRegistry::getPassRegistry()); |
| 71 } | 78 } |
| 72 | 79 |
| 73 virtual bool runOnModule(Module &M); | 80 virtual bool runOnModule(Module &M); |
| 74 }; | 81 }; |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 // This lets us remove the "NumChainEntries" field from the PsoRoot. | 651 // This lets us remove the "NumChainEntries" field from the PsoRoot. |
| 645 assert(NumChainEntries == ExportPtrs.size() && "Malformed export hash table"); | 652 assert(NumChainEntries == ExportPtrs.size() && "Malformed export hash table"); |
| 646 | 653 |
| 647 // Set up string of exported names. | 654 // Set up string of exported names. |
| 648 Constant *StringTableArray = ConstantDataArray::getString( | 655 Constant *StringTableArray = ConstantDataArray::getString( |
| 649 C, StringRef(StringTable.data(), StringTable.size()), false); | 656 C, StringRef(StringTable.data(), StringTable.size()), false); |
| 650 Constant *StringTableVar = new GlobalVariable( | 657 Constant *StringTableVar = new GlobalVariable( |
| 651 M, StringTableArray->getType(), true, GlobalValue::InternalLinkage, | 658 M, StringTableArray->getType(), true, GlobalValue::InternalLinkage, |
| 652 StringTableArray, "string_table"); | 659 StringTableArray, "string_table"); |
| 653 | 660 |
| 661 // Set up string of PLL dependencies. | |
| 662 SmallString<1024> DependenciesList; | |
| 663 for (unsigned i = 0; i != LibraryDependencies.size(); ++i) { | |
|
Mark Seaborn
2016/03/29 15:29:39
You can use "for (... : LibrariesDependencies)"
Sean Klein
2016/03/29 17:58:29
Done.
| |
| 664 DependenciesList.append(LibraryDependencies[i]); | |
| 665 DependenciesList.push_back(0); | |
| 666 } | |
| 667 Constant *DependenciesListArray = ConstantDataArray::getString( | |
| 668 C, StringRef(DependenciesList.data(), DependenciesList.size()), false); | |
| 669 Constant *DependenciesListVar = new GlobalVariable( | |
| 670 M, DependenciesListArray->getType(), true, GlobalValue::InternalLinkage, | |
| 671 DependenciesListArray, "dependencies_list"); | |
| 672 | |
| 654 SmallVector<Constant *, 32> PsoRoot = { | 673 SmallVector<Constant *, 32> PsoRoot = { |
| 655 ConstantInt::get(IntPtrType, PSOFormatVersion), | 674 ConstantInt::get(IntPtrType, PSOFormatVersion), |
| 656 | 675 |
| 657 // String Table | 676 // String Table |
| 658 StringTableVar, | 677 StringTableVar, |
| 659 | 678 |
| 660 // Exports | 679 // Exports |
| 661 createArray(M, "export_ptrs", &ExportPtrs, PtrType), | 680 createArray(M, "export_ptrs", &ExportPtrs, PtrType), |
| 662 createArray(M, "export_names", &ExportNames, IntPtrType), | 681 createArray(M, "export_names", &ExportNames, IntPtrType), |
| 663 ConstantInt::get(IntPtrType, ExportPtrs.size()), | 682 ConstantInt::get(IntPtrType, ExportPtrs.size()), |
| 664 | 683 |
| 665 // Imports | 684 // Imports |
| 666 createArray(M, "import_ptrs", &ImportPtrs, PtrType), | 685 createArray(M, "import_ptrs", &ImportPtrs, PtrType), |
| 667 createArray(M, "import_names", &ImportNames, IntPtrType), | 686 createArray(M, "import_names", &ImportNames, IntPtrType), |
| 668 ConstantInt::get(IntPtrType, ImportPtrs.size()), | 687 ConstantInt::get(IntPtrType, ImportPtrs.size()), |
| 669 | 688 |
| 670 // Hash Table (for quick string lookup of exports) | 689 // Hash Table (for quick string lookup of exports) |
| 671 ConstantInt::get(IntPtrType, NumBuckets), | 690 ConstantInt::get(IntPtrType, NumBuckets), |
| 672 createDataArray(M, "hash_buckets", &HashBuckets), | 691 createDataArray(M, "hash_buckets", &HashBuckets), |
| 673 createDataArray(M, "hash_chains", &HashChains), | 692 createDataArray(M, "hash_chains", &HashChains), |
| 674 | 693 |
| 675 // Bloom Filter (for quick string lookup rejection of exports) | 694 // Bloom Filter (for quick string lookup rejection of exports) |
| 676 ConstantInt::get(IntPtrType, MaskWords - 1), | 695 ConstantInt::get(IntPtrType, MaskWords - 1), |
| 677 ConstantInt::get(IntPtrType, Shift2), | 696 ConstantInt::get(IntPtrType, Shift2), |
| 678 createDataArray(M, "bloom_filter", &BloomFilter), | 697 createDataArray(M, "bloom_filter", &BloomFilter), |
| 698 | |
| 699 // Dependencies List | |
|
Mark Seaborn
2016/03/29 15:40:06
When you rebase, this should go at the end, after
Sean Klein
2016/03/29 17:58:29
Do you mean that I should place these fields after
Mark Seaborn
2016/03/29 18:50:44
Yes, that would be better in the sense that it avo
| |
| 700 ConstantInt::get(IntPtrType, LibraryDependencies.size()), | |
| 701 DependenciesListVar, | |
| 679 }; | 702 }; |
| 680 for (auto FieldVal : PsoRootTlsFields) | 703 for (auto FieldVal : PsoRootTlsFields) |
| 681 PsoRoot.push_back(FieldVal); | 704 PsoRoot.push_back(FieldVal); |
| 682 Constant *PsoRootConst = ConstantStruct::getAnon(PsoRoot); | 705 Constant *PsoRootConst = ConstantStruct::getAnon(PsoRoot); |
| 683 new GlobalVariable( | 706 new GlobalVariable( |
| 684 M, PsoRootConst->getType(), true, GlobalValue::ExternalLinkage, | 707 M, PsoRootConst->getType(), true, GlobalValue::ExternalLinkage, |
| 685 PsoRootConst, "__pnacl_pso_root"); | 708 PsoRootConst, "__pnacl_pso_root"); |
| 686 | 709 |
| 687 // As soon as we have finished exporting aliases, we can resolve them. | 710 // As soon as we have finished exporting aliases, we can resolve them. |
| 688 ModulePass *AliasPass = createResolveAliasesPass(); | 711 ModulePass *AliasPass = createResolveAliasesPass(); |
| 689 AliasPass->runOnModule(M); | 712 AliasPass->runOnModule(M); |
| 690 delete AliasPass; | 713 delete AliasPass; |
| 691 | 714 |
| 692 return true; | 715 return true; |
| 693 } | 716 } |
| 694 | 717 |
| 695 ModulePass *llvm::createConvertToPSOPass() { | 718 ModulePass *llvm::createConvertToPSOPass() { |
| 696 return new ConvertToPSO(); | 719 return new ConvertToPSO(); |
| 697 } | 720 } |
| OLD | NEW |