28#define DEBUG_TYPE "mir-debugify"
42 assert(SP &&
"IR Debugify just created it?");
47 unsigned NextLine = SP->getLine();
72 if (!DVR.isDbgValue())
74 unsigned Line = DVR.getDebugLoc().getLine();
75 assert(Line != 0 &&
"debugify should not insert line 0 locations");
76 Line2Var[Line] = DVR.getVariable();
77 if (!EarliestDVR || Line < EarliestDVR->
getDebugLoc().getLine())
79 Expr = DVR.getExpression();
94 for (
auto I =
MBB.begin(), E =
MBB.end();
I != E;) {
99 if (
MI.isDebugInstr())
103 if (
MI.isTerminator())
107 auto InsertBeforeIt =
MI.isPHI() ? FirstNonPHIIt :
I;
110 unsigned Line =
MI.getDebugLoc().getLine();
111 auto It = Line2Var.
find(Line);
112 if (It == Line2Var.
end()) {
114 It = Line2Var.
find(Line);
118 assert(LocalVar &&
"No variable for current line?");
127 BuildMI(
MBB, InsertBeforeIt,
MI.getDebugLoc(), DbgValDesc,
128 false, *MO, LocalVar, Expr);
131 if (RegDefs.
empty()) {
133 BuildMI(
MBB, InsertBeforeIt,
MI.getDebugLoc(), DbgValDesc,
134 false, ImmOp, LocalVar, Expr);
141 NamedMDNode *NMD = M.getNamedMetadata(
"llvm.mir.debugify");
144 NMD = M.getOrInsertNamedMetadata(
"llvm.mir.debugify");
145 auto addDebugifyOperand = [&](
unsigned N) {
150 addDebugifyOperand(NextLine - 1);
152 addDebugifyOperand(VarSet.
size());
155 "llvm.mir.debugify should have exactly 2 operands!");
156 auto setDebugifyOperand = [&](
unsigned Idx,
unsigned N) {
160 auto getDebugifyOperand = [&](
unsigned Idx) {
165 setDebugifyOperand(0, NextLine - 1);
167 auto OldNumVars = getDebugifyOperand(1);
168 setDebugifyOperand(1, OldNumVars + VarSet.
size());
178struct DebugifyMachineModule :
public ModulePass {
179 bool runOnModule(
Module &M)
override {
181 assert(!M.getNamedMetadata(
"llvm.mir.debugify") &&
182 "llvm.mir.debugify metadata already exists! Strip it first");
184 getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
188 return applyDebugifyMetadataToMachineFunction(
189 DIB, F, [&MMI](Function &F) -> MachineFunction * {
190 return MMI.getMachineFunction(F);
205char DebugifyMachineModule::ID = 0;
210 "Machine Debugify Module",
false,
false)
215 return new DebugifyMachineModule();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
const HexagonInstrInfo * TII
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first DebugLoc that has line number information, given a range of instructions.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
LLVM Basic Block Representation.
Subprogram description. Uses SubclassData1.
DebugLoc getDebugLoc() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
LLVM_ABI unsigned getLine() const
iterator find(const_arg_type_t< KeyT > Val)
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
Describe properties that are true of each instruction in the target description file.
const MDOperand & getOperand(unsigned I) const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
MachineInstrBundleIterator< MachineInstr > iterator
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
This class contains meta information specific to a module.
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateImm(int64_t Val)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
LLVM_ABI void setOperand(unsigned I, MDNode *New)
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
LLVM_ABI void addOperand(MDNode *M)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
virtual const TargetInstrInfo * getInstrInfo() const
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
An efficient, type-erasing, non-owning reference to a callable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionAddr VTableAddr uintptr_t uintptr_t Int32Ty
LLVM_ABI bool applyDebugifyMetadata(Module &M, iterator_range< Module::iterator > Functions, StringRef Banner, std::function< bool(DIBuilder &, Function &)> ApplyToMF)
Add synthesized debug information to a module.
LLVM_ABI bool applyDebugifyMetadataToMachineFunction(DIBuilder &DIB, Function &F, llvm::function_ref< MachineFunction *(Function &)> GetMF)
LLVM_ABI ModulePass * createDebugifyMachineModulePass()
Creates MIR Debugify pass.
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.