comparison lib/CodeGen/SlotIndexes.cpp @ 120:1172e4bd9c6f

update 4.0.0
author mir3636
date Fri, 25 Nov 2016 19:14:25 +0900
parents afa8332a0e37
children 803732b1fca8
comparison
equal deleted inserted replaced
101:34baf5011add 120:1172e4bd9c6f
67 idx2MBBMap.reserve(mf->size()); 67 idx2MBBMap.reserve(mf->size());
68 68
69 indexList.push_back(createEntry(nullptr, index)); 69 indexList.push_back(createEntry(nullptr, index));
70 70
71 // Iterate over the function. 71 // Iterate over the function.
72 for (MachineFunction::iterator mbbItr = mf->begin(), mbbEnd = mf->end(); 72 for (MachineBasicBlock &MBB : *mf) {
73 mbbItr != mbbEnd; ++mbbItr) {
74 MachineBasicBlock *mbb = &*mbbItr;
75
76 // Insert an index for the MBB start. 73 // Insert an index for the MBB start.
77 SlotIndex blockStartIndex(&indexList.back(), SlotIndex::Slot_Block); 74 SlotIndex blockStartIndex(&indexList.back(), SlotIndex::Slot_Block);
78 75
79 for (MachineBasicBlock::iterator miItr = mbb->begin(), miEnd = mbb->end(); 76 for (MachineInstr &MI : MBB) {
80 miItr != miEnd; ++miItr) { 77 if (MI.isDebugValue())
81 MachineInstr *mi = miItr;
82 if (mi->isDebugValue())
83 continue; 78 continue;
84 79
85 // Insert a store index for the instr. 80 // Insert a store index for the instr.
86 indexList.push_back(createEntry(mi, index += SlotIndex::InstrDist)); 81 indexList.push_back(createEntry(&MI, index += SlotIndex::InstrDist));
87 82
88 // Save this base index in the maps. 83 // Save this base index in the maps.
89 mi2iMap.insert(std::make_pair(mi, SlotIndex(&indexList.back(), 84 mi2iMap.insert(std::make_pair(
90 SlotIndex::Slot_Block))); 85 &MI, SlotIndex(&indexList.back(), SlotIndex::Slot_Block)));
91 } 86 }
92 87
93 // We insert one blank instructions between basic blocks. 88 // We insert one blank instructions between basic blocks.
94 indexList.push_back(createEntry(nullptr, index += SlotIndex::InstrDist)); 89 indexList.push_back(createEntry(nullptr, index += SlotIndex::InstrDist));
95 90
96 MBBRanges[mbb->getNumber()].first = blockStartIndex; 91 MBBRanges[MBB.getNumber()].first = blockStartIndex;
97 MBBRanges[mbb->getNumber()].second = SlotIndex(&indexList.back(), 92 MBBRanges[MBB.getNumber()].second = SlotIndex(&indexList.back(),
98 SlotIndex::Slot_Block); 93 SlotIndex::Slot_Block);
99 idx2MBBMap.push_back(IdxMBBPair(blockStartIndex, mbb)); 94 idx2MBBMap.push_back(IdxMBBPair(blockStartIndex, &MBB));
100 } 95 }
101 96
102 // Sort the Idx2MBBMap 97 // Sort the Idx2MBBMap
103 std::sort(idx2MBBMap.begin(), idx2MBBMap.end(), Idx2MBBCompare()); 98 std::sort(idx2MBBMap.begin(), idx2MBBMap.end(), Idx2MBBCompare());
104 99
148 MachineBasicBlock::iterator End) { 143 MachineBasicBlock::iterator End) {
149 // FIXME: Is this really necessary? The only caller repairIntervalsForRange() 144 // FIXME: Is this really necessary? The only caller repairIntervalsForRange()
150 // does the same thing. 145 // does the same thing.
151 // Find anchor points, which are at the beginning/end of blocks or at 146 // Find anchor points, which are at the beginning/end of blocks or at
152 // instructions that already have indexes. 147 // instructions that already have indexes.
153 while (Begin != MBB->begin() && !hasIndex(Begin)) 148 while (Begin != MBB->begin() && !hasIndex(*Begin))
154 --Begin; 149 --Begin;
155 while (End != MBB->end() && !hasIndex(End)) 150 while (End != MBB->end() && !hasIndex(*End))
156 ++End; 151 ++End;
157 152
158 bool includeStart = (Begin == MBB->begin()); 153 bool includeStart = (Begin == MBB->begin());
159 SlotIndex startIdx; 154 SlotIndex startIdx;
160 if (includeStart) 155 if (includeStart)
161 startIdx = getMBBStartIdx(MBB); 156 startIdx = getMBBStartIdx(MBB);
162 else 157 else
163 startIdx = getInstructionIndex(Begin); 158 startIdx = getInstructionIndex(*Begin);
164 159
165 SlotIndex endIdx; 160 SlotIndex endIdx;
166 if (End == MBB->end()) 161 if (End == MBB->end())
167 endIdx = getMBBEndIdx(MBB); 162 endIdx = getMBBEndIdx(MBB);
168 else 163 else
169 endIdx = getInstructionIndex(End); 164 endIdx = getInstructionIndex(*End);
170 165
171 // FIXME: Conceptually, this code is implementing an iterator on MBB that 166 // FIXME: Conceptually, this code is implementing an iterator on MBB that
172 // optionally includes an additional position prior to MBB->begin(), indicated 167 // optionally includes an additional position prior to MBB->begin(), indicated
173 // by the includeStart flag. This is done so that we can iterate MIs in a MBB 168 // by the includeStart flag. This is done so that we can iterate MIs in a MBB
174 // in parallel with SlotIndexes, but there should be a better way to do this. 169 // in parallel with SlotIndexes, but there should be a better way to do this.
180 assert(ListI->getIndex() >= startIdx.getIndex() && 175 assert(ListI->getIndex() >= startIdx.getIndex() &&
181 (includeStart || !pastStart) && 176 (includeStart || !pastStart) &&
182 "Decremented past the beginning of region to repair."); 177 "Decremented past the beginning of region to repair.");
183 178
184 MachineInstr *SlotMI = ListI->getInstr(); 179 MachineInstr *SlotMI = ListI->getInstr();
185 MachineInstr *MI = (MBBI != MBB->end() && !pastStart) ? MBBI : nullptr; 180 MachineInstr *MI = (MBBI != MBB->end() && !pastStart) ? &*MBBI : nullptr;
186 bool MBBIAtBegin = MBBI == Begin && (!includeStart || pastStart); 181 bool MBBIAtBegin = MBBI == Begin && (!includeStart || pastStart);
187 182
188 if (SlotMI == MI && !MBBIAtBegin) { 183 if (SlotMI == MI && !MBBIAtBegin) {
189 --ListI; 184 --ListI;
190 if (MBBI != Begin) 185 if (MBBI != Begin)
197 else 192 else
198 pastStart = true; 193 pastStart = true;
199 } else { 194 } else {
200 --ListI; 195 --ListI;
201 if (SlotMI) 196 if (SlotMI)
202 removeMachineInstrFromMaps(SlotMI); 197 removeMachineInstrFromMaps(*SlotMI);
203 } 198 }
204 } 199 }
205 200
206 // In theory this could be combined with the previous loop, but it is tricky 201 // In theory this could be combined with the previous loop, but it is tricky
207 // to update the IndexList while we are iterating it. 202 // to update the IndexList while we are iterating it.
208 for (MachineBasicBlock::iterator I = End; I != Begin;) { 203 for (MachineBasicBlock::iterator I = End; I != Begin;) {
209 --I; 204 --I;
210 MachineInstr *MI = I; 205 MachineInstr &MI = *I;
211 if (!MI->isDebugValue() && mi2iMap.find(MI) == mi2iMap.end()) 206 if (!MI.isDebugValue() && mi2iMap.find(&MI) == mi2iMap.end())
212 insertMachineInstrInMaps(MI); 207 insertMachineInstrInMaps(MI);
213 } 208 }
214 } 209 }
215 210
216 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 211 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
217 void SlotIndexes::dump() const { 212 LLVM_DUMP_METHOD void SlotIndexes::dump() const {
218 for (IndexList::const_iterator itr = indexList.begin(); 213 for (IndexList::const_iterator itr = indexList.begin();
219 itr != indexList.end(); ++itr) { 214 itr != indexList.end(); ++itr) {
220 dbgs() << itr->getIndex() << " "; 215 dbgs() << itr->getIndex() << " ";
221 216
222 if (itr->getInstr()) { 217 if (itr->getInstr()) {
240 os << "invalid"; 235 os << "invalid";
241 } 236 }
242 237
243 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 238 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
244 // Dump a SlotIndex to stderr. 239 // Dump a SlotIndex to stderr.
245 void SlotIndex::dump() const { 240 LLVM_DUMP_METHOD void SlotIndex::dump() const {
246 print(dbgs()); 241 print(dbgs());
247 dbgs() << "\n"; 242 dbgs() << "\n";
248 } 243 }
249 #endif 244 #endif
250 245