28#define DEBUG_TYPE "mir-debugify"
42 assert(SP &&
"IR Debugify just created it?");
47 unsigned NextLine = SP->getLine();
54 MI.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
66 Function *DbgValF = M.getFunction(
"llvm.dbg.value");
72 for (
const Use &U : DbgValF->
uses()) {
73 auto *DVI = dyn_cast<DbgValueInst>(U.getUser());
74 if (!DVI || DVI->getFunction() != &
F)
76 unsigned Line = DVI->getDebugLoc().getLine();
77 assert(Line != 0 &&
"debugify should not insert line 0 locations");
78 Line2Var[Line] = DVI->getVariable();
79 if (!EarliestDVI || Line < EarliestDVI->
getDebugLoc().getLine())
81 Expr = DVI->getExpression();
87 if (!DVR.isDbgValue())
89 unsigned Line = DVR.getDebugLoc().getLine();
90 assert(Line != 0 &&
"debugify should not insert line 0 locations");
91 Line2Var[Line] = DVR.getVariable();
92 if (!EarliestDVR || Line < EarliestDVR->
getDebugLoc().getLine())
94 Expr = DVR.getExpression();
114 if (
MI.isDebugInstr())
118 if (
MI.isTerminator())
122 auto InsertBeforeIt =
MI.isPHI() ? FirstNonPHIIt :
I;
125 unsigned Line =
MI.getDebugLoc().getLine();
126 if (!Line2Var.
count(Line))
130 assert(LocalVar &&
"No variable for current line?");
139 BuildMI(
MBB, InsertBeforeIt,
MI.getDebugLoc(), DbgValDesc,
140 false, *MO, LocalVar, Expr);
143 if (RegDefs.
empty()) {
145 BuildMI(
MBB, InsertBeforeIt,
MI.getDebugLoc(), DbgValDesc,
146 false, ImmOp, LocalVar, Expr);
153 NamedMDNode *NMD = M.getNamedMetadata(
"llvm.mir.debugify");
156 NMD = M.getOrInsertNamedMetadata(
"llvm.mir.debugify");
157 auto addDebugifyOperand = [&](
unsigned N) {
162 addDebugifyOperand(NextLine - 1);
164 addDebugifyOperand(VarSet.
size());
167 "llvm.mir.debugify should have exactly 2 operands!");
168 auto setDebugifyOperand = [&](
unsigned Idx,
unsigned N) {
170 ConstantInt::get(Int32Ty,
N))));
172 auto getDebugifyOperand = [&](
unsigned Idx) {
177 setDebugifyOperand(0, NextLine - 1);
179 auto OldNumVars = getDebugifyOperand(1);
180 setDebugifyOperand(1, OldNumVars + VarSet.
size());
188struct DebugifyMachineModule :
public ModulePass {
191 assert(!M.getNamedMetadata(
"llvm.mir.debugify") &&
192 "llvm.mir.debugify metadata already exists! Strip it first");
194 getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
198 return applyDebugifyMetadataToMachineFunction(MMI, DIB, F);
212char DebugifyMachineModule::ID = 0;
217 "Machine Debugify Module",
false,
false)
222 return new DebugifyMachineModule();
COFF::MachineTypes Machine
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
const HexagonInstrInfo * TII
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
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.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
LLVM Basic Block Representation.
DebugLoc getDebugLoc() const
This represents the llvm.dbg.value instruction.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
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)
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
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.
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
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...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
void setOperand(unsigned I, MDNode *New)
MDNode * getOperand(unsigned i) const
unsigned getNumOperands() const
void addOperand(MDNode *M)
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
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 IntegerType * getInt32Ty(LLVMContext &C)
A Use represents the edge between a Value definition and its users.
iterator_range< use_iterator > uses()
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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.
bool applyDebugifyMetadata(Module &M, iterator_range< Module::iterator > Functions, StringRef Banner, std::function< bool(DIBuilder &, Function &)> ApplyToMF)
Add synthesized debug information to a module.
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.