1414#include " llvm/Bitcode/BitcodeWriter.h"
1515#include " llvm/CGData/CodeGenDataReader.h"
1616#include " llvm/CGData/OutlinedHashTreeRecord.h"
17+ #include " llvm/CGData/StableFunctionMapRecord.h"
1718#include " llvm/Object/ObjectFile.h"
1819#include " llvm/Support/Caching.h"
1920#include " llvm/Support/CommandLine.h"
@@ -163,6 +164,8 @@ CodeGenData &CodeGenData::getInstance() {
163164 auto Reader = ReaderOrErr->get ();
164165 if (Reader->hasOutlinedHashTree ())
165166 Instance->publishOutlinedHashTree (Reader->releaseOutlinedHashTree ());
167+ if (Reader->hasStableFunctionMap ())
168+ Instance->publishStableFunctionMap (Reader->releaseStableFunctionMap ());
166169 }
167170 });
168171 return *(Instance.get ());
@@ -185,18 +188,14 @@ Expected<Header> Header::readFromBuffer(const unsigned char *Curr) {
185188 return make_error<CGDataError>(cgdata_error::unsupported_version);
186189 H.DataKind = endian::readNext<uint32_t , endianness::little, unaligned>(Curr);
187190
188- switch (H.Version ) {
189- // When a new field is added to the header add a case statement here to
190- // compute the size as offset of the new field + size of the new field. This
191- // relies on the field being added to the end of the list.
192- static_assert (IndexedCGData::CGDataVersion::CurrentVersion == Version1,
193- " Please update the size computation below if a new field has "
194- " been added to the header, if not add a case statement to "
195- " fall through to the latest version." );
196- case 1ull :
197- H.OutlinedHashTreeOffset =
191+ static_assert (IndexedCGData::CGDataVersion::CurrentVersion == Version2,
192+ " Please update the offset computation below if a new field has "
193+ " been added to the header." );
194+ H.OutlinedHashTreeOffset =
195+ endian::readNext<uint64_t , endianness::little, unaligned>(Curr);
196+ if (H.Version >= 2 )
197+ H.StableFunctionMapOffset =
198198 endian::readNext<uint64_t , endianness::little, unaligned>(Curr);
199- }
200199
201200 return H;
202201}
@@ -257,6 +256,7 @@ std::unique_ptr<Module> loadModuleForTwoRounds(BitcodeModule &OrigModule,
257256
258257Expected<stable_hash> mergeCodeGenData (ArrayRef<StringRef> ObjFiles) {
259258 OutlinedHashTreeRecord GlobalOutlineRecord;
259+ StableFunctionMapRecord GlobalStableFunctionMapRecord;
260260 stable_hash CombinedHash = 0 ;
261261 for (auto File : ObjFiles) {
262262 if (File.empty ())
@@ -270,12 +270,18 @@ Expected<stable_hash> mergeCodeGenData(ArrayRef<StringRef> ObjFiles) {
270270
271271 std::unique_ptr<object::ObjectFile> &Obj = BinOrErr.get ();
272272 if (auto E = CodeGenDataReader::mergeFromObjectFile (
273- Obj.get (), GlobalOutlineRecord, &CombinedHash))
273+ Obj.get (), GlobalOutlineRecord, GlobalStableFunctionMapRecord,
274+ &CombinedHash))
274275 return E;
275276 }
276277
278+ GlobalStableFunctionMapRecord.finalize ();
279+
277280 if (!GlobalOutlineRecord.empty ())
278281 cgdata::publishOutlinedHashTree (std::move (GlobalOutlineRecord.HashTree ));
282+ if (!GlobalStableFunctionMapRecord.empty ())
283+ cgdata::publishStableFunctionMap (
284+ std::move (GlobalStableFunctionMapRecord.FunctionMap ));
279285
280286 return CombinedHash;
281287}
0 commit comments