llvm.org GIT mirror llvm / e70cab0
Provide a function that ensures MBB numbering is dense and inorder. This can be used by MachineFunctionPasses who need this property. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30706 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 14 years ago
2 changed file(s) with 55 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
223223 }
224224
225225 /// getNumBlockIDs - Return the number of MBB ID's allocated.
226 ///
226227 unsigned getNumBlockIDs() const { return MBBNumbering.size(); }
228
229 /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and
230 /// recomputes them. This guarantees that the MBB numbers are sequential,
231 /// dense, and match the ordering of the blocks within the function. If a
232 /// specific MachineBasicBlock is specified, only that block and those after
233 /// it are renumbered.
234 void RenumberBlocks(MachineBasicBlock *MBBFrom = 0);
227235
228236 /// print - Print out the MachineFunction in a format suitable for debugging
229237 /// to the specified stream.
131131 delete[] UsedPhysRegs;
132132 }
133133
134
135 /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and
136 /// recomputes them. This guarantees that the MBB numbers are sequential,
137 /// dense, and match the ordering of the blocks within the function. If a
138 /// specific MachineBasicBlock is specified, only that block and those after
139 /// it are renumbered.
140 void MachineFunction::RenumberBlocks(MachineBasicBlock *MBB) {
141 if (empty()) { MBBNumbering.clear(); return; }
142 MachineFunction::iterator MBBI, E = end();
143 if (MBB == 0)
144 MBBI = begin();
145 else
146 MBBI = MBB;
147
148 // Figure out the block number this should have.
149 unsigned BlockNo = 0;
150 if (MBB != &front()) {
151 MachineFunction::iterator I = MBB;
152 --I;
153 BlockNo = I->getNumber()+1;
154 }
155
156 for (; MBBI != E; ++MBBI, ++BlockNo) {
157 if (MBBI->getNumber() != (int)BlockNo) {
158 // Remove use of the old number.
159 if (MBBI->getNumber() != -1) {
160 assert(MBBNumbering[MBBI->getNumber()] == &*MBBI &&
161 "MBB number mismatch!");
162 MBBNumbering[MBBI->getNumber()] = 0;
163 }
164
165 // If BlockNo is already taken, set that block's number to -1.
166 if (MBBNumbering[BlockNo])
167 MBBNumbering[BlockNo]->setNumber(-1);
168
169 MBBNumbering[BlockNo] = MBBI;
170 MBBI->setNumber(BlockNo);
171 }
172 }
173
174 // Okay, all the blocks are renumbered. If we have compactified the block
175 // numbering, shrink MBBNumbering now.
176 assert(BlockNo <= MBBNumbering.size() && "Mismatch!");
177 MBBNumbering.resize(BlockNo);
178 }
179
180
134181 void MachineFunction::dump() const { print(std::cerr); }
135182
136183 void MachineFunction::print(std::ostream &OS) const {