blob: 2297c908b1e00038a1a247556fba2d9b2bad2bf8 [file] [log] [blame]
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +00001//===-- MachineVerifier.cpp - Machine Code Verifier -------------*- C++ -*-===//
2//
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"
27#include "llvm/CodeGen/LiveVariables.h"
28#include "llvm/CodeGen/MachineFunctionPass.h"
Jakob Stoklund Olesena6b677d2009-08-13 16:19:51 +000029#include "llvm/CodeGen/MachineFrameInfo.h"
Dan Gohman2dbc4c82009-10-07 17:36:00 +000030#include "llvm/CodeGen/MachineMemOperand.h"
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000031#include "llvm/CodeGen/MachineRegisterInfo.h"
32#include "llvm/CodeGen/Passes.h"
33#include "llvm/Target/TargetMachine.h"
34#include "llvm/Target/TargetRegisterInfo.h"
35#include "llvm/Target/TargetInstrInfo.h"
Chris Lattnercf143a42009-08-23 03:13:20 +000036#include "llvm/ADT/DenseSet.h"
37#include "llvm/ADT/SetOperations.h"
38#include "llvm/ADT/SmallVector.h"
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000039#include "llvm/Support/Debug.h"
Torok Edwin7d696d82009-07-11 13:10:19 +000040#include "llvm/Support/ErrorHandling.h"
41#include "llvm/Support/raw_ostream.h"
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000042using namespace llvm;
43
44namespace {
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +000045 struct MachineVerifier {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000046
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +000047 MachineVerifier(Pass *pass, bool allowDoubleDefs) :
48 PASS(pass),
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000049 allowVirtDoubleDefs(allowDoubleDefs),
Jakob Stoklund Olesen1b2c7612010-05-14 20:28:32 +000050 allowPhysDoubleDefs(true),
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000051 OutFileName(getenv("LLVM_VERIFY_MACHINEINSTRS"))
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +000052 {}
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000053
54 bool runOnMachineFunction(MachineFunction &MF);
55
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +000056 Pass *const PASS;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000057 const bool allowVirtDoubleDefs;
58 const bool allowPhysDoubleDefs;
59
60 const char *const OutFileName;
Chris Lattner17e9edc2009-08-23 02:51:22 +000061 raw_ostream *OS;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000062 const MachineFunction *MF;
63 const TargetMachine *TM;
64 const TargetRegisterInfo *TRI;
65 const MachineRegisterInfo *MRI;
66
67 unsigned foundErrors;
68
69 typedef SmallVector<unsigned, 16> RegVector;
70 typedef DenseSet<unsigned> RegSet;
71 typedef DenseMap<unsigned, const MachineInstr*> RegMap;
72
73 BitVector regsReserved;
74 RegSet regsLive;
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +000075 RegVector regsDefined, regsDead, regsKilled;
76 RegSet regsLiveInButUnused;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000077
78 // Add Reg and any sub-registers to RV
79 void addRegWithSubRegs(RegVector &RV, unsigned Reg) {
80 RV.push_back(Reg);
81 if (TargetRegisterInfo::isPhysicalRegister(Reg))
82 for (const unsigned *R = TRI->getSubRegisters(Reg); *R; R++)
83 RV.push_back(*R);
84 }
85
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000086 struct BBInfo {
87 // Is this MBB reachable from the MF entry point?
88 bool reachable;
89
90 // Vregs that must be live in because they are used without being
91 // defined. Map value is the user.
92 RegMap vregsLiveIn;
93
94 // Vregs that must be dead in because they are defined without being
95 // killed first. Map value is the defining instruction.
96 RegMap vregsDeadIn;
97
98 // Regs killed in MBB. They may be defined again, and will then be in both
99 // regsKilled and regsLiveOut.
100 RegSet regsKilled;
101
102 // Regs defined in MBB and live out. Note that vregs passing through may
103 // be live out without being mentioned here.
104 RegSet regsLiveOut;
105
106 // Vregs that pass through MBB untouched. This set is disjoint from
107 // regsKilled and regsLiveOut.
108 RegSet vregsPassed;
109
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000110 // Vregs that must pass through MBB because they are needed by a successor
111 // block. This set is disjoint from regsLiveOut.
112 RegSet vregsRequired;
113
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000114 BBInfo() : reachable(false) {}
115
116 // Add register to vregsPassed if it belongs there. Return true if
117 // anything changed.
118 bool addPassed(unsigned Reg) {
119 if (!TargetRegisterInfo::isVirtualRegister(Reg))
120 return false;
121 if (regsKilled.count(Reg) || regsLiveOut.count(Reg))
122 return false;
123 return vregsPassed.insert(Reg).second;
124 }
125
126 // Same for a full set.
127 bool addPassed(const RegSet &RS) {
128 bool changed = false;
129 for (RegSet::const_iterator I = RS.begin(), E = RS.end(); I != E; ++I)
130 if (addPassed(*I))
131 changed = true;
132 return changed;
133 }
134
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000135 // Add register to vregsRequired if it belongs there. Return true if
136 // anything changed.
137 bool addRequired(unsigned Reg) {
138 if (!TargetRegisterInfo::isVirtualRegister(Reg))
139 return false;
140 if (regsLiveOut.count(Reg))
141 return false;
142 return vregsRequired.insert(Reg).second;
143 }
144
145 // Same for a full set.
146 bool addRequired(const RegSet &RS) {
147 bool changed = false;
148 for (RegSet::const_iterator I = RS.begin(), E = RS.end(); I != E; ++I)
149 if (addRequired(*I))
150 changed = true;
151 return changed;
152 }
153
154 // Same for a full map.
155 bool addRequired(const RegMap &RM) {
156 bool changed = false;
157 for (RegMap::const_iterator I = RM.begin(), E = RM.end(); I != E; ++I)
158 if (addRequired(I->first))
159 changed = true;
160 return changed;
161 }
162
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000163 // Live-out registers are either in regsLiveOut or vregsPassed.
164 bool isLiveOut(unsigned Reg) const {
165 return regsLiveOut.count(Reg) || vregsPassed.count(Reg);
166 }
167 };
168
169 // Extra register info per MBB.
170 DenseMap<const MachineBasicBlock*, BBInfo> MBBInfoMap;
171
172 bool isReserved(unsigned Reg) {
Jakob Stoklund Olesend37bc5a2009-08-04 19:18:01 +0000173 return Reg < regsReserved.size() && regsReserved.test(Reg);
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000174 }
175
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000176 // Analysis information if available
177 LiveVariables *LiveVars;
178
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000179 void visitMachineFunctionBefore();
180 void visitMachineBasicBlockBefore(const MachineBasicBlock *MBB);
181 void visitMachineInstrBefore(const MachineInstr *MI);
182 void visitMachineOperand(const MachineOperand *MO, unsigned MONum);
183 void visitMachineInstrAfter(const MachineInstr *MI);
184 void visitMachineBasicBlockAfter(const MachineBasicBlock *MBB);
185 void visitMachineFunctionAfter();
186
187 void report(const char *msg, const MachineFunction *MF);
188 void report(const char *msg, const MachineBasicBlock *MBB);
189 void report(const char *msg, const MachineInstr *MI);
190 void report(const char *msg, const MachineOperand *MO, unsigned MONum);
191
192 void markReachable(const MachineBasicBlock *MBB);
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000193 void calcRegsPassed();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000194 void checkPHIOps(const MachineBasicBlock *MBB);
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000195
196 void calcRegsRequired();
197 void verifyLiveVariables();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000198 };
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000199
200 struct MachineVerifierPass : public MachineFunctionPass {
201 static char ID; // Pass ID, replacement for typeid
202 bool AllowDoubleDefs;
203
204 explicit MachineVerifierPass(bool allowDoubleDefs = false)
205 : MachineFunctionPass(&ID),
206 AllowDoubleDefs(allowDoubleDefs) {}
207
208 void getAnalysisUsage(AnalysisUsage &AU) const {
209 AU.setPreservesAll();
210 MachineFunctionPass::getAnalysisUsage(AU);
211 }
212
213 bool runOnMachineFunction(MachineFunction &MF) {
214 MF.verify(this, AllowDoubleDefs);
215 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;
222static RegisterPass<MachineVerifierPass>
Jakob Stoklund Olesende67a512009-05-17 19:37:14 +0000223MachineVer("machineverifier", "Verify generated machine code");
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000224static const PassInfo *const MachineVerifyID = &MachineVer;
225
Chris Lattner17e9edc2009-08-23 02:51:22 +0000226FunctionPass *llvm::createMachineVerifierPass(bool allowPhysDoubleDefs) {
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000227 return new MachineVerifierPass(allowPhysDoubleDefs);
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000228}
229
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000230void MachineFunction::verify(Pass *p, bool allowDoubleDefs) const {
231 MachineVerifier(p, allowDoubleDefs)
232 .runOnMachineFunction(const_cast<MachineFunction&>(*this));
Jakob Stoklund Olesence727d02009-11-13 21:56:09 +0000233}
234
Chris Lattner17e9edc2009-08-23 02:51:22 +0000235bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
236 raw_ostream *OutFile = 0;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000237 if (OutFileName) {
Chris Lattner17e9edc2009-08-23 02:51:22 +0000238 std::string ErrorInfo;
239 OutFile = new raw_fd_ostream(OutFileName, ErrorInfo,
240 raw_fd_ostream::F_Append);
241 if (!ErrorInfo.empty()) {
242 errs() << "Error opening '" << OutFileName << "': " << ErrorInfo << '\n';
243 exit(1);
244 }
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000245
Chris Lattner17e9edc2009-08-23 02:51:22 +0000246 OS = OutFile;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000247 } else {
Chris Lattner17e9edc2009-08-23 02:51:22 +0000248 OS = &errs();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000249 }
250
251 foundErrors = 0;
252
253 this->MF = &MF;
254 TM = &MF.getTarget();
255 TRI = TM->getRegisterInfo();
256 MRI = &MF.getRegInfo();
257
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000258 if (PASS) {
259 LiveVars = PASS->getAnalysisIfAvailable<LiveVariables>();
260 } else {
261 LiveVars = NULL;
262 }
263
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000264 visitMachineFunctionBefore();
265 for (MachineFunction::const_iterator MFI = MF.begin(), MFE = MF.end();
266 MFI!=MFE; ++MFI) {
267 visitMachineBasicBlockBefore(MFI);
268 for (MachineBasicBlock::const_iterator MBBI = MFI->begin(),
269 MBBE = MFI->end(); MBBI != MBBE; ++MBBI) {
270 visitMachineInstrBefore(MBBI);
271 for (unsigned I = 0, E = MBBI->getNumOperands(); I != E; ++I)
272 visitMachineOperand(&MBBI->getOperand(I), I);
273 visitMachineInstrAfter(MBBI);
274 }
275 visitMachineBasicBlockAfter(MFI);
276 }
277 visitMachineFunctionAfter();
278
Chris Lattner17e9edc2009-08-23 02:51:22 +0000279 if (OutFile)
280 delete OutFile;
281 else if (foundErrors)
Chris Lattner75361b62010-04-07 22:58:41 +0000282 report_fatal_error("Found "+Twine(foundErrors)+" machine code errors.");
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000283
Jakob Stoklund Olesen63496682009-08-08 15:34:50 +0000284 // Clean up.
285 regsLive.clear();
286 regsDefined.clear();
287 regsDead.clear();
288 regsKilled.clear();
289 regsLiveInButUnused.clear();
290 MBBInfoMap.clear();
291
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000292 return false; // no changes
293}
294
Chris Lattner372fefe2009-08-23 01:03:30 +0000295void MachineVerifier::report(const char *msg, const MachineFunction *MF) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000296 assert(MF);
Chris Lattner17e9edc2009-08-23 02:51:22 +0000297 *OS << '\n';
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000298 if (!foundErrors++)
Chris Lattner372fefe2009-08-23 01:03:30 +0000299 MF->print(*OS);
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000300 *OS << "*** Bad machine code: " << msg << " ***\n"
Daniel Dunbarce63ffb2009-07-25 00:23:56 +0000301 << "- function: " << MF->getFunction()->getNameStr() << "\n";
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000302}
303
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000304void MachineVerifier::report(const char *msg, const MachineBasicBlock *MBB) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000305 assert(MBB);
306 report(msg, MBB->getParent());
Jakob Stoklund Olesen324da762009-11-20 01:17:03 +0000307 *OS << "- basic block: " << MBB->getName()
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000308 << " " << (void*)MBB
Dan Gohman0ba90f32009-10-31 20:19:03 +0000309 << " (BB#" << MBB->getNumber() << ")\n";
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000310}
311
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000312void MachineVerifier::report(const char *msg, const MachineInstr *MI) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000313 assert(MI);
314 report(msg, MI->getParent());
315 *OS << "- instruction: ";
Chris Lattner705e07f2009-08-23 03:41:05 +0000316 MI->print(*OS, TM);
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000317}
318
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000319void MachineVerifier::report(const char *msg,
320 const MachineOperand *MO, unsigned MONum) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000321 assert(MO);
322 report(msg, MO->getParent());
323 *OS << "- operand " << MONum << ": ";
324 MO->print(*OS, TM);
325 *OS << "\n";
326}
327
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000328void MachineVerifier::markReachable(const MachineBasicBlock *MBB) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000329 BBInfo &MInfo = MBBInfoMap[MBB];
330 if (!MInfo.reachable) {
331 MInfo.reachable = true;
332 for (MachineBasicBlock::const_succ_iterator SuI = MBB->succ_begin(),
333 SuE = MBB->succ_end(); SuI != SuE; ++SuI)
334 markReachable(*SuI);
335 }
336}
337
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000338void MachineVerifier::visitMachineFunctionBefore() {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000339 regsReserved = TRI->getReservedRegs(*MF);
Jakob Stoklund Olesend37bc5a2009-08-04 19:18:01 +0000340
341 // A sub-register of a reserved register is also reserved
342 for (int Reg = regsReserved.find_first(); Reg>=0;
343 Reg = regsReserved.find_next(Reg)) {
344 for (const unsigned *Sub = TRI->getSubRegisters(Reg); *Sub; ++Sub) {
345 // FIXME: This should probably be:
346 // assert(regsReserved.test(*Sub) && "Non-reserved sub-register");
347 regsReserved.set(*Sub);
348 }
349 }
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000350 markReachable(&MF->front());
351}
352
Jakob Stoklund Olesen1dc0fcb2009-11-13 21:55:54 +0000353// Does iterator point to a and b as the first two elements?
Dan Gohmanb3579832010-04-15 17:08:50 +0000354static bool matchPair(MachineBasicBlock::const_succ_iterator i,
355 const MachineBasicBlock *a, const MachineBasicBlock *b) {
Jakob Stoklund Olesen1dc0fcb2009-11-13 21:55:54 +0000356 if (*i == a)
357 return *++i == b;
358 if (*i == b)
359 return *++i == a;
360 return false;
361}
362
363void
364MachineVerifier::visitMachineBasicBlockBefore(const MachineBasicBlock *MBB) {
Dan Gohman27920592009-08-27 02:43:49 +0000365 const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
366
Dan Gohman27920592009-08-27 02:43:49 +0000367 // Call AnalyzeBranch. If it succeeds, there several more conditions to check.
368 MachineBasicBlock *TBB = 0, *FBB = 0;
369 SmallVector<MachineOperand, 4> Cond;
370 if (!TII->AnalyzeBranch(*const_cast<MachineBasicBlock *>(MBB),
371 TBB, FBB, Cond)) {
372 // Ok, AnalyzeBranch thinks it knows what's going on with this block. Let's
373 // check whether its answers match up with reality.
374 if (!TBB && !FBB) {
375 // Block falls through to its successor.
376 MachineFunction::const_iterator MBBI = MBB;
377 ++MBBI;
378 if (MBBI == MF->end()) {
Dan Gohmana01a80f2009-08-27 18:14:26 +0000379 // It's possible that the block legitimately ends with a noreturn
380 // call or an unreachable, in which case it won't actually fall
381 // out the bottom of the function.
382 } else if (MBB->succ_empty()) {
383 // It's possible that the block legitimately ends with a noreturn
384 // call or an unreachable, in which case it won't actuall fall
385 // out of the block.
Dan Gohman27920592009-08-27 02:43:49 +0000386 } else if (MBB->succ_size() != 1) {
387 report("MBB exits via unconditional fall-through but doesn't have "
388 "exactly one CFG successor!", MBB);
389 } else if (MBB->succ_begin()[0] != MBBI) {
390 report("MBB exits via unconditional fall-through but its successor "
391 "differs from its CFG successor!", MBB);
392 }
Evan Cheng86050dc2010-06-18 23:09:54 +0000393 if (!MBB->empty() && MBB->back().getDesc().isBarrier() &&
394 !TII->isPredicated(&MBB->back())) {
Dan Gohman27920592009-08-27 02:43:49 +0000395 report("MBB exits via unconditional fall-through but ends with a "
396 "barrier instruction!", MBB);
397 }
398 if (!Cond.empty()) {
399 report("MBB exits via unconditional fall-through but has a condition!",
400 MBB);
401 }
402 } else if (TBB && !FBB && Cond.empty()) {
403 // Block unconditionally branches somewhere.
404 if (MBB->succ_size() != 1) {
405 report("MBB exits via unconditional branch but doesn't have "
406 "exactly one CFG successor!", MBB);
407 } else if (MBB->succ_begin()[0] != TBB) {
408 report("MBB exits via unconditional branch but the CFG "
409 "successor doesn't match the actual successor!", MBB);
410 }
411 if (MBB->empty()) {
412 report("MBB exits via unconditional branch but doesn't contain "
413 "any instructions!", MBB);
414 } else if (!MBB->back().getDesc().isBarrier()) {
415 report("MBB exits via unconditional branch but doesn't end with a "
416 "barrier instruction!", MBB);
417 } else if (!MBB->back().getDesc().isTerminator()) {
418 report("MBB exits via unconditional branch but the branch isn't a "
419 "terminator instruction!", MBB);
420 }
421 } else if (TBB && !FBB && !Cond.empty()) {
422 // Block conditionally branches somewhere, otherwise falls through.
423 MachineFunction::const_iterator MBBI = MBB;
424 ++MBBI;
425 if (MBBI == MF->end()) {
426 report("MBB conditionally falls through out of function!", MBB);
427 } if (MBB->succ_size() != 2) {
428 report("MBB exits via conditional branch/fall-through but doesn't have "
429 "exactly two CFG successors!", MBB);
Jakob Stoklund Olesen1dc0fcb2009-11-13 21:55:54 +0000430 } else if (!matchPair(MBB->succ_begin(), TBB, MBBI)) {
Dan Gohman27920592009-08-27 02:43:49 +0000431 report("MBB exits via conditional branch/fall-through but the CFG "
432 "successors don't match the actual successors!", MBB);
433 }
434 if (MBB->empty()) {
435 report("MBB exits via conditional branch/fall-through but doesn't "
436 "contain any instructions!", MBB);
437 } else if (MBB->back().getDesc().isBarrier()) {
438 report("MBB exits via conditional branch/fall-through but ends with a "
439 "barrier instruction!", MBB);
440 } else if (!MBB->back().getDesc().isTerminator()) {
441 report("MBB exits via conditional branch/fall-through but the branch "
442 "isn't a terminator instruction!", MBB);
443 }
444 } else if (TBB && FBB) {
445 // Block conditionally branches somewhere, otherwise branches
446 // somewhere else.
447 if (MBB->succ_size() != 2) {
448 report("MBB exits via conditional branch/branch but doesn't have "
449 "exactly two CFG successors!", MBB);
Jakob Stoklund Olesen1dc0fcb2009-11-13 21:55:54 +0000450 } else if (!matchPair(MBB->succ_begin(), TBB, FBB)) {
Dan Gohman27920592009-08-27 02:43:49 +0000451 report("MBB exits via conditional branch/branch but the CFG "
452 "successors don't match the actual successors!", MBB);
453 }
454 if (MBB->empty()) {
455 report("MBB exits via conditional branch/branch but doesn't "
456 "contain any instructions!", MBB);
457 } else if (!MBB->back().getDesc().isBarrier()) {
458 report("MBB exits via conditional branch/branch but doesn't end with a "
459 "barrier instruction!", MBB);
460 } else if (!MBB->back().getDesc().isTerminator()) {
461 report("MBB exits via conditional branch/branch but the branch "
462 "isn't a terminator instruction!", MBB);
463 }
464 if (Cond.empty()) {
465 report("MBB exits via conditinal branch/branch but there's no "
466 "condition!", MBB);
467 }
468 } else {
469 report("AnalyzeBranch returned invalid data!", MBB);
470 }
471 }
472
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000473 regsLive.clear();
Dan Gohman81bf03e2010-04-13 16:57:55 +0000474 for (MachineBasicBlock::livein_iterator I = MBB->livein_begin(),
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000475 E = MBB->livein_end(); I != E; ++I) {
476 if (!TargetRegisterInfo::isPhysicalRegister(*I)) {
477 report("MBB live-in list contains non-physical register", MBB);
478 continue;
479 }
480 regsLive.insert(*I);
481 for (const unsigned *R = TRI->getSubRegisters(*I); *R; R++)
482 regsLive.insert(*R);
483 }
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000484 regsLiveInButUnused = regsLive;
Jakob Stoklund Olesena6b677d2009-08-13 16:19:51 +0000485
486 const MachineFrameInfo *MFI = MF->getFrameInfo();
487 assert(MFI && "Function has no frame info");
488 BitVector PR = MFI->getPristineRegs(MBB);
489 for (int I = PR.find_first(); I>0; I = PR.find_next(I)) {
490 regsLive.insert(I);
491 for (const unsigned *R = TRI->getSubRegisters(I); *R; R++)
492 regsLive.insert(*R);
493 }
494
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000495 regsKilled.clear();
496 regsDefined.clear();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000497}
498
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000499void MachineVerifier::visitMachineInstrBefore(const MachineInstr *MI) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000500 const TargetInstrDesc &TI = MI->getDesc();
Jakob Stoklund Olesen39523e22009-09-23 20:57:55 +0000501 if (MI->getNumOperands() < TI.getNumOperands()) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000502 report("Too few operands", MI);
503 *OS << TI.getNumOperands() << " operands expected, but "
504 << MI->getNumExplicitOperands() << " given.\n";
505 }
Dan Gohman2dbc4c82009-10-07 17:36:00 +0000506
507 // Check the MachineMemOperands for basic consistency.
508 for (MachineInstr::mmo_iterator I = MI->memoperands_begin(),
509 E = MI->memoperands_end(); I != E; ++I) {
510 if ((*I)->isLoad() && !TI.mayLoad())
511 report("Missing mayLoad flag", MI);
512 if ((*I)->isStore() && !TI.mayStore())
513 report("Missing mayStore flag", MI);
514 }
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000515}
516
517void
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000518MachineVerifier::visitMachineOperand(const MachineOperand *MO, unsigned MONum) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000519 const MachineInstr *MI = MO->getParent();
Jakob Stoklund Olesen44b27e52009-05-16 07:25:20 +0000520 const TargetInstrDesc &TI = MI->getDesc();
521
522 // The first TI.NumDefs operands must be explicit register defines
523 if (MONum < TI.getNumDefs()) {
524 if (!MO->isReg())
525 report("Explicit definition must be a register", MO, MONum);
526 else if (!MO->isDef())
527 report("Explicit definition marked as use", MO, MONum);
528 else if (MO->isImplicit())
529 report("Explicit definition marked as implicit", MO, MONum);
Jakob Stoklund Olesen39523e22009-09-23 20:57:55 +0000530 } else if (MONum < TI.getNumOperands()) {
531 if (MO->isReg()) {
532 if (MO->isDef())
533 report("Explicit operand marked as def", MO, MONum);
534 if (MO->isImplicit())
535 report("Explicit operand marked as implicit", MO, MONum);
536 }
537 } else {
Jakob Stoklund Olesen57115642009-12-22 21:48:20 +0000538 // ARM adds %reg0 operands to indicate predicates. We'll allow that.
539 if (MO->isReg() && !MO->isImplicit() && !TI.isVariadic() && MO->getReg())
Jakob Stoklund Olesen39523e22009-09-23 20:57:55 +0000540 report("Extra explicit operand on non-variadic instruction", MO, MONum);
Jakob Stoklund Olesen44b27e52009-05-16 07:25:20 +0000541 }
542
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000543 switch (MO->getType()) {
544 case MachineOperand::MO_Register: {
545 const unsigned Reg = MO->getReg();
546 if (!Reg)
547 return;
548
549 // Check Live Variables.
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000550 if (MO->isUndef()) {
551 // An <undef> doesn't refer to any register, so just skip it.
552 } else if (MO->isUse()) {
553 regsLiveInButUnused.erase(Reg);
554
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000555 bool isKill = false;
Jakob Stoklund Olesen1b2c7612010-05-14 20:28:32 +0000556 unsigned defIdx;
557 if (MI->isRegTiedToDefOperand(MONum, &defIdx)) {
558 // A two-addr use counts as a kill if use and def are the same.
559 unsigned DefReg = MI->getOperand(defIdx).getReg();
560 if (Reg == DefReg) {
561 isKill = true;
562 // ANd in that case an explicit kill flag is not allowed.
563 if (MO->isKill())
Jakob Stoklund Olesenf7d3e692009-07-15 23:37:26 +0000564 report("Illegal kill flag on two-address instruction operand",
565 MO, MONum);
Jakob Stoklund Olesen1b2c7612010-05-14 20:28:32 +0000566 } else if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
567 report("Two-address instruction operands must be identical",
568 MO, MONum);
569 }
570 } else
571 isKill = MO->isKill();
572
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000573 if (isKill) {
574 addRegWithSubRegs(regsKilled, Reg);
575
576 // Check that LiveVars knows this kill
577 if (LiveVars && TargetRegisterInfo::isVirtualRegister(Reg)) {
578 LiveVariables::VarInfo &VI = LiveVars->getVarInfo(Reg);
579 if (std::find(VI.Kills.begin(),
580 VI.Kills.end(), MI) == VI.Kills.end())
581 report("Kill missing from LiveVariables", MO, MONum);
582 }
583 }
584
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000585 // Use of a dead register.
586 if (!regsLive.count(Reg)) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000587 if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
588 // Reserved registers may be used even when 'dead'.
589 if (!isReserved(Reg))
590 report("Using an undefined physical register", MO, MONum);
591 } else {
592 BBInfo &MInfo = MBBInfoMap[MI->getParent()];
593 // We don't know which virtual registers are live in, so only complain
594 // if vreg was killed in this MBB. Otherwise keep track of vregs that
595 // must be live in. PHI instructions are handled separately.
596 if (MInfo.regsKilled.count(Reg))
597 report("Using a killed virtual register", MO, MONum);
Chris Lattner518bb532010-02-09 19:54:29 +0000598 else if (!MI->isPHI())
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000599 MInfo.vregsLiveIn.insert(std::make_pair(Reg, MI));
600 }
Duncan Sandse5567202009-05-16 03:28:54 +0000601 }
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000602 } else {
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000603 assert(MO->isDef());
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000604 // Register defined.
605 // TODO: verify that earlyclobber ops are not used.
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000606 if (MO->isDead())
607 addRegWithSubRegs(regsDead, Reg);
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000608 else
609 addRegWithSubRegs(regsDefined, Reg);
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000610 }
611
612 // Check register classes.
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000613 if (MONum < TI.getNumOperands() && !MO->isImplicit()) {
614 const TargetOperandInfo &TOI = TI.OpInfo[MONum];
615 unsigned SubIdx = MO->getSubReg();
616
617 if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
618 unsigned sr = Reg;
619 if (SubIdx) {
620 unsigned s = TRI->getSubReg(Reg, SubIdx);
621 if (!s) {
622 report("Invalid subregister index for physical register",
623 MO, MONum);
624 return;
625 }
626 sr = s;
627 }
Chris Lattnercb778a82009-07-29 21:10:12 +0000628 if (const TargetRegisterClass *DRC = TOI.getRegClass(TRI)) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000629 if (!DRC->contains(sr)) {
630 report("Illegal physical register for instruction", MO, MONum);
631 *OS << TRI->getName(sr) << " is not a "
632 << DRC->getName() << " register.\n";
633 }
634 }
635 } else {
636 // Virtual register.
637 const TargetRegisterClass *RC = MRI->getRegClass(Reg);
638 if (SubIdx) {
Jakob Stoklund Olesen6a8d2c62010-05-18 17:31:12 +0000639 const TargetRegisterClass *SRC = RC->getSubRegisterRegClass(SubIdx);
640 if (!SRC) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000641 report("Invalid subregister index for virtual register", MO, MONum);
Jakob Stoklund Olesen6a8d2c62010-05-18 17:31:12 +0000642 *OS << "Register class " << RC->getName()
643 << " does not support subreg index " << SubIdx << "\n";
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000644 return;
645 }
Jakob Stoklund Olesen6a8d2c62010-05-18 17:31:12 +0000646 RC = SRC;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000647 }
Chris Lattnercb778a82009-07-29 21:10:12 +0000648 if (const TargetRegisterClass *DRC = TOI.getRegClass(TRI)) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000649 if (RC != DRC && !RC->hasSuperClass(DRC)) {
650 report("Illegal virtual register for instruction", MO, MONum);
651 *OS << "Expected a " << DRC->getName() << " register, but got a "
652 << RC->getName() << " register\n";
653 }
654 }
655 }
656 }
657 break;
658 }
Jakob Stoklund Olesena5ba07c2009-09-21 07:19:08 +0000659
660 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner518bb532010-02-09 19:54:29 +0000661 if (MI->isPHI() && !MO->getMBB()->isSuccessor(MI->getParent()))
662 report("PHI operand is not in the CFG", MO, MONum);
Jakob Stoklund Olesena5ba07c2009-09-21 07:19:08 +0000663 break;
664
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000665 default:
666 break;
667 }
668}
669
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000670void MachineVerifier::visitMachineInstrAfter(const MachineInstr *MI) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000671 BBInfo &MInfo = MBBInfoMap[MI->getParent()];
672 set_union(MInfo.regsKilled, regsKilled);
673 set_subtract(regsLive, regsKilled);
674 regsKilled.clear();
675
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000676 // Verify that both <def> and <def,dead> operands refer to dead registers.
677 RegVector defs(regsDefined);
678 defs.append(regsDead.begin(), regsDead.end());
679
680 for (RegVector::const_iterator I = defs.begin(), E = defs.end();
681 I != E; ++I) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000682 if (regsLive.count(*I)) {
683 if (TargetRegisterInfo::isPhysicalRegister(*I)) {
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000684 if (!allowPhysDoubleDefs && !isReserved(*I) &&
685 !regsLiveInButUnused.count(*I)) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000686 report("Redefining a live physical register", MI);
687 *OS << "Register " << TRI->getName(*I)
688 << " was defined but already live.\n";
689 }
690 } else {
691 if (!allowVirtDoubleDefs) {
692 report("Redefining a live virtual register", MI);
693 *OS << "Virtual register %reg" << *I
694 << " was defined but already live.\n";
695 }
696 }
697 } else if (TargetRegisterInfo::isVirtualRegister(*I) &&
698 !MInfo.regsKilled.count(*I)) {
699 // Virtual register defined without being killed first must be dead on
700 // entry.
701 MInfo.vregsDeadIn.insert(std::make_pair(*I, MI));
702 }
703 }
704
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000705 set_subtract(regsLive, regsDead); regsDead.clear();
Jakob Stoklund Olesen710b13b2009-08-08 13:19:25 +0000706 set_union(regsLive, regsDefined); regsDefined.clear();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000707}
708
709void
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000710MachineVerifier::visitMachineBasicBlockAfter(const MachineBasicBlock *MBB) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000711 MBBInfoMap[MBB].regsLiveOut = regsLive;
712 regsLive.clear();
713}
714
715// Calculate the largest possible vregsPassed sets. These are the registers that
716// can pass through an MBB live, but may not be live every time. It is assumed
717// that all vregsPassed sets are empty before the call.
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000718void MachineVerifier::calcRegsPassed() {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000719 // First push live-out regs to successors' vregsPassed. Remember the MBBs that
720 // have any vregsPassed.
721 DenseSet<const MachineBasicBlock*> todo;
722 for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end();
723 MFI != MFE; ++MFI) {
724 const MachineBasicBlock &MBB(*MFI);
725 BBInfo &MInfo = MBBInfoMap[&MBB];
726 if (!MInfo.reachable)
727 continue;
728 for (MachineBasicBlock::const_succ_iterator SuI = MBB.succ_begin(),
729 SuE = MBB.succ_end(); SuI != SuE; ++SuI) {
730 BBInfo &SInfo = MBBInfoMap[*SuI];
731 if (SInfo.addPassed(MInfo.regsLiveOut))
732 todo.insert(*SuI);
733 }
734 }
735
736 // Iteratively push vregsPassed to successors. This will converge to the same
737 // final state regardless of DenseSet iteration order.
738 while (!todo.empty()) {
739 const MachineBasicBlock *MBB = *todo.begin();
740 todo.erase(MBB);
741 BBInfo &MInfo = MBBInfoMap[MBB];
742 for (MachineBasicBlock::const_succ_iterator SuI = MBB->succ_begin(),
743 SuE = MBB->succ_end(); SuI != SuE; ++SuI) {
744 if (*SuI == MBB)
745 continue;
746 BBInfo &SInfo = MBBInfoMap[*SuI];
747 if (SInfo.addPassed(MInfo.vregsPassed))
748 todo.insert(*SuI);
749 }
750 }
751}
752
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000753// Calculate the set of virtual registers that must be passed through each basic
754// block in order to satisfy the requirements of successor blocks. This is very
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000755// similar to calcRegsPassed, only backwards.
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000756void MachineVerifier::calcRegsRequired() {
757 // First push live-in regs to predecessors' vregsRequired.
758 DenseSet<const MachineBasicBlock*> todo;
759 for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end();
760 MFI != MFE; ++MFI) {
761 const MachineBasicBlock &MBB(*MFI);
762 BBInfo &MInfo = MBBInfoMap[&MBB];
763 for (MachineBasicBlock::const_pred_iterator PrI = MBB.pred_begin(),
764 PrE = MBB.pred_end(); PrI != PrE; ++PrI) {
765 BBInfo &PInfo = MBBInfoMap[*PrI];
766 if (PInfo.addRequired(MInfo.vregsLiveIn))
767 todo.insert(*PrI);
768 }
769 }
770
771 // Iteratively push vregsRequired to predecessors. This will converge to the
772 // same final state regardless of DenseSet iteration order.
773 while (!todo.empty()) {
774 const MachineBasicBlock *MBB = *todo.begin();
775 todo.erase(MBB);
776 BBInfo &MInfo = MBBInfoMap[MBB];
777 for (MachineBasicBlock::const_pred_iterator PrI = MBB->pred_begin(),
778 PrE = MBB->pred_end(); PrI != PrE; ++PrI) {
779 if (*PrI == MBB)
780 continue;
781 BBInfo &SInfo = MBBInfoMap[*PrI];
782 if (SInfo.addRequired(MInfo.vregsRequired))
783 todo.insert(*PrI);
784 }
785 }
786}
787
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000788// Check PHI instructions at the beginning of MBB. It is assumed that
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000789// calcRegsPassed has been run so BBInfo::isLiveOut is valid.
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000790void MachineVerifier::checkPHIOps(const MachineBasicBlock *MBB) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000791 for (MachineBasicBlock::const_iterator BBI = MBB->begin(), BBE = MBB->end();
Chris Lattner518bb532010-02-09 19:54:29 +0000792 BBI != BBE && BBI->isPHI(); ++BBI) {
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000793 DenseSet<const MachineBasicBlock*> seen;
794
795 for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) {
796 unsigned Reg = BBI->getOperand(i).getReg();
797 const MachineBasicBlock *Pre = BBI->getOperand(i + 1).getMBB();
798 if (!Pre->isSuccessor(MBB))
799 continue;
800 seen.insert(Pre);
801 BBInfo &PrInfo = MBBInfoMap[Pre];
802 if (PrInfo.reachable && !PrInfo.isLiveOut(Reg))
803 report("PHI operand is not live-out from predecessor",
804 &BBI->getOperand(i), i);
805 }
806
807 // Did we see all predecessors?
808 for (MachineBasicBlock::const_pred_iterator PrI = MBB->pred_begin(),
809 PrE = MBB->pred_end(); PrI != PrE; ++PrI) {
810 if (!seen.count(*PrI)) {
811 report("Missing PHI operand", BBI);
Dan Gohman0ba90f32009-10-31 20:19:03 +0000812 *OS << "BB#" << (*PrI)->getNumber()
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000813 << " is a predecessor according to the CFG.\n";
814 }
815 }
816 }
817}
818
Jakob Stoklund Olesenb44fad72009-10-04 18:18:39 +0000819void MachineVerifier::visitMachineFunctionAfter() {
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000820 calcRegsPassed();
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000821
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000822 for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end();
823 MFI != MFE; ++MFI) {
824 BBInfo &MInfo = MBBInfoMap[MFI];
825
826 // Skip unreachable MBBs.
827 if (!MInfo.reachable)
828 continue;
829
830 checkPHIOps(MFI);
831
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000832 // Verify dead-in virtual registers.
833 if (!allowVirtDoubleDefs) {
834 for (MachineBasicBlock::const_pred_iterator PrI = MFI->pred_begin(),
835 PrE = MFI->pred_end(); PrI != PrE; ++PrI) {
836 BBInfo &PrInfo = MBBInfoMap[*PrI];
837 if (!PrInfo.reachable)
838 continue;
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000839
Jakob Stoklund Olesenb31defe2010-01-05 20:59:36 +0000840 for (RegMap::iterator I = MInfo.vregsDeadIn.begin(),
841 E = MInfo.vregsDeadIn.end(); I != E; ++I) {
842 // DeadIn register must be in neither regsLiveOut or vregsPassed of
843 // any predecessor.
844 if (PrInfo.isLiveOut(I->first)) {
845 report("Live-in virtual register redefined", I->second);
846 *OS << "Register %reg" << I->first
847 << " was live-out from predecessor MBB #"
848 << (*PrI)->getNumber() << ".\n";
849 }
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000850 }
851 }
852 }
853 }
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000854
855 // Now check LiveVariables info if available
856 if (LiveVars) {
857 calcRegsRequired();
858 verifyLiveVariables();
859 }
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000860}
Jakob Stoklund Olesen8f16e022009-11-18 20:36:57 +0000861
862void MachineVerifier::verifyLiveVariables() {
863 assert(LiveVars && "Don't call verifyLiveVariables without LiveVars");
864 for (unsigned Reg = TargetRegisterInfo::FirstVirtualRegister,
865 RegE = MRI->getLastVirtReg()-1; Reg != RegE; ++Reg) {
866 LiveVariables::VarInfo &VI = LiveVars->getVarInfo(Reg);
867 for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end();
868 MFI != MFE; ++MFI) {
869 BBInfo &MInfo = MBBInfoMap[MFI];
870
871 // Our vregsRequired should be identical to LiveVariables' AliveBlocks
872 if (MInfo.vregsRequired.count(Reg)) {
873 if (!VI.AliveBlocks.test(MFI->getNumber())) {
874 report("LiveVariables: Block missing from AliveBlocks", MFI);
875 *OS << "Virtual register %reg" << Reg
876 << " must be live through the block.\n";
877 }
878 } else {
879 if (VI.AliveBlocks.test(MFI->getNumber())) {
880 report("LiveVariables: Block should not be in AliveBlocks", MFI);
881 *OS << "Virtual register %reg" << Reg
882 << " is not needed live through the block.\n";
883 }
884 }
885 }
886 }
887}
888
889