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

Side by Side 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: Fixed nits. Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 //===- NaClBitstreamReader.cpp --------------------------------------------===// 1 //===- NaClBitstreamReader.cpp --------------------------------------------===//
2 // NaClBitstreamReader implementation 2 // NaClBitstreamReader implementation
3 // 3 //
4 // The LLVM Compiler Infrastructure 4 // The LLVM Compiler Infrastructure
5 // 5 //
6 // This file is distributed under the University of Illinois Open Source 6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details. 7 // License. See LICENSE.TXT for details.
8 // 8 //
9 //===----------------------------------------------------------------------===// 9 //===----------------------------------------------------------------------===//
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 //===----------------------------------------------------------------------===// 42 //===----------------------------------------------------------------------===//
43 // NaClBitstreamCursor implementation 43 // NaClBitstreamCursor implementation
44 //===----------------------------------------------------------------------===// 44 //===----------------------------------------------------------------------===//
45 45
46 void NaClBitstreamCursor::ErrorHandler:: 46 void NaClBitstreamCursor::ErrorHandler::
47 Fatal(const std::string &ErrorMessage) const { 47 Fatal(const std::string &ErrorMessage) const {
48 // Default implementation is simply print message, and the bit where 48 // Default implementation is simply print message, and the bit where
49 // the error occurred. 49 // the error occurred.
50 std::string Buffer; 50 std::string Buffer;
51 raw_string_ostream StrBuf(Buffer); 51 raw_string_ostream StrBuf(Buffer);
52 naclbitc::ErrorAt(StrBuf, naclbitc::Fatal, Cursor.GetCurrentBitNo()) 52 naclbitc::ErrorAt(StrBuf, naclbitc::Fatal, getCurrentBitNo()) << ErrorMessage;
53 << ErrorMessage;
54 report_fatal_error(StrBuf.str()); 53 report_fatal_error(StrBuf.str());
55 } 54 }
56 55
57 void NaClBitstreamCursor::reportInvalidAbbrevNumber(unsigned AbbrevNo) const { 56 void NaClBitstreamCursor::reportInvalidAbbrevNumber(unsigned AbbrevNo) const {
58 std::string Buffer; 57 std::string Buffer;
59 raw_string_ostream StrBuf(Buffer); 58 raw_string_ostream StrBuf(Buffer);
60 StrBuf << "Invalid abbreviation # " << AbbrevNo << " defined for record"; 59 StrBuf << "Invalid abbreviation # " << AbbrevNo << " defined for record";
61 ErrHandler->Fatal(StrBuf.str()); 60 ErrHandler->Fatal(StrBuf.str());
62 } 61 }
63 62
64 void NaClBitstreamCursor::reportInvalidJumpToBit(uint64_t BitNo) const { 63 void NaClBitstreamCursor::reportInvalidJumpToBit(uint64_t BitNo) const {
65 std::string Buffer; 64 std::string Buffer;
66 raw_string_ostream StrBuf(Buffer); 65 raw_string_ostream StrBuf(Buffer);
67 StrBuf << "Invalid jump to bit " << BitNo; 66 StrBuf << "Invalid jump to bit " << BitNo;
68 ErrHandler->Fatal(StrBuf.str()); 67 ErrHandler->Fatal(StrBuf.str());
69 } 68 }
70 69
71 /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter 70 /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter
72 /// the block, and return true if the block has an error. 71 /// the block, and return true if the block has an error.
73 bool NaClBitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) { 72 bool NaClBitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) {
74 const bool IsFixed = true; 73 const bool IsFixed = true;
75 NaClBitcodeSelectorAbbrev 74 NaClBitcodeSelectorAbbrev
76 CodeAbbrev(IsFixed, ReadVBR(naclbitc::CodeLenWidth)); 75 CodeAbbrev(IsFixed, ReadVBR(naclbitc::CodeLenWidth));
77 BlockScope.push_back(Block(&BitStream->getOrCreateBlockInfo(BlockID), 76 BlockScope.push_back(Block(&BitStream->getBlockInfo(BlockID), CodeAbbrev));
78 CodeAbbrev));
79 SkipToFourByteBoundary(); 77 SkipToFourByteBoundary();
80 unsigned NumWords = Read(naclbitc::BlockSizeWidth); 78 unsigned NumWords = Read(naclbitc::BlockSizeWidth);
81 if (NumWordsP) *NumWordsP = NumWords; 79 if (NumWordsP) *NumWordsP = NumWords;
82 80
83 // Validate that this block is sane. 81 // Validate that this block is sane.
84 if (BlockScope.back().getCodeAbbrev().NumBits == 0 || AtEndOfStream()) 82 if (BlockScope.back().getCodeAbbrev().NumBits == 0 || AtEndOfStream())
85 return true; 83 return true;
86 84
87 return false; 85 return false;
88 } 86 }
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 continue; 321 continue;
324 } 322 }
325 NaClBitCodeAbbrevOp::Encoding E = getEncoding(Read(3)); 323 NaClBitCodeAbbrevOp::Encoding E = getEncoding(Read(3));
326 if (NaClBitCodeAbbrevOp::hasValue(E)) { 324 if (NaClBitCodeAbbrevOp::hasValue(E)) {
327 ReadVBR64(5); 325 ReadVBR64(5);
328 } 326 }
329 } 327 }
330 SkipToByteBoundaryIfAligned(); 328 SkipToByteBoundaryIfAligned();
331 } 329 }
332 330
331 namespace {
332
333 unsigned ValidBlockIDs[] = {
334 naclbitc::BLOCKINFO_BLOCK_ID,
335 naclbitc::CONSTANTS_BLOCK_ID,
336 naclbitc::FUNCTION_BLOCK_ID,
337 naclbitc::GLOBALVAR_BLOCK_ID,
338 naclbitc::MODULE_BLOCK_ID,
339 naclbitc::TOP_LEVEL_BLOCKID,
340 naclbitc::TYPE_BLOCK_ID_NEW,
341 naclbitc::VALUE_SYMTAB_BLOCK_ID
342 };
343
344 const size_t InfosBucketSize = 23;
Jim Stichnoth 2016/03/29 19:47:18 Can you explain this magic constant?
Karl 2016/03/29 20:10:47 Not worth it. Removing the magic.
345
346 } // end of anonymous namespace
347
348 NaClBitstreamReader::BlockInfoRecordsMap::
349 BlockInfoRecordsMap() : Infos(InfosBucketSize), IsFrozen(false) {
350 for (size_t BlockID : ValidBlockIDs)
351 Infos.emplace(BlockID, BlockInfo(BlockID));
352 }
353
354 NaClBitstreamReader::BlockInfoRecordsMap::UpdateLock::
355 UpdateLock(BlockInfoRecordsMap &BlockInfoRecords)
356 : BlockInfoRecords(BlockInfoRecords), Lock(BlockInfoRecords.Lock)
357 {}
358
359 NaClBitstreamReader::BlockInfoRecordsMap::UpdateLock::
360 ~UpdateLock() {
361 if (BlockInfoRecords.freeze())
362 report_fatal_error("Global abbreviations block frozen while building.");
363 }
364
333 bool NaClBitstreamCursor::ReadBlockInfoBlock(NaClAbbrevListener *Listener) { 365 bool NaClBitstreamCursor::ReadBlockInfoBlock(NaClAbbrevListener *Listener) {
334 // If this is the second stream to get to the block info block, skip it. 366 // If this is the second read of the block info block, skip it.
335 if (BitStream->HasReadBlockInfoBlock) 367 if (BitStream->BlockInfoRecords->isFrozen())
336 return SkipBlock(); 368 return SkipBlock();
337 369
338 BitStream->HasReadBlockInfoBlock = true; 370 NaClBitstreamReader::BlockInfoRecordsMap::UpdateLock
339 371 Lock(*BitStream->BlockInfoRecords);
340 unsigned NumWords; 372 unsigned NumWords;
341 if (EnterSubBlock(naclbitc::BLOCKINFO_BLOCK_ID, &NumWords)) return true; 373 if (EnterSubBlock(naclbitc::BLOCKINFO_BLOCK_ID, &NumWords)) return true;
342 374
343 if (Listener) Listener->BeginBlockInfoBlock(NumWords); 375 if (Listener) Listener->BeginBlockInfoBlock(NumWords);
344 376
345 NaClBitcodeRecordVector Record; 377 NaClBitcodeRecordVector Record;
346 Block &CurBlock = BlockScope.back(); 378 Block &CurBlock = BlockScope.back();
347 NaClBitstreamReader::AbbrevList *UpdateAbbrevs = 379 NaClBitstreamReader::AbbrevList *UpdateAbbrevs =
348 &CurBlock.GlobalAbbrevs->getAbbrevs(); 380 &CurBlock.GlobalAbbrevs->getAbbrevs();
349 bool FoundSetBID = false; 381 bool FoundSetBID = false;
(...skipping 30 matching lines...) Expand all
380 // Read a record. 412 // Read a record.
381 Record.clear(); 413 Record.clear();
382 switch (readRecord(Entry.ID, Record)) { 414 switch (readRecord(Entry.ID, Record)) {
383 default: 415 default:
384 // No other records should be found! 416 // No other records should be found!
385 return true; 417 return true;
386 case naclbitc::BLOCKINFO_CODE_SETBID: 418 case naclbitc::BLOCKINFO_CODE_SETBID:
387 if (Record.size() < 1) return true; 419 if (Record.size() < 1) return true;
388 FoundSetBID = true; 420 FoundSetBID = true;
389 UpdateAbbrevs = 421 UpdateAbbrevs =
390 &BitStream->getOrCreateBlockInfo((unsigned)Record[0]).getAbbrevs(); 422 &BitStream->getBlockInfo((unsigned)Record[0]).getAbbrevs();
391 if (Listener) { 423 if (Listener) {
392 Listener->Values = Record; 424 Listener->Values = Record;
393 Listener->SetBID(); 425 Listener->SetBID();
394 } 426 }
395 break; 427 break;
396 } 428 }
397 } 429 }
398 } 430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698