| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 if (Mask == 0) | 107 if (Mask == 0) |
| 108 return false; // another early-exit optimization | 108 return false; // another early-exit optimization |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 return false; | 112 return false; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void Inst::livenessLightweight(Cfg *Func, LivenessBV &Live) { | 115 void Inst::livenessLightweight(Cfg *Func, LivenessBV &Live) { |
| 116 assert(!isDeleted()); | 116 assert(!isDeleted()); |
| 117 if (llvm::isa<InstFakeKill>(this)) | |
| 118 return; | |
| 119 resetLastUses(); | 117 resetLastUses(); |
| 120 VariablesMetadata *VMetadata = Func->getVMetadata(); | 118 VariablesMetadata *VMetadata = Func->getVMetadata(); |
| 121 SizeT VarIndex = 0; | 119 SizeT VarIndex = 0; |
| 122 for (SizeT I = 0; I < getSrcSize(); ++I) { | 120 for (SizeT I = 0; I < getSrcSize(); ++I) { |
| 123 Operand *Src = getSrc(I); | 121 Operand *Src = getSrc(I); |
| 124 SizeT NumVars = Src->getNumVars(); | 122 SizeT NumVars = Src->getNumVars(); |
| 125 for (SizeT J = 0; J < NumVars; ++J, ++VarIndex) { | 123 for (SizeT J = 0; J < NumVars; ++J, ++VarIndex) { |
| 126 const Variable *Var = Src->getVar(J); | 124 const Variable *Var = Src->getVar(J); |
| 127 if (VMetadata->isMultiBlock(Var)) | 125 if (VMetadata->isMultiBlock(Var)) |
| 128 continue; | 126 continue; |
| 129 SizeT Index = Var->getIndex(); | 127 SizeT Index = Var->getIndex(); |
| 130 if (Live[Index]) | 128 if (Live[Index]) |
| 131 continue; | 129 continue; |
| 132 Live[Index] = true; | 130 Live[Index] = true; |
| 133 setLastUse(VarIndex); | 131 setLastUse(VarIndex); |
| 134 } | 132 } |
| 135 } | 133 } |
| 136 } | 134 } |
| 137 | 135 |
| 138 bool Inst::liveness(InstNumberT InstNumber, LivenessBV &Live, | 136 bool Inst::liveness(InstNumberT InstNumber, LivenessBV &Live, |
| 139 Liveness *Liveness, LiveBeginEndMap *LiveBegin, | 137 Liveness *Liveness, LiveBeginEndMap *LiveBegin, |
| 140 LiveBeginEndMap *LiveEnd) { | 138 LiveBeginEndMap *LiveEnd) { |
| 141 assert(!isDeleted()); | 139 assert(!isDeleted()); |
| 142 if (llvm::isa<InstFakeKill>(this)) | |
| 143 return true; | |
| 144 | 140 |
| 145 Dead = false; | 141 Dead = false; |
| 146 if (Dest) { | 142 if (Dest) { |
| 147 SizeT VarNum = Liveness->getLiveIndex(Dest->getIndex()); | 143 SizeT VarNum = Liveness->getLiveIndex(Dest->getIndex()); |
| 148 if (Live[VarNum]) { | 144 if (Live[VarNum]) { |
| 149 if (!isDestNonKillable()) { | 145 if (!isDestNonKillable()) { |
| 150 Live[VarNum] = false; | 146 Live[VarNum] = false; |
| 151 if (LiveBegin) { | 147 if (LiveBegin) { |
| 152 LiveBegin->push_back(std::make_pair(VarNum, InstNumber)); | 148 LiveBegin->push_back(std::make_pair(VarNum, InstNumber)); |
| 153 } | 149 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 174 setLastUse(VarIndex); | 170 setLastUse(VarIndex); |
| 175 if (!IsPhi) { | 171 if (!IsPhi) { |
| 176 Live[VarNum] = true; | 172 Live[VarNum] = true; |
| 177 // For a variable in SSA form, its live range can end at | 173 // For a variable in SSA form, its live range can end at |
| 178 // most once in a basic block. However, after lowering to | 174 // most once in a basic block. However, after lowering to |
| 179 // two-address instructions, we end up with sequences like | 175 // two-address instructions, we end up with sequences like |
| 180 // "t=b;t+=c;a=t" where t's live range begins and ends | 176 // "t=b;t+=c;a=t" where t's live range begins and ends |
| 181 // twice. ICE only allows a variable to have a single | 177 // twice. ICE only allows a variable to have a single |
| 182 // liveness interval in a basic block (except for blocks | 178 // liveness interval in a basic block (except for blocks |
| 183 // where a variable is live-in and live-out but there is a | 179 // where a variable is live-in and live-out but there is a |
| 184 // gap in the middle, and except for the special | 180 // gap in the middle). Therefore, this lowered sequence |
| 185 // InstFakeKill instruction that can appear multiple | 181 // needs to represent a single conservative live range for |
| 186 // times in the same block). Therefore, this lowered | 182 // t. Since the instructions are being traversed backwards, |
| 187 // sequence needs to represent a single conservative live | 183 // we make sure LiveEnd is only set once by setting it only |
| 188 // range for t. Since the instructions are being traversed | 184 // when LiveEnd[VarNum]==0 (sentinel value). Note that it's |
| 189 // backwards, we make sure LiveEnd is only set once by | 185 // OK to set LiveBegin multiple times because of the |
| 190 // setting it only when LiveEnd[VarNum]==0 (sentinel value). | 186 // backwards traversal. |
| 191 // Note that it's OK to set LiveBegin multiple times because | |
| 192 // of the backwards traversal. | |
| 193 if (LiveEnd) { | 187 if (LiveEnd) { |
| 194 // Ideally, we would verify that VarNum wasn't already | 188 // Ideally, we would verify that VarNum wasn't already |
| 195 // added in this block, but this can't be done very | 189 // added in this block, but this can't be done very |
| 196 // efficiently with LiveEnd as a vector. Instead, | 190 // efficiently with LiveEnd as a vector. Instead, |
| 197 // livenessPostprocess() verifies this after the vector | 191 // livenessPostprocess() verifies this after the vector |
| 198 // has been sorted. | 192 // has been sorted. |
| 199 LiveEnd->push_back(std::make_pair(VarNum, InstNumber)); | 193 LiveEnd->push_back(std::make_pair(VarNum, InstNumber)); |
| 200 } | 194 } |
| 201 } | 195 } |
| 202 } | 196 } |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 if (Src) | 439 if (Src) |
| 446 addSource(Src); | 440 addSource(Src); |
| 447 } | 441 } |
| 448 | 442 |
| 449 InstFakeUse::InstFakeUse(Cfg *Func, Variable *Src) | 443 InstFakeUse::InstFakeUse(Cfg *Func, Variable *Src) |
| 450 : InstHighLevel(Func, Inst::FakeUse, 1, NULL) { | 444 : InstHighLevel(Func, Inst::FakeUse, 1, NULL) { |
| 451 assert(Src); | 445 assert(Src); |
| 452 addSource(Src); | 446 addSource(Src); |
| 453 } | 447 } |
| 454 | 448 |
| 455 InstFakeKill::InstFakeKill(Cfg *Func, const VarList &KilledRegs, | 449 InstFakeKill::InstFakeKill(Cfg *Func, const Inst *Linked) |
| 456 const Inst *Linked) | 450 : InstHighLevel(Func, Inst::FakeKill, 0, NULL), Linked(Linked) {} |
| 457 : InstHighLevel(Func, Inst::FakeKill, 0, NULL), KilledRegs(KilledRegs), | |
| 458 Linked(Linked) {} | |
| 459 | 451 |
| 460 // ======================== Dump routines ======================== // | 452 // ======================== Dump routines ======================== // |
| 461 | 453 |
| 462 void Inst::dumpDecorated(const Cfg *Func) const { | 454 void Inst::dumpDecorated(const Cfg *Func) const { |
| 463 Ostream &Str = Func->getContext()->getStrDump(); | 455 Ostream &Str = Func->getContext()->getStrDump(); |
| 464 if (!Func->getContext()->isVerbose(IceV_Deleted) && | 456 if (!Func->getContext()->isVerbose(IceV_Deleted) && |
| 465 (isDeleted() || isRedundantAssign())) | 457 (isDeleted() || isRedundantAssign())) |
| 466 return; | 458 return; |
| 467 if (Func->getContext()->isVerbose(IceV_InstNumbers)) { | 459 if (Func->getContext()->isVerbose(IceV_InstNumbers)) { |
| 468 char buf[30]; | 460 char buf[30]; |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 Str << "use.pseudo "; | 742 Str << "use.pseudo "; |
| 751 dumpSources(Func); | 743 dumpSources(Func); |
| 752 } | 744 } |
| 753 | 745 |
| 754 void InstFakeKill::emit(const Cfg *Func) const { (void)Func; } | 746 void InstFakeKill::emit(const Cfg *Func) const { (void)Func; } |
| 755 | 747 |
| 756 void InstFakeKill::dump(const Cfg *Func) const { | 748 void InstFakeKill::dump(const Cfg *Func) const { |
| 757 Ostream &Str = Func->getContext()->getStrDump(); | 749 Ostream &Str = Func->getContext()->getStrDump(); |
| 758 if (Linked->isDeleted()) | 750 if (Linked->isDeleted()) |
| 759 Str << "// "; | 751 Str << "// "; |
| 760 Str << "kill.pseudo "; | 752 Str << "kill.pseudo scratch_regs"; |
| 761 bool First = true; | |
| 762 for (Variable *Var : KilledRegs) { | |
| 763 if (!First) | |
| 764 Str << ", "; | |
| 765 First = false; | |
| 766 Var->dump(Func); | |
| 767 } | |
| 768 } | 753 } |
| 769 | 754 |
| 770 void InstTarget::dump(const Cfg *Func) const { | 755 void InstTarget::dump(const Cfg *Func) const { |
| 771 Ostream &Str = Func->getContext()->getStrDump(); | 756 Ostream &Str = Func->getContext()->getStrDump(); |
| 772 Str << "[TARGET] "; | 757 Str << "[TARGET] "; |
| 773 Inst::dump(Func); | 758 Inst::dump(Func); |
| 774 } | 759 } |
| 775 | 760 |
| 776 } // end of namespace Ice | 761 } // end of namespace Ice |
| OLD | NEW |