| 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 /// \file |
| 11 // global variable declarations, and the corresponding variable | 11 /// This file declares the representation of function declarations, |
| 12 // initializers in Subzero. Global variable initializers are | 12 /// global variable declarations, and the corresponding variable |
| 13 // represented as a sequence of simple initializers. | 13 /// initializers in Subzero. Global variable initializers are |
| 14 // | 14 /// represented as a sequence of simple initializers. |
| 15 /// |
| 15 //===----------------------------------------------------------------------===// | 16 //===----------------------------------------------------------------------===// |
| 16 | 17 |
| 17 #ifndef SUBZERO_SRC_ICEGLOBALINITS_H | 18 #ifndef SUBZERO_SRC_ICEGLOBALINITS_H |
| 18 #define SUBZERO_SRC_ICEGLOBALINITS_H | 19 #define SUBZERO_SRC_ICEGLOBALINITS_H |
| 19 | 20 |
| 20 #include "IceDefs.h" | 21 #include "IceDefs.h" |
| 21 #include "IceGlobalContext.h" | 22 #include "IceGlobalContext.h" |
| 22 #include "IceTypes.h" | 23 #include "IceTypes.h" |
| 23 | 24 |
| 24 #pragma clang diagnostic push | 25 #pragma clang diagnostic push |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 void dump(Ostream &Stream) const { | 73 void dump(Ostream &Stream) const { |
| 73 if (!BuildDefs::dump()) | 74 if (!BuildDefs::dump()) |
| 74 return; | 75 return; |
| 75 GlobalContext *const Ctx = nullptr; | 76 GlobalContext *const Ctx = nullptr; |
| 76 dump(Ctx, Stream); | 77 dump(Ctx, Stream); |
| 77 } | 78 } |
| 78 | 79 |
| 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 Kind, |
| 90 llvm::GlobalValue::LinkageTypes Linkage) | 91 llvm::GlobalValue::LinkageTypes Linkage) |
| 91 : Kind(Kind), Linkage(Linkage) {} | 92 : Kind(Kind), Linkage(Linkage) {} |
| 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; |
| 102 FunctionDeclaration(const FunctionDeclaration &) = delete; | 103 FunctionDeclaration(const FunctionDeclaration &) = delete; |
| 103 FunctionDeclaration &operator=(const FunctionDeclaration &) = delete; | 104 FunctionDeclaration &operator=(const FunctionDeclaration &) = delete; |
| 104 | 105 |
| 105 public: | 106 public: |
| 106 static FunctionDeclaration *create(GlobalContext *Context, | 107 static FunctionDeclaration *create(GlobalContext *Context, |
| 107 const FuncSigType &Signature, | 108 const FuncSigType &Signature, |
| 108 llvm::CallingConv::ID CallingConv, | 109 llvm::CallingConv::ID CallingConv, |
| 109 llvm::GlobalValue::LinkageTypes Linkage, | 110 llvm::GlobalValue::LinkageTypes Linkage, |
| 110 bool IsProto) { | 111 bool IsProto) { |
| 111 return new (Context->allocate<FunctionDeclaration>()) | 112 return new (Context->allocate<FunctionDeclaration>()) |
| 112 FunctionDeclaration(Signature, CallingConv, Linkage, IsProto); | 113 FunctionDeclaration(Signature, CallingConv, Linkage, IsProto); |
| 113 } | 114 } |
| 114 const FuncSigType &getSignature() const { return Signature; } | 115 const FuncSigType &getSignature() const { return Signature; } |
| 115 llvm::CallingConv::ID getCallingConv() const { return CallingConv; } | 116 llvm::CallingConv::ID getCallingConv() const { return CallingConv; } |
| 116 // isProto implies that there isn't a (local) definition for the function. | 117 /// isProto implies that there isn't a (local) definition for the function. |
| 117 bool isProto() const { return IsProto; } | 118 bool isProto() const { return IsProto; } |
| 118 static bool classof(const GlobalDeclaration *Addr) { | 119 static bool classof(const GlobalDeclaration *Addr) { |
| 119 return Addr->getKind() == FunctionDeclarationKind; | 120 return Addr->getKind() == FunctionDeclarationKind; |
| 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; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 163 } |
| 163 virtual void dumpType(Ostream &Stream) const; | 164 virtual void dumpType(Ostream &Stream) const; |
| 164 | 165 |
| 165 protected: | 166 protected: |
| 166 explicit Initializer(InitializerKind Kind) : Kind(Kind) {} | 167 explicit Initializer(InitializerKind Kind) : Kind(Kind) {} |
| 167 | 168 |
| 168 private: | 169 private: |
| 169 const InitializerKind Kind; | 170 const InitializerKind Kind; |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 // Models the data in a data initializer. | 173 /// Models the data in a data initializer. |
| 173 typedef std::vector<char> DataVecType; | 174 typedef std::vector<char> DataVecType; |
| 174 | 175 |
| 175 /// Defines a sequence of byte values as a data initializer. | 176 /// Defines a sequence of byte values as a data initializer. |
| 176 class DataInitializer : public Initializer { | 177 class DataInitializer : public Initializer { |
| 177 DataInitializer(const DataInitializer &) = delete; | 178 DataInitializer(const DataInitializer &) = delete; |
| 178 DataInitializer &operator=(const DataInitializer &) = delete; | 179 DataInitializer &operator=(const DataInitializer &) = delete; |
| 179 | 180 |
| 180 public: | 181 public: |
| 181 template <class... Args> | 182 template <class... Args> |
| 182 static std::unique_ptr<DataInitializer> create(Args &&... TheArgs) { | 183 static std::unique_ptr<DataInitializer> create(Args &&... TheArgs) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 198 for (SizeT I = 0; I < Values.size(); ++I) | 199 for (SizeT I = 0; I < Values.size(); ++I) |
| 199 Contents[I] = static_cast<int8_t>(Values[I]); | 200 Contents[I] = static_cast<int8_t>(Values[I]); |
| 200 } | 201 } |
| 201 | 202 |
| 202 DataInitializer(const char *Str, size_t StrLen) | 203 DataInitializer(const char *Str, size_t StrLen) |
| 203 : Initializer(DataInitializerKind), Contents(StrLen) { | 204 : Initializer(DataInitializerKind), Contents(StrLen) { |
| 204 for (size_t i = 0; i < StrLen; ++i) | 205 for (size_t i = 0; i < StrLen; ++i) |
| 205 Contents[i] = Str[i]; | 206 Contents[i] = Str[i]; |
| 206 } | 207 } |
| 207 | 208 |
| 208 // The byte contents of the data initializer. | 209 /// The byte contents of the data initializer. |
| 209 DataVecType Contents; | 210 DataVecType Contents; |
| 210 }; | 211 }; |
| 211 | 212 |
| 212 /// Defines a sequence of bytes initialized to zero. | 213 /// Defines a sequence of bytes initialized to zero. |
| 213 class ZeroInitializer : public Initializer { | 214 class ZeroInitializer : public Initializer { |
| 214 ZeroInitializer(const ZeroInitializer &) = delete; | 215 ZeroInitializer(const ZeroInitializer &) = delete; |
| 215 ZeroInitializer &operator=(const ZeroInitializer &) = delete; | 216 ZeroInitializer &operator=(const ZeroInitializer &) = delete; |
| 216 | 217 |
| 217 public: | 218 public: |
| 218 static std::unique_ptr<ZeroInitializer> create(SizeT Size) { | 219 static std::unique_ptr<ZeroInitializer> create(SizeT Size) { |
| 219 return makeUnique<ZeroInitializer>(Size); | 220 return makeUnique<ZeroInitializer>(Size); |
| 220 } | 221 } |
| 221 SizeT getNumBytes() const final { return Size; } | 222 SizeT getNumBytes() const final { return Size; } |
| 222 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 223 void dump(GlobalContext *Ctx, Ostream &Stream) const final; |
| 223 static bool classof(const Initializer *Z) { | 224 static bool classof(const Initializer *Z) { |
| 224 return Z->getKind() == ZeroInitializerKind; | 225 return Z->getKind() == ZeroInitializerKind; |
| 225 } | 226 } |
| 226 | 227 |
| 227 private: | 228 private: |
| 228 ENABLE_MAKE_UNIQUE; | 229 ENABLE_MAKE_UNIQUE; |
| 229 | 230 |
| 230 explicit ZeroInitializer(SizeT Size) | 231 explicit ZeroInitializer(SizeT Size) |
| 231 : Initializer(ZeroInitializerKind), Size(Size) {} | 232 : Initializer(ZeroInitializerKind), Size(Size) {} |
| 232 | 233 |
| 233 // The number of bytes to be zero initialized. | 234 /// The number of bytes to be zero initialized. |
| 234 SizeT Size; | 235 SizeT Size; |
| 235 }; | 236 }; |
| 236 | 237 |
| 237 /// Defines the relocation value of another global declaration. | 238 /// Defines the relocation value of another global declaration. |
| 238 class RelocInitializer : public Initializer { | 239 class RelocInitializer : public Initializer { |
| 239 RelocInitializer(const RelocInitializer &) = delete; | 240 RelocInitializer(const RelocInitializer &) = delete; |
| 240 RelocInitializer &operator=(const RelocInitializer &) = delete; | 241 RelocInitializer &operator=(const RelocInitializer &) = delete; |
| 241 | 242 |
| 242 public: | 243 public: |
| 243 static std::unique_ptr<RelocInitializer> | 244 static std::unique_ptr<RelocInitializer> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 255 } | 256 } |
| 256 | 257 |
| 257 private: | 258 private: |
| 258 ENABLE_MAKE_UNIQUE; | 259 ENABLE_MAKE_UNIQUE; |
| 259 | 260 |
| 260 RelocInitializer(const GlobalDeclaration *Declaration, RelocOffsetT Offset) | 261 RelocInitializer(const GlobalDeclaration *Declaration, RelocOffsetT Offset) |
| 261 : Initializer(RelocInitializerKind), Declaration(Declaration), | 262 : Initializer(RelocInitializerKind), Declaration(Declaration), |
| 262 Offset(Offset) {} // The global declaration used in the relocation. | 263 Offset(Offset) {} // The global declaration used in the relocation. |
| 263 | 264 |
| 264 const GlobalDeclaration *Declaration; | 265 const GlobalDeclaration *Declaration; |
| 265 // The offset to add to the relocation. | 266 /// The offset to add to the relocation. |
| 266 const RelocOffsetT Offset; | 267 const RelocOffsetT Offset; |
| 267 }; | 268 }; |
| 268 | 269 |
| 269 /// Models the list of initializers. | 270 /// Models the list of initializers. |
| 270 typedef std::vector<std::unique_ptr<Initializer>> InitializerListType; | 271 typedef std::vector<std::unique_ptr<Initializer>> InitializerListType; |
| 271 | 272 |
| 272 static VariableDeclaration *create(GlobalContext *Context) { | 273 static VariableDeclaration *create(GlobalContext *Context) { |
| 273 return new (Context->allocate<VariableDeclaration>()) VariableDeclaration(); | 274 return new (Context->allocate<VariableDeclaration>()) VariableDeclaration(); |
| 274 } | 275 } |
| 275 | 276 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 if (ForceSuppressMangling) | 318 if (ForceSuppressMangling) |
| 318 return true; | 319 return true; |
| 319 return isExternal() && !hasInitializer(); | 320 return isExternal() && !hasInitializer(); |
| 320 } | 321 } |
| 321 | 322 |
| 322 void setSuppressMangling() { ForceSuppressMangling = true; } | 323 void setSuppressMangling() { ForceSuppressMangling = true; } |
| 323 | 324 |
| 324 void discardInitializers() { Initializers = nullptr; } | 325 void discardInitializers() { Initializers = nullptr; } |
| 325 | 326 |
| 326 private: | 327 private: |
| 327 // list of initializers for the declared variable. | 328 /// List of initializers for the declared variable. |
| 328 std::unique_ptr<InitializerListType> Initializers; | 329 std::unique_ptr<InitializerListType> Initializers; |
| 329 bool HasInitializer; | 330 bool HasInitializer; |
| 330 // The alignment of the declared variable. | 331 /// The alignment of the declared variable. |
| 331 uint32_t Alignment; | 332 uint32_t Alignment; |
| 332 // True if a declared (global) constant. | 333 /// True if a declared (global) constant. |
| 333 bool IsConstant; | 334 bool IsConstant; |
| 334 // If set to true, force getSuppressMangling() to return true. | 335 /// If set to true, force getSuppressMangling() to return true. |
| 335 bool ForceSuppressMangling; | 336 bool ForceSuppressMangling; |
| 336 | 337 |
| 337 VariableDeclaration() | 338 VariableDeclaration() |
| 338 : GlobalDeclaration(VariableDeclarationKind, | 339 : GlobalDeclaration(VariableDeclarationKind, |
| 339 llvm::GlobalValue::InternalLinkage), | 340 llvm::GlobalValue::InternalLinkage), |
| 340 Initializers(new InitializerListType), HasInitializer(false), | 341 Initializers(new InitializerListType), HasInitializer(false), |
| 341 Alignment(0), IsConstant(false), ForceSuppressMangling(false) {} | 342 Alignment(0), IsConstant(false), ForceSuppressMangling(false) {} |
| 342 }; | 343 }; |
| 343 | 344 |
| 344 template <class StreamType> | 345 template <class StreamType> |
| 345 inline StreamType &operator<<(StreamType &Stream, | 346 inline StreamType &operator<<(StreamType &Stream, |
| 346 const VariableDeclaration::Initializer &Init) { | 347 const VariableDeclaration::Initializer &Init) { |
| 347 Init.dump(Stream); | 348 Init.dump(Stream); |
| 348 return Stream; | 349 return Stream; |
| 349 } | 350 } |
| 350 | 351 |
| 351 template <class StreamType> | 352 template <class StreamType> |
| 352 inline StreamType &operator<<(StreamType &Stream, | 353 inline StreamType &operator<<(StreamType &Stream, |
| 353 const GlobalDeclaration &Addr) { | 354 const GlobalDeclaration &Addr) { |
| 354 Addr.dump(Stream); | 355 Addr.dump(Stream); |
| 355 return Stream; | 356 return Stream; |
| 356 } | 357 } |
| 357 | 358 |
| 358 } // end of namespace Ice | 359 } // end of namespace Ice |
| 359 | 360 |
| 360 #endif // SUBZERO_SRC_ICEGLOBALINITS_H | 361 #endif // SUBZERO_SRC_ICEGLOBALINITS_H |
| OLD | NEW |