Skip to content

Commit dc06d75

Browse files
committed
Revert "[RemoveDIs] Print non-intrinsic debug info in textual IR output (#79281)"
Reverted due to failures on buildbots, where a new cl flag was placed in the wrong file, resulting in link errors. https://lab.llvm.org/buildbot/#/builders/198/builds/8548 This reverts commit 0b39825.
1 parent f1bb88b commit dc06d75

20 files changed

+146
-272
lines changed

Diff for: llvm/include/llvm/IR/Module.h

-14
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,11 @@ class LLVM_EXTERNAL_VISIBILITY Module {
218218
/// \ref BasicBlock.
219219
bool IsNewDbgInfoFormat;
220220

221-
/// Used when converting this module to the new debug info format; removes all
222-
/// declarations of debug intrinsics that are replaced by non-intrinsic
223-
/// records in the new format.
224-
void removeDebugIntrinsicDeclarations();
225-
226221
/// \see BasicBlock::convertToNewDbgValues.
227222
void convertToNewDbgValues() {
228223
for (auto &F : *this) {
229224
F.convertToNewDbgValues();
230225
}
231-
// Remove the declarations of the old debug intrinsics, if any exist.
232-
removeDebugIntrinsicDeclarations();
233226
IsNewDbgInfoFormat = true;
234227
}
235228

@@ -241,13 +234,6 @@ class LLVM_EXTERNAL_VISIBILITY Module {
241234
IsNewDbgInfoFormat = false;
242235
}
243236

244-
void setIsNewDbgInfoFormat(bool UseNewFormat) {
245-
if (UseNewFormat && !IsNewDbgInfoFormat)
246-
convertToNewDbgValues();
247-
else if (!UseNewFormat && IsNewDbgInfoFormat)
248-
convertFromNewDbgValues();
249-
}
250-
251237
/// The Module constructor. Note that there is no default constructor. You
252238
/// must provide a name for the module upon construction.
253239
explicit Module(StringRef ModuleID, LLVMContext& C);

Diff for: llvm/include/llvm/IR/PrintPasses.h

-19
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,6 @@ std::string doSystemDiff(StringRef Before, StringRef After,
7878
StringRef OldLineFormat, StringRef NewLineFormat,
7979
StringRef UnchangedLineFormat);
8080

81-
/// Used to temporarily set the debug info format of a function, module, or
82-
/// basic block for the duration of this object's lifetime, after which the
83-
/// prior state will be restored.
84-
template <typename T> class ScopedDbgInfoFormatSetter {
85-
T &Obj;
86-
bool OldState;
87-
88-
public:
89-
ScopedDbgInfoFormatSetter(T &Obj, bool NewState)
90-
: Obj(Obj), OldState(Obj.IsNewDbgInfoFormat) {
91-
Obj.setIsNewDbgInfoFormat(NewState);
92-
}
93-
~ScopedDbgInfoFormatSetter() { Obj.setIsNewDbgInfoFormat(OldState); }
94-
};
95-
96-
template <typename T>
97-
ScopedDbgInfoFormatSetter(T &Obj, bool NewState)
98-
-> ScopedDbgInfoFormatSetter<T>;
99-
10081
} // namespace llvm
10182

10283
#endif // LLVM_IR_PRINTPASSES_H

Diff for: llvm/lib/IR/AsmWriter.cpp

+43-32
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ class SlotTracker : public AbstractSlotTrackerStorage {
861861
/// Add all of the metadata from an instruction.
862862
void processInstructionMetadata(const Instruction &I);
863863

864-
/// Add all of the metadata from a DbgRecord.
864+
/// Add all of the metadata from an instruction.
865865
void processDbgRecordMetadata(const DbgRecord &DPV);
866866
};
867867

@@ -1140,9 +1140,6 @@ void SlotTracker::processFunctionMetadata(const Function &F) {
11401140

11411141
void SlotTracker::processDbgRecordMetadata(const DbgRecord &DR) {
11421142
if (const DPValue *DPV = dyn_cast<const DPValue>(&DR)) {
1143-
// Process metadata used by DbgRecords; we only specifically care about the
1144-
// DILocalVariable, DILocation, and DIAssignID fields, as the Value and
1145-
// Expression fields should only be printed inline and so do not use a slot.
11461143
CreateMetadataSlot(DPV->getVariable());
11471144
if (DPV->isDbgAssign())
11481145
CreateMetadataSlot(DPV->getAssignID());
@@ -2706,7 +2703,6 @@ class AssemblyWriter {
27062703
void printDPValue(const DPValue &DPI);
27072704
void printDPLabel(const DPLabel &DPL);
27082705
void printDbgRecord(const DbgRecord &DPI);
2709-
void printDbgRecordLine(const DbgRecord &DPI);
27102706

27112707
void printUseListOrder(const Value *V, const std::vector<unsigned> &Shuffle);
27122708
void printUseLists(const Function *F);
@@ -3889,6 +3885,9 @@ void AssemblyWriter::printTypeIdentities() {
38893885

38903886
/// printFunction - Print all aspects of a function.
38913887
void AssemblyWriter::printFunction(const Function *F) {
3888+
bool ConvertBack = F->IsNewDbgInfoFormat;
3889+
if (ConvertBack)
3890+
const_cast<Function *>(F)->convertFromNewDbgValues();
38923891
if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
38933892

38943893
if (F->isMaterializable())
@@ -4031,6 +4030,8 @@ void AssemblyWriter::printFunction(const Function *F) {
40314030
Out << "}\n";
40324031
}
40334032

4033+
if (ConvertBack)
4034+
const_cast<Function *>(F)->convertToNewDbgValues();
40344035
Machine.purgeFunction();
40354036
}
40364037

@@ -4097,8 +4098,6 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
40974098

40984099
// Output all of the instructions in the basic block...
40994100
for (const Instruction &I : *BB) {
4100-
for (const DbgRecord &DR : I.getDbgValueRange())
4101-
printDbgRecordLine(DR);
41024101
printInstructionLine(I);
41034102
}
41044103

@@ -4612,10 +4611,12 @@ void AssemblyWriter::printDbgRecord(const DbgRecord &DR) {
46124611
llvm_unreachable("Unexpected DbgRecord kind");
46134612
}
46144613

4615-
void AssemblyWriter::printDPValue(const DPValue &DPV) {
4616-
auto WriterCtx = getContext();
4617-
Out << "#dbg_";
4618-
switch (DPV.getType()) {
4614+
void AssemblyWriter::printDPValue(const DPValue &Value) {
4615+
// There's no formal representation of a DPValue -- print purely as a
4616+
// debugging aid.
4617+
Out << " DPValue ";
4618+
4619+
switch (Value.getType()) {
46194620
case DPValue::LocationType::Value:
46204621
Out << "value";
46214622
break;
@@ -4628,39 +4629,35 @@ void AssemblyWriter::printDPValue(const DPValue &DPV) {
46284629
default:
46294630
llvm_unreachable("Tried to print a DPValue with an invalid LocationType!");
46304631
}
4631-
Out << "(";
4632-
WriteAsOperandInternal(Out, DPV.getRawLocation(), WriterCtx, true);
4632+
Out << " { ";
4633+
auto WriterCtx = getContext();
4634+
WriteAsOperandInternal(Out, Value.getRawLocation(), WriterCtx, true);
46334635
Out << ", ";
4634-
WriteAsOperandInternal(Out, DPV.getVariable(), WriterCtx, true);
4636+
WriteAsOperandInternal(Out, Value.getVariable(), WriterCtx, true);
46354637
Out << ", ";
4636-
WriteAsOperandInternal(Out, DPV.getExpression(), WriterCtx, true);
4638+
WriteAsOperandInternal(Out, Value.getExpression(), WriterCtx, true);
46374639
Out << ", ";
4638-
if (DPV.isDbgAssign()) {
4639-
WriteAsOperandInternal(Out, DPV.getAssignID(), WriterCtx, true);
4640+
if (Value.isDbgAssign()) {
4641+
WriteAsOperandInternal(Out, Value.getAssignID(), WriterCtx, true);
46404642
Out << ", ";
4641-
WriteAsOperandInternal(Out, DPV.getRawAddress(), WriterCtx, true);
4643+
WriteAsOperandInternal(Out, Value.getRawAddress(), WriterCtx, true);
46424644
Out << ", ";
4643-
WriteAsOperandInternal(Out, DPV.getAddressExpression(), WriterCtx, true);
4645+
WriteAsOperandInternal(Out, Value.getAddressExpression(), WriterCtx, true);
46444646
Out << ", ";
46454647
}
4646-
WriteAsOperandInternal(Out, DPV.getDebugLoc().getAsMDNode(), WriterCtx, true);
4647-
Out << ")";
4648-
}
4649-
4650-
/// printDbgRecordLine - Print a DbgRecord with indentation and a newline
4651-
/// character.
4652-
void AssemblyWriter::printDbgRecordLine(const DbgRecord &DR) {
4653-
// Print lengthier indentation to bring out-of-line with instructions.
4654-
Out << " ";
4655-
printDbgRecord(DR);
4656-
Out << '\n';
4648+
WriteAsOperandInternal(Out, Value.getDebugLoc().get(), WriterCtx, true);
4649+
Out << " marker @" << Value.getMarker();
4650+
Out << " }";
46574651
}
46584652

46594653
void AssemblyWriter::printDPLabel(const DPLabel &Label) {
4654+
// There's no formal representation of a DPLabel -- print purely as
4655+
// a debugging aid.
4656+
Out << " DPLabel { ";
46604657
auto WriterCtx = getContext();
4661-
Out << "#dbg_label(";
46624658
WriteAsOperandInternal(Out, Label.getLabel(), WriterCtx, true);
4663-
Out << ")";
4659+
Out << " marker @" << Label.getMarker();
4660+
Out << " }";
46644661
}
46654662

46664663
void AssemblyWriter::printMetadataAttachments(
@@ -4808,11 +4805,19 @@ void BasicBlock::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
48084805

48094806
void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
48104807
bool ShouldPreserveUseListOrder, bool IsForDebug) const {
4808+
// RemoveDIs: always print with debug-info in intrinsic format.
4809+
bool ConvertAfter = IsNewDbgInfoFormat;
4810+
if (IsNewDbgInfoFormat)
4811+
const_cast<Module *>(this)->convertFromNewDbgValues();
4812+
48114813
SlotTracker SlotTable(this);
48124814
formatted_raw_ostream OS(ROS);
48134815
AssemblyWriter W(OS, SlotTable, this, AAW, IsForDebug,
48144816
ShouldPreserveUseListOrder);
48154817
W.printModule(this);
4818+
4819+
if (ConvertAfter)
4820+
const_cast<Module *>(this)->convertToNewDbgValues();
48164821
}
48174822

48184823
void NamedMDNode::print(raw_ostream &ROS, bool IsForDebug) const {
@@ -4903,6 +4908,8 @@ void DPValue::print(raw_ostream &ROS, bool IsForDebug) const {
49034908

49044909
void DPMarker::print(raw_ostream &ROS, ModuleSlotTracker &MST,
49054910
bool IsForDebug) const {
4911+
// There's no formal representation of a DPMarker -- print purely as a
4912+
// debugging aid.
49064913
formatted_raw_ostream OS(ROS);
49074914
SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));
49084915
SlotTracker &SlotTable =
@@ -4924,6 +4931,8 @@ void DPLabel::print(raw_ostream &ROS, bool IsForDebug) const {
49244931

49254932
void DPValue::print(raw_ostream &ROS, ModuleSlotTracker &MST,
49264933
bool IsForDebug) const {
4934+
// There's no formal representation of a DPValue -- print purely as a
4935+
// debugging aid.
49274936
formatted_raw_ostream OS(ROS);
49284937
SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));
49294938
SlotTracker &SlotTable =
@@ -4941,6 +4950,8 @@ void DPValue::print(raw_ostream &ROS, ModuleSlotTracker &MST,
49414950

49424951
void DPLabel::print(raw_ostream &ROS, ModuleSlotTracker &MST,
49434952
bool IsForDebug) const {
4953+
// There's no formal representation of a DbgLabelRecord -- print purely as
4954+
// a debugging aid.
49444955
formatted_raw_ostream OS(ROS);
49454956
SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));
49464957
SlotTracker &SlotTable =

Diff for: llvm/lib/IR/BasicBlock.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ DPMarker *BasicBlock::createMarker(InstListType::iterator It) {
6161
}
6262

6363
void BasicBlock::convertToNewDbgValues() {
64+
// Is the command line option set?
65+
if (!UseNewDbgInfoFormat)
66+
return;
67+
6468
IsNewDbgInfoFormat = true;
6569

6670
// Iterate over all instructions in the instruction list, collecting dbg.value

Diff for: llvm/lib/IR/IRPrintingPasses.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
using namespace llvm;
2525

26-
extern cl::opt<bool> WriteNewDbgInfoFormat;
27-
2826
namespace {
2927

3028
class PrintModulePassWrapper : public ModulePass {
@@ -41,9 +39,11 @@ class PrintModulePassWrapper : public ModulePass {
4139
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
4240

4341
bool runOnModule(Module &M) override {
44-
// RemoveDIs: Regardless of the format we've processed this module in, use
45-
// `WriteNewDbgInfoFormat` to determine which format we use to write it.
46-
ScopedDbgInfoFormatSetter FormatSetter(M, WriteNewDbgInfoFormat);
42+
// RemoveDIs: there's no textual representation of the DPValue debug-info,
43+
// convert to dbg.values before writing out.
44+
bool IsNewDbgInfoFormat = M.IsNewDbgInfoFormat;
45+
if (IsNewDbgInfoFormat)
46+
M.convertFromNewDbgValues();
4747

4848
if (llvm::isFunctionInPrintList("*")) {
4949
if (!Banner.empty())
@@ -62,6 +62,9 @@ class PrintModulePassWrapper : public ModulePass {
6262
}
6363
}
6464

65+
if (IsNewDbgInfoFormat)
66+
M.convertToNewDbgValues();
67+
6568
return false;
6669
}
6770

@@ -84,9 +87,11 @@ class PrintFunctionPassWrapper : public FunctionPass {
8487

8588
// This pass just prints a banner followed by the function as it's processed.
8689
bool runOnFunction(Function &F) override {
87-
// RemoveDIs: Regardless of the format we've processed this function in, use
88-
// `WriteNewDbgInfoFormat` to determine which format we use to write it.
89-
ScopedDbgInfoFormatSetter FormatSetter(F, WriteNewDbgInfoFormat);
90+
// RemoveDIs: there's no textual representation of the DPValue debug-info,
91+
// convert to dbg.values before writing out.
92+
bool IsNewDbgInfoFormat = F.IsNewDbgInfoFormat;
93+
if (IsNewDbgInfoFormat)
94+
F.convertFromNewDbgValues();
9095

9196
if (isFunctionInPrintList(F.getName())) {
9297
if (forcePrintModuleIR())
@@ -96,6 +101,9 @@ class PrintFunctionPassWrapper : public FunctionPass {
96101
OS << Banner << '\n' << static_cast<Value &>(F);
97102
}
98103

104+
if (IsNewDbgInfoFormat)
105+
F.convertToNewDbgValues();
106+
99107
return false;
100108
}
101109

Diff for: llvm/lib/IR/Module.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,6 @@ Module::~Module() {
8585
IFuncList.clear();
8686
}
8787

88-
void Module::removeDebugIntrinsicDeclarations() {
89-
auto *DeclareIntrinsicFn =
90-
Intrinsic::getDeclaration(this, Intrinsic::dbg_declare);
91-
assert((!isMaterialized() || DeclareIntrinsicFn->hasZeroLiveUses()) &&
92-
"Debug declare intrinsic should have had uses removed.");
93-
DeclareIntrinsicFn->eraseFromParent();
94-
auto *ValueIntrinsicFn =
95-
Intrinsic::getDeclaration(this, Intrinsic::dbg_value);
96-
assert((!isMaterialized() || ValueIntrinsicFn->hasZeroLiveUses()) &&
97-
"Debug value intrinsic should have had uses removed.");
98-
ValueIntrinsicFn->eraseFromParent();
99-
auto *AssignIntrinsicFn =
100-
Intrinsic::getDeclaration(this, Intrinsic::dbg_assign);
101-
assert((!isMaterialized() || AssignIntrinsicFn->hasZeroLiveUses()) &&
102-
"Debug assign intrinsic should have had uses removed.");
103-
AssignIntrinsicFn->eraseFromParent();
104-
auto *LabelntrinsicFn = Intrinsic::getDeclaration(this, Intrinsic::dbg_label);
105-
assert((!isMaterialized() || LabelntrinsicFn->hasZeroLiveUses()) &&
106-
"Debug label intrinsic should have had uses removed.");
107-
LabelntrinsicFn->eraseFromParent();
108-
}
109-
11088
std::unique_ptr<RandomNumberGenerator>
11189
Module::createRNG(const StringRef Name) const {
11290
SmallString<32> Salt(Name);

Diff for: llvm/lib/IRPrinter/IRPrintingPasses.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222

2323
using namespace llvm;
2424

25-
cl::opt<bool> WriteNewDbgInfoFormat(
26-
"write-experimental-debuginfo",
27-
cl::desc("Write debug info in the new non-intrinsic format"),
28-
cl::init(false));
29-
3025
PrintModulePass::PrintModulePass() : OS(dbgs()) {}
3126
PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner,
3227
bool ShouldPreserveUseListOrder,
@@ -36,9 +31,11 @@ PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner,
3631
EmitSummaryIndex(EmitSummaryIndex) {}
3732

3833
PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &AM) {
39-
// RemoveDIs: Regardless of the format we've processed this module in, use
40-
// `WriteNewDbgInfoFormat` to determine which format we use to write it.
41-
ScopedDbgInfoFormatSetter FormatSetter(M, WriteNewDbgInfoFormat);
34+
// RemoveDIs: there's no textual representation of the DPValue debug-info,
35+
// convert to dbg.values before writing out.
36+
bool ShouldConvert = M.IsNewDbgInfoFormat;
37+
if (ShouldConvert)
38+
M.convertFromNewDbgValues();
4239

4340
if (llvm::isFunctionInPrintList("*")) {
4441
if (!Banner.empty())
@@ -66,6 +63,9 @@ PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &AM) {
6663
Index->print(OS);
6764
}
6865

66+
if (ShouldConvert)
67+
M.convertToNewDbgValues();
68+
6969
return PreservedAnalyses::all();
7070
}
7171

@@ -75,9 +75,11 @@ PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, const std::string &Banner)
7575

7676
PreservedAnalyses PrintFunctionPass::run(Function &F,
7777
FunctionAnalysisManager &) {
78-
// RemoveDIs: Regardless of the format we've processed this function in, use
79-
// `WriteNewDbgInfoFormat` to determine which format we use to write it.
80-
ScopedDbgInfoFormatSetter FormatSetter(F, WriteNewDbgInfoFormat);
78+
// RemoveDIs: there's no textual representation of the DPValue debug-info,
79+
// convert to dbg.values before writing out.
80+
bool ShouldConvert = F.IsNewDbgInfoFormat;
81+
if (ShouldConvert)
82+
F.convertFromNewDbgValues();
8183

8284
if (isFunctionInPrintList(F.getName())) {
8385
if (forcePrintModuleIR())
@@ -86,5 +88,8 @@ PreservedAnalyses PrintFunctionPass::run(Function &F,
8688
OS << Banner << '\n' << static_cast<Value &>(F);
8789
}
8890

91+
if (ShouldConvert)
92+
F.convertToNewDbgValues();
93+
8994
return PreservedAnalyses::all();
9095
}

0 commit comments

Comments
 (0)