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

Side by Side Diff: src/IceGlobalInits.h

Issue 1838753002: Subzero: Remove IceString. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Cleanup Created 4 years, 8 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/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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 GlobalDeclaration(const GlobalDeclaration &) = delete; 54 GlobalDeclaration(const GlobalDeclaration &) = delete;
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 GlobalString getName() const { return Name; }
65 void setName(const IceString &NewName) { 65 void setName(GlobalContext *Ctx, const std::string &NewName) {
66 Name = getSuppressMangling() ? NewName : mangleName(NewName); 66 Name = Ctx->getGlobalString(getSuppressMangling() ? NewName
67 : mangleName(NewName));
67 } 68 }
68 bool hasName() const { return !Name.empty(); } 69 void setName(GlobalString NewName) { Name = NewName; }
70 void setName(GlobalContext *Ctx) { Name = GlobalString(Ctx); }
71 bool hasName() const { return Name.hasString(); }
69 bool isInternal() const { 72 bool isInternal() const {
70 return Linkage == llvm::GlobalValue::InternalLinkage; 73 return Linkage == llvm::GlobalValue::InternalLinkage;
71 } 74 }
72 llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; } 75 llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; }
73 void setLinkage(llvm::GlobalValue::LinkageTypes L) { 76 void setLinkage(llvm::GlobalValue::LinkageTypes L) {
74 assert(!hasName()); 77 assert(!hasName());
75 Linkage = L; 78 Linkage = L;
76 } 79 }
77 bool isExternal() const { 80 bool isExternal() const {
78 return Linkage == llvm::GlobalValue::ExternalLinkage; 81 return Linkage == llvm::GlobalValue::ExternalLinkage;
79 } 82 }
80 virtual ~GlobalDeclaration() = default; 83 virtual ~GlobalDeclaration() = default;
81 84
82 /// Prints out type of the global declaration. 85 /// Prints out type of the global declaration.
83 virtual void dumpType(Ostream &Stream) const = 0; 86 virtual void dumpType(Ostream &Stream) const = 0;
84 87
85 /// Prints out the global declaration. 88 /// Prints out the global declaration.
86 virtual void dump(Ostream &Stream) const = 0; 89 virtual void dump(Ostream &Stream) const = 0;
87 90
88 /// Returns true if when emitting names, we should suppress mangling. 91 /// Returns true if when emitting names, we should suppress mangling.
89 virtual bool getSuppressMangling() const = 0; 92 virtual bool getSuppressMangling() const = 0;
90 93
91 /// Returns textual name of linkage. 94 /// Returns textual name of linkage.
92 const char *getLinkageName() const { 95 const char *getLinkageName() const {
93 return isInternal() ? "internal" : "external"; 96 return isInternal() ? "internal" : "external";
94 } 97 }
95 98
96 /// Returns true if the name of this GlobalDeclaration indicates that it 99 /// Returns true if the name of this GlobalDeclaration indicates that it
97 /// should have ExternalLinkage (as a special case). 100 /// should have ExternalLinkage (as a special case).
98 virtual bool isPNaClABIExternalName(const IceString &Name) const = 0; 101 virtual bool isPNaClABIExternalName(const std::string &Name) const = 0;
99 102
100 protected: 103 protected:
101 GlobalDeclaration(GlobalDeclarationKind Kind, 104 GlobalDeclaration(GlobalDeclarationKind Kind,
102 llvm::GlobalValue::LinkageTypes Linkage) 105 llvm::GlobalValue::LinkageTypes Linkage)
103 : Kind(Kind), Linkage(Linkage) {} 106 : Kind(Kind), Linkage(Linkage) {}
104 107
105 /// Returns true if linkage is defined correctly for the global declaration, 108 /// Returns true if linkage is defined correctly for the global declaration,
106 /// based on default rules. 109 /// based on default rules.
107 bool verifyLinkageDefault(const GlobalContext *Ctx) const { 110 bool verifyLinkageDefault(const GlobalContext *Ctx) const {
108 switch (Linkage) { 111 switch (Linkage) {
109 default: 112 default:
110 return false; 113 return false;
111 case llvm::GlobalValue::InternalLinkage: 114 case llvm::GlobalValue::InternalLinkage:
112 return true; 115 return true;
113 case llvm::GlobalValue::ExternalLinkage: 116 case llvm::GlobalValue::ExternalLinkage:
114 return Ctx->getFlags().getAllowExternDefinedSymbols(); 117 return Ctx->getFlags().getAllowExternDefinedSymbols();
115 } 118 }
116 } 119 }
117 120
118 const GlobalDeclarationKind Kind; 121 const GlobalDeclarationKind Kind;
119 llvm::GlobalValue::LinkageTypes Linkage; 122 llvm::GlobalValue::LinkageTypes Linkage;
120 IceString Name; 123 GlobalString Name;
121 }; 124 };
122 125
123 /// Models a function declaration. This includes the type signature of the 126 /// Models a function declaration. This includes the type signature of the
124 /// function, its calling conventions, and its linkage. 127 /// function, its calling conventions, and its linkage.
125 class FunctionDeclaration : public GlobalDeclaration { 128 class FunctionDeclaration : public GlobalDeclaration {
126 FunctionDeclaration() = delete; 129 FunctionDeclaration() = delete;
127 FunctionDeclaration(const FunctionDeclaration &) = delete; 130 FunctionDeclaration(const FunctionDeclaration &) = delete;
128 FunctionDeclaration &operator=(const FunctionDeclaration &) = delete; 131 FunctionDeclaration &operator=(const FunctionDeclaration &) = delete;
129 132
130 public: 133 public:
(...skipping 11 matching lines...) Expand all
142 bool isProto() const { return IsProto; } 145 bool isProto() const { return IsProto; }
143 static bool classof(const GlobalDeclaration *Addr) { 146 static bool classof(const GlobalDeclaration *Addr) {
144 return Addr->getKind() == FunctionDeclarationKind; 147 return Addr->getKind() == FunctionDeclarationKind;
145 } 148 }
146 void dumpType(Ostream &Stream) const final; 149 void dumpType(Ostream &Stream) const final;
147 void dump(Ostream &Stream) const final; 150 void dump(Ostream &Stream) const final;
148 bool getSuppressMangling() const final { return isExternal() && IsProto; } 151 bool getSuppressMangling() const final { return isExternal() && IsProto; }
149 152
150 /// Returns true if linkage is correct for the function declaration. 153 /// Returns true if linkage is correct for the function declaration.
151 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { 154 bool verifyLinkageCorrect(const GlobalContext *Ctx) const {
152 if (isPNaClABIExternalName(getName()) || isIntrinsicName(Ctx)) { 155 if (getName().hasString()) {
153 return Linkage == llvm::GlobalValue::ExternalLinkage; 156 if (isPNaClABIExternalName(getName().toString()) ||
154 } else { 157 isIntrinsicName(Ctx)) {
155 return verifyLinkageDefault(Ctx); 158 return Linkage == llvm::GlobalValue::ExternalLinkage;
159 }
156 } 160 }
161 return verifyLinkageDefault(Ctx);
157 } 162 }
158 163
159 /// Validates that the type signature of the function is correct. Returns true 164 /// Validates that the type signature of the function is correct. Returns true
160 /// if valid. 165 /// if valid.
161 bool validateTypeSignature(const GlobalContext *Ctx) const { 166 bool validateTypeSignature(const GlobalContext *Ctx) const {
162 bool IsIntrinsic; 167 bool IsIntrinsic;
163 if (const Intrinsics::FullIntrinsicInfo *Info = 168 if (const Intrinsics::FullIntrinsicInfo *Info =
164 getIntrinsicInfo(Ctx, &IsIntrinsic)) 169 getIntrinsicInfo(Ctx, &IsIntrinsic))
165 return validateIntrinsicTypeSignature(Info); 170 return validateIntrinsicTypeSignature(Info);
166 return !IsIntrinsic && validateRegularTypeSignature(); 171 return !IsIntrinsic && validateRegularTypeSignature();
167 } 172 }
168 173
169 /// Generates an error message describing why validateTypeSignature returns 174 /// Generates an error message describing why validateTypeSignature returns
170 /// false. 175 /// false.
171 IceString getTypeSignatureError(const GlobalContext *Ctx); 176 std::string getTypeSignatureError(const GlobalContext *Ctx);
172 177
173 /// Returns corresponding PNaCl intrisic information. 178 /// Returns corresponding PNaCl intrisic information.
174 const Intrinsics::FullIntrinsicInfo * 179 const Intrinsics::FullIntrinsicInfo *
175 getIntrinsicInfo(const GlobalContext *Ctx) const { 180 getIntrinsicInfo(const GlobalContext *Ctx) const {
176 bool BadIntrinsic; 181 bool BadIntrinsic;
177 return getIntrinsicInfo(Ctx, &BadIntrinsic); 182 return getIntrinsicInfo(Ctx, &BadIntrinsic);
178 } 183 }
179 184
180 /// Same as above, except IsIntrinsic is true if the function is intrinsic 185 /// Same as above, except IsIntrinsic is true if the function is intrinsic
181 /// (even if not a PNaCl intrinsic). 186 /// (even if not a PNaCl intrinsic).
182 const Intrinsics::FullIntrinsicInfo * 187 const Intrinsics::FullIntrinsicInfo *
183 getIntrinsicInfo(const GlobalContext *Ctx, bool *IsIntrinsic) const; 188 getIntrinsicInfo(const GlobalContext *Ctx, bool *IsIntrinsic) const;
184 189
185 private: 190 private:
186 const Ice::FuncSigType Signature; 191 const Ice::FuncSigType Signature;
187 llvm::CallingConv::ID CallingConv; 192 llvm::CallingConv::ID CallingConv;
188 const bool IsProto; 193 const bool IsProto;
189 194
190 FunctionDeclaration(const FuncSigType &Signature, 195 FunctionDeclaration(const FuncSigType &Signature,
191 llvm::CallingConv::ID CallingConv, 196 llvm::CallingConv::ID CallingConv,
192 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto) 197 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto)
193 : GlobalDeclaration(FunctionDeclarationKind, Linkage), 198 : GlobalDeclaration(FunctionDeclarationKind, Linkage),
194 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {} 199 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {}
195 200
196 bool isPNaClABIExternalName(const IceString &Name) const override { 201 bool isPNaClABIExternalName(const std::string &Name) const override {
197 return Name == "_start"; 202 return Name == "_start";
198 } 203 }
199 204
200 bool isIntrinsicName(const GlobalContext *Ctx) const { 205 bool isIntrinsicName(const GlobalContext *Ctx) const {
201 bool IsIntrinsic; 206 bool IsIntrinsic;
202 getIntrinsicInfo(Ctx, &IsIntrinsic); 207 getIntrinsicInfo(Ctx, &IsIntrinsic);
203 return IsIntrinsic; 208 return IsIntrinsic;
204 } 209 }
205 210
206 bool validateRegularTypeSignature() const; 211 bool validateRegularTypeSignature() const;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 void addInitializer(Initializer *Initializer) { 441 void addInitializer(Initializer *Initializer) {
437 const bool OldSuppressMangling = getSuppressMangling(); 442 const bool OldSuppressMangling = getSuppressMangling();
438 Initializers.emplace_back(Initializer); 443 Initializers.emplace_back(Initializer);
439 HasInitializer = true; 444 HasInitializer = true;
440 // The getSuppressMangling() logic depends on whether the global variable 445 // The getSuppressMangling() logic depends on whether the global variable
441 // has initializers. If its value changed as a result of adding an 446 // has initializers. If its value changed as a result of adding an
442 // initializer, then make sure we haven't previously set the name based on 447 // initializer, then make sure we haven't previously set the name based on
443 // faulty SuppressMangling logic. 448 // faulty SuppressMangling logic.
444 const bool SameMangling = (OldSuppressMangling == getSuppressMangling()); 449 const bool SameMangling = (OldSuppressMangling == getSuppressMangling());
445 (void)SameMangling; 450 (void)SameMangling;
446 assert(!Name.empty() || SameMangling); 451 assert(Name.hasString() || SameMangling);
447 } 452 }
448 453
449 /// Prints out type for initializer associated with the declaration to Stream. 454 /// Prints out type for initializer associated with the declaration to Stream.
450 void dumpType(Ostream &Stream) const final; 455 void dumpType(Ostream &Stream) const final;
451 456
452 /// Prints out the definition of the global variable declaration (including 457 /// Prints out the definition of the global variable declaration (including
453 /// initialization). 458 /// initialization).
454 virtual void dump(Ostream &Stream) const override; 459 virtual void dump(Ostream &Stream) const override;
455 460
456 /// Returns true if linkage is correct for the variable declaration. 461 /// Returns true if linkage is correct for the variable declaration.
457 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { 462 bool verifyLinkageCorrect(const GlobalContext *Ctx) const {
458 if (isPNaClABIExternalName(getName())) { 463 if (getName().hasString()) {
459 return Linkage == llvm::GlobalValue::ExternalLinkage; 464 if (isPNaClABIExternalName(getName().toString())) {
465 return Linkage == llvm::GlobalValue::ExternalLinkage;
466 }
460 } 467 }
461 return verifyLinkageDefault(Ctx); 468 return verifyLinkageDefault(Ctx);
462 } 469 }
463 470
464 static bool classof(const GlobalDeclaration *Addr) { 471 static bool classof(const GlobalDeclaration *Addr) {
465 return Addr->getKind() == VariableDeclarationKind; 472 return Addr->getKind() == VariableDeclarationKind;
466 } 473 }
467 474
468 bool getSuppressMangling() const final { 475 bool getSuppressMangling() const final {
469 if (ForceSuppressMangling) 476 if (ForceSuppressMangling)
470 return true; 477 return true;
471 return isExternal() && !hasInitializer(); 478 return isExternal() && !hasInitializer();
472 } 479 }
473 480
474 void discardInitializers() { Initializers.clear(); } 481 void discardInitializers() { Initializers.clear(); }
475 482
476 bool isPNaClABIExternalName(const IceString &Name) const override { 483 bool isPNaClABIExternalName(const std::string &Name) const override {
477 return Name == "__pnacl_pso_root"; 484 return Name == "__pnacl_pso_root";
478 } 485 }
479 486
480 private: 487 private:
481 /// List of initializers for the declared variable. 488 /// List of initializers for the declared variable.
482 InitializerListType Initializers; 489 InitializerListType Initializers;
483 bool HasInitializer = false; 490 bool HasInitializer = false;
484 /// The alignment of the declared variable. 491 /// The alignment of the declared variable.
485 uint32_t Alignment = 0; 492 uint32_t Alignment = 0;
486 /// True if a declared (global) constant. 493 /// True if a declared (global) constant.
(...skipping 17 matching lines...) Expand all
504 template <class StreamType> 511 template <class StreamType>
505 inline StreamType &operator<<(StreamType &Stream, 512 inline StreamType &operator<<(StreamType &Stream,
506 const GlobalDeclaration &Addr) { 513 const GlobalDeclaration &Addr) {
507 Addr.dump(Stream); 514 Addr.dump(Stream);
508 return Stream; 515 return Stream;
509 } 516 }
510 517
511 } // end of namespace Ice 518 } // end of namespace Ice
512 519
513 #endif // SUBZERO_SRC_ICEGLOBALINITS_H 520 #endif // SUBZERO_SRC_ICEGLOBALINITS_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698