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

Side by Side Diff: src/IceOperand.cpp

Issue 300563003: Subzero: Initial O2 lowering (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Jan's third-round comments Created 6 years, 6 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/IceOperand.h ('k') | src/IceRegAlloc.h » ('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/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 10 // This file implements the Operand class and its target-independent
11 // target-independent subclasses, primarily for the methods of the 11 // subclasses, primarily for the methods of the Variable class.
12 // Variable class.
13 // 12 //
14 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
15 14
16 #include "IceCfg.h" 15 #include "IceCfg.h"
17 #include "IceInst.h" 16 #include "IceInst.h"
18 #include "IceOperand.h" 17 #include "IceOperand.h"
19 #include "IceTargetLowering.h" // dumping stack/frame pointer register 18 #include "IceTargetLowering.h" // dumping stack/frame pointer register
20 19
21 namespace Ice { 20 namespace Ice {
22 21
23 bool operator<(const RelocatableTuple &A, const RelocatableTuple &B) { 22 bool operator<(const RelocatableTuple &A, const RelocatableTuple &B) {
24 if (A.Offset != B.Offset) 23 if (A.Offset != B.Offset)
25 return A.Offset < B.Offset; 24 return A.Offset < B.Offset;
26 if (A.SuppressMangling != B.SuppressMangling) 25 if (A.SuppressMangling != B.SuppressMangling)
27 return A.SuppressMangling < B.SuppressMangling; 26 return A.SuppressMangling < B.SuppressMangling;
28 return A.Name < B.Name; 27 return A.Name < B.Name;
29 } 28 }
30 29
31 bool operator<(const RegWeight &A, const RegWeight &B) { 30 bool operator<(const RegWeight &A, const RegWeight &B) {
32 return A.getWeight() < B.getWeight(); 31 return A.getWeight() < B.getWeight();
33 } 32 }
34 bool operator<=(const RegWeight &A, const RegWeight &B) { return !(B < A); } 33 bool operator<=(const RegWeight &A, const RegWeight &B) { return !(B < A); }
35 bool operator==(const RegWeight &A, const RegWeight &B) { 34 bool operator==(const RegWeight &A, const RegWeight &B) {
36 return !(B < A) && !(A < B); 35 return !(B < A) && !(A < B);
37 } 36 }
38 37
38 void LiveRange::addSegment(InstNumberT Start, InstNumberT End) {
39 #ifdef USE_SET
40 RangeElementType Element(Start, End);
41 RangeType::iterator Next = Range.lower_bound(Element);
42 assert(Next == Range.upper_bound(Element)); // Element not already present
43
44 // Beginning of code that merges contiguous segments. TODO: change
45 // "if(true)" to "if(false)" to see if this extra optimization code
46 // gives any performance gain, or is just destabilizing.
47 if (true) {
48 RangeType::iterator FirstDelete = Next;
49 RangeType::iterator Prev = Next;
50 bool hasPrev = (Next != Range.begin());
51 bool hasNext = (Next != Range.end());
52 if (hasPrev)
53 --Prev;
54 // See if Element and Next should be joined.
55 if (hasNext && End == Next->first) {
56 Element.second = Next->second;
57 ++Next;
58 }
59 // See if Prev and Element should be joined.
60 if (hasPrev && Prev->second == Start) {
61 Element.first = Prev->first;
62 FirstDelete = Prev;
63 }
64 Range.erase(FirstDelete, Next);
65 }
66 // End of code that merges contiguous segments.
67
68 Range.insert(Next, Element);
69 #else
70 if (Range.empty()) {
71 Range.push_back(RangeElementType(Start, End));
72 return;
73 }
74 // Special case for faking in-arg liveness.
75 if (End < Range.front().first) {
76 assert(Start < 0);
77 Range.push_front(RangeElementType(Start, End));
78 return;
79 }
80 InstNumberT CurrentEnd = Range.back().second;
81 assert(Start >= CurrentEnd);
82 // Check for merge opportunity.
83 if (Start == CurrentEnd) {
84 Range.back().second = End;
85 return;
86 }
87 Range.push_back(RangeElementType(Start, End));
88 #endif
89 }
90
91 // Returns true if this live range ends before Other's live range
92 // starts. This means that the highest instruction number in this
93 // live range is less than or equal to the lowest instruction number
94 // of the Other live range.
95 bool LiveRange::endsBefore(const LiveRange &Other) const {
96 // Neither range should be empty, but let's be graceful.
97 if (Range.empty() || Other.Range.empty())
98 return true;
99 InstNumberT MyEnd = (*Range.rbegin()).second;
100 InstNumberT OtherStart = (*Other.Range.begin()).first;
101 return MyEnd <= OtherStart;
102 }
103
104 // Returns true if there is any overlap between the two live ranges.
105 bool LiveRange::overlaps(const LiveRange &Other) const {
106 // Do a two-finger walk through the two sorted lists of segments.
107 RangeType::const_iterator I1 = Range.begin(), I2 = Other.Range.begin();
108 RangeType::const_iterator E1 = Range.end(), E2 = Other.Range.end();
109 while (I1 != E1 && I2 != E2) {
110 if (I1->second <= I2->first) {
111 ++I1;
112 continue;
113 }
114 if (I2->second <= I1->first) {
115 ++I2;
116 continue;
117 }
118 return true;
119 }
120 return false;
121 }
122
123 bool LiveRange::overlaps(InstNumberT OtherBegin) const {
124 LiveRange Temp;
125 Temp.addSegment(OtherBegin, OtherBegin + 1);
126 return overlaps(Temp);
127 }
128
129 // Returns true if the live range contains the given instruction
130 // number. This is only used for validating the live range
131 // calculation.
132 bool LiveRange::containsValue(InstNumberT Value) const {
133 for (RangeType::const_iterator I = Range.begin(), E = Range.end(); I != E;
134 ++I) {
135 if (I->first <= Value && Value <= I->second)
136 return true;
137 }
138 return false;
139 }
140
39 void Variable::setUse(const Inst *Inst, const CfgNode *Node) { 141 void Variable::setUse(const Inst *Inst, const CfgNode *Node) {
40 if (DefNode == NULL) 142 if (DefNode == NULL)
41 return; 143 return;
42 if (llvm::isa<InstPhi>(Inst) || Node != DefNode) 144 if (llvm::isa<InstPhi>(Inst) || Node != DefNode)
43 DefNode = NULL; 145 DefNode = NULL;
44 } 146 }
45 147
46 void Variable::setDefinition(Inst *Inst, const CfgNode *Node) { 148 void Variable::setDefinition(Inst *Inst, const CfgNode *Node) {
47 if (DefNode == NULL) 149 if (DefNode == NULL)
48 return; 150 return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 int32_t Offset = getStackOffset(); 210 int32_t Offset = getStackOffset();
109 if (Offset) { 211 if (Offset) {
110 if (Offset > 0) 212 if (Offset > 0)
111 Str << "+"; 213 Str << "+";
112 Str << Offset; 214 Str << Offset;
113 } 215 }
114 Str << "]"; 216 Str << "]";
115 } 217 }
116 } 218 }
117 219
118 void ConstantRelocatable::emit(const Cfg *Func) const { 220 void ConstantRelocatable::emit(GlobalContext *Ctx) const {
119 Ostream &Str = Func->getContext()->getStrEmit(); 221 Ostream &Str = Ctx->getStrEmit();
120 if (SuppressMangling) 222 if (SuppressMangling)
121 Str << Name; 223 Str << Name;
122 else 224 else
123 Str << Func->getContext()->mangleName(Name); 225 Str << Ctx->mangleName(Name);
124 if (Offset) { 226 if (Offset) {
125 if (Offset > 0) 227 if (Offset > 0)
126 Str << "+"; 228 Str << "+";
127 Str << Offset; 229 Str << Offset;
128 } 230 }
129 } 231 }
130 232
131 void ConstantRelocatable::dump(const Cfg *Func) const { 233 void ConstantRelocatable::dump(GlobalContext *Ctx) const {
132 Ostream &Str = Func->getContext()->getStrDump(); 234 Ostream &Str = Ctx->getStrDump();
133 Str << "@" << Name; 235 Str << "@" << Name;
134 if (Offset) 236 if (Offset)
135 Str << "+" << Offset; 237 Str << "+" << Offset;
136 } 238 }
137 239
240 void LiveRange::dump(Ostream &Str) const {
241 Str << "(weight=" << Weight << ") ";
242 for (RangeType::const_iterator I = Range.begin(), E = Range.end(); I != E;
243 ++I) {
244 if (I != Range.begin())
245 Str << ", ";
246 Str << "[" << (*I).first << ":" << (*I).second << ")";
247 }
248 }
249
250 Ostream &operator<<(Ostream &Str, const LiveRange &L) {
251 L.dump(Str);
252 return Str;
253 }
254
138 Ostream &operator<<(Ostream &Str, const RegWeight &W) { 255 Ostream &operator<<(Ostream &Str, const RegWeight &W) {
139 if (W.getWeight() == RegWeight::Inf) 256 if (W.getWeight() == RegWeight::Inf)
140 Str << "Inf"; 257 Str << "Inf";
141 else 258 else
142 Str << W.getWeight(); 259 Str << W.getWeight();
143 return Str; 260 return Str;
144 } 261 }
145 262
146 } // end of namespace Ice 263 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceOperand.h ('k') | src/IceRegAlloc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698