31 cl::desc(
"Suppress verbose debugify output"));
35 uint64_t getAllocSizeInBits(
Module &M,
Type *Ty) {
55 bool applyDebugifyMetadata(
Module &M,
60 dbg() << Banner <<
"Skipping module with debug info\n";
69 auto getCachedDIType = [&](
Type *Ty) ->
DIType * {
70 uint64_t
Size = getAllocSizeInBits(M, Ty);
74 DTy = DIB.createBasicType(Name, Size, dwarf::DW_ATE_unsigned);
79 unsigned NextLine = 1;
82 auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C,
File,
"debugify",
87 if (isFunctionSkipped(F))
90 auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(
None));
92 DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized;
94 SPFlags |= DISubprogram::SPFlagLocalToUnit;
96 SPType, NextLine, DINode::FlagZero, SPFlags);
109 Instruction *LastInst = findTerminatingInstruction(BB);
110 assert(LastInst &&
"Expected basic block with a terminator");
115 assert(InsertPt != BB.end() &&
"Expected to find an insertion point");
119 for (
Instruction *
I = &*BB.begin();
I != LastInst;
I =
I->getNextNode()) {
121 if (
I->getType()->isVoidTy())
126 if (!isa<PHINode>(
I) && !
I->isEHPad())
127 InsertBefore =
I->getNextNode();
131 auto LocalVar = DIB.createAutoVariable(
SP, Name,
File, Loc->getLine(),
132 getCachedDIType(
I->getType()),
134 DIB.insertDbgValueIntrinsic(
I,
LocalVar, DIB.createExpression(), Loc,
138 DIB.finalizeSubprogram(
SP);
145 auto addDebugifyOperand = [&](
unsigned N) {
149 addDebugifyOperand(NextLine - 1);
150 addDebugifyOperand(NextVar - 1);
152 "llvm.debugify should have exactly 2 operands!");
155 StringRef DIVersionKey =
"Debug Info Version";
179 uint64_t ValueOperandSize = getAllocSizeInBits(M, Ty);
181 if (!ValueOperandSize || !DbgVarSize)
184 bool HasBadSize =
false;
188 HasBadSize = ValueOperandSize < *DbgVarSize;
190 HasBadSize = ValueOperandSize != *DbgVarSize;
194 dbg() <<
"ERROR: dbg.value operand has size " << ValueOperandSize
195 <<
", but its variable has size " << *DbgVarSize <<
": ";
202 bool checkDebugifyMetadata(
Module &M,
209 dbg() << Banner <<
"Skipping module without debugify metadata\n";
213 auto getDebugifyOperand = [&](
unsigned Idx) ->
unsigned {
218 "llvm.debugify should have exactly 2 operands!");
219 unsigned OriginalNumLines = getDebugifyOperand(0);
220 unsigned OriginalNumVars = getDebugifyOperand(1);
221 bool HasErrors =
false;
225 if (StatsMap && !NameOfWrappedPass.
empty())
226 Stats = &StatsMap->operator[](NameOfWrappedPass);
228 BitVector MissingLines{OriginalNumLines,
true};
229 BitVector MissingVars{OriginalNumVars,
true};
231 if (isFunctionSkipped(F))
236 if (isa<DbgValueInst>(&
I))
239 auto DL =
I.getDebugLoc();
240 if (DL && DL.getLine() != 0) {
241 MissingLines.reset(DL.getLine() - 1);
246 dbg() <<
"ERROR: Instruction with empty DebugLoc in function ";
247 dbg() << F.getName() <<
" --";
262 assert(Var <= OriginalNumVars &&
"Unexpected name for DILocalVariable");
263 bool HasBadSize = diagnoseMisSizedDbgValue(M, DVI);
265 MissingVars.reset(Var - 1);
266 HasErrors |= HasBadSize;
271 for (
unsigned Idx : MissingLines.set_bits())
272 dbg() <<
"WARNING: Missing line " << Idx + 1 <<
"\n";
274 for (
unsigned Idx : MissingVars.set_bits())
275 dbg() <<
"WARNING: Missing variable " << Idx + 1 <<
"\n";
286 if (!NameOfWrappedPass.
empty())
287 dbg() <<
" [" << NameOfWrappedPass <<
"]";
288 dbg() <<
": " << (HasErrors ?
"FAIL" :
"PASS") <<
'\n';
302 struct DebugifyModulePass :
public ModulePass {
303 bool runOnModule(
Module &M)
override {
304 return applyDebugifyMetadata(M, M.
functions(),
"ModuleDebugify: ");
322 return applyDebugifyMetadata(M,
make_range(FuncIt, std::next(FuncIt)),
323 "FunctionDebugify: ");
337 struct CheckDebugifyModulePass :
public ModulePass {
338 bool runOnModule(
Module &M)
override {
339 return checkDebugifyMetadata(M, M.
functions(), NameOfWrappedPass,
340 "CheckModuleDebugify", Strip, StatsMap);
343 CheckDebugifyModulePass(
bool Strip =
false,
StringRef NameOfWrappedPass =
"",
345 :
ModulePass(
ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass),
346 StatsMap(StatsMap) {}
362 struct CheckDebugifyFunctionPass :
public FunctionPass {
366 return checkDebugifyMetadata(M,
make_range(FuncIt, std::next(FuncIt)),
367 NameOfWrappedPass,
"CheckFunctionDebugify",
371 CheckDebugifyFunctionPass(
bool Strip =
false,
374 :
FunctionPass(
ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass),
375 StatsMap(StatsMap) {}
394 return new DebugifyFunctionPass();
398 applyDebugifyMetadata(M, M.
functions(),
"ModuleDebugify: ");
405 return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap);
411 return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap);
416 checkDebugifyMetadata(M, M.
functions(),
"",
"CheckModuleDebugify",
false,
423 "Attach debug info to everything");
427 CDM(
"check-debugify",
"Check debug info from -debugify");
431 "Attach debug info to a function");
435 CDF(
"check-debugify-function",
"Check debug info from -debugify-function");
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
RegisterPass<t> template - This template class is used to notify the system that a Pass is available ...
MDNode * getOperand(unsigned i) const
bool hasPrivateLinkage() const
This class represents lattice values for constants.
Track how much debugify information has been lost.
bool to_integer(StringRef S, N &Num, unsigned Base=0)
Convert the string S to an integer of the specified type using the radix Base.
A Module instance is used to store all the information related to an LLVM module. ...
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
void addOperand(MDNode *M)
unsigned NumDbgValuesMissing
Number of missing dbg.values.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
This class implements a map that also provides access to all stored values in a deterministic order...
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
StringRef getName() const
Get a short "name" for the module.
Optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable's type, or None if this type is neither signed nor unsigned...
const MDOperand & getOperand(unsigned I) const
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static RegisterPass< CheckDebugifyFunctionPass > CDF("check-debugify-function", "Check debug info from -debugify-function")
FunctionPass * createCheckDebugifyFunctionPass(bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap)
Optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM)
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
StringRef getName() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
LLVMContext & getContext() const
Get the global data context.
bool isIntegerTy() const
True if this is an instance of IntegerType.
unsigned getNumOperands() const
block placement Basic Block Placement Stats
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
unsigned NumDbgLocsMissing
Number of instructions with empty debug locations.
Type * getType() const
All values are typed, get the type of this value.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
FunctionPass * createDebugifyFunctionPass()
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
static bool runOnFunction(Function &F, bool PostInlining)
void setSubprogram(DISubprogram *SP)
Set the attached subprogram.
A set of analyses that are preserved following a run of a transformation pass.
iterator_range< iterator > functions()
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
static RegisterPass< CheckDebugifyModulePass > CDM("check-debugify", "Check debug info from -debugify")
This is an important class for using LLVM in a threaded context.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Instrumentation for Order File
unsigned NumDbgLocsExpected
Number of instructions expected to have debug locations.
unsigned NumDbgValuesExpected
Number of dbg.values expected.
DIExpression * getExpression() const
Represent the analysis usage information of a pass.
bool hasInternalLinkage() const
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
FunctionPass class - This class is used to implement most global optimizations.
self_iterator getIterator()
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
Module.h This file contains the declarations for the Module class.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
std::string utostr(uint64_t X, bool isNeg=false)
A range adaptor for a pair of iterators.
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM)
Emits a warning if two values disagree.
void setPreservesAll()
Set by analyses that do not transform their input at all.
unsigned getNumElements() const
static IntegerType * getInt32Ty(LLVMContext &C)
This represents the llvm.dbg.value instruction.
StringRef getName() const
Return a constant reference to the value's name.
bool hasExactDefinition() const
Return true if this global has an exact defintion.
ModulePass * createCheckDebugifyModulePass(bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
DILocalVariable * getVariable() const
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
DISPFlags
Debug info subprogram flags.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
inst_range instructions(Function *F)
A container for analyses that lazily runs them and caches their results.
ModulePass * createDebugifyModulePass()