+ Context.setDiagnosticHandler(diagnosticHandlerForContext, nullptr, true);
+
+ // If we are doing ThinLTO compilation, simply build the combined
+ // function index/summary and emit it. We don't need to parse the modules
+ // and link them in this case.
+ if (options::thinlto) {
+ FunctionInfoIndex CombinedIndex;
+ uint64_t NextModuleId = 0;
+ for (claimed_file &F : Modules) {
+ ld_plugin_input_file File;
+ if (get_input_file(F.handle, &File) != LDPS_OK)
+ message(LDPL_FATAL, "Failed to get file information");
+
+ std::unique_ptr<FunctionInfoIndex> Index =
+ getFunctionIndexForFile(F, File);
+
+ // Skip files without a function summary.
+ if (!Index)
+ continue;
+
+ CombinedIndex.mergeFrom(std::move(Index), ++NextModuleId);
+ }
+
+ std::error_code EC;
+ raw_fd_ostream OS(output_name + ".thinlto.bc", EC,
+ sys::fs::OpenFlags::F_None);
+ if (EC)
+ message(LDPL_FATAL, "Unable to open %s.thinlto.bc for writing: %s",
+ output_name.data(), EC.message().c_str());
+ WriteFunctionSummaryToFile(CombinedIndex, OS);
+ OS.close();
+
+ cleanup_hook();
+ exit(0);
+ }
+