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

Side by Side Diff: src/IceOperand.cpp

Issue 652633002: Subzero: Improve performance of liveness analysis and live range construction. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Remove TODO Created 6 years, 2 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/IceTargetLoweringX8632.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 target-independent 10 // This file implements the Operand class and its target-independent
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 LiveRange Temp; 144 LiveRange Temp;
145 Temp.addSegment(OtherBegin, OtherBegin + 1); 145 Temp.addSegment(OtherBegin, OtherBegin + 1);
146 bool Validation = overlaps(Temp); 146 bool Validation = overlaps(Temp);
147 assert(Result == Validation); 147 assert(Result == Validation);
148 #endif 148 #endif
149 return Result; 149 return Result;
150 } 150 }
151 151
152 // Returns true if the live range contains the given instruction 152 // Returns true if the live range contains the given instruction
153 // number. This is only used for validating the live range 153 // number. This is only used for validating the live range
154 // calculation. 154 // calculation. The IsDest argument indicates whether the Variable
155 bool LiveRange::containsValue(InstNumberT Value) const { 155 // being tested is used in the Dest position (as opposed to a Src
156 // position).
157 bool LiveRange::containsValue(InstNumberT Value, bool IsDest) const {
156 for (const RangeElementType &I : Range) { 158 for (const RangeElementType &I : Range) {
157 if (I.first <= Value && Value <= I.second) 159 if (I.first <= Value &&
160 (Value < I.second || (!IsDest && Value == I.second)))
158 return true; 161 return true;
159 } 162 }
160 return false; 163 return false;
161 } 164 }
162 165
163 void LiveRange::trim(InstNumberT Lower) { 166 void LiveRange::trim(InstNumberT Lower) {
164 while (TrimmedBegin != Range.end() && TrimmedBegin->second <= Lower) 167 while (TrimmedBegin != Range.end() && TrimmedBegin->second <= Lower)
165 ++TrimmedBegin; 168 ++TrimmedBegin;
166 } 169 }
167 170
168 IceString Variable::getName() const { 171 IceString Variable::getName() const {
169 if (!Name.empty()) 172 if (!Name.empty())
170 return Name; 173 return Name;
171 char buf[30]; 174 char buf[30];
172 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex()); 175 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex());
173 return buf; 176 return buf;
174 } 177 }
175 178
176 Variable Variable::asType(Type Ty) { 179 Variable Variable::asType(Type Ty) {
177 // Note: This returns a Variable, even if the "this" object is a 180 // Note: This returns a Variable, even if the "this" object is a
178 // subclass of Variable. 181 // subclass of Variable.
179 Variable V(kVariable, Ty, Number, Name); 182 Variable V(kVariable, Ty, Number, Name);
180 V.RegNum = RegNum; 183 V.RegNum = RegNum;
181 V.StackOffset = StackOffset; 184 V.StackOffset = StackOffset;
182 return V; 185 return V;
183 } 186 }
184 187
185 void VariableTracking::markUse(const Inst *Instr, const CfgNode *Node, 188 void VariableTracking::markUse(const Inst *Instr, const CfgNode *Node,
186 bool IsFromDef, bool IsImplicit) { 189 bool IsFromDef, bool IsImplicit) {
190 if (MultiBlock == MBS_MultiBlock)
191 return;
187 // TODO(stichnot): If the use occurs as a source operand in the 192 // TODO(stichnot): If the use occurs as a source operand in the
188 // first instruction of the block, and its definition is in this 193 // first instruction of the block, and its definition is in this
189 // block's only predecessor, we might consider not marking this as a 194 // block's only predecessor, we might consider not marking this as a
190 // separate use. This may also apply if it's the first instruction 195 // separate use. This may also apply if it's the first instruction
191 // of the block that actually uses a Variable. 196 // of the block that actually uses a Variable.
192 assert(Node); 197 assert(Node);
193 bool MakeMulti = false; 198 bool MakeMulti = false;
194 if (IsImplicit) 199 if (IsImplicit)
195 MakeMulti = true; 200 MakeMulti = true;
196 // A phi source variable conservatively needs to be marked as 201 // A phi source variable conservatively needs to be marked as
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 299
295 // Mark implicit args as being used in the entry node. 300 // Mark implicit args as being used in the entry node.
296 for (Variable *Var : Func->getImplicitArgs()) { 301 for (Variable *Var : Func->getImplicitArgs()) {
297 const Inst *NoInst = NULL; 302 const Inst *NoInst = NULL;
298 const CfgNode *EntryNode = Func->getEntryNode(); 303 const CfgNode *EntryNode = Func->getEntryNode();
299 const bool IsFromDef = false; 304 const bool IsFromDef = false;
300 const bool IsImplicit = true; 305 const bool IsImplicit = true;
301 Metadata[Var->getIndex()].markUse(NoInst, EntryNode, IsFromDef, IsImplicit); 306 Metadata[Var->getIndex()].markUse(NoInst, EntryNode, IsFromDef, IsImplicit);
302 } 307 }
303 308
304 SizeT NumNodes = Func->getNumNodes(); 309 for (CfgNode *Node : Func->getNodes()) {
305 for (SizeT N = 0; N < NumNodes; ++N) {
306 CfgNode *Node = Func->getNodes()[N];
307 for (Inst *I : Node->getInsts()) { 310 for (Inst *I : Node->getInsts()) {
308 if (I->isDeleted()) 311 if (I->isDeleted())
309 continue; 312 continue;
310 if (InstFakeKill *Kill = llvm::dyn_cast<InstFakeKill>(I)) { 313 if (InstFakeKill *Kill = llvm::dyn_cast<InstFakeKill>(I)) {
311 // A FakeKill instruction indicates certain Variables (usually 314 // A FakeKill instruction indicates certain Variables (usually
312 // physical scratch registers) are redefined, so we register 315 // physical scratch registers) are redefined, so we register
313 // them as defs. 316 // them as defs.
314 for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) { 317 for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) {
315 Variable *Var = llvm::cast<Variable>(I->getSrc(SrcNum)); 318 Variable *Var = llvm::cast<Variable>(I->getSrc(SrcNum));
316 SizeT VarNum = Var->getIndex(); 319 SizeT VarNum = Var->getIndex();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 464
462 Ostream &operator<<(Ostream &Str, const RegWeight &W) { 465 Ostream &operator<<(Ostream &Str, const RegWeight &W) {
463 if (W.getWeight() == RegWeight::Inf) 466 if (W.getWeight() == RegWeight::Inf)
464 Str << "Inf"; 467 Str << "Inf";
465 else 468 else
466 Str << W.getWeight(); 469 Str << W.getWeight();
467 return Str; 470 return Str;
468 } 471 }
469 472
470 } // end of namespace Ice 473 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceOperand.h ('k') | src/IceTargetLoweringX8632.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698