OLD | NEW |
1 //===- subzero/src/IceRegAlloc.cpp - Linear-scan implementation -----------===// | 1 //===- subzero/src/IceRegAlloc.cpp - Linear-scan 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 /// \file | 10 /// \file |
(...skipping 20 matching lines...) Expand all Loading... |
31 // live ranges are trimmed, since all the overlapsDefs() tests are whether some | 31 // live ranges are trimmed, since all the overlapsDefs() tests are whether some |
32 // variable's definitions overlap Cur, and trimming is with respect Cur.start. | 32 // variable's definitions overlap Cur, and trimming is with respect Cur.start. |
33 // Initial tests show no measurable performance difference, so we'll keep the | 33 // Initial tests show no measurable performance difference, so we'll keep the |
34 // code simple for now. | 34 // code simple for now. |
35 bool overlapsDefs(const Cfg *Func, const Variable *Item, const Variable *Var) { | 35 bool overlapsDefs(const Cfg *Func, const Variable *Item, const Variable *Var) { |
36 constexpr bool UseTrimmed = true; | 36 constexpr bool UseTrimmed = true; |
37 VariablesMetadata *VMetadata = Func->getVMetadata(); | 37 VariablesMetadata *VMetadata = Func->getVMetadata(); |
38 if (const Inst *FirstDef = VMetadata->getFirstDefinition(Var)) | 38 if (const Inst *FirstDef = VMetadata->getFirstDefinition(Var)) |
39 if (Item->getLiveRange().overlapsInst(FirstDef->getNumber(), UseTrimmed)) | 39 if (Item->getLiveRange().overlapsInst(FirstDef->getNumber(), UseTrimmed)) |
40 return true; | 40 return true; |
41 const InstDefList &Defs = VMetadata->getLatterDefinitions(Var); | 41 for (const Inst *Def : VMetadata->getLatterDefinitions(Var)) { |
42 for (size_t i = 0; i < Defs.size(); ++i) { | 42 if (Item->getLiveRange().overlapsInst(Def->getNumber(), UseTrimmed)) |
43 if (Item->getLiveRange().overlapsInst(Defs[i]->getNumber(), UseTrimmed)) | |
44 return true; | 43 return true; |
45 } | 44 } |
46 return false; | 45 return false; |
47 } | 46 } |
48 | 47 |
49 void dumpDisableOverlap(const Cfg *Func, const Variable *Var, | 48 void dumpDisableOverlap(const Cfg *Func, const Variable *Var, |
50 const char *Reason) { | 49 const char *Reason) { |
51 if (!BuildDefs::dump()) | 50 if (!BuildDefs::dump()) |
52 return; | 51 return; |
53 if (Func->isVerbose(IceV_LinearScan)) { | 52 if (Func->isVerbose(IceV_LinearScan)) { |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 // assignment - i.e., the register gets copied/aliased but is never modified. | 455 // assignment - i.e., the register gets copied/aliased but is never modified. |
457 // Furthermore, overlap is only allowed when preferred Variable definition | 456 // Furthermore, overlap is only allowed when preferred Variable definition |
458 // instructions do not appear within the current Variable's live range. | 457 // instructions do not appear within the current Variable's live range. |
459 void LinearScan::findRegisterPreference(IterationState &Iter) { | 458 void LinearScan::findRegisterPreference(IterationState &Iter) { |
460 Iter.Prefer = nullptr; | 459 Iter.Prefer = nullptr; |
461 Iter.PreferReg = Variable::NoRegister; | 460 Iter.PreferReg = Variable::NoRegister; |
462 Iter.AllowOverlap = false; | 461 Iter.AllowOverlap = false; |
463 | 462 |
464 if (FindPreference) { | 463 if (FindPreference) { |
465 VariablesMetadata *VMetadata = Func->getVMetadata(); | 464 VariablesMetadata *VMetadata = Func->getVMetadata(); |
466 if (const Inst *DefInst = VMetadata->getFirstDefinition(Iter.Cur)) { | 465 if (const Inst *DefInst = |
| 466 VMetadata->getFirstDefinitionSingleBlock(Iter.Cur)) { |
467 assert(DefInst->getDest() == Iter.Cur); | 467 assert(DefInst->getDest() == Iter.Cur); |
468 bool IsAssign = DefInst->isSimpleAssign(); | 468 bool IsAssign = DefInst->isSimpleAssign(); |
469 bool IsSingleDef = !VMetadata->isMultiDef(Iter.Cur); | 469 bool IsSingleDef = !VMetadata->isMultiDef(Iter.Cur); |
470 for (SizeT i = 0; i < DefInst->getSrcSize(); ++i) { | 470 for (SizeT i = 0; i < DefInst->getSrcSize(); ++i) { |
471 // TODO(stichnot): Iterate through the actual Variables of the | 471 // TODO(stichnot): Iterate through the actual Variables of the |
472 // instruction, not just the source operands. This could capture Load | 472 // instruction, not just the source operands. This could capture Load |
473 // instructions, including address mode optimization, for Prefer (but | 473 // instructions, including address mode optimization, for Prefer (but |
474 // not for AllowOverlap). | 474 // not for AllowOverlap). |
475 if (Variable *SrcVar = llvm::dyn_cast<Variable>(DefInst->getSrc(i))) { | 475 if (Variable *SrcVar = llvm::dyn_cast<Variable>(DefInst->getSrc(i))) { |
476 int32_t SrcReg = SrcVar->getRegNumTmp(); | 476 int32_t SrcReg = SrcVar->getRegNumTmp(); |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 Str << "\n"; | 944 Str << "\n"; |
945 } | 945 } |
946 Str << "++++++ Inactive:\n"; | 946 Str << "++++++ Inactive:\n"; |
947 for (const Variable *Item : Inactive) { | 947 for (const Variable *Item : Inactive) { |
948 dumpLiveRange(Item, Func); | 948 dumpLiveRange(Item, Func); |
949 Str << "\n"; | 949 Str << "\n"; |
950 } | 950 } |
951 } | 951 } |
952 | 952 |
953 } // end of namespace Ice | 953 } // end of namespace Ice |
OLD | NEW |