diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/MachineBasicBlock.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp | 19 |
2 files changed, 21 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index 8fef85ff82c..99e7615e534 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -1255,6 +1255,16 @@ MachineBasicBlock::findDebugLoc(instr_iterator MBBI) { return {}; } +/// Find the previous valid DebugLoc preceding MBBI, skipping and DBG_VALUE +/// instructions. Return UnknownLoc if there is none. +DebugLoc MachineBasicBlock::findPrevDebugLoc(instr_iterator MBBI) { + if (MBBI == instr_begin()) return {}; + // Skip debug declarations, we don't want a DebugLoc from them. + MBBI = skipDebugInstructionsBackward(std::prev(MBBI), instr_begin()); + if (!MBBI->isDebugValue()) return MBBI->getDebugLoc(); + return {}; +} + /// Find and return the merged DebugLoc of the branch instructions of the block. /// Return UnknownLoc if there is none. DebugLoc diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp index cab21007d3f..5a8ddadb0c9 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp @@ -143,9 +143,9 @@ static void PlaceBlockMarker( } // Add the BLOCK. - MachineInstr *Begin = BuildMI(*Header, InsertPos, DebugLoc(), + MachineInstr *Begin = BuildMI(*Header, InsertPos, MBB.findDebugLoc(InsertPos), TII.get(WebAssembly::BLOCK)) - .addImm(int64_t(WebAssembly::ExprType::Void)); + .addImm(int64_t(WebAssembly::ExprType::Void)); // Mark the end of the block. InsertPos = MBB.begin(); @@ -153,7 +153,7 @@ static void PlaceBlockMarker( InsertPos->getOpcode() == WebAssembly::END_LOOP && LoopTops[&*InsertPos]->getParent()->getNumber() >= Header->getNumber()) ++InsertPos; - MachineInstr *End = BuildMI(MBB, InsertPos, DebugLoc(), + MachineInstr *End = BuildMI(MBB, InsertPos, MBB.findPrevDebugLoc(InsertPos), TII.get(WebAssembly::END_BLOCK)); BlockTops[End] = Begin; @@ -193,12 +193,14 @@ static void PlaceLoopMarker( while (InsertPos != MBB.end() && InsertPos->getOpcode() == WebAssembly::END_LOOP) ++InsertPos; - MachineInstr *Begin = BuildMI(MBB, InsertPos, DebugLoc(), + MachineInstr *Begin = BuildMI(MBB, InsertPos, MBB.findDebugLoc(InsertPos), TII.get(WebAssembly::LOOP)) - .addImm(int64_t(WebAssembly::ExprType::Void)); + .addImm(int64_t(WebAssembly::ExprType::Void)); - // Mark the end of the loop. - MachineInstr *End = BuildMI(*AfterLoop, AfterLoop->begin(), DebugLoc(), + // Mark the end of the loop (using arbitrary debug location that branched + // to the loop end as its location). + DebugLoc EndDL = (*AfterLoop->pred_rbegin())->findBranchDebugLoc(); + MachineInstr *End = BuildMI(*AfterLoop, AfterLoop->begin(), EndDL, TII.get(WebAssembly::END_LOOP)); LoopTops[End] = Begin; @@ -276,7 +278,8 @@ static void FixEndsAtEndOfFunction( static void AppendEndToFunction( MachineFunction &MF, const WebAssemblyInstrInfo &TII) { - BuildMI(MF.back(), MF.back().end(), DebugLoc(), + BuildMI(MF.back(), MF.back().end(), + MF.back().findPrevDebugLoc(MF.back().end()), TII.get(WebAssembly::END_FUNCTION)); } |