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 // This file implements the Operand class and its target-independent | 10 // This file implements the Operand class and its target-independent |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 bool LiveRange::endsBefore(const LiveRange &Other) const { | 98 bool LiveRange::endsBefore(const LiveRange &Other) const { |
99 // Neither range should be empty, but let's be graceful. | 99 // Neither range should be empty, but let's be graceful. |
100 if (Range.empty() || Other.Range.empty()) | 100 if (Range.empty() || Other.Range.empty()) |
101 return true; | 101 return true; |
102 InstNumberT MyEnd = (*Range.rbegin()).second; | 102 InstNumberT MyEnd = (*Range.rbegin()).second; |
103 InstNumberT OtherStart = (*Other.Range.begin()).first; | 103 InstNumberT OtherStart = (*Other.Range.begin()).first; |
104 return MyEnd <= OtherStart; | 104 return MyEnd <= OtherStart; |
105 } | 105 } |
106 | 106 |
107 // Returns true if there is any overlap between the two live ranges. | 107 // Returns true if there is any overlap between the two live ranges. |
108 bool LiveRange::overlaps(const LiveRange &Other) const { | 108 bool LiveRange::overlaps(const LiveRange &Other, bool UseTrimmed) const { |
109 // Do a two-finger walk through the two sorted lists of segments. | 109 // Do a two-finger walk through the two sorted lists of segments. |
110 RangeType::const_iterator I1 = Range.begin(), I2 = Other.Range.begin(); | 110 auto I1 = (UseTrimmed ? TrimmedBegin : Range.begin()), |
111 RangeType::const_iterator E1 = Range.end(), E2 = Other.Range.end(); | 111 I2 = (UseTrimmed ? Other.TrimmedBegin : Other.Range.begin()); |
| 112 auto E1 = Range.end(), E2 = Other.Range.end(); |
112 while (I1 != E1 && I2 != E2) { | 113 while (I1 != E1 && I2 != E2) { |
113 if (I1->second <= I2->first) { | 114 if (I1->second <= I2->first) { |
114 ++I1; | 115 ++I1; |
115 continue; | 116 continue; |
116 } | 117 } |
117 if (I2->second <= I1->first) { | 118 if (I2->second <= I1->first) { |
118 ++I2; | 119 ++I2; |
119 continue; | 120 continue; |
120 } | 121 } |
121 return true; | 122 return true; |
122 } | 123 } |
123 return false; | 124 return false; |
124 } | 125 } |
125 | 126 |
126 bool LiveRange::overlaps(InstNumberT OtherBegin) const { | 127 bool LiveRange::overlapsInst(InstNumberT OtherBegin, bool UseTrimmed) const { |
127 if (!IsNonpoints) | 128 if (!IsNonpoints) |
128 return false; | 129 return false; |
129 bool Result = false; | 130 bool Result = false; |
130 for (const RangeElementType &I : Range) { | 131 for (auto I = (UseTrimmed ? TrimmedBegin : Range.begin()), E = Range.end(); |
131 if (OtherBegin < I.first) { | 132 I != E; ++I) { |
| 133 if (OtherBegin < I->first) { |
132 Result = false; | 134 Result = false; |
133 break; | 135 break; |
134 } | 136 } |
135 if (OtherBegin < I.second) { | 137 if (OtherBegin < I->second) { |
136 Result = true; | 138 Result = true; |
137 break; | 139 break; |
138 } | 140 } |
139 } | 141 } |
140 #if 0 | 142 #if 0 |
141 // An equivalent but less inefficient implementation: | 143 // An equivalent but less inefficient implementation: |
142 LiveRange Temp; | 144 LiveRange Temp; |
143 Temp.addSegment(OtherBegin, OtherBegin + 1); | 145 Temp.addSegment(OtherBegin, OtherBegin + 1); |
144 bool Validation = overlaps(Temp); | 146 bool Validation = overlaps(Temp); |
145 assert(Result == Validation); | 147 assert(Result == Validation); |
146 #endif | 148 #endif |
147 return Result; | 149 return Result; |
148 } | 150 } |
149 | 151 |
150 // Returns true if the live range contains the given instruction | 152 // Returns true if the live range contains the given instruction |
151 // number. This is only used for validating the live range | 153 // number. This is only used for validating the live range |
152 // calculation. | 154 // calculation. |
153 bool LiveRange::containsValue(InstNumberT Value) const { | 155 bool LiveRange::containsValue(InstNumberT Value) const { |
154 for (const RangeElementType &I : Range) { | 156 for (const RangeElementType &I : Range) { |
155 if (I.first <= Value && Value <= I.second) | 157 if (I.first <= Value && Value <= I.second) |
156 return true; | 158 return true; |
157 } | 159 } |
158 return false; | 160 return false; |
159 } | 161 } |
160 | 162 |
| 163 void LiveRange::trim(InstNumberT Lower) { |
| 164 while (TrimmedBegin != Range.end() && TrimmedBegin->second <= Lower) |
| 165 ++TrimmedBegin; |
| 166 } |
| 167 |
161 IceString Variable::getName() const { | 168 IceString Variable::getName() const { |
162 if (!Name.empty()) | 169 if (!Name.empty()) |
163 return Name; | 170 return Name; |
164 char buf[30]; | 171 char buf[30]; |
165 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex()); | 172 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex()); |
166 return buf; | 173 return buf; |
167 } | 174 } |
168 | 175 |
169 Variable Variable::asType(Type Ty) { | 176 Variable Variable::asType(Type Ty) { |
170 // Note: This returns a Variable, even if the "this" object is a | 177 // Note: This returns a Variable, even if the "this" object is a |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 SingleUseNode = NULL; | 221 SingleUseNode = NULL; |
215 } | 222 } |
216 } | 223 } |
217 | 224 |
218 void VariableTracking::markDef(const Inst *Instr, const CfgNode *Node) { | 225 void VariableTracking::markDef(const Inst *Instr, const CfgNode *Node) { |
219 // TODO(stichnot): If the definition occurs in the last instruction | 226 // TODO(stichnot): If the definition occurs in the last instruction |
220 // of the block, consider not marking this as a separate use. But | 227 // of the block, consider not marking this as a separate use. But |
221 // be careful not to omit all uses of the variable if markDef() and | 228 // be careful not to omit all uses of the variable if markDef() and |
222 // markUse() both use this optimization. | 229 // markUse() both use this optimization. |
223 assert(Node); | 230 assert(Node); |
| 231 // Verify that instructions are added in increasing order. |
| 232 assert(Definitions.empty() || |
| 233 Instr->getNumber() >= Definitions.back()->getNumber()); |
224 Definitions.push_back(Instr); | 234 Definitions.push_back(Instr); |
225 const bool IsFromDef = true; | 235 const bool IsFromDef = true; |
226 const bool IsImplicit = false; | 236 const bool IsImplicit = false; |
227 markUse(Instr, Node, IsFromDef, IsImplicit); | 237 markUse(Instr, Node, IsFromDef, IsImplicit); |
228 switch (MultiDef) { | 238 switch (MultiDef) { |
229 case MDS_Unknown: | 239 case MDS_Unknown: |
230 assert(SingleDefNode == NULL); | 240 assert(SingleDefNode == NULL); |
231 MultiDef = MDS_SingleDef; | 241 MultiDef = MDS_SingleDef; |
232 SingleDefNode = Node; | 242 SingleDefNode = Node; |
233 break; | 243 break; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 462 |
453 Ostream &operator<<(Ostream &Str, const RegWeight &W) { | 463 Ostream &operator<<(Ostream &Str, const RegWeight &W) { |
454 if (W.getWeight() == RegWeight::Inf) | 464 if (W.getWeight() == RegWeight::Inf) |
455 Str << "Inf"; | 465 Str << "Inf"; |
456 else | 466 else |
457 Str << W.getWeight(); | 467 Str << W.getWeight(); |
458 return Str; | 468 return Str; |
459 } | 469 } |
460 | 470 |
461 } // end of namespace Ice | 471 } // end of namespace Ice |
OLD | NEW |