aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp184
1 files changed, 102 insertions, 82 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp b/contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp
index 589622d69578..205f7a7d9ed2 100644
--- a/contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp
+++ b/contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp
@@ -37,12 +37,16 @@ namespace {
cl::opt<bool> Quiet("debugify-quiet",
cl::desc("Suppress verbose debugify output"));
+cl::opt<uint64_t> DebugifyFunctionsLimit(
+ "debugify-func-limit",
+ cl::desc("Set max number of processed functions per pass."),
+ cl::init(UINT_MAX));
+
enum class Level {
Locations,
LocationsAndVariables
};
-// Used for the synthetic mode only.
cl::opt<Level> DebugifyLevel(
"debugify-level", cl::desc("Kind of debug info to add"),
cl::values(clEnumValN(Level::Locations, "locations", "Locations only"),
@@ -210,15 +214,15 @@ bool llvm::applyDebugifyMetadata(
static bool
applyDebugify(Function &F,
enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
- DebugInfoPerPassMap *DIPreservationMap = nullptr,
+ DebugInfoPerPass *DebugInfoBeforePass = nullptr,
StringRef NameOfWrappedPass = "") {
Module &M = *F.getParent();
auto FuncIt = F.getIterator();
if (Mode == DebugifyMode::SyntheticDebugInfo)
return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
"FunctionDebugify: ", /*ApplyToMF*/ nullptr);
- assert(DIPreservationMap);
- return collectDebugInfoMetadata(M, M.functions(), *DIPreservationMap,
+ assert(DebugInfoBeforePass);
+ return collectDebugInfoMetadata(M, M.functions(), *DebugInfoBeforePass,
"FunctionDebugify (original debuginfo)",
NameOfWrappedPass);
}
@@ -226,12 +230,12 @@ applyDebugify(Function &F,
static bool
applyDebugify(Module &M,
enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
- DebugInfoPerPassMap *DIPreservationMap = nullptr,
+ DebugInfoPerPass *DebugInfoBeforePass = nullptr,
StringRef NameOfWrappedPass = "") {
if (Mode == DebugifyMode::SyntheticDebugInfo)
return applyDebugifyMetadata(M, M.functions(),
"ModuleDebugify: ", /*ApplyToMF*/ nullptr);
- return collectDebugInfoMetadata(M, M.functions(), *DIPreservationMap,
+ return collectDebugInfoMetadata(M, M.functions(), *DebugInfoBeforePass,
"ModuleDebugify (original debuginfo)",
NameOfWrappedPass);
}
@@ -267,7 +271,7 @@ bool llvm::stripDebugifyMetadata(Module &M) {
SmallVector<MDNode *, 4> Flags(NMD->operands());
NMD->clearOperands();
for (MDNode *Flag : Flags) {
- MDString *Key = dyn_cast_or_null<MDString>(Flag->getOperand(1));
+ auto *Key = cast<MDString>(Flag->getOperand(1));
if (Key->getString() == "Debug Info Version") {
Changed = true;
continue;
@@ -283,32 +287,37 @@ bool llvm::stripDebugifyMetadata(Module &M) {
bool llvm::collectDebugInfoMetadata(Module &M,
iterator_range<Module::iterator> Functions,
- DebugInfoPerPassMap &DIPreservationMap,
+ DebugInfoPerPass &DebugInfoBeforePass,
StringRef Banner,
StringRef NameOfWrappedPass) {
LLVM_DEBUG(dbgs() << Banner << ": (before) " << NameOfWrappedPass << '\n');
- // Clear the map with the debug info before every single pass.
- DIPreservationMap.clear();
-
if (!M.getNamedMetadata("llvm.dbg.cu")) {
dbg() << Banner << ": Skipping module without debug info\n";
return false;
}
+ uint64_t FunctionsCnt = DebugInfoBeforePass.DIFunctions.size();
// Visit each instruction.
for (Function &F : Functions) {
+ // Use DI collected after previous Pass (when -debugify-each is used).
+ if (DebugInfoBeforePass.DIFunctions.count(&F))
+ continue;
+
if (isFunctionSkipped(F))
continue;
+ // Stop collecting DI if the Functions number reached the limit.
+ if (++FunctionsCnt >= DebugifyFunctionsLimit)
+ break;
// Collect the DISubprogram.
auto *SP = F.getSubprogram();
- DIPreservationMap[NameOfWrappedPass].DIFunctions.insert({F.getName(), SP});
+ DebugInfoBeforePass.DIFunctions.insert({&F, SP});
if (SP) {
LLVM_DEBUG(dbgs() << " Collecting subprogram: " << *SP << '\n');
for (const DINode *DN : SP->getRetainedNodes()) {
if (const auto *DV = dyn_cast<DILocalVariable>(DN)) {
- DIPreservationMap[NameOfWrappedPass].DIVariables[DV] = 0;
+ DebugInfoBeforePass.DIVariables[DV] = 0;
}
}
}
@@ -320,20 +329,22 @@ bool llvm::collectDebugInfoMetadata(Module &M,
if (isa<PHINode>(I))
continue;
- // Collect dbg.values and dbg.declares.
- if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I)) {
- if (!SP)
- continue;
- // Skip inlined variables.
- if (I.getDebugLoc().getInlinedAt())
+ // Cllect dbg.values and dbg.declare.
+ if (DebugifyLevel > Level::Locations) {
+ if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I)) {
+ if (!SP)
+ continue;
+ // Skip inlined variables.
+ if (I.getDebugLoc().getInlinedAt())
+ continue;
+ // Skip undef values.
+ if (DVI->isUndef())
+ continue;
+
+ auto *Var = DVI->getVariable();
+ DebugInfoBeforePass.DIVariables[Var]++;
continue;
- // Skip undef values.
- if (DVI->isUndef())
- continue;
-
- auto *Var = DVI->getVariable();
- DIPreservationMap[NameOfWrappedPass].DIVariables[Var]++;
- continue;
+ }
}
// Skip debug instructions other than dbg.value and dbg.declare.
@@ -341,11 +352,11 @@ bool llvm::collectDebugInfoMetadata(Module &M,
continue;
LLVM_DEBUG(dbgs() << " Collecting info for inst: " << I << '\n');
- DIPreservationMap[NameOfWrappedPass].InstToDelete.insert({&I, &I});
+ DebugInfoBeforePass.InstToDelete.insert({&I, &I});
const DILocation *Loc = I.getDebugLoc().get();
bool HasLoc = Loc != nullptr;
- DIPreservationMap[NameOfWrappedPass].DILocations.insert({&I, HasLoc});
+ DebugInfoBeforePass.DILocations.insert({&I, HasLoc});
}
}
}
@@ -367,12 +378,12 @@ static bool checkFunctions(const DebugFnMap &DIFunctionsBefore,
if (SPIt == DIFunctionsBefore.end()) {
if (ShouldWriteIntoJSON)
Bugs.push_back(llvm::json::Object({{"metadata", "DISubprogram"},
- {"name", F.first},
+ {"name", F.first->getName()},
{"action", "not-generate"}}));
else
dbg() << "ERROR: " << NameOfWrappedPass
- << " did not generate DISubprogram for " << F.first << " from "
- << FileNameFromCU << '\n';
+ << " did not generate DISubprogram for " << F.first->getName()
+ << " from " << FileNameFromCU << '\n';
Preserved = false;
} else {
auto SP = SPIt->second;
@@ -382,11 +393,11 @@ static bool checkFunctions(const DebugFnMap &DIFunctionsBefore,
// a debug info bug.
if (ShouldWriteIntoJSON)
Bugs.push_back(llvm::json::Object({{"metadata", "DISubprogram"},
- {"name", F.first},
+ {"name", F.first->getName()},
{"action", "drop"}}));
else
dbg() << "ERROR: " << NameOfWrappedPass << " dropped DISubprogram of "
- << F.first << " from " << FileNameFromCU << '\n';
+ << F.first->getName() << " from " << FileNameFromCU << '\n';
Preserved = false;
}
}
@@ -515,7 +526,7 @@ static void writeJSON(StringRef OrigDIVerifyBugsReportFilePath,
bool llvm::checkDebugInfoMetadata(Module &M,
iterator_range<Module::iterator> Functions,
- DebugInfoPerPassMap &DIPreservationMap,
+ DebugInfoPerPass &DebugInfoBeforePass,
StringRef Banner, StringRef NameOfWrappedPass,
StringRef OrigDIVerifyBugsReportFilePath) {
LLVM_DEBUG(dbgs() << Banner << ": (after) " << NameOfWrappedPass << '\n');
@@ -526,24 +537,26 @@ bool llvm::checkDebugInfoMetadata(Module &M,
}
// Map the debug info holding DIs after a pass.
- DebugInfoPerPassMap DIPreservationAfter;
+ DebugInfoPerPass DebugInfoAfterPass;
// Visit each instruction.
for (Function &F : Functions) {
if (isFunctionSkipped(F))
continue;
+ // Don't process functions without DI collected before the Pass.
+ if (!DebugInfoBeforePass.DIFunctions.count(&F))
+ continue;
// TODO: Collect metadata other than DISubprograms.
// Collect the DISubprogram.
auto *SP = F.getSubprogram();
- DIPreservationAfter[NameOfWrappedPass].DIFunctions.insert(
- {F.getName(), SP});
+ DebugInfoAfterPass.DIFunctions.insert({&F, SP});
if (SP) {
LLVM_DEBUG(dbgs() << " Collecting subprogram: " << *SP << '\n');
for (const DINode *DN : SP->getRetainedNodes()) {
if (const auto *DV = dyn_cast<DILocalVariable>(DN)) {
- DIPreservationAfter[NameOfWrappedPass].DIVariables[DV] = 0;
+ DebugInfoAfterPass.DIVariables[DV] = 0;
}
}
}
@@ -556,19 +569,21 @@ bool llvm::checkDebugInfoMetadata(Module &M,
continue;
// Collect dbg.values and dbg.declares.
- if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I)) {
- if (!SP)
- continue;
- // Skip inlined variables.
- if (I.getDebugLoc().getInlinedAt())
- continue;
- // Skip undef values.
- if (DVI->isUndef())
+ if (DebugifyLevel > Level::Locations) {
+ if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I)) {
+ if (!SP)
+ continue;
+ // Skip inlined variables.
+ if (I.getDebugLoc().getInlinedAt())
+ continue;
+ // Skip undef values.
+ if (DVI->isUndef())
+ continue;
+
+ auto *Var = DVI->getVariable();
+ DebugInfoAfterPass.DIVariables[Var]++;
continue;
-
- auto *Var = DVI->getVariable();
- DIPreservationAfter[NameOfWrappedPass].DIVariables[Var]++;
- continue;
+ }
}
// Skip debug instructions other than dbg.value and dbg.declare.
@@ -580,7 +595,7 @@ bool llvm::checkDebugInfoMetadata(Module &M,
const DILocation *Loc = I.getDebugLoc().get();
bool HasLoc = Loc != nullptr;
- DIPreservationAfter[NameOfWrappedPass].DILocations.insert({&I, HasLoc});
+ DebugInfoAfterPass.DILocations.insert({&I, HasLoc});
}
}
}
@@ -590,16 +605,16 @@ bool llvm::checkDebugInfoMetadata(Module &M,
(cast<DICompileUnit>(M.getNamedMetadata("llvm.dbg.cu")->getOperand(0)))
->getFilename();
- auto DIFunctionsBefore = DIPreservationMap[NameOfWrappedPass].DIFunctions;
- auto DIFunctionsAfter = DIPreservationAfter[NameOfWrappedPass].DIFunctions;
+ auto DIFunctionsBefore = DebugInfoBeforePass.DIFunctions;
+ auto DIFunctionsAfter = DebugInfoAfterPass.DIFunctions;
- auto DILocsBefore = DIPreservationMap[NameOfWrappedPass].DILocations;
- auto DILocsAfter = DIPreservationAfter[NameOfWrappedPass].DILocations;
+ auto DILocsBefore = DebugInfoBeforePass.DILocations;
+ auto DILocsAfter = DebugInfoAfterPass.DILocations;
- auto InstToDelete = DIPreservationMap[NameOfWrappedPass].InstToDelete;
+ auto InstToDelete = DebugInfoBeforePass.InstToDelete;
- auto DIVarsBefore = DIPreservationMap[NameOfWrappedPass].DIVariables;
- auto DIVarsAfter = DIPreservationAfter[NameOfWrappedPass].DIVariables;
+ auto DIVarsBefore = DebugInfoBeforePass.DIVariables;
+ auto DIVarsAfter = DebugInfoAfterPass.DIVariables;
bool ShouldWriteIntoJSON = !OrigDIVerifyBugsReportFilePath.empty();
llvm::json::Array Bugs;
@@ -626,6 +641,11 @@ bool llvm::checkDebugInfoMetadata(Module &M,
else
dbg() << ResultBanner << ": FAIL\n";
+ // In the case of the `debugify-each`, no need to go over all the instructions
+ // again in the collectDebugInfoMetadata(), since as an input we can use
+ // the debugging information from the previous pass.
+ DebugInfoBeforePass = DebugInfoAfterPass;
+
LLVM_DEBUG(dbgs() << "\n\n");
return Result;
}
@@ -770,14 +790,14 @@ bool checkDebugifyMetadata(Module &M,
/// legacy module pass manager.
struct DebugifyModulePass : public ModulePass {
bool runOnModule(Module &M) override {
- return applyDebugify(M, Mode, DIPreservationMap, NameOfWrappedPass);
+ return applyDebugify(M, Mode, DebugInfoBeforePass, NameOfWrappedPass);
}
DebugifyModulePass(enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
StringRef NameOfWrappedPass = "",
- DebugInfoPerPassMap *DIPreservationMap = nullptr)
+ DebugInfoPerPass *DebugInfoBeforePass = nullptr)
: ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass),
- DIPreservationMap(DIPreservationMap), Mode(Mode) {}
+ DebugInfoBeforePass(DebugInfoBeforePass), Mode(Mode) {}
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesAll();
@@ -787,7 +807,7 @@ struct DebugifyModulePass : public ModulePass {
private:
StringRef NameOfWrappedPass;
- DebugInfoPerPassMap *DIPreservationMap;
+ DebugInfoPerPass *DebugInfoBeforePass;
enum DebugifyMode Mode;
};
@@ -795,15 +815,15 @@ private:
/// single function, used with the legacy module pass manager.
struct DebugifyFunctionPass : public FunctionPass {
bool runOnFunction(Function &F) override {
- return applyDebugify(F, Mode, DIPreservationMap, NameOfWrappedPass);
+ return applyDebugify(F, Mode, DebugInfoBeforePass, NameOfWrappedPass);
}
DebugifyFunctionPass(
enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
StringRef NameOfWrappedPass = "",
- DebugInfoPerPassMap *DIPreservationMap = nullptr)
+ DebugInfoPerPass *DebugInfoBeforePass = nullptr)
: FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass),
- DIPreservationMap(DIPreservationMap), Mode(Mode) {}
+ DebugInfoBeforePass(DebugInfoBeforePass), Mode(Mode) {}
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesAll();
@@ -813,7 +833,7 @@ struct DebugifyFunctionPass : public FunctionPass {
private:
StringRef NameOfWrappedPass;
- DebugInfoPerPassMap *DIPreservationMap;
+ DebugInfoPerPass *DebugInfoBeforePass;
enum DebugifyMode Mode;
};
@@ -825,7 +845,7 @@ struct CheckDebugifyModulePass : public ModulePass {
return checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
"CheckModuleDebugify", Strip, StatsMap);
return checkDebugInfoMetadata(
- M, M.functions(), *DIPreservationMap,
+ M, M.functions(), *DebugInfoBeforePass,
"CheckModuleDebugify (original debuginfo)", NameOfWrappedPass,
OrigDIVerifyBugsReportFilePath);
}
@@ -834,11 +854,11 @@ struct CheckDebugifyModulePass : public ModulePass {
bool Strip = false, StringRef NameOfWrappedPass = "",
DebugifyStatsMap *StatsMap = nullptr,
enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
- DebugInfoPerPassMap *DIPreservationMap = nullptr,
+ DebugInfoPerPass *DebugInfoBeforePass = nullptr,
StringRef OrigDIVerifyBugsReportFilePath = "")
: ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass),
OrigDIVerifyBugsReportFilePath(OrigDIVerifyBugsReportFilePath),
- StatsMap(StatsMap), DIPreservationMap(DIPreservationMap), Mode(Mode),
+ StatsMap(StatsMap), DebugInfoBeforePass(DebugInfoBeforePass), Mode(Mode),
Strip(Strip) {}
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -851,7 +871,7 @@ private:
StringRef NameOfWrappedPass;
StringRef OrigDIVerifyBugsReportFilePath;
DebugifyStatsMap *StatsMap;
- DebugInfoPerPassMap *DIPreservationMap;
+ DebugInfoPerPass *DebugInfoBeforePass;
enum DebugifyMode Mode;
bool Strip;
};
@@ -867,7 +887,7 @@ struct CheckDebugifyFunctionPass : public FunctionPass {
NameOfWrappedPass, "CheckFunctionDebugify",
Strip, StatsMap);
return checkDebugInfoMetadata(
- M, make_range(FuncIt, std::next(FuncIt)), *DIPreservationMap,
+ M, make_range(FuncIt, std::next(FuncIt)), *DebugInfoBeforePass,
"CheckFunctionDebugify (original debuginfo)", NameOfWrappedPass,
OrigDIVerifyBugsReportFilePath);
}
@@ -876,11 +896,11 @@ struct CheckDebugifyFunctionPass : public FunctionPass {
bool Strip = false, StringRef NameOfWrappedPass = "",
DebugifyStatsMap *StatsMap = nullptr,
enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
- DebugInfoPerPassMap *DIPreservationMap = nullptr,
+ DebugInfoPerPass *DebugInfoBeforePass = nullptr,
StringRef OrigDIVerifyBugsReportFilePath = "")
: FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass),
OrigDIVerifyBugsReportFilePath(OrigDIVerifyBugsReportFilePath),
- StatsMap(StatsMap), DIPreservationMap(DIPreservationMap), Mode(Mode),
+ StatsMap(StatsMap), DebugInfoBeforePass(DebugInfoBeforePass), Mode(Mode),
Strip(Strip) {}
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -893,7 +913,7 @@ private:
StringRef NameOfWrappedPass;
StringRef OrigDIVerifyBugsReportFilePath;
DebugifyStatsMap *StatsMap;
- DebugInfoPerPassMap *DIPreservationMap;
+ DebugInfoPerPass *DebugInfoBeforePass;
enum DebugifyMode Mode;
bool Strip;
};
@@ -923,21 +943,21 @@ void llvm::exportDebugifyStats(StringRef Path, const DebugifyStatsMap &Map) {
ModulePass *createDebugifyModulePass(enum DebugifyMode Mode,
llvm::StringRef NameOfWrappedPass,
- DebugInfoPerPassMap *DIPreservationMap) {
+ DebugInfoPerPass *DebugInfoBeforePass) {
if (Mode == DebugifyMode::SyntheticDebugInfo)
return new DebugifyModulePass();
assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
- return new DebugifyModulePass(Mode, NameOfWrappedPass, DIPreservationMap);
+ return new DebugifyModulePass(Mode, NameOfWrappedPass, DebugInfoBeforePass);
}
FunctionPass *
createDebugifyFunctionPass(enum DebugifyMode Mode,
llvm::StringRef NameOfWrappedPass,
- DebugInfoPerPassMap *DIPreservationMap) {
+ DebugInfoPerPass *DebugInfoBeforePass) {
if (Mode == DebugifyMode::SyntheticDebugInfo)
return new DebugifyFunctionPass();
assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
- return new DebugifyFunctionPass(Mode, NameOfWrappedPass, DIPreservationMap);
+ return new DebugifyFunctionPass(Mode, NameOfWrappedPass, DebugInfoBeforePass);
}
PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) {
@@ -948,25 +968,25 @@ PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) {
ModulePass *createCheckDebugifyModulePass(
bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
- enum DebugifyMode Mode, DebugInfoPerPassMap *DIPreservationMap,
+ enum DebugifyMode Mode, DebugInfoPerPass *DebugInfoBeforePass,
StringRef OrigDIVerifyBugsReportFilePath) {
if (Mode == DebugifyMode::SyntheticDebugInfo)
return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap);
assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
return new CheckDebugifyModulePass(false, NameOfWrappedPass, nullptr, Mode,
- DIPreservationMap,
+ DebugInfoBeforePass,
OrigDIVerifyBugsReportFilePath);
}
FunctionPass *createCheckDebugifyFunctionPass(
bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
- enum DebugifyMode Mode, DebugInfoPerPassMap *DIPreservationMap,
+ enum DebugifyMode Mode, DebugInfoPerPass *DebugInfoBeforePass,
StringRef OrigDIVerifyBugsReportFilePath) {
if (Mode == DebugifyMode::SyntheticDebugInfo)
return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap);
assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
return new CheckDebugifyFunctionPass(false, NameOfWrappedPass, nullptr, Mode,
- DIPreservationMap,
+ DebugInfoBeforePass,
OrigDIVerifyBugsReportFilePath);
}