| OLD | NEW |
| 1 //===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===// | 1 //===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===// |
| 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 LLVM to ICE converter. | 10 // This file implements the LLVM to ICE converter. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 O->print(Stream); | 46 O->print(Stream); |
| 47 return Stream.str(); | 47 return Stream.str(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Base class for converting LLVM to ICE. | 50 // Base class for converting LLVM to ICE. |
| 51 // TODO(stichnot): Redesign Converter, LLVM2ICEConverter, | 51 // TODO(stichnot): Redesign Converter, LLVM2ICEConverter, |
| 52 // LLVM2ICEFunctionConverter, and LLVM2ICEGlobalsConverter with | 52 // LLVM2ICEFunctionConverter, and LLVM2ICEGlobalsConverter with |
| 53 // respect to Translator. In particular, the unique_ptr ownership | 53 // respect to Translator. In particular, the unique_ptr ownership |
| 54 // rules in LLVM2ICEFunctionConverter. | 54 // rules in LLVM2ICEFunctionConverter. |
| 55 class LLVM2ICEConverter { | 55 class LLVM2ICEConverter { |
| 56 LLVM2ICEConverter() = delete; |
| 56 LLVM2ICEConverter(const LLVM2ICEConverter &) = delete; | 57 LLVM2ICEConverter(const LLVM2ICEConverter &) = delete; |
| 57 LLVM2ICEConverter &operator=(const LLVM2ICEConverter &) = delete; | 58 LLVM2ICEConverter &operator=(const LLVM2ICEConverter &) = delete; |
| 58 | 59 |
| 59 public: | 60 public: |
| 60 LLVM2ICEConverter(Ice::Converter &Converter) | 61 explicit LLVM2ICEConverter(Ice::Converter &Converter) |
| 61 : Converter(Converter), Ctx(Converter.getContext()), | 62 : Converter(Converter), Ctx(Converter.getContext()), |
| 62 TypeConverter(Converter.getModule()->getContext()) {} | 63 TypeConverter(Converter.getModule()->getContext()) {} |
| 63 | 64 |
| 64 Ice::Converter &getConverter() const { return Converter; } | 65 Ice::Converter &getConverter() const { return Converter; } |
| 65 | 66 |
| 66 protected: | 67 protected: |
| 67 Ice::Converter &Converter; | 68 Ice::Converter &Converter; |
| 68 Ice::GlobalContext *Ctx; | 69 Ice::GlobalContext *Ctx; |
| 69 const Ice::TypeConverter TypeConverter; | 70 const Ice::TypeConverter TypeConverter; |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 // Converter from LLVM functions to ICE. The entry point is the | 73 // Converter from LLVM functions to ICE. The entry point is the |
| 73 // convertFunction method. | 74 // convertFunction method. |
| 74 // | 75 // |
| 75 // Note: this currently assumes that the given IR was verified to be | 76 // Note: this currently assumes that the given IR was verified to be |
| 76 // valid PNaCl bitcode. Otherwise, the behavior is undefined. | 77 // valid PNaCl bitcode. Otherwise, the behavior is undefined. |
| 77 class LLVM2ICEFunctionConverter : LLVM2ICEConverter { | 78 class LLVM2ICEFunctionConverter : LLVM2ICEConverter { |
| 79 LLVM2ICEFunctionConverter() = delete; |
| 78 LLVM2ICEFunctionConverter(const LLVM2ICEFunctionConverter &) = delete; | 80 LLVM2ICEFunctionConverter(const LLVM2ICEFunctionConverter &) = delete; |
| 79 LLVM2ICEFunctionConverter & | 81 LLVM2ICEFunctionConverter & |
| 80 operator=(const LLVM2ICEFunctionConverter &) = delete; | 82 operator=(const LLVM2ICEFunctionConverter &) = delete; |
| 81 | 83 |
| 82 public: | 84 public: |
| 83 LLVM2ICEFunctionConverter(Ice::Converter &Converter) | 85 explicit LLVM2ICEFunctionConverter(Ice::Converter &Converter) |
| 84 : LLVM2ICEConverter(Converter), Func(nullptr) {} | 86 : LLVM2ICEConverter(Converter), Func(nullptr) {} |
| 85 | 87 |
| 86 void convertFunction(const Function *F) { | 88 void convertFunction(const Function *F) { |
| 87 if (Ctx->isIRGenerationDisabled()) | 89 if (Ctx->isIRGenerationDisabled()) |
| 88 return; | 90 return; |
| 89 Func = Ice::Cfg::create(Ctx, Converter.getNextSequenceNumber()); | 91 Func = Ice::Cfg::create(Ctx, Converter.getNextSequenceNumber()); |
| 90 Ice::Cfg::setCurrentCfg(Func.get()); | 92 Ice::Cfg::setCurrentCfg(Func.get()); |
| 91 | 93 |
| 92 VarMap.clear(); | 94 VarMap.clear(); |
| 93 NodeMap.clear(); | 95 NodeMap.clear(); |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 std::map<const Value *, Ice::Variable *> VarMap; | 646 std::map<const Value *, Ice::Variable *> VarMap; |
| 645 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; | 647 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; |
| 646 }; | 648 }; |
| 647 | 649 |
| 648 // Converter from LLVM global variables to ICE. The entry point is the | 650 // Converter from LLVM global variables to ICE. The entry point is the |
| 649 // convertGlobalsToIce method. | 651 // convertGlobalsToIce method. |
| 650 // | 652 // |
| 651 // Note: this currently assumes that the given IR was verified to be | 653 // Note: this currently assumes that the given IR was verified to be |
| 652 // valid PNaCl bitcode. Othewise, the behavior is undefined. | 654 // valid PNaCl bitcode. Othewise, the behavior is undefined. |
| 653 class LLVM2ICEGlobalsConverter : public LLVM2ICEConverter { | 655 class LLVM2ICEGlobalsConverter : public LLVM2ICEConverter { |
| 656 LLVM2ICEGlobalsConverter() = delete; |
| 654 LLVM2ICEGlobalsConverter(const LLVM2ICEGlobalsConverter &) = delete; | 657 LLVM2ICEGlobalsConverter(const LLVM2ICEGlobalsConverter &) = delete; |
| 655 LLVM2ICEGlobalsConverter & | 658 LLVM2ICEGlobalsConverter & |
| 656 operator-(const LLVM2ICEGlobalsConverter &) = delete; | 659 operator-(const LLVM2ICEGlobalsConverter &) = delete; |
| 657 | 660 |
| 658 public: | 661 public: |
| 659 LLVM2ICEGlobalsConverter(Ice::Converter &Converter) | 662 explicit LLVM2ICEGlobalsConverter(Ice::Converter &Converter) |
| 660 : LLVM2ICEConverter(Converter) {} | 663 : LLVM2ICEConverter(Converter) {} |
| 661 | 664 |
| 662 /// Converts global variables, and their initializers into ICE | 665 /// Converts global variables, and their initializers into ICE |
| 663 /// global variable declarations, for module Mod. Returns the set of | 666 /// global variable declarations, for module Mod. Returns the set of |
| 664 /// converted declarations. | 667 /// converted declarations. |
| 665 std::unique_ptr<Ice::VariableDeclarationList> | 668 std::unique_ptr<Ice::VariableDeclarationList> |
| 666 convertGlobalsToIce(Module *Mod); | 669 convertGlobalsToIce(Module *Mod); |
| 667 | 670 |
| 668 private: | 671 private: |
| 669 // Adds the Initializer to the list of initializers for the Global | 672 // Adds the Initializer to the list of initializers for the Global |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 Ctx->pushTimer(TimerID, StackID); | 906 Ctx->pushTimer(TimerID, StackID); |
| 904 } | 907 } |
| 905 LLVM2ICEFunctionConverter FunctionConverter(*this); | 908 LLVM2ICEFunctionConverter FunctionConverter(*this); |
| 906 FunctionConverter.convertFunction(&I); | 909 FunctionConverter.convertFunction(&I); |
| 907 if (TimeThisFunction) | 910 if (TimeThisFunction) |
| 908 Ctx->popTimer(TimerID, StackID); | 911 Ctx->popTimer(TimerID, StackID); |
| 909 } | 912 } |
| 910 } | 913 } |
| 911 | 914 |
| 912 } // end of namespace Ice | 915 } // end of namespace Ice |
| OLD | NEW |