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