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

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

Powered by Google App Engine
This is Rietveld 408576698