OLD | NEW |
---|---|
1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// | 1 //===- subzero/src/IceOperand.h - High-level operands -----------*- 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 |
11 /// \brief Declares the Operand class and its target-independent subclasses. | 11 /// \brief Declares the Operand class and its target-independent subclasses. |
12 /// | 12 /// |
13 /// The main classes are Variable, which represents an LLVM variable that is | 13 /// The main classes are Variable, which represents an LLVM variable that is |
14 /// either register- or stack-allocated, and the Constant hierarchy, which | 14 /// either register- or stack-allocated, and the Constant hierarchy, which |
15 /// represents integer, floating-point, and/or symbolic constants. | 15 /// represents integer, floating-point, and/or symbolic constants. |
16 /// | 16 /// |
17 //===----------------------------------------------------------------------===// | 17 //===----------------------------------------------------------------------===// |
18 | 18 |
19 #ifndef SUBZERO_SRC_ICEOPERAND_H | 19 #ifndef SUBZERO_SRC_ICEOPERAND_H |
20 #define SUBZERO_SRC_ICEOPERAND_H | 20 #define SUBZERO_SRC_ICEOPERAND_H |
21 | 21 |
22 #include "IceDefs.h" | 22 #include "IceDefs.h" |
23 #include "IceCfg.h" | 23 #include "IceCfg.h" |
24 #include "IceGlobalContext.h" | 24 #include "IceGlobalContext.h" |
25 #include "IceStringPool.h" | |
25 #include "IceTypes.h" | 26 #include "IceTypes.h" |
26 | 27 |
27 #include "llvm/Support/Format.h" | 28 #include "llvm/Support/Format.h" |
28 | 29 |
29 #include <limits> | 30 #include <limits> |
30 #include <type_traits> | 31 #include <type_traits> |
31 | 32 |
32 namespace Ice { | 33 namespace Ice { |
33 | 34 |
34 class Operand { | 35 class Operand { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 } | 115 } |
115 | 116 |
116 /// Constant is the abstract base class for constants. All constants are | 117 /// Constant is the abstract base class for constants. All constants are |
117 /// allocated from a global arena and are pooled. | 118 /// allocated from a global arena and are pooled. |
118 class Constant : public Operand { | 119 class Constant : public Operand { |
119 Constant() = delete; | 120 Constant() = delete; |
120 Constant(const Constant &) = delete; | 121 Constant(const Constant &) = delete; |
121 Constant &operator=(const Constant &) = delete; | 122 Constant &operator=(const Constant &) = delete; |
122 | 123 |
123 public: | 124 public: |
124 virtual void emitPoolLabel(Ostream &Str) const { | |
125 (void)Str; | |
126 llvm::report_fatal_error("emitPoolLabel not defined for type"); | |
127 }; | |
128 // Declare the lookup counter to take minimal space in a non-DUMP build. | 125 // Declare the lookup counter to take minimal space in a non-DUMP build. |
129 using CounterType = | 126 using CounterType = |
130 std::conditional<BuildDefs::dump(), uint64_t, uint8_t>::type; | 127 std::conditional<BuildDefs::dump(), uint64_t, uint8_t>::type; |
131 void emit(const Cfg *Func) const override { emit(Func->getTarget()); } | 128 void emit(const Cfg *Func) const override { emit(Func->getTarget()); } |
132 virtual void emit(TargetLowering *Target) const = 0; | 129 virtual void emit(TargetLowering *Target) const = 0; |
133 | 130 |
134 static bool classof(const Operand *Operand) { | 131 static bool classof(const Operand *Operand) { |
135 OperandKind Kind = Operand->getKind(); | 132 OperandKind Kind = Operand->getKind(); |
136 return Kind >= kConst_Base && Kind <= kConst_Max; | 133 return Kind >= kConst_Base && Kind <= kConst_Max; |
137 } | 134 } |
138 | 135 |
136 const GlobalString getLabelName() const { return LabelName; } | |
137 | |
139 /// Judge if this given immediate should be randomized or pooled By default | 138 /// Judge if this given immediate should be randomized or pooled By default |
140 /// should return false, only constant integers should truly go through this | 139 /// should return false, only constant integers should truly go through this |
141 /// method. | 140 /// method. |
142 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) { | 141 virtual bool shouldBeRandomizedOrPooled() const { return false; } |
143 (void)Ctx; | |
144 return false; | |
145 } | |
146 | 142 |
147 void setShouldBePooled(bool R) { ShouldBePooled = R; } | 143 void initShouldBePooled(); |
John
2016/03/29 14:23:16
maybe explain this?
should this be private?
Should
Jim Stichnoth
2016/03/29 21:40:49
Done.
| |
148 bool getShouldBePooled() const { return ShouldBePooled; } | 144 bool getShouldBePooled() const { return ShouldBePooled; } |
149 | 145 |
150 // This should be thread-safe because the constant pool lock is acquired | 146 // This should be thread-safe because the constant pool lock is acquired |
151 // before the method is invoked. | 147 // before the method is invoked. |
152 void updateLookupCount() { | 148 void updateLookupCount() { |
153 if (!BuildDefs::dump()) | 149 if (!BuildDefs::dump()) |
154 return; | 150 return; |
155 ++LookupCount; | 151 ++LookupCount; |
156 } | 152 } |
157 CounterType getLookupCount() const { return LookupCount; } | 153 CounterType getLookupCount() const { return LookupCount; } |
158 | 154 |
159 protected: | 155 protected: |
160 Constant(OperandKind Kind, Type Ty) : Operand(Kind, Ty) { | 156 Constant(OperandKind Kind, Type Ty) : Operand(Kind, Ty) { |
161 Vars = nullptr; | 157 Vars = nullptr; |
162 NumVars = 0; | 158 NumVars = 0; |
163 } | 159 } |
160 GlobalString LabelName; | |
164 /// Whether we should pool this constant. Usually Float/Double and pooled | 161 /// Whether we should pool this constant. Usually Float/Double and pooled |
165 /// Integers should be flagged true. | 162 /// Integers should be flagged true. Ideally this field would be const, but |
163 /// it needs to be initialized only after the subclass is fully constructed. | |
166 bool ShouldBePooled = false; | 164 bool ShouldBePooled = false; |
167 /// Note: If ShouldBePooled is ever removed from the base class, we will want | 165 /// Note: If ShouldBePooled is ever removed from the base class, we will want |
168 /// to completely disable LookupCount in a non-DUMP build to save space. | 166 /// to completely disable LookupCount in a non-DUMP build to save space. |
169 CounterType LookupCount = 0; | 167 CounterType LookupCount = 0; |
170 }; | 168 }; |
171 | 169 |
172 /// ConstantPrimitive<> wraps a primitive type. | 170 /// ConstantPrimitive<> wraps a primitive type. |
173 template <typename T, Operand::OperandKind K> | 171 template <typename T, Operand::OperandKind K> |
174 class ConstantPrimitive : public Constant { | 172 class ConstantPrimitive : public Constant { |
175 ConstantPrimitive() = delete; | 173 ConstantPrimitive() = delete; |
176 ConstantPrimitive(const ConstantPrimitive &) = delete; | 174 ConstantPrimitive(const ConstantPrimitive &) = delete; |
177 ConstantPrimitive &operator=(const ConstantPrimitive &) = delete; | 175 ConstantPrimitive &operator=(const ConstantPrimitive &) = delete; |
178 | 176 |
179 public: | 177 public: |
180 using PrimType = T; | 178 using PrimType = T; |
181 | 179 |
182 static ConstantPrimitive *create(GlobalContext *Ctx, Type Ty, | 180 static ConstantPrimitive *create(GlobalContext *Ctx, Type Ty, |
183 PrimType Value) { | 181 PrimType Value) { |
184 return new (Ctx->allocate<ConstantPrimitive>()) | 182 auto *Const = |
185 ConstantPrimitive(Ty, Value); | 183 new (Ctx->allocate<ConstantPrimitive>()) ConstantPrimitive(Ty, Value); |
184 Const->initShouldBePooled(); | |
185 if (Const->getShouldBePooled()) | |
186 Const->initName(Ctx); | |
187 return Const; | |
186 } | 188 } |
187 PrimType getValue() const { return Value; } | 189 PrimType getValue() const { return Value; } |
188 void emitPoolLabel(Ostream &Str) const final { | 190 using Constant::emit; |
191 void emit(TargetLowering *Target) const final; | |
192 using Constant::dump; | |
193 void dump(const Cfg *, Ostream &Str) const override { | |
194 if (BuildDefs::dump()) | |
195 Str << getValue(); | |
196 } | |
197 | |
198 static bool classof(const Operand *Operand) { | |
199 return Operand->getKind() == K; | |
200 } | |
201 | |
202 virtual bool shouldBeRandomizedOrPooled() const override { return false; } | |
203 | |
204 private: | |
205 ConstantPrimitive(Type Ty, PrimType Value) : Constant(K, Ty), Value(Value) {} | |
206 | |
207 void initName(GlobalContext *Ctx) { | |
208 std::string Buffer; | |
209 llvm::raw_string_ostream Str(Buffer); | |
189 Str << ".L$" << getType() << "$"; | 210 Str << ".L$" << getType() << "$"; |
190 // Print hex characters byte by byte, starting from the most significant | 211 // Print hex characters byte by byte, starting from the most significant |
191 // byte. NOTE: This ordering assumes Subzero runs on a little-endian | 212 // byte. NOTE: This ordering assumes Subzero runs on a little-endian |
192 // platform. That means the possibility of different label names depending | 213 // platform. That means the possibility of different label names depending |
193 // on the endian-ness of the platform where Subzero runs. | 214 // on the endian-ness of the platform where Subzero runs. |
194 for (unsigned i = 0; i < sizeof(Value); ++i) { | 215 for (unsigned i = 0; i < sizeof(Value); ++i) { |
195 constexpr unsigned HexWidthChars = 2; | 216 constexpr unsigned HexWidthChars = 2; |
196 unsigned Offset = sizeof(Value) - 1 - i; | 217 unsigned Offset = sizeof(Value) - 1 - i; |
197 Str << llvm::format_hex_no_prefix( | 218 Str << llvm::format_hex_no_prefix( |
198 *(Offset + (const unsigned char *)&Value), HexWidthChars); | 219 *(Offset + (const unsigned char *)&Value), HexWidthChars); |
199 } | 220 } |
200 // For a floating-point value in DecorateAsm mode, also append the value in | 221 // For a floating-point value in DecorateAsm mode, also append the value in |
201 // human-readable sprintf form, changing '+' to 'p' and '-' to 'm' to | 222 // human-readable sprintf form, changing '+' to 'p' and '-' to 'm' to |
202 // maintain valid asm labels. | 223 // maintain valid asm labels. |
203 if (std::is_floating_point<PrimType>::value && !BuildDefs::minimal() && | 224 if (std::is_floating_point<PrimType>::value && !BuildDefs::minimal() && |
204 GlobalContext::getFlags().getDecorateAsm()) { | 225 GlobalContext::getFlags().getDecorateAsm()) { |
205 char Buf[30]; | 226 char Buf[30]; |
206 snprintf(Buf, llvm::array_lengthof(Buf), "$%g", (double)Value); | 227 snprintf(Buf, llvm::array_lengthof(Buf), "$%g", (double)Value); |
207 for (unsigned i = 0; i < llvm::array_lengthof(Buf) && Buf[i]; ++i) { | 228 for (unsigned i = 0; i < llvm::array_lengthof(Buf) && Buf[i]; ++i) { |
208 if (Buf[i] == '-') | 229 if (Buf[i] == '-') |
209 Buf[i] = 'm'; | 230 Buf[i] = 'm'; |
210 else if (Buf[i] == '+') | 231 else if (Buf[i] == '+') |
211 Buf[i] = 'p'; | 232 Buf[i] = 'p'; |
212 } | 233 } |
213 Str << Buf; | 234 Str << Buf; |
214 } | 235 } |
215 } | 236 LabelName = GlobalString(Ctx, Str.str()); |
216 using Constant::emit; | |
217 void emit(TargetLowering *Target) const final; | |
218 using Constant::dump; | |
219 void dump(const Cfg *, Ostream &Str) const override { | |
220 if (BuildDefs::dump()) | |
221 Str << getValue(); | |
222 } | 237 } |
223 | 238 |
224 static bool classof(const Operand *Operand) { | |
225 return Operand->getKind() == K; | |
226 } | |
227 | |
228 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) override { | |
229 (void)Ctx; | |
230 return false; | |
231 } | |
232 | |
233 private: | |
234 ConstantPrimitive(Type Ty, PrimType Value) : Constant(K, Ty), Value(Value) {} | |
235 const PrimType Value; | 239 const PrimType Value; |
236 }; | 240 }; |
237 | 241 |
238 using ConstantInteger32 = ConstantPrimitive<int32_t, Operand::kConstInteger32>; | 242 using ConstantInteger32 = ConstantPrimitive<int32_t, Operand::kConstInteger32>; |
239 using ConstantInteger64 = ConstantPrimitive<int64_t, Operand::kConstInteger64>; | 243 using ConstantInteger64 = ConstantPrimitive<int64_t, Operand::kConstInteger64>; |
240 using ConstantFloat = ConstantPrimitive<float, Operand::kConstFloat>; | 244 using ConstantFloat = ConstantPrimitive<float, Operand::kConstFloat>; |
241 using ConstantDouble = ConstantPrimitive<double, Operand::kConstDouble>; | 245 using ConstantDouble = ConstantPrimitive<double, Operand::kConstDouble>; |
242 | 246 |
243 template <> | 247 template <> |
244 inline void ConstantInteger32::dump(const Cfg *, Ostream &Str) const { | 248 inline void ConstantInteger32::dump(const Cfg *, Ostream &Str) const { |
245 if (!BuildDefs::dump()) | 249 if (!BuildDefs::dump()) |
246 return; | 250 return; |
247 if (getType() == IceType_i1) | 251 if (getType() == IceType_i1) |
248 Str << (getValue() ? "true" : "false"); | 252 Str << (getValue() ? "true" : "false"); |
249 else | 253 else |
250 Str << static_cast<int32_t>(getValue()); | 254 Str << static_cast<int32_t>(getValue()); |
251 } | 255 } |
252 | 256 |
253 /// Specialization of the template member function for ConstantInteger32 | 257 /// Specialization of the template member function for ConstantInteger32 |
254 template <> | 258 template <> bool ConstantInteger32::shouldBeRandomizedOrPooled() const; |
255 bool ConstantInteger32::shouldBeRandomizedOrPooled(const GlobalContext *Ctx); | |
256 | 259 |
257 template <> | 260 template <> |
258 inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const { | 261 inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const { |
259 if (!BuildDefs::dump()) | 262 if (!BuildDefs::dump()) |
260 return; | 263 return; |
261 assert(getType() == IceType_i64); | 264 assert(getType() == IceType_i64); |
262 Str << static_cast<int64_t>(getValue()); | 265 Str << static_cast<int64_t>(getValue()); |
263 } | 266 } |
264 | 267 |
265 /// RelocOffset allows symbolic references in ConstantRelocatables' offsets, | 268 /// RelocOffset allows symbolic references in ConstantRelocatables' offsets, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 | 311 |
309 /// RelocatableTuple bundles the parameters that are used to construct an | 312 /// RelocatableTuple bundles the parameters that are used to construct an |
310 /// ConstantRelocatable. It is done this way so that ConstantRelocatable can fit | 313 /// ConstantRelocatable. It is done this way so that ConstantRelocatable can fit |
311 /// into the global constant pool template mechanism. | 314 /// into the global constant pool template mechanism. |
312 class RelocatableTuple { | 315 class RelocatableTuple { |
313 RelocatableTuple() = delete; | 316 RelocatableTuple() = delete; |
314 RelocatableTuple &operator=(const RelocatableTuple &) = delete; | 317 RelocatableTuple &operator=(const RelocatableTuple &) = delete; |
315 | 318 |
316 public: | 319 public: |
317 RelocatableTuple(const RelocOffsetT Offset, | 320 RelocatableTuple(const RelocOffsetT Offset, |
318 const RelocOffsetArray &OffsetExpr, const IceString &Name) | 321 const RelocOffsetArray &OffsetExpr, GlobalString Name) |
319 : Offset(Offset), OffsetExpr(OffsetExpr), Name(Name) {} | 322 : Offset(Offset), OffsetExpr(OffsetExpr), Name(Name) {} |
320 | 323 |
321 RelocatableTuple(const RelocOffsetT Offset, | 324 RelocatableTuple(const RelocOffsetT Offset, |
322 const RelocOffsetArray &OffsetExpr, const IceString &Name, | 325 const RelocOffsetArray &OffsetExpr, GlobalString Name, |
323 const IceString &EmitString) | 326 const std::string &EmitString) |
324 : Offset(Offset), OffsetExpr(OffsetExpr), Name(Name), | 327 : Offset(Offset), OffsetExpr(OffsetExpr), Name(Name), |
325 EmitString(EmitString) {} | 328 EmitString(EmitString) {} |
326 | 329 |
327 RelocatableTuple(const RelocatableTuple &) = default; | 330 RelocatableTuple(const RelocatableTuple &) = default; |
328 | 331 |
329 const RelocOffsetT Offset; | 332 const RelocOffsetT Offset; |
330 const RelocOffsetArray OffsetExpr; | 333 const RelocOffsetArray OffsetExpr; |
331 const IceString Name; | 334 const GlobalString Name; |
332 const IceString EmitString; | 335 const std::string EmitString; |
333 }; | 336 }; |
334 | 337 |
335 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B); | 338 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B); |
336 | 339 |
337 /// ConstantRelocatable represents a symbolic constant combined with a fixed | 340 /// ConstantRelocatable represents a symbolic constant combined with a fixed |
338 /// offset. | 341 /// offset. |
339 class ConstantRelocatable : public Constant { | 342 class ConstantRelocatable : public Constant { |
340 ConstantRelocatable() = delete; | 343 ConstantRelocatable() = delete; |
341 ConstantRelocatable(const ConstantRelocatable &) = delete; | 344 ConstantRelocatable(const ConstantRelocatable &) = delete; |
342 ConstantRelocatable &operator=(const ConstantRelocatable &) = delete; | 345 ConstantRelocatable &operator=(const ConstantRelocatable &) = delete; |
343 | 346 |
344 public: | 347 public: |
345 template <typename T> | 348 template <typename T> |
346 static ConstantRelocatable *create(T *AllocOwner, Type Ty, | 349 static ConstantRelocatable *create(T *AllocOwner, Type Ty, |
347 const RelocatableTuple &Tuple) { | 350 const RelocatableTuple &Tuple) { |
348 return new (AllocOwner->template allocate<ConstantRelocatable>()) | 351 return new (AllocOwner->template allocate<ConstantRelocatable>()) |
349 ConstantRelocatable(Ty, Tuple.Offset, Tuple.OffsetExpr, Tuple.Name, | 352 ConstantRelocatable(Ty, Tuple.Offset, Tuple.OffsetExpr, Tuple.Name, |
350 Tuple.EmitString); | 353 Tuple.EmitString); |
351 } | 354 } |
355 #if 0 | |
John
2016/03/29 14:23:16
remove if 0
Jim Stichnoth
2016/03/29 21:40:49
Done.
| |
356 static ConstantRelocatable *create(GlobalContext *Ctx, Type Ty, | |
357 const RelocatableTuple &Tuple) { | |
358 return create(Ctx, Ty, Tuple); | |
359 } | |
360 #endif | |
352 | 361 |
353 RelocOffsetT getOffset() const { | 362 RelocOffsetT getOffset() const { |
354 RelocOffsetT Ret = Offset; | 363 RelocOffsetT Ret = Offset; |
355 for (const auto *const OffsetReloc : OffsetExpr) { | 364 for (const auto *const OffsetReloc : OffsetExpr) { |
356 Ret += OffsetReloc->getOffset(); | 365 Ret += OffsetReloc->getOffset(); |
357 } | 366 } |
358 return Ret; | 367 return Ret; |
359 } | 368 } |
360 | 369 |
361 const IceString &getEmitString() const { return EmitString; } | 370 const std::string &getEmitString() const { return EmitString; } |
362 | 371 |
363 const IceString &getName() const { return Name; } | 372 GlobalString getName() const { return Name; } |
364 using Constant::emit; | 373 using Constant::emit; |
365 void emit(TargetLowering *Target) const final; | 374 void emit(TargetLowering *Target) const final; |
366 void emitWithoutPrefix(const TargetLowering *Target, | 375 void emitWithoutPrefix(const TargetLowering *Target, |
367 const char *Suffix = "") const; | 376 const char *Suffix = "") const; |
368 using Constant::dump; | 377 using Constant::dump; |
369 void dump(const Cfg *Func, Ostream &Str) const override; | 378 void dump(const Cfg *Func, Ostream &Str) const override; |
370 | 379 |
371 static bool classof(const Operand *Operand) { | 380 static bool classof(const Operand *Operand) { |
372 OperandKind Kind = Operand->getKind(); | 381 OperandKind Kind = Operand->getKind(); |
373 return Kind == kConstRelocatable; | 382 return Kind == kConstRelocatable; |
374 } | 383 } |
375 | 384 |
376 private: | 385 private: |
377 ConstantRelocatable(Type Ty, const RelocOffsetT Offset, | 386 ConstantRelocatable(Type Ty, const RelocOffsetT Offset, |
378 const RelocOffsetArray &OffsetExpr, const IceString &Name, | 387 const RelocOffsetArray &OffsetExpr, GlobalString Name, |
379 const IceString &EmitString) | 388 const std::string &EmitString) |
380 : Constant(kConstRelocatable, Ty), Offset(Offset), OffsetExpr(OffsetExpr), | 389 : Constant(kConstRelocatable, Ty), Offset(Offset), OffsetExpr(OffsetExpr), |
381 Name(Name), EmitString(EmitString) {} | 390 Name(Name), EmitString(EmitString) {} |
382 | 391 |
383 const RelocOffsetT Offset; /// fixed, known offset to add | 392 const RelocOffsetT Offset; /// fixed, known offset to add |
384 const RelocOffsetArray OffsetExpr; /// fixed, unknown offset to add | 393 const RelocOffsetArray OffsetExpr; /// fixed, unknown offset to add |
385 const IceString Name; /// optional for debug/dump | 394 const GlobalString Name; /// optional for debug/dump |
386 const IceString EmitString; /// optional for textual emission | 395 const std::string EmitString; /// optional for textual emission |
387 }; | 396 }; |
388 | 397 |
389 /// ConstantUndef represents an unspecified bit pattern. Although it is legal to | 398 /// ConstantUndef represents an unspecified bit pattern. Although it is legal to |
390 /// lower ConstantUndef to any value, backends should try to make code | 399 /// lower ConstantUndef to any value, backends should try to make code |
391 /// generation deterministic by lowering ConstantUndefs to 0. | 400 /// generation deterministic by lowering ConstantUndefs to 0. |
392 class ConstantUndef : public Constant { | 401 class ConstantUndef : public Constant { |
393 ConstantUndef() = delete; | 402 ConstantUndef() = delete; |
394 ConstantUndef(const ConstantUndef &) = delete; | 403 ConstantUndef(const ConstantUndef &) = delete; |
395 ConstantUndef &operator=(const ConstantUndef &) = delete; | 404 ConstantUndef &operator=(const ConstantUndef &) = delete; |
396 | 405 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 Variable &operator=(const Variable &) = delete; | 639 Variable &operator=(const Variable &) = delete; |
631 | 640 |
632 enum RegRequirement : uint8_t { | 641 enum RegRequirement : uint8_t { |
633 RR_MayHaveRegister, | 642 RR_MayHaveRegister, |
634 RR_MustHaveRegister, | 643 RR_MustHaveRegister, |
635 RR_MustNotHaveRegister, | 644 RR_MustNotHaveRegister, |
636 }; | 645 }; |
637 | 646 |
638 public: | 647 public: |
639 static Variable *create(Cfg *Func, Type Ty, SizeT Index) { | 648 static Variable *create(Cfg *Func, Type Ty, SizeT Index) { |
640 return new (Func->allocate<Variable>()) Variable(kVariable, Ty, Index); | 649 return new (Func->allocate<Variable>()) |
650 Variable(Func, kVariable, Ty, Index); | |
641 } | 651 } |
642 | 652 |
643 SizeT getIndex() const { return Number; } | 653 SizeT getIndex() const { return Number; } |
644 IceString getName(const Cfg *Func) const; | 654 std::string getName(const Cfg *Func) const; |
645 virtual void setName(Cfg *Func, const IceString &NewName) { | 655 virtual void setName(const Cfg *Func, const std::string &NewName) { |
646 // Make sure that the name can only be set once. | 656 (void)Func; |
647 assert(NameIndex == Cfg::IdentifierIndexInvalid); | 657 if (NewName.empty()) |
648 if (!NewName.empty()) | 658 return; |
649 NameIndex = Func->addIdentifierName(NewName); | 659 Name = VariableString(Func, NewName); |
650 } | 660 } |
651 | 661 |
652 bool getIsArg() const { return IsArgument; } | 662 bool getIsArg() const { return IsArgument; } |
653 virtual void setIsArg(bool Val = true) { IsArgument = Val; } | 663 virtual void setIsArg(bool Val = true) { IsArgument = Val; } |
654 bool getIsImplicitArg() const { return IsImplicitArgument; } | 664 bool getIsImplicitArg() const { return IsImplicitArgument; } |
655 void setIsImplicitArg(bool Val = true) { IsImplicitArgument = Val; } | 665 void setIsImplicitArg(bool Val = true) { IsImplicitArgument = Val; } |
656 | 666 |
657 void setIgnoreLiveness() { IgnoreLiveness = true; } | 667 void setIgnoreLiveness() { IgnoreLiveness = true; } |
658 bool getIgnoreLiveness() const { return IgnoreLiveness; } | 668 bool getIgnoreLiveness() const { return IgnoreLiveness; } |
659 | 669 |
660 int32_t getStackOffset() const { return StackOffset; } | 670 int32_t getStackOffset() const { return StackOffset; } |
661 void setStackOffset(int32_t Offset) { StackOffset = Offset; } | 671 void setStackOffset(int32_t Offset) { StackOffset = Offset; } |
662 /// Returns the variable's stack offset in symbolic form, to improve | 672 /// Returns the variable's stack offset in symbolic form, to improve |
663 /// readability in DecorateAsm mode. | 673 /// readability in DecorateAsm mode. |
664 IceString getSymbolicStackOffset(const Cfg *Func) const { | 674 std::string getSymbolicStackOffset(const Cfg *Func) const { |
665 if (!BuildDefs::dump()) | 675 if (!BuildDefs::dump()) |
666 return ""; | 676 return ""; |
667 return "lv$" + getName(Func); | 677 return "lv$" + getName(Func); |
668 } | 678 } |
669 | 679 |
670 bool hasReg() const { return getRegNum().hasValue(); } | 680 bool hasReg() const { return getRegNum().hasValue(); } |
671 RegNumT getRegNum() const { return RegNum; } | 681 RegNumT getRegNum() const { return RegNum; } |
672 void setRegNum(RegNumT NewRegNum) { | 682 void setRegNum(RegNumT NewRegNum) { |
673 // Regnum shouldn't be set more than once. | 683 // Regnum shouldn't be set more than once. |
674 assert(!hasReg() || RegNum == NewRegNum); | 684 assert(!hasReg() || RegNum == NewRegNum); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 constexpr bool UseTrimmed = true; | 728 constexpr bool UseTrimmed = true; |
719 return Live.overlapsInst(Other->Live.getStart(), UseTrimmed); | 729 return Live.overlapsInst(Other->Live.getStart(), UseTrimmed); |
720 } | 730 } |
721 | 731 |
722 /// Creates a temporary copy of the variable with a different type. Used | 732 /// Creates a temporary copy of the variable with a different type. Used |
723 /// primarily for syntactic correctness of textual assembly emission. Note | 733 /// primarily for syntactic correctness of textual assembly emission. Note |
724 /// that only basic information is copied, in particular not IsArgument, | 734 /// that only basic information is copied, in particular not IsArgument, |
725 /// IsImplicitArgument, IgnoreLiveness, RegNumTmp, Live, LoVar, HiVar, | 735 /// IsImplicitArgument, IgnoreLiveness, RegNumTmp, Live, LoVar, HiVar, |
726 /// VarsReal. If NewRegNum.hasValue(), then that register assignment is made | 736 /// VarsReal. If NewRegNum.hasValue(), then that register assignment is made |
727 /// instead of copying the existing assignment. | 737 /// instead of copying the existing assignment. |
728 const Variable *asType(Type Ty, RegNumT NewRegNum) const; | 738 const Variable *asType(const Cfg *Func, Type Ty, RegNumT NewRegNum) const; |
729 | 739 |
730 void emit(const Cfg *Func) const override; | 740 void emit(const Cfg *Func) const override; |
731 using Operand::dump; | 741 using Operand::dump; |
732 void dump(const Cfg *Func, Ostream &Str) const override; | 742 void dump(const Cfg *Func, Ostream &Str) const override; |
733 | 743 |
734 /// Return reg num of base register, if different from stack/frame register. | 744 /// Return reg num of base register, if different from stack/frame register. |
735 virtual RegNumT getBaseRegNum() const { return RegNumT(); } | 745 virtual RegNumT getBaseRegNum() const { return RegNumT(); } |
736 | 746 |
737 static bool classof(const Operand *Operand) { | 747 static bool classof(const Operand *Operand) { |
738 OperandKind Kind = Operand->getKind(); | 748 OperandKind Kind = Operand->getKind(); |
739 return Kind >= kVariable && Kind <= kVariable_Max; | 749 return Kind >= kVariable && Kind <= kVariable_Max; |
740 } | 750 } |
741 | 751 |
742 protected: | 752 protected: |
743 Variable(OperandKind K, Type Ty, SizeT Index) | 753 Variable(const Cfg *Func, OperandKind K, Type Ty, SizeT Index) |
744 : Operand(K, Ty), Number(Index), | 754 : Operand(K, Ty), Number(Index), Name(Func), |
745 RegisterClass(static_cast<RegClass>(Ty)) { | 755 RegisterClass(static_cast<RegClass>(Ty)) { |
746 Vars = VarsReal; | 756 Vars = VarsReal; |
747 Vars[0] = this; | 757 Vars[0] = this; |
748 NumVars = 1; | 758 NumVars = 1; |
759 if (BuildDefs::dump()) { | |
760 Name = VariableString(Func, "__" + std::to_string(getIndex())); | |
761 } else { | |
762 Name = VariableString(Func); | |
763 } | |
749 } | 764 } |
750 /// Number is unique across all variables, and is used as a (bit)vector index | 765 /// Number is unique across all variables, and is used as a (bit)vector index |
751 /// for liveness analysis. | 766 /// for liveness analysis. |
752 const SizeT Number; | 767 const SizeT Number; |
753 Cfg::IdentifierIndexType NameIndex = Cfg::IdentifierIndexInvalid; | 768 VariableString Name; |
754 bool IsArgument = false; | 769 bool IsArgument = false; |
755 bool IsImplicitArgument = false; | 770 bool IsImplicitArgument = false; |
756 /// IgnoreLiveness means that the variable should be ignored when constructing | 771 /// IgnoreLiveness means that the variable should be ignored when constructing |
757 /// and validating live ranges. This is usually reserved for the stack | 772 /// and validating live ranges. This is usually reserved for the stack |
758 /// pointer and other physical registers specifically referenced by name. | 773 /// pointer and other physical registers specifically referenced by name. |
759 bool IgnoreLiveness = false; | 774 bool IgnoreLiveness = false; |
760 // If IsRematerializable, RegNum keeps track of which register (stack or frame | 775 // If IsRematerializable, RegNum keeps track of which register (stack or frame |
761 // pointer), and StackOffset is the known offset from that register. | 776 // pointer), and StackOffset is the known offset from that register. |
762 bool IsRematerializable = false; | 777 bool IsRematerializable = false; |
763 RegRequirement RegRequirement = RR_MayHaveRegister; | 778 RegRequirement RegRequirement = RR_MayHaveRegister; |
(...skipping 13 matching lines...) Expand all Loading... | |
777 // Variable64On32 represents a 64-bit variable on a 32-bit architecture. In | 792 // Variable64On32 represents a 64-bit variable on a 32-bit architecture. In |
778 // this situation the variable must be split into a low and a high word. | 793 // this situation the variable must be split into a low and a high word. |
779 class Variable64On32 : public Variable { | 794 class Variable64On32 : public Variable { |
780 Variable64On32() = delete; | 795 Variable64On32() = delete; |
781 Variable64On32(const Variable64On32 &) = delete; | 796 Variable64On32(const Variable64On32 &) = delete; |
782 Variable64On32 &operator=(const Variable64On32 &) = delete; | 797 Variable64On32 &operator=(const Variable64On32 &) = delete; |
783 | 798 |
784 public: | 799 public: |
785 static Variable64On32 *create(Cfg *Func, Type Ty, SizeT Index) { | 800 static Variable64On32 *create(Cfg *Func, Type Ty, SizeT Index) { |
786 return new (Func->allocate<Variable64On32>()) | 801 return new (Func->allocate<Variable64On32>()) |
787 Variable64On32(kVariable64On32, Ty, Index); | 802 Variable64On32(Func, kVariable64On32, Ty, Index); |
788 } | 803 } |
789 | 804 |
790 void setName(Cfg *Func, const IceString &NewName) override { | 805 void setName(const Cfg *Func, const std::string &NewName) override { |
791 Variable::setName(Func, NewName); | 806 Variable::setName(Func, NewName); |
792 if (LoVar && HiVar) { | 807 if (LoVar && HiVar) { |
793 LoVar->setName(Func, getName(Func) + "__lo"); | 808 LoVar->setName(Func, getName(Func) + "__lo"); |
794 HiVar->setName(Func, getName(Func) + "__hi"); | 809 HiVar->setName(Func, getName(Func) + "__hi"); |
795 } | 810 } |
796 } | 811 } |
797 | 812 |
798 void setIsArg(bool Val = true) override { | 813 void setIsArg(bool Val = true) override { |
799 Variable::setIsArg(Val); | 814 Variable::setIsArg(Val); |
800 if (LoVar && HiVar) { | 815 if (LoVar && HiVar) { |
(...skipping 11 matching lines...) Expand all Loading... | |
812 return HiVar; | 827 return HiVar; |
813 } | 828 } |
814 | 829 |
815 void initHiLo(Cfg *Func) { | 830 void initHiLo(Cfg *Func) { |
816 assert(LoVar == nullptr); | 831 assert(LoVar == nullptr); |
817 assert(HiVar == nullptr); | 832 assert(HiVar == nullptr); |
818 LoVar = Func->makeVariable(IceType_i32); | 833 LoVar = Func->makeVariable(IceType_i32); |
819 HiVar = Func->makeVariable(IceType_i32); | 834 HiVar = Func->makeVariable(IceType_i32); |
820 LoVar->setIsArg(getIsArg()); | 835 LoVar->setIsArg(getIsArg()); |
821 HiVar->setIsArg(getIsArg()); | 836 HiVar->setIsArg(getIsArg()); |
822 LoVar->setName(Func, getName(Func) + "__lo"); | 837 if (BuildDefs::dump()) { |
823 HiVar->setName(Func, getName(Func) + "__hi"); | 838 LoVar->setName(Func, getName(Func) + "__lo"); |
839 HiVar->setName(Func, getName(Func) + "__hi"); | |
840 } | |
824 } | 841 } |
825 | 842 |
826 static bool classof(const Operand *Operand) { | 843 static bool classof(const Operand *Operand) { |
827 OperandKind Kind = Operand->getKind(); | 844 OperandKind Kind = Operand->getKind(); |
828 return Kind == kVariable64On32; | 845 return Kind == kVariable64On32; |
829 } | 846 } |
830 | 847 |
831 protected: | 848 protected: |
832 Variable64On32(OperandKind K, Type Ty, SizeT Index) : Variable(K, Ty, Index) { | 849 Variable64On32(const Cfg *Func, OperandKind K, Type Ty, SizeT Index) |
850 : Variable(Func, K, Ty, Index) { | |
833 assert(typeWidthInBytes(Ty) == 8); | 851 assert(typeWidthInBytes(Ty) == 8); |
834 } | 852 } |
835 | 853 |
836 Variable *LoVar = nullptr; | 854 Variable *LoVar = nullptr; |
837 Variable *HiVar = nullptr; | 855 Variable *HiVar = nullptr; |
838 }; | 856 }; |
839 | 857 |
840 enum MetadataKind { | 858 enum MetadataKind { |
841 VMK_Uses, /// Track only uses, not defs | 859 VMK_Uses, /// Track only uses, not defs |
842 VMK_SingleDefs, /// Track uses+defs, but only record single def | 860 VMK_SingleDefs, /// Track uses+defs, but only record single def |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 private: | 961 private: |
944 const Cfg *Func; | 962 const Cfg *Func; |
945 MetadataKind Kind; | 963 MetadataKind Kind; |
946 CfgVector<VariableTracking> Metadata; | 964 CfgVector<VariableTracking> Metadata; |
947 const static InstDefList NoDefinitions; | 965 const static InstDefList NoDefinitions; |
948 }; | 966 }; |
949 | 967 |
950 } // end of namespace Ice | 968 } // end of namespace Ice |
951 | 969 |
952 #endif // SUBZERO_SRC_ICEOPERAND_H | 970 #endif // SUBZERO_SRC_ICEOPERAND_H |
OLD | NEW |