Skip to content

Commit 00821fe

Browse files
committed
Revert "[RemoveDIs] Load into new debug info format by default in LLVM (#89799)"
A unit test was broken by the above commit: https://lab.llvm.org/buildbot/#/builders/139/builds/64627 This reverts commit 2f01fd9.
1 parent 2f01fd9 commit 00821fe

File tree

16 files changed

+61
-143
lines changed

16 files changed

+61
-143
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,6 @@ Changes to the Metadata Info
170170
Changes to the Debug Info
171171
---------------------------------
172172

173-
* LLVM has switched from using debug intrinsics internally to using debug
174-
records by default. This should happen transparently when using the DIBuilder
175-
to construct debug variable information, but will require changes for any code
176-
that interacts with debug intrinsics directly. Debug intrinsics will only be
177-
supported on a best-effort basis from here onwards; for more information, see
178-
the `migration docs <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_.
179-
180173
Changes to the LLVM tools
181174
---------------------------------
182175
* llvm-nm and llvm-objdump can now print symbol information from linked

llvm/include/llvm/AsmParser/LLParser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ namespace llvm {
337337

338338
// Top-Level Entities
339339
bool parseTopLevelEntities();
340+
bool finalizeDebugInfoFormat(Module *M);
340341
void dropUnknownMetadataReferences();
341342
bool validateEndOfModule(bool UpgradeDebugInfo);
342343
bool validateEndOfIndex();

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ static std::string getTypeString(Type *T) {
7474
return Tmp.str();
7575
}
7676

77+
// Whatever debug info format we parsed, we should convert to the expected debug
78+
// info format immediately afterwards.
79+
bool LLParser::finalizeDebugInfoFormat(Module *M) {
80+
// We should have already returned an error if we observed both intrinsics and
81+
// records in this IR.
82+
assert(!(SeenNewDbgInfoFormat && SeenOldDbgInfoFormat) &&
83+
"Mixed debug intrinsics/records seen without a parsing error?");
84+
if (PreserveInputDbgFormat == cl::boolOrDefault::BOU_TRUE) {
85+
UseNewDbgInfoFormat = SeenNewDbgInfoFormat;
86+
WriteNewDbgInfoFormatToBitcode = SeenNewDbgInfoFormat;
87+
WriteNewDbgInfoFormat = SeenNewDbgInfoFormat;
88+
} else if (M) {
89+
M->setIsNewDbgInfoFormat(false);
90+
}
91+
return false;
92+
}
93+
7794
/// Run: module ::= toplevelentity*
7895
bool LLParser::Run(bool UpgradeDebugInfo,
7996
DataLayoutCallbackTy DataLayoutCallback) {
@@ -91,7 +108,7 @@ bool LLParser::Run(bool UpgradeDebugInfo,
91108
}
92109

93110
return parseTopLevelEntities() || validateEndOfModule(UpgradeDebugInfo) ||
94-
validateEndOfIndex();
111+
validateEndOfIndex() || finalizeDebugInfoFormat(M);
95112
}
96113

97114
bool LLParser::parseStandaloneConstantValue(Constant *&C,
@@ -190,18 +207,6 @@ void LLParser::dropUnknownMetadataReferences() {
190207
bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
191208
if (!M)
192209
return false;
193-
194-
// We should have already returned an error if we observed both intrinsics and
195-
// records in this IR.
196-
assert(!(SeenNewDbgInfoFormat && SeenOldDbgInfoFormat) &&
197-
"Mixed debug intrinsics/records seen without a parsing error?");
198-
if (PreserveInputDbgFormat == cl::boolOrDefault::BOU_TRUE) {
199-
UseNewDbgInfoFormat = SeenNewDbgInfoFormat;
200-
WriteNewDbgInfoFormatToBitcode = SeenNewDbgInfoFormat;
201-
WriteNewDbgInfoFormat = SeenNewDbgInfoFormat;
202-
M->setNewDbgInfoFormatFlag(SeenNewDbgInfoFormat);
203-
}
204-
205210
// Handle any function attribute group forward references.
206211
for (const auto &RAG : ForwardRefAttrGroups) {
207212
Value *V = RAG.first;
@@ -434,9 +439,6 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
434439
UpgradeModuleFlags(*M);
435440
UpgradeSectionAttributes(*M);
436441

437-
if (PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE)
438-
M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat);
439-
440442
if (!Slots)
441443
return false;
442444
// Initialize the slot mapping.

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4319,7 +4319,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
43194319
if (PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE) {
43204320
TheModule->IsNewDbgInfoFormat =
43214321
UseNewDbgInfoFormat &&
4322-
LoadBitcodeIntoNewDbgInfoFormat != cl::boolOrDefault::BOU_FALSE;
4322+
LoadBitcodeIntoNewDbgInfoFormat == cl::boolOrDefault::BOU_TRUE;
43234323
}
43244324

43254325
this->ValueTypeCallback = std::move(Callbacks.ValueType);

llvm/lib/IR/BasicBlock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ template class llvm::SymbolTableListTraits<Instruction,
181181
BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
182182
BasicBlock *InsertBefore)
183183
: Value(Type::getLabelTy(C), Value::BasicBlockVal),
184-
IsNewDbgInfoFormat(UseNewDbgInfoFormat), Parent(nullptr) {
184+
IsNewDbgInfoFormat(false), Parent(nullptr) {
185185

186186
if (NewParent)
187187
insertInto(NewParent, InsertBefore);

llvm/lib/IR/Function.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ static cl::opt<unsigned> NonGlobalValueMaxNameSize(
8383
"non-global-value-max-name-size", cl::Hidden, cl::init(1024),
8484
cl::desc("Maximum size for the name of non-global values."));
8585

86-
extern cl::opt<bool> UseNewDbgInfoFormat;
87-
8886
void Function::convertToNewDbgValues() {
8987
IsNewDbgInfoFormat = true;
9088
for (auto &BB : *this) {
@@ -440,7 +438,7 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
440438
: GlobalObject(Ty, Value::FunctionVal,
441439
OperandTraits<Function>::op_begin(this), 0, Linkage, name,
442440
computeAddrSpace(AddrSpace, ParentModule)),
443-
NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
441+
NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(false) {
444442
assert(FunctionType::isValidReturnType(getReturnType()) &&
445443
"invalid return type");
446444
setGlobalObjectSubClassData(0);

llvm/lib/IR/Module.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454

5555
using namespace llvm;
5656

57-
extern cl::opt<bool> UseNewDbgInfoFormat;
58-
5957
//===----------------------------------------------------------------------===//
6058
// Methods to implement the globals and functions lists.
6159
//
@@ -74,7 +72,7 @@ template class llvm::SymbolTableListTraits<GlobalIFunc>;
7472
Module::Module(StringRef MID, LLVMContext &C)
7573
: Context(C), ValSymTab(std::make_unique<ValueSymbolTable>(-1)),
7674
ModuleID(std::string(MID)), SourceFileName(std::string(MID)), DL(""),
77-
IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
75+
IsNewDbgInfoFormat(false) {
7876
Context.addModule(this);
7977
}
8078

llvm/tools/llvm-as/llvm-as.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ int main(int argc, char **argv) {
142142
}
143143

144144
// Convert to new debug format if requested.
145-
M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat &&
146-
WriteNewDbgInfoFormatToBitcode);
147-
if (M->IsNewDbgInfoFormat)
145+
assert(!M->IsNewDbgInfoFormat && "Unexpectedly in new debug mode");
146+
if (UseNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode) {
147+
M->convertToNewDbgValues();
148148
M->removeDebugIntrinsicDeclarations();
149+
}
149150

150151
std::unique_ptr<ModuleSummaryIndex> Index = std::move(ModuleAndIndex.Index);
151152

llvm/tools/llvm-dis/llvm-dis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ int main(int argc, char **argv) {
258258
// All that llvm-dis does is write the assembly to a file.
259259
if (!DontPrint) {
260260
if (M) {
261-
M->setIsNewDbgInfoFormat(WriteNewDbgInfoFormat);
261+
ScopedDbgInfoFormatSetter FormatSetter(*M, WriteNewDbgInfoFormat);
262262
if (WriteNewDbgInfoFormat)
263263
M->removeDebugIntrinsicDeclarations();
264264
M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder);

llvm/tools/llvm-link/llvm-link.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,12 @@ int main(int argc, char **argv) {
489489
if (LoadBitcodeIntoNewDbgInfoFormat == cl::boolOrDefault::BOU_UNSET)
490490
LoadBitcodeIntoNewDbgInfoFormat = cl::boolOrDefault::BOU_TRUE;
491491

492+
// RemoveDIs debug-info transition: tests may request that we /try/ to use the
493+
// new debug-info format.
494+
if (TryUseNewDbgInfoFormat) {
495+
// Turn the new debug-info format on.
496+
UseNewDbgInfoFormat = true;
497+
}
492498
// Since llvm-link collects multiple IR modules together, for simplicity's
493499
// sake we disable the "PreserveInputDbgFormat" flag to enforce a single
494500
// debug info format.
@@ -550,7 +556,7 @@ int main(int argc, char **argv) {
550556
SetFormat(WriteNewDbgInfoFormat);
551557
Composite->print(Out.os(), nullptr, PreserveAssemblyUseListOrder);
552558
} else if (Force || !CheckBitcodeOutputToConsole(Out.os())) {
553-
SetFormat(UseNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode);
559+
SetFormat(WriteNewDbgInfoFormatToBitcode);
554560
WriteBitcodeToFile(*Composite, Out.os(), PreserveBitcodeUseListOrder);
555561
}
556562

llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "llvm/Analysis/IRSimilarityIdentifier.h"
15-
#include "llvm/ADT/ScopeExit.h"
1615
#include "llvm/AsmParser/Parser.h"
1716
#include "llvm/IR/LLVMContext.h"
1817
#include "llvm/IR/Module.h"
@@ -23,27 +22,6 @@
2322
using namespace llvm;
2423
using namespace IRSimilarity;
2524

26-
extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
27-
extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;
28-
extern bool WriteNewDbgInfoFormatToBitcode;
29-
extern cl::opt<bool> WriteNewDbgInfoFormat;
30-
31-
// Backup all of the existing settings that may be modified when
32-
// PreserveInputDbgFormat=true, so that when the test is finished we return them
33-
// (and the "preserve" setting) to their original values.
34-
static auto SaveDbgInfoFormat() {
35-
return make_scope_exit(
36-
[OldPreserveInputDbgFormat = PreserveInputDbgFormat.getValue(),
37-
OldUseNewDbgInfoFormat = UseNewDbgInfoFormat.getValue(),
38-
OldWriteNewDbgInfoFormatToBitcode = WriteNewDbgInfoFormatToBitcode,
39-
OldWriteNewDbgInfoFormat = WriteNewDbgInfoFormat.getValue()] {
40-
PreserveInputDbgFormat = OldPreserveInputDbgFormat;
41-
UseNewDbgInfoFormat = OldUseNewDbgInfoFormat;
42-
WriteNewDbgInfoFormatToBitcode = OldWriteNewDbgInfoFormatToBitcode;
43-
WriteNewDbgInfoFormat = OldWriteNewDbgInfoFormat;
44-
});
45-
}
46-
4725
static std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context,
4826
StringRef ModuleStr) {
4927
SMDiagnostic Err;
@@ -1330,9 +1308,6 @@ TEST(IRInstructionMapper, CallBrInstIllegal) {
13301308

13311309
// Checks that an debuginfo intrinsics are mapped to be invisible. Since they
13321310
// do not semantically change the program, they can be recognized as similar.
1333-
// FIXME: PreserveInputDbgFormat is set to true because this test contains
1334-
// malformed debug info that cannot be converted to the new debug info format;
1335-
// this test should be updated later to use valid debug info.
13361311
TEST(IRInstructionMapper, DebugInfoInvisible) {
13371312
StringRef ModuleString = R"(
13381313
define i32 @f(i32 %a, i32 %b) {
@@ -1345,8 +1320,6 @@ TEST(IRInstructionMapper, DebugInfoInvisible) {
13451320
13461321
declare void @llvm.dbg.value(metadata)
13471322
!0 = distinct !{!"test\00", i32 10})";
1348-
auto SettingGuard = SaveDbgInfoFormat();
1349-
PreserveInputDbgFormat = cl::boolOrDefault::BOU_TRUE;
13501323
LLVMContext Context;
13511324
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
13521325

@@ -1943,9 +1916,6 @@ TEST(IRSimilarityCandidate, CheckRegionsDifferentTypes) {
19431916

19441917
// Check that debug instructions do not impact similarity. They are marked as
19451918
// invisible.
1946-
// FIXME: PreserveInputDbgFormat is set to true because this test contains
1947-
// malformed debug info that cannot be converted to the new debug info format;
1948-
// this test should be updated later to use valid debug info.
19491919
TEST(IRSimilarityCandidate, IdenticalWithDebug) {
19501920
StringRef ModuleString = R"(
19511921
define i32 @f(i32 %a, i32 %b) {
@@ -1968,8 +1938,6 @@ TEST(IRSimilarityCandidate, IdenticalWithDebug) {
19681938
declare void @llvm.dbg.value(metadata)
19691939
!0 = distinct !{!"test\00", i32 10}
19701940
!1 = distinct !{!"test\00", i32 11})";
1971-
auto SettingGuard = SaveDbgInfoFormat();
1972-
PreserveInputDbgFormat = cl::boolOrDefault::BOU_TRUE;
19731941
LLVMContext Context;
19741942
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
19751943

llvm/unittests/IR/BasicBlockDbgInfoTest.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ TEST(BasicBlockDbgInfoTest, InsertAfterSelf) {
7272
!11 = !DILocation(line: 1, column: 1, scope: !6)
7373
)");
7474

75+
// Convert the module to "new" form debug-info.
76+
M->convertToNewDbgValues();
7577
// Fetch the entry block.
7678
BasicBlock &BB = M->getFunction("f")->getEntryBlock();
7779

@@ -102,6 +104,8 @@ TEST(BasicBlockDbgInfoTest, InsertAfterSelf) {
102104
auto Range2 = RetInst->getDbgRecordRange();
103105
EXPECT_EQ(std::distance(Range2.begin(), Range2.end()), 1u);
104106

107+
M->convertFromNewDbgValues();
108+
105109
UseNewDbgInfoFormat = false;
106110
}
107111

@@ -192,6 +196,8 @@ TEST(BasicBlockDbgInfoTest, MarkerOperations) {
192196

193197
// Fetch the entry block,
194198
BasicBlock &BB = M->getFunction("f")->getEntryBlock();
199+
// Convert the module to "new" form debug-info.
200+
M->convertToNewDbgValues();
195201
EXPECT_EQ(BB.size(), 2u);
196202

197203
// Fetch out our two markers,
@@ -326,6 +332,8 @@ TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
326332
// Test that the movement of debug-data when using moveBefore etc and
327333
// insertBefore etc are governed by the "head" bit of iterators.
328334
BasicBlock &BB = M->getFunction("f")->getEntryBlock();
335+
// Convert the module to "new" form debug-info.
336+
M->convertToNewDbgValues();
329337

330338
// Test that the head bit behaves as expected: it should be set when the
331339
// code wants the _start_ of the block, but not otherwise.
@@ -433,6 +441,8 @@ TEST(BasicBlockDbgInfoTest, InstrDbgAccess) {
433441
// Check that DbgVariableRecords can be accessed from Instructions without
434442
// digging into the depths of DbgMarkers.
435443
BasicBlock &BB = M->getFunction("f")->getEntryBlock();
444+
// Convert the module to "new" form debug-info.
445+
M->convertToNewDbgValues();
436446

437447
Instruction *BInst = &*BB.begin();
438448
Instruction *CInst = BInst->getNextNode();
@@ -569,6 +579,7 @@ class DbgSpliceTest : public ::testing::Test {
569579
void SetUp() override {
570580
UseNewDbgInfoFormat = true;
571581
M = parseIR(C, SpliceTestIR.c_str());
582+
M->convertToNewDbgValues();
572583

573584
BBEntry = &M->getFunction("f")->getEntryBlock();
574585
BBExit = BBEntry->getNextNode();
@@ -1208,6 +1219,7 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceTrailing) {
12081219

12091220
BasicBlock &Entry = M->getFunction("f")->getEntryBlock();
12101221
BasicBlock &Exit = *Entry.getNextNode();
1222+
M->convertToNewDbgValues();
12111223

12121224
// Begin by forcing entry block to have dangling DbgVariableRecord.
12131225
Entry.getTerminator()->eraseFromParent();
@@ -1261,6 +1273,7 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsert) {
12611273
)");
12621274

12631275
BasicBlock &Entry = M->getFunction("f")->getEntryBlock();
1276+
M->convertToNewDbgValues();
12641277

12651278
// Fetch the relevant instructions from the converted function.
12661279
Instruction *SubInst = &*Entry.begin();
@@ -1339,6 +1352,7 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsertForOneDbgVariableRecord) {
13391352
)");
13401353

13411354
BasicBlock &Entry = M->getFunction("f")->getEntryBlock();
1355+
M->convertToNewDbgValues();
13421356

13431357
// Fetch the relevant instructions from the converted function.
13441358
Instruction *SubInst = &*Entry.begin();
@@ -1422,6 +1436,7 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty1) {
14221436
Function &F = *M->getFunction("f");
14231437
BasicBlock &Entry = F.getEntryBlock();
14241438
BasicBlock &Exit = *Entry.getNextNode();
1439+
M->convertToNewDbgValues();
14251440

14261441
// Begin by forcing entry block to have dangling DbgVariableRecord.
14271442
Entry.getTerminator()->eraseFromParent();
@@ -1491,6 +1506,7 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty2) {
14911506
Function &F = *M->getFunction("f");
14921507
BasicBlock &Entry = F.getEntryBlock();
14931508
BasicBlock &Exit = *Entry.getNextNode();
1509+
M->convertToNewDbgValues();
14941510

14951511
// Begin by forcing entry block to have dangling DbgVariableRecord.
14961512
Entry.getTerminator()->eraseFromParent();
@@ -1560,6 +1576,7 @@ TEST(BasicBlockDbgInfoTest, DbgMoveToEnd) {
15601576
Function &F = *M->getFunction("f");
15611577
BasicBlock &Entry = F.getEntryBlock();
15621578
BasicBlock &Exit = *Entry.getNextNode();
1579+
M->convertToNewDbgValues();
15631580

15641581
// Move the return to the end of the entry block.
15651582
Instruction *Br = Entry.getTerminator();

0 commit comments

Comments
 (0)