OLD | NEW |
---|---|
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 // This file implements the PNaCl bitcode file to Ice, to machine code | 10 // This file implements the PNaCl bitcode file to Ice, to machine code |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 unsigned getNumErrors() const { return NumErrors; } | 184 unsigned getNumErrors() const { return NumErrors; } |
185 | 185 |
186 /// Returns the number of bytes in the bitcode header. | 186 /// Returns the number of bytes in the bitcode header. |
187 size_t getHeaderSize() const { return Header.getHeaderSize(); } | 187 size_t getHeaderSize() const { return Header.getHeaderSize(); } |
188 | 188 |
189 /// Changes the size of the type list to the given size. | 189 /// Changes the size of the type list to the given size. |
190 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } | 190 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } |
191 | 191 |
192 /// Returns true if generation of Subzero IR is disabled. | 192 /// Returns true if generation of Subzero IR is disabled. |
193 bool isIRGenerationDisabled() const { | 193 bool isIRGenerationDisabled() const { |
194 return ALLOW_DISABLE_IR_GEN ? Translator.getFlags().DisableIRGeneration | 194 return ALLOW_DISABLE_IR_GEN ? Translator.getFlags().getDisableIRGeneration() |
Jim Stichnoth
2015/02/05 22:30:09
Change to
return ALLOW_DISABLE_IR_GEN && getTran
Karl
2015/02/05 23:57:38
Done. Also did similar changes to: getDumpStats, g
| |
195 : false; | 195 : false; |
196 } | 196 } |
197 | 197 |
198 /// Returns the undefined type associated with type ID. | 198 /// Returns the undefined type associated with type ID. |
199 /// Note: Returns extended type ready to be defined. | 199 /// Note: Returns extended type ready to be defined. |
200 ExtendedType *getTypeByIDForDefining(unsigned ID) { | 200 ExtendedType *getTypeByIDForDefining(unsigned ID) { |
201 // Get corresponding element, verifying the value is still undefined | 201 // Get corresponding element, verifying the value is still undefined |
202 // (and hence allowed to be defined). | 202 // (and hence allowed to be defined). |
203 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined); | 203 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined); |
204 if (Ty) | 204 if (Ty) |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 }; | 451 }; |
452 | 452 |
453 bool TopLevelParser::Error(const std::string &Message) { | 453 bool TopLevelParser::Error(const std::string &Message) { |
454 ErrorStatus.assign(Ice::EC_Bitcode); | 454 ErrorStatus.assign(Ice::EC_Bitcode); |
455 ++NumErrors; | 455 ++NumErrors; |
456 Ice::GlobalContext *Context = Translator.getContext(); | 456 Ice::GlobalContext *Context = Translator.getContext(); |
457 Ice::OstreamLocker L(Context); | 457 Ice::OstreamLocker L(Context); |
458 raw_ostream &OldErrStream = setErrStream(Context->getStrDump()); | 458 raw_ostream &OldErrStream = setErrStream(Context->getStrDump()); |
459 NaClBitcodeParser::Error(Message); | 459 NaClBitcodeParser::Error(Message); |
460 setErrStream(OldErrStream); | 460 setErrStream(OldErrStream); |
461 if (!Translator.getFlags().AllowErrorRecovery) | 461 if (!Translator.getFlags().getAllowErrorRecovery()) |
462 report_fatal_error("Unable to continue"); | 462 report_fatal_error("Unable to continue"); |
463 return true; | 463 return true; |
464 } | 464 } |
465 | 465 |
466 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, | 466 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, |
467 ExtendedType::TypeKind WantedType) { | 467 ExtendedType::TypeKind WantedType) { |
468 std::string Buffer; | 468 std::string Buffer; |
469 raw_string_ostream StrBuf(Buffer); | 469 raw_string_ostream StrBuf(Buffer); |
470 if (Ty == nullptr) { | 470 if (Ty == nullptr) { |
471 StrBuf << "Can't find extended type for type id: " << ID; | 471 StrBuf << "Can't find extended type for type id: " << ID; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 545 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
546 : NaClBitcodeParser(BlockID, EnclosingParser), | 546 : NaClBitcodeParser(BlockID, EnclosingParser), |
547 Context(EnclosingParser->Context) {} | 547 Context(EnclosingParser->Context) {} |
548 | 548 |
549 // Gets the translator associated with the bitcode parser. | 549 // Gets the translator associated with the bitcode parser. |
550 Ice::Translator &getTranslator() const { return Context->getTranslator(); } | 550 Ice::Translator &getTranslator() const { return Context->getTranslator(); } |
551 | 551 |
552 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } | 552 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } |
553 | 553 |
554 bool isIRGenerationDisabled() const { | 554 bool isIRGenerationDisabled() const { |
555 return ALLOW_DISABLE_IR_GEN ? getTranslator().getFlags().DisableIRGeneration | 555 return ALLOW_DISABLE_IR_GEN |
556 : false; | 556 ? getTranslator().getFlags().getDisableIRGeneration() |
557 : false; | |
557 } | 558 } |
558 | 559 |
559 // Default implementation. Reports that block is unknown and skips | 560 // Default implementation. Reports that block is unknown and skips |
560 // its contents. | 561 // its contents. |
561 bool ParseBlock(unsigned BlockID) override; | 562 bool ParseBlock(unsigned BlockID) override; |
562 | 563 |
563 // Default implementation. Reports that the record is not | 564 // Default implementation. Reports that the record is not |
564 // understood. | 565 // understood. |
565 void ProcessRecord() override; | 566 void ProcessRecord() override; |
566 | 567 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 // Generates an error Message with the bit address prefixed to it. | 626 // Generates an error Message with the bit address prefixed to it. |
626 bool BlockParserBaseClass::Error(const std::string &Message) { | 627 bool BlockParserBaseClass::Error(const std::string &Message) { |
627 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; | 628 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; |
628 std::string Buffer; | 629 std::string Buffer; |
629 raw_string_ostream StrBuf(Buffer); | 630 raw_string_ostream StrBuf(Buffer); |
630 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), | 631 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), |
631 static_cast<unsigned>(Bit % 8)) << ") "; | 632 static_cast<unsigned>(Bit % 8)) << ") "; |
632 // Note: If dump routines have been turned off, the error messages | 633 // Note: If dump routines have been turned off, the error messages |
633 // will not be readable. Hence, replace with simple error. We also | 634 // will not be readable. Hence, replace with simple error. We also |
634 // use the simple form for unit tests. | 635 // use the simple form for unit tests. |
635 if (ALLOW_DUMP && !getFlags().GenerateUnitTestMessages) { | 636 if (ALLOW_DUMP && !getFlags().getGenerateUnitTestMessages()) { |
636 StrBuf << Message; | 637 StrBuf << Message; |
637 } else { | 638 } else { |
638 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode(); | 639 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode(); |
639 for (const uint64_t Val : Record.GetValues()) { | 640 for (const uint64_t Val : Record.GetValues()) { |
640 StrBuf << " " << Val; | 641 StrBuf << " " << Val; |
641 } | 642 } |
642 StrBuf << ">"; | 643 StrBuf << ">"; |
643 } | 644 } |
644 return Context->Error(StrBuf.str()); | 645 return Context->Error(StrBuf.str()); |
645 } | 646 } |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1084 Func(nullptr), CurrentBbIndex(0), | 1085 Func(nullptr), CurrentBbIndex(0), |
1085 FcnId(Context->getNextFunctionBlockValueID()), | 1086 FcnId(Context->getNextFunctionBlockValueID()), |
1086 FuncDecl(Context->getFunctionByID(FcnId)), | 1087 FuncDecl(Context->getFunctionByID(FcnId)), |
1087 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), | 1088 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), |
1088 NextLocalInstIndex(Context->getNumGlobalIDs()), | 1089 NextLocalInstIndex(Context->getNumGlobalIDs()), |
1089 InstIsTerminating(false) {} | 1090 InstIsTerminating(false) {} |
1090 | 1091 |
1091 bool convertFunction() { | 1092 bool convertFunction() { |
1092 const Ice::TimerStackIdT StackID = Ice::GlobalContext::TSK_Funcs; | 1093 const Ice::TimerStackIdT StackID = Ice::GlobalContext::TSK_Funcs; |
1093 Ice::TimerIdT TimerID = 0; | 1094 Ice::TimerIdT TimerID = 0; |
1094 const bool TimeThisFunction = ALLOW_DUMP && getFlags().TimeEachFunction; | 1095 const bool TimeThisFunction = |
1096 ALLOW_DUMP && getFlags().getTimeEachFunction(); | |
1095 if (TimeThisFunction) { | 1097 if (TimeThisFunction) { |
1096 TimerID = getTranslator().getContext()->getTimerID(StackID, | 1098 TimerID = getTranslator().getContext()->getTimerID(StackID, |
1097 FuncDecl->getName()); | 1099 FuncDecl->getName()); |
1098 getTranslator().getContext()->pushTimer(TimerID, StackID); | 1100 getTranslator().getContext()->pushTimer(TimerID, StackID); |
1099 } | 1101 } |
1100 | 1102 |
1101 if (!isIRGenerationDisabled()) | 1103 if (!isIRGenerationDisabled()) |
1102 Func = Ice::Cfg::create(getTranslator().getContext()); | 1104 Func = Ice::Cfg::create(getTranslator().getContext()); |
1103 Ice::Cfg::setCurrentCfg(Func.get()); | 1105 Ice::Cfg::setCurrentCfg(Func.get()); |
1104 | 1106 |
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2454 if (!IntrinsicInfo) { | 2456 if (!IntrinsicInfo) { |
2455 std::string Buffer; | 2457 std::string Buffer; |
2456 raw_string_ostream StrBuf(Buffer); | 2458 raw_string_ostream StrBuf(Buffer); |
2457 StrBuf << "Invalid PNaCl intrinsic call to " << Name; | 2459 StrBuf << "Invalid PNaCl intrinsic call to " << Name; |
2458 Error(StrBuf.str()); | 2460 Error(StrBuf.str()); |
2459 appendErrorInstruction(ReturnType); | 2461 appendErrorInstruction(ReturnType); |
2460 return; | 2462 return; |
2461 } | 2463 } |
2462 } | 2464 } |
2463 } else { | 2465 } else { |
2464 if (getFlags().StubConstantCalls && | 2466 if (getFlags().getStubConstantCalls() && |
2465 llvm::isa<Ice::ConstantInteger32>(Callee)) { | 2467 llvm::isa<Ice::ConstantInteger32>(Callee)) { |
2466 Callee = Context->getStubbedConstCallValue(Callee); | 2468 Callee = Context->getStubbedConstCallValue(Callee); |
2467 } | 2469 } |
2468 ReturnType = Context->getSimpleTypeByID(Values[2]); | 2470 ReturnType = Context->getSimpleTypeByID(Values[2]); |
2469 } | 2471 } |
2470 | 2472 |
2471 // Extract call information. | 2473 // Extract call information. |
2472 uint64_t CCInfo = Values[0]; | 2474 uint64_t CCInfo = Values[0]; |
2473 CallingConv::ID CallingConv; | 2475 CallingConv::ID CallingConv; |
2474 if (!naclbitc::DecodeCallingConv(CCInfo >> 1, CallingConv)) { | 2476 if (!naclbitc::DecodeCallingConv(CCInfo >> 1, CallingConv)) { |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2804 // and have generated global constant initializers. | 2806 // and have generated global constant initializers. |
2805 bool GlobalDeclarationNamesAndInitializersInstalled; | 2807 bool GlobalDeclarationNamesAndInitializersInstalled; |
2806 | 2808 |
2807 // Generates names for unnamed global addresses (i.e. functions and | 2809 // Generates names for unnamed global addresses (i.e. functions and |
2808 // global variables). Then lowers global variable declaration | 2810 // global variables). Then lowers global variable declaration |
2809 // initializers to the target. May be called multiple times. Only | 2811 // initializers to the target. May be called multiple times. Only |
2810 // the first call will do the installation. | 2812 // the first call will do the installation. |
2811 void InstallGlobalNamesAndGlobalVarInitializers() { | 2813 void InstallGlobalNamesAndGlobalVarInitializers() { |
2812 if (!GlobalDeclarationNamesAndInitializersInstalled) { | 2814 if (!GlobalDeclarationNamesAndInitializersInstalled) { |
2813 Ice::Translator &Trans = getTranslator(); | 2815 Ice::Translator &Trans = getTranslator(); |
2814 const Ice::IceString &GlobalPrefix = getFlags().DefaultGlobalPrefix; | 2816 const Ice::IceString &GlobalPrefix = getFlags().getDefaultGlobalPrefix(); |
2815 if (!GlobalPrefix.empty()) { | 2817 if (!GlobalPrefix.empty()) { |
2816 uint32_t NameIndex = 0; | 2818 uint32_t NameIndex = 0; |
2817 for (Ice::VariableDeclaration *Var : Context->getGlobalVariables()) { | 2819 for (Ice::VariableDeclaration *Var : Context->getGlobalVariables()) { |
2818 installDeclarationName(Trans, Var, GlobalPrefix, "global", NameIndex); | 2820 installDeclarationName(Trans, Var, GlobalPrefix, "global", NameIndex); |
2819 } | 2821 } |
2820 } | 2822 } |
2821 const Ice::IceString &FunctionPrefix = getFlags().DefaultFunctionPrefix; | 2823 const Ice::IceString &FunctionPrefix = |
2824 getFlags().getDefaultFunctionPrefix(); | |
2822 if (!FunctionPrefix.empty()) { | 2825 if (!FunctionPrefix.empty()) { |
2823 uint32_t NameIndex = 0; | 2826 uint32_t NameIndex = 0; |
2824 for (Ice::FunctionDeclaration *Func : | 2827 for (Ice::FunctionDeclaration *Func : |
2825 Context->getFunctionDeclarationList()) { | 2828 Context->getFunctionDeclarationList()) { |
2826 installDeclarationName(Trans, Func, FunctionPrefix, "function", | 2829 installDeclarationName(Trans, Func, FunctionPrefix, "function", |
2827 NameIndex); | 2830 NameIndex); |
2828 } | 2831 } |
2829 } | 2832 } |
2830 getTranslator().lowerGlobals(Context->getGlobalVariables()); | 2833 getTranslator().lowerGlobals(Context->getGlobalVariables()); |
2831 GlobalDeclarationNamesAndInitializersInstalled = true; | 2834 GlobalDeclarationNamesAndInitializersInstalled = true; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3021 | 3024 |
3022 if (TopLevelBlocks != 1) { | 3025 if (TopLevelBlocks != 1) { |
3023 errs() << IRFilename | 3026 errs() << IRFilename |
3024 << ": Contains more than one module. Found: " << TopLevelBlocks | 3027 << ": Contains more than one module. Found: " << TopLevelBlocks |
3025 << "\n"; | 3028 << "\n"; |
3026 ErrorStatus.assign(EC_Bitcode); | 3029 ErrorStatus.assign(EC_Bitcode); |
3027 } | 3030 } |
3028 } | 3031 } |
3029 | 3032 |
3030 } // end of namespace Ice | 3033 } // end of namespace Ice |
OLD | NEW |