diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp b/contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp index 24126b5ab67b..989473693a0b 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Utils/Debugify.cpp @@ -27,6 +27,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/JSON.h" +#include <optional> #define DEBUG_TYPE "debugify" @@ -114,7 +115,8 @@ bool llvm::applyDebugifyMetadata( continue; bool InsertedDbgVal = false; - auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None)); + auto SPType = + DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt)); DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized; if (F.hasPrivateLinkage() || F.hasInternalLinkage()) @@ -243,13 +245,18 @@ applyDebugify(Module &M, bool llvm::stripDebugifyMetadata(Module &M) { bool Changed = false; - // Remove the llvm.debugify module-level named metadata. + // Remove the llvm.debugify and llvm.mir.debugify module-level named metadata. NamedMDNode *DebugifyMD = M.getNamedMetadata("llvm.debugify"); if (DebugifyMD) { M.eraseNamedMetadata(DebugifyMD); Changed = true; } + if (auto *MIRDebugifyMD = M.getNamedMetadata("llvm.mir.debugify")) { + M.eraseNamedMetadata(MIRDebugifyMD); + Changed = true; + } + // Strip out all debug intrinsics and supporting metadata (subprograms, types, // variables, etc). Changed |= StripDebugInfo(M); @@ -338,7 +345,7 @@ bool llvm::collectDebugInfoMetadata(Module &M, if (I.getDebugLoc().getInlinedAt()) continue; // Skip undef values. - if (DVI->isUndef()) + if (DVI->isKillLocation()) continue; auto *Var = DVI->getVariable(); @@ -513,15 +520,19 @@ static void writeJSON(StringRef OrigDIVerifyBugsReportFilePath, return; } - OS_FILE << "{\"file\":\"" << FileNameFromCU << "\", "; + if (auto L = OS_FILE.lock()) { + OS_FILE << "{\"file\":\"" << FileNameFromCU << "\", "; - StringRef PassName = NameOfWrappedPass != "" ? NameOfWrappedPass : "no-name"; - OS_FILE << "\"pass\":\"" << PassName << "\", "; + StringRef PassName = + NameOfWrappedPass != "" ? NameOfWrappedPass : "no-name"; + OS_FILE << "\"pass\":\"" << PassName << "\", "; - llvm::json::Value BugsToPrint{std::move(Bugs)}; - OS_FILE << "\"bugs\": " << BugsToPrint; + llvm::json::Value BugsToPrint{std::move(Bugs)}; + OS_FILE << "\"bugs\": " << BugsToPrint; - OS_FILE << "}\n"; + OS_FILE << "}\n"; + } + OS_FILE.close(); } bool llvm::checkDebugInfoMetadata(Module &M, @@ -577,7 +588,7 @@ bool llvm::checkDebugInfoMetadata(Module &M, if (I.getDebugLoc().getInlinedAt()) continue; // Skip undef values. - if (DVI->isUndef()) + if (DVI->isKillLocation()) continue; auto *Var = DVI->getVariable(); @@ -670,7 +681,7 @@ bool diagnoseMisSizedDbgValue(Module &M, DbgValueInst *DVI) { Type *Ty = V->getType(); uint64_t ValueOperandSize = getAllocSizeInBits(M, Ty); - Optional<uint64_t> DbgVarSize = DVI->getFragmentSizeInBits(); + std::optional<uint64_t> DbgVarSize = DVI->getFragmentSizeInBits(); if (!ValueOperandSize || !DbgVarSize) return false; @@ -1020,19 +1031,19 @@ void DebugifyEachInstrumentation::registerCallbacks( PIC.registerBeforeNonSkippedPassCallback([this](StringRef P, Any IR) { if (isIgnoredPass(P)) return; - if (any_isa<const Function *>(IR)) - applyDebugify(*const_cast<Function *>(any_cast<const Function *>(IR)), + if (const auto **F = any_cast<const Function *>(&IR)) + applyDebugify(*const_cast<Function *>(*F), Mode, DebugInfoBeforePass, P); - else if (any_isa<const Module *>(IR)) - applyDebugify(*const_cast<Module *>(any_cast<const Module *>(IR)), + else if (const auto **M = any_cast<const Module *>(&IR)) + applyDebugify(*const_cast<Module *>(*M), Mode, DebugInfoBeforePass, P); }); PIC.registerAfterPassCallback([this](StringRef P, Any IR, const PreservedAnalyses &PassPA) { if (isIgnoredPass(P)) return; - if (any_isa<const Function *>(IR)) { - auto &F = *const_cast<Function *>(any_cast<const Function *>(IR)); + if (const auto **CF = any_cast<const Function *>(&IR)) { + auto &F = *const_cast<Function *>(*CF); Module &M = *F.getParent(); auto It = F.getIterator(); if (Mode == DebugifyMode::SyntheticDebugInfo) @@ -1043,8 +1054,8 @@ void DebugifyEachInstrumentation::registerCallbacks( M, make_range(It, std::next(It)), *DebugInfoBeforePass, "CheckModuleDebugify (original debuginfo)", P, OrigDIVerifyBugsReportFilePath); - } else if (any_isa<const Module *>(IR)) { - auto &M = *const_cast<Module *>(any_cast<const Module *>(IR)); + } else if (const auto **CM = any_cast<const Module *>(&IR)) { + auto &M = *const_cast<Module *>(*CM); if (Mode == DebugifyMode::SyntheticDebugInfo) checkDebugifyMetadata(M, M.functions(), P, "CheckModuleDebugify", /*Strip=*/true, DIStatsMap); |