diff options
-rw-r--r-- | llvm/include/llvm/IR/Module.h | 12 | ||||
-rw-r--r-- | llvm/include/llvm/IR/PrintPasses.h | 19 | ||||
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 75 | ||||
-rw-r--r-- | llvm/lib/IR/BasicBlock.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/IRPrintingPasses.cpp | 32 | ||||
-rw-r--r-- | llvm/lib/IR/Module.cpp | 22 | ||||
-rw-r--r-- | llvm/lib/IRPrinter/IRPrintingPasses.cpp | 29 | ||||
-rw-r--r-- | llvm/test/DebugInfo/Generic/inline-alloca-ordering.ll | 7 | ||||
-rw-r--r-- | llvm/test/DebugInfo/Generic/inline-dbg-values.ll | 8 | ||||
-rwxr-xr-x | llvm/test/DebugInfo/dpvalue-print-nocrash.ll | 3 | ||||
-rw-r--r-- | llvm/test/DebugInfo/print-non-instruction-debug-info.ll | 86 | ||||
-rw-r--r-- | llvm/test/Transforms/Attributor/ArgumentPromotion/pr33641_remove_arg_dbgvalue.ll | 18 | ||||
-rw-r--r-- | llvm/test/Transforms/DeadArgElim/2010-04-30-DbgInfo.ll | 32 | ||||
-rw-r--r-- | llvm/test/Transforms/IROutliner/outlining-debug-statements.ll | 7 |
14 files changed, 245 insertions, 109 deletions
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h index 68a89dc..e41a594 100644 --- a/llvm/include/llvm/IR/Module.h +++ b/llvm/include/llvm/IR/Module.h @@ -218,6 +218,11 @@ public: /// \ref BasicBlock. bool IsNewDbgInfoFormat; + /// Used when printing this module in the new debug info format; removes all + /// declarations of debug intrinsics that are replaced by non-intrinsic + /// records in the new format. + void removeDebugIntrinsicDeclarations(); + /// \see BasicBlock::convertToNewDbgValues. void convertToNewDbgValues() { for (auto &F : *this) { @@ -234,6 +239,13 @@ public: IsNewDbgInfoFormat = false; } + void setIsNewDbgInfoFormat(bool UseNewFormat) { + if (UseNewFormat && !IsNewDbgInfoFormat) + convertToNewDbgValues(); + else if (!UseNewFormat && IsNewDbgInfoFormat) + convertFromNewDbgValues(); + } + /// The Module constructor. Note that there is no default constructor. You /// must provide a name for the module upon construction. explicit Module(StringRef ModuleID, LLVMContext& C); diff --git a/llvm/include/llvm/IR/PrintPasses.h b/llvm/include/llvm/IR/PrintPasses.h index 95b97e7..3803bd0 100644 --- a/llvm/include/llvm/IR/PrintPasses.h +++ b/llvm/include/llvm/IR/PrintPasses.h @@ -78,6 +78,25 @@ std::string doSystemDiff(StringRef Before, StringRef After, StringRef OldLineFormat, StringRef NewLineFormat, StringRef UnchangedLineFormat); +/// Used to temporarily set the debug info format of a function, module, or +/// basic block for the duration of this object's lifetime, after which the +/// prior state will be restored. +template <typename T> class ScopedDbgInfoFormatSetter { + T &Obj; + bool OldState; + +public: + ScopedDbgInfoFormatSetter(T &Obj, bool NewState) + : Obj(Obj), OldState(Obj.IsNewDbgInfoFormat) { + Obj.setIsNewDbgInfoFormat(NewState); + } + ~ScopedDbgInfoFormatSetter() { Obj.setIsNewDbgInfoFormat(OldState); } +}; + +template <typename T> +ScopedDbgInfoFormatSetter(T &Obj, bool NewState) + -> ScopedDbgInfoFormatSetter<T>; + } // namespace llvm #endif // LLVM_IR_PRINTPASSES_H diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index fba404c..a3da6ca 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -861,7 +861,7 @@ private: /// Add all of the metadata from an instruction. void processInstructionMetadata(const Instruction &I); - /// Add all of the metadata from an instruction. + /// Add all of the metadata from a DbgRecord. void processDbgRecordMetadata(const DbgRecord &DPV); }; @@ -1140,6 +1140,9 @@ void SlotTracker::processFunctionMetadata(const Function &F) { void SlotTracker::processDbgRecordMetadata(const DbgRecord &DR) { if (const DPValue *DPV = dyn_cast<const DPValue>(&DR)) { + // Process metadata used by DbgRecords; we only specifically care about the + // DILocalVariable, DILocation, and DIAssignID fields, as the Value and + // Expression fields should only be printed inline and so do not use a slot. CreateMetadataSlot(DPV->getVariable()); if (DPV->isDbgAssign()) CreateMetadataSlot(DPV->getAssignID()); @@ -2703,6 +2706,7 @@ public: void printDPValue(const DPValue &DPI); void printDPLabel(const DPLabel &DPL); void printDbgRecord(const DbgRecord &DPI); + void printDbgRecordLine(const DbgRecord &DPI); void printUseListOrder(const Value *V, const std::vector<unsigned> &Shuffle); void printUseLists(const Function *F); @@ -3885,9 +3889,6 @@ void AssemblyWriter::printTypeIdentities() { /// printFunction - Print all aspects of a function. void AssemblyWriter::printFunction(const Function *F) { - bool ConvertBack = F->IsNewDbgInfoFormat; - if (ConvertBack) - const_cast<Function *>(F)->convertFromNewDbgValues(); if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out); if (F->isMaterializable()) @@ -4030,8 +4031,6 @@ void AssemblyWriter::printFunction(const Function *F) { Out << "}\n"; } - if (ConvertBack) - const_cast<Function *>(F)->convertToNewDbgValues(); Machine.purgeFunction(); } @@ -4098,6 +4097,8 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) { // Output all of the instructions in the basic block... for (const Instruction &I : *BB) { + for (const DbgRecord &DR : I.getDbgValueRange()) + printDbgRecordLine(DR); printInstructionLine(I); } @@ -4611,12 +4612,10 @@ void AssemblyWriter::printDbgRecord(const DbgRecord &DR) { llvm_unreachable("Unexpected DbgRecord kind"); } -void AssemblyWriter::printDPValue(const DPValue &Value) { - // There's no formal representation of a DPValue -- print purely as a - // debugging aid. - Out << " DPValue "; - - switch (Value.getType()) { +void AssemblyWriter::printDPValue(const DPValue &DPV) { + auto WriterCtx = getContext(); + Out << "#dbg_"; + switch (DPV.getType()) { case DPValue::LocationType::Value: Out << "value"; break; @@ -4629,35 +4628,39 @@ void AssemblyWriter::printDPValue(const DPValue &Value) { default: llvm_unreachable("Tried to print a DPValue with an invalid LocationType!"); } - Out << " { "; - auto WriterCtx = getContext(); - WriteAsOperandInternal(Out, Value.getRawLocation(), WriterCtx, true); + Out << "("; + WriteAsOperandInternal(Out, DPV.getRawLocation(), WriterCtx, true); Out << ", "; - WriteAsOperandInternal(Out, Value.getVariable(), WriterCtx, true); + WriteAsOperandInternal(Out, DPV.getVariable(), WriterCtx, true); Out << ", "; - WriteAsOperandInternal(Out, Value.getExpression(), WriterCtx, true); + WriteAsOperandInternal(Out, DPV.getExpression(), WriterCtx, true); Out << ", "; - if (Value.isDbgAssign()) { - WriteAsOperandInternal(Out, Value.getAssignID(), WriterCtx, true); + if (DPV.isDbgAssign()) { + WriteAsOperandInternal(Out, DPV.getAssignID(), WriterCtx, true); Out << ", "; - WriteAsOperandInternal(Out, Value.getRawAddress(), WriterCtx, true); + WriteAsOperandInternal(Out, DPV.getRawAddress(), WriterCtx, true); Out << ", "; - WriteAsOperandInternal(Out, Value.getAddressExpression(), WriterCtx, true); + WriteAsOperandInternal(Out, DPV.getAddressExpression(), WriterCtx, true); Out << ", "; } - WriteAsOperandInternal(Out, Value.getDebugLoc().get(), WriterCtx, true); - Out << " marker @" << Value.getMarker(); - Out << " }"; + WriteAsOperandInternal(Out, DPV.getDebugLoc().getAsMDNode(), WriterCtx, true); + Out << ")"; +} + +/// printDbgRecordLine - Print a DbgRecord with indentation and a newline +/// character. +void AssemblyWriter::printDbgRecordLine(const DbgRecord &DR) { + // Print lengthier indentation to bring out-of-line with instructions. + Out << " "; + printDbgRecord(DR); + Out << '\n'; } void AssemblyWriter::printDPLabel(const DPLabel &Label) { - // There's no formal representation of a DPLabel -- print purely as - // a debugging aid. - Out << " DPLabel { "; auto WriterCtx = getContext(); + Out << "#dbg_label("; WriteAsOperandInternal(Out, Label.getLabel(), WriterCtx, true); - Out << " marker @" << Label.getMarker(); - Out << " }"; + Out << ")"; } void AssemblyWriter::printMetadataAttachments( @@ -4805,19 +4808,11 @@ void BasicBlock::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW, void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder, bool IsForDebug) const { - // RemoveDIs: always print with debug-info in intrinsic format. - bool ConvertAfter = IsNewDbgInfoFormat; - if (IsNewDbgInfoFormat) - const_cast<Module *>(this)->convertFromNewDbgValues(); - SlotTracker SlotTable(this); formatted_raw_ostream OS(ROS); AssemblyWriter W(OS, SlotTable, this, AAW, IsForDebug, ShouldPreserveUseListOrder); W.printModule(this); - - if (ConvertAfter) - const_cast<Module *>(this)->convertToNewDbgValues(); } void NamedMDNode::print(raw_ostream &ROS, bool IsForDebug) const { @@ -4908,8 +4903,6 @@ void DPValue::print(raw_ostream &ROS, bool IsForDebug) const { void DPMarker::print(raw_ostream &ROS, ModuleSlotTracker &MST, bool IsForDebug) const { - // There's no formal representation of a DPMarker -- print purely as a - // debugging aid. formatted_raw_ostream OS(ROS); SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr)); SlotTracker &SlotTable = @@ -4931,8 +4924,6 @@ void DPLabel::print(raw_ostream &ROS, bool IsForDebug) const { void DPValue::print(raw_ostream &ROS, ModuleSlotTracker &MST, bool IsForDebug) const { - // There's no formal representation of a DPValue -- print purely as a - // debugging aid. formatted_raw_ostream OS(ROS); SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr)); SlotTracker &SlotTable = @@ -4950,8 +4941,6 @@ void DPValue::print(raw_ostream &ROS, ModuleSlotTracker &MST, void DPLabel::print(raw_ostream &ROS, ModuleSlotTracker &MST, bool IsForDebug) const { - // There's no formal representation of a DbgLabelRecord -- print purely as - // a debugging aid. formatted_raw_ostream OS(ROS); SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr)); SlotTracker &SlotTable = diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp index 6ea876f..c110c4c 100644 --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -61,10 +61,6 @@ DPMarker *BasicBlock::createMarker(InstListType::iterator It) { } void BasicBlock::convertToNewDbgValues() { - // Is the command line option set? - if (!UseNewDbgInfoFormat) - return; - IsNewDbgInfoFormat = true; // Iterate over all instructions in the instruction list, collecting dbg.value diff --git a/llvm/lib/IR/IRPrintingPasses.cpp b/llvm/lib/IR/IRPrintingPasses.cpp index b19210e..84fb8e6 100644 --- a/llvm/lib/IR/IRPrintingPasses.cpp +++ b/llvm/lib/IR/IRPrintingPasses.cpp @@ -23,6 +23,11 @@ using namespace llvm; +cl::opt<bool> WriteNewDbgInfoFormat( + "write-experimental-debuginfo", + cl::desc("Write debug info in the new non-intrinsic format"), + cl::init(false)); + namespace { class PrintModulePassWrapper : public ModulePass { @@ -39,11 +44,14 @@ public: ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {} bool runOnModule(Module &M) override { - // RemoveDIs: there's no textual representation of the DPValue debug-info, - // convert to dbg.values before writing out. - bool IsNewDbgInfoFormat = M.IsNewDbgInfoFormat; - if (IsNewDbgInfoFormat) - M.convertFromNewDbgValues(); + // RemoveDIs: Regardless of the format we've processed this module in, use + // `WriteNewDbgInfoFormat` to determine which format we use to write it. + ScopedDbgInfoFormatSetter FormatSetter(M, WriteNewDbgInfoFormat); + // Remove intrinsic declarations when printing in the new format. + // TODO: Move this into Module::setIsNewDbgInfoFormat when we're ready to + // update test output. + if (WriteNewDbgInfoFormat) + M.removeDebugIntrinsicDeclarations(); if (llvm::isFunctionInPrintList("*")) { if (!Banner.empty()) @@ -62,9 +70,6 @@ public: } } - if (IsNewDbgInfoFormat) - M.convertToNewDbgValues(); - return false; } @@ -87,11 +92,9 @@ public: // This pass just prints a banner followed by the function as it's processed. bool runOnFunction(Function &F) override { - // RemoveDIs: there's no textual representation of the DPValue debug-info, - // convert to dbg.values before writing out. - bool IsNewDbgInfoFormat = F.IsNewDbgInfoFormat; - if (IsNewDbgInfoFormat) - F.convertFromNewDbgValues(); + // RemoveDIs: Regardless of the format we've processed this function in, use + // `WriteNewDbgInfoFormat` to determine which format we use to write it. + ScopedDbgInfoFormatSetter FormatSetter(F, WriteNewDbgInfoFormat); if (isFunctionInPrintList(F.getName())) { if (forcePrintModuleIR()) @@ -101,9 +104,6 @@ public: OS << Banner << '\n' << static_cast<Value &>(F); } - if (IsNewDbgInfoFormat) - F.convertToNewDbgValues(); - return false; } diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 1946db2..a8696ed 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -85,6 +85,28 @@ Module::~Module() { IFuncList.clear(); } +void Module::removeDebugIntrinsicDeclarations() { + auto *DeclareIntrinsicFn = + Intrinsic::getDeclaration(this, Intrinsic::dbg_declare); + assert((!isMaterialized() || DeclareIntrinsicFn->hasZeroLiveUses()) && + "Debug declare intrinsic should have had uses removed."); + DeclareIntrinsicFn->eraseFromParent(); + auto *ValueIntrinsicFn = + Intrinsic::getDeclaration(this, Intrinsic::dbg_value); + assert((!isMaterialized() || ValueIntrinsicFn->hasZeroLiveUses()) && + "Debug value intrinsic should have had uses removed."); + ValueIntrinsicFn->eraseFromParent(); + auto *AssignIntrinsicFn = + Intrinsic::getDeclaration(this, Intrinsic::dbg_assign); + assert((!isMaterialized() || AssignIntrinsicFn->hasZeroLiveUses()) && + "Debug assign intrinsic should have had uses removed."); + AssignIntrinsicFn->eraseFromParent(); + auto *LabelntrinsicFn = Intrinsic::getDeclaration(this, Intrinsic::dbg_label); + assert((!isMaterialized() || LabelntrinsicFn->hasZeroLiveUses()) && + "Debug label intrinsic should have had uses removed."); + LabelntrinsicFn->eraseFromParent(); +} + std::unique_ptr<RandomNumberGenerator> Module::createRNG(const StringRef Name) const { SmallString<32> Salt(Name); diff --git a/llvm/lib/IRPrinter/IRPrintingPasses.cpp b/llvm/lib/IRPrinter/IRPrintingPasses.cpp index 52b242b..026fa4d 100644 --- a/llvm/lib/IRPrinter/IRPrintingPasses.cpp +++ b/llvm/lib/IRPrinter/IRPrintingPasses.cpp @@ -22,6 +22,8 @@ using namespace llvm; +extern cl::opt<bool> WriteNewDbgInfoFormat; + PrintModulePass::PrintModulePass() : OS(dbgs()) {} PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner, bool ShouldPreserveUseListOrder, @@ -31,11 +33,14 @@ PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner, EmitSummaryIndex(EmitSummaryIndex) {} PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &AM) { - // RemoveDIs: there's no textual representation of the DPValue debug-info, - // convert to dbg.values before writing out. - bool ShouldConvert = M.IsNewDbgInfoFormat; - if (ShouldConvert) - M.convertFromNewDbgValues(); + // RemoveDIs: Regardless of the format we've processed this module in, use + // `WriteNewDbgInfoFormat` to determine which format we use to write it. + ScopedDbgInfoFormatSetter FormatSetter(M, WriteNewDbgInfoFormat); + // Remove intrinsic declarations when printing in the new format. + // TODO: Move this into Module::setIsNewDbgInfoFormat when we're ready to + // update test output. + if (WriteNewDbgInfoFormat) + M.removeDebugIntrinsicDeclarations(); if (llvm::isFunctionInPrintList("*")) { if (!Banner.empty()) @@ -63,9 +68,6 @@ PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &AM) { Index->print(OS); } - if (ShouldConvert) - M.convertToNewDbgValues(); - return PreservedAnalyses::all(); } @@ -75,11 +77,9 @@ PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, const std::string &Banner) PreservedAnalyses PrintFunctionPass::run(Function &F, FunctionAnalysisManager &) { - // RemoveDIs: there's no textual representation of the DPValue debug-info, - // convert to dbg.values before writing out. - bool ShouldConvert = F.IsNewDbgInfoFormat; - if (ShouldConvert) - F.convertFromNewDbgValues(); + // RemoveDIs: Regardless of the format we've processed this function in, use + // `WriteNewDbgInfoFormat` to determine which format we use to write it. + ScopedDbgInfoFormatSetter FormatSetter(F, WriteNewDbgInfoFormat); if (isFunctionInPrintList(F.getName())) { if (forcePrintModuleIR()) @@ -88,8 +88,5 @@ PreservedAnalyses PrintFunctionPass::run(Function &F, OS << Banner << '\n' << static_cast<Value &>(F); } - if (ShouldConvert) - F.convertToNewDbgValues(); - return PreservedAnalyses::all(); } diff --git a/llvm/test/DebugInfo/Generic/inline-alloca-ordering.ll b/llvm/test/DebugInfo/Generic/inline-alloca-ordering.ll index 9ff3d80..9f401ce 100644 --- a/llvm/test/DebugInfo/Generic/inline-alloca-ordering.ll +++ b/llvm/test/DebugInfo/Generic/inline-alloca-ordering.ll @@ -15,8 +15,6 @@ ;; doesn't transfer the dbg.value to the entry block. This needs Special ;; Handling once we get rid of debug-intrinsics. -; CHECK: declare void @llvm.dbg.value(metadata, - ; CHECK: define i32 @bar() ; CHECK-NEXT: %1 = alloca [65 x i32], align 16 ; CHECK-NEXT: call void @ext() @@ -24,9 +22,10 @@ ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 0, metadata !10, metadata !DIExpression()), !dbg !12 ; CHECK-NEXT: call void @init(ptr %1) +; CHECK: declare void @llvm.dbg.value(metadata, + declare void @ext() declare void @init(ptr) -declare void @llvm.dbg.value(metadata, metadata, metadata) define internal i32 @foo() !dbg !4 { %1 = alloca [65 x i32], align 16 @@ -42,6 +41,8 @@ define i32 @bar() !dbg !16 { ret i32 %1 } +declare void @llvm.dbg.value(metadata, metadata, metadata) + !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!8, !9} !llvm.ident = !{!10} diff --git a/llvm/test/DebugInfo/Generic/inline-dbg-values.ll b/llvm/test/DebugInfo/Generic/inline-dbg-values.ll index 7d580d6..b0390b9 100644 --- a/llvm/test/DebugInfo/Generic/inline-dbg-values.ll +++ b/llvm/test/DebugInfo/Generic/inline-dbg-values.ll @@ -7,8 +7,6 @@ ;; ;; test should be inlined into test2 -; CHECK: declare void @llvm.dbg.value(metadata, - ; CHECK: define i32 @test2 ; CHECK-NEXT: entry: ; CHECK: %k.addr.i = alloca i32, align 4 @@ -47,6 +45,8 @@ ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 1, metadata ![[KVAR]], metadata !DIExpression()), !dbg ![[KLINE]] ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 1, metadata ![[K2VAR]], metadata !DIExpression()), !dbg ![[GLINE]] ; +; CHECK: declare void @llvm.dbg.value(metadata, +; ;; Test that the metadata maps onto the correct things, and that the DILocations ;; attached to the intrinsics have been inlined. ; @@ -100,8 +100,6 @@ return: ; preds = %if.end, %if.then ret i32 %3, !dbg !20 } -declare void @llvm.dbg.value(metadata, metadata, metadata) #1 - declare i32 @_Z8test_exti(i32) define i32 @test2(i32 %foo, i32 %bar) !dbg !10 { @@ -118,6 +116,8 @@ try.cont: ; preds = %catch, %invoke.cont ret i32 0, !dbg !30 } +declare void @llvm.dbg.value(metadata, metadata, metadata) #1 + !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!31} diff --git a/llvm/test/DebugInfo/dpvalue-print-nocrash.ll b/llvm/test/DebugInfo/dpvalue-print-nocrash.ll index 9f120af..0a618c6 100755 --- a/llvm/test/DebugInfo/dpvalue-print-nocrash.ll +++ b/llvm/test/DebugInfo/dpvalue-print-nocrash.ll @@ -2,8 +2,7 @@ ; RUN: opt -passes="instcombine" -debug %s -o /dev/null 2>&1 | FileCheck %s ; REQUIRES: asserts -; CHECK: CLONE: DPValue value { -; CHECK-SAME: marker @0x0 +; CHECK: CLONE: #dbg_value( define ptr @func_10(i32 %p_11) { entry: diff --git a/llvm/test/DebugInfo/print-non-instruction-debug-info.ll b/llvm/test/DebugInfo/print-non-instruction-debug-info.ll new file mode 100644 index 0000000..f8271df --- /dev/null +++ b/llvm/test/DebugInfo/print-non-instruction-debug-info.ll @@ -0,0 +1,86 @@ +;; Test that we can write in the new debug info format. +; RUN: opt --passes=verify -S --experimental-debuginfo-iterators=false --write-experimental-debuginfo=false < %s \ +; RUN: | FileCheck %s --check-prefixes=CHECK,OLDDBG --implicit-check-not=llvm.dbg +; RUN: opt --passes=verify -S --experimental-debuginfo-iterators=false --write-experimental-debuginfo=true < %s \ +; RUN: | FileCheck %s --check-prefixes=CHECK,NEWDBG --implicit-check-not=llvm.dbg + +;; Test also that the new flag is independent of the flag that enables use of +;; these non-instruction debug info during LLVM passes. +; RUN: opt --passes=verify -S --experimental-debuginfo-iterators=true --write-experimental-debuginfo=false < %s \ +; RUN: | FileCheck %s --check-prefixes=CHECK,OLDDBG --implicit-check-not=llvm.dbg +; RUN: opt --passes=verify -S --experimental-debuginfo-iterators=true --write-experimental-debuginfo=true < %s \ +; RUN: | FileCheck %s --check-prefixes=CHECK,NEWDBG --implicit-check-not=llvm.dbg + +; CHECK: @f(i32 %[[VAL_A:[0-9a-zA-Z]+]]) +; CHECK-NEXT: entry: +; OLDDBG-NEXT: call void @llvm.dbg.value(metadata i32 %[[VAL_A]], metadata ![[VAR_A:[0-9]+]], metadata !DIExpression()), !dbg ![[LOC_1:[0-9]+]] +; NEWDBG-NEXT: {{^}} #dbg_value(i32 %[[VAL_A]], ![[VAR_A:[0-9]+]], !DIExpression(), ![[LOC_1:[0-9]+]]) +; CHECK-NEXT: {{^}} %[[VAL_B:[0-9a-zA-Z]+]] = alloca +; OLDDBG-NEXT: call void @llvm.dbg.declare(metadata ptr %[[VAL_B]], metadata ![[VAR_B:[0-9]+]], metadata !DIExpression()), !dbg ![[LOC_2:[0-9]+]] +; NEWDBG-NEXT: {{^}} #dbg_declare(ptr %[[VAL_B]], ![[VAR_B:[0-9]+]], !DIExpression(), ![[LOC_2:[0-9]+]]) +; CHECK-NEXT: {{^}} %[[VAL_ADD:[0-9a-zA-Z]+]] = add i32 %[[VAL_A]], 5 +; OLDDBG-NEXT: call void @llvm.dbg.value(metadata !DIArgList(i32 %[[VAL_A]], i32 %[[VAL_ADD]]), metadata ![[VAR_A]], metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus)), !dbg ![[LOC_3:[0-9]+]] +; NEWDBG-NEXT: {{^}} #dbg_value(!DIArgList(i32 %[[VAL_A]], i32 %[[VAL_ADD]]), ![[VAR_A]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), ![[LOC_3:[0-9]+]]) +; OLDDBG-NEXT: call void @llvm.dbg.label(metadata ![[LABEL_ID:[0-9]+]]) +; NEWDBG-NEXT: {{^}} #dbg_label(![[LABEL_ID:[0-9]+]]) +; CHECK-NEXT: {{^}} store i32 %[[VAL_ADD]]{{.+}}, !DIAssignID ![[ASSIGNID:[0-9]+]] +; OLDDBG-NEXT: call void @llvm.dbg.assign(metadata i32 %[[VAL_ADD]], metadata ![[VAR_B]], metadata !DIExpression(), metadata ![[ASSIGNID]], metadata ptr %[[VAL_B]], metadata !DIExpression()), !dbg ![[LOC_4:[0-9]+]] +; NEWDBG-NEXT: {{^}} #dbg_assign(i32 %[[VAL_ADD]], ![[VAR_B]], !DIExpression(), ![[ASSIGNID]], ptr %[[VAL_B]], !DIExpression(), ![[LOC_4:[0-9]+]]) +; CHECK-NEXT: {{^}} ret i32 + +; OLDDBG-DAG: declare void @llvm.dbg.value +; OLDDBG-DAG: declare void @llvm.dbg.declare +; OLDDBG-DAG: declare void @llvm.dbg.assign + +; CHECK-DAG: llvm.dbg.cu +; CHECK-DAG: ![[VAR_A]] = !DILocalVariable(name: "a" +; CHECK-DAG: ![[VAR_B]] = !DILocalVariable(name: "b" +; CHECK-DAG: ![[LOC_1]] = !DILocation(line: 3, column: 15 +; CHECK-DAG: ![[LOC_2]] = !DILocation(line: 3, column: 20 +; CHECK-DAG: ![[LOC_3]] = !DILocation(line: 3, column: 25 +; CHECK-DAG: ![[LOC_4]] = !DILocation(line: 3, column: 30 +; CHECK-DAG: ![[LABEL_ID]] = !DILabel( + +define dso_local i32 @f(i32 %a) !dbg !7 { +entry: + call void @llvm.dbg.value(metadata i32 %a, metadata !20, metadata !DIExpression()), !dbg !30 + %b = alloca i32, !dbg !30, !DIAssignID !40 + call void @llvm.dbg.declare(metadata ptr %b, metadata !21, metadata !DIExpression()), !dbg !31 + %add = add i32 %a, 5, !dbg !31 + call void @llvm.dbg.value(metadata !DIArgList(i32 %a, i32 %add), metadata !20, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus)), !dbg !32 + call void @llvm.dbg.label(metadata !50), !dbg !32 + store i32 %add, ptr %b, !dbg !32, !DIAssignID !40 + call void @llvm.dbg.assign(metadata i32 %add, metadata !21, metadata !DIExpression(), metadata !40, metadata ptr %b, metadata !DIExpression()), !dbg !33 + ret i32 %add, !dbg !33 + +} + +declare void @llvm.dbg.value(metadata, metadata, metadata) +declare void @llvm.dbg.declare(metadata, metadata, metadata) +declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) +declare void @llvm.dbg.label(metadata) + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 18.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "print.c", directory: "/tmp") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 5} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{!"clang version 18.0.0"} +!7 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !13) +!8 = !DISubroutineType(types: !9) +!9 = !{!12, !12} +!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!13 = !{!20, !21} +!20 = !DILocalVariable(name: "a", arg: 1, scope: !7, file: !1, line: 3, type: !12) +!21 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 3, type: !12) +!30 = !DILocation(line: 3, column: 15, scope: !7) +!31 = !DILocation(line: 3, column: 20, scope: !7) +!32 = !DILocation(line: 3, column: 25, scope: !7) +!33 = !DILocation(line: 3, column: 30, scope: !7) +!40 = distinct !DIAssignID() +!50 = !DILabel(scope: !7, name: "label", file: !1, line: 3) diff --git a/llvm/test/Transforms/Attributor/ArgumentPromotion/pr33641_remove_arg_dbgvalue.ll b/llvm/test/Transforms/Attributor/ArgumentPromotion/pr33641_remove_arg_dbgvalue.ll index 83226e5..e0777f9 100644 --- a/llvm/test/Transforms/Attributor/ArgumentPromotion/pr33641_remove_arg_dbgvalue.ll +++ b/llvm/test/Transforms/Attributor/ArgumentPromotion/pr33641_remove_arg_dbgvalue.ll @@ -30,8 +30,7 @@ define internal void @bar(%p_t %p) { ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) ; CGSCC-LABEL: define {{[^@]+}}@bar ; CGSCC-SAME: (ptr nocapture nofree readnone [[P:%.*]]) #[[ATTR0]] { -; CGSCC-NEXT: call void @llvm.dbg.value(metadata ptr [[P]], metadata [[META3:![0-9]+]], metadata !DIExpression()) -; CGSCC-SAME: !dbg [[DBG5:![0-9]+]] +; CGSCC-NEXT: tail call void @llvm.dbg.value(metadata ptr [[P]], metadata [[META3:![0-9]+]], metadata !DIExpression()), !dbg [[DBG5:![0-9]+]] ; CGSCC-NEXT: ret void ; call void @llvm.dbg.value(metadata %p_t %p, metadata !4, metadata !5), !dbg !6 @@ -52,21 +51,20 @@ declare void @llvm.dbg.value(metadata, metadata, metadata) !6 = !DILocation(line: 1, column: 1, scope: !3) ;. ; TUNIT: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) } -; TUNIT: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } ;. ; CGSCC: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) } ; CGSCC: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } ;. -; TUNIT: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug) -; TUNIT: [[META1:![0-9]+]] = !DIFile(filename: "test.c", directory: "") +; TUNIT: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug) +; TUNIT: [[META1]] = !DIFile(filename: "test.c", directory: "") ; TUNIT: [[META2:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3} ;. -; CGSCC: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug) -; CGSCC: [[META1:![0-9]+]] = !DIFile(filename: "test.c", directory: "") +; CGSCC: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug) +; CGSCC: [[META1]] = !DIFile(filename: "test.c", directory: "") ; CGSCC: [[META2:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3} -; CGSCC: [[META3]] = !DILocalVariable(name: "p", scope: !4) -; CGSCC: [[META4:![0-9]+]] = distinct !DISubprogram(name: "bar", scope: null, spFlags: DISPFlagDefinition, unit: !0) -; CGSCC: [[DBG5]] = !DILocation(line: 1, column: 1, scope: !4) +; CGSCC: [[META3]] = !DILocalVariable(name: "p", scope: [[META4:![0-9]+]]) +; CGSCC: [[META4]] = distinct !DISubprogram(name: "bar", scope: null, spFlags: DISPFlagDefinition, unit: [[META0]]) +; CGSCC: [[DBG5]] = !DILocation(line: 1, column: 1, scope: [[META4]]) ;. ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: ; TUNIT: {{.*}} diff --git a/llvm/test/Transforms/DeadArgElim/2010-04-30-DbgInfo.ll b/llvm/test/Transforms/DeadArgElim/2010-04-30-DbgInfo.ll index 0dee72f..5e49437 100644 --- a/llvm/test/Transforms/DeadArgElim/2010-04-30-DbgInfo.ll +++ b/llvm/test/Transforms/DeadArgElim/2010-04-30-DbgInfo.ll @@ -8,12 +8,21 @@ define ptr @vfs_addname(ptr %name, i32 %len, i32 %hash, i32 %flags) nounwind ssp !dbg !1 { ; +; CHECK-LABEL: define {{[^@]+}}@vfs_addname +; CHECK-SAME: (ptr [[NAME:%.*]], i32 [[LEN:%.*]], i32 [[HASH:%.*]], i32 [[FLAGS:%.*]]) #[[ATTR0:[0-9]+]] !dbg [[DBG4:![0-9]+]] { +; CHECK-NEXT: entry: +; CHECK-NEXT: tail call void @llvm.dbg.value(metadata ptr [[NAME]], metadata [[META11:![0-9]+]], metadata !DIExpression()), !dbg [[DBG12:![0-9]+]] +; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 [[LEN]], metadata [[META13:![0-9]+]], metadata !DIExpression()), !dbg [[DBG12]] +; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 [[HASH]], metadata [[META14:![0-9]+]], metadata !DIExpression()), !dbg [[DBG12]] +; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 [[FLAGS]], metadata [[META15:![0-9]+]], metadata !DIExpression()), !dbg [[DBG12]] +; CHECK-NEXT: [[TMP0:%.*]] = call fastcc ptr @add_name_internal(ptr [[NAME]], i32 [[HASH]]) #[[ATTR3:[0-9]+]], !dbg [[DBG16:![0-9]+]] +; CHECK-NEXT: ret ptr [[TMP0]], !dbg [[DBG16]] +; entry: call void @llvm.dbg.value(metadata ptr %name, metadata !0, metadata !DIExpression()), !dbg !DILocation(scope: !1) call void @llvm.dbg.value(metadata i32 %len, metadata !10, metadata !DIExpression()), !dbg !DILocation(scope: !1) call void @llvm.dbg.value(metadata i32 %hash, metadata !11, metadata !DIExpression()), !dbg !DILocation(scope: !1) call void @llvm.dbg.value(metadata i32 %flags, metadata !12, metadata !DIExpression()), !dbg !DILocation(scope: !1) -; CHECK: call fastcc ptr @add_name_internal(ptr %name, i32 %hash) [[NUW:#[0-9]+]], !dbg !{{[0-9]+}} %0 = call fastcc ptr @add_name_internal(ptr %name, i32 %len, i32 %hash, i8 zeroext 0, i32 %flags) nounwind, !dbg !13 ; <ptr> [#uses=1] ret ptr %0, !dbg !13 } @@ -22,6 +31,24 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone define internal fastcc ptr @add_name_internal(ptr %name, i32 %len, i32 %hash, i8 zeroext %extra, i32 %flags) noinline nounwind ssp !dbg !16 { ; +; CHECK-LABEL: define {{[^@]+}}@add_name_internal +; CHECK-SAME: (ptr [[NAME:%.*]], i32 [[HASH:%.*]]) #[[ATTR1:[0-9]+]] !dbg [[DBG18:![0-9]+]] { +; CHECK-NEXT: entry: +; CHECK-NEXT: tail call void @llvm.dbg.value(metadata ptr [[NAME]], metadata [[META22:![0-9]+]], metadata !DIExpression()), !dbg [[DBG23:![0-9]+]] +; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 poison, metadata [[META24:![0-9]+]], metadata !DIExpression()), !dbg [[DBG23]] +; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 [[HASH]], metadata [[META25:![0-9]+]], metadata !DIExpression()), !dbg [[DBG23]] +; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i8 poison, metadata [[META26:![0-9]+]], metadata !DIExpression()), !dbg [[DBG23]] +; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 poison, metadata [[META27:![0-9]+]], metadata !DIExpression()), !dbg [[DBG23]] +; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[HASH]], 0, !dbg [[DBG28:![0-9]+]] +; CHECK-NEXT: br i1 [[TMP0]], label [[BB:%.*]], label [[BB1:%.*]], !dbg [[DBG28]] +; CHECK: bb: +; CHECK-NEXT: br label [[BB2:%.*]], !dbg [[DBG30:![0-9]+]] +; CHECK: bb1: +; CHECK-NEXT: br label [[BB2]], !dbg [[DBG31:![0-9]+]] +; CHECK: bb2: +; CHECK-NEXT: [[DOT0:%.*]] = phi ptr [ @.str, [[BB]] ], [ [[NAME]], [[BB1]] ] +; CHECK-NEXT: ret ptr [[DOT0]], !dbg [[DBG31]] +; entry: call void @llvm.dbg.value(metadata ptr %name, metadata !15, metadata !DIExpression()), !dbg !DILocation(scope: !16) call void @llvm.dbg.value(metadata i32 %len, metadata !20, metadata !DIExpression()), !dbg !DILocation(scope: !16) @@ -47,7 +74,6 @@ declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone ; CHECK: attributes #0 = { nounwind ssp } ; CHECK: attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } ; CHECK: attributes #2 = { noinline nounwind ssp } -; CHECK: attributes [[NUW]] = { nounwind } !llvm.dbg.cu = !{!3} !llvm.module.flags = !{!30} @@ -68,9 +94,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone !14 = distinct !DILexicalBlock(line: 12, column: 0, file: !28, scope: !1) !15 = !DILocalVariable(name: "name", line: 17, arg: 1, scope: !16, file: !2, type: !6) ; CHECK: !DISubprogram(name: "add_name_internal" -; CHECK-SAME: type: ![[MD:[0-9]+]] !16 = distinct !DISubprogram(name: "add_name_internal", linkageName: "add_name_internal", line: 22, isLocal: true, isDefinition: true, virtualIndex: 6, isOptimized: false, unit: !3, file: !28, scope: !2, type: !17) -; CHECK: ![[MD]] = !DISubroutineType(cc: DW_CC_nocall, types: !{{[0-9]+}}) !17 = !DISubroutineType(types: !18) !18 = !{!6, !6, !9, !9, !19, !9} !19 = !DIBasicType(tag: DW_TAG_base_type, name: "unsigned char", size: 8, align: 8, encoding: DW_ATE_unsigned_char) diff --git a/llvm/test/Transforms/IROutliner/outlining-debug-statements.ll b/llvm/test/Transforms/IROutliner/outlining-debug-statements.ll index f932788..bf846c3 100644 --- a/llvm/test/Transforms/IROutliner/outlining-debug-statements.ll +++ b/llvm/test/Transforms/IROutliner/outlining-debug-statements.ll @@ -51,14 +51,7 @@ entry: ret void } -; CHECK: define internal void @outlined_ir_func_0(ptr [[ARG0:%.*]], ptr [[ARG1:%.*]], ptr [[ARG2:%.*]]) #1 { ; CHECK: entry_to_outline: -; CHECK-NEXT: store i32 2, ptr [[ARG0]], align 4 -; CHECK-NEXT: store i32 3, ptr [[ARG1]], align 4 -; CHECK-NEXT: store i32 4, ptr [[ARG2]], align 4 -; CHECK-NEXT: [[AL:%.*]] = load i32, ptr [[ARG0]], align 4 -; CHECK-NEXT: [[BL:%.*]] = load i32, ptr [[ARG1]], align 4 -; CHECK-NEXT: [[CL:%.*]] = load i32, ptr [[ARG2]], align 4 !0 = !DIFile(filename: "foo.c", directory: "/tmp") !1 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) |