Author: Jeremy Morse Date: 2025-06-09T19:36:34+01:00 New Revision: 0e4b8b8f81c97ef7374c321fd67a804dd17b4532
URL: https://github.com/llvm/llvm-project/commit/0e4b8b8f81c97ef7374c321fd67a804dd17b4532 DIFF: https://github.com/llvm/llvm-project/commit/0e4b8b8f81c97ef7374c321fd67a804dd17b4532.diff LOG: [DebugInfo][RemoveDIs] Rip out the UseNewDbgInfoFormat flag (#143207) Start removing debug intrinsics support -- starting with the flag that controls production of their replacement, debug records. This patch removes the command-line-flag and with it the ability to switch back to intrinsics. The module / function / block level "IsNewDbgInfoFormat" flags get hardcoded to true, I'll to incrementally remove things that depend on those flags. Added: Modified: clang/test/CodeGenCXX/tmp-md-nodes2.cpp flang/test/Integration/debug-local-var-2.f90 llvm/include/llvm/IR/BasicBlock.h llvm/include/llvm/IR/PassManagerImpl.h llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/CodeGen/MIRPrinter.cpp llvm/lib/IR/BasicBlock.cpp llvm/lib/IR/Function.cpp llvm/lib/IR/IRPrintingPasses.cpp llvm/lib/IR/Instruction.cpp llvm/lib/IR/LegacyPassManager.cpp llvm/lib/IR/Module.cpp llvm/lib/IRPrinter/IRPrintingPasses.cpp llvm/lib/LTO/LTO.cpp llvm/lib/Transforms/Coroutines/CoroFrame.cpp llvm/lib/Transforms/Utils/Local.cpp llvm/tools/llvm-as/llvm-as.cpp llvm/tools/llvm-dis/llvm-dis.cpp llvm/tools/llvm-link/llvm-link.cpp llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp llvm/unittests/IR/DebugInfoTest.cpp llvm/unittests/IR/InstructionsTest.cpp llvm/unittests/IR/ValueTest.cpp mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp mlir/lib/Target/LLVMIR/ModuleTranslation.cpp Removed: ################################################################################ diff --git a/clang/test/CodeGenCXX/tmp-md-nodes2.cpp b/clang/test/CodeGenCXX/tmp-md-nodes2.cpp index e5081884447bc..8500cf3c42393 100644 --- a/clang/test/CodeGenCXX/tmp-md-nodes2.cpp +++ b/clang/test/CodeGenCXX/tmp-md-nodes2.cpp @@ -1,8 +1,6 @@ // REQUIRES: asserts // RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | \ // RUN: FileCheck %s -// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm -mllvm --experimental-debuginfo-iterators=true %s -o - | \ -// RUN: FileCheck %s // This test simply checks that the varargs thunk is created. The failing test // case asserts. diff --git a/flang/test/Integration/debug-local-var-2.f90 b/flang/test/Integration/debug-local-var-2.f90 index 468bb0c5a1289..b97be141cc8d0 100644 --- a/flang/test/Integration/debug-local-var-2.f90 +++ b/flang/test/Integration/debug-local-var-2.f90 @@ -1,6 +1,5 @@ -! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -mllvm --experimental-debuginfo-iterators=true -o - | FileCheck %s --check-prefixes=BOTH,RECORDS -! RUN: %flang_fc1 -emit-llvm -debug-info-kind=line-tables-only %s -mllvm --experimental-debuginfo-iterators=false -o - | FileCheck --check-prefix=LINEONLY %s -! RUN: %flang_fc1 -emit-llvm -debug-info-kind=line-tables-only %s -mllvm --experimental-debuginfo-iterators=true -o - | FileCheck --check-prefix=LINEONLY %s +! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s --check-prefixes=BOTH,RECORDS +! RUN: %flang_fc1 -emit-llvm -debug-info-kind=line-tables-only %s -o - | FileCheck --check-prefix=LINEONLY %s ! This tests checks the debug information for local variables in llvm IR. diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h index b5ad0ded2464b..07444cd6779e1 100644 --- a/llvm/include/llvm/IR/BasicBlock.h +++ b/llvm/include/llvm/IR/BasicBlock.h @@ -87,8 +87,7 @@ class BasicBlock final : public Value, // Basic blocks are data objects also /// Convert variable location debugging information stored in dbg.value /// intrinsics into DbgMarkers / DbgRecords. Deletes all dbg.values in - /// the process and sets IsNewDbgInfoFormat = true. Only takes effect if - /// the UseNewDbgInfoFormat LLVM command line option is given. + /// the process and sets IsNewDbgInfoFormat = true. LLVM_ABI void convertToNewDbgValues(); /// Convert variable location debugging information stored in DbgMarkers and diff --git a/llvm/include/llvm/IR/PassManagerImpl.h b/llvm/include/llvm/IR/PassManagerImpl.h index 04ccbbbccb428..fe7b35fbce2c5 100644 --- a/llvm/include/llvm/IR/PassManagerImpl.h +++ b/llvm/include/llvm/IR/PassManagerImpl.h @@ -22,8 +22,6 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/PrettyStackTrace.h" -LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat; - namespace llvm { template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs> @@ -67,7 +65,7 @@ PreservedAnalyses PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...>::run( // RemoveDIs: if requested, convert debug-info to DbgRecord representation // for duration of these passes. - ScopedDbgInfoFormatSetter FormatSetter(IR, UseNewDbgInfoFormat); + ScopedDbgInfoFormatSetter FormatSetter(IR, true); StackTraceEntry Entry(PI, IR); for (auto &Pass : Passes) { diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 23db009654f4f..b933d240c4d27 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -64,8 +64,6 @@ static cl::opt<bool> AllowIncompleteIR( "Allow incomplete IR on a best effort basis (references to unknown " "metadata will be dropped)")); -LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat; - static std::string getTypeString(Type *T) { std::string Result; raw_string_ostream Tmp(Result); @@ -443,7 +441,7 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { UpgradeNVVMAnnotations(*M); UpgradeSectionAttributes(*M); - M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat); + M->setIsNewDbgInfoFormat(true); if (!Slots) return false; diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 105edb943eb7f..31129b7e5cf77 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -101,8 +101,6 @@ static cl::opt<bool> ExpandConstantExprs( cl::desc( "Expand constant expressions to instructions for testing purposes")); -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; - namespace { enum { @@ -4481,9 +4479,9 @@ Error BitcodeReader::parseGlobalIndirectSymbolRecord( Error BitcodeReader::parseModule(uint64_t ResumeBit, bool ShouldLazyLoadMetadata, ParserCallbacks Callbacks) { - // In preparation for the deletion of debug-intrinsics, don't allow module - // loading to escape intrinsics being autoupgraded to debug records. - TheModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat; + // Don't allow modules to use debug-intrinsics: autoupgrading them is now + // mandatory. + TheModule->IsNewDbgInfoFormat = true; this->ValueTypeCallback = std::move(Callbacks.ValueType); if (ResumeBit) { diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index fad8ebfad9f9a..628b939af19ce 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -122,8 +122,6 @@ namespace llvm { extern FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold; } -LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat; - namespace { /// These are manifest constants used by the bitcode writer. They do not need to diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index b7b8f66736a49..34ac0794f901f 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -70,8 +70,6 @@ static cl::opt<bool> SimplifyMIR( static cl::opt<bool> PrintLocations("mir-debug-loc", cl::Hidden, cl::init(true), cl::desc("Print MIR debug-locations")); -extern cl::opt<bool> UseNewDbgInfoFormat; - namespace { /// This structure describes how to print out stack object references. @@ -967,8 +965,7 @@ void MIRFormatter::printIRValue(raw_ostream &OS, const Value &V, } void llvm::printMIR(raw_ostream &OS, const Module &M) { - ScopedDbgInfoFormatSetter FormatSetter(const_cast<Module &>(M), - UseNewDbgInfoFormat); + ScopedDbgInfoFormatSetter FormatSetter(const_cast<Module &>(M), true); yaml::Output Out(OS); Out << const_cast<Module &>(M); @@ -979,6 +976,6 @@ void llvm::printMIR(raw_ostream &OS, const MachineModuleInfo &MMI, // RemoveDIs: as there's no textual form for DbgRecords yet, print debug-info // in dbg.value format. ScopedDbgInfoFormatSetter FormatSetter( - const_cast<Function &>(MF.getFunction()), UseNewDbgInfoFormat); + const_cast<Function &>(MF.getFunction()), true); printMF(OS, MMI, MF); } diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp index 628f062580fa5..ed11ea06398f1 100644 --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -31,30 +31,6 @@ using namespace llvm; #define DEBUG_TYPE "ir" STATISTIC(NumInstrRenumberings, "Number of renumberings across all blocks"); -// This cl-opt exists to control whether variable-location information is -// produced using intrinsics, or whether DbgRecords are produced. However, -// it's imminently being phased out, so give it a flag-name that is very -// unlikely to be used anywhere. -// -// If you find yourself needing to use this flag for any period longer than -// five minutes, please revert the patch making this change, and make contact -// in this discourse post, where we can discuss any further transition work -// that might be needed to remove debug intrinsics. -// -// https://discourse.llvm.org/t/psa-ir-output-changing-from-debug-intrinsics-to-debug-records/79578 -LLVM_ABI cl::opt<bool> - UseNewDbgInfoFormat("dont-pass-this-flag-please-experimental-debuginfo", - cl::Hidden, cl::init(true)); - -// This cl-opt collects the --experimental-debuginfo-iterators flag and then -// does nothing with it (because the it gets stored into an otherwise unused -// cl-opt), so that we can disable debug-intrinsic production without -// immediately modifying lots of tests. If your tests break because of this -// change, please see the next comment up. -static cl::opt<bool> DeliberatelyUnseenDbgInfoFlag( - "experimental-debuginfo-iterators", cl::Hidden, - cl::init(true)); - DbgMarker *BasicBlock::createMarker(Instruction *I) { assert(IsNewDbgInfoFormat && "Tried to create a marker in a non new debug-info block!"); @@ -187,7 +163,7 @@ template class llvm::SymbolTableListTraits< BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent, BasicBlock *InsertBefore) : Value(Type::getLabelTy(C), Value::BasicBlockVal), - IsNewDbgInfoFormat(UseNewDbgInfoFormat), Parent(nullptr) { + IsNewDbgInfoFormat(true), Parent(nullptr) { if (NewParent) insertInto(NewParent, InsertBefore); diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index dfffbbfcf5d2a..63665d837c398 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -65,8 +65,6 @@ static cl::opt<int> NonGlobalValueMaxNameSize( "non-global-value-max-name-size", cl::Hidden, cl::init(1024), cl::desc("Maximum size for the name of non-global values.")); -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; - void Function::renumberBlocks() { validateBlockNumbers(); @@ -492,7 +490,7 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &name, Module *ParentModule) : GlobalObject(Ty, Value::FunctionVal, AllocMarker, Linkage, name, computeAddrSpace(AddrSpace, ParentModule)), - NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(UseNewDbgInfoFormat) { + NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(true) { assert(FunctionType::isValidReturnType(getReturnType()) && "invalid return type"); setGlobalObjectSubClassData(0); diff --git a/llvm/lib/IR/IRPrintingPasses.cpp b/llvm/lib/IR/IRPrintingPasses.cpp index a26bb0f5af012..eb35377d0fb23 100644 --- a/llvm/lib/IR/IRPrintingPasses.cpp +++ b/llvm/lib/IR/IRPrintingPasses.cpp @@ -24,8 +24,6 @@ using namespace llvm; -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; - namespace { class PrintModulePassWrapper : public ModulePass { @@ -42,12 +40,10 @@ class PrintModulePassWrapper : public ModulePass { ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {} bool runOnModule(Module &M) override { - ScopedDbgInfoFormatSetter FormatSetter(M, UseNewDbgInfoFormat); + ScopedDbgInfoFormatSetter FormatSetter(M, true); // Remove intrinsic declarations when printing in the new format. - // TODO: Move this into Module::setIsNewDbgInfoFormat when we're ready to - // update test output. - if (UseNewDbgInfoFormat) - M.removeDebugIntrinsicDeclarations(); + // TODO: consider removing this as debug-intrinsics are gone. + M.removeDebugIntrinsicDeclarations(); if (llvm::isFunctionInPrintList("*")) { if (!Banner.empty()) @@ -88,7 +84,7 @@ class PrintFunctionPassWrapper : public FunctionPass { // This pass just prints a banner followed by the function as it's processed. bool runOnFunction(Function &F) override { - ScopedDbgInfoFormatSetter FormatSetter(F, UseNewDbgInfoFormat); + ScopedDbgInfoFormatSetter FormatSetter(F, true); if (isFunctionInPrintList(F.getName())) { if (forcePrintModuleIR()) diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp index 18ce16522af90..109d516c61b7c 100644 --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -130,8 +130,6 @@ BasicBlock::iterator Instruction::insertInto(BasicBlock *ParentBB, return getIterator(); } -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; - void Instruction::insertBefore(BasicBlock &BB, InstListType::iterator InsertPos) { assert(!DebugMarker); diff --git a/llvm/lib/IR/LegacyPassManager.cpp b/llvm/lib/IR/LegacyPassManager.cpp index 110636b2e9032..fd69e309cdf10 100644 --- a/llvm/lib/IR/LegacyPassManager.cpp +++ b/llvm/lib/IR/LegacyPassManager.cpp @@ -32,7 +32,6 @@ using namespace llvm; -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; // See PassManagers.h for Pass Manager infrastructure overview. //===----------------------------------------------------------------------===// @@ -530,7 +529,7 @@ bool PassManagerImpl::run(Module &M) { // RemoveDIs: if a command line flag is given, convert to the // DbgVariableRecord representation of debug-info for the duration of these // passes. - ScopedDbgInfoFormatSetter FormatSetter(M, UseNewDbgInfoFormat); + ScopedDbgInfoFormatSetter FormatSetter(M, true); for (ImmutablePass *ImPass : getImmutablePasses()) Changed |= ImPass->doInitialization(M); diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 132a8c8d19d8a..0a47f98619691 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -54,8 +54,6 @@ using namespace llvm; -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; - //===----------------------------------------------------------------------===// // Methods to implement the globals and functions lists. // @@ -74,7 +72,7 @@ template class LLVM_EXPORT_TEMPLATE llvm::SymbolTableListTraits<GlobalIFunc>; Module::Module(StringRef MID, LLVMContext &C) : Context(C), ValSymTab(std::make_unique<ValueSymbolTable>(-1)), ModuleID(std::string(MID)), SourceFileName(std::string(MID)), - IsNewDbgInfoFormat(UseNewDbgInfoFormat) { + IsNewDbgInfoFormat(true) { Context.addModule(this); } diff --git a/llvm/lib/IRPrinter/IRPrintingPasses.cpp b/llvm/lib/IRPrinter/IRPrintingPasses.cpp index d6bd6c32002da..5fd6a094fa57b 100644 --- a/llvm/lib/IRPrinter/IRPrintingPasses.cpp +++ b/llvm/lib/IRPrinter/IRPrintingPasses.cpp @@ -23,8 +23,6 @@ using namespace llvm; -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; - PrintModulePass::PrintModulePass() : OS(dbgs()) {} PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner, bool ShouldPreserveUseListOrder, @@ -34,12 +32,10 @@ PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner, EmitSummaryIndex(EmitSummaryIndex) {} PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &AM) { - ScopedDbgInfoFormatSetter FormatSetter(M, UseNewDbgInfoFormat); + ScopedDbgInfoFormatSetter FormatSetter(M, true); // Remove intrinsic declarations when printing in the new format. - // TODO: Move this into Module::setIsNewDbgInfoFormat when we're ready to - // update test output. - if (UseNewDbgInfoFormat) - M.removeDebugIntrinsicDeclarations(); + // TODO: consider removing this now that debug intrinsics are gone. + M.removeDebugIntrinsicDeclarations(); if (llvm::isFunctionInPrintList("*")) { if (!Banner.empty()) @@ -76,7 +72,7 @@ PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, const std::string &Banner) PreservedAnalyses PrintFunctionPass::run(Function &F, FunctionAnalysisManager &) { - ScopedDbgInfoFormatSetter FormatSetter(F, UseNewDbgInfoFormat); + ScopedDbgInfoFormatSetter FormatSetter(F, true); if (isFunctionInPrintList(F.getName())) { if (forcePrintModuleIR()) diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index ba120a0566834..df395073359cf 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -70,8 +70,6 @@ using namespace object; #define DEBUG_TYPE "lto" -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; - static cl::opt<bool> DumpThinCGSCCs("dump-thin-cg-sccs", cl::init(false), cl::Hidden, cl::desc("Dump the SCCs in the ThinLTO index's callgraph")); @@ -602,7 +600,7 @@ LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel, : ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel), Ctx(Conf), CombinedModule(std::make_unique<Module>("ld-temp.o", Ctx)), Mover(std::make_unique<IRMover>(*CombinedModule)) { - CombinedModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat; + CombinedModule->IsNewDbgInfoFormat = true; } LTO::ThinLTOState::ThinLTOState(ThinBackend BackendParam) diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp index 53d78edda2e9f..26843ebc71666 100644 --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -41,8 +41,6 @@ using namespace llvm; -extern cl::opt<bool> UseNewDbgInfoFormat; - #define DEBUG_TYPE "coro-frame" namespace { @@ -842,18 +840,12 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape, DILocation::get(DIS->getContext(), LineNum, /*Column=*/1, DIS); assert(FrameDIVar->isValidLocationForIntrinsic(DILoc)); - if (UseNewDbgInfoFormat) { - DbgVariableRecord *NewDVR = - new DbgVariableRecord(ValueAsMetadata::get(Shape.FramePtr), FrameDIVar, - DBuilder.createExpression(), DILoc, - DbgVariableRecord::LocationType::Declare); - BasicBlock::iterator It = Shape.getInsertPtAfterFramePtr(); - It->getParent()->insertDbgRecordBefore(NewDVR, It); - } else { - DBuilder.insertDeclare(Shape.FramePtr, FrameDIVar, - DBuilder.createExpression(), DILoc, - Shape.getInsertPtAfterFramePtr()); - } + DbgVariableRecord *NewDVR = + new DbgVariableRecord(ValueAsMetadata::get(Shape.FramePtr), FrameDIVar, + DBuilder.createExpression(), DILoc, + DbgVariableRecord::LocationType::Declare); + BasicBlock::iterator It = Shape.getInsertPtAfterFramePtr(); + It->getParent()->insertDbgRecordBefore(NewDVR, It); } // Build a struct that will keep state for an active coroutine. @@ -1136,19 +1128,12 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) { // This dbg.declare is preserved for all coro-split function // fragments. It will be unreachable in the main function, and // processed by coro::salvageDebugInfo() by the Cloner. - if (UseNewDbgInfoFormat) { - DbgVariableRecord *NewDVR = new DbgVariableRecord( - ValueAsMetadata::get(CurrentReload), DDI->getVariable(), - DDI->getExpression(), DDI->getDebugLoc(), - DbgVariableRecord::LocationType::Declare); - Builder.GetInsertPoint()->getParent()->insertDbgRecordBefore( - NewDVR, Builder.GetInsertPoint()); - } else { - DIBuilder(*CurrentBlock->getParent()->getParent(), AllowUnresolved) - .insertDeclare(CurrentReload, DDI->getVariable(), - DDI->getExpression(), DDI->getDebugLoc(), - Builder.GetInsertPoint()); - } + DbgVariableRecord *NewDVR = new DbgVariableRecord( + ValueAsMetadata::get(CurrentReload), DDI->getVariable(), + DDI->getExpression(), DDI->getDebugLoc(), + DbgVariableRecord::LocationType::Declare); + Builder.GetInsertPoint()->getParent()->insertDbgRecordBefore( + NewDVR, Builder.GetInsertPoint()); // This dbg.declare is for the main function entry point. It // will be deleted in all coro-split functions. coro::salvageDebugInfo(ArgToAllocaMap, *DDI, false /*UseEntryValue*/); diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index be71cb69ad8cc..c8ad01a592ff6 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -88,8 +88,6 @@ using namespace llvm; using namespace llvm::PatternMatch; -extern cl::opt<bool> UseNewDbgInfoFormat; - #define DEBUG_TYPE "local" STATISTIC(NumRemoved, "Number of unreachable basic blocks removed"); @@ -1691,16 +1689,10 @@ static void insertDbgValueOrDbgVariableRecord(DIBuilder &Builder, Value *DV, DIExpression *DIExpr, const DebugLoc &NewLoc, BasicBlock::iterator Instr) { - if (!UseNewDbgInfoFormat) { - Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc, Instr); - } else { - // RemoveDIs: if we're using the new debug-info format, allocate a - // DbgVariableRecord directly instead of a dbg.value intrinsic. - ValueAsMetadata *DVAM = ValueAsMetadata::get(DV); - DbgVariableRecord *DV = - new DbgVariableRecord(DVAM, DIVar, DIExpr, NewLoc.get()); - Instr->getParent()->insertDbgRecordBefore(DV, Instr); - } + ValueAsMetadata *DVAM = ValueAsMetadata::get(DV); + DbgVariableRecord *DVRec = + new DbgVariableRecord(DVAM, DIVar, DIExpr, NewLoc.get()); + Instr->getParent()->insertDbgRecordBefore(DVRec, Instr); } static void insertDbgValueOrDbgVariableRecordAfter( @@ -1838,7 +1830,6 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, // then we want to insert a dbg.value for the corresponding fragment. LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to dbg.value: " << *DVR << '\n'); - assert(UseNewDbgInfoFormat); // For now, when there is a store to parts of the variable (but we do not // know which part) we insert an dbg.value intrinsic to indicate that we @@ -1919,7 +1910,6 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, LoadInst *LI, // future if multi-location support is added to the IR, it might be // preferable to keep tracking both the loaded value and the original // address in case the alloca can not be elided. - assert(UseNewDbgInfoFormat); // Create a DbgVariableRecord directly and insert. ValueAsMetadata *LIVAM = ValueAsMetadata::get(LI); diff --git a/llvm/tools/llvm-as/llvm-as.cpp b/llvm/tools/llvm-as/llvm-as.cpp index 081bcb6faa719..f42a08e2e9c8b 100644 --- a/llvm/tools/llvm-as/llvm-as.cpp +++ b/llvm/tools/llvm-as/llvm-as.cpp @@ -66,7 +66,6 @@ static cl::opt<std::string> ClDataLayout("data-layout", cl::desc("data layout string to use"), cl::value_desc("layout-string"), cl::init(""), cl::cat(AsCat)); -extern cl::opt<bool> UseNewDbgInfoFormat; static void WriteOutputFile(const Module *M, const ModuleSummaryIndex *Index) { // Infer the output filename if needed. @@ -140,10 +139,8 @@ int main(int argc, char **argv) { return 1; } - // Convert to new debug format if requested. - M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat); - if (M->IsNewDbgInfoFormat) - M->removeDebugIntrinsicDeclarations(); + M->setIsNewDbgInfoFormat(true); + M->removeDebugIntrinsicDeclarations(); std::unique_ptr<ModuleSummaryIndex> Index = std::move(ModuleAndIndex.Index); diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp index 8c1aaf6fd604b..8937272abb92a 100644 --- a/llvm/tools/llvm-dis/llvm-dis.cpp +++ b/llvm/tools/llvm-dis/llvm-dis.cpp @@ -96,8 +96,6 @@ static cl::opt<bool> PrintThinLTOIndexOnly( cl::desc("Only read thinlto index and print the index as LLVM assembly."), cl::init(false), cl::Hidden, cl::cat(DisCategory)); -extern cl::opt<bool> UseNewDbgInfoFormat; - namespace { static void printDebugLoc(const DebugLoc &DL, formatted_raw_ostream &OS) { @@ -270,9 +268,8 @@ int main(int argc, char **argv) { // All that llvm-dis does is write the assembly to a file. if (!DontPrint) { if (M) { - M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat); - if (UseNewDbgInfoFormat) - M->removeDebugIntrinsicDeclarations(); + M->setIsNewDbgInfoFormat(true); + M->removeDebugIntrinsicDeclarations(); M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder); } if (Index) diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp index ac5b5f52741ad..35b4f0af97f6e 100644 --- a/llvm/tools/llvm-link/llvm-link.cpp +++ b/llvm/tools/llvm-link/llvm-link.cpp @@ -129,8 +129,6 @@ static cl::opt<bool> IgnoreNonBitcode( cl::desc("Do not report an error for non-bitcode files in archives"), cl::Hidden); -extern cl::opt<bool> UseNewDbgInfoFormat; - static ExitOnError ExitOnErr; // Read the specified bitcode file in and return it. This routine searches the @@ -531,10 +529,10 @@ int main(int argc, char **argv) { Composite->removeDebugIntrinsicDeclarations(); }; if (OutputAssembly) { - SetFormat(UseNewDbgInfoFormat); + SetFormat(true); Composite->print(Out.os(), nullptr, PreserveAssemblyUseListOrder); } else if (Force || !CheckBitcodeOutputToConsole(Out.os())) { - SetFormat(UseNewDbgInfoFormat); + SetFormat(true); WriteBitcodeToFile(*Composite, Out.os(), PreserveBitcodeUseListOrder); } diff --git a/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp b/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp index 9edb21f71d0af..03009d53d63f4 100644 --- a/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp +++ b/llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp @@ -24,9 +24,6 @@ using namespace llvm; using namespace IRSimilarity; -LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat; -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; - static std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context, StringRef ModuleStr) { SMDiagnostic Err; diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp index c3a0f665d423a..a888fd6c6cdc3 100644 --- a/llvm/unittests/IR/DebugInfoTest.cpp +++ b/llvm/unittests/IR/DebugInfoTest.cpp @@ -27,8 +27,6 @@ using namespace llvm; -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; - static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) { SMDiagnostic Err; std::unique_ptr<Module> Mod = parseAssemblyString(IR, Err, C); @@ -241,8 +239,6 @@ TEST(DbgVariableIntrinsic, EmptyMDIsKillLocation) { // Duplicate of above test, but in DbgVariableRecord representation. TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) { LLVMContext C; - bool OldDbgValueMode = UseNewDbgInfoFormat; - UseNewDbgInfoFormat = true; std::unique_ptr<Module> M = parseIR(C, R"( define i16 @f(i16 %a) !dbg !6 { @@ -285,23 +281,19 @@ TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) { EXPECT_EQ(DVRs[1]->getNumVariableLocationOps(), 2u); EXPECT_TRUE(isa<UndefValue>(DVRs[1]->getVariableLocationOp(1))); EXPECT_TRUE(DVRs[1]->isKillLocation()); - UseNewDbgInfoFormat = OldDbgValueMode; } // Ensure that the order of dbg.value intrinsics returned by findDbgValues, and // their corresponding DbgVariableRecord representation, are consistent. TEST(MetadataTest, OrderingOfDbgVariableRecords) { - bool OldDbgValueMode = UseNewDbgInfoFormat; - UseNewDbgInfoFormat = false; LLVMContext C; std::unique_ptr<Module> M = parseIR(C, R"( define i16 @f(i16 %a) !dbg !6 { %b = add i16 %a, 1, !dbg !11 - call void @llvm.dbg.value(metadata i16 %b, metadata !9, metadata !DIExpression()), !dbg !11 - call void @llvm.dbg.value(metadata i16 %b, metadata !12, metadata !DIExpression()), !dbg !11 + #dbg_value(i16 %b, !9, !DIExpression(), !11) + #dbg_value(i16 %b, !12, !DIExpression(), !11) ret i16 0, !dbg !11 } - declare void @llvm.dbg.value(metadata, metadata, metadata) #0 attributes #0 = { nounwind readnone speculatable willreturn } !llvm.dbg.cu = !{!0} @@ -324,33 +316,20 @@ TEST(MetadataTest, OrderingOfDbgVariableRecords) { SmallVector<DbgValueInst *, 2> DVIs; SmallVector<DbgVariableRecord *, 2> DVRs; - findDbgValues(DVIs, &I, &DVRs); - ASSERT_EQ(DVIs.size(), 2u); - ASSERT_EQ(DVRs.size(), 0u); - - // The correct order of dbg.values is given by their use-list, which becomes - // the reverse order of creation. Thus the dbg.values should come out as - // "bar" and then "foo". - DILocalVariable *Var0 = DVIs[0]->getVariable(); - EXPECT_TRUE(Var0->getName() == "bar"); - DILocalVariable *Var1 = DVIs[1]->getVariable(); - EXPECT_TRUE(Var1->getName() == "foo"); - // Now try again, but in DbgVariableRecord form. - DVIs.clear(); - - M->convertToNewDbgValues(); findDbgValues(DVIs, &I, &DVRs); ASSERT_EQ(DVIs.size(), 0u); ASSERT_EQ(DVRs.size(), 2u); - Var0 = DVRs[0]->getVariable(); + // The correct order of dbg.values is given by their use-list, which becomes + // the reverse order of creation. Thus the dbg.values should come out as + // "bar" and then "foo". + const DILocalVariable *Var0 = DVRs[0]->getVariable(); EXPECT_TRUE(Var0->getName() == "bar"); - Var1 = DVRs[1]->getVariable(); + const DILocalVariable *Var1 = DVRs[1]->getVariable(); EXPECT_TRUE(Var1->getName() == "foo"); M->convertFromNewDbgValues(); - UseNewDbgInfoFormat = OldDbgValueMode; } TEST(DIBuilder, CreateFile) { @@ -923,8 +902,6 @@ TEST(AssignmentTrackingTest, InstrMethods) { // dbg.values that have been converted to a non-instruction format. TEST(MetadataTest, ConvertDbgToDbgVariableRecord) { LLVMContext C; - bool OldDbgValueMode = UseNewDbgInfoFormat; - UseNewDbgInfoFormat = false; std::unique_ptr<Module> M = parseIR(C, R"( define i16 @f(i16 %a) !dbg !6 { call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11 @@ -954,6 +931,12 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) { !11 = !DILocation(line: 1, column: 1, scope: !6) )"); + // The IR above will be autoupgraded to debug records: but this test is about + // the conversion routines, so convert it back. This test will have value + // going forwards for the purpose of testing the conversion routine, which + // some compatibility tools (DXIL?) wish to use. + M->convertFromNewDbgValues(); + // Find the first dbg.value, Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHIIt(); const DILocalVariable *Var = nullptr; @@ -1099,15 +1082,11 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) { // The record of those trailing DbgVariableRecords would dangle and cause an // assertion failure if it lived until the end of the LLVMContext. ExitBlock->deleteTrailingDbgRecords(); - UseNewDbgInfoFormat = OldDbgValueMode; } TEST(MetadataTest, DbgVariableRecordConversionRoutines) { LLVMContext C; - bool OldDbgValueMode = UseNewDbgInfoFormat; - UseNewDbgInfoFormat = false; - std::unique_ptr<Module> M = parseIR(C, R"( define i16 @f(i16 %a) !dbg !6 { call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11 @@ -1137,13 +1116,13 @@ TEST(MetadataTest, DbgVariableRecordConversionRoutines) { !11 = !DILocation(line: 1, column: 1, scope: !6) )"); - // For the purpose of this test, set and un-set the command line option - // corresponding to UseNewDbgInfoFormat, but only after parsing, to ensure - // that the IR starts off in the old format. - UseNewDbgInfoFormat = true; + // This test exists to check we can convert back and forth between old and new + // debug info formats (dbg.value intrinsics versus #dbg_value records). + // We're ripping out support for debug intrinsics, but the conversions will + // live on in bitcode autoupgrade and possibly DXIL autodowngrade. Thus, this + // test is still valuable. Begin by starting in the intrinsic format: + M->convertFromNewDbgValues(); - // Check that the conversion routines and utilities between dbg.value - // debug-info format and DbgVariableRecords works. Function *F = M->getFunction("f"); BasicBlock *BB1 = &F->getEntryBlock(); // First instruction should be a dbg.value. @@ -1245,8 +1224,6 @@ TEST(MetadataTest, DbgVariableRecordConversionRoutines) { EXPECT_EQ(DVI1->getExpression(), Expr1); EXPECT_EQ(DVI2->getVariable(), DLV2); EXPECT_EQ(DVI2->getExpression(), Expr2); - - UseNewDbgInfoFormat = OldDbgValueMode; } // Test that the hashing function for DISubprograms representing methods produce diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp index acf169278a9fd..126db4d4c1625 100644 --- a/llvm/unittests/IR/InstructionsTest.cpp +++ b/llvm/unittests/IR/InstructionsTest.cpp @@ -33,8 +33,6 @@ #include "gtest/gtest.h" #include <memory> -LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat; - namespace llvm { namespace { @@ -1452,8 +1450,6 @@ TEST(InstructionsTest, GetSplat) { TEST(InstructionsTest, SkipDebug) { LLVMContext C; - bool OldDbgValueMode = UseNewDbgInfoFormat; - UseNewDbgInfoFormat = false; std::unique_ptr<Module> M = parseIR(C, R"( declare void @llvm.dbg.value(metadata, metadata, metadata) @@ -1480,6 +1476,8 @@ TEST(InstructionsTest, SkipDebug) { )"); ASSERT_TRUE(M); Function *F = cast<Function>(M->getNamedValue("f")); + // This test wants to see dbg.values. + F->convertFromNewDbgValues(); BasicBlock &BB = F->front(); // The first non-debug instruction is the terminator. @@ -1489,7 +1487,6 @@ TEST(InstructionsTest, SkipDebug) { // After the terminator, there are no non-debug instructions. EXPECT_EQ(nullptr, Term->getNextNonDebugInstruction()); - UseNewDbgInfoFormat = OldDbgValueMode; } TEST(InstructionsTest, PhiMightNotBeFPMathOperator) { diff --git a/llvm/unittests/IR/ValueTest.cpp b/llvm/unittests/IR/ValueTest.cpp index 888595efdb66e..4d28fe019ecd2 100644 --- a/llvm/unittests/IR/ValueTest.cpp +++ b/llvm/unittests/IR/ValueTest.cpp @@ -20,8 +20,6 @@ #include "gtest/gtest.h" using namespace llvm; -LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat; - namespace { TEST(ValueTest, UsedInBasicBlock) { @@ -256,74 +254,6 @@ TEST(ValueTest, getLocalSlotDeath) { #endif TEST(ValueTest, replaceUsesOutsideBlock) { - // Check that Value::replaceUsesOutsideBlock(New, BB) replaces uses outside - // BB, including dbg.* uses of MetadataAsValue(ValueAsMetadata(this)). - bool OldDbgValueMode = UseNewDbgInfoFormat; - UseNewDbgInfoFormat = false; - const auto *IR = R"( - define i32 @f() !dbg !6 { - entry: - %a = add i32 0, 1, !dbg !15 - %b = add i32 0, 2, !dbg !15 - %c = add i32 %a, 2, !dbg !15 - call void @llvm.dbg.value(metadata i32 %a, metadata !9, metadata !DIExpression()), !dbg !15 - br label %exit, !dbg !15 - - exit: - call void @llvm.dbg.value(metadata i32 %a, metadata !11, metadata !DIExpression()), !dbg !16 - ret i32 %a, !dbg !16 - } - - declare void @llvm.dbg.value(metadata, metadata, metadata) - - !llvm.dbg.cu = !{!0} - !llvm.module.flags = !{!5} - - !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) - !1 = !DIFile(filename: "test.ll", directory: "/") - !2 = !{} - !5 = !{i32 2, !"Debug Info Version", i32 3} - !6 = distinct !DISubprogram(name: "f", linkageName: "f", scope: null, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !8) - !7 = !DISubroutineType(types: !2) - !8 = !{!9, !11} - !9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10) - !10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_signed) - !11 = !DILocalVariable(name: "2", scope: !6, file: !1, line: 2, type: !12) - !12 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_signed) - !15 = !DILocation(line: 1, column: 1, scope: !6) - !16 = !DILocation(line: 5, column: 1, scope: !6) - )"; - LLVMContext Ctx; - SMDiagnostic Err; - std::unique_ptr<Module> M = parseAssemblyString(IR, Err, Ctx); - if (!M) - Err.print("ValueTest", errs()); - - auto GetNext = [](auto *I) { return &*++I->getIterator(); }; - - Function *F = M->getFunction("f"); - // Entry. - BasicBlock *Entry = &F->front(); - Instruction *A = &Entry->front(); - Instruction *B = GetNext(A); - Instruction *C = GetNext(B); - auto *EntryDbg = cast<DbgValueInst>(GetNext(C)); - // Exit. - BasicBlock *Exit = GetNext(Entry); - auto *ExitDbg = cast<DbgValueInst>(&Exit->front()); - Instruction *Ret = GetNext(ExitDbg); - - A->replaceUsesOutsideBlock(B, Entry); - // These users are in Entry so shouldn't be changed. - ASSERT_TRUE(C->getOperand(0) == cast<Value>(A)); - ASSERT_TRUE(EntryDbg->getValue(0) == cast<Value>(A)); - // These users are outside Entry so should be changed. - ASSERT_TRUE(ExitDbg->getValue(0) == cast<Value>(B)); - ASSERT_TRUE(Ret->getOperand(0) == cast<Value>(B)); - UseNewDbgInfoFormat = OldDbgValueMode; -} - -TEST(ValueTest, replaceUsesOutsideBlockDbgVariableRecord) { // Check that Value::replaceUsesOutsideBlock(New, BB) replaces uses outside // BB, including DbgVariableRecords. const auto *IR = R"( diff --git a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp index e3fa7c883c524..73e8626db3a09 100644 --- a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp @@ -20,8 +20,6 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" -extern llvm::cl::opt<bool> UseNewDbgInfoFormat; - using namespace mlir; namespace mlir { @@ -37,10 +35,8 @@ void registerToLLVMIRTranslation() { // When printing LLVM IR, we should convert the module to the debug info // format that LLVM expects us to print. // See https://llvm.org/docs/RemoveDIsDebugInfo.html - llvm::ScopedDbgInfoFormatSetter formatSetter(*llvmModule, - UseNewDbgInfoFormat); - if (UseNewDbgInfoFormat) - llvmModule->removeDebugIntrinsicDeclarations(); + llvm::ScopedDbgInfoFormatSetter formatSetter(*llvmModule, true); + llvmModule->removeDebugIntrinsicDeclarations(); llvmModule->print(output, nullptr); return success(); }, diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index 4cc419c7cde5b..22b391b7d20f8 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -67,8 +67,6 @@ using namespace mlir; using namespace mlir::LLVM; using namespace mlir::LLVM::detail; -extern llvm::cl::opt<bool> UseNewDbgInfoFormat; - #include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc" namespace { @@ -2328,7 +2326,7 @@ mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext, // Once we've finished constructing elements in the module, we should convert // it to use the debug info format desired by LLVM. // See https://llvm.org/docs/RemoveDIsDebugInfo.html - translator.llvmModule->setIsNewDbgInfoFormat(UseNewDbgInfoFormat); + translator.llvmModule->setIsNewDbgInfoFormat(true); // Add the necessary debug info module flags, if they were not encoded in MLIR // beforehand. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits