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 // This file declares the Operand class and its target-independent | 10 // This file declares the Operand class and its target-independent |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 319 |
320 // LiveRange is a set of instruction number intervals representing | 320 // LiveRange is a set of instruction number intervals representing |
321 // a variable's live range. Generally there is one interval per basic | 321 // a variable's live range. Generally there is one interval per basic |
322 // block where the variable is live, but adjacent intervals get | 322 // block where the variable is live, but adjacent intervals get |
323 // coalesced into a single interval. LiveRange also includes a | 323 // coalesced into a single interval. LiveRange also includes a |
324 // weight, in case e.g. we want a live range to have higher weight | 324 // weight, in case e.g. we want a live range to have higher weight |
325 // inside a loop. | 325 // inside a loop. |
326 class LiveRange { | 326 class LiveRange { |
327 public: | 327 public: |
328 LiveRange() : Weight(0) {} | 328 LiveRange() : Weight(0) {} |
| 329 // Special constructor for building a kill set. The advantage is |
| 330 // that we can reserve the right amount of space in advance. |
| 331 LiveRange(const std::vector<InstNumberT> &Kills) : Weight(0) { |
| 332 Range.reserve(Kills.size()); |
| 333 for (InstNumberT I : Kills) |
| 334 addSegment(I, I); |
| 335 } |
329 LiveRange(const LiveRange &) = default; | 336 LiveRange(const LiveRange &) = default; |
330 LiveRange &operator=(const LiveRange &) = default; | 337 LiveRange &operator=(const LiveRange &) = default; |
331 | 338 |
332 void reset() { | 339 void reset() { |
333 Range.clear(); | 340 Range.clear(); |
334 Weight.setWeight(0); | 341 Weight.setWeight(0); |
335 untrim(); | 342 untrim(); |
336 } | 343 } |
337 void addSegment(InstNumberT Start, InstNumberT End); | 344 void addSegment(InstNumberT Start, InstNumberT End); |
338 | 345 |
339 bool endsBefore(const LiveRange &Other) const; | 346 bool endsBefore(const LiveRange &Other) const; |
340 bool overlaps(const LiveRange &Other, bool UseTrimmed = false) const; | 347 bool overlaps(const LiveRange &Other, bool UseTrimmed = false) const; |
341 bool overlapsInst(InstNumberT OtherBegin, bool UseTrimmed = false) const; | 348 bool overlapsInst(InstNumberT OtherBegin, bool UseTrimmed = false) const; |
342 bool containsValue(InstNumberT Value, bool IsDest) const; | 349 bool containsValue(InstNumberT Value, bool IsDest) const; |
343 bool isEmpty() const { return Range.empty(); } | 350 bool isEmpty() const { return Range.empty(); } |
344 InstNumberT getStart() const { | 351 InstNumberT getStart() const { |
345 return Range.empty() ? -1 : Range.begin()->first; | 352 return Range.empty() ? -1 : Range.begin()->first; |
346 } | 353 } |
347 | 354 |
348 void untrim() { TrimmedBegin = Range.begin(); } | 355 void untrim() { TrimmedBegin = Range.begin(); } |
349 void trim(InstNumberT Lower); | 356 void trim(InstNumberT Lower); |
350 | 357 |
351 RegWeight getWeight() const { return Weight; } | 358 RegWeight getWeight() const { return Weight; } |
352 void setWeight(const RegWeight &NewWeight) { Weight = NewWeight; } | 359 void setWeight(const RegWeight &NewWeight) { Weight = NewWeight; } |
353 void addWeight(uint32_t Delta) { Weight.addWeight(Delta); } | 360 void addWeight(uint32_t Delta) { Weight.addWeight(Delta); } |
354 void dump(Ostream &Str) const; | 361 void dump(Ostream &Str) const; |
355 | 362 |
356 // Defining USE_SET uses std::set to hold the segments instead of | |
357 // std::list. Using std::list will be slightly faster, but is more | |
358 // restrictive because new segments cannot be added in the middle. | |
359 | |
360 //#define USE_SET | |
361 | |
362 private: | 363 private: |
363 typedef std::pair<InstNumberT, InstNumberT> RangeElementType; | 364 typedef std::pair<InstNumberT, InstNumberT> RangeElementType; |
364 #ifdef USE_SET | 365 typedef std::vector<RangeElementType> RangeType; |
365 typedef std::set<RangeElementType> RangeType; | |
366 #else | |
367 typedef std::list<RangeElementType> RangeType; | |
368 #endif | |
369 RangeType Range; | 366 RangeType Range; |
370 RegWeight Weight; | 367 RegWeight Weight; |
371 // TrimmedBegin is an optimization for the overlaps() computation. | 368 // TrimmedBegin is an optimization for the overlaps() computation. |
372 // Since the linear-scan algorithm always calls it as overlaps(Cur) | 369 // Since the linear-scan algorithm always calls it as overlaps(Cur) |
373 // and Cur advances monotonically according to live range start, we | 370 // and Cur advances monotonically according to live range start, we |
374 // can optimize overlaps() by ignoring all segments that end before | 371 // can optimize overlaps() by ignoring all segments that end before |
375 // the start of Cur's range. The linear-scan code enables this by | 372 // the start of Cur's range. The linear-scan code enables this by |
376 // calling trim() on the ranges of interest as Cur advances. Note | 373 // calling trim() on the ranges of interest as Cur advances. Note |
377 // that linear-scan also has to initialize TrimmedBegin at the | 374 // that linear-scan also has to initialize TrimmedBegin at the |
378 // beginning by calling untrim(). | 375 // beginning by calling untrim(). |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 private: | 632 private: |
636 const Cfg *Func; | 633 const Cfg *Func; |
637 MetadataKind Kind; | 634 MetadataKind Kind; |
638 std::vector<VariableTracking> Metadata; | 635 std::vector<VariableTracking> Metadata; |
639 const static InstDefList NoDefinitions; | 636 const static InstDefList NoDefinitions; |
640 }; | 637 }; |
641 | 638 |
642 } // end of namespace Ice | 639 } // end of namespace Ice |
643 | 640 |
644 #endif // SUBZERO_SRC_ICEOPERAND_H | 641 #endif // SUBZERO_SRC_ICEOPERAND_H |
OLD | NEW |