blob: cceb4b6b7309575597b8034cf63579ed71280b13 [file] [log] [blame]
Bill Wendling5567bb02010-08-19 18:52:17 +00001//===-- MachineVerifier.cpp - Machine Code Verifier -----------------------===//
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Pass to verify generated machine code. The following is checked:
11//
12// Operand counts: All explicit operands must be present.
13//
14// Register classes: All physical and virtual register operands must be
15// compatible with the register class required by the instruction descriptor.
16//
17// Register live intervals: Registers must be defined only once, and must be
18// defined before use.
19//
20// The machine code verifier is enabled from LLVMTargetMachine.cpp with the
21// command-line option -verify-machineinstrs, or by defining the environment
22// variable LLVM_VERIFY_MACHINEINSTRS to the name of a file that will receive
23// the verifier errors.
24//===----------------------------------------------------------------------===//
25
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000026#include "llvm/Function.h"
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +000027#include "llvm/CodeGen/LiveIntervalAnalysis.h"
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000028#include "llvm/CodeGen/LiveVariables.h"
Jakob Stoklund Olesene8f08232010-11-01 19:49:52 +000029#include "llvm/CodeGen/LiveStackAnalysis.h"
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000030#include "llvm/CodeGen/MachineFunctionPass.h"
Jakob Stoklund Olesena6b677d2009-08-13 16:19:51 +000031#include "llvm/CodeGen/MachineFrameInfo.h"
Dan Gohman2dbc4c82009-10-07 17:36:00 +000032#include "llvm/CodeGen/MachineMemOperand.h"
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000033#include "llvm/CodeGen/MachineRegisterInfo.h"
34#include "llvm/CodeGen/Passes.h"
35#include "llvm/Target/TargetMachine.h"
36#include "llvm/Target/TargetRegisterInfo.h"
37#include "llvm/Target/TargetInstrInfo.h"
Chris Lattnercf143a42009-08-23 03:13:20 +000038#include "llvm/ADT/DenseSet.h"
39#include "llvm/ADT/SetOperations.h"
40#include "llvm/ADT/SmallVector.h"
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000041#include "llvm/Support/Debug.h"
Torok Edwin7d696d82009-07-11 13:10:19 +000042#include "llvm/Support/ErrorHandling.h"
43#include "llvm/Support/raw_ostream.h"
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000044using namespace llvm;
45
46namespace {
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +000047 struct MachineVerifier {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000048
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +000049 MachineVerifier(Pass *pass, const char *b) :
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +000050 PASS(pass),
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +000051 Banner(b),
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000052 OutFileName(getenv("LLVM_VERIFY_MACHINEINSTRS"))
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +000053 {}
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000054
55 bool runOnMachineFunction(MachineFunction &MF);
56
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +000057 Pass *const PASS;
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +000058 const char *Banner;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000059 const char *const OutFileName;
Chris Lattner17e9edc2009-08-23 02:51:22 +000060 raw_ostream *OS;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000061 const MachineFunction *MF;
62 const TargetMachine *TM;
63 const TargetRegisterInfo *TRI;
64 const MachineRegisterInfo *MRI;
65
66 unsigned foundErrors;
67
68 typedef SmallVector<unsigned, 16> RegVector;
69 typedef DenseSet<unsigned> RegSet;
70 typedef DenseMap<unsigned, const MachineInstr*> RegMap;
71
72 BitVector regsReserved;
73 RegSet regsLive;
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +000074 RegVector regsDefined, regsDead, regsKilled;
75 RegSet regsLiveInButUnused;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000076
77 // Add Reg and any sub-registers to RV
78 void addRegWithSubRegs(RegVector &RV, unsigned Reg) {
79 RV.push_back(Reg);
80 if (TargetRegisterInfo::isPhysicalRegister(Reg))
81 for (const unsigned *R = TRI->getSubRegisters(Reg); *R; R++)
82 RV.push_back(*R);
83 }
84
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000085 struct BBInfo {
86 // Is this MBB reachable from the MF entry point?
87 bool reachable;
88
89 // Vregs that must be live in because they are used without being
90 // defined. Map value is the user.
91 RegMap vregsLiveIn;
92
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000093 // Regs killed in MBB. They may be defined again, and will then be in both
94 // regsKilled and regsLiveOut.
95 RegSet regsKilled;
96
97 // Regs defined in MBB and live out. Note that vregs passing through may
98 // be live out without being mentioned here.
99 RegSet regsLiveOut;
100
101 // Vregs that pass through MBB untouched. This set is disjoint from
102 // regsKilled and regsLiveOut.
103 RegSet vregsPassed;
104
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000105 // Vregs that must pass through MBB because they are needed by a successor
106 // block. This set is disjoint from regsLiveOut.
107 RegSet vregsRequired;
108
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000109 BBInfo() : reachable(false) {}
110
111 // Add register to vregsPassed if it belongs there. Return true if
112 // anything changed.
113 bool addPassed(unsigned Reg) {
114 if (!TargetRegisterInfo::isVirtualRegister(Reg))
115 return false;
116 if (regsKilled.count(Reg) || regsLiveOut.count(Reg))
117 return false;
118 return vregsPassed.insert(Reg).second;
119 }
120
121 // Same for a full set.
122 bool addPassed(const RegSet &RS) {
123 bool changed = false;
124 for (RegSet::const_iterator I = RS.begin(), E = RS.end(); I != E; ++I)
125 if (addPassed(*I))
126 changed = true;
127 return changed;
128 }
129
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000130 // Add register to vregsRequired if it belongs there. Return true if
131 // anything changed.
132 bool addRequired(unsigned Reg) {
133 if (!TargetRegisterInfo::isVirtualRegister(Reg))
134 return false;
135 if (regsLiveOut.count(Reg))
136 return false;
137 return vregsRequired.insert(Reg).second;
138 }
139
140 // Same for a full set.
141 bool addRequired(const RegSet &RS) {
142 bool changed = false;
143 for (RegSet::const_iterator I = RS.begin(), E = RS.end(); I != E; ++I)
144 if (addRequired(*I))
145 changed = true;
146 return changed;
147 }
148
149 // Same for a full map.
150 bool addRequired(const RegMap &RM) {
151 bool changed = false;
152 for (RegMap::const_iterator I = RM.begin(), E = RM.end(); I != E; ++I)
153 if (addRequired(I->first))
154 changed = true;
155 return changed;
156 }
157
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000158 // Live-out registers are either in regsLiveOut or vregsPassed.
159 bool isLiveOut(unsigned Reg) const {
160 return regsLiveOut.count(Reg) || vregsPassed.count(Reg);
161 }
162 };
163
164 // Extra register info per MBB.
165 DenseMap<const MachineBasicBlock*, BBInfo> MBBInfoMap;
166
167 bool isReserved(unsigned Reg) {
Jakob Stoklund Olesend37bc5a2009-08-04 19:18:01 +0000168 return Reg < regsReserved.size() && regsReserved.test(Reg);
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000169 }
170
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000171 // Analysis information if available
172 LiveVariables *LiveVars;
Jakob Stoklund Olesen501dc422010-10-26 22:36:07 +0000173 LiveIntervals *LiveInts;
Jakob Stoklund Olesene8f08232010-11-01 19:49:52 +0000174 LiveStacks *LiveStks;
Jakob Stoklund Olesenf4a1e1a2010-10-26 20:21:46 +0000175 SlotIndexes *Indexes;
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000176
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000177 void visitMachineFunctionBefore();
178 void visitMachineBasicBlockBefore(const MachineBasicBlock *MBB);
179 void visitMachineInstrBefore(const MachineInstr *MI);
180 void visitMachineOperand(const MachineOperand *MO, unsigned MONum);
181 void visitMachineInstrAfter(const MachineInstr *MI);
182 void visitMachineBasicBlockAfter(const MachineBasicBlock *MBB);
183 void visitMachineFunctionAfter();
184
185 void report(const char *msg, const MachineFunction *MF);
186 void report(const char *msg, const MachineBasicBlock *MBB);
187 void report(const char *msg, const MachineInstr *MI);
188 void report(const char *msg, const MachineOperand *MO, unsigned MONum);
189
190 void markReachable(const MachineBasicBlock *MBB);
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000191 void calcRegsPassed();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000192 void checkPHIOps(const MachineBasicBlock *MBB);
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000193
194 void calcRegsRequired();
195 void verifyLiveVariables();
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +0000196 void verifyLiveIntervals();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000197 };
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000198
199 struct MachineVerifierPass : public MachineFunctionPass {
200 static char ID; // Pass ID, replacement for typeid
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +0000201 const char *const Banner;
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000202
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +0000203 MachineVerifierPass(const char *b = 0)
204 : MachineFunctionPass(ID), Banner(b) {
Owen Anderson081c34b2010-10-19 17:21:58 +0000205 initializeMachineVerifierPassPass(*PassRegistry::getPassRegistry());
206 }
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000207
208 void getAnalysisUsage(AnalysisUsage &AU) const {
209 AU.setPreservesAll();
210 MachineFunctionPass::getAnalysisUsage(AU);
211 }
212
213 bool runOnMachineFunction(MachineFunction &MF) {
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +0000214 MF.verify(this, Banner);
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000215 return false;
216 }
217 };
218
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000219}
220
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000221char MachineVerifierPass::ID = 0;
Owen Anderson02dd53e2010-08-23 17:52:01 +0000222INITIALIZE_PASS(MachineVerifierPass, "machineverifier",
Owen Andersonce665bd2010-10-07 22:25:06 +0000223 "Verify generated machine code", false, false)
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000224
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +0000225FunctionPass *llvm::createMachineVerifierPass(const char *Banner) {
226 return new MachineVerifierPass(Banner);
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000227}
228
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +0000229void MachineFunction::verify(Pass *p, const char *Banner) const {
230 MachineVerifier(p, Banner)
231 .runOnMachineFunction(const_cast<MachineFunction&>(*this));
Jakob Stoklund Olesence727d02009-11-13 21:56:09 +0000232}
233
Chris Lattner17e9edc2009-08-23 02:51:22 +0000234bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
235 raw_ostream *OutFile = 0;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000236 if (OutFileName) {
Chris Lattner17e9edc2009-08-23 02:51:22 +0000237 std::string ErrorInfo;
238 OutFile = new raw_fd_ostream(OutFileName, ErrorInfo,
239 raw_fd_ostream::F_Append);
240 if (!ErrorInfo.empty()) {
241 errs() << "Error opening '" << OutFileName << "': " << ErrorInfo << '\n';
242 exit(1);
243 }
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000244
Chris Lattner17e9edc2009-08-23 02:51:22 +0000245 OS = OutFile;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000246 } else {
Chris Lattner17e9edc2009-08-23 02:51:22 +0000247 OS = &errs();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000248 }
249
250 foundErrors = 0;
251
252 this->MF = &MF;
253 TM = &MF.getTarget();
254 TRI = TM->getRegisterInfo();
255 MRI = &MF.getRegInfo();
256
Jakob Stoklund Olesenc910c8d2010-08-05 23:51:26 +0000257 LiveVars = NULL;
258 LiveInts = NULL;
Jakob Stoklund Olesene8f08232010-11-01 19:49:52 +0000259 LiveStks = NULL;
Jakob Stoklund Olesenf4a1e1a2010-10-26 20:21:46 +0000260 Indexes = NULL;
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000261 if (PASS) {
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000262 LiveInts = PASS->getAnalysisIfAvailable<LiveIntervals>();
Jakob Stoklund Olesenc910c8d2010-08-05 23:51:26 +0000263 // We don't want to verify LiveVariables if LiveIntervals is available.
264 if (!LiveInts)
265 LiveVars = PASS->getAnalysisIfAvailable<LiveVariables>();
Jakob Stoklund Olesene8f08232010-11-01 19:49:52 +0000266 LiveStks = PASS->getAnalysisIfAvailable<LiveStacks>();
Jakob Stoklund Olesenf4a1e1a2010-10-26 20:21:46 +0000267 Indexes = PASS->getAnalysisIfAvailable<SlotIndexes>();
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000268 }
269
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000270 visitMachineFunctionBefore();
271 for (MachineFunction::const_iterator MFI = MF.begin(), MFE = MF.end();
272 MFI!=MFE; ++MFI) {
273 visitMachineBasicBlockBefore(MFI);
274 for (MachineBasicBlock::const_iterator MBBI = MFI->begin(),
275 MBBE = MFI->end(); MBBI != MBBE; ++MBBI) {
Jakob Stoklund Olesen7bd46da2011-01-12 21:27:41 +0000276 if (MBBI->getParent() != MFI) {
277 report("Bad instruction parent pointer", MFI);
278 *OS << "Instruction: " << *MBBI;
279 continue;
280 }
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000281 visitMachineInstrBefore(MBBI);
282 for (unsigned I = 0, E = MBBI->getNumOperands(); I != E; ++I)
283 visitMachineOperand(&MBBI->getOperand(I), I);
284 visitMachineInstrAfter(MBBI);
285 }
286 visitMachineBasicBlockAfter(MFI);
287 }
288 visitMachineFunctionAfter();
289
Chris Lattner17e9edc2009-08-23 02:51:22 +0000290 if (OutFile)
291 delete OutFile;
292 else if (foundErrors)
Chris Lattner75361b62010-04-07 22:58:41 +0000293 report_fatal_error("Found "+Twine(foundErrors)+" machine code errors.");
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000294
Jakob Stoklund Olesen63496682009-08-08 15:34:50 +0000295 // Clean up.
296 regsLive.clear();
297 regsDefined.clear();
298 regsDead.clear();
299 regsKilled.clear();
300 regsLiveInButUnused.clear();
301 MBBInfoMap.clear();
302
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000303 return false; // no changes
304}
305
Chris Lattner372fefe2009-08-23 01:03:30 +0000306void MachineVerifier::report(const char *msg, const MachineFunction *MF) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000307 assert(MF);
Chris Lattner17e9edc2009-08-23 02:51:22 +0000308 *OS << '\n';
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +0000309 if (!foundErrors++) {
310 if (Banner)
311 *OS << "# " << Banner << '\n';
Jakob Stoklund Olesenf4a1e1a2010-10-26 20:21:46 +0000312 MF->print(*OS, Indexes);
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +0000313 }
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000314 *OS << "*** Bad machine code: " << msg << " ***\n"
Daniel Dunbarce63ffb2009-07-25 00:23:56 +0000315 << "- function: " << MF->getFunction()->getNameStr() << "\n";
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000316}
317
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000318void MachineVerifier::report(const char *msg, const MachineBasicBlock *MBB) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000319 assert(MBB);
320 report(msg, MBB->getParent());
Jakob Stoklund Olesen324da762009-11-20 01:17:03 +0000321 *OS << "- basic block: " << MBB->getName()
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000322 << " " << (void*)MBB
Jakob Stoklund Olesenf4a1e1a2010-10-26 20:21:46 +0000323 << " (BB#" << MBB->getNumber() << ")";
324 if (Indexes)
325 *OS << " [" << Indexes->getMBBStartIdx(MBB)
326 << ';' << Indexes->getMBBEndIdx(MBB) << ')';
327 *OS << '\n';
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000328}
329
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000330void MachineVerifier::report(const char *msg, const MachineInstr *MI) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000331 assert(MI);
332 report(msg, MI->getParent());
333 *OS << "- instruction: ";
Jakob Stoklund Olesenf4a1e1a2010-10-26 20:21:46 +0000334 if (Indexes && Indexes->hasIndex(MI))
335 *OS << Indexes->getInstructionIndex(MI) << '\t';
Chris Lattner705e07f2009-08-23 03:41:05 +0000336 MI->print(*OS, TM);
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000337}
338
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000339void MachineVerifier::report(const char *msg,
340 const MachineOperand *MO, unsigned MONum) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000341 assert(MO);
342 report(msg, MO->getParent());
343 *OS << "- operand " << MONum << ": ";
344 MO->print(*OS, TM);
345 *OS << "\n";
346}
347
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000348void MachineVerifier::markReachable(const MachineBasicBlock *MBB) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000349 BBInfo &MInfo = MBBInfoMap[MBB];
350 if (!MInfo.reachable) {
351 MInfo.reachable = true;
352 for (MachineBasicBlock::const_succ_iterator SuI = MBB->succ_begin(),
353 SuE = MBB->succ_end(); SuI != SuE; ++SuI)
354 markReachable(*SuI);
355 }
356}
357
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000358void MachineVerifier::visitMachineFunctionBefore() {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000359 regsReserved = TRI->getReservedRegs(*MF);
Jakob Stoklund Olesend37bc5a2009-08-04 19:18:01 +0000360
361 // A sub-register of a reserved register is also reserved
362 for (int Reg = regsReserved.find_first(); Reg>=0;
363 Reg = regsReserved.find_next(Reg)) {
364 for (const unsigned *Sub = TRI->getSubRegisters(Reg); *Sub; ++Sub) {
365 // FIXME: This should probably be:
366 // assert(regsReserved.test(*Sub) && "Non-reserved sub-register");
367 regsReserved.set(*Sub);
368 }
369 }
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000370 markReachable(&MF->front());
371}
372
Jakob Stoklund Olesen1dc0fcb2009-11-13 21:55:54 +0000373// Does iterator point to a and b as the first two elements?
Dan Gohmanb3579832010-04-15 17:08:50 +0000374static bool matchPair(MachineBasicBlock::const_succ_iterator i,
375 const MachineBasicBlock *a, const MachineBasicBlock *b) {
Jakob Stoklund Olesen1dc0fcb2009-11-13 21:55:54 +0000376 if (*i == a)
377 return *++i == b;
378 if (*i == b)
379 return *++i == a;
380 return false;
381}
382
383void
384MachineVerifier::visitMachineBasicBlockBefore(const MachineBasicBlock *MBB) {
Dan Gohman27920592009-08-27 02:43:49 +0000385 const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
386
Jakob Stoklund Olesen0a7bbcb2010-10-21 18:47:06 +0000387 // Count the number of landing pad successors.
Cameron Zwarich2100d212010-12-20 04:19:48 +0000388 SmallPtrSet<MachineBasicBlock*, 4> LandingPadSuccs;
Jakob Stoklund Olesen0a7bbcb2010-10-21 18:47:06 +0000389 for (MachineBasicBlock::const_succ_iterator I = MBB->succ_begin(),
Cameron Zwarich2100d212010-12-20 04:19:48 +0000390 E = MBB->succ_end(); I != E; ++I) {
391 if ((*I)->isLandingPad())
392 LandingPadSuccs.insert(*I);
393 }
394 if (LandingPadSuccs.size() > 1)
Jakob Stoklund Olesen0a7bbcb2010-10-21 18:47:06 +0000395 report("MBB has more than one landing pad successor", MBB);
396
Dan Gohman27920592009-08-27 02:43:49 +0000397 // Call AnalyzeBranch. If it succeeds, there several more conditions to check.
398 MachineBasicBlock *TBB = 0, *FBB = 0;
399 SmallVector<MachineOperand, 4> Cond;
400 if (!TII->AnalyzeBranch(*const_cast<MachineBasicBlock *>(MBB),
401 TBB, FBB, Cond)) {
402 // Ok, AnalyzeBranch thinks it knows what's going on with this block. Let's
403 // check whether its answers match up with reality.
404 if (!TBB && !FBB) {
405 // Block falls through to its successor.
406 MachineFunction::const_iterator MBBI = MBB;
407 ++MBBI;
408 if (MBBI == MF->end()) {
Dan Gohmana01a80f2009-08-27 18:14:26 +0000409 // It's possible that the block legitimately ends with a noreturn
410 // call or an unreachable, in which case it won't actually fall
411 // out the bottom of the function.
Cameron Zwarich2100d212010-12-20 04:19:48 +0000412 } else if (MBB->succ_size() == LandingPadSuccs.size()) {
Dan Gohmana01a80f2009-08-27 18:14:26 +0000413 // It's possible that the block legitimately ends with a noreturn
414 // call or an unreachable, in which case it won't actuall fall
415 // out of the block.
Cameron Zwarich2100d212010-12-20 04:19:48 +0000416 } else if (MBB->succ_size() != 1+LandingPadSuccs.size()) {
Dan Gohman27920592009-08-27 02:43:49 +0000417 report("MBB exits via unconditional fall-through but doesn't have "
418 "exactly one CFG successor!", MBB);
Jakob Stoklund Olesen0a7bbcb2010-10-21 18:47:06 +0000419 } else if (!MBB->isSuccessor(MBBI)) {
Dan Gohman27920592009-08-27 02:43:49 +0000420 report("MBB exits via unconditional fall-through but its successor "
421 "differs from its CFG successor!", MBB);
422 }
Evan Cheng86050dc2010-06-18 23:09:54 +0000423 if (!MBB->empty() && MBB->back().getDesc().isBarrier() &&
424 !TII->isPredicated(&MBB->back())) {
Dan Gohman27920592009-08-27 02:43:49 +0000425 report("MBB exits via unconditional fall-through but ends with a "
426 "barrier instruction!", MBB);
427 }
428 if (!Cond.empty()) {
429 report("MBB exits via unconditional fall-through but has a condition!",
430 MBB);
431 }
432 } else if (TBB && !FBB && Cond.empty()) {
433 // Block unconditionally branches somewhere.
Cameron Zwarich2100d212010-12-20 04:19:48 +0000434 if (MBB->succ_size() != 1+LandingPadSuccs.size()) {
Dan Gohman27920592009-08-27 02:43:49 +0000435 report("MBB exits via unconditional branch but doesn't have "
436 "exactly one CFG successor!", MBB);
Jakob Stoklund Olesen0a7bbcb2010-10-21 18:47:06 +0000437 } else if (!MBB->isSuccessor(TBB)) {
Dan Gohman27920592009-08-27 02:43:49 +0000438 report("MBB exits via unconditional branch but the CFG "
439 "successor doesn't match the actual successor!", MBB);
440 }
441 if (MBB->empty()) {
442 report("MBB exits via unconditional branch but doesn't contain "
443 "any instructions!", MBB);
444 } else if (!MBB->back().getDesc().isBarrier()) {
445 report("MBB exits via unconditional branch but doesn't end with a "
446 "barrier instruction!", MBB);
447 } else if (!MBB->back().getDesc().isTerminator()) {
448 report("MBB exits via unconditional branch but the branch isn't a "
449 "terminator instruction!", MBB);
450 }
451 } else if (TBB && !FBB && !Cond.empty()) {
452 // Block conditionally branches somewhere, otherwise falls through.
453 MachineFunction::const_iterator MBBI = MBB;
454 ++MBBI;
455 if (MBBI == MF->end()) {
456 report("MBB conditionally falls through out of function!", MBB);
457 } if (MBB->succ_size() != 2) {
458 report("MBB exits via conditional branch/fall-through but doesn't have "
459 "exactly two CFG successors!", MBB);
Jakob Stoklund Olesen1dc0fcb2009-11-13 21:55:54 +0000460 } else if (!matchPair(MBB->succ_begin(), TBB, MBBI)) {
Dan Gohman27920592009-08-27 02:43:49 +0000461 report("MBB exits via conditional branch/fall-through but the CFG "
462 "successors don't match the actual successors!", MBB);
463 }
464 if (MBB->empty()) {
465 report("MBB exits via conditional branch/fall-through but doesn't "
466 "contain any instructions!", MBB);
467 } else if (MBB->back().getDesc().isBarrier()) {
468 report("MBB exits via conditional branch/fall-through but ends with a "
469 "barrier instruction!", MBB);
470 } else if (!MBB->back().getDesc().isTerminator()) {
471 report("MBB exits via conditional branch/fall-through but the branch "
472 "isn't a terminator instruction!", MBB);
473 }
474 } else if (TBB && FBB) {
475 // Block conditionally branches somewhere, otherwise branches
476 // somewhere else.
477 if (MBB->succ_size() != 2) {
478 report("MBB exits via conditional branch/branch but doesn't have "
479 "exactly two CFG successors!", MBB);
Jakob Stoklund Olesen1dc0fcb2009-11-13 21:55:54 +0000480 } else if (!matchPair(MBB->succ_begin(), TBB, FBB)) {
Dan Gohman27920592009-08-27 02:43:49 +0000481 report("MBB exits via conditional branch/branch but the CFG "
482 "successors don't match the actual successors!", MBB);
483 }
484 if (MBB->empty()) {
485 report("MBB exits via conditional branch/branch but doesn't "
486 "contain any instructions!", MBB);
487 } else if (!MBB->back().getDesc().isBarrier()) {
488 report("MBB exits via conditional branch/branch but doesn't end with a "
489 "barrier instruction!", MBB);
490 } else if (!MBB->back().getDesc().isTerminator()) {
491 report("MBB exits via conditional branch/branch but the branch "
492 "isn't a terminator instruction!", MBB);
493 }
494 if (Cond.empty()) {
495 report("MBB exits via conditinal branch/branch but there's no "
496 "condition!", MBB);
497 }
498 } else {
499 report("AnalyzeBranch returned invalid data!", MBB);
500 }
501 }
502
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000503 regsLive.clear();
Dan Gohman81bf03e2010-04-13 16:57:55 +0000504 for (MachineBasicBlock::livein_iterator I = MBB->livein_begin(),
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000505 E = MBB->livein_end(); I != E; ++I) {
506 if (!TargetRegisterInfo::isPhysicalRegister(*I)) {
507 report("MBB live-in list contains non-physical register", MBB);
508 continue;
509 }
510 regsLive.insert(*I);
511 for (const unsigned *R = TRI->getSubRegisters(*I); *R; R++)
512 regsLive.insert(*R);
513 }
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000514 regsLiveInButUnused = regsLive;
Jakob Stoklund Olesena6b677d2009-08-13 16:19:51 +0000515
516 const MachineFrameInfo *MFI = MF->getFrameInfo();
517 assert(MFI && "Function has no frame info");
518 BitVector PR = MFI->getPristineRegs(MBB);
519 for (int I = PR.find_first(); I>0; I = PR.find_next(I)) {
520 regsLive.insert(I);
521 for (const unsigned *R = TRI->getSubRegisters(I); *R; R++)
522 regsLive.insert(*R);
523 }
524
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000525 regsKilled.clear();
526 regsDefined.clear();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000527}
528
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000529void MachineVerifier::visitMachineInstrBefore(const MachineInstr *MI) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000530 const TargetInstrDesc &TI = MI->getDesc();
Jakob Stoklund Olesen39523e22009-09-23 20:57:55 +0000531 if (MI->getNumOperands() < TI.getNumOperands()) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000532 report("Too few operands", MI);
533 *OS << TI.getNumOperands() << " operands expected, but "
534 << MI->getNumExplicitOperands() << " given.\n";
535 }
Dan Gohman2dbc4c82009-10-07 17:36:00 +0000536
537 // Check the MachineMemOperands for basic consistency.
538 for (MachineInstr::mmo_iterator I = MI->memoperands_begin(),
539 E = MI->memoperands_end(); I != E; ++I) {
540 if ((*I)->isLoad() && !TI.mayLoad())
541 report("Missing mayLoad flag", MI);
542 if ((*I)->isStore() && !TI.mayStore())
543 report("Missing mayStore flag", MI);
544 }
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000545
546 // Debug values must not have a slot index.
547 // Other instructions must have one.
548 if (LiveInts) {
549 bool mapped = !LiveInts->isNotInMIMap(MI);
550 if (MI->isDebugValue()) {
551 if (mapped)
552 report("Debug instruction has a slot index", MI);
553 } else {
554 if (!mapped)
555 report("Missing slot index", MI);
556 }
557 }
558
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000559}
560
561void
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000562MachineVerifier::visitMachineOperand(const MachineOperand *MO, unsigned MONum) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000563 const MachineInstr *MI = MO->getParent();
Jakob Stoklund Olesen44b27e52009-05-16 07:25:20 +0000564 const TargetInstrDesc &TI = MI->getDesc();
Cameron Zwarich22d67cf2010-12-19 21:37:23 +0000565 const TargetOperandInfo &TOI = TI.OpInfo[MONum];
Jakob Stoklund Olesen44b27e52009-05-16 07:25:20 +0000566
567 // The first TI.NumDefs operands must be explicit register defines
568 if (MONum < TI.getNumDefs()) {
569 if (!MO->isReg())
570 report("Explicit definition must be a register", MO, MONum);
571 else if (!MO->isDef())
572 report("Explicit definition marked as use", MO, MONum);
573 else if (MO->isImplicit())
574 report("Explicit definition marked as implicit", MO, MONum);
Jakob Stoklund Olesen39523e22009-09-23 20:57:55 +0000575 } else if (MONum < TI.getNumOperands()) {
Eric Christopher113a06c2010-11-17 00:55:36 +0000576 // Don't check if it's the last operand in a variadic instruction. See,
577 // e.g., LDM_RET in the arm back end.
578 if (MO->isReg() && !(TI.isVariadic() && MONum == TI.getNumOperands()-1)) {
Cameron Zwarich22d67cf2010-12-19 21:37:23 +0000579 if (MO->isDef() && !TOI.isOptionalDef())
580 report("Explicit operand marked as def", MO, MONum);
Jakob Stoklund Olesen39523e22009-09-23 20:57:55 +0000581 if (MO->isImplicit())
582 report("Explicit operand marked as implicit", MO, MONum);
583 }
584 } else {
Jakob Stoklund Olesen57115642009-12-22 21:48:20 +0000585 // ARM adds %reg0 operands to indicate predicates. We'll allow that.
586 if (MO->isReg() && !MO->isImplicit() && !TI.isVariadic() && MO->getReg())
Jakob Stoklund Olesen39523e22009-09-23 20:57:55 +0000587 report("Extra explicit operand on non-variadic instruction", MO, MONum);
Jakob Stoklund Olesen44b27e52009-05-16 07:25:20 +0000588 }
589
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000590 switch (MO->getType()) {
591 case MachineOperand::MO_Register: {
592 const unsigned Reg = MO->getReg();
593 if (!Reg)
594 return;
595
596 // Check Live Variables.
Cameron Zwarich8ec88ba2010-12-20 00:08:10 +0000597 if (MI->isDebugValue()) {
598 // Liveness checks are not valid for debug values.
599 } else if (MO->isUndef()) {
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000600 // An <undef> doesn't refer to any register, so just skip it.
601 } else if (MO->isUse()) {
602 regsLiveInButUnused.erase(Reg);
603
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000604 bool isKill = false;
Jakob Stoklund Olesen1b2c7612010-05-14 20:28:32 +0000605 unsigned defIdx;
606 if (MI->isRegTiedToDefOperand(MONum, &defIdx)) {
607 // A two-addr use counts as a kill if use and def are the same.
608 unsigned DefReg = MI->getOperand(defIdx).getReg();
609 if (Reg == DefReg) {
610 isKill = true;
Jakob Stoklund Olesen1c163d22010-11-01 21:51:31 +0000611 // And in that case an explicit kill flag is not allowed.
Jakob Stoklund Olesen1b2c7612010-05-14 20:28:32 +0000612 if (MO->isKill())
Jakob Stoklund Olesenf7d3e692009-07-15 23:37:26 +0000613 report("Illegal kill flag on two-address instruction operand",
614 MO, MONum);
Jakob Stoklund Olesen1b2c7612010-05-14 20:28:32 +0000615 } else if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
616 report("Two-address instruction operands must be identical",
617 MO, MONum);
618 }
619 } else
620 isKill = MO->isKill();
621
Jakob Stoklund Olesenc910c8d2010-08-05 23:51:26 +0000622 if (isKill)
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000623 addRegWithSubRegs(regsKilled, Reg);
624
Jakob Stoklund Olesenc910c8d2010-08-05 23:51:26 +0000625 // Check that LiveVars knows this kill.
626 if (LiveVars && TargetRegisterInfo::isVirtualRegister(Reg) &&
627 MO->isKill()) {
628 LiveVariables::VarInfo &VI = LiveVars->getVarInfo(Reg);
629 if (std::find(VI.Kills.begin(),
630 VI.Kills.end(), MI) == VI.Kills.end())
631 report("Kill missing from LiveVariables", MO, MONum);
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000632 }
633
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000634 // Check LiveInts liveness and kill.
Jakob Stoklund Olesenab566472010-10-30 01:26:11 +0000635 if (TargetRegisterInfo::isVirtualRegister(Reg) &&
636 LiveInts && !LiveInts->isNotInMIMap(MI)) {
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000637 SlotIndex UseIdx = LiveInts->getInstructionIndex(MI).getUseIndex();
638 if (LiveInts->hasInterval(Reg)) {
639 const LiveInterval &LI = LiveInts->getInterval(Reg);
640 if (!LI.liveAt(UseIdx)) {
641 report("No live range at use", MO, MONum);
642 *OS << UseIdx << " is not live in " << LI << '\n';
643 }
Jakob Stoklund Olesen1c163d22010-11-01 21:51:31 +0000644 // Verify isKill == LI.killedAt.
Jakob Stoklund Olesen2f3a4aa2010-12-17 19:18:41 +0000645 // Two-address instrs don't have kill flags on the tied operands, and
646 // we even allow
647 // %r1 = add %r1, %r1
648 // without a kill flag on the untied operand.
649 // MI->findRegisterUseOperandIdx finds the first operand using reg.
650 if (!MI->isRegTiedToDefOperand(MI->findRegisterUseOperandIdx(Reg))) {
Jakob Stoklund Olesen962c7102010-11-01 23:59:53 +0000651 // MI could kill register without a kill flag on MO.
652 bool miKill = MI->killsRegister(Reg);
Jakob Stoklund Olesen1c163d22010-11-01 21:51:31 +0000653 bool liKill = LI.killedAt(UseIdx.getDefIndex());
Jakob Stoklund Olesen962c7102010-11-01 23:59:53 +0000654 if (miKill && !liKill) {
Jakob Stoklund Olesen1c163d22010-11-01 21:51:31 +0000655 report("Live range continues after kill flag", MO, MONum);
656 *OS << "Live range: " << LI << '\n';
657 }
Jakob Stoklund Olesen962c7102010-11-01 23:59:53 +0000658 if (!miKill && liKill) {
Jakob Stoklund Olesen1c163d22010-11-01 21:51:31 +0000659 report("Live range ends without kill flag", MO, MONum);
660 *OS << "Live range: " << LI << '\n';
661 }
662 }
Jakob Stoklund Olesenab566472010-10-30 01:26:11 +0000663 } else {
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000664 report("Virtual register has no Live interval", MO, MONum);
665 }
666 }
667
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000668 // Use of a dead register.
669 if (!regsLive.count(Reg)) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000670 if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
671 // Reserved registers may be used even when 'dead'.
672 if (!isReserved(Reg))
673 report("Using an undefined physical register", MO, MONum);
674 } else {
675 BBInfo &MInfo = MBBInfoMap[MI->getParent()];
676 // We don't know which virtual registers are live in, so only complain
677 // if vreg was killed in this MBB. Otherwise keep track of vregs that
678 // must be live in. PHI instructions are handled separately.
679 if (MInfo.regsKilled.count(Reg))
680 report("Using a killed virtual register", MO, MONum);
Chris Lattner518bb532010-02-09 19:54:29 +0000681 else if (!MI->isPHI())
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000682 MInfo.vregsLiveIn.insert(std::make_pair(Reg, MI));
683 }
Duncan Sandse5567202009-05-16 03:28:54 +0000684 }
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000685 } else {
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000686 assert(MO->isDef());
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000687 // Register defined.
688 // TODO: verify that earlyclobber ops are not used.
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000689 if (MO->isDead())
690 addRegWithSubRegs(regsDead, Reg);
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000691 else
692 addRegWithSubRegs(regsDefined, Reg);
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000693
Jakob Stoklund Olesen775aa222010-08-06 18:04:14 +0000694 // Check LiveInts for a live range, but only for virtual registers.
695 if (LiveInts && TargetRegisterInfo::isVirtualRegister(Reg) &&
696 !LiveInts->isNotInMIMap(MI)) {
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000697 SlotIndex DefIdx = LiveInts->getInstructionIndex(MI).getDefIndex();
698 if (LiveInts->hasInterval(Reg)) {
699 const LiveInterval &LI = LiveInts->getInterval(Reg);
Jakob Stoklund Olesened826352010-10-02 05:24:46 +0000700 if (const VNInfo *VNI = LI.getVNInfoAt(DefIdx)) {
701 assert(VNI && "NULL valno is not allowed");
Cameron Zwarich1b031dd2010-12-19 23:50:53 +0000702 if (VNI->def != DefIdx && !MO->isEarlyClobber()) {
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000703 report("Inconsistent valno->def", MO, MONum);
Jakob Stoklund Olesened826352010-10-02 05:24:46 +0000704 *OS << "Valno " << VNI->id << " is not defined at "
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000705 << DefIdx << " in " << LI << '\n';
706 }
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000707 } else {
708 report("No live range at def", MO, MONum);
709 *OS << DefIdx << " is not live in " << LI << '\n';
710 }
Jakob Stoklund Olesen775aa222010-08-06 18:04:14 +0000711 } else {
Jakob Stoklund Olesen1fe9c342010-08-05 22:32:21 +0000712 report("Virtual register has no Live interval", MO, MONum);
713 }
714 }
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000715 }
716
717 // Check register classes.
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000718 if (MONum < TI.getNumOperands() && !MO->isImplicit()) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000719 unsigned SubIdx = MO->getSubReg();
720
721 if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
722 unsigned sr = Reg;
723 if (SubIdx) {
724 unsigned s = TRI->getSubReg(Reg, SubIdx);
725 if (!s) {
726 report("Invalid subregister index for physical register",
727 MO, MONum);
728 return;
729 }
730 sr = s;
731 }
Chris Lattnercb778a82009-07-29 21:10:12 +0000732 if (const TargetRegisterClass *DRC = TOI.getRegClass(TRI)) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000733 if (!DRC->contains(sr)) {
734 report("Illegal physical register for instruction", MO, MONum);
735 *OS << TRI->getName(sr) << " is not a "
736 << DRC->getName() << " register.\n";
737 }
738 }
739 } else {
740 // Virtual register.
741 const TargetRegisterClass *RC = MRI->getRegClass(Reg);
742 if (SubIdx) {
Jakob Stoklund Olesen6a8d2c62010-05-18 17:31:12 +0000743 const TargetRegisterClass *SRC = RC->getSubRegisterRegClass(SubIdx);
744 if (!SRC) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000745 report("Invalid subregister index for virtual register", MO, MONum);
Jakob Stoklund Olesen6a8d2c62010-05-18 17:31:12 +0000746 *OS << "Register class " << RC->getName()
747 << " does not support subreg index " << SubIdx << "\n";
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000748 return;
749 }
Jakob Stoklund Olesen6a8d2c62010-05-18 17:31:12 +0000750 RC = SRC;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000751 }
Chris Lattnercb778a82009-07-29 21:10:12 +0000752 if (const TargetRegisterClass *DRC = TOI.getRegClass(TRI)) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000753 if (RC != DRC && !RC->hasSuperClass(DRC)) {
754 report("Illegal virtual register for instruction", MO, MONum);
755 *OS << "Expected a " << DRC->getName() << " register, but got a "
756 << RC->getName() << " register\n";
757 }
758 }
759 }
760 }
761 break;
762 }
Jakob Stoklund Olesena5ba07c2009-09-21 07:19:08 +0000763
764 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner518bb532010-02-09 19:54:29 +0000765 if (MI->isPHI() && !MO->getMBB()->isSuccessor(MI->getParent()))
766 report("PHI operand is not in the CFG", MO, MONum);
Jakob Stoklund Olesena5ba07c2009-09-21 07:19:08 +0000767 break;
768
Jakob Stoklund Olesene8f08232010-11-01 19:49:52 +0000769 case MachineOperand::MO_FrameIndex:
770 if (LiveStks && LiveStks->hasInterval(MO->getIndex()) &&
771 LiveInts && !LiveInts->isNotInMIMap(MI)) {
772 LiveInterval &LI = LiveStks->getInterval(MO->getIndex());
773 SlotIndex Idx = LiveInts->getInstructionIndex(MI);
774 if (TI.mayLoad() && !LI.liveAt(Idx.getUseIndex())) {
775 report("Instruction loads from dead spill slot", MO, MONum);
776 *OS << "Live stack: " << LI << '\n';
777 }
778 if (TI.mayStore() && !LI.liveAt(Idx.getDefIndex())) {
779 report("Instruction stores to dead spill slot", MO, MONum);
780 *OS << "Live stack: " << LI << '\n';
781 }
782 }
783 break;
784
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000785 default:
786 break;
787 }
788}
789
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000790void MachineVerifier::visitMachineInstrAfter(const MachineInstr *MI) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000791 BBInfo &MInfo = MBBInfoMap[MI->getParent()];
792 set_union(MInfo.regsKilled, regsKilled);
Jakob Stoklund Olesen73cf7092010-08-05 18:59:59 +0000793 set_subtract(regsLive, regsKilled); regsKilled.clear();
794 set_subtract(regsLive, regsDead); regsDead.clear();
795 set_union(regsLive, regsDefined); regsDefined.clear();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000796}
797
798void
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000799MachineVerifier::visitMachineBasicBlockAfter(const MachineBasicBlock *MBB) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000800 MBBInfoMap[MBB].regsLiveOut = regsLive;
801 regsLive.clear();
802}
803
804// Calculate the largest possible vregsPassed sets. These are the registers that
805// can pass through an MBB live, but may not be live every time. It is assumed
806// that all vregsPassed sets are empty before the call.
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000807void MachineVerifier::calcRegsPassed() {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000808 // First push live-out regs to successors' vregsPassed. Remember the MBBs that
809 // have any vregsPassed.
810 DenseSet<const MachineBasicBlock*> todo;
811 for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end();
812 MFI != MFE; ++MFI) {
813 const MachineBasicBlock &MBB(*MFI);
814 BBInfo &MInfo = MBBInfoMap[&MBB];
815 if (!MInfo.reachable)
816 continue;
817 for (MachineBasicBlock::const_succ_iterator SuI = MBB.succ_begin(),
818 SuE = MBB.succ_end(); SuI != SuE; ++SuI) {
819 BBInfo &SInfo = MBBInfoMap[*SuI];
820 if (SInfo.addPassed(MInfo.regsLiveOut))
821 todo.insert(*SuI);
822 }
823 }
824
825 // Iteratively push vregsPassed to successors. This will converge to the same
826 // final state regardless of DenseSet iteration order.
827 while (!todo.empty()) {
828 const MachineBasicBlock *MBB = *todo.begin();
829 todo.erase(MBB);
830 BBInfo &MInfo = MBBInfoMap[MBB];
831 for (MachineBasicBlock::const_succ_iterator SuI = MBB->succ_begin(),
832 SuE = MBB->succ_end(); SuI != SuE; ++SuI) {
833 if (*SuI == MBB)
834 continue;
835 BBInfo &SInfo = MBBInfoMap[*SuI];
836 if (SInfo.addPassed(MInfo.vregsPassed))
837 todo.insert(*SuI);
838 }
839 }
840}
841
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000842// Calculate the set of virtual registers that must be passed through each basic
843// block in order to satisfy the requirements of successor blocks. This is very
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000844// similar to calcRegsPassed, only backwards.
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000845void MachineVerifier::calcRegsRequired() {
846 // First push live-in regs to predecessors' vregsRequired.
847 DenseSet<const MachineBasicBlock*> todo;
848 for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end();
849 MFI != MFE; ++MFI) {
850 const MachineBasicBlock &MBB(*MFI);
851 BBInfo &MInfo = MBBInfoMap[&MBB];
852 for (MachineBasicBlock::const_pred_iterator PrI = MBB.pred_begin(),
853 PrE = MBB.pred_end(); PrI != PrE; ++PrI) {
854 BBInfo &PInfo = MBBInfoMap[*PrI];
855 if (PInfo.addRequired(MInfo.vregsLiveIn))
856 todo.insert(*PrI);
857 }
858 }
859
860 // Iteratively push vregsRequired to predecessors. This will converge to the
861 // same final state regardless of DenseSet iteration order.
862 while (!todo.empty()) {
863 const MachineBasicBlock *MBB = *todo.begin();
864 todo.erase(MBB);
865 BBInfo &MInfo = MBBInfoMap[MBB];
866 for (MachineBasicBlock::const_pred_iterator PrI = MBB->pred_begin(),
867 PrE = MBB->pred_end(); PrI != PrE; ++PrI) {
868 if (*PrI == MBB)
869 continue;
870 BBInfo &SInfo = MBBInfoMap[*PrI];
871 if (SInfo.addRequired(MInfo.vregsRequired))
872 todo.insert(*PrI);
873 }
874 }
875}
876
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000877// Check PHI instructions at the beginning of MBB. It is assumed that
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000878// calcRegsPassed has been run so BBInfo::isLiveOut is valid.
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000879void MachineVerifier::checkPHIOps(const MachineBasicBlock *MBB) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000880 for (MachineBasicBlock::const_iterator BBI = MBB->begin(), BBE = MBB->end();
Chris Lattner518bb532010-02-09 19:54:29 +0000881 BBI != BBE && BBI->isPHI(); ++BBI) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000882 DenseSet<const MachineBasicBlock*> seen;
883
884 for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) {
885 unsigned Reg = BBI->getOperand(i).getReg();
886 const MachineBasicBlock *Pre = BBI->getOperand(i + 1).getMBB();
887 if (!Pre->isSuccessor(MBB))
888 continue;
889 seen.insert(Pre);
890 BBInfo &PrInfo = MBBInfoMap[Pre];
891 if (PrInfo.reachable && !PrInfo.isLiveOut(Reg))
892 report("PHI operand is not live-out from predecessor",
893 &BBI->getOperand(i), i);
894 }
895
896 // Did we see all predecessors?
897 for (MachineBasicBlock::const_pred_iterator PrI = MBB->pred_begin(),
898 PrE = MBB->pred_end(); PrI != PrE; ++PrI) {
899 if (!seen.count(*PrI)) {
900 report("Missing PHI operand", BBI);
Dan Gohman0ba90f32009-10-31 20:19:03 +0000901 *OS << "BB#" << (*PrI)->getNumber()
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000902 << " is a predecessor according to the CFG.\n";
903 }
904 }
905 }
906}
907
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000908void MachineVerifier::visitMachineFunctionAfter() {
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000909 calcRegsPassed();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000910
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000911 for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end();
912 MFI != MFE; ++MFI) {
913 BBInfo &MInfo = MBBInfoMap[MFI];
914
915 // Skip unreachable MBBs.
916 if (!MInfo.reachable)
917 continue;
918
919 checkPHIOps(MFI);
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000920 }
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000921
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +0000922 // Now check liveness info if available
923 if (LiveVars || LiveInts)
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000924 calcRegsRequired();
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +0000925 if (LiveVars)
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000926 verifyLiveVariables();
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +0000927 if (LiveInts)
928 verifyLiveIntervals();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000929}
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000930
931void MachineVerifier::verifyLiveVariables() {
932 assert(LiveVars && "Don't call verifyLiveVariables without LiveVars");
Jakob Stoklund Olesen98c54762011-01-08 23:11:02 +0000933 for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
934 unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000935 LiveVariables::VarInfo &VI = LiveVars->getVarInfo(Reg);
936 for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end();
937 MFI != MFE; ++MFI) {
938 BBInfo &MInfo = MBBInfoMap[MFI];
939
940 // Our vregsRequired should be identical to LiveVariables' AliveBlocks
941 if (MInfo.vregsRequired.count(Reg)) {
942 if (!VI.AliveBlocks.test(MFI->getNumber())) {
943 report("LiveVariables: Block missing from AliveBlocks", MFI);
Jakob Stoklund Olesen43142682011-01-09 03:05:53 +0000944 *OS << "Virtual register " << PrintReg(Reg)
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000945 << " must be live through the block.\n";
946 }
947 } else {
948 if (VI.AliveBlocks.test(MFI->getNumber())) {
949 report("LiveVariables: Block should not be in AliveBlocks", MFI);
Jakob Stoklund Olesen43142682011-01-09 03:05:53 +0000950 *OS << "Virtual register " << PrintReg(Reg)
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000951 << " is not needed live through the block.\n";
952 }
953 }
954 }
955 }
956}
957
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +0000958void MachineVerifier::verifyLiveIntervals() {
959 assert(LiveInts && "Don't call verifyLiveIntervals without LiveInts");
960 for (LiveIntervals::const_iterator LVI = LiveInts->begin(),
961 LVE = LiveInts->end(); LVI != LVE; ++LVI) {
962 const LiveInterval &LI = *LVI->second;
Jakob Stoklund Olesen893ab5d2010-10-06 23:54:35 +0000963
964 // Spilling and splitting may leave unused registers around. Skip them.
965 if (MRI->use_empty(LI.reg))
966 continue;
967
Jakob Stoklund Olesen8c456422010-10-28 20:44:22 +0000968 // Physical registers have much weirdness going on, mostly from coalescing.
969 // We should probably fix it, but for now just ignore them.
970 if (TargetRegisterInfo::isPhysicalRegister(LI.reg))
971 continue;
972
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +0000973 assert(LVI->first == LI.reg && "Invalid reg to interval mapping");
974
975 for (LiveInterval::const_vni_iterator I = LI.vni_begin(), E = LI.vni_end();
976 I!=E; ++I) {
977 VNInfo *VNI = *I;
Jakob Stoklund Olesened826352010-10-02 05:24:46 +0000978 const VNInfo *DefVNI = LI.getVNInfoAt(VNI->def);
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +0000979
Jakob Stoklund Olesened826352010-10-02 05:24:46 +0000980 if (!DefVNI) {
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +0000981 if (!VNI->isUnused()) {
982 report("Valno not live at def and not marked unused", MF);
983 *OS << "Valno #" << VNI->id << " in " << LI << '\n';
984 }
985 continue;
986 }
987
988 if (VNI->isUnused())
989 continue;
990
Jakob Stoklund Olesened826352010-10-02 05:24:46 +0000991 if (DefVNI != VNI) {
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +0000992 report("Live range at def has different valno", MF);
Jakob Stoklund Olesened826352010-10-02 05:24:46 +0000993 *OS << "Valno #" << VNI->id << " is defined at " << VNI->def
Jakob Stoklund Olesendbcc2e12010-10-26 20:21:43 +0000994 << " where valno #" << DefVNI->id << " is live in " << LI << '\n';
Jakob Stoklund Olesen3bf7cf92010-10-22 22:48:58 +0000995 continue;
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +0000996 }
997
Jakob Stoklund Olesen3bf7cf92010-10-22 22:48:58 +0000998 const MachineBasicBlock *MBB = LiveInts->getMBBFromIndex(VNI->def);
999 if (!MBB) {
1000 report("Invalid definition index", MF);
Jakob Stoklund Olesendbcc2e12010-10-26 20:21:43 +00001001 *OS << "Valno #" << VNI->id << " is defined at " << VNI->def
1002 << " in " << LI << '\n';
Jakob Stoklund Olesen3bf7cf92010-10-22 22:48:58 +00001003 continue;
1004 }
1005
1006 if (VNI->isPHIDef()) {
1007 if (VNI->def != LiveInts->getMBBStartIdx(MBB)) {
1008 report("PHIDef value is not defined at MBB start", MF);
1009 *OS << "Valno #" << VNI->id << " is defined at " << VNI->def
Jakob Stoklund Olesendbcc2e12010-10-26 20:21:43 +00001010 << ", not at the beginning of BB#" << MBB->getNumber()
1011 << " in " << LI << '\n';
Jakob Stoklund Olesen3bf7cf92010-10-22 22:48:58 +00001012 }
1013 } else {
1014 // Non-PHI def.
Jakob Stoklund Olesen3bf7cf92010-10-22 22:48:58 +00001015 const MachineInstr *MI = LiveInts->getInstructionFromIndex(VNI->def);
1016 if (!MI) {
1017 report("No instruction at def index", MF);
Jakob Stoklund Olesen78716872010-10-23 00:49:09 +00001018 *OS << "Valno #" << VNI->id << " is defined at " << VNI->def
1019 << " in " << LI << '\n';
Jakob Stoklund Olesen3bf7cf92010-10-22 22:48:58 +00001020 } else if (!MI->modifiesRegister(LI.reg, TRI)) {
1021 report("Defining instruction does not modify register", MI);
1022 *OS << "Valno #" << VNI->id << " in " << LI << '\n';
1023 }
Cameron Zwarich0b13d7d2010-12-20 03:15:20 +00001024
1025 bool isEarlyClobber = false;
1026 if (MI) {
1027 for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(),
1028 MOE = MI->operands_end(); MOI != MOE; ++MOI) {
1029 if (MOI->isReg() && MOI->getReg() == LI.reg && MOI->isDef() &&
1030 MOI->isEarlyClobber()) {
1031 isEarlyClobber = true;
1032 break;
1033 }
1034 }
1035 }
1036
1037 // Early clobber defs begin at USE slots, but other defs must begin at
1038 // DEF slots.
1039 if (isEarlyClobber) {
1040 if (!VNI->def.isUse()) {
1041 report("Early clobber def must be at a USE slot", MF);
1042 *OS << "Valno #" << VNI->id << " is defined at " << VNI->def
1043 << " in " << LI << '\n';
1044 }
1045 } else if (!VNI->def.isDef()) {
1046 report("Non-PHI, non-early clobber def must be at a DEF slot", MF);
1047 *OS << "Valno #" << VNI->id << " is defined at " << VNI->def
1048 << " in " << LI << '\n';
1049 }
Jakob Stoklund Olesen3bf7cf92010-10-22 22:48:58 +00001050 }
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +00001051 }
1052
1053 for (LiveInterval::const_iterator I = LI.begin(), E = LI.end(); I!=E; ++I) {
Jakob Stoklund Olesened826352010-10-02 05:24:46 +00001054 const VNInfo *VNI = I->valno;
1055 assert(VNI && "Live range has no valno");
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +00001056
Jakob Stoklund Olesened826352010-10-02 05:24:46 +00001057 if (VNI->id >= LI.getNumValNums() || VNI != LI.getValNumInfo(VNI->id)) {
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +00001058 report("Foreign valno in live range", MF);
Jakob Stoklund Olesened826352010-10-02 05:24:46 +00001059 I->print(*OS);
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +00001060 *OS << " has a valno not in " << LI << '\n';
1061 }
1062
Jakob Stoklund Olesened826352010-10-02 05:24:46 +00001063 if (VNI->isUnused()) {
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +00001064 report("Live range valno is marked unused", MF);
Jakob Stoklund Olesened826352010-10-02 05:24:46 +00001065 I->print(*OS);
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +00001066 *OS << " in " << LI << '\n';
1067 }
1068
Jakob Stoklund Olesen78716872010-10-23 00:49:09 +00001069 const MachineBasicBlock *MBB = LiveInts->getMBBFromIndex(I->start);
1070 if (!MBB) {
1071 report("Bad start of live segment, no basic block", MF);
1072 I->print(*OS);
1073 *OS << " in " << LI << '\n';
1074 continue;
1075 }
1076 SlotIndex MBBStartIdx = LiveInts->getMBBStartIdx(MBB);
1077 if (I->start != MBBStartIdx && I->start != VNI->def) {
1078 report("Live segment must begin at MBB entry or valno def", MBB);
1079 I->print(*OS);
1080 *OS << " in " << LI << '\n' << "Basic block starts at "
1081 << MBBStartIdx << '\n';
1082 }
1083
1084 const MachineBasicBlock *EndMBB =
1085 LiveInts->getMBBFromIndex(I->end.getPrevSlot());
1086 if (!EndMBB) {
1087 report("Bad end of live segment, no basic block", MF);
1088 I->print(*OS);
1089 *OS << " in " << LI << '\n';
1090 continue;
1091 }
1092 if (I->end != LiveInts->getMBBEndIdx(EndMBB)) {
1093 // The live segment is ending inside EndMBB
1094 const MachineInstr *MI =
1095 LiveInts->getInstructionFromIndex(I->end.getPrevSlot());
1096 if (!MI) {
1097 report("Live segment doesn't end at a valid instruction", EndMBB);
1098 I->print(*OS);
1099 *OS << " in " << LI << '\n' << "Basic block starts at "
1100 << MBBStartIdx << '\n';
1101 } else if (TargetRegisterInfo::isVirtualRegister(LI.reg) &&
1102 !MI->readsVirtualRegister(LI.reg)) {
Cameron Zwarich636f15f2010-12-20 01:22:37 +00001103 // A live range can end with either a redefinition, a kill flag on a
1104 // use, or a dead flag on a def.
1105 // FIXME: Should we check for each of these?
1106 bool hasDeadDef = false;
1107 for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(),
1108 MOE = MI->operands_end(); MOI != MOE; ++MOI) {
Cameron Zwarich5e61f992010-12-20 02:59:51 +00001109 if (MOI->isReg() && MOI->getReg() == LI.reg && MOI->isDef() && MOI->isDead()) {
Cameron Zwarich636f15f2010-12-20 01:22:37 +00001110 hasDeadDef = true;
1111 break;
1112 }
1113 }
1114
1115 if (!hasDeadDef) {
1116 report("Instruction killing live segment neither defines nor reads "
1117 "register", MI);
1118 I->print(*OS);
1119 *OS << " in " << LI << '\n';
1120 }
Jakob Stoklund Olesen78716872010-10-23 00:49:09 +00001121 }
1122 }
1123
1124 // Now check all the basic blocks in this live segment.
1125 MachineFunction::const_iterator MFI = MBB;
Cameron Zwarichcb584d02010-12-28 23:45:38 +00001126 // Is this live range the beginning of a non-PHIDef VN?
1127 if (I->start == VNI->def && !VNI->isPHIDef()) {
Jakob Stoklund Olesen78716872010-10-23 00:49:09 +00001128 // Not live-in to any blocks.
1129 if (MBB == EndMBB)
1130 continue;
1131 // Skip this block.
1132 ++MFI;
1133 }
1134 for (;;) {
1135 assert(LiveInts->isLiveInToMBB(LI, MFI));
Jakob Stoklund Olesene459d552010-10-26 16:49:23 +00001136 // We don't know how to track physregs into a landing pad.
1137 if (TargetRegisterInfo::isPhysicalRegister(LI.reg) &&
1138 MFI->isLandingPad()) {
1139 if (&*MFI == EndMBB)
1140 break;
1141 ++MFI;
1142 continue;
1143 }
Jakob Stoklund Olesen78716872010-10-23 00:49:09 +00001144 // Check that VNI is live-out of all predecessors.
1145 for (MachineBasicBlock::const_pred_iterator PI = MFI->pred_begin(),
1146 PE = MFI->pred_end(); PI != PE; ++PI) {
1147 SlotIndex PEnd = LiveInts->getMBBEndIdx(*PI).getPrevSlot();
1148 const VNInfo *PVNI = LI.getVNInfoAt(PEnd);
Cameron Zwarich4eee42c2010-12-27 05:17:23 +00001149
1150 if (VNI->isPHIDef() && VNI->def == LiveInts->getMBBStartIdx(MFI)) {
Cameron Zwarichcb584d02010-12-28 23:45:38 +00001151 if (PVNI && !PVNI->hasPHIKill()) {
Cameron Zwarich4eee42c2010-12-27 05:17:23 +00001152 report("Value live out of predecessor doesn't have PHIKill", MF);
1153 *OS << "Valno #" << PVNI->id << " live out of BB#"
1154 << (*PI)->getNumber() << '@' << PEnd
1155 << " doesn't have PHIKill, but Valno #" << VNI->id
1156 << " is PHIDef and defined at the beginning of BB#"
1157 << MFI->getNumber() << '@' << LiveInts->getMBBStartIdx(MFI)
1158 << " in " << LI << '\n';
1159 }
1160 continue;
1161 }
1162
Cameron Zwarichcb584d02010-12-28 23:45:38 +00001163 if (!PVNI) {
1164 report("Register not marked live out of predecessor", *PI);
1165 *OS << "Valno #" << VNI->id << " live into BB#" << MFI->getNumber()
1166 << '@' << LiveInts->getMBBStartIdx(MFI) << ", not live at "
1167 << PEnd << " in " << LI << '\n';
1168 continue;
1169 }
1170
Cameron Zwarich4eee42c2010-12-27 05:17:23 +00001171 if (PVNI != VNI) {
Jakob Stoklund Olesen78716872010-10-23 00:49:09 +00001172 report("Different value live out of predecessor", *PI);
1173 *OS << "Valno #" << PVNI->id << " live out of BB#"
1174 << (*PI)->getNumber() << '@' << PEnd
1175 << "\nValno #" << VNI->id << " live into BB#" << MFI->getNumber()
1176 << '@' << LiveInts->getMBBStartIdx(MFI) << " in " << LI << '\n';
1177 }
1178 }
1179 if (&*MFI == EndMBB)
1180 break;
1181 ++MFI;
1182 }
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +00001183 }
Jakob Stoklund Olesen501dc422010-10-26 22:36:07 +00001184
1185 // Check the LI only has one connected component.
Jakob Stoklund Olesen8c593f92010-10-27 00:39:01 +00001186 if (TargetRegisterInfo::isVirtualRegister(LI.reg)) {
1187 ConnectedVNInfoEqClasses ConEQ(*LiveInts);
1188 unsigned NumComp = ConEQ.Classify(&LI);
1189 if (NumComp > 1) {
1190 report("Multiple connected components in live interval", MF);
1191 *OS << NumComp << " components in " << LI << '\n';
Jakob Stoklund Olesencb367772010-10-29 00:40:57 +00001192 for (unsigned comp = 0; comp != NumComp; ++comp) {
1193 *OS << comp << ": valnos";
1194 for (LiveInterval::const_vni_iterator I = LI.vni_begin(),
1195 E = LI.vni_end(); I!=E; ++I)
1196 if (comp == ConEQ.getEqClass(*I))
1197 *OS << ' ' << (*I)->id;
1198 *OS << '\n';
1199 }
Jakob Stoklund Olesen8c593f92010-10-27 00:39:01 +00001200 }
Jakob Stoklund Olesen501dc422010-10-26 22:36:07 +00001201 }
Jakob Stoklund Olesen58e12482010-08-06 18:04:19 +00001202 }
1203}
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +00001204