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 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 std::string Buffer; | 624 std::string Buffer; |
625 raw_string_ostream StrBuf(Buffer); | 625 raw_string_ostream StrBuf(Buffer); |
626 StrBuf << "Don't know how to process record: " << Record; | 626 StrBuf << "Don't know how to process record: " << Record; |
627 Error(StrBuf.str()); | 627 Error(StrBuf.str()); |
628 } | 628 } |
629 | 629 |
630 // Class to parse a types block. | 630 // Class to parse a types block. |
631 class TypesParser : public BlockParserBaseClass { | 631 class TypesParser : public BlockParserBaseClass { |
632 public: | 632 public: |
633 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 633 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
634 : BlockParserBaseClass(BlockID, EnclosingParser), NextTypeId(0) {} | 634 : BlockParserBaseClass(BlockID, EnclosingParser), |
| 635 Timer(Ice::TimerStack::TT_parseTypes, getTranslator().getContext()), |
| 636 NextTypeId(0) {} |
635 | 637 |
636 ~TypesParser() override {} | 638 ~TypesParser() override {} |
637 | 639 |
638 private: | 640 private: |
| 641 Ice::TimerMarker Timer; |
639 // The type ID that will be associated with the next type defining | 642 // The type ID that will be associated with the next type defining |
640 // record in the types block. | 643 // record in the types block. |
641 unsigned NextTypeId; | 644 unsigned NextTypeId; |
642 | 645 |
643 void ProcessRecord() override; | 646 void ProcessRecord() override; |
644 | 647 |
645 void setNextTypeIDAsSimpleType(Ice::Type Ty) { | 648 void setNextTypeIDAsSimpleType(Ice::Type Ty) { |
646 Context->getTypeByIDForDefining(NextTypeId++)->setAsSimpleType(Ty); | 649 Context->getTypeByIDForDefining(NextTypeId++)->setAsSimpleType(Ty); |
647 } | 650 } |
648 }; | 651 }; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 return; | 797 return; |
795 } | 798 } |
796 llvm_unreachable("Unknown type block record not processed!"); | 799 llvm_unreachable("Unknown type block record not processed!"); |
797 } | 800 } |
798 | 801 |
799 /// Parses the globals block (i.e. global variable declarations and | 802 /// Parses the globals block (i.e. global variable declarations and |
800 /// corresponding initializers). | 803 /// corresponding initializers). |
801 class GlobalsParser : public BlockParserBaseClass { | 804 class GlobalsParser : public BlockParserBaseClass { |
802 public: | 805 public: |
803 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 806 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
804 : BlockParserBaseClass(BlockID, EnclosingParser), InitializersNeeded(0), | 807 : BlockParserBaseClass(BlockID, EnclosingParser), |
805 NextGlobalID(0), DummyGlobalVar(Ice::VariableDeclaration::create( | 808 Timer(Ice::TimerStack::TT_parseGlobals, getTranslator().getContext()), |
806 getTranslator().getContext())), | 809 InitializersNeeded(0), NextGlobalID(0), |
| 810 DummyGlobalVar( |
| 811 Ice::VariableDeclaration::create(getTranslator().getContext())), |
807 CurGlobalVar(DummyGlobalVar) {} | 812 CurGlobalVar(DummyGlobalVar) {} |
808 | 813 |
809 private: | 814 private: |
| 815 Ice::TimerMarker Timer; |
810 // Keeps track of how many initializers are expected for the global variable | 816 // Keeps track of how many initializers are expected for the global variable |
811 // declaration being built. | 817 // declaration being built. |
812 unsigned InitializersNeeded; | 818 unsigned InitializersNeeded; |
813 | 819 |
814 // The index of the next global variable declaration. | 820 // The index of the next global variable declaration. |
815 unsigned NextGlobalID; | 821 unsigned NextGlobalID; |
816 | 822 |
817 // Dummy global variable declaration to guarantee CurGlobalVar is | 823 // Dummy global variable declaration to guarantee CurGlobalVar is |
818 // always defined (allowing code to not need to check if | 824 // always defined (allowing code to not need to check if |
819 // CurGlobalVar is nullptr). | 825 // CurGlobalVar is nullptr). |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 | 1003 |
998 /// Parses function blocks in the bitcode file. | 1004 /// Parses function blocks in the bitcode file. |
999 class FunctionParser : public BlockParserBaseClass { | 1005 class FunctionParser : public BlockParserBaseClass { |
1000 FunctionParser(const FunctionParser &) = delete; | 1006 FunctionParser(const FunctionParser &) = delete; |
1001 FunctionParser &operator=(const FunctionParser &) = delete; | 1007 FunctionParser &operator=(const FunctionParser &) = delete; |
1002 friend class FunctionValuesymtabParser; | 1008 friend class FunctionValuesymtabParser; |
1003 | 1009 |
1004 public: | 1010 public: |
1005 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 1011 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
1006 : BlockParserBaseClass(BlockID, EnclosingParser), | 1012 : BlockParserBaseClass(BlockID, EnclosingParser), |
| 1013 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()), |
1007 Func(new Ice::Cfg(getTranslator().getContext())), CurrentBbIndex(0), | 1014 Func(new Ice::Cfg(getTranslator().getContext())), CurrentBbIndex(0), |
1008 FcnId(Context->getNextFunctionBlockValueID()), | 1015 FcnId(Context->getNextFunctionBlockValueID()), |
1009 FuncDecl(Context->getFunctionByID(FcnId)), | 1016 FuncDecl(Context->getFunctionByID(FcnId)), |
1010 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), | 1017 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), |
1011 NextLocalInstIndex(Context->getNumGlobalIDs()), | 1018 NextLocalInstIndex(Context->getNumGlobalIDs()), |
1012 InstIsTerminating(false) { | 1019 InstIsTerminating(false) { |
1013 Func->setFunctionName(FuncDecl->getName()); | 1020 Func->setFunctionName(FuncDecl->getName()); |
1014 if (getFlags().TimeEachFunction) | 1021 if (getFlags().TimeEachFunction) |
1015 getTranslator().getContext()->pushTimer( | 1022 getTranslator().getContext()->pushTimer( |
1016 getTranslator().getContext()->getTimerID( | 1023 getTranslator().getContext()->getTimerID( |
(...skipping 12 matching lines...) Expand all Loading... |
1029 } | 1036 } |
1030 | 1037 |
1031 ~FunctionParser() override {}; | 1038 ~FunctionParser() override {}; |
1032 | 1039 |
1033 // Set the next constant ID to the given constant C. | 1040 // Set the next constant ID to the given constant C. |
1034 void setNextConstantID(Ice::Constant *C) { | 1041 void setNextConstantID(Ice::Constant *C) { |
1035 setOperand(NextLocalInstIndex++, C); | 1042 setOperand(NextLocalInstIndex++, C); |
1036 } | 1043 } |
1037 | 1044 |
1038 private: | 1045 private: |
| 1046 Ice::TimerMarker Timer; |
1039 // The corresponding ICE function defined by the function block. | 1047 // The corresponding ICE function defined by the function block. |
1040 Ice::Cfg *Func; | 1048 Ice::Cfg *Func; |
1041 // The index to the current basic block being built. | 1049 // The index to the current basic block being built. |
1042 uint32_t CurrentBbIndex; | 1050 uint32_t CurrentBbIndex; |
1043 // The basic block being built. | 1051 // The basic block being built. |
1044 Ice::CfgNode *CurrentNode; | 1052 Ice::CfgNode *CurrentNode; |
1045 // The ID for the function. | 1053 // The ID for the function. |
1046 unsigned FcnId; | 1054 unsigned FcnId; |
1047 // The corresponding function declaration. | 1055 // The corresponding function declaration. |
1048 Ice::FunctionDeclaration *FuncDecl; | 1056 Ice::FunctionDeclaration *FuncDecl; |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2244 } | 2252 } |
2245 } | 2253 } |
2246 | 2254 |
2247 /// Parses constants within a function block. | 2255 /// Parses constants within a function block. |
2248 class ConstantsParser : public BlockParserBaseClass { | 2256 class ConstantsParser : public BlockParserBaseClass { |
2249 ConstantsParser(const ConstantsParser &) = delete; | 2257 ConstantsParser(const ConstantsParser &) = delete; |
2250 ConstantsParser &operator=(const ConstantsParser &) = delete; | 2258 ConstantsParser &operator=(const ConstantsParser &) = delete; |
2251 | 2259 |
2252 public: | 2260 public: |
2253 ConstantsParser(unsigned BlockID, FunctionParser *FuncParser) | 2261 ConstantsParser(unsigned BlockID, FunctionParser *FuncParser) |
2254 : BlockParserBaseClass(BlockID, FuncParser), FuncParser(FuncParser), | 2262 : BlockParserBaseClass(BlockID, FuncParser), |
2255 NextConstantType(Ice::IceType_void) {} | 2263 Timer(Ice::TimerStack::TT_parseConstants, getTranslator().getContext()), |
| 2264 FuncParser(FuncParser), NextConstantType(Ice::IceType_void) {} |
2256 | 2265 |
2257 ~ConstantsParser() override {} | 2266 ~ConstantsParser() override {} |
2258 | 2267 |
2259 private: | 2268 private: |
| 2269 Ice::TimerMarker Timer; |
2260 // The parser of the function block this constants block appears in. | 2270 // The parser of the function block this constants block appears in. |
2261 FunctionParser *FuncParser; | 2271 FunctionParser *FuncParser; |
2262 // The type to use for succeeding constants. | 2272 // The type to use for succeeding constants. |
2263 Ice::Type NextConstantType; | 2273 Ice::Type NextConstantType; |
2264 | 2274 |
2265 void ProcessRecord() override; | 2275 void ProcessRecord() override; |
2266 | 2276 |
2267 Ice::GlobalContext *getContext() { return getTranslator().getContext(); } | 2277 Ice::GlobalContext *getContext() { return getTranslator().getContext(); } |
2268 | 2278 |
2269 // Returns true if the type to use for succeeding constants is defined. | 2279 // Returns true if the type to use for succeeding constants is defined. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2359 } | 2369 } |
2360 } | 2370 } |
2361 | 2371 |
2362 // Parses valuesymtab blocks appearing in a function block. | 2372 // Parses valuesymtab blocks appearing in a function block. |
2363 class FunctionValuesymtabParser : public ValuesymtabParser { | 2373 class FunctionValuesymtabParser : public ValuesymtabParser { |
2364 FunctionValuesymtabParser(const FunctionValuesymtabParser &) = delete; | 2374 FunctionValuesymtabParser(const FunctionValuesymtabParser &) = delete; |
2365 void operator=(const FunctionValuesymtabParser &) = delete; | 2375 void operator=(const FunctionValuesymtabParser &) = delete; |
2366 | 2376 |
2367 public: | 2377 public: |
2368 FunctionValuesymtabParser(unsigned BlockID, FunctionParser *EnclosingParser) | 2378 FunctionValuesymtabParser(unsigned BlockID, FunctionParser *EnclosingParser) |
2369 : ValuesymtabParser(BlockID, EnclosingParser) {} | 2379 : ValuesymtabParser(BlockID, EnclosingParser), |
| 2380 Timer(Ice::TimerStack::TT_parseFunctionValuesymtabs, |
| 2381 getTranslator().getContext()) {} |
2370 | 2382 |
2371 private: | 2383 private: |
| 2384 Ice::TimerMarker Timer; |
2372 // Returns the enclosing function parser. | 2385 // Returns the enclosing function parser. |
2373 FunctionParser *getFunctionParser() const { | 2386 FunctionParser *getFunctionParser() const { |
2374 return reinterpret_cast<FunctionParser *>(GetEnclosingParser()); | 2387 return reinterpret_cast<FunctionParser *>(GetEnclosingParser()); |
2375 } | 2388 } |
2376 | 2389 |
2377 void setValueName(uint64_t Index, StringType &Name) override; | 2390 void setValueName(uint64_t Index, StringType &Name) override; |
2378 void setBbName(uint64_t Index, StringType &Name) override; | 2391 void setBbName(uint64_t Index, StringType &Name) override; |
2379 | 2392 |
2380 // Reports that the assignment of Name to the value associated with | 2393 // Reports that the assignment of Name to the value associated with |
2381 // index is not possible, for the given Context. | 2394 // index is not possible, for the given Context. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2432 break; | 2445 break; |
2433 } | 2446 } |
2434 return BlockParserBaseClass::ParseBlock(BlockID); | 2447 return BlockParserBaseClass::ParseBlock(BlockID); |
2435 } | 2448 } |
2436 | 2449 |
2437 /// Parses the module block in the bitcode file. | 2450 /// Parses the module block in the bitcode file. |
2438 class ModuleParser : public BlockParserBaseClass { | 2451 class ModuleParser : public BlockParserBaseClass { |
2439 public: | 2452 public: |
2440 ModuleParser(unsigned BlockID, TopLevelParser *Context) | 2453 ModuleParser(unsigned BlockID, TopLevelParser *Context) |
2441 : BlockParserBaseClass(BlockID, Context), | 2454 : BlockParserBaseClass(BlockID, Context), |
| 2455 Timer(Ice::TimerStack::TT_parseModule, |
| 2456 Context->getTranslator().getContext()), |
2442 GlobalDeclarationNamesAndInitializersInstalled(false) {} | 2457 GlobalDeclarationNamesAndInitializersInstalled(false) {} |
2443 | 2458 |
2444 ~ModuleParser() override {} | 2459 ~ModuleParser() override {} |
2445 | 2460 |
2446 private: | 2461 private: |
| 2462 Ice::TimerMarker Timer; |
2447 // True if we have already installed names for unnamed global declarations, | 2463 // True if we have already installed names for unnamed global declarations, |
2448 // and have generated global constant initializers. | 2464 // and have generated global constant initializers. |
2449 bool GlobalDeclarationNamesAndInitializersInstalled; | 2465 bool GlobalDeclarationNamesAndInitializersInstalled; |
2450 | 2466 |
2451 // Generates names for unnamed global addresses (i.e. functions and | 2467 // Generates names for unnamed global addresses (i.e. functions and |
2452 // global variables). Then lowers global variable declaration | 2468 // global variables). Then lowers global variable declaration |
2453 // initializers to the target. May be called multiple times. Only | 2469 // initializers to the target. May be called multiple times. Only |
2454 // the first call will do the installation. | 2470 // the first call will do the installation. |
2455 void InstallGlobalNamesAndGlobalVarInitializers() { | 2471 void InstallGlobalNamesAndGlobalVarInitializers() { |
2456 if (!GlobalDeclarationNamesAndInitializersInstalled) { | 2472 if (!GlobalDeclarationNamesAndInitializersInstalled) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2498 | 2514 |
2499 void ProcessRecord() override; | 2515 void ProcessRecord() override; |
2500 }; | 2516 }; |
2501 | 2517 |
2502 class ModuleValuesymtabParser : public ValuesymtabParser { | 2518 class ModuleValuesymtabParser : public ValuesymtabParser { |
2503 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; | 2519 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; |
2504 void operator=(const ModuleValuesymtabParser &) = delete; | 2520 void operator=(const ModuleValuesymtabParser &) = delete; |
2505 | 2521 |
2506 public: | 2522 public: |
2507 ModuleValuesymtabParser(unsigned BlockID, ModuleParser *MP) | 2523 ModuleValuesymtabParser(unsigned BlockID, ModuleParser *MP) |
2508 : ValuesymtabParser(BlockID, MP) {} | 2524 : ValuesymtabParser(BlockID, MP), |
| 2525 Timer(Ice::TimerStack::TT_parseModuleValuesymtabs, |
| 2526 getTranslator().getContext()) {} |
2509 | 2527 |
2510 ~ModuleValuesymtabParser() override {} | 2528 ~ModuleValuesymtabParser() override {} |
2511 | 2529 |
2512 private: | 2530 private: |
| 2531 Ice::TimerMarker Timer; |
2513 void setValueName(uint64_t Index, StringType &Name) override; | 2532 void setValueName(uint64_t Index, StringType &Name) override; |
2514 void setBbName(uint64_t Index, StringType &Name) override; | 2533 void setBbName(uint64_t Index, StringType &Name) override; |
2515 }; | 2534 }; |
2516 | 2535 |
2517 void ModuleValuesymtabParser::setValueName(uint64_t Index, StringType &Name) { | 2536 void ModuleValuesymtabParser::setValueName(uint64_t Index, StringType &Name) { |
2518 Context->getGlobalDeclarationByID(Index) | 2537 Context->getGlobalDeclarationByID(Index) |
2519 ->setName(StringRef(Name.data(), Name.size())); | 2538 ->setName(StringRef(Name.data(), Name.size())); |
2520 } | 2539 } |
2521 | 2540 |
2522 void ModuleValuesymtabParser::setBbName(uint64_t Index, StringType &Name) { | 2541 void ModuleValuesymtabParser::setBbName(uint64_t Index, StringType &Name) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2663 | 2682 |
2664 if (TopLevelBlocks != 1) { | 2683 if (TopLevelBlocks != 1) { |
2665 errs() << IRFilename | 2684 errs() << IRFilename |
2666 << ": Contains more than one module. Found: " << TopLevelBlocks | 2685 << ": Contains more than one module. Found: " << TopLevelBlocks |
2667 << "\n"; | 2686 << "\n"; |
2668 ErrorStatus = true; | 2687 ErrorStatus = true; |
2669 } | 2688 } |
2670 } | 2689 } |
2671 | 2690 |
2672 } // end of namespace Ice | 2691 } // end of namespace Ice |
OLD | NEW |