| 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 /// \file | 10 /// \file |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 GlobalDeclaration &operator=(const GlobalDeclaration &) = delete; | 55 GlobalDeclaration &operator=(const GlobalDeclaration &) = delete; |
| 56 | 56 |
| 57 public: | 57 public: |
| 58 /// Discriminator for LLVM-style RTTI. | 58 /// Discriminator for LLVM-style RTTI. |
| 59 enum GlobalDeclarationKind { | 59 enum GlobalDeclarationKind { |
| 60 FunctionDeclarationKind, | 60 FunctionDeclarationKind, |
| 61 VariableDeclarationKind | 61 VariableDeclarationKind |
| 62 }; | 62 }; |
| 63 GlobalDeclarationKind getKind() const { return Kind; } | 63 GlobalDeclarationKind getKind() const { return Kind; } |
| 64 const IceString &getName() const { return Name; } | 64 const IceString &getName() const { return Name; } |
| 65 void setName(const IceString &NewName) { Name = NewName; } | 65 void setName(const IceString &NewName) { |
| 66 Name = getSuppressMangling() ? NewName : GlobalContext::mangleName(NewName); |
| 67 } |
| 66 bool hasName() const { return !Name.empty(); } | 68 bool hasName() const { return !Name.empty(); } |
| 67 bool isInternal() const { | 69 bool isInternal() const { |
| 68 return Linkage == llvm::GlobalValue::InternalLinkage; | 70 return Linkage == llvm::GlobalValue::InternalLinkage; |
| 69 } | 71 } |
| 70 llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; } | 72 llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; } |
| 71 bool isExternal() const { | 73 bool isExternal() const { |
| 72 return Linkage == llvm::GlobalValue::ExternalLinkage; | 74 return Linkage == llvm::GlobalValue::ExternalLinkage; |
| 73 } | 75 } |
| 74 void setLinkage(llvm::GlobalValue::LinkageTypes NewLinkage) { | |
| 75 Linkage = NewLinkage; | |
| 76 } | |
| 77 virtual ~GlobalDeclaration() = default; | 76 virtual ~GlobalDeclaration() = default; |
| 78 | 77 |
| 79 /// Prints out type of the global declaration. | 78 /// Prints out type of the global declaration. |
| 80 virtual void dumpType(Ostream &Stream) const = 0; | 79 virtual void dumpType(Ostream &Stream) const = 0; |
| 81 | 80 |
| 82 /// Prints out the global declaration. | 81 /// Prints out the global declaration. |
| 83 virtual void dump(GlobalContext *Ctx, Ostream &Stream) const = 0; | 82 virtual void dump(Ostream &Stream) const = 0; |
| 84 void dump(Ostream &Stream) const { | |
| 85 if (!BuildDefs::dump()) | |
| 86 return; | |
| 87 GlobalContext *const Ctx = nullptr; | |
| 88 dump(Ctx, Stream); | |
| 89 } | |
| 90 | 83 |
| 91 /// Returns true if when emitting names, we should suppress mangling. | 84 /// Returns true if when emitting names, we should suppress mangling. |
| 92 virtual bool getSuppressMangling() const = 0; | 85 virtual bool getSuppressMangling() const = 0; |
| 93 | 86 |
| 94 /// Mangles name for cross tests, unless external and not defined locally (so | |
| 95 /// that relocations across pnacl-sz and pnacl-llc will work). | |
| 96 virtual IceString mangleName(GlobalContext *Ctx) const { | |
| 97 return getSuppressMangling() ? Name : Ctx->mangleName(Name); | |
| 98 } | |
| 99 | |
| 100 /// Returns textual name of linkage. | 87 /// Returns textual name of linkage. |
| 101 const char *getLinkageName() const { | 88 const char *getLinkageName() const { |
| 102 return isInternal() ? "internal" : "external"; | 89 return isInternal() ? "internal" : "external"; |
| 103 } | 90 } |
| 104 | 91 |
| 105 protected: | 92 protected: |
| 106 GlobalDeclaration(GlobalDeclarationKind Kind, | 93 GlobalDeclaration(GlobalDeclarationKind Kind, |
| 107 llvm::GlobalValue::LinkageTypes Linkage) | 94 llvm::GlobalValue::LinkageTypes Linkage) |
| 108 : Kind(Kind), Linkage(Linkage) {} | 95 : Kind(Kind), Linkage(Linkage) {} |
| 109 | 96 |
| 110 /// Returns true if linkage is defined correctly for the global declaration, | 97 /// Returns true if linkage is defined correctly for the global declaration, |
| 111 /// based on default rules. | 98 /// based on default rules. |
| 112 bool verifyLinkageDefault(const GlobalContext *Ctx) const { | 99 bool verifyLinkageDefault(const GlobalContext *Ctx) const { |
| 113 switch (Linkage) { | 100 switch (Linkage) { |
| 114 default: | 101 default: |
| 115 return false; | 102 return false; |
| 116 case llvm::GlobalValue::InternalLinkage: | 103 case llvm::GlobalValue::InternalLinkage: |
| 117 return true; | 104 return true; |
| 118 case llvm::GlobalValue::ExternalLinkage: | 105 case llvm::GlobalValue::ExternalLinkage: |
| 119 return Ctx->getFlags().getAllowExternDefinedSymbols(); | 106 return Ctx->getFlags().getAllowExternDefinedSymbols(); |
| 120 } | 107 } |
| 121 } | 108 } |
| 122 | 109 |
| 123 const GlobalDeclarationKind Kind; | 110 const GlobalDeclarationKind Kind; |
| 111 const llvm::GlobalValue::LinkageTypes Linkage; |
| 124 IceString Name; | 112 IceString Name; |
| 125 llvm::GlobalValue::LinkageTypes Linkage; | |
| 126 }; | 113 }; |
| 127 | 114 |
| 128 /// Models a function declaration. This includes the type signature of the | 115 /// Models a function declaration. This includes the type signature of the |
| 129 /// function, its calling conventions, and its linkage. | 116 /// function, its calling conventions, and its linkage. |
| 130 class FunctionDeclaration : public GlobalDeclaration { | 117 class FunctionDeclaration : public GlobalDeclaration { |
| 131 FunctionDeclaration() = delete; | 118 FunctionDeclaration() = delete; |
| 132 FunctionDeclaration(const FunctionDeclaration &) = delete; | 119 FunctionDeclaration(const FunctionDeclaration &) = delete; |
| 133 FunctionDeclaration &operator=(const FunctionDeclaration &) = delete; | 120 FunctionDeclaration &operator=(const FunctionDeclaration &) = delete; |
| 134 | 121 |
| 135 public: | 122 public: |
| 136 static FunctionDeclaration *create(GlobalContext *Context, | 123 static FunctionDeclaration *create(GlobalContext *Context, |
| 137 const FuncSigType &Signature, | 124 const FuncSigType &Signature, |
| 138 llvm::CallingConv::ID CallingConv, | 125 llvm::CallingConv::ID CallingConv, |
| 139 llvm::GlobalValue::LinkageTypes Linkage, | 126 llvm::GlobalValue::LinkageTypes Linkage, |
| 140 bool IsProto) { | 127 bool IsProto) { |
| 141 return new (Context->allocate<FunctionDeclaration>()) | 128 return new (Context->allocate<FunctionDeclaration>()) |
| 142 FunctionDeclaration(Signature, CallingConv, Linkage, IsProto); | 129 FunctionDeclaration(Signature, CallingConv, Linkage, IsProto); |
| 143 } | 130 } |
| 144 const FuncSigType &getSignature() const { return Signature; } | 131 const FuncSigType &getSignature() const { return Signature; } |
| 145 llvm::CallingConv::ID getCallingConv() const { return CallingConv; } | 132 llvm::CallingConv::ID getCallingConv() const { return CallingConv; } |
| 146 /// isProto implies that there isn't a (local) definition for the function. | 133 /// isProto implies that there isn't a (local) definition for the function. |
| 147 bool isProto() const { return IsProto; } | 134 bool isProto() const { return IsProto; } |
| 148 static bool classof(const GlobalDeclaration *Addr) { | 135 static bool classof(const GlobalDeclaration *Addr) { |
| 149 return Addr->getKind() == FunctionDeclarationKind; | 136 return Addr->getKind() == FunctionDeclarationKind; |
| 150 } | 137 } |
| 151 void dumpType(Ostream &Stream) const final; | 138 void dumpType(Ostream &Stream) const final; |
| 152 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 139 void dump(Ostream &Stream) const final; |
| 153 bool getSuppressMangling() const final { return isExternal() && IsProto; } | 140 bool getSuppressMangling() const final { return isExternal() && IsProto; } |
| 154 | 141 |
| 155 /// Returns true if linkage is correct for the function declaration. | 142 /// Returns true if linkage is correct for the function declaration. |
| 156 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { | 143 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { |
| 157 if (isPNaClABIExternalName() || isIntrinsicName(Ctx)) | 144 if (isPNaClABIExternalName() || isIntrinsicName(Ctx)) |
| 158 return Linkage == llvm::GlobalValue::ExternalLinkage; | 145 return Linkage == llvm::GlobalValue::ExternalLinkage; |
| 159 return verifyLinkageDefault(Ctx); | 146 return verifyLinkageDefault(Ctx); |
| 160 } | 147 } |
| 161 | 148 |
| 162 /// Validates that the type signature of the function is correct. Returns true | 149 /// Validates that the type signature of the function is correct. Returns true |
| (...skipping 18 matching lines...) Expand all Loading... |
| 181 } | 168 } |
| 182 | 169 |
| 183 /// Same as above, except IsIntrinsic is true if the function is intrinsic | 170 /// Same as above, except IsIntrinsic is true if the function is intrinsic |
| 184 /// (even if not a PNaCl intrinsic). | 171 /// (even if not a PNaCl intrinsic). |
| 185 const Intrinsics::FullIntrinsicInfo * | 172 const Intrinsics::FullIntrinsicInfo * |
| 186 getIntrinsicInfo(const GlobalContext *Ctx, bool *IsIntrinsic) const; | 173 getIntrinsicInfo(const GlobalContext *Ctx, bool *IsIntrinsic) const; |
| 187 | 174 |
| 188 private: | 175 private: |
| 189 const Ice::FuncSigType Signature; | 176 const Ice::FuncSigType Signature; |
| 190 llvm::CallingConv::ID CallingConv; | 177 llvm::CallingConv::ID CallingConv; |
| 191 bool IsProto; | 178 const bool IsProto; |
| 192 | 179 |
| 193 FunctionDeclaration(const FuncSigType &Signature, | 180 FunctionDeclaration(const FuncSigType &Signature, |
| 194 llvm::CallingConv::ID CallingConv, | 181 llvm::CallingConv::ID CallingConv, |
| 195 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto) | 182 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto) |
| 196 : GlobalDeclaration(FunctionDeclarationKind, Linkage), | 183 : GlobalDeclaration(FunctionDeclarationKind, Linkage), |
| 197 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {} | 184 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {} |
| 198 | 185 |
| 199 bool isPNaClABIExternalName() const { | 186 bool isPNaClABIExternalName() const { |
| 200 const char *Name = getName().c_str(); | 187 const char *Name = getName().c_str(); |
| 201 return strcmp(Name, "_start") == 0 || strcmp(Name, "__pnacl_pso_root") == 0; | 188 return strcmp(Name, "_start") == 0 || strcmp(Name, "__pnacl_pso_root") == 0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 227 public: | 214 public: |
| 228 /// Discriminator for LLVM-style RTTI. | 215 /// Discriminator for LLVM-style RTTI. |
| 229 enum InitializerKind { | 216 enum InitializerKind { |
| 230 DataInitializerKind, | 217 DataInitializerKind, |
| 231 ZeroInitializerKind, | 218 ZeroInitializerKind, |
| 232 RelocInitializerKind | 219 RelocInitializerKind |
| 233 }; | 220 }; |
| 234 InitializerKind getKind() const { return Kind; } | 221 InitializerKind getKind() const { return Kind; } |
| 235 virtual ~Initializer() = default; | 222 virtual ~Initializer() = default; |
| 236 virtual SizeT getNumBytes() const = 0; | 223 virtual SizeT getNumBytes() const = 0; |
| 237 virtual void dump(GlobalContext *Ctx, Ostream &Stream) const = 0; | 224 virtual void dump(Ostream &Stream) const = 0; |
| 238 void dump(Ostream &Stream) const { | |
| 239 if (BuildDefs::dump()) | |
| 240 dump(nullptr, Stream); | |
| 241 } | |
| 242 virtual void dumpType(Ostream &Stream) const; | 225 virtual void dumpType(Ostream &Stream) const; |
| 243 | 226 |
| 244 protected: | 227 protected: |
| 245 explicit Initializer(InitializerKind Kind) : Kind(Kind) {} | 228 explicit Initializer(InitializerKind Kind) : Kind(Kind) {} |
| 246 | 229 |
| 247 private: | 230 private: |
| 248 const InitializerKind Kind; | 231 const InitializerKind Kind; |
| 249 }; | 232 }; |
| 250 | 233 |
| 251 /// Models the data in a data initializer. | 234 /// Models the data in a data initializer. |
| 252 using DataVecType = std::vector<char>; | 235 using DataVecType = std::vector<char>; |
| 253 | 236 |
| 254 /// Defines a sequence of byte values as a data initializer. | 237 /// Defines a sequence of byte values as a data initializer. |
| 255 class DataInitializer : public Initializer { | 238 class DataInitializer : public Initializer { |
| 256 DataInitializer(const DataInitializer &) = delete; | 239 DataInitializer(const DataInitializer &) = delete; |
| 257 DataInitializer &operator=(const DataInitializer &) = delete; | 240 DataInitializer &operator=(const DataInitializer &) = delete; |
| 258 | 241 |
| 259 public: | 242 public: |
| 260 template <class... Args> | 243 template <class... Args> |
| 261 static std::unique_ptr<DataInitializer> create(Args &&... TheArgs) { | 244 static std::unique_ptr<DataInitializer> create(Args &&... TheArgs) { |
| 262 return makeUnique<DataInitializer>(std::forward<Args>(TheArgs)...); | 245 return makeUnique<DataInitializer>(std::forward<Args>(TheArgs)...); |
| 263 } | 246 } |
| 264 | 247 |
| 265 const DataVecType &getContents() const { return Contents; } | 248 const DataVecType &getContents() const { return Contents; } |
| 266 SizeT getNumBytes() const final { return Contents.size(); } | 249 SizeT getNumBytes() const final { return Contents.size(); } |
| 267 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 250 void dump(Ostream &Stream) const final; |
| 268 static bool classof(const Initializer *D) { | 251 static bool classof(const Initializer *D) { |
| 269 return D->getKind() == DataInitializerKind; | 252 return D->getKind() == DataInitializerKind; |
| 270 } | 253 } |
| 271 | 254 |
| 272 private: | 255 private: |
| 273 ENABLE_MAKE_UNIQUE; | 256 ENABLE_MAKE_UNIQUE; |
| 274 | 257 |
| 275 DataInitializer(const llvm::NaClBitcodeRecord::RecordVector &Values) | 258 DataInitializer(const llvm::NaClBitcodeRecord::RecordVector &Values) |
| 276 : Initializer(DataInitializerKind), Contents(Values.size()) { | 259 : Initializer(DataInitializerKind), Contents(Values.size()) { |
| 277 for (SizeT I = 0; I < Values.size(); ++I) | 260 for (SizeT I = 0; I < Values.size(); ++I) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 291 /// Defines a sequence of bytes initialized to zero. | 274 /// Defines a sequence of bytes initialized to zero. |
| 292 class ZeroInitializer : public Initializer { | 275 class ZeroInitializer : public Initializer { |
| 293 ZeroInitializer(const ZeroInitializer &) = delete; | 276 ZeroInitializer(const ZeroInitializer &) = delete; |
| 294 ZeroInitializer &operator=(const ZeroInitializer &) = delete; | 277 ZeroInitializer &operator=(const ZeroInitializer &) = delete; |
| 295 | 278 |
| 296 public: | 279 public: |
| 297 static std::unique_ptr<ZeroInitializer> create(SizeT Size) { | 280 static std::unique_ptr<ZeroInitializer> create(SizeT Size) { |
| 298 return makeUnique<ZeroInitializer>(Size); | 281 return makeUnique<ZeroInitializer>(Size); |
| 299 } | 282 } |
| 300 SizeT getNumBytes() const final { return Size; } | 283 SizeT getNumBytes() const final { return Size; } |
| 301 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 284 void dump(Ostream &Stream) const final; |
| 302 static bool classof(const Initializer *Z) { | 285 static bool classof(const Initializer *Z) { |
| 303 return Z->getKind() == ZeroInitializerKind; | 286 return Z->getKind() == ZeroInitializerKind; |
| 304 } | 287 } |
| 305 | 288 |
| 306 private: | 289 private: |
| 307 ENABLE_MAKE_UNIQUE; | 290 ENABLE_MAKE_UNIQUE; |
| 308 | 291 |
| 309 explicit ZeroInitializer(SizeT Size) | 292 explicit ZeroInitializer(SizeT Size) |
| 310 : Initializer(ZeroInitializerKind), Size(Size) {} | 293 : Initializer(ZeroInitializerKind), Size(Size) {} |
| 311 | 294 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 326 } |
| 344 | 327 |
| 345 bool hasFixup() const { return HasFixup; } | 328 bool hasFixup() const { return HasFixup; } |
| 346 FixupKind getFixup() const { | 329 FixupKind getFixup() const { |
| 347 assert(HasFixup); | 330 assert(HasFixup); |
| 348 return Fixup; | 331 return Fixup; |
| 349 } | 332 } |
| 350 | 333 |
| 351 const GlobalDeclaration *getDeclaration() const { return Declaration; } | 334 const GlobalDeclaration *getDeclaration() const { return Declaration; } |
| 352 SizeT getNumBytes() const final { return RelocAddrSize; } | 335 SizeT getNumBytes() const final { return RelocAddrSize; } |
| 353 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 336 void dump(Ostream &Stream) const final; |
| 354 void dumpType(Ostream &Stream) const final; | 337 void dumpType(Ostream &Stream) const final; |
| 355 static bool classof(const Initializer *R) { | 338 static bool classof(const Initializer *R) { |
| 356 return R->getKind() == RelocInitializerKind; | 339 return R->getKind() == RelocInitializerKind; |
| 357 } | 340 } |
| 358 | 341 |
| 359 private: | 342 private: |
| 360 ENABLE_MAKE_UNIQUE; | 343 ENABLE_MAKE_UNIQUE; |
| 361 | 344 |
| 362 RelocInitializer(const GlobalDeclaration *Declaration, | 345 RelocInitializer(const GlobalDeclaration *Declaration, |
| 363 const RelocOffsetArray &OffsetExpr, bool HasFixup, | 346 const RelocOffsetArray &OffsetExpr, bool HasFixup, |
| 364 FixupKind Fixup = 0) | 347 FixupKind Fixup = 0) |
| 365 : Initializer(RelocInitializerKind), | 348 : Initializer(RelocInitializerKind), |
| 366 Declaration(Declaration), // The global declaration used in the reloc. | 349 Declaration(Declaration), // The global declaration used in the reloc. |
| 367 OffsetExpr(OffsetExpr), HasFixup(HasFixup), Fixup(Fixup) {} | 350 OffsetExpr(OffsetExpr), HasFixup(HasFixup), Fixup(Fixup) {} |
| 368 | 351 |
| 369 const GlobalDeclaration *Declaration; | 352 const GlobalDeclaration *Declaration; |
| 370 /// The offset to add to the relocation. | 353 /// The offset to add to the relocation. |
| 371 const RelocOffsetArray OffsetExpr; | 354 const RelocOffsetArray OffsetExpr; |
| 372 const bool HasFixup = false; | 355 const bool HasFixup = false; |
| 373 const FixupKind Fixup = 0; | 356 const FixupKind Fixup = 0; |
| 374 }; | 357 }; |
| 375 | 358 |
| 376 /// Models the list of initializers. | 359 /// Models the list of initializers. |
| 377 using InitializerListType = std::vector<std::unique_ptr<Initializer>>; | 360 using InitializerListType = std::vector<std::unique_ptr<Initializer>>; |
| 378 | 361 |
| 379 static VariableDeclaration *create(GlobalContext *Context) { | 362 static VariableDeclaration *create(GlobalContext *Context, |
| 380 return new (Context->allocate<VariableDeclaration>()) VariableDeclaration(); | 363 bool SuppressMangling = false, |
| 364 llvm::GlobalValue::LinkageTypes Linkage = |
| 365 llvm::GlobalValue::InternalLinkage) { |
| 366 return new (Context->allocate<VariableDeclaration>()) |
| 367 VariableDeclaration(Linkage, SuppressMangling); |
| 368 } |
| 369 static VariableDeclaration *createExternal(GlobalContext *Context) { |
| 370 constexpr bool SuppressMangling = true; |
| 371 constexpr llvm::GlobalValue::LinkageTypes Linkage = |
| 372 llvm::GlobalValue::ExternalLinkage; |
| 373 return create(Context, SuppressMangling, Linkage); |
| 381 } | 374 } |
| 382 | 375 |
| 383 const InitializerListType &getInitializers() const { return *Initializers; } | 376 const InitializerListType &getInitializers() const { return *Initializers; } |
| 384 bool getIsConstant() const { return IsConstant; } | 377 bool getIsConstant() const { return IsConstant; } |
| 385 void setIsConstant(bool NewValue) { IsConstant = NewValue; } | 378 void setIsConstant(bool NewValue) { IsConstant = NewValue; } |
| 386 uint32_t getAlignment() const { return Alignment; } | 379 uint32_t getAlignment() const { return Alignment; } |
| 387 void setAlignment(uint32_t NewAlignment) { Alignment = NewAlignment; } | 380 void setAlignment(uint32_t NewAlignment) { Alignment = NewAlignment; } |
| 388 bool hasInitializer() const { return HasInitializer; } | 381 bool hasInitializer() const { return HasInitializer; } |
| 389 bool hasNonzeroInitializer() const { | 382 bool hasNonzeroInitializer() const { |
| 390 return !(Initializers->size() == 1 && | 383 return !(Initializers->size() == 1 && |
| 391 llvm::isa<ZeroInitializer>((*Initializers)[0].get())); | 384 llvm::isa<ZeroInitializer>((*Initializers)[0].get())); |
| 392 } | 385 } |
| 393 | 386 |
| 394 /// Returns the number of bytes for the initializer of the global address. | 387 /// Returns the number of bytes for the initializer of the global address. |
| 395 SizeT getNumBytes() const { | 388 SizeT getNumBytes() const { |
| 396 SizeT Count = 0; | 389 SizeT Count = 0; |
| 397 for (const std::unique_ptr<Initializer> &Init : *Initializers) { | 390 for (const std::unique_ptr<Initializer> &Init : *Initializers) { |
| 398 Count += Init->getNumBytes(); | 391 Count += Init->getNumBytes(); |
| 399 } | 392 } |
| 400 return Count; | 393 return Count; |
| 401 } | 394 } |
| 402 | 395 |
| 403 /// Adds Initializer to the list of initializers. Takes ownership of the | 396 /// Adds Initializer to the list of initializers. Takes ownership of the |
| 404 /// initializer. | 397 /// initializer. |
| 405 void addInitializer(std::unique_ptr<Initializer> Initializer) { | 398 void addInitializer(std::unique_ptr<Initializer> Initializer) { |
| 399 const bool OldSuppressMangling = getSuppressMangling(); |
| 406 Initializers->emplace_back(std::move(Initializer)); | 400 Initializers->emplace_back(std::move(Initializer)); |
| 407 HasInitializer = true; | 401 HasInitializer = true; |
| 402 // The getSuppressMangling() logic depends on whether the global variable |
| 403 // has initializers. If its value changed as a result of adding an |
| 404 // initializer, then make sure we haven't previously set the name based on |
| 405 // faulty SuppressMangling logic. |
| 406 const bool SameMangling = (OldSuppressMangling == getSuppressMangling()); |
| 407 (void)SameMangling; |
| 408 assert(!Name.empty() || SameMangling); |
| 408 } | 409 } |
| 409 | 410 |
| 410 /// Prints out type for initializer associated with the declaration to Stream. | 411 /// Prints out type for initializer associated with the declaration to Stream. |
| 411 void dumpType(Ostream &Stream) const final; | 412 void dumpType(Ostream &Stream) const final; |
| 412 | 413 |
| 413 /// Prints out the definition of the global variable declaration (including | 414 /// Prints out the definition of the global variable declaration (including |
| 414 /// initialization). | 415 /// initialization). |
| 415 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 416 virtual void dump(Ostream &Stream) const; |
| 416 | 417 |
| 417 /// Returns true if linkage is correct for the variable declaration. | 418 /// Returns true if linkage is correct for the variable declaration. |
| 418 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { | 419 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { |
| 419 return verifyLinkageDefault(Ctx); | 420 return verifyLinkageDefault(Ctx); |
| 420 } | 421 } |
| 421 | 422 |
| 422 static bool classof(const GlobalDeclaration *Addr) { | 423 static bool classof(const GlobalDeclaration *Addr) { |
| 423 return Addr->getKind() == VariableDeclarationKind; | 424 return Addr->getKind() == VariableDeclarationKind; |
| 424 } | 425 } |
| 425 | 426 |
| 426 bool getSuppressMangling() const final { | 427 bool getSuppressMangling() const final { |
| 427 if (ForceSuppressMangling) | 428 if (ForceSuppressMangling) |
| 428 return true; | 429 return true; |
| 429 return isExternal() && !hasInitializer(); | 430 return isExternal() && !hasInitializer(); |
| 430 } | 431 } |
| 431 | 432 |
| 432 void setSuppressMangling() { ForceSuppressMangling = true; } | |
| 433 | |
| 434 void discardInitializers() { Initializers = nullptr; } | 433 void discardInitializers() { Initializers = nullptr; } |
| 435 | 434 |
| 436 private: | 435 private: |
| 437 /// List of initializers for the declared variable. | 436 /// List of initializers for the declared variable. |
| 438 std::unique_ptr<InitializerListType> Initializers; | 437 std::unique_ptr<InitializerListType> Initializers; |
| 439 bool HasInitializer; | 438 bool HasInitializer = false; |
| 440 /// The alignment of the declared variable. | 439 /// The alignment of the declared variable. |
| 441 uint32_t Alignment; | 440 uint32_t Alignment = 0; |
| 442 /// True if a declared (global) constant. | 441 /// True if a declared (global) constant. |
| 443 bool IsConstant; | 442 bool IsConstant = false; |
| 444 /// If set to true, force getSuppressMangling() to return true. | 443 /// If set to true, force getSuppressMangling() to return true. |
| 445 bool ForceSuppressMangling; | 444 const bool ForceSuppressMangling; |
| 446 | 445 |
| 447 VariableDeclaration() | 446 VariableDeclaration(llvm::GlobalValue::LinkageTypes Linkage, |
| 448 : GlobalDeclaration(VariableDeclarationKind, | 447 bool SuppressMangling) |
| 449 llvm::GlobalValue::InternalLinkage), | 448 : GlobalDeclaration(VariableDeclarationKind, Linkage), |
| 450 Initializers(new InitializerListType), HasInitializer(false), | 449 Initializers(new InitializerListType), |
| 451 Alignment(0), IsConstant(false), ForceSuppressMangling(false) {} | 450 ForceSuppressMangling(SuppressMangling) {} |
| 452 }; | 451 }; |
| 453 | 452 |
| 454 template <class StreamType> | 453 template <class StreamType> |
| 455 inline StreamType &operator<<(StreamType &Stream, | 454 inline StreamType &operator<<(StreamType &Stream, |
| 456 const VariableDeclaration::Initializer &Init) { | 455 const VariableDeclaration::Initializer &Init) { |
| 457 Init.dump(Stream); | 456 Init.dump(Stream); |
| 458 return Stream; | 457 return Stream; |
| 459 } | 458 } |
| 460 | 459 |
| 461 template <class StreamType> | 460 template <class StreamType> |
| 462 inline StreamType &operator<<(StreamType &Stream, | 461 inline StreamType &operator<<(StreamType &Stream, |
| 463 const GlobalDeclaration &Addr) { | 462 const GlobalDeclaration &Addr) { |
| 464 Addr.dump(Stream); | 463 Addr.dump(Stream); |
| 465 return Stream; | 464 return Stream; |
| 466 } | 465 } |
| 467 | 466 |
| 468 } // end of namespace Ice | 467 } // end of namespace Ice |
| 469 | 468 |
| 470 #endif // SUBZERO_SRC_ICEGLOBALINITS_H | 469 #endif // SUBZERO_SRC_ICEGLOBALINITS_H |
| OLD | NEW |