| OLD | NEW |
| 1 //===- subzero/src/IceInst.cpp - High-level instruction implementation ----===// | 1 //===- subzero/src/IceInst.cpp - High-level instruction 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 Inst class, primarily the various | 10 // This file implements the Inst class, primarily the various |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 InstAssign::InstAssign(Cfg *Func, Variable *Dest, Operand *Source) | 228 InstAssign::InstAssign(Cfg *Func, Variable *Dest, Operand *Source) |
| 229 : InstHighLevel(Func, Inst::Assign, 1, Dest) { | 229 : InstHighLevel(Func, Inst::Assign, 1, Dest) { |
| 230 addSource(Source); | 230 addSource(Source); |
| 231 } | 231 } |
| 232 | 232 |
| 233 // If TargetTrue==TargetFalse, we turn it into an unconditional | 233 // If TargetTrue==TargetFalse, we turn it into an unconditional |
| 234 // branch. This ensures that, along with the 'switch' instruction | 234 // branch. This ensures that, along with the 'switch' instruction |
| 235 // semantics, there is at most one edge from one node to another. | 235 // semantics, there is at most one edge from one node to another. |
| 236 InstBr::InstBr(Cfg *Func, Operand *Source, CfgNode *TargetTrue, | 236 InstBr::InstBr(Cfg *Func, Operand *Source, CfgNode *TargetTrue, |
| 237 CfgNode *TargetFalse) | 237 CfgNode *TargetFalse) |
| 238 : InstHighLevel(Func, Inst::Br, 1, NULL), TargetFalse(TargetFalse), | 238 : InstHighLevel(Func, Inst::Br, 1, nullptr), TargetFalse(TargetFalse), |
| 239 TargetTrue(TargetTrue) { | 239 TargetTrue(TargetTrue) { |
| 240 if (TargetTrue == TargetFalse) { | 240 if (TargetTrue == TargetFalse) { |
| 241 TargetTrue = NULL; // turn into unconditional version | 241 TargetTrue = nullptr; // turn into unconditional version |
| 242 } else { | 242 } else { |
| 243 addSource(Source); | 243 addSource(Source); |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 | 246 |
| 247 InstBr::InstBr(Cfg *Func, CfgNode *Target) | 247 InstBr::InstBr(Cfg *Func, CfgNode *Target) |
| 248 : InstHighLevel(Func, Inst::Br, 0, NULL), TargetFalse(Target), | 248 : InstHighLevel(Func, Inst::Br, 0, nullptr), TargetFalse(Target), |
| 249 TargetTrue(NULL) {} | 249 TargetTrue(nullptr) {} |
| 250 | 250 |
| 251 NodeList InstBr::getTerminatorEdges() const { | 251 NodeList InstBr::getTerminatorEdges() const { |
| 252 NodeList OutEdges; | 252 NodeList OutEdges; |
| 253 OutEdges.reserve(TargetTrue ? 2 : 1); | 253 OutEdges.reserve(TargetTrue ? 2 : 1); |
| 254 OutEdges.push_back(TargetFalse); | 254 OutEdges.push_back(TargetFalse); |
| 255 if (TargetTrue) | 255 if (TargetTrue) |
| 256 OutEdges.push_back(TargetTrue); | 256 OutEdges.push_back(TargetTrue); |
| 257 return OutEdges; | 257 return OutEdges; |
| 258 } | 258 } |
| 259 | 259 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 324 |
| 325 // Find the source operand corresponding to the incoming edge for the | 325 // Find the source operand corresponding to the incoming edge for the |
| 326 // given node. TODO: This uses a linear-time search, which could be | 326 // given node. TODO: This uses a linear-time search, which could be |
| 327 // improved if it becomes a problem. | 327 // improved if it becomes a problem. |
| 328 Operand *InstPhi::getOperandForTarget(CfgNode *Target) const { | 328 Operand *InstPhi::getOperandForTarget(CfgNode *Target) const { |
| 329 for (SizeT I = 0; I < getSrcSize(); ++I) { | 329 for (SizeT I = 0; I < getSrcSize(); ++I) { |
| 330 if (Labels[I] == Target) | 330 if (Labels[I] == Target) |
| 331 return getSrc(I); | 331 return getSrc(I); |
| 332 } | 332 } |
| 333 llvm_unreachable("Phi target not found"); | 333 llvm_unreachable("Phi target not found"); |
| 334 return NULL; | 334 return nullptr; |
| 335 } | 335 } |
| 336 | 336 |
| 337 // Updates liveness for a particular operand based on the given | 337 // Updates liveness for a particular operand based on the given |
| 338 // predecessor edge. Doesn't mark the operand as live if the Phi | 338 // predecessor edge. Doesn't mark the operand as live if the Phi |
| 339 // instruction is dead or deleted. | 339 // instruction is dead or deleted. |
| 340 void InstPhi::livenessPhiOperand(LivenessBV &Live, CfgNode *Target, | 340 void InstPhi::livenessPhiOperand(LivenessBV &Live, CfgNode *Target, |
| 341 Liveness *Liveness) { | 341 Liveness *Liveness) { |
| 342 if (isDeleted() || Dead) | 342 if (isDeleted() || Dead) |
| 343 return; | 343 return; |
| 344 for (SizeT I = 0; I < getSrcSize(); ++I) { | 344 for (SizeT I = 0; I < getSrcSize(); ++I) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 362 Variable *Dest = getDest(); | 362 Variable *Dest = getDest(); |
| 363 assert(Dest); | 363 assert(Dest); |
| 364 Variable *NewSrc = Func->makeVariable(Dest->getType()); | 364 Variable *NewSrc = Func->makeVariable(Dest->getType()); |
| 365 if (ALLOW_DUMP) | 365 if (ALLOW_DUMP) |
| 366 NewSrc->setName(Func, Dest->getName(Func) + "_phi"); | 366 NewSrc->setName(Func, Dest->getName(Func) + "_phi"); |
| 367 this->Dest = NewSrc; | 367 this->Dest = NewSrc; |
| 368 return InstAssign::create(Func, Dest, NewSrc); | 368 return InstAssign::create(Func, Dest, NewSrc); |
| 369 } | 369 } |
| 370 | 370 |
| 371 InstRet::InstRet(Cfg *Func, Operand *RetValue) | 371 InstRet::InstRet(Cfg *Func, Operand *RetValue) |
| 372 : InstHighLevel(Func, Ret, RetValue ? 1 : 0, NULL) { | 372 : InstHighLevel(Func, Ret, RetValue ? 1 : 0, nullptr) { |
| 373 if (RetValue) | 373 if (RetValue) |
| 374 addSource(RetValue); | 374 addSource(RetValue); |
| 375 } | 375 } |
| 376 | 376 |
| 377 InstSelect::InstSelect(Cfg *Func, Variable *Dest, Operand *Condition, | 377 InstSelect::InstSelect(Cfg *Func, Variable *Dest, Operand *Condition, |
| 378 Operand *SourceTrue, Operand *SourceFalse) | 378 Operand *SourceTrue, Operand *SourceFalse) |
| 379 : InstHighLevel(Func, Inst::Select, 3, Dest) { | 379 : InstHighLevel(Func, Inst::Select, 3, Dest) { |
| 380 assert(typeElementType(Condition->getType()) == IceType_i1); | 380 assert(typeElementType(Condition->getType()) == IceType_i1); |
| 381 addSource(Condition); | 381 addSource(Condition); |
| 382 addSource(SourceTrue); | 382 addSource(SourceTrue); |
| 383 addSource(SourceFalse); | 383 addSource(SourceFalse); |
| 384 } | 384 } |
| 385 | 385 |
| 386 InstStore::InstStore(Cfg *Func, Operand *Data, Operand *Addr) | 386 InstStore::InstStore(Cfg *Func, Operand *Data, Operand *Addr) |
| 387 : InstHighLevel(Func, Inst::Store, 2, NULL) { | 387 : InstHighLevel(Func, Inst::Store, 2, nullptr) { |
| 388 addSource(Data); | 388 addSource(Data); |
| 389 addSource(Addr); | 389 addSource(Addr); |
| 390 } | 390 } |
| 391 | 391 |
| 392 InstSwitch::InstSwitch(Cfg *Func, SizeT NumCases, Operand *Source, | 392 InstSwitch::InstSwitch(Cfg *Func, SizeT NumCases, Operand *Source, |
| 393 CfgNode *LabelDefault) | 393 CfgNode *LabelDefault) |
| 394 : InstHighLevel(Func, Inst::Switch, 1, NULL), LabelDefault(LabelDefault), | 394 : InstHighLevel(Func, Inst::Switch, 1, nullptr), LabelDefault(LabelDefault), |
| 395 NumCases(NumCases) { | 395 NumCases(NumCases) { |
| 396 addSource(Source); | 396 addSource(Source); |
| 397 Values = Func->allocateArrayOf<uint64_t>(NumCases); | 397 Values = Func->allocateArrayOf<uint64_t>(NumCases); |
| 398 Labels = Func->allocateArrayOf<CfgNode *>(NumCases); | 398 Labels = Func->allocateArrayOf<CfgNode *>(NumCases); |
| 399 // Initialize in case buggy code doesn't set all entries | 399 // Initialize in case buggy code doesn't set all entries |
| 400 for (SizeT I = 0; I < NumCases; ++I) { | 400 for (SizeT I = 0; I < NumCases; ++I) { |
| 401 Values[I] = 0; | 401 Values[I] = 0; |
| 402 Labels[I] = NULL; | 402 Labels[I] = nullptr; |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 | 405 |
| 406 void InstSwitch::addBranch(SizeT CaseIndex, uint64_t Value, CfgNode *Label) { | 406 void InstSwitch::addBranch(SizeT CaseIndex, uint64_t Value, CfgNode *Label) { |
| 407 assert(CaseIndex < NumCases); | 407 assert(CaseIndex < NumCases); |
| 408 Values[CaseIndex] = Value; | 408 Values[CaseIndex] = Value; |
| 409 Labels[CaseIndex] = Label; | 409 Labels[CaseIndex] = Label; |
| 410 } | 410 } |
| 411 | 411 |
| 412 NodeList InstSwitch::getTerminatorEdges() const { | 412 NodeList InstSwitch::getTerminatorEdges() const { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 427 for (SizeT I = 0; I < NumCases; ++I) { | 427 for (SizeT I = 0; I < NumCases; ++I) { |
| 428 if (Labels[I] == OldNode) { | 428 if (Labels[I] == OldNode) { |
| 429 Labels[I] = NewNode; | 429 Labels[I] = NewNode; |
| 430 return true; | 430 return true; |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 return false; | 433 return false; |
| 434 } | 434 } |
| 435 | 435 |
| 436 InstUnreachable::InstUnreachable(Cfg *Func) | 436 InstUnreachable::InstUnreachable(Cfg *Func) |
| 437 : InstHighLevel(Func, Inst::Unreachable, 0, NULL) {} | 437 : InstHighLevel(Func, Inst::Unreachable, 0, nullptr) {} |
| 438 | 438 |
| 439 InstFakeDef::InstFakeDef(Cfg *Func, Variable *Dest, Variable *Src) | 439 InstFakeDef::InstFakeDef(Cfg *Func, Variable *Dest, Variable *Src) |
| 440 : InstHighLevel(Func, Inst::FakeDef, Src ? 1 : 0, Dest) { | 440 : InstHighLevel(Func, Inst::FakeDef, Src ? 1 : 0, Dest) { |
| 441 assert(Dest); | 441 assert(Dest); |
| 442 if (Src) | 442 if (Src) |
| 443 addSource(Src); | 443 addSource(Src); |
| 444 } | 444 } |
| 445 | 445 |
| 446 InstFakeUse::InstFakeUse(Cfg *Func, Variable *Src) | 446 InstFakeUse::InstFakeUse(Cfg *Func, Variable *Src) |
| 447 : InstHighLevel(Func, Inst::FakeUse, 1, NULL) { | 447 : InstHighLevel(Func, Inst::FakeUse, 1, nullptr) { |
| 448 assert(Src); | 448 assert(Src); |
| 449 addSource(Src); | 449 addSource(Src); |
| 450 } | 450 } |
| 451 | 451 |
| 452 InstFakeKill::InstFakeKill(Cfg *Func, const Inst *Linked) | 452 InstFakeKill::InstFakeKill(Cfg *Func, const Inst *Linked) |
| 453 : InstHighLevel(Func, Inst::FakeKill, 0, NULL), Linked(Linked) {} | 453 : InstHighLevel(Func, Inst::FakeKill, 0, nullptr), Linked(Linked) {} |
| 454 | 454 |
| 455 Type InstCall::getReturnType() const { | 455 Type InstCall::getReturnType() const { |
| 456 if (Dest == NULL) | 456 if (Dest == nullptr) |
| 457 return IceType_void; | 457 return IceType_void; |
| 458 return Dest->getType(); | 458 return Dest->getType(); |
| 459 } | 459 } |
| 460 | 460 |
| 461 // ======================== Dump routines ======================== // | 461 // ======================== Dump routines ======================== // |
| 462 | 462 |
| 463 void Inst::dumpDecorated(const Cfg *Func) const { | 463 void Inst::dumpDecorated(const Cfg *Func) const { |
| 464 if (!ALLOW_DUMP) | 464 if (!ALLOW_DUMP) |
| 465 return; | 465 return; |
| 466 Ostream &Str = Func->getContext()->getStrDump(); | 466 Ostream &Str = Func->getContext()->getStrDump(); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 | 819 |
| 820 void InstTarget::dump(const Cfg *Func) const { | 820 void InstTarget::dump(const Cfg *Func) const { |
| 821 if (!ALLOW_DUMP) | 821 if (!ALLOW_DUMP) |
| 822 return; | 822 return; |
| 823 Ostream &Str = Func->getContext()->getStrDump(); | 823 Ostream &Str = Func->getContext()->getStrDump(); |
| 824 Str << "[TARGET] "; | 824 Str << "[TARGET] "; |
| 825 Inst::dump(Func); | 825 Inst::dump(Func); |
| 826 } | 826 } |
| 827 | 827 |
| 828 } // end of namespace Ice | 828 } // end of namespace Ice |
| OLD | NEW |