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: |
| 37 typedef std::vector<Ice::GlobalAddress *> GlobalAddressList; |
| 38 |
36 Translator(GlobalContext *Ctx, const ClFlags &Flags) | 39 Translator(GlobalContext *Ctx, const ClFlags &Flags) |
37 : Ctx(Ctx), Flags(Flags), ErrorStatus(0) {} | 40 : Ctx(Ctx), Flags(Flags), ErrorStatus(0) {} |
38 | 41 |
39 ~Translator(); | 42 ~Translator(); |
40 bool getErrorStatus() const { return ErrorStatus; } | 43 bool getErrorStatus() const { return ErrorStatus; } |
41 | 44 |
42 GlobalContext *getContext() const { return Ctx; } | 45 GlobalContext *getContext() const { return Ctx; } |
43 | 46 |
44 const ClFlags &getFlags() const { return Flags; } | 47 const ClFlags &getFlags() const { return Flags; } |
45 | 48 |
46 /// Translates the constructed ICE function Fcn to machine code. | 49 /// Translates the constructed ICE function Fcn to machine code. |
47 /// Takes ownership of Fcn. Note: As a side effect, Field Func is | 50 /// Takes ownership of Fcn. Note: As a side effect, Field Func is |
48 /// set to Fcn. | 51 /// set to Fcn. |
49 void translateFcn(Cfg *Fcn); | 52 void translateFcn(Cfg *Fcn); |
50 | 53 |
51 /// Emits the constant pool. | 54 /// Emits the constant pool. |
52 void emitConstants(); | 55 void emitConstants(); |
53 | 56 |
54 // Walks module and generates names for unnamed globals and | 57 /// Lowers the given list of global addresses to target. |
55 // functions using prefix getFlags().DefaultGlobalPrefix, if the | 58 void lowerGlobals(const GlobalAddressList &GlobalAddresses); |
56 // prefix is non-empty. | 59 |
| 60 /// Creates a name using the given prefix and corresponding index. |
| 61 std::string createUnnamedName(const IceString &Prefix, SizeT Index); |
| 62 |
| 63 /// Reports if there is a (potential) conflict between Name, and using |
| 64 /// Prefix to name unnamed names. Errors are put on Ostream. |
| 65 /// Returns true if there isn't a potential conflict. |
| 66 bool checkIfUnnamedNameSafe(const IceString &Name, const char *Kind, |
| 67 const IceString &Prefix, Ostream &Stream); |
| 68 |
| 69 // Walks module and generates names for unnamed globals using prefix |
| 70 // getFlags().DefaultGlobalPrefix, if the prefix is non-empty. |
57 void nameUnnamedGlobalAddresses(llvm::Module *Mod); | 71 void nameUnnamedGlobalAddresses(llvm::Module *Mod); |
58 | 72 |
59 // Converts globals to ICE, and then machine code. | 73 // Walks module and generates names for unnamed functions using |
60 // TODO(kschimpf) Remove this once we have ported to PNaClTranslator, | 74 // prefix getFlags().DefaultFunctionPrefix, if the prefix is |
61 // and PNaClTranslator generates initializers while parsing. | 75 // non-empty. |
62 void convertGlobals(llvm::Module *Mod); | 76 void nameUnnamedFunctions(llvm::Module *Mod); |
63 | 77 |
64 protected: | 78 protected: |
65 GlobalContext *Ctx; | 79 GlobalContext *Ctx; |
66 const ClFlags &Flags; | 80 const ClFlags &Flags; |
67 // The exit status of the translation. False is successful. True | 81 // The exit status of the translation. False is successful. True |
68 // otherwise. | 82 // otherwise. |
69 bool ErrorStatus; | 83 bool ErrorStatus; |
70 // Ideally, Func would be inside the methods that converts IR to | 84 // Ideally, Func would be inside the methods that converts IR to |
71 // functions. However, emitting the constant pool requires a valid | 85 // functions. However, emitting the constant pool requires a valid |
72 // Cfg object, so we need to defer deleting the last non-empty Cfg | 86 // Cfg object, so we need to defer deleting the last non-empty Cfg |
73 // object to emit the constant pool (via emitConstants). TODO: | 87 // object to emit the constant pool (via emitConstants). TODO: |
74 // Since all constants are globally pooled in the GlobalContext | 88 // Since all constants are globally pooled in the GlobalContext |
75 // object, change all Constant related functions to use | 89 // object, change all Constant related functions to use |
76 // GlobalContext instead of Cfg, and then make emitConstantPool use | 90 // GlobalContext instead of Cfg, and then make emitConstantPool use |
77 // that. | 91 // that. |
78 std::unique_ptr<Cfg> Func; | 92 std::unique_ptr<Cfg> Func; |
79 | 93 |
80 private: | 94 private: |
81 Translator(const Translator &) = delete; | 95 Translator(const Translator &) = delete; |
82 Translator &operator=(const Translator &) = delete; | 96 Translator &operator=(const Translator &) = delete; |
83 }; | 97 }; |
84 } | 98 } |
85 | 99 |
86 #endif // SUBZERO_SRC_ICETRANSLATOR_H | 100 #endif // SUBZERO_SRC_ICETRANSLATOR_H |
OLD | NEW |