diff options
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/llvm-lto/llvm-lto.cpp | 43 | ||||
| -rw-r--r-- | llvm/tools/lto/lto.cpp | 25 | ||||
| -rw-r--r-- | llvm/tools/lto/lto.exports | 4 |
3 files changed, 62 insertions, 10 deletions
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index 9aabe0a4282..585207b2518 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -204,6 +204,10 @@ static cl::opt<bool> ListSymbolsOnly( "list-symbols-only", cl::init(false), cl::desc("Instead of running LTO, list the symbols in each IR file")); +static cl::opt<bool> ListDependentLibrariesOnly( + "list-dependent-libraries-only", cl::init(false), + cl::desc("Instead of running LTO, list the dependent libraries in each IR file")); + static cl::opt<bool> SetMergedModule( "set-merged-module", cl::init(false), cl::desc("Use the first input module as the merged module")); @@ -372,6 +376,34 @@ static void listSymbols(const TargetOptions &Options) { } } +static std::unique_ptr<MemoryBuffer> loadFile(StringRef Filename) { + ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename.str() + + "': "); + return ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(Filename))); +} + +static void listDependentLibraries() { + for (auto &Filename : InputFilenames) { + auto Buffer = loadFile(Filename); + std::string E; + std::unique_ptr<lto::InputFile> Input(LTOModule::createInputFile( + Buffer->getBufferStart(), Buffer->getBufferSize(), Filename.c_str(), + E)); + if (!Input) + error(E); + + // List the dependent libraries. + outs() << Filename << ":\n"; + for (size_t I = 0, C = LTOModule::getDependentLibraryCount(Input.get()); + I != C; ++I) { + size_t L = 0; + const char *S = LTOModule::getDependentLibrary(Input.get(), I, &L); + assert(S); + outs() << StringRef(S, L) << "\n"; + } + } +} + /// Create a combined index file from the input IR files and write it. /// /// This is meant to enable testing of ThinLTO combined index generation, @@ -449,12 +481,6 @@ std::unique_ptr<ModuleSummaryIndex> loadCombinedIndex() { return ExitOnErr(getModuleSummaryIndexForFile(ThinLTOIndex)); } -static std::unique_ptr<MemoryBuffer> loadFile(StringRef Filename) { - ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename.str() + - "': "); - return ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(Filename))); -} - static std::unique_ptr<lto::InputFile> loadInputFile(MemoryBufferRef Buffer) { ExitOnError ExitOnErr("llvm-lto: error loading input '" + Buffer.getBufferIdentifier().str() + "': "); @@ -854,6 +880,11 @@ int main(int argc, char **argv) { return 0; } + if (ListDependentLibrariesOnly) { + listDependentLibraries(); + return 0; + } + if (IndexStats) { printIndexStats(); return 0; diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp index 01dc141ffd0..fc2d3da43c0 100644 --- a/llvm/tools/lto/lto.cpp +++ b/llvm/tools/lto/lto.cpp @@ -18,6 +18,7 @@ #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/LTO/LTO.h" #include "llvm/LTO/legacy/LTOCodeGenerator.h" #include "llvm/LTO/legacy/LTOModule.h" #include "llvm/LTO/legacy/ThinLTOCodeGenerator.h" @@ -325,10 +326,6 @@ const char* lto_module_get_linkeropts(lto_module_t mod) { return unwrap(mod)->getLinkerOpts().data(); } -const char* lto_module_get_dependent_libraries(lto_module_t mod) { - return unwrap(mod)->getDependentLibraries().data(); -} - void lto_codegen_set_diagnostic_handler(lto_code_gen_t cg, lto_diagnostic_handler_t diag_handler, void *ctxt) { @@ -635,3 +632,23 @@ lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg, sLastErrorString = "Unknown PIC model"; return true; } + +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(lto::InputFile, lto_input_t) + +lto_input_t lto_input_create(const void *buffer, size_t buffer_size, const char *path) { + return wrap(LTOModule::createInputFile(buffer, buffer_size, path, sLastErrorString)); +} + +void lto_input_dispose(lto_input_t input) { + delete unwrap(input); +} + +extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input) { + return LTOModule::getDependentLibraryCount(unwrap(input)); +} + +extern const char *lto_input_get_dependent_library(lto_input_t input, + size_t index, + size_t *size) { + return LTOModule::getDependentLibrary(unwrap(input), index, size); +} diff --git a/llvm/tools/lto/lto.exports b/llvm/tools/lto/lto.exports index cb881d104fb..34922c820d6 100644 --- a/llvm/tools/lto/lto.exports +++ b/llvm/tools/lto/lto.exports @@ -72,3 +72,7 @@ thinlto_codegen_disable_codegen thinlto_module_get_num_object_files thinlto_module_get_object_file thinlto_set_generated_objects_dir +lto_input_create +lto_input_destroy +lto_input_get_num_dependent_libraries +lto_input_get_dependent_library |

