| OLD | NEW |
| 1 //===- subzero/src/IceTranslator.h - ICE to machine code --------*- C++ -*-===// | 1 //===- subzero/src/IceTranslator.h - ICE to machine code --------*- C++ -*-===// |
| 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 declares the general driver class for translating ICE to | 10 // This file declares the general driver class for translating ICE to |
| 11 // machine code. | 11 // machine code. |
| 12 // | 12 // |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #ifndef SUBZERO_SRC_ICETRANSLATOR_H | 15 #ifndef SUBZERO_SRC_ICETRANSLATOR_H |
| 16 #define SUBZERO_SRC_ICETRANSLATOR_H | 16 #define SUBZERO_SRC_ICETRANSLATOR_H |
| 17 | 17 |
| 18 #include <memory> | 18 #include <memory> |
| 19 | 19 |
| 20 namespace llvm { | 20 namespace llvm { |
| 21 class Module; | 21 class Module; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace Ice { | 24 namespace Ice { |
| 25 | 25 |
| 26 class ClFlags; | 26 class ClFlags; |
| 27 class Cfg; | 27 class Cfg; |
| 28 class GlobalAddress; |
| 28 class GlobalContext; | 29 class GlobalContext; |
| 29 | 30 |
| 30 // Base class for translating ICE to machine code. | 31 // Base class for translating ICE to machine code. |
| 31 // Derived classes convert other intermediate representations down to ICE, | 32 // Derived classes convert other intermediate representations down to ICE, |
| 32 // and then call the appropriate (inherited) methods to convert ICE into | 33 // and then call the appropriate (inherited) methods to convert ICE into |
| 33 // machine instructions. | 34 // machine instructions. |
| 34 class Translator { | 35 class Translator { |
| 35 public: | 36 public: |
| 36 Translator(GlobalContext *Ctx, const ClFlags &Flags) | 37 Translator(GlobalContext *Ctx, const ClFlags &Flags) |
| 37 : Ctx(Ctx), Flags(Flags), ErrorStatus(0) {} | 38 : Ctx(Ctx), Flags(Flags), ErrorStatus(0) {} |
| 38 | 39 |
| 39 ~Translator(); | 40 ~Translator(); |
| 40 bool getErrorStatus() const { return ErrorStatus; } | 41 bool getErrorStatus() const { return ErrorStatus; } |
| 41 | 42 |
| 42 GlobalContext *getContext() const { return Ctx; } | 43 GlobalContext *getContext() const { return Ctx; } |
| 43 | 44 |
| 44 const ClFlags &getFlags() const { return Flags; } | 45 const ClFlags &getFlags() const { return Flags; } |
| 45 | 46 |
| 46 /// Translates the constructed ICE function Fcn to machine code. | 47 /// Translates the constructed ICE function Fcn to machine code. |
| 47 /// Takes ownership of Fcn. Note: As a side effect, Field Func is | 48 /// Takes ownership of Fcn. Note: As a side effect, Field Func is |
| 48 /// set to Fcn. | 49 /// set to Fcn. |
| 49 void translateFcn(Cfg *Fcn); | 50 void translateFcn(Cfg *Fcn); |
| 50 | 51 |
| 51 /// Emits the constant pool. | 52 /// Emits the constant pool. |
| 52 void emitConstants(); | 53 void emitConstants(); |
| 53 | 54 |
| 54 // Walks module and generates names for unnamed globals and | 55 /// Lowers the given list of global addresses to target. |
| 55 // functions using prefix getFlags().DefaultGlobalPrefix, if the | 56 void |
| 56 // prefix is non-empty. | 57 lowerIceGlobals(const std::vector<Ice::GlobalAddress *> &GlobalAddresses); |
| 58 |
| 59 /// Creates a name using the given prefix and corresponding index. |
| 60 std::string createUnnamedName(const IceString &Prefix, SizeT Index); |
| 61 |
| 62 /// Reports if there is a (potential) conflict between Name, and using |
| 63 /// Prefix to name unnamed names. Errors are put on Ostream. |
| 64 /// Returns true if there isn't a potential conflict. |
| 65 bool checkIfUnnamedNameSafe(const IceString &Name, const char *Kind, |
| 66 const IceString &Prefix, Ostream &Stream); |
| 67 |
| 68 // Walks module and generates names for unnamed globals using prefix |
| 69 // getFlags().DefaultGlobalPrefix, if the prefix is non-empty. |
| 57 void nameUnnamedGlobalAddresses(llvm::Module *Mod); | 70 void nameUnnamedGlobalAddresses(llvm::Module *Mod); |
| 58 | 71 |
| 59 // Converts globals to ICE, and then machine code. | 72 // Walks module and generates names for unnamed functions using |
| 60 // TODO(kschimpf) Remove this once we have ported to PNaClTranslator, | 73 // prefix getFlags().DefaultFunctionPrefix, if the prefix is |
| 61 // and PNaClTranslator generates initializers while parsing. | 74 // non-empty. |
| 62 void convertGlobals(llvm::Module *Mod); | 75 void nameUnnamedFunctions(llvm::Module *Mod); |
| 63 | 76 |
| 64 protected: | 77 protected: |
| 65 GlobalContext *Ctx; | 78 GlobalContext *Ctx; |
| 66 const ClFlags &Flags; | 79 const ClFlags &Flags; |
| 67 // The exit status of the translation. False is successful. True | 80 // The exit status of the translation. False is successful. True |
| 68 // otherwise. | 81 // otherwise. |
| 69 bool ErrorStatus; | 82 bool ErrorStatus; |
| 70 // Ideally, Func would be inside the methods that converts IR to | 83 // Ideally, Func would be inside the methods that converts IR to |
| 71 // functions. However, emitting the constant pool requires a valid | 84 // functions. However, emitting the constant pool requires a valid |
| 72 // Cfg object, so we need to defer deleting the last non-empty Cfg | 85 // Cfg object, so we need to defer deleting the last non-empty Cfg |
| 73 // object to emit the constant pool (via emitConstants). TODO: | 86 // object to emit the constant pool (via emitConstants). TODO: |
| 74 // Since all constants are globally pooled in the GlobalContext | 87 // Since all constants are globally pooled in the GlobalContext |
| 75 // object, change all Constant related functions to use | 88 // object, change all Constant related functions to use |
| 76 // GlobalContext instead of Cfg, and then make emitConstantPool use | 89 // GlobalContext instead of Cfg, and then make emitConstantPool use |
| 77 // that. | 90 // that. |
| 78 std::unique_ptr<Cfg> Func; | 91 std::unique_ptr<Cfg> Func; |
| 79 | 92 |
| 80 private: | 93 private: |
| 81 Translator(const Translator &) LLVM_DELETED_FUNCTION; | 94 Translator(const Translator &) LLVM_DELETED_FUNCTION; |
| 82 Translator &operator=(const Translator &) LLVM_DELETED_FUNCTION; | 95 Translator &operator=(const Translator &) LLVM_DELETED_FUNCTION; |
| 83 }; | 96 }; |
| 84 } | 97 } |
| 85 | 98 |
| 86 #endif // SUBZERO_SRC_ICETRANSLATOR_H | 99 #endif // SUBZERO_SRC_ICETRANSLATOR_H |
| OLD | NEW |