MachineBasicBlock::iterator InstrItr = BB->begin(); MachineInstr& MI = *InstrItr; DebugLoc DL = MI.getDebugLoc(); if (DL) { Instruction* Inst = DL->getInlinedAt(); if (Inst) { errs() << "Inlined at: " << Inst->getDebugLoc()->getLine() << "\n"; } else { errs() << "Debug location: " << DL.getLine() << "\n"; } }
MachineBasicBlock::iterator InstrItr = BB->begin(); MachineInstr& MI = *InstrItr; DebugLoc DL1 = MI.getDebugLoc(); MI.setDebugLoc(DL1.getFnDebugLoc()); DebugLoc DL2 = MI.getDebugLoc();This code snippet demonstrates how to modify the debug location of a machine instruction using getDebugLoc() and setDebugLoc(). It first retrieves the debug location of the instruction and assigns it to DL1. Then, it sets the debug location of the instruction to the function debug location (which is the debug location of the enclosing function). Finally, it retrieves the debug location of the instruction again and assigns it to DL2. The resulting debug location of the instruction should be the same as the function debug location. Package library: LLVM Core.