| 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("convert-to-pso-deps", |
| 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 (auto dependency : LibraryDependencies) { |
| 664 DependenciesList.append(dependency); |
| 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), |
| 679 }; | 698 }; |
| 680 for (auto FieldVal : PsoRootTlsFields) | 699 for (auto FieldVal : PsoRootTlsFields) |
| 681 PsoRoot.push_back(FieldVal); | 700 PsoRoot.push_back(FieldVal); |
| 701 |
| 702 // Dependencies List |
| 703 PsoRoot.push_back(ConstantInt::get(IntPtrType, LibraryDependencies.size())); |
| 704 PsoRoot.push_back(DependenciesListVar); |
| 705 |
| 682 Constant *PsoRootConst = ConstantStruct::getAnon(PsoRoot); | 706 Constant *PsoRootConst = ConstantStruct::getAnon(PsoRoot); |
| 683 new GlobalVariable( | 707 new GlobalVariable( |
| 684 M, PsoRootConst->getType(), true, GlobalValue::ExternalLinkage, | 708 M, PsoRootConst->getType(), true, GlobalValue::ExternalLinkage, |
| 685 PsoRootConst, "__pnacl_pso_root"); | 709 PsoRootConst, "__pnacl_pso_root"); |
| 686 | 710 |
| 687 // As soon as we have finished exporting aliases, we can resolve them. | 711 // As soon as we have finished exporting aliases, we can resolve them. |
| 688 ModulePass *AliasPass = createResolveAliasesPass(); | 712 ModulePass *AliasPass = createResolveAliasesPass(); |
| 689 AliasPass->runOnModule(M); | 713 AliasPass->runOnModule(M); |
| 690 delete AliasPass; | 714 delete AliasPass; |
| 691 | 715 |
| 692 return true; | 716 return true; |
| 693 } | 717 } |
| 694 | 718 |
| 695 ModulePass *llvm::createConvertToPSOPass() { | 719 ModulePass *llvm::createConvertToPSOPass() { |
| 696 return new ConvertToPSO(); | 720 return new ConvertToPSO(); |
| 697 } | 721 } |
| OLD | NEW |