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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 /// that relocations across pnacl-sz and pnacl-llc will work). | 95 /// that relocations across pnacl-sz and pnacl-llc will work). |
96 virtual IceString mangleName(GlobalContext *Ctx) const { | 96 virtual IceString mangleName(GlobalContext *Ctx) const { |
97 return getSuppressMangling() ? Name : Ctx->mangleName(Name); | 97 return getSuppressMangling() ? Name : Ctx->mangleName(Name); |
98 } | 98 } |
99 | 99 |
100 /// Returns textual name of linkage. | 100 /// Returns textual name of linkage. |
101 const char *getLinkageName() const { | 101 const char *getLinkageName() const { |
102 return isInternal() ? "internal" : "external"; | 102 return isInternal() ? "internal" : "external"; |
103 } | 103 } |
104 | 104 |
105 /// Returns true if the name of this GlobalDeclaration indicates that it | |
106 /// should have ExternalLinkage (as a special case). | |
107 virtual bool isPNaClABIExternalName() const = 0; | |
108 | |
105 protected: | 109 protected: |
106 GlobalDeclaration(GlobalDeclarationKind Kind, | 110 GlobalDeclaration(GlobalDeclarationKind Kind, |
107 llvm::GlobalValue::LinkageTypes Linkage) | 111 llvm::GlobalValue::LinkageTypes Linkage) |
108 : Kind(Kind), Linkage(Linkage) {} | 112 : Kind(Kind), Linkage(Linkage) {} |
109 | 113 |
110 /// Returns true if linkage is defined correctly for the global declaration, | 114 /// Returns true if linkage is defined correctly for the global declaration, |
111 /// based on default rules. | 115 /// based on default rules. |
112 bool verifyLinkageDefault(const GlobalContext *Ctx) const { | 116 bool verifyLinkageDefault(const GlobalContext *Ctx) const { |
113 switch (Linkage) { | 117 switch (Linkage) { |
114 default: | 118 default: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 bool isProto() const { return IsProto; } | 151 bool isProto() const { return IsProto; } |
148 static bool classof(const GlobalDeclaration *Addr) { | 152 static bool classof(const GlobalDeclaration *Addr) { |
149 return Addr->getKind() == FunctionDeclarationKind; | 153 return Addr->getKind() == FunctionDeclarationKind; |
150 } | 154 } |
151 void dumpType(Ostream &Stream) const final; | 155 void dumpType(Ostream &Stream) const final; |
152 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 156 void dump(GlobalContext *Ctx, Ostream &Stream) const final; |
153 bool getSuppressMangling() const final { return isExternal() && IsProto; } | 157 bool getSuppressMangling() const final { return isExternal() && IsProto; } |
154 | 158 |
155 /// Returns true if linkage is correct for the function declaration. | 159 /// Returns true if linkage is correct for the function declaration. |
156 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { | 160 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { |
157 if (isPNaClABIExternalName() || isIntrinsicName(Ctx)) | 161 if (isIntrinsicName(Ctx)) |
158 return Linkage == llvm::GlobalValue::ExternalLinkage; | 162 return Linkage == llvm::GlobalValue::ExternalLinkage; |
159 return verifyLinkageDefault(Ctx); | 163 else if (Linkage == llvm::GlobalValue::ExternalLinkage) |
164 return isPNaClABIExternalName(); | |
165 else | |
166 return verifyLinkageDefault(Ctx); | |
160 } | 167 } |
161 | 168 |
162 /// Validates that the type signature of the function is correct. Returns true | 169 /// Validates that the type signature of the function is correct. Returns true |
163 /// if valid. | 170 /// if valid. |
164 bool validateTypeSignature(const GlobalContext *Ctx) const { | 171 bool validateTypeSignature(const GlobalContext *Ctx) const { |
165 bool IsIntrinsic; | 172 bool IsIntrinsic; |
166 if (const Intrinsics::FullIntrinsicInfo *Info = | 173 if (const Intrinsics::FullIntrinsicInfo *Info = |
167 getIntrinsicInfo(Ctx, &IsIntrinsic)) | 174 getIntrinsicInfo(Ctx, &IsIntrinsic)) |
168 return validateIntrinsicTypeSignature(Info); | 175 return validateIntrinsicTypeSignature(Info); |
169 return !IsIntrinsic && validateRegularTypeSignature(); | 176 return !IsIntrinsic && validateRegularTypeSignature(); |
(...skipping 19 matching lines...) Expand all Loading... | |
189 const Ice::FuncSigType Signature; | 196 const Ice::FuncSigType Signature; |
190 llvm::CallingConv::ID CallingConv; | 197 llvm::CallingConv::ID CallingConv; |
191 bool IsProto; | 198 bool IsProto; |
192 | 199 |
193 FunctionDeclaration(const FuncSigType &Signature, | 200 FunctionDeclaration(const FuncSigType &Signature, |
194 llvm::CallingConv::ID CallingConv, | 201 llvm::CallingConv::ID CallingConv, |
195 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto) | 202 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto) |
196 : GlobalDeclaration(FunctionDeclarationKind, Linkage), | 203 : GlobalDeclaration(FunctionDeclarationKind, Linkage), |
197 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {} | 204 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {} |
198 | 205 |
199 bool isPNaClABIExternalName() const { | 206 bool isPNaClABIExternalName() const override { |
200 const char *Name = getName().c_str(); | 207 static constexpr char Start[] = "_start"; |
John
2016/02/26 19:48:37
thanks! :)
| |
201 return strcmp(Name, "_start") == 0 || strcmp(Name, "__pnacl_pso_root") == 0; | 208 return getName() == Start; |
202 } | 209 } |
203 | 210 |
204 bool isIntrinsicName(const GlobalContext *Ctx) const { | 211 bool isIntrinsicName(const GlobalContext *Ctx) const { |
205 bool IsIntrinsic; | 212 bool IsIntrinsic; |
206 getIntrinsicInfo(Ctx, &IsIntrinsic); | 213 getIntrinsicInfo(Ctx, &IsIntrinsic); |
207 return IsIntrinsic; | 214 return IsIntrinsic; |
208 } | 215 } |
209 | 216 |
210 bool validateRegularTypeSignature() const; | 217 bool validateRegularTypeSignature() const; |
211 | 218 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 | 416 |
410 /// Prints out type for initializer associated with the declaration to Stream. | 417 /// Prints out type for initializer associated with the declaration to Stream. |
411 void dumpType(Ostream &Stream) const final; | 418 void dumpType(Ostream &Stream) const final; |
412 | 419 |
413 /// Prints out the definition of the global variable declaration (including | 420 /// Prints out the definition of the global variable declaration (including |
414 /// initialization). | 421 /// initialization). |
415 void dump(GlobalContext *Ctx, Ostream &Stream) const final; | 422 void dump(GlobalContext *Ctx, Ostream &Stream) const final; |
416 | 423 |
417 /// Returns true if linkage is correct for the variable declaration. | 424 /// Returns true if linkage is correct for the variable declaration. |
418 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { | 425 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { |
426 if (isPNaClABIExternalName()) { | |
427 return Linkage == llvm::GlobalValue::ExternalLinkage; | |
428 } | |
419 return verifyLinkageDefault(Ctx); | 429 return verifyLinkageDefault(Ctx); |
420 } | 430 } |
421 | 431 |
422 static bool classof(const GlobalDeclaration *Addr) { | 432 static bool classof(const GlobalDeclaration *Addr) { |
423 return Addr->getKind() == VariableDeclarationKind; | 433 return Addr->getKind() == VariableDeclarationKind; |
424 } | 434 } |
425 | 435 |
426 bool getSuppressMangling() const final { | 436 bool getSuppressMangling() const final { |
427 if (ForceSuppressMangling) | 437 if (ForceSuppressMangling) |
428 return true; | 438 return true; |
429 return isExternal() && !hasInitializer(); | 439 return isExternal() && !hasInitializer(); |
430 } | 440 } |
431 | 441 |
432 void setSuppressMangling() { ForceSuppressMangling = true; } | 442 void setSuppressMangling() { ForceSuppressMangling = true; } |
433 | 443 |
434 void discardInitializers() { Initializers = nullptr; } | 444 void discardInitializers() { Initializers = nullptr; } |
435 | 445 |
446 bool isPNaClABIExternalName() const override { | |
447 static constexpr char PnaclPsoRoot[] = "__pnacl_pso_root"; | |
448 return getName() == PnaclPsoRoot; | |
449 } | |
450 | |
436 private: | 451 private: |
437 /// List of initializers for the declared variable. | 452 /// List of initializers for the declared variable. |
438 std::unique_ptr<InitializerListType> Initializers; | 453 std::unique_ptr<InitializerListType> Initializers; |
439 bool HasInitializer; | 454 bool HasInitializer; |
440 /// The alignment of the declared variable. | 455 /// The alignment of the declared variable. |
441 uint32_t Alignment; | 456 uint32_t Alignment; |
442 /// True if a declared (global) constant. | 457 /// True if a declared (global) constant. |
443 bool IsConstant; | 458 bool IsConstant; |
444 /// If set to true, force getSuppressMangling() to return true. | 459 /// If set to true, force getSuppressMangling() to return true. |
445 bool ForceSuppressMangling; | 460 bool ForceSuppressMangling; |
(...skipping 15 matching lines...) Expand all Loading... | |
461 template <class StreamType> | 476 template <class StreamType> |
462 inline StreamType &operator<<(StreamType &Stream, | 477 inline StreamType &operator<<(StreamType &Stream, |
463 const GlobalDeclaration &Addr) { | 478 const GlobalDeclaration &Addr) { |
464 Addr.dump(Stream); | 479 Addr.dump(Stream); |
465 return Stream; | 480 return Stream; |
466 } | 481 } |
467 | 482 |
468 } // end of namespace Ice | 483 } // end of namespace Ice |
469 | 484 |
470 #endif // SUBZERO_SRC_ICEGLOBALINITS_H | 485 #endif // SUBZERO_SRC_ICEGLOBALINITS_H |
OLD | NEW |