Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 88a607f

Browse files
committed
IRGen: Factor out function clang::FindThinLTOModule. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292970 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9d48ebf commit 88a607f

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

include/clang/CodeGen/BackendUtil.h

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <memory>
1616

1717
namespace llvm {
18+
class BitcodeModule;
19+
template <typename T> class Expected;
1820
class Module;
1921
class MemoryBufferRef;
2022
}
@@ -44,6 +46,9 @@ namespace clang {
4446

4547
void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
4648
llvm::MemoryBufferRef Buf);
49+
50+
llvm::Expected<llvm::BitcodeModule>
51+
FindThinLTOModule(llvm::MemoryBufferRef MBRef);
4752
}
4853

4954
#endif

lib/CodeGen/BackendUtil.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,23 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
862862
}
863863
}
864864

865+
Expected<BitcodeModule> clang::FindThinLTOModule(MemoryBufferRef MBRef) {
866+
Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList(MBRef);
867+
if (!BMsOrErr)
868+
return BMsOrErr.takeError();
869+
870+
// The bitcode file may contain multiple modules, we want the one with a
871+
// summary.
872+
for (BitcodeModule &BM : *BMsOrErr) {
873+
Expected<bool> HasSummary = BM.hasSummary();
874+
if (HasSummary && *HasSummary)
875+
return BM;
876+
}
877+
878+
return make_error<StringError>("Could not find module summary",
879+
inconvertibleErrorCode());
880+
}
881+
865882
static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
866883
std::unique_ptr<raw_pwrite_stream> OS,
867884
std::string SampleProfile) {
@@ -899,32 +916,15 @@ static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
899916
return;
900917
}
901918

902-
Expected<std::vector<BitcodeModule>> BMsOrErr =
903-
getBitcodeModuleList(**MBOrErr);
904-
if (!BMsOrErr) {
905-
handleAllErrors(BMsOrErr.takeError(), [&](ErrorInfoBase &EIB) {
919+
Expected<BitcodeModule> BMOrErr = FindThinLTOModule(**MBOrErr);
920+
if (!BMOrErr) {
921+
handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase &EIB) {
906922
errs() << "Error loading imported file '" << I.first()
907923
<< "': " << EIB.message() << '\n';
908924
});
909925
return;
910926
}
911-
912-
// The bitcode file may contain multiple modules, we want the one with a
913-
// summary.
914-
bool FoundModule = false;
915-
for (BitcodeModule &BM : *BMsOrErr) {
916-
Expected<bool> HasSummary = BM.hasSummary();
917-
if (HasSummary && *HasSummary) {
918-
ModuleMap.insert({I.first(), BM});
919-
FoundModule = true;
920-
break;
921-
}
922-
}
923-
if (!FoundModule) {
924-
errs() << "Error loading imported file '" << I.first()
925-
<< "': Could not find module summary\n";
926-
return;
927-
}
927+
ModuleMap.insert({I.first(), *BMOrErr});
928928

929929
OwnedImports.push_back(std::move(*MBOrErr));
930930
}

0 commit comments

Comments
 (0)