Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: src/IceTranslator.h

Issue 641193002: Introduce the notion of function addresses in Subzero. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Clean up code and fix nits. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 GlobalVariable;
29 class GlobalContext; 29 class GlobalContext;
30 30
31 // Base class for translating ICE to machine code. 31 // Base class for translating ICE to machine code.
32 // Derived classes convert other intermediate representations down to ICE, 32 // Derived classes convert other intermediate representations down to ICE,
33 // and then call the appropriate (inherited) methods to convert ICE into 33 // and then call the appropriate (inherited) methods to convert ICE into
34 // machine instructions. 34 // machine instructions.
35 class Translator { 35 class Translator {
36 public: 36 public:
37 typedef std::vector<Ice::GlobalAddress *> GlobalAddressList; 37 typedef std::vector<Ice::GlobalVariable *> GlobalVariableListType;
38 38
39 Translator(GlobalContext *Ctx, const ClFlags &Flags) 39 Translator(GlobalContext *Ctx, const ClFlags &Flags)
40 : Ctx(Ctx), Flags(Flags), ErrorStatus(0) {} 40 : Ctx(Ctx), Flags(Flags), ErrorStatus(0) {}
41 41
42 ~Translator(); 42 ~Translator();
43 bool getErrorStatus() const { return ErrorStatus; } 43 bool getErrorStatus() const { return ErrorStatus; }
44 44
45 GlobalContext *getContext() const { return Ctx; } 45 GlobalContext *getContext() const { return Ctx; }
46 46
47 const ClFlags &getFlags() const { return Flags; } 47 const ClFlags &getFlags() const { return Flags; }
48 48
49 /// Translates the constructed ICE function Fcn to machine code. 49 /// Translates the constructed ICE function Fcn to machine code.
50 /// 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
51 /// set to Fcn. 51 /// set to Fcn.
52 void translateFcn(Cfg *Fcn); 52 void translateFcn(Cfg *Fcn);
53 53
54 /// Emits the constant pool. 54 /// Emits the constant pool.
55 void emitConstants(); 55 void emitConstants();
56 56
57 /// Lowers the given list of global addresses to target. 57 /// Lowers the given list of global addresses to target.
58 void lowerGlobals(const GlobalAddressList &GlobalAddresses); 58 void lowerGlobals(const GlobalVariableListType &GlobalVariables);
59 59
60 /// Creates a name using the given prefix and corresponding index. 60 /// Creates a name using the given prefix and corresponding index.
61 std::string createUnnamedName(const IceString &Prefix, SizeT Index); 61 std::string createUnnamedName(const IceString &Prefix, SizeT Index);
62 62
63 /// Reports if there is a (potential) conflict between Name, and using 63 /// Reports if there is a (potential) conflict between Name, and using
64 /// Prefix to name unnamed names. Errors are put on Ostream. 64 /// Prefix to name unnamed names. Errors are put on Ostream.
65 /// Returns true if there isn't a potential conflict. 65 /// Returns true if there isn't a potential conflict.
66 bool checkIfUnnamedNameSafe(const IceString &Name, const char *Kind, 66 bool checkIfUnnamedNameSafe(const IceString &Name, const char *Kind,
67 const IceString &Prefix, Ostream &Stream); 67 const IceString &Prefix, Ostream &Stream);
68 68
69 // Walks module and generates names for unnamed globals using prefix 69 // Walks module and generates names for unnamed globals using prefix
70 // getFlags().DefaultGlobalPrefix, if the prefix is non-empty. 70 // getFlags().DefaultGlobalPrefix, if the prefix is non-empty.
71 void nameUnnamedGlobalAddresses(llvm::Module *Mod); 71 void nameUnnamedGlobalVariables(llvm::Module *Mod);
72 72
73 // Walks module and generates names for unnamed functions using 73 // Walks module and generates names for unnamed functions using
74 // prefix getFlags().DefaultFunctionPrefix, if the prefix is 74 // prefix getFlags().DefaultFunctionPrefix, if the prefix is
75 // non-empty. 75 // non-empty.
76 void nameUnnamedFunctions(llvm::Module *Mod); 76 void nameUnnamedFunctions(llvm::Module *Mod);
77 77
78 protected: 78 protected:
79 GlobalContext *Ctx; 79 GlobalContext *Ctx;
80 const ClFlags &Flags; 80 const ClFlags &Flags;
81 // The exit status of the translation. False is successful. True 81 // The exit status of the translation. False is successful. True
82 // otherwise. 82 // otherwise.
83 bool ErrorStatus; 83 bool ErrorStatus;
84 // Ideally, Func would be inside the methods that converts IR to 84 // Ideally, Func would be inside the methods that converts IR to
85 // functions. However, emitting the constant pool requires a valid 85 // functions. However, emitting the constant pool requires a valid
86 // 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
87 // object to emit the constant pool (via emitConstants). TODO: 87 // object to emit the constant pool (via emitConstants). TODO:
88 // Since all constants are globally pooled in the GlobalContext 88 // Since all constants are globally pooled in the GlobalContext
89 // object, change all Constant related functions to use 89 // object, change all Constant related functions to use
90 // GlobalContext instead of Cfg, and then make emitConstantPool use 90 // GlobalContext instead of Cfg, and then make emitConstantPool use
91 // that. 91 // that.
92 std::unique_ptr<Cfg> Func; 92 std::unique_ptr<Cfg> Func;
93 93
94 private: 94 private:
95 Translator(const Translator &) = delete; 95 Translator(const Translator &) = delete;
96 Translator &operator=(const Translator &) = delete; 96 Translator &operator=(const Translator &) = delete;
97 }; 97 };
98 } 98 }
99 99
100 #endif // SUBZERO_SRC_ICETRANSLATOR_H 100 #endif // SUBZERO_SRC_ICETRANSLATOR_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698