Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Unified Diff: lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp

Issue 1838203002: Modify NaCl bitstream reader to allow parallel parses. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp
index bd43d0b390e8edad754de9a8a8d7b6ad184a89d3..87e8de4bec75aefc80e400576bc40857b4285f39 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp
+++ b/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp
@@ -49,8 +49,7 @@ Fatal(const std::string &ErrorMessage) const {
// the error occurred.
std::string Buffer;
raw_string_ostream StrBuf(Buffer);
- naclbitc::ErrorAt(StrBuf, naclbitc::Fatal, Cursor.GetCurrentBitNo())
- << ErrorMessage;
+ naclbitc::ErrorAt(StrBuf, naclbitc::Fatal, getCurrentBitNo()) << ErrorMessage;
report_fatal_error(StrBuf.str());
}
@@ -74,8 +73,7 @@ bool NaClBitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) {
const bool IsFixed = true;
NaClBitcodeSelectorAbbrev
CodeAbbrev(IsFixed, ReadVBR(naclbitc::CodeLenWidth));
- BlockScope.push_back(Block(&BitStream->getOrCreateBlockInfo(BlockID),
- CodeAbbrev));
+ BlockScope.push_back(Block(&BitStream->getBlockInfo(BlockID), CodeAbbrev));
SkipToFourByteBoundary();
unsigned NumWords = Read(naclbitc::BlockSizeWidth);
if (NumWordsP) *NumWordsP = NumWords;
@@ -330,13 +328,49 @@ void NaClBitstreamCursor::SkipAbbrevRecord() {
SkipToByteBoundaryIfAligned();
}
+namespace {
+
+unsigned ValidBlockIDs[] = {
+ naclbitc::BLOCKINFO_BLOCK_ID,
+ naclbitc::CONSTANTS_BLOCK_ID,
+ naclbitc::FUNCTION_BLOCK_ID,
+ naclbitc::GLOBALVAR_BLOCK_ID,
+ naclbitc::MODULE_BLOCK_ID,
+ naclbitc::TOP_LEVEL_BLOCKID,
+ naclbitc::TYPE_BLOCK_ID_NEW,
+ naclbitc::VALUE_SYMTAB_BLOCK_ID
+};
+
+const size_t InfosBucketSize = 23;
+
+} // end of anonymous namespace
John 2016/03/29 16:27:10 is this annotation part of the llvm coding style?
Karl 2016/03/29 20:10:47 There is a similar comment at the beginning of the
+
+NaClBitstreamReader::BlockInfoRecordsMap::
+BlockInfoRecordsMap() : Infos(InfosBucketSize), IsFrozen(false) {
+ for (size_t i = 0; i < array_lengthof(ValidBlockIDs); ++i) {
John 2016/03/29 16:27:10 you can use for each loops for static array !!!! (
Karl 2016/03/29 20:10:47 Done.
+ unsigned BlockID = ValidBlockIDs[i];
+ Infos.emplace(BlockID, BlockInfo(BlockID));
+ }
+}
+
+NaClBitstreamReader::BlockInfoRecordsMap::UpdateLock::
+UpdateLock(BlockInfoRecordsMap &BlockInfoRecords)
+ : BlockInfoRecords(BlockInfoRecords), Lock(BlockInfoRecords.Lock)
+{}
+
+NaClBitstreamReader::BlockInfoRecordsMap::UpdateLock::
+~UpdateLock() {
+ if (BlockInfoRecords.freeze())
+ report_fatal_error("Global abbreviations block frozen while building.");
+}
+
bool NaClBitstreamCursor::ReadBlockInfoBlock(NaClAbbrevListener *Listener) {
- // If this is the second stream to get to the block info block, skip it.
- if (BitStream->HasReadBlockInfoBlock)
+ // If this is the second read of the block info block, skip it.
+ if (BitStream->BlockInfoRecords->isFrozen())
return SkipBlock();
- BitStream->HasReadBlockInfoBlock = true;
-
+ NaClBitstreamReader::BlockInfoRecordsMap::UpdateLock
+ Lock(*BitStream->BlockInfoRecords);
unsigned NumWords;
if (EnterSubBlock(naclbitc::BLOCKINFO_BLOCK_ID, &NumWords)) return true;
@@ -387,7 +421,7 @@ bool NaClBitstreamCursor::ReadBlockInfoBlock(NaClAbbrevListener *Listener) {
if (Record.size() < 1) return true;
FoundSetBID = true;
UpdateAbbrevs =
- &BitStream->getOrCreateBlockInfo((unsigned)Record[0]).getAbbrevs();
+ &BitStream->getBlockInfo((unsigned)Record[0]).getAbbrevs();
if (Listener) {
Listener->Values = Record;
Listener->SetBID();

Powered by Google App Engine
This is Rietveld 408576698