Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
MachineCheckDebugify.cpp
Go to the documentation of this file.
1//===- MachineCheckDebugify.cpp - Check debug info ------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file This checks debug info after mir-debugify (+ pass-to-test). Currently
10/// it simply checks the integrity of line info in DILocation and
11/// DILocalVariable which mir-debugifiy generated before.
12//===----------------------------------------------------------------------===//
13
14#include "llvm/ADT/StringExtras.h"
15#include "llvm/CodeGen/MachineBasicBlock.h"
16#include "llvm/CodeGen/MachineFunction.h"
17#include "llvm/CodeGen/MachineModuleInfo.h"
18#include "llvm/CodeGen/Passes.h"
19#include "llvm/IR/Constants.h"
20#include "llvm/IR/DebugInfoMetadata.h"
21#include "llvm/IR/Module.h"
22#include "llvm/InitializePasses.h"
23#include "llvm/Pass.h"
24
25#define DEBUG_TYPE "mir-check-debugify"
26
27using namespacellvm;
28
29namespace{
30
31structCheckDebugMachineModule :publicModulePass {
32boolrunOnModule(Module &M) override{
33NamedMDNode *NMD = M.getNamedMetadata("llvm.mir.debugify");
34if (!NMD) {
35errs() <<"WARNING: Please run mir-debugify to generate "
36"llvm.mir.debugify metadata first.\n";
37returnfalse;
38 }
39
40MachineModuleInfo &MMI =
41 getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
42
43auto getDebugifyOperand = [&](unsignedIdx) ->unsigned {
44return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
45 ->getZExtValue();
46 };
47assert(NMD->getNumOperands() == 2 &&
48"llvm.mir.debugify should have exactly 2 operands!");
49unsigned NumLines = getDebugifyOperand(0);
50unsigned NumVars = getDebugifyOperand(1);
51BitVector MissingLines{NumLines,true};
52BitVector MissingVars{NumVars,true};
53
54for (Function &F : M.functions()) {
55MachineFunction *MF = MMI.getMachineFunction(F);
56if (!MF)
57continue;
58for (MachineBasicBlock &MBB : *MF) {
59// Find missing lines.
60// TODO: Avoid meta instructions other than dbg_val.
61for (MachineInstr &MI :MBB) {
62if (MI.isDebugValue())
63continue;
64constDebugLocDL =MI.getDebugLoc();
65if (DL &&DL.getLine() != 0) {
66 MissingLines.reset(DL.getLine() - 1);
67continue;
68 }
69
70if (!DL) {
71errs() <<"WARNING: Instruction with empty DebugLoc in function ";
72errs() <<F.getName() <<" --";
73MI.print(errs());
74 }
75 }
76
77// Find missing variables.
78// TODO: Handle DBG_INSTR_REF which is under an experimental option now.
79for (MachineInstr &MI :MBB) {
80if (!MI.isDebugValue())
81continue;
82constDILocalVariable *LocalVar =MI.getDebugVariable();
83unsigned Var = ~0U;
84
85 (void)to_integer(LocalVar->getName(), Var, 10);
86assert(Var <= NumVars &&"Unexpected name for DILocalVariable");
87 MissingVars.reset(Var - 1);
88 }
89 }
90 }
91
92boolFail =false;
93for (unsignedIdx : MissingLines.set_bits()) {
94errs() <<"WARNING: Missing line " <<Idx + 1 <<"\n";
95Fail =true;
96 }
97
98for (unsignedIdx : MissingVars.set_bits()) {
99errs() <<"WARNING: Missing variable " <<Idx + 1 <<"\n";
100Fail =true;
101 }
102errs() <<"Machine IR debug info check: ";
103errs() << (Fail ?"FAIL" :"PASS") <<"\n";
104
105returnfalse;
106 }
107
108 CheckDebugMachineModule() :ModulePass(ID) {}
109
110voidgetAnalysisUsage(AnalysisUsage &AU) const override{
111 AU.addRequired<MachineModuleInfoWrapperPass>();
112 AU.setPreservesAll();
113 }
114
115staticcharID;// Pass identification.
116};
117char CheckDebugMachineModule::ID = 0;
118
119}// end anonymous namespace
120
121INITIALIZE_PASS_BEGIN(CheckDebugMachineModule,DEBUG_TYPE,
122"Machine Check Debug Module",false,false)
123INITIALIZE_PASS_END(CheckDebugMachineModule,DEBUG_TYPE,
124 "MachineCheckDebugModule",false,false)
125
126ModulePass *llvm::createCheckDebugMachineModulePass() {
127returnnew CheckDebugMachineModule();
128}
Fail
#define Fail
Definition:AArch64Disassembler.cpp:221
MBB
MachineBasicBlock & MBB
Definition:ARMSLSHardening.cpp:71
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
Machine
COFF::MachineTypes Machine
Definition:COFFYAML.cpp:390
Passes.h
Constants.h
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Idx
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
Definition:DeadArgumentElimination.cpp:353
DebugInfoMetadata.h
Debug
static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug
Definition:Debug.cpp:108
Check
#define Check(C,...)
Definition:GenericConvergenceVerifierImpl.h:34
MI
IRTranslator LLVM IR MI
Definition:IRTranslator.cpp:112
Module.h
Module.h This file contains the declarations for the Module class.
InitializePasses.h
F
#define F(x, y, z)
Definition:MD5.cpp:55
MachineBasicBlock.h
DEBUG_TYPE
#define DEBUG_TYPE
Definition:MachineCheckDebugify.cpp:25
MachineFunction.h
MachineModuleInfo.h
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition:PassSupport.h:57
INITIALIZE_PASS_BEGIN
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition:PassSupport.h:52
Pass.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringExtras.h
This file contains some functions that are useful when dealing with strings.
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition:PassAnalysisSupport.h:47
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition:PassAnalysisSupport.h:75
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition:PassAnalysisSupport.h:130
llvm::BitVector
Definition:BitVector.h:82
llvm::DILocalVariable
Local variable.
Definition:DebugInfoMetadata.h:3460
llvm::DebugLoc
A debug info location.
Definition:DebugLoc.h:33
llvm::Function
Definition:Function.h:63
llvm::MDNode::getOperand
const MDOperand & getOperand(unsigned I) const
Definition:Metadata.h:1434
llvm::MachineBasicBlock
Definition:MachineBasicBlock.h:125
llvm::MachineFunction
Definition:MachineFunction.h:267
llvm::MachineInstr
Representation of each machine instruction.
Definition:MachineInstr.h:71
llvm::MachineModuleInfoWrapperPass
Definition:MachineModuleInfo.h:170
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition:MachineModuleInfo.h:82
llvm::MachineModuleInfo::getMachineFunction
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
Definition:MachineModuleInfo.cpp:72
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition:Pass.h:251
llvm::ModulePass::runOnModule
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition:Module.h:65
llvm::NamedMDNode
A tuple of MDNodes.
Definition:Metadata.h:1737
llvm::NamedMDNode::getOperand
MDNode * getOperand(unsigned i) const
Definition:Metadata.cpp:1425
llvm::NamedMDNode::getNumOperands
unsigned getNumOperands() const
Definition:Metadata.cpp:1421
llvm::Pass::print
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition:Pass.cpp:130
llvm::Pass::getAnalysisUsage
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition:Pass.cpp:98
unsigned
false
Definition:StackSlotColoring.cpp:193
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition:CallingConv.h:24
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition:raw_ostream.cpp:907
llvm::createCheckDebugMachineModulePass
ModulePass * createCheckDebugMachineModulePass()
Creates MIR Check Debug pass.
Definition:MachineCheckDebugify.cpp:126

Generated on Thu Jul 17 2025 11:29:17 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp