llvm.org GIT mirror llvm / f4a1e1a
Teach MachineBasicBlock::print() to annotate instructions and blocks with SlotIndexes when available. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117392 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 10 years ago
6 changed file(s) with 32 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
2222 class BasicBlock;
2323 class MachineFunction;
2424 class MCSymbol;
25 class SlotIndexes;
2526 class StringRef;
2627 class raw_ostream;
2728
360361
361362 // Debugging methods.
362363 void dump() const;
363 void print(raw_ostream &OS) const;
364 void print(raw_ostream &OS, SlotIndexes* = 0) const;
364365
365366 /// getNumber - MachineBasicBlocks are uniquely numbered at the function
366367 /// level, unless they're not in a MachineFunction yet, in which case this
243243 /// print - Print out the MachineFunction in a format suitable for debugging
244244 /// to the specified stream.
245245 ///
246 void print(raw_ostream &OS) const;
246 void print(raw_ostream &OS, SlotIndexes* = 0) const;
247247
248248 /// viewCFG - This function is meant for use from the debugger. You can just
249249 /// say 'call F->viewCFG()' and a ghostview window should pop up from the
140140
141141 void LiveIntervals::printInstrs(raw_ostream &OS) const {
142142 OS << "********** MACHINEINSTRS **********\n";
143
144 for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end();
145 mbbi != mbbe; ++mbbi) {
146 OS << "BB#" << mbbi->getNumber()
147 << ":\t\t# derived from " << mbbi->getName() << "\n";
148 for (MachineBasicBlock::iterator mii = mbbi->begin(),
149 mie = mbbi->end(); mii != mie; ++mii) {
150 if (mii->isDebugValue())
151 OS << " \t" << *mii;
152 else
153 OS << getInstructionIndex(mii) << '\t' << *mii;
154 }
155 }
143 mf_->print(OS, indexes_);
156144 }
157145
158146 void LiveIntervals::dumpInstrs() const {
1616 #include "llvm/CodeGen/MachineDominators.h"
1717 #include "llvm/CodeGen/MachineFunction.h"
1818 #include "llvm/CodeGen/MachineLoopInfo.h"
19 #include "llvm/CodeGen/SlotIndexes.h"
1920 #include "llvm/MC/MCAsmInfo.h"
2021 #include "llvm/MC/MCContext.h"
2122 #include "llvm/Target/TargetRegisterInfo.h"
175176 return "(null)";
176177 }
177178
178 void MachineBasicBlock::print(raw_ostream &OS) const {
179 void MachineBasicBlock::print(raw_ostream &OS, SlotIndexes *Indexes) const {
179180 const MachineFunction *MF = getParent();
180181 if (!MF) {
181182 OS << "Can't print out MachineBasicBlock because parent MachineFunction"
185186
186187 if (Alignment) { OS << "Alignment " << Alignment << "\n"; }
187188
189 if (Indexes)
190 OS << Indexes->getMBBStartIdx(this) << '\t';
191
188192 OS << "BB#" << getNumber() << ": ";
189193
190194 const char *Comma = "";
197201 if (hasAddressTaken()) { OS << Comma << "ADDRESS TAKEN"; Comma = ", "; }
198202 OS << '\n';
199203
200 const TargetRegisterInfo *TRI = MF->getTarget().getRegisterInfo();
204 const TargetRegisterInfo *TRI = MF->getTarget().getRegisterInfo();
201205 if (!livein_empty()) {
206 if (Indexes) OS << '\t';
202207 OS << " Live Ins:";
203208 for (livein_iterator I = livein_begin(),E = livein_end(); I != E; ++I)
204209 OutputReg(OS, *I, TRI);
206211 }
207212 // Print the preds of this block according to the CFG.
208213 if (!pred_empty()) {
214 if (Indexes) OS << '\t';
209215 OS << " Predecessors according to CFG:";
210216 for (const_pred_iterator PI = pred_begin(), E = pred_end(); PI != E; ++PI)
211217 OS << " BB#" << (*PI)->getNumber();
212218 OS << '\n';
213219 }
214
220
215221 for (const_iterator I = begin(); I != end(); ++I) {
222 if (Indexes) {
223 if (Indexes->hasIndex(I))
224 OS << Indexes->getInstructionIndex(I);
225 OS << '\t';
226 }
216227 OS << '\t';
217228 I->print(OS, &getParent()->getTarget());
218229 }
219230
220231 // Print the successors of this block according to the CFG.
221232 if (!succ_empty()) {
233 if (Indexes) OS << '\t';
222234 OS << " Successors according to CFG:";
223235 for (const_succ_iterator SI = succ_begin(), E = succ_end(); SI != E; ++SI)
224236 OS << " BB#" << (*SI)->getNumber();
279279 print(dbgs());
280280 }
281281
282 void MachineFunction::print(raw_ostream &OS) const {
282 void MachineFunction::print(raw_ostream &OS, SlotIndexes *Indexes) const {
283283 OS << "# Machine code for function " << Fn->getName() << ":\n";
284284
285285 // Print Frame Information
328328
329329 for (const_iterator BB = begin(), E = end(); BB != E; ++BB) {
330330 OS << '\n';
331 BB->print(OS);
331 BB->print(OS, Indexes);
332332 }
333333
334334 OS << "\n# End machine code for function " << Fn->getName() << ".\n\n";
167167 // Analysis information if available
168168 LiveVariables *LiveVars;
169169 const LiveIntervals *LiveInts;
170 SlotIndexes *Indexes;
170171
171172 void visitMachineFunctionBefore();
172173 void visitMachineBasicBlockBefore(const MachineBasicBlock *MBB);
248249
249250 LiveVars = NULL;
250251 LiveInts = NULL;
252 Indexes = NULL;
251253 if (PASS) {
252254 LiveInts = PASS->getAnalysisIfAvailable();
253255 // We don't want to verify LiveVariables if LiveIntervals is available.
254256 if (!LiveInts)
255257 LiveVars = PASS->getAnalysisIfAvailable();
258 Indexes = PASS->getAnalysisIfAvailable();
256259 }
257260
258261 visitMachineFunctionBefore();
290293 assert(MF);
291294 *OS << '\n';
292295 if (!foundErrors++)
293 MF->print(*OS);
296 MF->print(*OS, Indexes);
294297 *OS << "*** Bad machine code: " << msg << " ***\n"
295298 << "- function: " << MF->getFunction()->getNameStr() << "\n";
296299 }
300303 report(msg, MBB->getParent());
301304 *OS << "- basic block: " << MBB->getName()
302305 << " " << (void*)MBB
303 << " (BB#" << MBB->getNumber() << ")\n";
306 << " (BB#" << MBB->getNumber() << ")";
307 if (Indexes)
308 *OS << " [" << Indexes->getMBBStartIdx(MBB)
309 << ';' << Indexes->getMBBEndIdx(MBB) << ')';
310 *OS << '\n';
304311 }
305312
306313 void MachineVerifier::report(const char *msg, const MachineInstr *MI) {
307314 assert(MI);
308315 report(msg, MI->getParent());
309316 *OS << "- instruction: ";
317 if (Indexes && Indexes->hasIndex(MI))
318 *OS << Indexes->getInstructionIndex(MI) << '\t';
310319 MI->print(*OS, TM);
311320 }
312321