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

Side by Side Diff: src/PNaClTranslator.cpp

Issue 1834473002: Allow Subzero to parse function blocks in parallel. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Clean up code. 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 unified diff | Download patch
OLDNEW
1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // Error recover with value that is always acceptable. 424 // Error recover with value that is always acceptable.
425 return 1; 425 return 1;
426 } 426 }
427 427
428 private: 428 private:
429 // The translator associated with the parser. 429 // The translator associated with the parser.
430 Ice::Translator &Translator; 430 Ice::Translator &Translator;
431 // The exit status that should be set to true if an error occurs. 431 // The exit status that should be set to true if an error occurs.
432 Ice::ErrorCode &ErrorStatus; 432 Ice::ErrorCode &ErrorStatus;
433 // The number of errors reported. 433 // The number of errors reported.
434 unsigned NumErrors = 0; 434 unsigned NumErrors = 0;
Karl 2016/03/24 22:35:26 Removed this field. It is no longer used.
435 // The types associated with each type ID. 435 // The types associated with each type ID.
436 std::vector<ExtendedType> TypeIDValues; 436 std::vector<ExtendedType> TypeIDValues;
437 // The set of functions (prototype and defined). 437 // The set of functions (prototype and defined).
438 Ice::FunctionDeclarationList FunctionDeclarations; 438 Ice::FunctionDeclarationList FunctionDeclarations;
439 // The ID of the next possible defined function ID in FunctionDeclarations. 439 // The ID of the next possible defined function ID in FunctionDeclarations.
440 // FunctionDeclarations is filled first. It's the set of functions (either 440 // FunctionDeclarations is filled first. It's the set of functions (either
441 // defined or isproto). Then function definitions are encountered/parsed and 441 // defined or isproto). Then function definitions are encountered/parsed and
442 // NextDefiningFunctionID is incremented to track the next actually-defined 442 // NextDefiningFunctionID is incremented to track the next actually-defined
443 // function. 443 // function.
444 size_t NextDefiningFunctionID = 0; 444 size_t NextDefiningFunctionID = 0;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 Ice::VariableDeclaration * 572 Ice::VariableDeclaration *
573 reportGetGlobalVariableByIDError(NaClBcIndexSize_t Index); 573 reportGetGlobalVariableByIDError(NaClBcIndexSize_t Index);
574 574
575 // Reports that there is no corresponding ICE type for LLVMTy, and returns 575 // Reports that there is no corresponding ICE type for LLVMTy, and returns
576 // Ice::IceType_void. 576 // Ice::IceType_void.
577 Ice::Type convertToIceTypeError(Type *LLVMTy); 577 Ice::Type convertToIceTypeError(Type *LLVMTy);
578 }; 578 };
579 579
580 bool TopLevelParser::ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit, 580 bool TopLevelParser::ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit,
581 const std::string &Message) { 581 const std::string &Message) {
582 ErrorStatus.assign(Ice::EC_Bitcode); 582 { // Lock while printing out error message and updating state.
583 ++NumErrors; 583 Ice::GlobalContext *Context = Translator.getContext();
584 Ice::GlobalContext *Context = Translator.getContext();
585 { // Lock while printing out error message.
586 Ice::OstreamLocker L(Context); 584 Ice::OstreamLocker L(Context);
585 ErrorStatus.assign(Ice::EC_Bitcode);
John 2016/03/24 17:32:35 Are you using the OstreamLocker to prevent concurr
Karl 2016/03/24 22:35:25 Yes I was using the OstreamLocker. I did it becaus
586 ++NumErrors;
587 raw_ostream &OldErrStream = setErrStream(Context->getStrError()); 587 raw_ostream &OldErrStream = setErrStream(Context->getStrError());
588 NaClBitcodeParser::ErrorAt(Level, Bit, Message); 588 NaClBitcodeParser::ErrorAt(Level, Bit, Message);
589 setErrStream(OldErrStream); 589 setErrStream(OldErrStream);
590 } 590 }
591 if (Level >= naclbitc::Error && 591 if (Level >= naclbitc::Error &&
592 !Translator.getFlags().getAllowErrorRecovery()) 592 !Translator.getFlags().getAllowErrorRecovery())
593 Fatal(); 593 Fatal();
594 return true; 594 return true;
595 } 595 }
596 596
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 BlockParserBaseClass(const BlockParserBaseClass &) = delete; 657 BlockParserBaseClass(const BlockParserBaseClass &) = delete;
658 BlockParserBaseClass &operator=(const BlockParserBaseClass &) = delete; 658 BlockParserBaseClass &operator=(const BlockParserBaseClass &) = delete;
659 659
660 public: 660 public:
661 // Constructor for the top-level module block parser. 661 // Constructor for the top-level module block parser.
662 BlockParserBaseClass(unsigned BlockID, TopLevelParser *Context) 662 BlockParserBaseClass(unsigned BlockID, TopLevelParser *Context)
663 : NaClBitcodeParser(BlockID, Context), Context(Context) { 663 : NaClBitcodeParser(BlockID, Context), Context(Context) {
664 Context->setBlockParser(this); 664 Context->setBlockParser(this);
665 } 665 }
666 666
667 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser,
668 NaClBitstreamCursor &Cursor)
669 : NaClBitcodeParser(BlockID, EnclosingParser, Cursor),
670 Context(EnclosingParser->Context) {}
671
667 ~BlockParserBaseClass() override { Context->setBlockParser(nullptr); } 672 ~BlockParserBaseClass() override { Context->setBlockParser(nullptr); }
668 673
669 // Returns the printable name of the type of block being parsed. 674 // Returns the printable name of the type of block being parsed.
670 virtual const char *getBlockName() const { 675 virtual const char *getBlockName() const {
671 // If this class is used, it is parsing an unknown block. 676 // If this class is used, it is parsing an unknown block.
672 return "unknown"; 677 return "unknown";
673 } 678 }
674 679
675 // Generates an error Message with the Bit address prefixed to it. 680 // Generates an error Message with the Bit address prefixed to it.
676 bool ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit, 681 bool ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit,
677 const std::string &Message) final; 682 const std::string &Message) final;
678 683
679 protected: 684 protected:
680 // The context parser that contains the decoded state. 685 // The context parser that contains the decoded state.
681 TopLevelParser *Context; 686 TopLevelParser *Context;
687 // True if ErrorAt has been called in this block.
688 bool BlockHasError = false;
682 689
683 // Constructor for nested block parsers. 690 // Constructor for nested block parsers.
684 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) 691 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser)
685 : NaClBitcodeParser(BlockID, EnclosingParser), 692 : NaClBitcodeParser(BlockID, EnclosingParser),
686 Context(EnclosingParser->Context) {} 693 Context(EnclosingParser->Context) {}
687 694
688 // Gets the translator associated with the bitcode parser. 695 // Gets the translator associated with the bitcode parser.
689 Ice::Translator &getTranslator() const { return Context->getTranslator(); } 696 Ice::Translator &getTranslator() const { return Context->getTranslator(); }
690 697
691 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } 698 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 bool TopLevelParser::blockError(const std::string &Message) { 756 bool TopLevelParser::blockError(const std::string &Message) {
750 if (BlockParser) 757 if (BlockParser)
751 return BlockParser->Error(Message); 758 return BlockParser->Error(Message);
752 else 759 else
753 return Error(Message); 760 return Error(Message);
754 } 761 }
755 762
756 // Generates an error Message with the bit address prefixed to it. 763 // Generates an error Message with the bit address prefixed to it.
757 bool BlockParserBaseClass::ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit, 764 bool BlockParserBaseClass::ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit,
758 const std::string &Message) { 765 const std::string &Message) {
766 BlockHasError = true;
759 std::string Buffer; 767 std::string Buffer;
760 raw_string_ostream StrBuf(Buffer); 768 raw_string_ostream StrBuf(Buffer);
761 // Note: If dump routines have been turned off, the error messages will not 769 // Note: If dump routines have been turned off, the error messages will not
762 // be readable. Hence, replace with simple error. We also use the simple form 770 // be readable. Hence, replace with simple error. We also use the simple form
763 // for unit tests. 771 // for unit tests.
764 if (getFlags().getGenerateUnitTestMessages()) { 772 if (getFlags().getGenerateUnitTestMessages()) {
765 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode(); 773 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode();
766 for (const uint64_t Val : Record.GetValues()) { 774 for (const uint64_t Val : Record.GetValues()) {
767 StrBuf << " " << Val; 775 StrBuf << " " << Val;
768 } 776 }
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 return; 1343 return;
1336 } 1344 }
1337 1345
1338 /// Parses function blocks in the bitcode file. 1346 /// Parses function blocks in the bitcode file.
1339 class FunctionParser : public BlockParserBaseClass { 1347 class FunctionParser : public BlockParserBaseClass {
1340 FunctionParser() = delete; 1348 FunctionParser() = delete;
1341 FunctionParser(const FunctionParser &) = delete; 1349 FunctionParser(const FunctionParser &) = delete;
1342 FunctionParser &operator=(const FunctionParser &) = delete; 1350 FunctionParser &operator=(const FunctionParser &) = delete;
1343 1351
1344 public: 1352 public:
1345 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) 1353 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser,
1354 NaClBcIndexSize_t FcnId)
1346 : BlockParserBaseClass(BlockID, EnclosingParser), 1355 : BlockParserBaseClass(BlockID, EnclosingParser),
1347 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()), 1356 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()),
1348 Func(nullptr), FcnId(Context->getNextFunctionBlockValueID()), 1357 Func(nullptr), FuncDecl(Context->getFunctionByID(FcnId)),
1349 FuncDecl(Context->getFunctionByID(FcnId)),
1350 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), 1358 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()),
1351 NextLocalInstIndex(Context->getNumGlobalIDs()) {} 1359 NextLocalInstIndex(Context->getNumGlobalIDs()) {}
1352 1360
1353 bool convertFunction() { 1361 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser,
1362 NaClBcIndexSize_t FcnId, NaClBitstreamCursor &Cursor)
1363 : BlockParserBaseClass(BlockID, EnclosingParser, Cursor),
1364 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()),
1365 Func(nullptr), FuncDecl(Context->getFunctionByID(FcnId)),
1366 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()),
1367 NextLocalInstIndex(Context->getNumGlobalIDs()) {}
1368
1369 std::unique_ptr<Ice::Cfg> parseFunction(uint32_t SeqNumber) {
1354 bool ParserResult; 1370 bool ParserResult;
1371 Ice::GlobalContext *Ctx = getTranslator().getContext();
1355 { 1372 {
1356 Ice::TimerMarker T(getTranslator().getContext(), FuncDecl->getName()); 1373 Ice::TimerMarker T(Ctx, FuncDecl->getName());
1357 // Note: The Cfg is created, even when IR generation is disabled. This is 1374 // Note: The Cfg is created, even when IR generation is disabled. This is
1358 // done to install a CfgLocalAllocator for various internal containers. 1375 // done to install a CfgLocalAllocator for various internal containers.
1359 Func = Ice::Cfg::create(getTranslator().getContext(), 1376 Func = Ice::Cfg::create(Ctx, SeqNumber);
1360 getTranslator().getNextSequenceNumber());
1361 1377
1362 Ice::CfgLocalAllocatorScope _(Func.get()); 1378 Ice::CfgLocalAllocatorScope _(Func.get());
1363 1379
1364 // TODO(kschimpf) Clean up API to add a function signature to a CFG. 1380 // TODO(kschimpf) Clean up API to add a function signature to a CFG.
1365 const Ice::FuncSigType &Signature = FuncDecl->getSignature(); 1381 const Ice::FuncSigType &Signature = FuncDecl->getSignature();
1366 1382
1367 Func->setFunctionName(FuncDecl->getName()); 1383 Func->setFunctionName(FuncDecl->getName());
1368 Func->setReturnType(Signature.getReturnType()); 1384 Func->setReturnType(Signature.getReturnType());
1369 Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage); 1385 Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage);
1370 CurrentNode = installNextBasicBlock(); 1386 CurrentNode = installNextBasicBlock();
1371 Func->setEntryNode(CurrentNode); 1387 Func->setEntryNode(CurrentNode);
1372 for (Ice::Type ArgType : Signature.getArgList()) { 1388 for (Ice::Type ArgType : Signature.getArgList()) {
1373 Func->addArg(getNextInstVar(ArgType)); 1389 Func->addArg(getNextInstVar(ArgType));
1374 } 1390 }
1375 1391
1376 ParserResult = ParseThisBlock(); 1392 ParserResult = ParseThisBlock();
1377
1378 // Note: Once any errors have been found, we turn off all translation of
1379 // all remaining functions. This allows successive parsing errors to be
1380 // reported, without adding extra checks to the translator for such
1381 // parsing errors.
1382 }
1383 if (Context->getNumErrors() == 0 && Func) {
1384 getTranslator().translateFcn(std::move(Func));
1385 // The translator now has ownership of Func.
1386 } else {
1387 Func.reset();
1388 } 1393 }
1389 1394
1390 return ParserResult; 1395 if (ParserResult || BlockHasError)
1396 Func->setError("Unable to parse function");
1397
1398 return std::move(Func);
John 2016/03/24 17:32:35 no need to move it here -- Func is an xvalue here
Karl 2016/03/24 22:35:26 The compiler disagrees with you!
John 2016/03/25 04:55:22 Ah, Func is a class member... That's one of the wo
Karl 2016/03/29 17:35:02 It uses many instance fields and methods of the Fu
1391 } 1399 }
1392 1400
1393 ~FunctionParser() final = default; 1401 ~FunctionParser() final = default;
1394 1402
1395 const char *getBlockName() const override { return "function"; } 1403 const char *getBlockName() const override { return "function"; }
1396 1404
1397 Ice::Cfg *getFunc() const { return Func.get(); } 1405 Ice::Cfg *getFunc() const { return Func.get(); }
1398 1406
1399 size_t getNumGlobalIDs() const { return CachedNumGlobalValueIDs; } 1407 size_t getNumGlobalIDs() const { return CachedNumGlobalValueIDs; }
1400 1408
(...skipping 26 matching lines...) Expand all
1427 // the number of bytes defining the function block. 1435 // the number of bytes defining the function block.
1428 uint64_t MaxRecordsInBlock = 0; 1436 uint64_t MaxRecordsInBlock = 0;
1429 // The corresponding ICE function defined by the function block. 1437 // The corresponding ICE function defined by the function block.
1430 std::unique_ptr<Ice::Cfg> Func; 1438 std::unique_ptr<Ice::Cfg> Func;
1431 // The index to the current basic block being built. 1439 // The index to the current basic block being built.
1432 NaClBcIndexSize_t CurrentBbIndex = 0; 1440 NaClBcIndexSize_t CurrentBbIndex = 0;
1433 // The number of basic blocks declared for the function block. 1441 // The number of basic blocks declared for the function block.
1434 NaClBcIndexSize_t DeclaredNumberBbs = 0; 1442 NaClBcIndexSize_t DeclaredNumberBbs = 0;
1435 // The basic block being built. 1443 // The basic block being built.
1436 Ice::CfgNode *CurrentNode = nullptr; 1444 Ice::CfgNode *CurrentNode = nullptr;
1437 // The ID for the function.
1438 NaClBcIndexSize_t FcnId;
1439 // The corresponding function declaration. 1445 // The corresponding function declaration.
1440 Ice::FunctionDeclaration *FuncDecl; 1446 Ice::FunctionDeclaration *FuncDecl;
1441 // Holds the dividing point between local and global absolute value indices. 1447 // Holds the dividing point between local and global absolute value indices.
1442 size_t CachedNumGlobalValueIDs; 1448 size_t CachedNumGlobalValueIDs;
1443 // Holds operands local to the function block, based on indices defined in 1449 // Holds operands local to the function block, based on indices defined in
1444 // the bitcode file. 1450 // the bitcode file.
1445 Ice::OperandList LocalOperands; 1451 Ice::OperandList LocalOperands;
1446 // Holds the index within LocalOperands corresponding to the next instruction 1452 // Holds the index within LocalOperands corresponding to the next instruction
1447 // that generates a value. 1453 // that generates a value.
1448 NaClBcIndexSize_t NextLocalInstIndex; 1454 NaClBcIndexSize_t NextLocalInstIndex;
(...skipping 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 class ModuleParser : public BlockParserBaseClass { 2983 class ModuleParser : public BlockParserBaseClass {
2978 ModuleParser() = delete; 2984 ModuleParser() = delete;
2979 ModuleParser(const ModuleParser &) = delete; 2985 ModuleParser(const ModuleParser &) = delete;
2980 ModuleParser &operator=(const ModuleParser &) = delete; 2986 ModuleParser &operator=(const ModuleParser &) = delete;
2981 2987
2982 public: 2988 public:
2983 ModuleParser(unsigned BlockID, TopLevelParser *Context) 2989 ModuleParser(unsigned BlockID, TopLevelParser *Context)
2984 : BlockParserBaseClass(BlockID, Context), 2990 : BlockParserBaseClass(BlockID, Context),
2985 Timer(Ice::TimerStack::TT_parseModule, 2991 Timer(Ice::TimerStack::TT_parseModule,
2986 Context->getTranslator().getContext()) {} 2992 Context->getTranslator().getContext()) {}
2987 2993 ~ModuleParser() final = default;
John 2016/03/24 17:32:35 marking the destructor "final" is a pretty strong
Karl 2016/03/24 22:35:25 Moved final keywords (where appropriate) to the cl
2988 ~ModuleParser() override = default;
2989
2990 const char *getBlockName() const override { return "module"; } 2994 const char *getBlockName() const override { return "module"; }
2995 NaClBitstreamReader &getReader() { return Record.GetReader(); }
2991 2996
2992 private: 2997 private:
2993 Ice::TimerMarker Timer; 2998 Ice::TimerMarker Timer;
2994 // True if we have already installed names for unnamed global declarations, 2999 // True if we have already installed names for unnamed global declarations,
2995 // and have generated global constant initializers. 3000 // and have generated global constant initializers.
2996 bool GlobalDeclarationNamesAndInitializersInstalled = false; 3001 bool GlobalDeclarationNamesAndInitializersInstalled = false;
2997 // True if we have already processed the symbol table for the module. 3002 // True if we have already processed the symbol table for the module.
2998 bool FoundValuesymtab = false; 3003 bool FoundValuesymtab = false;
2999 3004
3000 // Generates names for unnamed global addresses (i.e. functions and global 3005 // Generates names for unnamed global addresses (i.e. functions and global
3001 // variables). Then lowers global variable declaration initializers to the 3006 // variables). Then lowers global variable declaration initializers to the
3002 // target. May be called multiple times. Only the first call will do the 3007 // target. May be called multiple times. Only the first call will do the
3003 // installation. 3008 // installation.
3004 void installGlobalNamesAndGlobalVarInitializers() { 3009 void installGlobalNamesAndGlobalVarInitializers() {
3005 if (!GlobalDeclarationNamesAndInitializersInstalled) { 3010 if (!GlobalDeclarationNamesAndInitializersInstalled) {
3006 Context->installGlobalNames(); 3011 Context->installGlobalNames();
3007 Context->createValueIDs(); 3012 Context->createValueIDs();
3008 Context->verifyFunctionTypeSignatures(); 3013 Context->verifyFunctionTypeSignatures();
3009 std::unique_ptr<Ice::VariableDeclarationList> Globals = 3014 std::unique_ptr<Ice::VariableDeclarationList> Globals =
3010 Context->getGlobalVariables(); 3015 Context->getGlobalVariables();
3011 if (Globals) 3016 if (Globals)
3012 getTranslator().lowerGlobals(std::move(Globals)); 3017 getTranslator().lowerGlobals(std::move(Globals));
3013 GlobalDeclarationNamesAndInitializersInstalled = true; 3018 GlobalDeclarationNamesAndInitializersInstalled = true;
3014 } 3019 }
3015 } 3020 }
3016 bool ParseBlock(unsigned BlockID) override; 3021 bool ParseBlock(unsigned BlockID) override;
3017 3022
3018 void ExitBlock() override { installGlobalNamesAndGlobalVarInitializers(); } 3023 void ExitBlock() override {
3024 installGlobalNamesAndGlobalVarInitializers();
3025 Context->getTranslator().getContext()->waitForWorkerThreads();
3026 }
3019 3027
3020 void ProcessRecord() override; 3028 void ProcessRecord() override;
3021 }; 3029 };
3022 3030
3023 class ModuleValuesymtabParser : public ValuesymtabParser { 3031 class ModuleValuesymtabParser : public ValuesymtabParser {
3024 ModuleValuesymtabParser() = delete; 3032 ModuleValuesymtabParser() = delete;
3025 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; 3033 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete;
3026 void operator=(const ModuleValuesymtabParser &) = delete; 3034 void operator=(const ModuleValuesymtabParser &) = delete;
3027 3035
3028 public: 3036 public:
(...skipping 24 matching lines...) Expand all
3053 } 3061 }
3054 3062
3055 Decl->setName(StringRef(Name.data(), Name.size())); 3063 Decl->setName(StringRef(Name.data(), Name.size()));
3056 } 3064 }
3057 3065
3058 void ModuleValuesymtabParser::setBbName(NaClBcIndexSize_t Index, 3066 void ModuleValuesymtabParser::setBbName(NaClBcIndexSize_t Index,
3059 StringType &Name) { 3067 StringType &Name) {
3060 reportUnableToAssign("Basic block", Index, Name); 3068 reportUnableToAssign("Basic block", Index, Name);
3061 } 3069 }
3062 3070
3071 class CfgParserWorkItem : public Ice::OptWorkItem {
3072 CfgParserWorkItem() = delete;
3073 CfgParserWorkItem(const CfgParserWorkItem &) = delete;
3074 CfgParserWorkItem &operator=(const CfgParserWorkItem &) = delete;
3075
3076 public:
3077 CfgParserWorkItem(unsigned BlockID, NaClBcIndexSize_t FcnId,
3078 ModuleParser *ModParser, uint64_t StartBit,
3079 uint32_t SeqNumber)
3080 : BlockID(BlockID), FcnId(FcnId), ModParser(ModParser),
3081 StartBit(StartBit), SeqNumber(SeqNumber) {}
3082 std::unique_ptr<Ice::Cfg> getParsedCfg() final {
3083 NaClBitstreamCursor Cursor(ModParser->getReader());
3084 Cursor.JumpToBit(StartBit);
3085 FunctionParser Parser(BlockID, ModParser, FcnId, Cursor);
3086 return Parser.parseFunction(SeqNumber);
3087 }
3088 ~CfgParserWorkItem() final {}
John 2016/03/24 17:32:35 make the class final instead?
Karl 2016/03/24 22:35:25 Done.
3089
3090 private:
3091 unsigned BlockID;
John 2016/03/24 17:32:35 can these be const?
Karl 2016/03/24 22:35:26 Done, except that ModParser can't be constant (Con
3092 NaClBcIndexSize_t FcnId;
3093 ModuleParser *ModParser;
3094 uint64_t StartBit;
3095 uint32_t SeqNumber;
3096 };
3097
3063 bool ModuleParser::ParseBlock(unsigned BlockID) { 3098 bool ModuleParser::ParseBlock(unsigned BlockID) {
3064 switch (BlockID) { 3099 switch (BlockID) {
3065 case naclbitc::BLOCKINFO_BLOCK_ID: 3100 case naclbitc::BLOCKINFO_BLOCK_ID:
3066 return NaClBitcodeParser::ParseBlock(BlockID); 3101 return NaClBitcodeParser::ParseBlock(BlockID);
3067 case naclbitc::TYPE_BLOCK_ID_NEW: { 3102 case naclbitc::TYPE_BLOCK_ID_NEW: {
3068 TypesParser Parser(BlockID, this); 3103 TypesParser Parser(BlockID, this);
3069 return Parser.ParseThisBlock(); 3104 return Parser.ParseThisBlock();
3070 } 3105 }
3071 case naclbitc::GLOBALVAR_BLOCK_ID: { 3106 case naclbitc::GLOBALVAR_BLOCK_ID: {
3072 GlobalsParser Parser(BlockID, this); 3107 GlobalsParser Parser(BlockID, this);
3073 return Parser.ParseThisBlock(); 3108 return Parser.ParseThisBlock();
3074 } 3109 }
3075 case naclbitc::VALUE_SYMTAB_BLOCK_ID: { 3110 case naclbitc::VALUE_SYMTAB_BLOCK_ID: {
3076 if (FoundValuesymtab) 3111 if (FoundValuesymtab)
3077 Fatal("Duplicate valuesymtab in module"); 3112 Fatal("Duplicate valuesymtab in module");
3078 3113
3079 // If we have already processed a function block (i.e. we have already 3114 // If we have already processed a function block (i.e. we have already
3080 // installed global names and variable initializers) we can no longer accept 3115 // installed global names and variable initializers) we can no longer accept
3081 // the value symbol table. Names have already been generated. 3116 // the value symbol table. Names have already been generated.
3082 if (GlobalDeclarationNamesAndInitializersInstalled) 3117 if (GlobalDeclarationNamesAndInitializersInstalled)
3083 Fatal("Module valuesymtab not allowed after function blocks"); 3118 Fatal("Module valuesymtab not allowed after function blocks");
3084 3119
3085 FoundValuesymtab = true; 3120 FoundValuesymtab = true;
3086 ModuleValuesymtabParser Parser(BlockID, this); 3121 ModuleValuesymtabParser Parser(BlockID, this);
3087 return Parser.ParseThisBlock(); 3122 return Parser.ParseThisBlock();
3088 } 3123 }
3089 case naclbitc::FUNCTION_BLOCK_ID: { 3124 case naclbitc::FUNCTION_BLOCK_ID: {
3090 installGlobalNamesAndGlobalVarInitializers(); 3125 installGlobalNamesAndGlobalVarInitializers();
3091 FunctionParser Parser(BlockID, this); 3126 Ice::GlobalContext *Ctx = Context->getTranslator().getContext();
3092 return Parser.convertFunction(); 3127 uint32_t SeqNumber = Context->getTranslator().getNextSequenceNumber();
3128 NaClBcIndexSize_t FcnId = Context->getNextFunctionBlockValueID();
3129 if (Ctx->getFlags().getParseParallel()) {
3130 uint64_t StartBit = Record.GetCursor().GetCurrentBitNo();
3131 if (SkipBlock())
3132 return true;
3133 Ice::GlobalContext *Ctx = Context->getTranslator().getContext();
3134 Ctx->optQueueBlockingPush(Ice::makeUnique<CfgParserWorkItem>(
3135 BlockID, FcnId, this, StartBit, SeqNumber));
3136 return false;
3137 } else {
3138 FunctionParser Parser(BlockID, this, FcnId);
3139 std::unique_ptr<Ice::Cfg> Func = Parser.parseFunction(SeqNumber);
3140 bool Failed = Func->hasError();
3141 getTranslator().translateFcn(std::move(Func));
3142 return Failed && !getTranslator().getFlags().getAllowErrorRecovery();
3143 }
3093 } 3144 }
3094 default: 3145 default:
3095 return BlockParserBaseClass::ParseBlock(BlockID); 3146 return BlockParserBaseClass::ParseBlock(BlockID);
3096 } 3147 }
3097 } 3148 }
3098 3149
3099 void ModuleParser::ProcessRecord() { 3150 void ModuleParser::ProcessRecord() {
3100 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); 3151 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues();
3101 switch (Record.GetCode()) { 3152 switch (Record.GetCode()) {
3102 case naclbitc::MODULE_CODE_VERSION: { 3153 case naclbitc::MODULE_CODE_VERSION: {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
3210 raw_string_ostream StrBuf(Buffer); 3261 raw_string_ostream StrBuf(Buffer);
3211 StrBuf << IRFilename << ": Does not contain a module!"; 3262 StrBuf << IRFilename << ": Does not contain a module!";
3212 llvm::report_fatal_error(StrBuf.str()); 3263 llvm::report_fatal_error(StrBuf.str());
3213 } 3264 }
3214 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { 3265 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) {
3215 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); 3266 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes");
3216 } 3267 }
3217 } 3268 }
3218 3269
3219 } // end of namespace Ice 3270 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698