OLD | NEW |
1 //===- subzero/src/IceOperand.cpp - High-level operand implementation -----===// | 1 //===- subzero/src/IceOperand.cpp - High-level operand implementation -----===// |
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 Implements the Operand class and its target-independent subclasses, | 11 /// \brief Implements the Operand class and its target-independent subclasses, |
12 /// primarily for the methods of the Variable class. | 12 /// primarily for the methods of the Variable class. |
13 /// | 13 /// |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #include "IceOperand.h" | 16 #include "IceOperand.h" |
17 | 17 |
18 #include "IceCfg.h" | 18 #include "IceCfg.h" |
19 #include "IceCfgNode.h" | 19 #include "IceCfgNode.h" |
20 #include "IceInst.h" | 20 #include "IceInst.h" |
21 #include "IceInstVarIter.h" | 21 #include "IceInstVarIter.h" |
22 #include "IceMemory.h" | 22 #include "IceMemory.h" |
23 #include "IceTargetLowering.h" // dumping stack/frame pointer register | 23 #include "IceTargetLowering.h" // dumping stack/frame pointer register |
24 | 24 |
25 namespace Ice { | 25 namespace Ice { |
26 | 26 |
| 27 void Constant::initShouldBePooled() { |
| 28 ShouldBePooled = TargetLowering::shouldBePooled(this); |
| 29 } |
| 30 |
27 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B) { | 31 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B) { |
28 // A and B are the same if: | 32 // A and B are the same if: |
29 // (1) they have the same name; and | 33 // (1) they have the same name; and |
30 // (2) they have the same offset. | 34 // (2) they have the same offset. |
31 // | 35 // |
32 // (1) is trivial to check, but (2) requires some care. | 36 // (1) is trivial to check, but (2) requires some care. |
33 // | 37 // |
34 // For (2): | 38 // For (2): |
35 // if A and B have known offsets (i.e., no symbolic references), then | 39 // if A and B have known offsets (i.e., no symbolic references), then |
36 // A == B -> A.Offset == B.Offset. | 40 // A == B -> A.Offset == B.Offset. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 return true; | 184 return true; |
181 } | 185 } |
182 return false; | 186 return false; |
183 } | 187 } |
184 | 188 |
185 void LiveRange::trim(InstNumberT Lower) { | 189 void LiveRange::trim(InstNumberT Lower) { |
186 while (TrimmedBegin != Range.end() && TrimmedBegin->second <= Lower) | 190 while (TrimmedBegin != Range.end() && TrimmedBegin->second <= Lower) |
187 ++TrimmedBegin; | 191 ++TrimmedBegin; |
188 } | 192 } |
189 | 193 |
190 IceString Variable::getName(const Cfg *Func) const { | 194 std::string Variable::getName(const Cfg *Func) const { |
191 if (Func && NameIndex >= 0) | 195 if (Func == nullptr) |
192 return Func->getIdentifierName(NameIndex); | 196 return "__" + std::to_string(getIndex()); |
193 return "__" + std::to_string(getIndex()); | 197 return Name.toString(); |
194 } | 198 } |
195 | 199 |
196 const Variable *Variable::asType(Type Ty, RegNumT NewRegNum) const { | 200 const Variable *Variable::asType(const Cfg *Func, Type Ty, |
| 201 RegNumT NewRegNum) const { |
197 // Note: This returns a Variable, even if the "this" object is a subclass of | 202 // Note: This returns a Variable, even if the "this" object is a subclass of |
198 // Variable. | 203 // Variable. |
199 if (!BuildDefs::dump() || getType() == Ty) | 204 if (!BuildDefs::dump() || getType() == Ty) |
200 return this; | 205 return this; |
201 static constexpr SizeT One = 1; | 206 static constexpr SizeT One = 1; |
202 Variable *V = new (CfgLocalAllocator<Variable>().allocate(One)) | 207 Variable *V = new (CfgLocalAllocator<Variable>().allocate(One)) |
203 Variable(kVariable, Ty, Number); | 208 Variable(Func, kVariable, Ty, Number); |
204 V->NameIndex = NameIndex; | 209 V->Name = Name; |
205 V->RegNum = NewRegNum.hasValue() ? NewRegNum : RegNum; | 210 V->RegNum = NewRegNum.hasValue() ? NewRegNum : RegNum; |
206 V->StackOffset = StackOffset; | 211 V->StackOffset = StackOffset; |
207 return V; | 212 return V; |
208 } | 213 } |
209 | 214 |
210 RegWeight Variable::getWeight(const Cfg *Func) const { | 215 RegWeight Variable::getWeight(const Cfg *Func) const { |
211 VariablesMetadata *VMetadata = Func->getVMetadata(); | 216 VariablesMetadata *VMetadata = Func->getVMetadata(); |
212 return mustHaveReg() ? RegWeight(RegWeight::Inf) | 217 return mustHaveReg() ? RegWeight(RegWeight::Inf) |
213 : mustNotHaveReg() ? RegWeight(RegWeight::Zero) | 218 : mustNotHaveReg() ? RegWeight(RegWeight::Zero) |
214 : VMetadata->getUseWeight(this); | 219 : VMetadata->getUseWeight(this); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 if (W.getWeight() == RegWeight::Inf) | 603 if (W.getWeight() == RegWeight::Inf) |
599 Str << "Inf"; | 604 Str << "Inf"; |
600 else | 605 else |
601 Str << W.getWeight(); | 606 Str << W.getWeight(); |
602 return Str; | 607 return Str; |
603 } | 608 } |
604 | 609 |
605 // =========== Immediate Randomization and Pooling routines ============== | 610 // =========== Immediate Randomization and Pooling routines ============== |
606 // Specialization of the template member function for ConstantInteger32 | 611 // Specialization of the template member function for ConstantInteger32 |
607 // TODO(stichnot): try to move this specialization into a target-specific file. | 612 // TODO(stichnot): try to move this specialization into a target-specific file. |
608 template <> | 613 template <> bool ConstantInteger32::shouldBeRandomizedOrPooled() const { |
609 bool ConstantInteger32::shouldBeRandomizedOrPooled(const GlobalContext *Ctx) { | 614 uint32_t Threshold = |
610 uint32_t Threshold = Ctx->getFlags().getRandomizeAndPoolImmediatesThreshold(); | 615 GlobalContext::getFlags().getRandomizeAndPoolImmediatesThreshold(); |
611 if (Ctx->getFlags().getRandomizeAndPoolImmediatesOption() == RPI_None) | 616 if (GlobalContext::getFlags().getRandomizeAndPoolImmediatesOption() == |
| 617 RPI_None) |
612 return false; | 618 return false; |
613 if (getType() != IceType_i32 && getType() != IceType_i16 && | 619 if (getType() != IceType_i32 && getType() != IceType_i16 && |
614 getType() != IceType_i8) | 620 getType() != IceType_i8) |
615 return false; | 621 return false; |
616 // The Following checks if the signed representation of Value is between | 622 // The Following checks if the signed representation of Value is between |
617 // -Threshold/2 and +Threshold/2 | 623 // -Threshold/2 and +Threshold/2 |
618 bool largerThanThreshold = Threshold / 2 + Value >= Threshold; | 624 bool largerThanThreshold = Threshold / 2 + Value >= Threshold; |
619 return largerThanThreshold; | 625 return largerThanThreshold; |
620 } | 626 } |
621 | 627 |
622 } // end of namespace Ice | 628 } // end of namespace Ice |
OLD | NEW |