[PATCH] D79058: [MachineVerifier] Add a pass to ensure debug locations within a basic block are monotonically increasing
Davide Italiano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 28 18:22:53 PDT 2020
davide updated this revision to Diff 260813.
davide added a comment.
Correct patch
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79058/new/
https://reviews.llvm.org/D79058
Files:
llvm/lib/CodeGen/MachineVerifier.cpp
Index: llvm/lib/CodeGen/MachineVerifier.cpp
===================================================================
--- llvm/lib/CodeGen/MachineVerifier.cpp
+++ llvm/lib/CodeGen/MachineVerifier.cpp
@@ -263,6 +263,7 @@
void verifyStackFrame();
void verifySlotIndexes() const;
+ void verifyDebugLocations(const MachineFunction &MF);
void verifyProperties(const MachineFunction &MF);
};
@@ -322,6 +323,40 @@
}
}
+void MachineVerifier::verifyDebugLocations(const MachineFunction &MF) {
+ // We're only guaranteed monotonicity at -O0. Optimizations
+ // may shuffle instructions around.
+ if (MF.getTarget().getOptLevel() != CodeGenOpt::None ||
+ !MF.getTarget().Options.EnableGlobalISel)
+ return;
+ for (const MachineBasicBlock &MBB : MF) {
+ for (const MachineInstr &MI : MBB.instrs()) {
+ // Reset the line every time we enter a new MBB.
+ unsigned LastLine = 0;
+
+ // Debug instructions don't generate code, so we
+ // can skip them for verification's sake.
+ if (MI.isDebugInstr())
+ continue;
+
+ // Also skip instructions without a debug location
+ // associated.
+ auto DL = MI.getDebugLoc();
+ if (!DL)
+ continue;
+ unsigned CurLine = DL.getLine();
+
+ // If the line associated with this instruction isn't
+ // line zero, and it's smaller than the last one we visited,
+ // trigger an error.
+ if (CurLine != 0 && CurLine < LastLine)
+ report("Non-monotonically increasing debug location within "
+ "a single MachineBasicBlock", &MI);
+ LastLine = CurLine;
+ }
+ }
+}
+
void MachineVerifier::verifyProperties(const MachineFunction &MF) {
// If a pass has introduced virtual registers without clearing the
// NoVRegs property (or set it without allocating the vregs)
@@ -372,6 +407,8 @@
verifyProperties(MF);
+ verifyDebugLocations(MF);
+
visitMachineFunctionBefore();
for (const MachineBasicBlock &MBB : MF) {
visitMachineBasicBlockBefore(&MBB);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79058.260813.patch
Type: text/x-patch
Size: 2037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200429/82b9b270/attachment.bin>
More information about the llvm-commits
mailing list