Bill Wendling | 5567bb0 | 2010-08-19 18:52:17 +0000 | [diff] [blame] | 1 | //===-- MachineVerifier.cpp - Machine Code Verifier -----------------------===// |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 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 | |
Bill Wendling | d29052b | 2011-05-04 22:54:05 +0000 | [diff] [blame] | 26 | #include "llvm/Instructions.h" |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 27 | #include "llvm/Function.h" |
Jakob Stoklund Olesen | 1fe9c34 | 2010-08-05 22:32:21 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/LiveVariables.h" |
Jakob Stoklund Olesen | e8f0823 | 2010-11-01 19:49:52 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/LiveStackAnalysis.h" |
Jakob Stoklund Olesen | 30e98a0 | 2012-02-29 00:33:41 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineInstrBundle.h" |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Jakob Stoklund Olesen | a6b677d | 2009-08-13 16:19:51 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Dan Gohman | 2dbc4c8 | 2009-10-07 17:36:00 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineMemOperand.h" |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 36 | #include "llvm/CodeGen/Passes.h" |
Bill Wendling | d29052b | 2011-05-04 22:54:05 +0000 | [diff] [blame] | 37 | #include "llvm/MC/MCAsmInfo.h" |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 38 | #include "llvm/Target/TargetMachine.h" |
| 39 | #include "llvm/Target/TargetRegisterInfo.h" |
| 40 | #include "llvm/Target/TargetInstrInfo.h" |
Chris Lattner | cf143a4 | 2009-08-23 03:13:20 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/DenseSet.h" |
| 42 | #include "llvm/ADT/SetOperations.h" |
| 43 | #include "llvm/ADT/SmallVector.h" |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 44 | #include "llvm/Support/Debug.h" |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 45 | #include "llvm/Support/ErrorHandling.h" |
| 46 | #include "llvm/Support/raw_ostream.h" |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 47 | using namespace llvm; |
| 48 | |
| 49 | namespace { |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 50 | struct MachineVerifier { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 51 | |
Jakob Stoklund Olesen | 89cab93 | 2010-12-18 00:06:56 +0000 | [diff] [blame] | 52 | MachineVerifier(Pass *pass, const char *b) : |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 53 | PASS(pass), |
Jakob Stoklund Olesen | 89cab93 | 2010-12-18 00:06:56 +0000 | [diff] [blame] | 54 | Banner(b), |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 55 | OutFileName(getenv("LLVM_VERIFY_MACHINEINSTRS")) |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 56 | {} |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 57 | |
| 58 | bool runOnMachineFunction(MachineFunction &MF); |
| 59 | |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 60 | Pass *const PASS; |
Jakob Stoklund Olesen | 89cab93 | 2010-12-18 00:06:56 +0000 | [diff] [blame] | 61 | const char *Banner; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 62 | const char *const OutFileName; |
Chris Lattner | 17e9edc | 2009-08-23 02:51:22 +0000 | [diff] [blame] | 63 | raw_ostream *OS; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 64 | const MachineFunction *MF; |
| 65 | const TargetMachine *TM; |
Evan Cheng | 15993f8 | 2011-06-27 21:26:13 +0000 | [diff] [blame] | 66 | const TargetInstrInfo *TII; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 67 | const TargetRegisterInfo *TRI; |
| 68 | const MachineRegisterInfo *MRI; |
| 69 | |
| 70 | unsigned foundErrors; |
| 71 | |
| 72 | typedef SmallVector<unsigned, 16> RegVector; |
Jakob Stoklund Olesen | 9ca12d2 | 2012-02-28 01:42:41 +0000 | [diff] [blame] | 73 | typedef SmallVector<const uint32_t*, 4> RegMaskVector; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 74 | typedef DenseSet<unsigned> RegSet; |
| 75 | typedef DenseMap<unsigned, const MachineInstr*> RegMap; |
| 76 | |
Jakob Stoklund Olesen | 5adc07e | 2011-09-23 22:45:39 +0000 | [diff] [blame] | 77 | const MachineInstr *FirstTerminator; |
| 78 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 79 | BitVector regsReserved; |
Lang Hames | 03698de | 2012-02-14 19:17:48 +0000 | [diff] [blame] | 80 | BitVector regsAllocatable; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 81 | RegSet regsLive; |
Jakob Stoklund Olesen | 710b13b | 2009-08-08 13:19:25 +0000 | [diff] [blame] | 82 | RegVector regsDefined, regsDead, regsKilled; |
Jakob Stoklund Olesen | 9ca12d2 | 2012-02-28 01:42:41 +0000 | [diff] [blame] | 83 | RegMaskVector regMasks; |
Jakob Stoklund Olesen | 710b13b | 2009-08-08 13:19:25 +0000 | [diff] [blame] | 84 | RegSet regsLiveInButUnused; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 85 | |
Jakob Stoklund Olesen | fc69c37 | 2011-01-12 21:27:48 +0000 | [diff] [blame] | 86 | SlotIndex lastIndex; |
| 87 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 88 | // Add Reg and any sub-registers to RV |
| 89 | void addRegWithSubRegs(RegVector &RV, unsigned Reg) { |
| 90 | RV.push_back(Reg); |
| 91 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
Jakob Stoklund Olesen | 396618b | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 92 | for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) |
| 93 | RV.push_back(*SubRegs); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 96 | struct BBInfo { |
| 97 | // Is this MBB reachable from the MF entry point? |
| 98 | bool reachable; |
| 99 | |
| 100 | // Vregs that must be live in because they are used without being |
| 101 | // defined. Map value is the user. |
| 102 | RegMap vregsLiveIn; |
| 103 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 104 | // Regs killed in MBB. They may be defined again, and will then be in both |
| 105 | // regsKilled and regsLiveOut. |
| 106 | RegSet regsKilled; |
| 107 | |
| 108 | // Regs defined in MBB and live out. Note that vregs passing through may |
| 109 | // be live out without being mentioned here. |
| 110 | RegSet regsLiveOut; |
| 111 | |
| 112 | // Vregs that pass through MBB untouched. This set is disjoint from |
| 113 | // regsKilled and regsLiveOut. |
| 114 | RegSet vregsPassed; |
| 115 | |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 116 | // Vregs that must pass through MBB because they are needed by a successor |
| 117 | // block. This set is disjoint from regsLiveOut. |
| 118 | RegSet vregsRequired; |
| 119 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 120 | BBInfo() : reachable(false) {} |
| 121 | |
| 122 | // Add register to vregsPassed if it belongs there. Return true if |
| 123 | // anything changed. |
| 124 | bool addPassed(unsigned Reg) { |
| 125 | if (!TargetRegisterInfo::isVirtualRegister(Reg)) |
| 126 | return false; |
| 127 | if (regsKilled.count(Reg) || regsLiveOut.count(Reg)) |
| 128 | return false; |
| 129 | return vregsPassed.insert(Reg).second; |
| 130 | } |
| 131 | |
| 132 | // Same for a full set. |
| 133 | bool addPassed(const RegSet &RS) { |
| 134 | bool changed = false; |
| 135 | for (RegSet::const_iterator I = RS.begin(), E = RS.end(); I != E; ++I) |
| 136 | if (addPassed(*I)) |
| 137 | changed = true; |
| 138 | return changed; |
| 139 | } |
| 140 | |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 141 | // Add register to vregsRequired if it belongs there. Return true if |
| 142 | // anything changed. |
| 143 | bool addRequired(unsigned Reg) { |
| 144 | if (!TargetRegisterInfo::isVirtualRegister(Reg)) |
| 145 | return false; |
| 146 | if (regsLiveOut.count(Reg)) |
| 147 | return false; |
| 148 | return vregsRequired.insert(Reg).second; |
| 149 | } |
| 150 | |
| 151 | // Same for a full set. |
| 152 | bool addRequired(const RegSet &RS) { |
| 153 | bool changed = false; |
| 154 | for (RegSet::const_iterator I = RS.begin(), E = RS.end(); I != E; ++I) |
| 155 | if (addRequired(*I)) |
| 156 | changed = true; |
| 157 | return changed; |
| 158 | } |
| 159 | |
| 160 | // Same for a full map. |
| 161 | bool addRequired(const RegMap &RM) { |
| 162 | bool changed = false; |
| 163 | for (RegMap::const_iterator I = RM.begin(), E = RM.end(); I != E; ++I) |
| 164 | if (addRequired(I->first)) |
| 165 | changed = true; |
| 166 | return changed; |
| 167 | } |
| 168 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 169 | // Live-out registers are either in regsLiveOut or vregsPassed. |
| 170 | bool isLiveOut(unsigned Reg) const { |
| 171 | return regsLiveOut.count(Reg) || vregsPassed.count(Reg); |
| 172 | } |
| 173 | }; |
| 174 | |
| 175 | // Extra register info per MBB. |
| 176 | DenseMap<const MachineBasicBlock*, BBInfo> MBBInfoMap; |
| 177 | |
| 178 | bool isReserved(unsigned Reg) { |
Jakob Stoklund Olesen | d37bc5a | 2009-08-04 19:18:01 +0000 | [diff] [blame] | 179 | return Reg < regsReserved.size() && regsReserved.test(Reg); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Lang Hames | 03698de | 2012-02-14 19:17:48 +0000 | [diff] [blame] | 182 | bool isAllocatable(unsigned Reg) { |
| 183 | return Reg < regsAllocatable.size() && regsAllocatable.test(Reg); |
| 184 | } |
| 185 | |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 186 | // Analysis information if available |
| 187 | LiveVariables *LiveVars; |
Jakob Stoklund Olesen | 501dc42 | 2010-10-26 22:36:07 +0000 | [diff] [blame] | 188 | LiveIntervals *LiveInts; |
Jakob Stoklund Olesen | e8f0823 | 2010-11-01 19:49:52 +0000 | [diff] [blame] | 189 | LiveStacks *LiveStks; |
Jakob Stoklund Olesen | f4a1e1a | 2010-10-26 20:21:46 +0000 | [diff] [blame] | 190 | SlotIndexes *Indexes; |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 191 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 192 | void visitMachineFunctionBefore(); |
| 193 | void visitMachineBasicBlockBefore(const MachineBasicBlock *MBB); |
Jakob Stoklund Olesen | 1f9c3ec | 2012-06-06 22:34:30 +0000 | [diff] [blame] | 194 | void visitMachineBundleBefore(const MachineInstr *MI); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 195 | void visitMachineInstrBefore(const MachineInstr *MI); |
| 196 | void visitMachineOperand(const MachineOperand *MO, unsigned MONum); |
| 197 | void visitMachineInstrAfter(const MachineInstr *MI); |
Jakob Stoklund Olesen | 1f9c3ec | 2012-06-06 22:34:30 +0000 | [diff] [blame] | 198 | void visitMachineBundleAfter(const MachineInstr *MI); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 199 | void visitMachineBasicBlockAfter(const MachineBasicBlock *MBB); |
| 200 | void visitMachineFunctionAfter(); |
| 201 | |
| 202 | void report(const char *msg, const MachineFunction *MF); |
| 203 | void report(const char *msg, const MachineBasicBlock *MBB); |
| 204 | void report(const char *msg, const MachineInstr *MI); |
| 205 | void report(const char *msg, const MachineOperand *MO, unsigned MONum); |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 206 | void report(const char *msg, const MachineFunction *MF, |
| 207 | const LiveInterval &LI); |
| 208 | void report(const char *msg, const MachineBasicBlock *MBB, |
| 209 | const LiveInterval &LI); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 210 | |
Jakob Stoklund Olesen | 948a444 | 2012-03-28 20:47:35 +0000 | [diff] [blame] | 211 | void checkLiveness(const MachineOperand *MO, unsigned MONum); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 212 | void markReachable(const MachineBasicBlock *MBB); |
Jakob Stoklund Olesen | b31defe | 2010-01-05 20:59:36 +0000 | [diff] [blame] | 213 | void calcRegsPassed(); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 214 | void checkPHIOps(const MachineBasicBlock *MBB); |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 215 | |
| 216 | void calcRegsRequired(); |
| 217 | void verifyLiveVariables(); |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 218 | void verifyLiveIntervals(); |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 219 | void verifyLiveInterval(const LiveInterval&); |
| 220 | void verifyLiveIntervalValue(const LiveInterval&, VNInfo*); |
| 221 | void verifyLiveIntervalSegment(const LiveInterval&, |
| 222 | LiveInterval::const_iterator); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 223 | }; |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 224 | |
| 225 | struct MachineVerifierPass : public MachineFunctionPass { |
| 226 | static char ID; // Pass ID, replacement for typeid |
Jakob Stoklund Olesen | 89cab93 | 2010-12-18 00:06:56 +0000 | [diff] [blame] | 227 | const char *const Banner; |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 228 | |
Jakob Stoklund Olesen | 89cab93 | 2010-12-18 00:06:56 +0000 | [diff] [blame] | 229 | MachineVerifierPass(const char *b = 0) |
| 230 | : MachineFunctionPass(ID), Banner(b) { |
Owen Anderson | 081c34b | 2010-10-19 17:21:58 +0000 | [diff] [blame] | 231 | initializeMachineVerifierPassPass(*PassRegistry::getPassRegistry()); |
| 232 | } |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 233 | |
| 234 | void getAnalysisUsage(AnalysisUsage &AU) const { |
| 235 | AU.setPreservesAll(); |
| 236 | MachineFunctionPass::getAnalysisUsage(AU); |
| 237 | } |
| 238 | |
| 239 | bool runOnMachineFunction(MachineFunction &MF) { |
Jakob Stoklund Olesen | 89cab93 | 2010-12-18 00:06:56 +0000 | [diff] [blame] | 240 | MF.verify(this, Banner); |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 241 | return false; |
| 242 | } |
| 243 | }; |
| 244 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 247 | char MachineVerifierPass::ID = 0; |
Owen Anderson | 02dd53e | 2010-08-23 17:52:01 +0000 | [diff] [blame] | 248 | INITIALIZE_PASS(MachineVerifierPass, "machineverifier", |
Owen Anderson | ce665bd | 2010-10-07 22:25:06 +0000 | [diff] [blame] | 249 | "Verify generated machine code", false, false) |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 250 | |
Jakob Stoklund Olesen | 89cab93 | 2010-12-18 00:06:56 +0000 | [diff] [blame] | 251 | FunctionPass *llvm::createMachineVerifierPass(const char *Banner) { |
| 252 | return new MachineVerifierPass(Banner); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Jakob Stoklund Olesen | 89cab93 | 2010-12-18 00:06:56 +0000 | [diff] [blame] | 255 | void MachineFunction::verify(Pass *p, const char *Banner) const { |
| 256 | MachineVerifier(p, Banner) |
| 257 | .runOnMachineFunction(const_cast<MachineFunction&>(*this)); |
Jakob Stoklund Olesen | ce727d0 | 2009-11-13 21:56:09 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Chris Lattner | 17e9edc | 2009-08-23 02:51:22 +0000 | [diff] [blame] | 260 | bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) { |
| 261 | raw_ostream *OutFile = 0; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 262 | if (OutFileName) { |
Chris Lattner | 17e9edc | 2009-08-23 02:51:22 +0000 | [diff] [blame] | 263 | std::string ErrorInfo; |
| 264 | OutFile = new raw_fd_ostream(OutFileName, ErrorInfo, |
| 265 | raw_fd_ostream::F_Append); |
| 266 | if (!ErrorInfo.empty()) { |
| 267 | errs() << "Error opening '" << OutFileName << "': " << ErrorInfo << '\n'; |
| 268 | exit(1); |
| 269 | } |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 270 | |
Chris Lattner | 17e9edc | 2009-08-23 02:51:22 +0000 | [diff] [blame] | 271 | OS = OutFile; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 272 | } else { |
Chris Lattner | 17e9edc | 2009-08-23 02:51:22 +0000 | [diff] [blame] | 273 | OS = &errs(); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | foundErrors = 0; |
| 277 | |
| 278 | this->MF = &MF; |
| 279 | TM = &MF.getTarget(); |
Evan Cheng | 15993f8 | 2011-06-27 21:26:13 +0000 | [diff] [blame] | 280 | TII = TM->getInstrInfo(); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 281 | TRI = TM->getRegisterInfo(); |
| 282 | MRI = &MF.getRegInfo(); |
| 283 | |
Jakob Stoklund Olesen | c910c8d | 2010-08-05 23:51:26 +0000 | [diff] [blame] | 284 | LiveVars = NULL; |
| 285 | LiveInts = NULL; |
Jakob Stoklund Olesen | e8f0823 | 2010-11-01 19:49:52 +0000 | [diff] [blame] | 286 | LiveStks = NULL; |
Jakob Stoklund Olesen | f4a1e1a | 2010-10-26 20:21:46 +0000 | [diff] [blame] | 287 | Indexes = NULL; |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 288 | if (PASS) { |
Jakob Stoklund Olesen | 1fe9c34 | 2010-08-05 22:32:21 +0000 | [diff] [blame] | 289 | LiveInts = PASS->getAnalysisIfAvailable<LiveIntervals>(); |
Jakob Stoklund Olesen | c910c8d | 2010-08-05 23:51:26 +0000 | [diff] [blame] | 290 | // We don't want to verify LiveVariables if LiveIntervals is available. |
| 291 | if (!LiveInts) |
| 292 | LiveVars = PASS->getAnalysisIfAvailable<LiveVariables>(); |
Jakob Stoklund Olesen | e8f0823 | 2010-11-01 19:49:52 +0000 | [diff] [blame] | 293 | LiveStks = PASS->getAnalysisIfAvailable<LiveStacks>(); |
Jakob Stoklund Olesen | f4a1e1a | 2010-10-26 20:21:46 +0000 | [diff] [blame] | 294 | Indexes = PASS->getAnalysisIfAvailable<SlotIndexes>(); |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 297 | visitMachineFunctionBefore(); |
| 298 | for (MachineFunction::const_iterator MFI = MF.begin(), MFE = MF.end(); |
| 299 | MFI!=MFE; ++MFI) { |
| 300 | visitMachineBasicBlockBefore(MFI); |
Jakob Stoklund Olesen | 1f9c3ec | 2012-06-06 22:34:30 +0000 | [diff] [blame] | 301 | // Keep track of the current bundle header. |
| 302 | const MachineInstr *CurBundle = 0; |
Evan Cheng | ddfd137 | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 303 | for (MachineBasicBlock::const_instr_iterator MBBI = MFI->instr_begin(), |
| 304 | MBBE = MFI->instr_end(); MBBI != MBBE; ++MBBI) { |
Jakob Stoklund Olesen | 7bd46da | 2011-01-12 21:27:41 +0000 | [diff] [blame] | 305 | if (MBBI->getParent() != MFI) { |
| 306 | report("Bad instruction parent pointer", MFI); |
| 307 | *OS << "Instruction: " << *MBBI; |
| 308 | continue; |
| 309 | } |
Jakob Stoklund Olesen | 1f9c3ec | 2012-06-06 22:34:30 +0000 | [diff] [blame] | 310 | // Is this a bundle header? |
| 311 | if (!MBBI->isInsideBundle()) { |
| 312 | if (CurBundle) |
| 313 | visitMachineBundleAfter(CurBundle); |
| 314 | CurBundle = MBBI; |
| 315 | visitMachineBundleBefore(CurBundle); |
| 316 | } else if (!CurBundle) |
| 317 | report("No bundle header", MBBI); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 318 | visitMachineInstrBefore(MBBI); |
| 319 | for (unsigned I = 0, E = MBBI->getNumOperands(); I != E; ++I) |
| 320 | visitMachineOperand(&MBBI->getOperand(I), I); |
| 321 | visitMachineInstrAfter(MBBI); |
| 322 | } |
Jakob Stoklund Olesen | 1f9c3ec | 2012-06-06 22:34:30 +0000 | [diff] [blame] | 323 | if (CurBundle) |
| 324 | visitMachineBundleAfter(CurBundle); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 325 | visitMachineBasicBlockAfter(MFI); |
| 326 | } |
| 327 | visitMachineFunctionAfter(); |
| 328 | |
Chris Lattner | 17e9edc | 2009-08-23 02:51:22 +0000 | [diff] [blame] | 329 | if (OutFile) |
| 330 | delete OutFile; |
| 331 | else if (foundErrors) |
Chris Lattner | 75361b6 | 2010-04-07 22:58:41 +0000 | [diff] [blame] | 332 | report_fatal_error("Found "+Twine(foundErrors)+" machine code errors."); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 333 | |
Jakob Stoklund Olesen | 6349668 | 2009-08-08 15:34:50 +0000 | [diff] [blame] | 334 | // Clean up. |
| 335 | regsLive.clear(); |
| 336 | regsDefined.clear(); |
| 337 | regsDead.clear(); |
| 338 | regsKilled.clear(); |
Jakob Stoklund Olesen | 9ca12d2 | 2012-02-28 01:42:41 +0000 | [diff] [blame] | 339 | regMasks.clear(); |
Jakob Stoklund Olesen | 6349668 | 2009-08-08 15:34:50 +0000 | [diff] [blame] | 340 | regsLiveInButUnused.clear(); |
| 341 | MBBInfoMap.clear(); |
| 342 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 343 | return false; // no changes |
| 344 | } |
| 345 | |
Chris Lattner | 372fefe | 2009-08-23 01:03:30 +0000 | [diff] [blame] | 346 | void MachineVerifier::report(const char *msg, const MachineFunction *MF) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 347 | assert(MF); |
Chris Lattner | 17e9edc | 2009-08-23 02:51:22 +0000 | [diff] [blame] | 348 | *OS << '\n'; |
Jakob Stoklund Olesen | 89cab93 | 2010-12-18 00:06:56 +0000 | [diff] [blame] | 349 | if (!foundErrors++) { |
| 350 | if (Banner) |
| 351 | *OS << "# " << Banner << '\n'; |
Jakob Stoklund Olesen | f4a1e1a | 2010-10-26 20:21:46 +0000 | [diff] [blame] | 352 | MF->print(*OS, Indexes); |
Jakob Stoklund Olesen | 89cab93 | 2010-12-18 00:06:56 +0000 | [diff] [blame] | 353 | } |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 354 | *OS << "*** Bad machine code: " << msg << " ***\n" |
Benjamin Kramer | a7b0cb7 | 2011-11-15 16:27:03 +0000 | [diff] [blame] | 355 | << "- function: " << MF->getFunction()->getName() << "\n"; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 358 | void MachineVerifier::report(const char *msg, const MachineBasicBlock *MBB) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 359 | assert(MBB); |
| 360 | report(msg, MBB->getParent()); |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 361 | *OS << "- basic block: BB#" << MBB->getNumber() |
| 362 | << ' ' << MBB->getName() |
| 363 | << " (" << (void*)MBB << ')'; |
Jakob Stoklund Olesen | f4a1e1a | 2010-10-26 20:21:46 +0000 | [diff] [blame] | 364 | if (Indexes) |
| 365 | *OS << " [" << Indexes->getMBBStartIdx(MBB) |
| 366 | << ';' << Indexes->getMBBEndIdx(MBB) << ')'; |
| 367 | *OS << '\n'; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 370 | void MachineVerifier::report(const char *msg, const MachineInstr *MI) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 371 | assert(MI); |
| 372 | report(msg, MI->getParent()); |
| 373 | *OS << "- instruction: "; |
Jakob Stoklund Olesen | f4a1e1a | 2010-10-26 20:21:46 +0000 | [diff] [blame] | 374 | if (Indexes && Indexes->hasIndex(MI)) |
| 375 | *OS << Indexes->getInstructionIndex(MI) << '\t'; |
Chris Lattner | 705e07f | 2009-08-23 03:41:05 +0000 | [diff] [blame] | 376 | MI->print(*OS, TM); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 379 | void MachineVerifier::report(const char *msg, |
| 380 | const MachineOperand *MO, unsigned MONum) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 381 | assert(MO); |
| 382 | report(msg, MO->getParent()); |
| 383 | *OS << "- operand " << MONum << ": "; |
| 384 | MO->print(*OS, TM); |
| 385 | *OS << "\n"; |
| 386 | } |
| 387 | |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 388 | void MachineVerifier::report(const char *msg, const MachineFunction *MF, |
| 389 | const LiveInterval &LI) { |
| 390 | report(msg, MF); |
| 391 | *OS << "- interval: "; |
| 392 | if (TargetRegisterInfo::isVirtualRegister(LI.reg)) |
| 393 | *OS << PrintReg(LI.reg, TRI); |
| 394 | else |
| 395 | *OS << PrintRegUnit(LI.reg, TRI); |
| 396 | *OS << ' ' << LI << '\n'; |
| 397 | } |
| 398 | |
| 399 | void MachineVerifier::report(const char *msg, const MachineBasicBlock *MBB, |
| 400 | const LiveInterval &LI) { |
| 401 | report(msg, MBB); |
| 402 | *OS << "- interval: "; |
| 403 | if (TargetRegisterInfo::isVirtualRegister(LI.reg)) |
| 404 | *OS << PrintReg(LI.reg, TRI); |
| 405 | else |
| 406 | *OS << PrintRegUnit(LI.reg, TRI); |
| 407 | *OS << ' ' << LI << '\n'; |
| 408 | } |
| 409 | |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 410 | void MachineVerifier::markReachable(const MachineBasicBlock *MBB) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 411 | BBInfo &MInfo = MBBInfoMap[MBB]; |
| 412 | if (!MInfo.reachable) { |
| 413 | MInfo.reachable = true; |
| 414 | for (MachineBasicBlock::const_succ_iterator SuI = MBB->succ_begin(), |
| 415 | SuE = MBB->succ_end(); SuI != SuE; ++SuI) |
| 416 | markReachable(*SuI); |
| 417 | } |
| 418 | } |
| 419 | |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 420 | void MachineVerifier::visitMachineFunctionBefore() { |
Jakob Stoklund Olesen | fc69c37 | 2011-01-12 21:27:48 +0000 | [diff] [blame] | 421 | lastIndex = SlotIndex(); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 422 | regsReserved = TRI->getReservedRegs(*MF); |
Jakob Stoklund Olesen | d37bc5a | 2009-08-04 19:18:01 +0000 | [diff] [blame] | 423 | |
| 424 | // A sub-register of a reserved register is also reserved |
| 425 | for (int Reg = regsReserved.find_first(); Reg>=0; |
| 426 | Reg = regsReserved.find_next(Reg)) { |
Jakob Stoklund Olesen | 396618b | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 427 | for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) { |
Jakob Stoklund Olesen | d37bc5a | 2009-08-04 19:18:01 +0000 | [diff] [blame] | 428 | // FIXME: This should probably be: |
Jakob Stoklund Olesen | 396618b | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 429 | // assert(regsReserved.test(*SubRegs) && "Non-reserved sub-register"); |
| 430 | regsReserved.set(*SubRegs); |
Jakob Stoklund Olesen | d37bc5a | 2009-08-04 19:18:01 +0000 | [diff] [blame] | 431 | } |
| 432 | } |
Lang Hames | 03698de | 2012-02-14 19:17:48 +0000 | [diff] [blame] | 433 | |
| 434 | regsAllocatable = TRI->getAllocatableSet(*MF); |
| 435 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 436 | markReachable(&MF->front()); |
| 437 | } |
| 438 | |
Jakob Stoklund Olesen | 1dc0fcb | 2009-11-13 21:55:54 +0000 | [diff] [blame] | 439 | // Does iterator point to a and b as the first two elements? |
Dan Gohman | b357983 | 2010-04-15 17:08:50 +0000 | [diff] [blame] | 440 | static bool matchPair(MachineBasicBlock::const_succ_iterator i, |
| 441 | const MachineBasicBlock *a, const MachineBasicBlock *b) { |
Jakob Stoklund Olesen | 1dc0fcb | 2009-11-13 21:55:54 +0000 | [diff] [blame] | 442 | if (*i == a) |
| 443 | return *++i == b; |
| 444 | if (*i == b) |
| 445 | return *++i == a; |
| 446 | return false; |
| 447 | } |
| 448 | |
| 449 | void |
| 450 | MachineVerifier::visitMachineBasicBlockBefore(const MachineBasicBlock *MBB) { |
Jakob Stoklund Olesen | 5adc07e | 2011-09-23 22:45:39 +0000 | [diff] [blame] | 451 | FirstTerminator = 0; |
| 452 | |
Lang Hames | 03698de | 2012-02-14 19:17:48 +0000 | [diff] [blame] | 453 | if (MRI->isSSA()) { |
| 454 | // If this block has allocatable physical registers live-in, check that |
| 455 | // it is an entry block or landing pad. |
| 456 | for (MachineBasicBlock::livein_iterator LI = MBB->livein_begin(), |
| 457 | LE = MBB->livein_end(); |
| 458 | LI != LE; ++LI) { |
| 459 | unsigned reg = *LI; |
| 460 | if (isAllocatable(reg) && !MBB->isLandingPad() && |
| 461 | MBB != MBB->getParent()->begin()) { |
| 462 | report("MBB has allocable live-in, but isn't entry or landing-pad.", MBB); |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
Jakob Stoklund Olesen | 0a7bbcb | 2010-10-21 18:47:06 +0000 | [diff] [blame] | 467 | // Count the number of landing pad successors. |
Cameron Zwarich | 2100d21 | 2010-12-20 04:19:48 +0000 | [diff] [blame] | 468 | SmallPtrSet<MachineBasicBlock*, 4> LandingPadSuccs; |
Jakob Stoklund Olesen | 0a7bbcb | 2010-10-21 18:47:06 +0000 | [diff] [blame] | 469 | for (MachineBasicBlock::const_succ_iterator I = MBB->succ_begin(), |
Cameron Zwarich | 2100d21 | 2010-12-20 04:19:48 +0000 | [diff] [blame] | 470 | E = MBB->succ_end(); I != E; ++I) { |
| 471 | if ((*I)->isLandingPad()) |
| 472 | LandingPadSuccs.insert(*I); |
| 473 | } |
Bill Wendling | d29052b | 2011-05-04 22:54:05 +0000 | [diff] [blame] | 474 | |
| 475 | const MCAsmInfo *AsmInfo = TM->getMCAsmInfo(); |
| 476 | const BasicBlock *BB = MBB->getBasicBlock(); |
| 477 | if (LandingPadSuccs.size() > 1 && |
| 478 | !(AsmInfo && |
| 479 | AsmInfo->getExceptionHandlingType() == ExceptionHandling::SjLj && |
| 480 | BB && isa<SwitchInst>(BB->getTerminator()))) |
Jakob Stoklund Olesen | 0a7bbcb | 2010-10-21 18:47:06 +0000 | [diff] [blame] | 481 | report("MBB has more than one landing pad successor", MBB); |
| 482 | |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 483 | // Call AnalyzeBranch. If it succeeds, there several more conditions to check. |
| 484 | MachineBasicBlock *TBB = 0, *FBB = 0; |
| 485 | SmallVector<MachineOperand, 4> Cond; |
| 486 | if (!TII->AnalyzeBranch(*const_cast<MachineBasicBlock *>(MBB), |
| 487 | TBB, FBB, Cond)) { |
| 488 | // Ok, AnalyzeBranch thinks it knows what's going on with this block. Let's |
| 489 | // check whether its answers match up with reality. |
| 490 | if (!TBB && !FBB) { |
| 491 | // Block falls through to its successor. |
| 492 | MachineFunction::const_iterator MBBI = MBB; |
| 493 | ++MBBI; |
| 494 | if (MBBI == MF->end()) { |
Dan Gohman | a01a80f | 2009-08-27 18:14:26 +0000 | [diff] [blame] | 495 | // It's possible that the block legitimately ends with a noreturn |
| 496 | // call or an unreachable, in which case it won't actually fall |
| 497 | // out the bottom of the function. |
Cameron Zwarich | 2100d21 | 2010-12-20 04:19:48 +0000 | [diff] [blame] | 498 | } else if (MBB->succ_size() == LandingPadSuccs.size()) { |
Dan Gohman | a01a80f | 2009-08-27 18:14:26 +0000 | [diff] [blame] | 499 | // It's possible that the block legitimately ends with a noreturn |
| 500 | // call or an unreachable, in which case it won't actuall fall |
| 501 | // out of the block. |
Cameron Zwarich | 2100d21 | 2010-12-20 04:19:48 +0000 | [diff] [blame] | 502 | } else if (MBB->succ_size() != 1+LandingPadSuccs.size()) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 503 | report("MBB exits via unconditional fall-through but doesn't have " |
| 504 | "exactly one CFG successor!", MBB); |
Jakob Stoklund Olesen | 0a7bbcb | 2010-10-21 18:47:06 +0000 | [diff] [blame] | 505 | } else if (!MBB->isSuccessor(MBBI)) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 506 | report("MBB exits via unconditional fall-through but its successor " |
| 507 | "differs from its CFG successor!", MBB); |
| 508 | } |
Akira Hatanaka | 6b0cd9b | 2012-06-14 20:51:13 +0000 | [diff] [blame] | 509 | if (!MBB->empty() && getBundleStart(&MBB->back())->isBarrier() && |
| 510 | !TII->isPredicated(getBundleStart(&MBB->back()))) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 511 | report("MBB exits via unconditional fall-through but ends with a " |
| 512 | "barrier instruction!", MBB); |
| 513 | } |
| 514 | if (!Cond.empty()) { |
| 515 | report("MBB exits via unconditional fall-through but has a condition!", |
| 516 | MBB); |
| 517 | } |
| 518 | } else if (TBB && !FBB && Cond.empty()) { |
| 519 | // Block unconditionally branches somewhere. |
Cameron Zwarich | 2100d21 | 2010-12-20 04:19:48 +0000 | [diff] [blame] | 520 | if (MBB->succ_size() != 1+LandingPadSuccs.size()) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 521 | report("MBB exits via unconditional branch but doesn't have " |
| 522 | "exactly one CFG successor!", MBB); |
Jakob Stoklund Olesen | 0a7bbcb | 2010-10-21 18:47:06 +0000 | [diff] [blame] | 523 | } else if (!MBB->isSuccessor(TBB)) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 524 | report("MBB exits via unconditional branch but the CFG " |
| 525 | "successor doesn't match the actual successor!", MBB); |
| 526 | } |
| 527 | if (MBB->empty()) { |
| 528 | report("MBB exits via unconditional branch but doesn't contain " |
| 529 | "any instructions!", MBB); |
Akira Hatanaka | 6b0cd9b | 2012-06-14 20:51:13 +0000 | [diff] [blame] | 530 | } else if (!getBundleStart(&MBB->back())->isBarrier()) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 531 | report("MBB exits via unconditional branch but doesn't end with a " |
| 532 | "barrier instruction!", MBB); |
Akira Hatanaka | 6b0cd9b | 2012-06-14 20:51:13 +0000 | [diff] [blame] | 533 | } else if (!getBundleStart(&MBB->back())->isTerminator()) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 534 | report("MBB exits via unconditional branch but the branch isn't a " |
| 535 | "terminator instruction!", MBB); |
| 536 | } |
| 537 | } else if (TBB && !FBB && !Cond.empty()) { |
| 538 | // Block conditionally branches somewhere, otherwise falls through. |
| 539 | MachineFunction::const_iterator MBBI = MBB; |
| 540 | ++MBBI; |
| 541 | if (MBBI == MF->end()) { |
| 542 | report("MBB conditionally falls through out of function!", MBB); |
| 543 | } if (MBB->succ_size() != 2) { |
| 544 | report("MBB exits via conditional branch/fall-through but doesn't have " |
| 545 | "exactly two CFG successors!", MBB); |
Jakob Stoklund Olesen | 1dc0fcb | 2009-11-13 21:55:54 +0000 | [diff] [blame] | 546 | } else if (!matchPair(MBB->succ_begin(), TBB, MBBI)) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 547 | report("MBB exits via conditional branch/fall-through but the CFG " |
| 548 | "successors don't match the actual successors!", MBB); |
| 549 | } |
| 550 | if (MBB->empty()) { |
| 551 | report("MBB exits via conditional branch/fall-through but doesn't " |
| 552 | "contain any instructions!", MBB); |
Akira Hatanaka | 6b0cd9b | 2012-06-14 20:51:13 +0000 | [diff] [blame] | 553 | } else if (getBundleStart(&MBB->back())->isBarrier()) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 554 | report("MBB exits via conditional branch/fall-through but ends with a " |
| 555 | "barrier instruction!", MBB); |
Akira Hatanaka | 6b0cd9b | 2012-06-14 20:51:13 +0000 | [diff] [blame] | 556 | } else if (!getBundleStart(&MBB->back())->isTerminator()) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 557 | report("MBB exits via conditional branch/fall-through but the branch " |
| 558 | "isn't a terminator instruction!", MBB); |
| 559 | } |
| 560 | } else if (TBB && FBB) { |
| 561 | // Block conditionally branches somewhere, otherwise branches |
| 562 | // somewhere else. |
| 563 | if (MBB->succ_size() != 2) { |
| 564 | report("MBB exits via conditional branch/branch but doesn't have " |
| 565 | "exactly two CFG successors!", MBB); |
Jakob Stoklund Olesen | 1dc0fcb | 2009-11-13 21:55:54 +0000 | [diff] [blame] | 566 | } else if (!matchPair(MBB->succ_begin(), TBB, FBB)) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 567 | report("MBB exits via conditional branch/branch but the CFG " |
| 568 | "successors don't match the actual successors!", MBB); |
| 569 | } |
| 570 | if (MBB->empty()) { |
| 571 | report("MBB exits via conditional branch/branch but doesn't " |
| 572 | "contain any instructions!", MBB); |
Akira Hatanaka | 6b0cd9b | 2012-06-14 20:51:13 +0000 | [diff] [blame] | 573 | } else if (!getBundleStart(&MBB->back())->isBarrier()) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 574 | report("MBB exits via conditional branch/branch but doesn't end with a " |
| 575 | "barrier instruction!", MBB); |
Akira Hatanaka | 6b0cd9b | 2012-06-14 20:51:13 +0000 | [diff] [blame] | 576 | } else if (!getBundleStart(&MBB->back())->isTerminator()) { |
Dan Gohman | 2792059 | 2009-08-27 02:43:49 +0000 | [diff] [blame] | 577 | report("MBB exits via conditional branch/branch but the branch " |
| 578 | "isn't a terminator instruction!", MBB); |
| 579 | } |
| 580 | if (Cond.empty()) { |
| 581 | report("MBB exits via conditinal branch/branch but there's no " |
| 582 | "condition!", MBB); |
| 583 | } |
| 584 | } else { |
| 585 | report("AnalyzeBranch returned invalid data!", MBB); |
| 586 | } |
| 587 | } |
| 588 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 589 | regsLive.clear(); |
Dan Gohman | 81bf03e | 2010-04-13 16:57:55 +0000 | [diff] [blame] | 590 | for (MachineBasicBlock::livein_iterator I = MBB->livein_begin(), |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 591 | E = MBB->livein_end(); I != E; ++I) { |
| 592 | if (!TargetRegisterInfo::isPhysicalRegister(*I)) { |
| 593 | report("MBB live-in list contains non-physical register", MBB); |
| 594 | continue; |
| 595 | } |
| 596 | regsLive.insert(*I); |
Jakob Stoklund Olesen | 396618b | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 597 | for (MCSubRegIterator SubRegs(*I, TRI); SubRegs.isValid(); ++SubRegs) |
| 598 | regsLive.insert(*SubRegs); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 599 | } |
Jakob Stoklund Olesen | 710b13b | 2009-08-08 13:19:25 +0000 | [diff] [blame] | 600 | regsLiveInButUnused = regsLive; |
Jakob Stoklund Olesen | a6b677d | 2009-08-13 16:19:51 +0000 | [diff] [blame] | 601 | |
| 602 | const MachineFrameInfo *MFI = MF->getFrameInfo(); |
| 603 | assert(MFI && "Function has no frame info"); |
| 604 | BitVector PR = MFI->getPristineRegs(MBB); |
| 605 | for (int I = PR.find_first(); I>0; I = PR.find_next(I)) { |
| 606 | regsLive.insert(I); |
Jakob Stoklund Olesen | 396618b | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 607 | for (MCSubRegIterator SubRegs(I, TRI); SubRegs.isValid(); ++SubRegs) |
| 608 | regsLive.insert(*SubRegs); |
Jakob Stoklund Olesen | a6b677d | 2009-08-13 16:19:51 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 611 | regsKilled.clear(); |
| 612 | regsDefined.clear(); |
Jakob Stoklund Olesen | fc69c37 | 2011-01-12 21:27:48 +0000 | [diff] [blame] | 613 | |
| 614 | if (Indexes) |
| 615 | lastIndex = Indexes->getMBBStartIdx(MBB); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Jakob Stoklund Olesen | 1f9c3ec | 2012-06-06 22:34:30 +0000 | [diff] [blame] | 618 | // This function gets called for all bundle headers, including normal |
| 619 | // stand-alone unbundled instructions. |
| 620 | void MachineVerifier::visitMachineBundleBefore(const MachineInstr *MI) { |
| 621 | if (Indexes && Indexes->hasIndex(MI)) { |
| 622 | SlotIndex idx = Indexes->getInstructionIndex(MI); |
| 623 | if (!(idx > lastIndex)) { |
| 624 | report("Instruction index out of order", MI); |
| 625 | *OS << "Last instruction was at " << lastIndex << '\n'; |
| 626 | } |
| 627 | lastIndex = idx; |
| 628 | } |
Pete Cooper | 83569cb | 2012-06-07 17:41:39 +0000 | [diff] [blame] | 629 | |
| 630 | // Ensure non-terminators don't follow terminators. |
| 631 | // Ignore predicated terminators formed by if conversion. |
| 632 | // FIXME: If conversion shouldn't need to violate this rule. |
| 633 | if (MI->isTerminator() && !TII->isPredicated(MI)) { |
| 634 | if (!FirstTerminator) |
| 635 | FirstTerminator = MI; |
| 636 | } else if (FirstTerminator) { |
| 637 | report("Non-terminator instruction after the first terminator", MI); |
| 638 | *OS << "First terminator was:\t" << *FirstTerminator; |
| 639 | } |
Jakob Stoklund Olesen | 1f9c3ec | 2012-06-06 22:34:30 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 642 | void MachineVerifier::visitMachineInstrBefore(const MachineInstr *MI) { |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 643 | const MCInstrDesc &MCID = MI->getDesc(); |
| 644 | if (MI->getNumOperands() < MCID.getNumOperands()) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 645 | report("Too few operands", MI); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 646 | *OS << MCID.getNumOperands() << " operands expected, but " |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 647 | << MI->getNumExplicitOperands() << " given.\n"; |
| 648 | } |
Dan Gohman | 2dbc4c8 | 2009-10-07 17:36:00 +0000 | [diff] [blame] | 649 | |
| 650 | // Check the MachineMemOperands for basic consistency. |
| 651 | for (MachineInstr::mmo_iterator I = MI->memoperands_begin(), |
| 652 | E = MI->memoperands_end(); I != E; ++I) { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 653 | if ((*I)->isLoad() && !MI->mayLoad()) |
Dan Gohman | 2dbc4c8 | 2009-10-07 17:36:00 +0000 | [diff] [blame] | 654 | report("Missing mayLoad flag", MI); |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 655 | if ((*I)->isStore() && !MI->mayStore()) |
Dan Gohman | 2dbc4c8 | 2009-10-07 17:36:00 +0000 | [diff] [blame] | 656 | report("Missing mayStore flag", MI); |
| 657 | } |
Jakob Stoklund Olesen | 1fe9c34 | 2010-08-05 22:32:21 +0000 | [diff] [blame] | 658 | |
| 659 | // Debug values must not have a slot index. |
Jakob Stoklund Olesen | 121b179 | 2012-02-27 18:24:30 +0000 | [diff] [blame] | 660 | // Other instructions must have one, unless they are inside a bundle. |
Jakob Stoklund Olesen | 1fe9c34 | 2010-08-05 22:32:21 +0000 | [diff] [blame] | 661 | if (LiveInts) { |
| 662 | bool mapped = !LiveInts->isNotInMIMap(MI); |
| 663 | if (MI->isDebugValue()) { |
| 664 | if (mapped) |
| 665 | report("Debug instruction has a slot index", MI); |
Jakob Stoklund Olesen | 121b179 | 2012-02-27 18:24:30 +0000 | [diff] [blame] | 666 | } else if (MI->isInsideBundle()) { |
| 667 | if (mapped) |
| 668 | report("Instruction inside bundle has a slot index", MI); |
Jakob Stoklund Olesen | 1fe9c34 | 2010-08-05 22:32:21 +0000 | [diff] [blame] | 669 | } else { |
| 670 | if (!mapped) |
| 671 | report("Missing slot index", MI); |
| 672 | } |
| 673 | } |
| 674 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 675 | StringRef ErrorInfo; |
| 676 | if (!TII->verifyInstruction(MI, ErrorInfo)) |
| 677 | report(ErrorInfo.data(), MI); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | void |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 681 | MachineVerifier::visitMachineOperand(const MachineOperand *MO, unsigned MONum) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 682 | const MachineInstr *MI = MO->getParent(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 683 | const MCInstrDesc &MCID = MI->getDesc(); |
| 684 | const MCOperandInfo &MCOI = MCID.OpInfo[MONum]; |
Jakob Stoklund Olesen | 44b27e5 | 2009-05-16 07:25:20 +0000 | [diff] [blame] | 685 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 686 | // The first MCID.NumDefs operands must be explicit register defines |
| 687 | if (MONum < MCID.getNumDefs()) { |
Jakob Stoklund Olesen | 44b27e5 | 2009-05-16 07:25:20 +0000 | [diff] [blame] | 688 | if (!MO->isReg()) |
| 689 | report("Explicit definition must be a register", MO, MONum); |
Evan Cheng | cac58aa | 2012-05-29 19:40:44 +0000 | [diff] [blame] | 690 | else if (!MO->isDef() && !MCOI.isOptionalDef()) |
Jakob Stoklund Olesen | 44b27e5 | 2009-05-16 07:25:20 +0000 | [diff] [blame] | 691 | report("Explicit definition marked as use", MO, MONum); |
| 692 | else if (MO->isImplicit()) |
| 693 | report("Explicit definition marked as implicit", MO, MONum); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 694 | } else if (MONum < MCID.getNumOperands()) { |
Eric Christopher | 113a06c | 2010-11-17 00:55:36 +0000 | [diff] [blame] | 695 | // Don't check if it's the last operand in a variadic instruction. See, |
| 696 | // e.g., LDM_RET in the arm back end. |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 697 | if (MO->isReg() && |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 698 | !(MI->isVariadic() && MONum == MCID.getNumOperands()-1)) { |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 699 | if (MO->isDef() && !MCOI.isOptionalDef()) |
Cameron Zwarich | 22d67cf | 2010-12-19 21:37:23 +0000 | [diff] [blame] | 700 | report("Explicit operand marked as def", MO, MONum); |
Jakob Stoklund Olesen | 39523e2 | 2009-09-23 20:57:55 +0000 | [diff] [blame] | 701 | if (MO->isImplicit()) |
| 702 | report("Explicit operand marked as implicit", MO, MONum); |
| 703 | } |
| 704 | } else { |
Jakob Stoklund Olesen | 5711564 | 2009-12-22 21:48:20 +0000 | [diff] [blame] | 705 | // ARM adds %reg0 operands to indicate predicates. We'll allow that. |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 706 | if (MO->isReg() && !MO->isImplicit() && !MI->isVariadic() && MO->getReg()) |
Jakob Stoklund Olesen | 39523e2 | 2009-09-23 20:57:55 +0000 | [diff] [blame] | 707 | report("Extra explicit operand on non-variadic instruction", MO, MONum); |
Jakob Stoklund Olesen | 44b27e5 | 2009-05-16 07:25:20 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 710 | switch (MO->getType()) { |
| 711 | case MachineOperand::MO_Register: { |
| 712 | const unsigned Reg = MO->getReg(); |
| 713 | if (!Reg) |
| 714 | return; |
Jakob Stoklund Olesen | 948a444 | 2012-03-28 20:47:35 +0000 | [diff] [blame] | 715 | if (MRI->tracksLiveness() && !MI->isDebugValue()) |
| 716 | checkLiveness(MO, MONum); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 717 | |
Jakob Stoklund Olesen | eba2bbb | 2012-07-25 16:49:11 +0000 | [diff] [blame] | 718 | // Verify two-address constraints after leaving SSA form. |
| 719 | unsigned DefIdx; |
| 720 | if (!MRI->isSSA() && MO->isUse() && |
| 721 | MI->isRegTiedToDefOperand(MONum, &DefIdx) && |
| 722 | Reg != MI->getOperand(DefIdx).getReg()) |
| 723 | report("Two-address instruction operands must be identical", MO, MONum); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 724 | |
| 725 | // Check register classes. |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 726 | if (MONum < MCID.getNumOperands() && !MO->isImplicit()) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 727 | unsigned SubIdx = MO->getSubReg(); |
| 728 | |
| 729 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 730 | if (SubIdx) { |
Jakob Stoklund Olesen | b4a0221 | 2011-10-05 22:12:57 +0000 | [diff] [blame] | 731 | report("Illegal subregister index for physical register", MO, MONum); |
| 732 | return; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 733 | } |
Jakob Stoklund Olesen | 397fc48 | 2012-05-07 22:10:26 +0000 | [diff] [blame] | 734 | if (const TargetRegisterClass *DRC = |
| 735 | TII->getRegClass(MCID, MONum, TRI, *MF)) { |
Jakob Stoklund Olesen | b4a0221 | 2011-10-05 22:12:57 +0000 | [diff] [blame] | 736 | if (!DRC->contains(Reg)) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 737 | report("Illegal physical register for instruction", MO, MONum); |
Jakob Stoklund Olesen | b4a0221 | 2011-10-05 22:12:57 +0000 | [diff] [blame] | 738 | *OS << TRI->getName(Reg) << " is not a " |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 739 | << DRC->getName() << " register.\n"; |
| 740 | } |
| 741 | } |
| 742 | } else { |
| 743 | // Virtual register. |
| 744 | const TargetRegisterClass *RC = MRI->getRegClass(Reg); |
| 745 | if (SubIdx) { |
Jakob Stoklund Olesen | b4a0221 | 2011-10-05 22:12:57 +0000 | [diff] [blame] | 746 | const TargetRegisterClass *SRC = |
| 747 | TRI->getSubClassWithSubReg(RC, SubIdx); |
Jakob Stoklund Olesen | 6a8d2c6 | 2010-05-18 17:31:12 +0000 | [diff] [blame] | 748 | if (!SRC) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 749 | report("Invalid subregister index for virtual register", MO, MONum); |
Jakob Stoklund Olesen | 6a8d2c6 | 2010-05-18 17:31:12 +0000 | [diff] [blame] | 750 | *OS << "Register class " << RC->getName() |
| 751 | << " does not support subreg index " << SubIdx << "\n"; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 752 | return; |
| 753 | } |
Jakob Stoklund Olesen | b4a0221 | 2011-10-05 22:12:57 +0000 | [diff] [blame] | 754 | if (RC != SRC) { |
| 755 | report("Invalid register class for subregister index", MO, MONum); |
| 756 | *OS << "Register class " << RC->getName() |
| 757 | << " does not fully support subreg index " << SubIdx << "\n"; |
| 758 | return; |
| 759 | } |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 760 | } |
Jakob Stoklund Olesen | 397fc48 | 2012-05-07 22:10:26 +0000 | [diff] [blame] | 761 | if (const TargetRegisterClass *DRC = |
| 762 | TII->getRegClass(MCID, MONum, TRI, *MF)) { |
Jakob Stoklund Olesen | b4a0221 | 2011-10-05 22:12:57 +0000 | [diff] [blame] | 763 | if (SubIdx) { |
| 764 | const TargetRegisterClass *SuperRC = |
| 765 | TRI->getLargestLegalSuperClass(RC); |
| 766 | if (!SuperRC) { |
| 767 | report("No largest legal super class exists.", MO, MONum); |
| 768 | return; |
| 769 | } |
| 770 | DRC = TRI->getMatchingSuperRegClass(SuperRC, DRC, SubIdx); |
| 771 | if (!DRC) { |
| 772 | report("No matching super-reg register class.", MO, MONum); |
| 773 | return; |
| 774 | } |
| 775 | } |
Jakob Stoklund Olesen | fa226bc | 2011-06-02 05:43:46 +0000 | [diff] [blame] | 776 | if (!RC->hasSuperClassEq(DRC)) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 777 | report("Illegal virtual register for instruction", MO, MONum); |
| 778 | *OS << "Expected a " << DRC->getName() << " register, but got a " |
| 779 | << RC->getName() << " register\n"; |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | break; |
| 785 | } |
Jakob Stoklund Olesen | a5ba07c | 2009-09-21 07:19:08 +0000 | [diff] [blame] | 786 | |
Jakob Stoklund Olesen | 9ca12d2 | 2012-02-28 01:42:41 +0000 | [diff] [blame] | 787 | case MachineOperand::MO_RegisterMask: |
| 788 | regMasks.push_back(MO->getRegMask()); |
| 789 | break; |
| 790 | |
Jakob Stoklund Olesen | a5ba07c | 2009-09-21 07:19:08 +0000 | [diff] [blame] | 791 | case MachineOperand::MO_MachineBasicBlock: |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 792 | if (MI->isPHI() && !MO->getMBB()->isSuccessor(MI->getParent())) |
| 793 | report("PHI operand is not in the CFG", MO, MONum); |
Jakob Stoklund Olesen | a5ba07c | 2009-09-21 07:19:08 +0000 | [diff] [blame] | 794 | break; |
| 795 | |
Jakob Stoklund Olesen | e8f0823 | 2010-11-01 19:49:52 +0000 | [diff] [blame] | 796 | case MachineOperand::MO_FrameIndex: |
| 797 | if (LiveStks && LiveStks->hasInterval(MO->getIndex()) && |
| 798 | LiveInts && !LiveInts->isNotInMIMap(MI)) { |
| 799 | LiveInterval &LI = LiveStks->getInterval(MO->getIndex()); |
| 800 | SlotIndex Idx = LiveInts->getInstructionIndex(MI); |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 801 | if (MI->mayLoad() && !LI.liveAt(Idx.getRegSlot(true))) { |
Jakob Stoklund Olesen | e8f0823 | 2010-11-01 19:49:52 +0000 | [diff] [blame] | 802 | report("Instruction loads from dead spill slot", MO, MONum); |
| 803 | *OS << "Live stack: " << LI << '\n'; |
| 804 | } |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 805 | if (MI->mayStore() && !LI.liveAt(Idx.getRegSlot())) { |
Jakob Stoklund Olesen | e8f0823 | 2010-11-01 19:49:52 +0000 | [diff] [blame] | 806 | report("Instruction stores to dead spill slot", MO, MONum); |
| 807 | *OS << "Live stack: " << LI << '\n'; |
| 808 | } |
| 809 | } |
| 810 | break; |
| 811 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 812 | default: |
| 813 | break; |
| 814 | } |
| 815 | } |
| 816 | |
Jakob Stoklund Olesen | 948a444 | 2012-03-28 20:47:35 +0000 | [diff] [blame] | 817 | void MachineVerifier::checkLiveness(const MachineOperand *MO, unsigned MONum) { |
| 818 | const MachineInstr *MI = MO->getParent(); |
| 819 | const unsigned Reg = MO->getReg(); |
| 820 | |
| 821 | // Both use and def operands can read a register. |
| 822 | if (MO->readsReg()) { |
| 823 | regsLiveInButUnused.erase(Reg); |
| 824 | |
Jakob Stoklund Olesen | eba2bbb | 2012-07-25 16:49:11 +0000 | [diff] [blame] | 825 | if (MO->isKill()) |
Jakob Stoklund Olesen | 948a444 | 2012-03-28 20:47:35 +0000 | [diff] [blame] | 826 | addRegWithSubRegs(regsKilled, Reg); |
| 827 | |
| 828 | // Check that LiveVars knows this kill. |
| 829 | if (LiveVars && TargetRegisterInfo::isVirtualRegister(Reg) && |
| 830 | MO->isKill()) { |
| 831 | LiveVariables::VarInfo &VI = LiveVars->getVarInfo(Reg); |
| 832 | if (std::find(VI.Kills.begin(), VI.Kills.end(), MI) == VI.Kills.end()) |
| 833 | report("Kill missing from LiveVariables", MO, MONum); |
| 834 | } |
| 835 | |
| 836 | // Check LiveInts liveness and kill. |
Jakob Stoklund Olesen | a62e1e8 | 2012-08-01 23:52:40 +0000 | [diff] [blame] | 837 | if (LiveInts && !LiveInts->isNotInMIMap(MI)) { |
| 838 | SlotIndex UseIdx = LiveInts->getInstructionIndex(MI); |
| 839 | // Check the cached regunit intervals. |
| 840 | if (TargetRegisterInfo::isPhysicalRegister(Reg) && !isReserved(Reg)) { |
| 841 | for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units) { |
| 842 | if (const LiveInterval *LI = LiveInts->getCachedRegUnit(*Units)) { |
| 843 | LiveRangeQuery LRQ(*LI, UseIdx); |
| 844 | if (!LRQ.valueIn()) { |
| 845 | report("No live range at use", MO, MONum); |
| 846 | *OS << UseIdx << " is not live in " << PrintRegUnit(*Units, TRI) |
| 847 | << ' ' << *LI << '\n'; |
| 848 | } |
| 849 | if (MO->isKill() && !LRQ.isKill()) { |
| 850 | report("Live range continues after kill flag", MO, MONum); |
| 851 | *OS << PrintRegUnit(*Units, TRI) << ' ' << *LI << '\n'; |
| 852 | } |
| 853 | } |
Jakob Stoklund Olesen | 948a444 | 2012-03-28 20:47:35 +0000 | [diff] [blame] | 854 | } |
Jakob Stoklund Olesen | a62e1e8 | 2012-08-01 23:52:40 +0000 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | if (TargetRegisterInfo::isVirtualRegister(Reg)) { |
| 858 | if (LiveInts->hasInterval(Reg)) { |
| 859 | // This is a virtual register interval. |
| 860 | const LiveInterval &LI = LiveInts->getInterval(Reg); |
| 861 | LiveRangeQuery LRQ(LI, UseIdx); |
| 862 | if (!LRQ.valueIn()) { |
| 863 | report("No live range at use", MO, MONum); |
| 864 | *OS << UseIdx << " is not live in " << LI << '\n'; |
| 865 | } |
| 866 | // Check for extra kill flags. |
| 867 | // Note that we allow missing kill flags for now. |
| 868 | if (MO->isKill() && !LRQ.isKill()) { |
| 869 | report("Live range continues after kill flag", MO, MONum); |
| 870 | *OS << "Live range: " << LI << '\n'; |
| 871 | } |
| 872 | } else { |
| 873 | report("Virtual register has no live interval", MO, MONum); |
Jakob Stoklund Olesen | 948a444 | 2012-03-28 20:47:35 +0000 | [diff] [blame] | 874 | } |
Jakob Stoklund Olesen | 948a444 | 2012-03-28 20:47:35 +0000 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | |
| 878 | // Use of a dead register. |
| 879 | if (!regsLive.count(Reg)) { |
| 880 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) { |
| 881 | // Reserved registers may be used even when 'dead'. |
| 882 | if (!isReserved(Reg)) |
| 883 | report("Using an undefined physical register", MO, MONum); |
Pete Cooper | b97c57a | 2012-07-19 23:40:38 +0000 | [diff] [blame] | 884 | } else if (MRI->def_empty(Reg)) { |
| 885 | report("Reading virtual register without a def", MO, MONum); |
Jakob Stoklund Olesen | 948a444 | 2012-03-28 20:47:35 +0000 | [diff] [blame] | 886 | } else { |
| 887 | BBInfo &MInfo = MBBInfoMap[MI->getParent()]; |
| 888 | // We don't know which virtual registers are live in, so only complain |
| 889 | // if vreg was killed in this MBB. Otherwise keep track of vregs that |
| 890 | // must be live in. PHI instructions are handled separately. |
| 891 | if (MInfo.regsKilled.count(Reg)) |
| 892 | report("Using a killed virtual register", MO, MONum); |
| 893 | else if (!MI->isPHI()) |
| 894 | MInfo.vregsLiveIn.insert(std::make_pair(Reg, MI)); |
| 895 | } |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | if (MO->isDef()) { |
| 900 | // Register defined. |
| 901 | // TODO: verify that earlyclobber ops are not used. |
| 902 | if (MO->isDead()) |
| 903 | addRegWithSubRegs(regsDead, Reg); |
| 904 | else |
| 905 | addRegWithSubRegs(regsDefined, Reg); |
| 906 | |
| 907 | // Verify SSA form. |
| 908 | if (MRI->isSSA() && TargetRegisterInfo::isVirtualRegister(Reg) && |
| 909 | llvm::next(MRI->def_begin(Reg)) != MRI->def_end()) |
| 910 | report("Multiple virtual register defs in SSA form", MO, MONum); |
| 911 | |
| 912 | // Check LiveInts for a live range, but only for virtual registers. |
| 913 | if (LiveInts && TargetRegisterInfo::isVirtualRegister(Reg) && |
| 914 | !LiveInts->isNotInMIMap(MI)) { |
Jakob Stoklund Olesen | f935e94 | 2012-06-22 22:23:58 +0000 | [diff] [blame] | 915 | SlotIndex DefIdx = LiveInts->getInstructionIndex(MI); |
| 916 | DefIdx = DefIdx.getRegSlot(MO->isEarlyClobber()); |
Jakob Stoklund Olesen | 948a444 | 2012-03-28 20:47:35 +0000 | [diff] [blame] | 917 | if (LiveInts->hasInterval(Reg)) { |
| 918 | const LiveInterval &LI = LiveInts->getInterval(Reg); |
| 919 | if (const VNInfo *VNI = LI.getVNInfoAt(DefIdx)) { |
| 920 | assert(VNI && "NULL valno is not allowed"); |
Jakob Stoklund Olesen | f935e94 | 2012-06-22 22:23:58 +0000 | [diff] [blame] | 921 | if (VNI->def != DefIdx) { |
Jakob Stoklund Olesen | 948a444 | 2012-03-28 20:47:35 +0000 | [diff] [blame] | 922 | report("Inconsistent valno->def", MO, MONum); |
| 923 | *OS << "Valno " << VNI->id << " is not defined at " |
| 924 | << DefIdx << " in " << LI << '\n'; |
| 925 | } |
| 926 | } else { |
| 927 | report("No live range at def", MO, MONum); |
| 928 | *OS << DefIdx << " is not live in " << LI << '\n'; |
| 929 | } |
| 930 | } else { |
| 931 | report("Virtual register has no Live interval", MO, MONum); |
| 932 | } |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 937 | void MachineVerifier::visitMachineInstrAfter(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 1f9c3ec | 2012-06-06 22:34:30 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | // This function gets called after visiting all instructions in a bundle. The |
| 941 | // argument points to the bundle header. |
| 942 | // Normal stand-alone instructions are also considered 'bundles', and this |
| 943 | // function is called for all of them. |
| 944 | void MachineVerifier::visitMachineBundleAfter(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 945 | BBInfo &MInfo = MBBInfoMap[MI->getParent()]; |
| 946 | set_union(MInfo.regsKilled, regsKilled); |
Jakob Stoklund Olesen | 73cf709 | 2010-08-05 18:59:59 +0000 | [diff] [blame] | 947 | set_subtract(regsLive, regsKilled); regsKilled.clear(); |
Jakob Stoklund Olesen | 9ca12d2 | 2012-02-28 01:42:41 +0000 | [diff] [blame] | 948 | // Kill any masked registers. |
| 949 | while (!regMasks.empty()) { |
| 950 | const uint32_t *Mask = regMasks.pop_back_val(); |
| 951 | for (RegSet::iterator I = regsLive.begin(), E = regsLive.end(); I != E; ++I) |
| 952 | if (TargetRegisterInfo::isPhysicalRegister(*I) && |
| 953 | MachineOperand::clobbersPhysReg(Mask, *I)) |
| 954 | regsDead.push_back(*I); |
| 955 | } |
Jakob Stoklund Olesen | 73cf709 | 2010-08-05 18:59:59 +0000 | [diff] [blame] | 956 | set_subtract(regsLive, regsDead); regsDead.clear(); |
| 957 | set_union(regsLive, regsDefined); regsDefined.clear(); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | void |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 961 | MachineVerifier::visitMachineBasicBlockAfter(const MachineBasicBlock *MBB) { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 962 | MBBInfoMap[MBB].regsLiveOut = regsLive; |
| 963 | regsLive.clear(); |
Jakob Stoklund Olesen | fc69c37 | 2011-01-12 21:27:48 +0000 | [diff] [blame] | 964 | |
| 965 | if (Indexes) { |
| 966 | SlotIndex stop = Indexes->getMBBEndIdx(MBB); |
| 967 | if (!(stop > lastIndex)) { |
| 968 | report("Block ends before last instruction index", MBB); |
| 969 | *OS << "Block ends at " << stop |
| 970 | << " last instruction was at " << lastIndex << '\n'; |
| 971 | } |
| 972 | lastIndex = stop; |
| 973 | } |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | // Calculate the largest possible vregsPassed sets. These are the registers that |
| 977 | // can pass through an MBB live, but may not be live every time. It is assumed |
| 978 | // that all vregsPassed sets are empty before the call. |
Jakob Stoklund Olesen | b31defe | 2010-01-05 20:59:36 +0000 | [diff] [blame] | 979 | void MachineVerifier::calcRegsPassed() { |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 980 | // First push live-out regs to successors' vregsPassed. Remember the MBBs that |
| 981 | // have any vregsPassed. |
Jakob Stoklund Olesen | 1efd6b9 | 2012-03-10 00:36:04 +0000 | [diff] [blame] | 982 | SmallPtrSet<const MachineBasicBlock*, 8> todo; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 983 | for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end(); |
| 984 | MFI != MFE; ++MFI) { |
| 985 | const MachineBasicBlock &MBB(*MFI); |
| 986 | BBInfo &MInfo = MBBInfoMap[&MBB]; |
| 987 | if (!MInfo.reachable) |
| 988 | continue; |
| 989 | for (MachineBasicBlock::const_succ_iterator SuI = MBB.succ_begin(), |
| 990 | SuE = MBB.succ_end(); SuI != SuE; ++SuI) { |
| 991 | BBInfo &SInfo = MBBInfoMap[*SuI]; |
| 992 | if (SInfo.addPassed(MInfo.regsLiveOut)) |
| 993 | todo.insert(*SuI); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | // Iteratively push vregsPassed to successors. This will converge to the same |
| 998 | // final state regardless of DenseSet iteration order. |
| 999 | while (!todo.empty()) { |
| 1000 | const MachineBasicBlock *MBB = *todo.begin(); |
| 1001 | todo.erase(MBB); |
| 1002 | BBInfo &MInfo = MBBInfoMap[MBB]; |
| 1003 | for (MachineBasicBlock::const_succ_iterator SuI = MBB->succ_begin(), |
| 1004 | SuE = MBB->succ_end(); SuI != SuE; ++SuI) { |
| 1005 | if (*SuI == MBB) |
| 1006 | continue; |
| 1007 | BBInfo &SInfo = MBBInfoMap[*SuI]; |
| 1008 | if (SInfo.addPassed(MInfo.vregsPassed)) |
| 1009 | todo.insert(*SuI); |
| 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 1014 | // Calculate the set of virtual registers that must be passed through each basic |
| 1015 | // block in order to satisfy the requirements of successor blocks. This is very |
Jakob Stoklund Olesen | b31defe | 2010-01-05 20:59:36 +0000 | [diff] [blame] | 1016 | // similar to calcRegsPassed, only backwards. |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 1017 | void MachineVerifier::calcRegsRequired() { |
| 1018 | // First push live-in regs to predecessors' vregsRequired. |
Jakob Stoklund Olesen | 1efd6b9 | 2012-03-10 00:36:04 +0000 | [diff] [blame] | 1019 | SmallPtrSet<const MachineBasicBlock*, 8> todo; |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 1020 | for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end(); |
| 1021 | MFI != MFE; ++MFI) { |
| 1022 | const MachineBasicBlock &MBB(*MFI); |
| 1023 | BBInfo &MInfo = MBBInfoMap[&MBB]; |
| 1024 | for (MachineBasicBlock::const_pred_iterator PrI = MBB.pred_begin(), |
| 1025 | PrE = MBB.pred_end(); PrI != PrE; ++PrI) { |
| 1026 | BBInfo &PInfo = MBBInfoMap[*PrI]; |
| 1027 | if (PInfo.addRequired(MInfo.vregsLiveIn)) |
| 1028 | todo.insert(*PrI); |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | // Iteratively push vregsRequired to predecessors. This will converge to the |
| 1033 | // same final state regardless of DenseSet iteration order. |
| 1034 | while (!todo.empty()) { |
| 1035 | const MachineBasicBlock *MBB = *todo.begin(); |
| 1036 | todo.erase(MBB); |
| 1037 | BBInfo &MInfo = MBBInfoMap[MBB]; |
| 1038 | for (MachineBasicBlock::const_pred_iterator PrI = MBB->pred_begin(), |
| 1039 | PrE = MBB->pred_end(); PrI != PrE; ++PrI) { |
| 1040 | if (*PrI == MBB) |
| 1041 | continue; |
| 1042 | BBInfo &SInfo = MBBInfoMap[*PrI]; |
| 1043 | if (SInfo.addRequired(MInfo.vregsRequired)) |
| 1044 | todo.insert(*PrI); |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 1049 | // Check PHI instructions at the beginning of MBB. It is assumed that |
Jakob Stoklund Olesen | b31defe | 2010-01-05 20:59:36 +0000 | [diff] [blame] | 1050 | // calcRegsPassed has been run so BBInfo::isLiveOut is valid. |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 1051 | void MachineVerifier::checkPHIOps(const MachineBasicBlock *MBB) { |
Jakob Stoklund Olesen | 1efd6b9 | 2012-03-10 00:36:04 +0000 | [diff] [blame] | 1052 | SmallPtrSet<const MachineBasicBlock*, 8> seen; |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 1053 | for (MachineBasicBlock::const_iterator BBI = MBB->begin(), BBE = MBB->end(); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 1054 | BBI != BBE && BBI->isPHI(); ++BBI) { |
Jakob Stoklund Olesen | 1efd6b9 | 2012-03-10 00:36:04 +0000 | [diff] [blame] | 1055 | seen.clear(); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 1056 | |
| 1057 | for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) { |
| 1058 | unsigned Reg = BBI->getOperand(i).getReg(); |
| 1059 | const MachineBasicBlock *Pre = BBI->getOperand(i + 1).getMBB(); |
| 1060 | if (!Pre->isSuccessor(MBB)) |
| 1061 | continue; |
| 1062 | seen.insert(Pre); |
| 1063 | BBInfo &PrInfo = MBBInfoMap[Pre]; |
| 1064 | if (PrInfo.reachable && !PrInfo.isLiveOut(Reg)) |
| 1065 | report("PHI operand is not live-out from predecessor", |
| 1066 | &BBI->getOperand(i), i); |
| 1067 | } |
| 1068 | |
| 1069 | // Did we see all predecessors? |
| 1070 | for (MachineBasicBlock::const_pred_iterator PrI = MBB->pred_begin(), |
| 1071 | PrE = MBB->pred_end(); PrI != PrE; ++PrI) { |
| 1072 | if (!seen.count(*PrI)) { |
| 1073 | report("Missing PHI operand", BBI); |
Dan Gohman | 0ba90f3 | 2009-10-31 20:19:03 +0000 | [diff] [blame] | 1074 | *OS << "BB#" << (*PrI)->getNumber() |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 1075 | << " is a predecessor according to the CFG.\n"; |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | |
Jakob Stoklund Olesen | b44fad7 | 2009-10-04 18:18:39 +0000 | [diff] [blame] | 1081 | void MachineVerifier::visitMachineFunctionAfter() { |
Jakob Stoklund Olesen | b31defe | 2010-01-05 20:59:36 +0000 | [diff] [blame] | 1082 | calcRegsPassed(); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 1083 | |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 1084 | for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end(); |
| 1085 | MFI != MFE; ++MFI) { |
| 1086 | BBInfo &MInfo = MBBInfoMap[MFI]; |
| 1087 | |
| 1088 | // Skip unreachable MBBs. |
| 1089 | if (!MInfo.reachable) |
| 1090 | continue; |
| 1091 | |
| 1092 | checkPHIOps(MFI); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 1093 | } |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 1094 | |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1095 | // Now check liveness info if available |
Jakob Stoklund Olesen | 64ffa83 | 2012-03-10 00:36:06 +0000 | [diff] [blame] | 1096 | calcRegsRequired(); |
| 1097 | |
Jakob Stoklund Olesen | bb07216 | 2012-06-29 21:00:00 +0000 | [diff] [blame] | 1098 | // Check for killed virtual registers that should be live out. |
| 1099 | for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end(); |
| 1100 | MFI != MFE; ++MFI) { |
| 1101 | BBInfo &MInfo = MBBInfoMap[MFI]; |
| 1102 | for (RegSet::iterator |
| 1103 | I = MInfo.vregsRequired.begin(), E = MInfo.vregsRequired.end(); I != E; |
| 1104 | ++I) |
| 1105 | if (MInfo.regsKilled.count(*I)) { |
Bill Wendling | 96cb112 | 2012-07-19 00:04:14 +0000 | [diff] [blame] | 1106 | report("Virtual register killed in block, but needed live out.", MFI); |
| 1107 | *OS << "Virtual register " << PrintReg(*I) |
Jakob Stoklund Olesen | bb07216 | 2012-06-29 21:00:00 +0000 | [diff] [blame] | 1108 | << " is used after the block.\n"; |
| 1109 | } |
| 1110 | } |
| 1111 | |
Jakob Stoklund Olesen | a4e6397 | 2012-06-25 18:18:27 +0000 | [diff] [blame] | 1112 | if (!MF->empty()) { |
Jakob Stoklund Olesen | 64ffa83 | 2012-03-10 00:36:06 +0000 | [diff] [blame] | 1113 | BBInfo &MInfo = MBBInfoMap[&MF->front()]; |
| 1114 | for (RegSet::iterator |
| 1115 | I = MInfo.vregsRequired.begin(), E = MInfo.vregsRequired.end(); I != E; |
Jakob Stoklund Olesen | ff0275e | 2012-03-10 00:44:11 +0000 | [diff] [blame] | 1116 | ++I) |
| 1117 | report("Virtual register def doesn't dominate all uses.", |
| 1118 | MRI->getVRegDef(*I)); |
Jakob Stoklund Olesen | 64ffa83 | 2012-03-10 00:36:06 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1121 | if (LiveVars) |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 1122 | verifyLiveVariables(); |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1123 | if (LiveInts) |
| 1124 | verifyLiveIntervals(); |
Jakob Stoklund Olesen | 48872e0 | 2009-05-16 00:33:53 +0000 | [diff] [blame] | 1125 | } |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 1126 | |
| 1127 | void MachineVerifier::verifyLiveVariables() { |
| 1128 | assert(LiveVars && "Don't call verifyLiveVariables without LiveVars"); |
Jakob Stoklund Olesen | 98c5476 | 2011-01-08 23:11:02 +0000 | [diff] [blame] | 1129 | for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) { |
| 1130 | unsigned Reg = TargetRegisterInfo::index2VirtReg(i); |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 1131 | LiveVariables::VarInfo &VI = LiveVars->getVarInfo(Reg); |
| 1132 | for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end(); |
| 1133 | MFI != MFE; ++MFI) { |
| 1134 | BBInfo &MInfo = MBBInfoMap[MFI]; |
| 1135 | |
| 1136 | // Our vregsRequired should be identical to LiveVariables' AliveBlocks |
| 1137 | if (MInfo.vregsRequired.count(Reg)) { |
| 1138 | if (!VI.AliveBlocks.test(MFI->getNumber())) { |
| 1139 | report("LiveVariables: Block missing from AliveBlocks", MFI); |
Jakob Stoklund Olesen | 4314268 | 2011-01-09 03:05:53 +0000 | [diff] [blame] | 1140 | *OS << "Virtual register " << PrintReg(Reg) |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 1141 | << " must be live through the block.\n"; |
| 1142 | } |
| 1143 | } else { |
| 1144 | if (VI.AliveBlocks.test(MFI->getNumber())) { |
| 1145 | report("LiveVariables: Block should not be in AliveBlocks", MFI); |
Jakob Stoklund Olesen | 4314268 | 2011-01-09 03:05:53 +0000 | [diff] [blame] | 1146 | *OS << "Virtual register " << PrintReg(Reg) |
Jakob Stoklund Olesen | 8f16e02 | 2009-11-18 20:36:57 +0000 | [diff] [blame] | 1147 | << " is not needed live through the block.\n"; |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1154 | void MachineVerifier::verifyLiveIntervals() { |
| 1155 | assert(LiveInts && "Don't call verifyLiveIntervals without LiveInts"); |
Jakob Stoklund Olesen | 12a7be9 | 2012-06-20 23:23:59 +0000 | [diff] [blame] | 1156 | for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) { |
| 1157 | unsigned Reg = TargetRegisterInfo::index2VirtReg(i); |
Jakob Stoklund Olesen | 893ab5d | 2010-10-06 23:54:35 +0000 | [diff] [blame] | 1158 | |
| 1159 | // Spilling and splitting may leave unused registers around. Skip them. |
Jakob Stoklund Olesen | 12a7be9 | 2012-06-20 23:23:59 +0000 | [diff] [blame] | 1160 | if (MRI->reg_nodbg_empty(Reg)) |
Jakob Stoklund Olesen | 893ab5d | 2010-10-06 23:54:35 +0000 | [diff] [blame] | 1161 | continue; |
| 1162 | |
Jakob Stoklund Olesen | 12a7be9 | 2012-06-20 23:23:59 +0000 | [diff] [blame] | 1163 | if (!LiveInts->hasInterval(Reg)) { |
| 1164 | report("Missing live interval for virtual register", MF); |
| 1165 | *OS << PrintReg(Reg, TRI) << " still has defs or uses\n"; |
Jakob Stoklund Olesen | 8c45642 | 2010-10-28 20:44:22 +0000 | [diff] [blame] | 1166 | continue; |
Jakob Stoklund Olesen | 12a7be9 | 2012-06-20 23:23:59 +0000 | [diff] [blame] | 1167 | } |
Jakob Stoklund Olesen | 8c45642 | 2010-10-28 20:44:22 +0000 | [diff] [blame] | 1168 | |
Jakob Stoklund Olesen | 12a7be9 | 2012-06-20 23:23:59 +0000 | [diff] [blame] | 1169 | const LiveInterval &LI = LiveInts->getInterval(Reg); |
| 1170 | assert(Reg == LI.reg && "Invalid reg to interval mapping"); |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1171 | verifyLiveInterval(LI); |
| 1172 | } |
Jakob Stoklund Olesen | 8044689 | 2012-08-02 16:36:50 +0000 | [diff] [blame^] | 1173 | |
| 1174 | // Verify all the cached regunit intervals. |
| 1175 | for (unsigned i = 0, e = TRI->getNumRegUnits(); i != e; ++i) |
| 1176 | if (const LiveInterval *LI = LiveInts->getCachedRegUnit(i)) |
| 1177 | verifyLiveInterval(*LI); |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1178 | } |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1179 | |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1180 | void MachineVerifier::verifyLiveIntervalValue(const LiveInterval &LI, |
| 1181 | VNInfo *VNI) { |
| 1182 | if (VNI->isUnused()) |
| 1183 | return; |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1184 | |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1185 | const VNInfo *DefVNI = LI.getVNInfoAt(VNI->def); |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1186 | |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1187 | if (!DefVNI) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1188 | report("Valno not live at def and not marked unused", MF, LI); |
| 1189 | *OS << "Valno #" << VNI->id << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1190 | return; |
| 1191 | } |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1192 | |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1193 | if (DefVNI != VNI) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1194 | report("Live range at def has different valno", MF, LI); |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1195 | *OS << "Valno #" << VNI->id << " is defined at " << VNI->def |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1196 | << " where valno #" << DefVNI->id << " is live\n"; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1197 | return; |
| 1198 | } |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1199 | |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1200 | const MachineBasicBlock *MBB = LiveInts->getMBBFromIndex(VNI->def); |
| 1201 | if (!MBB) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1202 | report("Invalid definition index", MF, LI); |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1203 | *OS << "Valno #" << VNI->id << " is defined at " << VNI->def |
| 1204 | << " in " << LI << '\n'; |
| 1205 | return; |
| 1206 | } |
Jakob Stoklund Olesen | 3bf7cf9 | 2010-10-22 22:48:58 +0000 | [diff] [blame] | 1207 | |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1208 | if (VNI->isPHIDef()) { |
| 1209 | if (VNI->def != LiveInts->getMBBStartIdx(MBB)) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1210 | report("PHIDef value is not defined at MBB start", MBB, LI); |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1211 | *OS << "Valno #" << VNI->id << " is defined at " << VNI->def |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1212 | << ", not at the beginning of BB#" << MBB->getNumber() << '\n'; |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1213 | } |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1214 | return; |
| 1215 | } |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1216 | |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1217 | // Non-PHI def. |
| 1218 | const MachineInstr *MI = LiveInts->getInstructionFromIndex(VNI->def); |
| 1219 | if (!MI) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1220 | report("No instruction at def index", MBB, LI); |
| 1221 | *OS << "Valno #" << VNI->id << " is defined at " << VNI->def << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1222 | return; |
| 1223 | } |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1224 | |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1225 | bool hasDef = false; |
| 1226 | bool isEarlyClobber = false; |
| 1227 | for (ConstMIBundleOperands MOI(MI); MOI.isValid(); ++MOI) { |
| 1228 | if (!MOI->isReg() || !MOI->isDef()) |
| 1229 | continue; |
Jakob Stoklund Olesen | 8c593f9 | 2010-10-27 00:39:01 +0000 | [diff] [blame] | 1230 | if (TargetRegisterInfo::isVirtualRegister(LI.reg)) { |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1231 | if (MOI->getReg() != LI.reg) |
| 1232 | continue; |
| 1233 | } else { |
| 1234 | if (!TargetRegisterInfo::isPhysicalRegister(MOI->getReg()) || |
Jakob Stoklund Olesen | 8044689 | 2012-08-02 16:36:50 +0000 | [diff] [blame^] | 1235 | !TRI->hasRegUnit(MOI->getReg(), LI.reg)) |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1236 | continue; |
| 1237 | } |
| 1238 | hasDef = true; |
| 1239 | if (MOI->isEarlyClobber()) |
| 1240 | isEarlyClobber = true; |
| 1241 | } |
| 1242 | |
| 1243 | if (!hasDef) { |
| 1244 | report("Defining instruction does not modify register", MI); |
| 1245 | *OS << "Valno #" << VNI->id << " in " << LI << '\n'; |
| 1246 | } |
| 1247 | |
| 1248 | // Early clobber defs begin at USE slots, but other defs must begin at |
| 1249 | // DEF slots. |
| 1250 | if (isEarlyClobber) { |
| 1251 | if (!VNI->def.isEarlyClobber()) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1252 | report("Early clobber def must be at an early-clobber slot", MBB, LI); |
| 1253 | *OS << "Valno #" << VNI->id << " is defined at " << VNI->def << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1254 | } |
| 1255 | } else if (!VNI->def.isRegister()) { |
| 1256 | report("Non-PHI, non-early clobber def must be at a register slot", |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1257 | MBB, LI); |
| 1258 | *OS << "Valno #" << VNI->id << " is defined at " << VNI->def << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | void |
| 1263 | MachineVerifier::verifyLiveIntervalSegment(const LiveInterval &LI, |
| 1264 | LiveInterval::const_iterator I) { |
| 1265 | const VNInfo *VNI = I->valno; |
| 1266 | assert(VNI && "Live range has no valno"); |
| 1267 | |
| 1268 | if (VNI->id >= LI.getNumValNums() || VNI != LI.getValNumInfo(VNI->id)) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1269 | report("Foreign valno in live range", MF, LI); |
| 1270 | *OS << *I << " has a bad valno\n"; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | if (VNI->isUnused()) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1274 | report("Live range valno is marked unused", MF, LI); |
| 1275 | *OS << *I << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | const MachineBasicBlock *MBB = LiveInts->getMBBFromIndex(I->start); |
| 1279 | if (!MBB) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1280 | report("Bad start of live segment, no basic block", MF, LI); |
| 1281 | *OS << *I << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1282 | return; |
| 1283 | } |
| 1284 | SlotIndex MBBStartIdx = LiveInts->getMBBStartIdx(MBB); |
| 1285 | if (I->start != MBBStartIdx && I->start != VNI->def) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1286 | report("Live segment must begin at MBB entry or valno def", MBB, LI); |
| 1287 | *OS << *I << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | const MachineBasicBlock *EndMBB = |
| 1291 | LiveInts->getMBBFromIndex(I->end.getPrevSlot()); |
| 1292 | if (!EndMBB) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1293 | report("Bad end of live segment, no basic block", MF, LI); |
| 1294 | *OS << *I << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1295 | return; |
| 1296 | } |
| 1297 | |
| 1298 | // No more checks for live-out segments. |
| 1299 | if (I->end == LiveInts->getMBBEndIdx(EndMBB)) |
| 1300 | return; |
| 1301 | |
Jakob Stoklund Olesen | 8044689 | 2012-08-02 16:36:50 +0000 | [diff] [blame^] | 1302 | // RegUnit intervals are allowed dead phis. |
| 1303 | if (!TargetRegisterInfo::isVirtualRegister(LI.reg) && VNI->isPHIDef() && |
| 1304 | I->start == VNI->def && I->end == VNI->def.getDeadSlot()) |
| 1305 | return; |
| 1306 | |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1307 | // The live segment is ending inside EndMBB |
| 1308 | const MachineInstr *MI = |
| 1309 | LiveInts->getInstructionFromIndex(I->end.getPrevSlot()); |
| 1310 | if (!MI) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1311 | report("Live segment doesn't end at a valid instruction", EndMBB, LI); |
| 1312 | *OS << *I << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1313 | return; |
| 1314 | } |
| 1315 | |
| 1316 | // The block slot must refer to a basic block boundary. |
| 1317 | if (I->end.isBlock()) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1318 | report("Live segment ends at B slot of an instruction", EndMBB, LI); |
| 1319 | *OS << *I << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | if (I->end.isDead()) { |
| 1323 | // Segment ends on the dead slot. |
| 1324 | // That means there must be a dead def. |
| 1325 | if (!SlotIndex::isSameInstr(I->start, I->end)) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1326 | report("Live segment ending at dead slot spans instructions", EndMBB, LI); |
| 1327 | *OS << *I << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | // A live segment can only end at an early-clobber slot if it is being |
| 1332 | // redefined by an early-clobber def. |
| 1333 | if (I->end.isEarlyClobber()) { |
| 1334 | if (I+1 == LI.end() || (I+1)->start != I->end) { |
| 1335 | report("Live segment ending at early clobber slot must be " |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1336 | "redefined by an EC def in the same instruction", EndMBB, LI); |
| 1337 | *OS << *I << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | // The following checks only apply to virtual registers. Physreg liveness |
| 1342 | // is too weird to check. |
| 1343 | if (TargetRegisterInfo::isVirtualRegister(LI.reg)) { |
| 1344 | // A live range can end with either a redefinition, a kill flag on a |
| 1345 | // use, or a dead flag on a def. |
| 1346 | bool hasRead = false; |
| 1347 | bool hasDeadDef = false; |
| 1348 | for (ConstMIBundleOperands MOI(MI); MOI.isValid(); ++MOI) { |
| 1349 | if (!MOI->isReg() || MOI->getReg() != LI.reg) |
| 1350 | continue; |
| 1351 | if (MOI->readsReg()) |
| 1352 | hasRead = true; |
| 1353 | if (MOI->isDef() && MOI->isDead()) |
| 1354 | hasDeadDef = true; |
| 1355 | } |
| 1356 | |
| 1357 | if (I->end.isDead()) { |
| 1358 | if (!hasDeadDef) { |
| 1359 | report("Instruction doesn't have a dead def operand", MI); |
| 1360 | I->print(*OS); |
| 1361 | *OS << " in " << LI << '\n'; |
| 1362 | } |
| 1363 | } else { |
| 1364 | if (!hasRead) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1365 | report("Instruction ending live range doesn't read the register", MI); |
| 1366 | *OS << *I << " in " << LI << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1367 | } |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | // Now check all the basic blocks in this live segment. |
| 1372 | MachineFunction::const_iterator MFI = MBB; |
| 1373 | // Is this live range the beginning of a non-PHIDef VN? |
| 1374 | if (I->start == VNI->def && !VNI->isPHIDef()) { |
| 1375 | // Not live-in to any blocks. |
| 1376 | if (MBB == EndMBB) |
| 1377 | return; |
| 1378 | // Skip this block. |
| 1379 | ++MFI; |
| 1380 | } |
| 1381 | for (;;) { |
| 1382 | assert(LiveInts->isLiveInToMBB(LI, MFI)); |
| 1383 | // We don't know how to track physregs into a landing pad. |
Jakob Stoklund Olesen | 8044689 | 2012-08-02 16:36:50 +0000 | [diff] [blame^] | 1384 | if (!TargetRegisterInfo::isVirtualRegister(LI.reg) && |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1385 | MFI->isLandingPad()) { |
| 1386 | if (&*MFI == EndMBB) |
| 1387 | break; |
| 1388 | ++MFI; |
| 1389 | continue; |
| 1390 | } |
| 1391 | |
| 1392 | // Is VNI a PHI-def in the current block? |
| 1393 | bool IsPHI = VNI->isPHIDef() && |
| 1394 | VNI->def == LiveInts->getMBBStartIdx(MFI); |
| 1395 | |
| 1396 | // Check that VNI is live-out of all predecessors. |
| 1397 | for (MachineBasicBlock::const_pred_iterator PI = MFI->pred_begin(), |
| 1398 | PE = MFI->pred_end(); PI != PE; ++PI) { |
| 1399 | SlotIndex PEnd = LiveInts->getMBBEndIdx(*PI); |
| 1400 | const VNInfo *PVNI = LI.getVNInfoBefore(PEnd); |
| 1401 | |
| 1402 | // All predecessors must have a live-out value. |
| 1403 | if (!PVNI) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1404 | report("Register not marked live out of predecessor", *PI, LI); |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1405 | *OS << "Valno #" << VNI->id << " live into BB#" << MFI->getNumber() |
| 1406 | << '@' << LiveInts->getMBBStartIdx(MFI) << ", not live before " |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1407 | << PEnd << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1408 | continue; |
| 1409 | } |
| 1410 | |
| 1411 | // Only PHI-defs can take different predecessor values. |
| 1412 | if (!IsPHI && PVNI != VNI) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1413 | report("Different value live out of predecessor", *PI, LI); |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1414 | *OS << "Valno #" << PVNI->id << " live out of BB#" |
| 1415 | << (*PI)->getNumber() << '@' << PEnd |
| 1416 | << "\nValno #" << VNI->id << " live into BB#" << MFI->getNumber() |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1417 | << '@' << LiveInts->getMBBStartIdx(MFI) << '\n'; |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1418 | } |
| 1419 | } |
| 1420 | if (&*MFI == EndMBB) |
| 1421 | break; |
| 1422 | ++MFI; |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | void MachineVerifier::verifyLiveInterval(const LiveInterval &LI) { |
| 1427 | for (LiveInterval::const_vni_iterator I = LI.vni_begin(), E = LI.vni_end(); |
| 1428 | I!=E; ++I) |
| 1429 | verifyLiveIntervalValue(LI, *I); |
| 1430 | |
| 1431 | for (LiveInterval::const_iterator I = LI.begin(), E = LI.end(); I!=E; ++I) |
| 1432 | verifyLiveIntervalSegment(LI, I); |
| 1433 | |
| 1434 | // Check the LI only has one connected component. |
| 1435 | if (TargetRegisterInfo::isVirtualRegister(LI.reg)) { |
| 1436 | ConnectedVNInfoEqClasses ConEQ(*LiveInts); |
| 1437 | unsigned NumComp = ConEQ.Classify(&LI); |
| 1438 | if (NumComp > 1) { |
Jakob Stoklund Olesen | 79240f95 | 2012-08-02 14:31:49 +0000 | [diff] [blame] | 1439 | report("Multiple connected components in live interval", MF, LI); |
Jakob Stoklund Olesen | e5c79a5 | 2012-08-02 00:20:20 +0000 | [diff] [blame] | 1440 | for (unsigned comp = 0; comp != NumComp; ++comp) { |
| 1441 | *OS << comp << ": valnos"; |
| 1442 | for (LiveInterval::const_vni_iterator I = LI.vni_begin(), |
| 1443 | E = LI.vni_end(); I!=E; ++I) |
| 1444 | if (comp == ConEQ.getEqClass(*I)) |
| 1445 | *OS << ' ' << (*I)->id; |
| 1446 | *OS << '\n'; |
Jakob Stoklund Olesen | 8c593f9 | 2010-10-27 00:39:01 +0000 | [diff] [blame] | 1447 | } |
Jakob Stoklund Olesen | 501dc42 | 2010-10-26 22:36:07 +0000 | [diff] [blame] | 1448 | } |
Jakob Stoklund Olesen | 58e1248 | 2010-08-06 18:04:19 +0000 | [diff] [blame] | 1449 | } |
| 1450 | } |