diff options
author | Zachary Turner <zturner@google.com> | 2017-05-23 15:50:37 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-05-23 15:50:37 +0000 |
commit | bf35e6ab2aae9b3d529d0659248ebb1af1a330d6 (patch) | |
tree | e34a07558433a11fecc9fe46ef94c6dd02a52efe /llvm/lib/DebugInfo/CodeView | |
parent | 57253043a4cf24a20b6dff922f9397e425761774 (diff) | |
download | bcm5719-llvm-bf35e6ab2aae9b3d529d0659248ebb1af1a330d6.tar.gz bcm5719-llvm-bf35e6ab2aae9b3d529d0659248ebb1af1a330d6.zip |
Revert "Make TypeSerializer's StringMap use the same allocator."
This reverts commit e34ccb7b57da25cc89ded913d8638a2906d1110a.
This is causing failures on the ASAN bots.
llvm-svn: 303640
Diffstat (limited to 'llvm/lib/DebugInfo/CodeView')
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp | 43 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp | 2 |
2 files changed, 32 insertions, 13 deletions
diff --git a/llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp b/llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp index f9865600bf8..3b061e67e05 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeSerializer.cpp @@ -52,26 +52,45 @@ Error TypeSerializer::writeRecordPrefix(TypeLeafKind Kind) { } TypeIndex -TypeSerializer::insertRecordBytesPrivate(ArrayRef<uint8_t> &Record) { +TypeSerializer::insertRecordBytesPrivate(MutableArrayRef<uint8_t> Record) { assert(Record.size() % 4 == 0 && "Record is not aligned to 4 bytes!"); StringRef S(reinterpret_cast<const char *>(Record.data()), Record.size()); TypeIndex NextTypeIndex = calcNextTypeIndex(); auto Result = HashedRecords.try_emplace(S, NextTypeIndex); - - StringRef NewData = Result.first->getKey(); - Record = ArrayRef<uint8_t>(NewData.bytes_begin(), NewData.bytes_end()); - if (Result.second) { - // If this triggered an insert into the map, store the bytes. LastTypeIndex = NextTypeIndex; SeenRecords.push_back(Record); } - return Result.first->getValue(); } +TypeIndex +TypeSerializer::insertRecordBytesWithCopy(CVType &Record, + MutableArrayRef<uint8_t> Data) { + assert(Data.size() % 4 == 0 && "Record is not aligned to 4 bytes!"); + + StringRef S(reinterpret_cast<const char *>(Data.data()), Data.size()); + + // Do a two state lookup / insert so that we don't have to allocate unless + // we're going + // to do an insert. This is a big memory savings. + auto Iter = HashedRecords.find(S); + if (Iter != HashedRecords.end()) + return Iter->second; + + LastTypeIndex = calcNextTypeIndex(); + uint8_t *Copy = RecordStorage.Allocate<uint8_t>(Data.size()); + ::memcpy(Copy, Data.data(), Data.size()); + Data = MutableArrayRef<uint8_t>(Copy, Data.size()); + S = StringRef(reinterpret_cast<const char *>(Data.data()), Data.size()); + HashedRecords.insert(std::make_pair(S, LastTypeIndex)); + SeenRecords.push_back(Data); + Record.RecordData = Data; + return LastTypeIndex; +} + Expected<MutableArrayRef<uint8_t>> TypeSerializer::addPadding(MutableArrayRef<uint8_t> Record) { uint32_t Align = Record.size() % 4; @@ -93,19 +112,19 @@ TypeSerializer::TypeSerializer(BumpPtrAllocator &Storage) : RecordStorage(Storage), LastTypeIndex(), RecordBuffer(MaxRecordLength * 2), Stream(RecordBuffer, llvm::support::little), Writer(Stream), - Mapping(Writer), HashedRecords(Storage) { + Mapping(Writer) { // RecordBuffer needs to be able to hold enough data so that if we are 1 // byte short of MaxRecordLen, and then we try to write MaxRecordLen bytes, // we won't overflow. } -ArrayRef<ArrayRef<uint8_t>> TypeSerializer::records() const { +ArrayRef<MutableArrayRef<uint8_t>> TypeSerializer::records() const { return SeenRecords; } TypeIndex TypeSerializer::getLastTypeIndex() const { return LastTypeIndex; } -TypeIndex TypeSerializer::insertRecordBytes(ArrayRef<uint8_t> Record) { +TypeIndex TypeSerializer::insertRecordBytes(MutableArrayRef<uint8_t> Record) { assert(!TypeKind.hasValue() && "Already in a type mapping!"); assert(Writer.getOffset() == 0 && "Stream has data already!"); @@ -144,8 +163,8 @@ Expected<TypeIndex> TypeSerializer::visitTypeEndGetIndex(CVType &Record) { Prefix->RecordLen = ThisRecordData.size() - sizeof(uint16_t); Record.Type = *TypeKind; - Record.RecordData = ThisRecordData; - TypeIndex InsertedTypeIndex = insertRecordBytesPrivate(Record.RecordData); + TypeIndex InsertedTypeIndex = + insertRecordBytesWithCopy(Record, ThisRecordData); // Write out each additional segment in reverse order, and update each // record's continuation index to point to the previous one. diff --git a/llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp b/llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp index 4adecbc483e..a18710d6ab5 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp @@ -25,7 +25,7 @@ static void error(Error &&EC) { } TypeTableCollection::TypeTableCollection( - ArrayRef<ArrayRef<uint8_t>> Records) + ArrayRef<MutableArrayRef<uint8_t>> Records) : Records(Records), Database(Records.size()) {} Optional<TypeIndex> TypeTableCollection::getFirst() { |