summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-lto
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-lto')
-rw-r--r--llvm/tools/llvm-lto/llvm-lto.cpp43
1 files changed, 37 insertions, 6 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;
OpenPOWER on IntegriCloud