| OLD | NEW |
| 1 //===- subzero/src/IceGlobalInits.h - Global declarations -------*- C++ -*-===// | 1 //===- subzero/src/IceGlobalInits.h - Global declarations -------*- 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 representation of function declarations, | 10 // This file declares the representation of function declarations, |
| 11 // global variable declarations, and the corresponding variable | 11 // global variable declarations, and the corresponding variable |
| 12 // initializers in Subzero. Global variable initializers are | 12 // initializers in Subzero. Global variable initializers are |
| 13 // represented as a sequence of simple initializers. | 13 // represented as a sequence of simple initializers. |
| 14 // | 14 // |
| 15 //===----------------------------------------------------------------------===// | 15 //===----------------------------------------------------------------------===// |
| 16 | 16 |
| 17 #ifndef SUBZERO_SRC_ICEGLOBALINITS_H | 17 #ifndef SUBZERO_SRC_ICEGLOBALINITS_H |
| 18 #define SUBZERO_SRC_ICEGLOBALINITS_H | 18 #define SUBZERO_SRC_ICEGLOBALINITS_H |
| 19 | 19 |
| 20 #include "IceDefs.h" | 20 #include "IceDefs.h" |
| 21 #include "IceGlobalContext.h" | 21 #include "IceGlobalContext.h" |
| 22 #include "IceTypes.h" | 22 #include "IceTypes.h" |
| 23 | 23 |
| 24 #pragma clang diagnostic push | 24 #pragma clang diagnostic push |
| 25 #pragma clang diagnostic ignored "-Wunused-parameter" | 25 #pragma clang diagnostic ignored "-Wunused-parameter" |
| 26 #pragma clang diagnostic ignored "-Wshadow" |
| 26 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" // for NaClBitcodeRecord. | 27 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" // for NaClBitcodeRecord. |
| 27 #include "llvm/IR/CallingConv.h" | 28 #include "llvm/IR/CallingConv.h" |
| 28 #include "llvm/IR/GlobalValue.h" // for GlobalValue::LinkageTypes. | 29 #include "llvm/IR/GlobalValue.h" // for GlobalValue::LinkageTypes. |
| 29 #pragma clang diagnostic pop | 30 #pragma clang diagnostic pop |
| 30 | 31 |
| 31 #include <memory> | 32 #include <memory> |
| 32 #include <utility> | 33 #include <utility> |
| 33 | 34 |
| 34 // TODO(kschimpf): Remove ourselves from using LLVM representation for calling | 35 // TODO(kschimpf): Remove ourselves from using LLVM representation for calling |
| 35 // conventions and linkage types. | 36 // conventions and linkage types. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 /// Returns true if when emitting names, we should suppress mangling. | 80 /// Returns true if when emitting names, we should suppress mangling. |
| 80 virtual bool getSuppressMangling() const = 0; | 81 virtual bool getSuppressMangling() const = 0; |
| 81 | 82 |
| 82 // Mangles name for cross tests, unless external and not defined locally | 83 // Mangles name for cross tests, unless external and not defined locally |
| 83 // (so that relocations accross pnacl-sz and pnacl-llc will work). | 84 // (so that relocations accross pnacl-sz and pnacl-llc will work). |
| 84 virtual IceString mangleName(GlobalContext *Ctx) const { | 85 virtual IceString mangleName(GlobalContext *Ctx) const { |
| 85 return getSuppressMangling() ? Name : Ctx->mangleName(Name); | 86 return getSuppressMangling() ? Name : Ctx->mangleName(Name); |
| 86 } | 87 } |
| 87 | 88 |
| 88 protected: | 89 protected: |
| 89 GlobalDeclaration(GlobalDeclarationKind Kind, | 90 GlobalDeclaration(GlobalDeclarationKind MyKind, |
| 90 llvm::GlobalValue::LinkageTypes Linkage) | 91 llvm::GlobalValue::LinkageTypes MyLinkage) |
| 91 : Kind(Kind), Linkage(Linkage) {} | 92 : Kind(MyKind), Linkage(MyLinkage) {} |
| 92 | 93 |
| 93 const GlobalDeclarationKind Kind; | 94 const GlobalDeclarationKind Kind; |
| 94 IceString Name; | 95 IceString Name; |
| 95 llvm::GlobalValue::LinkageTypes Linkage; | 96 llvm::GlobalValue::LinkageTypes Linkage; |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 // Models a function declaration. This includes the type signature of | 99 // Models a function declaration. This includes the type signature of |
| 99 // the function, its calling conventions, and its linkage. | 100 // the function, its calling conventions, and its linkage. |
| 100 class FunctionDeclaration : public GlobalDeclaration { | 101 class FunctionDeclaration : public GlobalDeclaration { |
| 101 FunctionDeclaration() = delete; | 102 FunctionDeclaration() = delete; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 120 } | 121 } |
| 121 void dumpType(Ostream &Stream) const final; | 122 void dumpType(Ostream &Stream) const final; |
| 122 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 123 void dump(GlobalContext *Ctx, Ostream &Stream) const final; |
| 123 bool getSuppressMangling() const final { return isExternal() && IsProto; } | 124 bool getSuppressMangling() const final { return isExternal() && IsProto; } |
| 124 | 125 |
| 125 private: | 126 private: |
| 126 const Ice::FuncSigType Signature; | 127 const Ice::FuncSigType Signature; |
| 127 llvm::CallingConv::ID CallingConv; | 128 llvm::CallingConv::ID CallingConv; |
| 128 bool IsProto; | 129 bool IsProto; |
| 129 | 130 |
| 130 FunctionDeclaration(const FuncSigType &Signature, | 131 FunctionDeclaration(const FuncSigType &MySignature, |
| 131 llvm::CallingConv::ID CallingConv, | 132 llvm::CallingConv::ID MyCallingConv, |
| 132 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto) | 133 llvm::GlobalValue::LinkageTypes Linkage, bool MyIsProto) |
| 133 : GlobalDeclaration(FunctionDeclarationKind, Linkage), | 134 : GlobalDeclaration(FunctionDeclarationKind, Linkage), |
| 134 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {} | 135 Signature(MySignature), CallingConv(MyCallingConv), IsProto(MyIsProto) { |
| 136 } |
| 135 }; | 137 }; |
| 136 | 138 |
| 137 /// Models a global variable declaration, and its initializers. | 139 /// Models a global variable declaration, and its initializers. |
| 138 class VariableDeclaration : public GlobalDeclaration { | 140 class VariableDeclaration : public GlobalDeclaration { |
| 139 VariableDeclaration(const VariableDeclaration &) = delete; | 141 VariableDeclaration(const VariableDeclaration &) = delete; |
| 140 VariableDeclaration &operator=(const VariableDeclaration &) = delete; | 142 VariableDeclaration &operator=(const VariableDeclaration &) = delete; |
| 141 | 143 |
| 142 public: | 144 public: |
| 143 /// Base class for a global variable initializer. | 145 /// Base class for a global variable initializer. |
| 144 class Initializer { | 146 class Initializer { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 156 virtual ~Initializer() = default; | 158 virtual ~Initializer() = default; |
| 157 virtual SizeT getNumBytes() const = 0; | 159 virtual SizeT getNumBytes() const = 0; |
| 158 virtual void dump(GlobalContext *Ctx, Ostream &Stream) const = 0; | 160 virtual void dump(GlobalContext *Ctx, Ostream &Stream) const = 0; |
| 159 void dump(Ostream &Stream) const { | 161 void dump(Ostream &Stream) const { |
| 160 if (BuildDefs::dump()) | 162 if (BuildDefs::dump()) |
| 161 dump(nullptr, Stream); | 163 dump(nullptr, Stream); |
| 162 } | 164 } |
| 163 virtual void dumpType(Ostream &Stream) const; | 165 virtual void dumpType(Ostream &Stream) const; |
| 164 | 166 |
| 165 protected: | 167 protected: |
| 166 explicit Initializer(InitializerKind Kind) : Kind(Kind) {} | 168 explicit Initializer(InitializerKind MyKind) : Kind(MyKind) {} |
| 167 | 169 |
| 168 private: | 170 private: |
| 169 const InitializerKind Kind; | 171 const InitializerKind Kind; |
| 170 }; | 172 }; |
| 171 | 173 |
| 172 // Models the data in a data initializer. | 174 // Models the data in a data initializer. |
| 173 typedef std::vector<char> DataVecType; | 175 typedef std::vector<char> DataVecType; |
| 174 | 176 |
| 175 /// Defines a sequence of byte values as a data initializer. | 177 /// Defines a sequence of byte values as a data initializer. |
| 176 class DataInitializer : public Initializer { | 178 class DataInitializer : public Initializer { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 222 } |
| 221 SizeT getNumBytes() const final { return Size; } | 223 SizeT getNumBytes() const final { return Size; } |
| 222 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 224 void dump(GlobalContext *Ctx, Ostream &Stream) const final; |
| 223 static bool classof(const Initializer *Z) { | 225 static bool classof(const Initializer *Z) { |
| 224 return Z->getKind() == ZeroInitializerKind; | 226 return Z->getKind() == ZeroInitializerKind; |
| 225 } | 227 } |
| 226 | 228 |
| 227 private: | 229 private: |
| 228 ENABLE_MAKE_UNIQUE; | 230 ENABLE_MAKE_UNIQUE; |
| 229 | 231 |
| 230 explicit ZeroInitializer(SizeT Size) | 232 explicit ZeroInitializer(SizeT MySize) |
| 231 : Initializer(ZeroInitializerKind), Size(Size) {} | 233 : Initializer(ZeroInitializerKind), Size(MySize) {} |
| 232 | 234 |
| 233 // The number of bytes to be zero initialized. | 235 // The number of bytes to be zero initialized. |
| 234 SizeT Size; | 236 SizeT Size; |
| 235 }; | 237 }; |
| 236 | 238 |
| 237 /// Defines the relocation value of another global declaration. | 239 /// Defines the relocation value of another global declaration. |
| 238 class RelocInitializer : public Initializer { | 240 class RelocInitializer : public Initializer { |
| 239 RelocInitializer(const RelocInitializer &) = delete; | 241 RelocInitializer(const RelocInitializer &) = delete; |
| 240 RelocInitializer &operator=(const RelocInitializer &) = delete; | 242 RelocInitializer &operator=(const RelocInitializer &) = delete; |
| 241 | 243 |
| 242 public: | 244 public: |
| 243 static std::unique_ptr<RelocInitializer> | 245 static std::unique_ptr<RelocInitializer> |
| 244 create(const GlobalDeclaration *Declaration, RelocOffsetT Offset) { | 246 create(const GlobalDeclaration *Declaration, RelocOffsetT Offset) { |
| 245 return makeUnique<RelocInitializer>(Declaration, Offset); | 247 return makeUnique<RelocInitializer>(Declaration, Offset); |
| 246 } | 248 } |
| 247 | 249 |
| 248 RelocOffsetT getOffset() const { return Offset; } | 250 RelocOffsetT getOffset() const { return Offset; } |
| 249 const GlobalDeclaration *getDeclaration() const { return Declaration; } | 251 const GlobalDeclaration *getDeclaration() const { return Declaration; } |
| 250 SizeT getNumBytes() const final { return RelocAddrSize; } | 252 SizeT getNumBytes() const final { return RelocAddrSize; } |
| 251 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 253 void dump(GlobalContext *Ctx, Ostream &Stream) const final; |
| 252 void dumpType(Ostream &Stream) const final; | 254 void dumpType(Ostream &Stream) const final; |
| 253 static bool classof(const Initializer *R) { | 255 static bool classof(const Initializer *R) { |
| 254 return R->getKind() == RelocInitializerKind; | 256 return R->getKind() == RelocInitializerKind; |
| 255 } | 257 } |
| 256 | 258 |
| 257 private: | 259 private: |
| 258 ENABLE_MAKE_UNIQUE; | 260 ENABLE_MAKE_UNIQUE; |
| 259 | 261 |
| 260 RelocInitializer(const GlobalDeclaration *Declaration, RelocOffsetT Offset) | 262 RelocInitializer(const GlobalDeclaration *MyDeclaration, |
| 261 : Initializer(RelocInitializerKind), Declaration(Declaration), | 263 RelocOffsetT MyOffset) |
| 262 Offset(Offset) {} // The global declaration used in the relocation. | 264 : Initializer(RelocInitializerKind), Declaration(MyDeclaration), |
| 265 Offset(MyOffset) {} // The global declaration used in the relocation. |
| 263 | 266 |
| 264 const GlobalDeclaration *Declaration; | 267 const GlobalDeclaration *Declaration; |
| 265 // The offset to add to the relocation. | 268 // The offset to add to the relocation. |
| 266 const RelocOffsetT Offset; | 269 const RelocOffsetT Offset; |
| 267 }; | 270 }; |
| 268 | 271 |
| 269 /// Models the list of initializers. | 272 /// Models the list of initializers. |
| 270 typedef std::vector<std::unique_ptr<Initializer>> InitializerListType; | 273 typedef std::vector<std::unique_ptr<Initializer>> InitializerListType; |
| 271 | 274 |
| 272 static VariableDeclaration *create(GlobalContext *Context) { | 275 static VariableDeclaration *create(GlobalContext *Context) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 template <class StreamType> | 354 template <class StreamType> |
| 352 inline StreamType &operator<<(StreamType &Stream, | 355 inline StreamType &operator<<(StreamType &Stream, |
| 353 const GlobalDeclaration &Addr) { | 356 const GlobalDeclaration &Addr) { |
| 354 Addr.dump(Stream); | 357 Addr.dump(Stream); |
| 355 return Stream; | 358 return Stream; |
| 356 } | 359 } |
| 357 | 360 |
| 358 } // end of namespace Ice | 361 } // end of namespace Ice |
| 359 | 362 |
| 360 #endif // SUBZERO_SRC_ICEGLOBALINITS_H | 363 #endif // SUBZERO_SRC_ICEGLOBALINITS_H |
| OLD | NEW |