Skip to content

Commit c5aeca7

Browse files
committed
Reapply#3 "[RemoveDIs] Load into new debug info format by default in LLVM (llvm#89799)"
Reapplies commit 91446e2, which was reverted due to a downstream error, discussed on the pull request. The error could not be reproduced upstream, and cannot be reproduced downstream as-of current main, so until the error can be confirmed to still exist this patch should return. This reverts commit 23f8fac.
1 parent 4f11119 commit c5aeca7

20 files changed

+237
-252
lines changed

clang/test/CodeGen/instrument-objc-method.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ @implementation ObjCClass
1111
+ (void)initialize {
1212
}
1313

14-
// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
15-
// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #2
14+
// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #1
1615
+ (void)load __attribute__((no_instrument_function)) {
1716
}
1817

19-
// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2
20-
// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2
18+
// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1
19+
// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1
2120
- (void)dealloc __attribute__((no_instrument_function)) {
2221
}
2322

23+
// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
2424
// PREINLINE: attributes #0 = { {{.*}}"instrument-function-entry"="__cyg_profile_func_enter"
2525
// PREINLINE-NOT: attributes #0 = { {{.*}}"instrument-function-entry"="__cyg_profile_func_enter_bare"
2626
// PREINLINE-NOT: attributes #2 = { {{.*}}"__cyg_profile_func_enter"

llvm/docs/ReleaseNotes.rst

+7
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ Changes to the Metadata Info
225225
Changes to the Debug Info
226226
---------------------------------
227227

228+
* LLVM has switched from using debug intrinsics internally to using debug
229+
records by default. This should happen transparently when using the DIBuilder
230+
to construct debug variable information, but will require changes for any code
231+
that interacts with debug intrinsics directly. Debug intrinsics will only be
232+
supported on a best-effort basis from here onwards; for more information, see
233+
the `migration docs <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_.
234+
228235
Changes to the LLVM tools
229236
---------------------------------
230237
* llvm-nm and llvm-objdump can now print symbol information from linked

llvm/include/llvm/AsmParser/LLParser.h

-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ namespace llvm {
337337

338338
// Top-Level Entities
339339
bool parseTopLevelEntities();
340-
bool finalizeDebugInfoFormat(Module *M);
341340
void dropUnknownMetadataReferences();
342341
bool validateEndOfModule(bool UpgradeDebugInfo);
343342
bool validateEndOfIndex();

llvm/lib/AsmParser/LLParser.cpp

+16-18
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,6 @@ 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-
9477
/// Run: module ::= toplevelentity*
9578
bool LLParser::Run(bool UpgradeDebugInfo,
9679
DataLayoutCallbackTy DataLayoutCallback) {
@@ -108,7 +91,7 @@ bool LLParser::Run(bool UpgradeDebugInfo,
10891
}
10992

11093
return parseTopLevelEntities() || validateEndOfModule(UpgradeDebugInfo) ||
111-
validateEndOfIndex() || finalizeDebugInfoFormat(M);
94+
validateEndOfIndex();
11295
}
11396

11497
bool LLParser::parseStandaloneConstantValue(Constant *&C,
@@ -207,6 +190,18 @@ void LLParser::dropUnknownMetadataReferences() {
207190
bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
208191
if (!M)
209192
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+
210205
// Handle any function attribute group forward references.
211206
for (const auto &RAG : ForwardRefAttrGroups) {
212207
Value *V = RAG.first;
@@ -439,6 +434,9 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
439434
UpgradeModuleFlags(*M);
440435
UpgradeSectionAttributes(*M);
441436

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

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4355,7 +4355,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
43554355
if (PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE) {
43564356
TheModule->IsNewDbgInfoFormat =
43574357
UseNewDbgInfoFormat &&
4358-
LoadBitcodeIntoNewDbgInfoFormat == cl::boolOrDefault::BOU_TRUE;
4358+
LoadBitcodeIntoNewDbgInfoFormat != cl::boolOrDefault::BOU_FALSE;
43594359
}
43604360

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

llvm/lib/IR/BasicBlock.cpp

+1-1
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(false), Parent(nullptr) {
184+
IsNewDbgInfoFormat(UseNewDbgInfoFormat), Parent(nullptr) {
185185

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

llvm/lib/IR/DebugProgramInstruction.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ void DbgVariableRecord::setKillLocation() {
366366
}
367367

368368
bool DbgVariableRecord::isKillLocation() const {
369-
return (getNumVariableLocationOps() == 0 &&
370-
!getExpression()->isComplex()) ||
369+
return (!hasArgList() && isa<MDNode>(getRawLocation())) ||
370+
(getNumVariableLocationOps() == 0 && !getExpression()->isComplex()) ||
371371
any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
372372
}
373373

llvm/lib/IR/Function.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ static cl::opt<int> 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+
8688
void Function::convertToNewDbgValues() {
8789
IsNewDbgInfoFormat = true;
8890
for (auto &BB : *this) {
@@ -441,7 +443,7 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
441443
: GlobalObject(Ty, Value::FunctionVal,
442444
OperandTraits<Function>::op_begin(this), 0, Linkage, name,
443445
computeAddrSpace(AddrSpace, ParentModule)),
444-
NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(false) {
446+
NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
445447
assert(FunctionType::isValidReturnType(getReturnType()) &&
446448
"invalid return type");
447449
setGlobalObjectSubClassData(0);

llvm/lib/IR/Module.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454

5555
using namespace llvm;
5656

57+
extern cl::opt<bool> UseNewDbgInfoFormat;
58+
5759
//===----------------------------------------------------------------------===//
5860
// Methods to implement the globals and functions lists.
5961
//
@@ -72,7 +74,7 @@ template class llvm::SymbolTableListTraits<GlobalIFunc>;
7274
Module::Module(StringRef MID, LLVMContext &C)
7375
: Context(C), ValSymTab(std::make_unique<ValueSymbolTable>(-1)),
7476
ModuleID(std::string(MID)), SourceFileName(std::string(MID)), DL(""),
75-
IsNewDbgInfoFormat(false) {
77+
IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
7678
Context.addModule(this);
7779
}
7880

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

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

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

151150
std::unique_ptr<ModuleSummaryIndex> Index = std::move(ModuleAndIndex.Index);
152151

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

+1-1
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-
ScopedDbgInfoFormatSetter FormatSetter(*M, WriteNewDbgInfoFormat);
261+
M->setIsNewDbgInfoFormat(WriteNewDbgInfoFormat);
262262
if (WriteNewDbgInfoFormat)
263263
M->removeDebugIntrinsicDeclarations();
264264
M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder);

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,6 @@ 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-
}
498492
// Since llvm-link collects multiple IR modules together, for simplicity's
499493
// sake we disable the "PreserveInputDbgFormat" flag to enforce a single
500494
// debug info format.
@@ -556,7 +550,7 @@ int main(int argc, char **argv) {
556550
SetFormat(WriteNewDbgInfoFormat);
557551
Composite->print(Out.os(), nullptr, PreserveAssemblyUseListOrder);
558552
} else if (Force || !CheckBitcodeOutputToConsole(Out.os())) {
559-
SetFormat(WriteNewDbgInfoFormatToBitcode);
553+
SetFormat(UseNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode);
560554
WriteBitcodeToFile(*Composite, Out.os(), PreserveBitcodeUseListOrder);
561555
}
562556

llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "llvm/Analysis/IRSimilarityIdentifier.h"
15+
#include "llvm/ADT/ScopeExit.h"
1516
#include "llvm/AsmParser/Parser.h"
1617
#include "llvm/IR/LLVMContext.h"
1718
#include "llvm/IR/Module.h"
@@ -22,6 +23,11 @@
2223
using namespace llvm;
2324
using namespace IRSimilarity;
2425

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+
2531
static std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context,
2632
StringRef ModuleStr) {
2733
SMDiagnostic Err;
@@ -1306,19 +1312,18 @@ TEST(IRInstructionMapper, CallBrInstIllegal) {
13061312
ASSERT_GT(UnsignedVec[0], Mapper.IllegalInstrNumber);
13071313
}
13081314

1309-
// Checks that an debuginfo intrinsics are mapped to be invisible. Since they
1315+
// Checks that an debuginfo records are mapped to be invisible. Since they
13101316
// do not semantically change the program, they can be recognized as similar.
13111317
TEST(IRInstructionMapper, DebugInfoInvisible) {
13121318
StringRef ModuleString = R"(
13131319
define i32 @f(i32 %a, i32 %b) {
13141320
then:
1315-
%0 = add i32 %a, %b
1316-
call void @llvm.dbg.value(metadata !0)
1317-
%1 = add i32 %a, %b
1321+
%0 = add i32 %a, %b
1322+
#dbg_value(i32 0, !0, !0, !0)
1323+
%1 = add i32 %a, %b
13181324
ret i32 0
13191325
}
13201326
1321-
declare void @llvm.dbg.value(metadata)
13221327
!0 = distinct !{!"test\00", i32 10})";
13231328
LLVMContext Context;
13241329
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
@@ -1914,19 +1919,19 @@ TEST(IRSimilarityCandidate, CheckRegionsDifferentTypes) {
19141919
ASSERT_FALSE(longSimCandCompare(InstrList));
19151920
}
19161921

1917-
// Check that debug instructions do not impact similarity. They are marked as
1922+
// Check that debug records do not impact similarity. They are marked as
19181923
// invisible.
19191924
TEST(IRSimilarityCandidate, IdenticalWithDebug) {
19201925
StringRef ModuleString = R"(
19211926
define i32 @f(i32 %a, i32 %b) {
19221927
bb0:
19231928
%0 = add i32 %a, %b
1924-
call void @llvm.dbg.value(metadata !0)
1929+
#dbg_value(i32 0, !0, !0, !0)
19251930
%1 = add i32 %b, %a
19261931
ret i32 0
19271932
bb1:
19281933
%2 = add i32 %a, %b
1929-
call void @llvm.dbg.value(metadata !1)
1934+
#dbg_value(i32 1, !1, !1, !1)
19301935
%3 = add i32 %b, %a
19311936
ret i32 0
19321937
bb2:
@@ -1935,7 +1940,6 @@ TEST(IRSimilarityCandidate, IdenticalWithDebug) {
19351940
ret i32 0
19361941
}
19371942
1938-
declare void @llvm.dbg.value(metadata)
19391943
!0 = distinct !{!"test\00", i32 10}
19401944
!1 = distinct !{!"test\00", i32 11})";
19411945
LLVMContext Context;

0 commit comments

Comments
 (0)