Skip to content

Commit c0de3f8

Browse files
committed
stephen's commit
1 parent da57609 commit c0de3f8

File tree

15 files changed

+132
-61
lines changed

15 files changed

+132
-61
lines changed

llvm/include/llvm/AsmParser/LLParser.h

Lines changed: 0 additions & 1 deletion
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

Lines changed: 16 additions & 18 deletions
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

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_TRUE;
4322+
LoadBitcodeIntoNewDbgInfoFormat != cl::boolOrDefault::BOU_FALSE;
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(false), Parent(nullptr) {
184+
IsNewDbgInfoFormat(UseNewDbgInfoFormat), Parent(nullptr) {
185185

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

llvm/lib/IR/Function.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ 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+
8688
void Function::convertToNewDbgValues() {
8789
IsNewDbgInfoFormat = true;
8890
for (auto &BB : *this) {
@@ -438,7 +440,7 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
438440
: GlobalObject(Ty, Value::FunctionVal,
439441
OperandTraits<Function>::op_begin(this), 0, Linkage, name,
440442
computeAddrSpace(AddrSpace, ParentModule)),
441-
NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(false) {
443+
NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
442444
assert(FunctionType::isValidReturnType(getReturnType()) &&
443445
"invalid return type");
444446
setGlobalObjectSubClassData(0);

llvm/lib/IR/Module.cpp

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 4 deletions
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

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-
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

Lines changed: 1 addition & 7 deletions
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

Lines changed: 32 additions & 0 deletions
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,27 @@
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+
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+
auto TempSettingChange() {
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+
2547
static std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context,
2648
StringRef ModuleStr) {
2749
SMDiagnostic Err;
@@ -1308,6 +1330,9 @@ TEST(IRInstructionMapper, CallBrInstIllegal) {
13081330

13091331
// Checks that an debuginfo intrinsics are mapped to be invisible. Since they
13101332
// 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.
13111336
TEST(IRInstructionMapper, DebugInfoInvisible) {
13121337
StringRef ModuleString = R"(
13131338
define i32 @f(i32 %a, i32 %b) {
@@ -1320,6 +1345,8 @@ TEST(IRInstructionMapper, DebugInfoInvisible) {
13201345
13211346
declare void @llvm.dbg.value(metadata)
13221347
!0 = distinct !{!"test\00", i32 10})";
1348+
auto SettingGuard = TempSettingChange();
1349+
PreserveInputDbgFormat = cl::boolOrDefault::BOU_TRUE;
13231350
LLVMContext Context;
13241351
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
13251352

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

19171944
// Check that debug instructions do not impact similarity. They are marked as
19181945
// 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.
19191949
TEST(IRSimilarityCandidate, IdenticalWithDebug) {
19201950
StringRef ModuleString = R"(
19211951
define i32 @f(i32 %a, i32 %b) {
@@ -1938,6 +1968,8 @@ TEST(IRSimilarityCandidate, IdenticalWithDebug) {
19381968
declare void @llvm.dbg.value(metadata)
19391969
!0 = distinct !{!"test\00", i32 10}
19401970
!1 = distinct !{!"test\00", i32 11})";
1971+
auto SettingGuard = TempSettingChange();
1972+
PreserveInputDbgFormat = cl::boolOrDefault::BOU_TRUE;
19411973
LLVMContext Context;
19421974
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
19431975

llvm/unittests/IR/BasicBlockDbgInfoTest.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ 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();
7775
// Fetch the entry block.
7876
BasicBlock &BB = M->getFunction("f")->getEntryBlock();
7977

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

107-
M->convertFromNewDbgValues();
108-
109105
UseNewDbgInfoFormat = false;
110106
}
111107

@@ -140,8 +136,6 @@ TEST(BasicBlockDbgInfoTest, MarkerOperations) {
140136

141137
// Fetch the entry block,
142138
BasicBlock &BB = M->getFunction("f")->getEntryBlock();
143-
// Convert the module to "new" form debug-info.
144-
M->convertToNewDbgValues();
145139
EXPECT_EQ(BB.size(), 2u);
146140

147141
// Fetch out our two markers,
@@ -276,8 +270,6 @@ TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
276270
// Test that the movement of debug-data when using moveBefore etc and
277271
// insertBefore etc are governed by the "head" bit of iterators.
278272
BasicBlock &BB = M->getFunction("f")->getEntryBlock();
279-
// Convert the module to "new" form debug-info.
280-
M->convertToNewDbgValues();
281273

282274
// Test that the head bit behaves as expected: it should be set when the
283275
// code wants the _start_ of the block, but not otherwise.
@@ -385,8 +377,6 @@ TEST(BasicBlockDbgInfoTest, InstrDbgAccess) {
385377
// Check that DbgVariableRecords can be accessed from Instructions without
386378
// digging into the depths of DbgMarkers.
387379
BasicBlock &BB = M->getFunction("f")->getEntryBlock();
388-
// Convert the module to "new" form debug-info.
389-
M->convertToNewDbgValues();
390380

391381
Instruction *BInst = &*BB.begin();
392382
Instruction *CInst = BInst->getNextNode();
@@ -523,7 +513,6 @@ class DbgSpliceTest : public ::testing::Test {
523513
void SetUp() override {
524514
UseNewDbgInfoFormat = true;
525515
M = parseIR(C, SpliceTestIR.c_str());
526-
M->convertToNewDbgValues();
527516

528517
BBEntry = &M->getFunction("f")->getEntryBlock();
529518
BBExit = BBEntry->getNextNode();
@@ -1163,7 +1152,6 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceTrailing) {
11631152

11641153
BasicBlock &Entry = M->getFunction("f")->getEntryBlock();
11651154
BasicBlock &Exit = *Entry.getNextNode();
1166-
M->convertToNewDbgValues();
11671155

11681156
// Begin by forcing entry block to have dangling DbgVariableRecord.
11691157
Entry.getTerminator()->eraseFromParent();
@@ -1217,7 +1205,6 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsert) {
12171205
)");
12181206

12191207
BasicBlock &Entry = M->getFunction("f")->getEntryBlock();
1220-
M->convertToNewDbgValues();
12211208

12221209
// Fetch the relevant instructions from the converted function.
12231210
Instruction *SubInst = &*Entry.begin();
@@ -1296,7 +1283,6 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsertForOneDbgVariableRecord) {
12961283
)");
12971284

12981285
BasicBlock &Entry = M->getFunction("f")->getEntryBlock();
1299-
M->convertToNewDbgValues();
13001286

13011287
// Fetch the relevant instructions from the converted function.
13021288
Instruction *SubInst = &*Entry.begin();
@@ -1380,7 +1366,6 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty1) {
13801366
Function &F = *M->getFunction("f");
13811367
BasicBlock &Entry = F.getEntryBlock();
13821368
BasicBlock &Exit = *Entry.getNextNode();
1383-
M->convertToNewDbgValues();
13841369

13851370
// Begin by forcing entry block to have dangling DbgVariableRecord.
13861371
Entry.getTerminator()->eraseFromParent();
@@ -1450,7 +1435,6 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty2) {
14501435
Function &F = *M->getFunction("f");
14511436
BasicBlock &Entry = F.getEntryBlock();
14521437
BasicBlock &Exit = *Entry.getNextNode();
1453-
M->convertToNewDbgValues();
14541438

14551439
// Begin by forcing entry block to have dangling DbgVariableRecord.
14561440
Entry.getTerminator()->eraseFromParent();
@@ -1520,7 +1504,6 @@ TEST(BasicBlockDbgInfoTest, DbgMoveToEnd) {
15201504
Function &F = *M->getFunction("f");
15211505
BasicBlock &Entry = F.getEntryBlock();
15221506
BasicBlock &Exit = *Entry.getNextNode();
1523-
M->convertToNewDbgValues();
15241507

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

llvm/unittests/IR/DebugInfoTest.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ TEST(DbgVariableIntrinsic, EmptyMDIsKillLocation) {
237237
// Duplicate of above test, but in DbgVariableRecord representation.
238238
TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) {
239239
LLVMContext C;
240+
bool OldDbgValueMode = UseNewDbgInfoFormat;
241+
UseNewDbgInfoFormat = true;
242+
240243
std::unique_ptr<Module> M = parseIR(C, R"(
241244
define i16 @f(i16 %a) !dbg !6 {
242245
%b = add i16 %a, 1, !dbg !11
@@ -262,10 +265,7 @@ TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) {
262265
!11 = !DILocation(line: 1, column: 1, scope: !6)
263266
)");
264267

265-
bool OldDbgValueMode = UseNewDbgInfoFormat;
266-
UseNewDbgInfoFormat = true;
267268
Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI();
268-
M->convertToNewDbgValues();
269269

270270
// Find the DbgVariableRecords using %b.
271271
SmallVector<DbgValueInst *, 2> DVIs;
@@ -1044,10 +1044,6 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
10441044
TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
10451045
LLVMContext C;
10461046

1047-
// For the purpose of this test, set and un-set the command line option
1048-
// corresponding to UseNewDbgInfoFormat.
1049-
UseNewDbgInfoFormat = true;
1050-
10511047
std::unique_ptr<Module> M = parseIR(C, R"(
10521048
define i16 @f(i16 %a) !dbg !6 {
10531049
call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11
@@ -1077,6 +1073,11 @@ TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
10771073
!11 = !DILocation(line: 1, column: 1, scope: !6)
10781074
)");
10791075

1076+
// For the purpose of this test, set and un-set the command line option
1077+
// corresponding to UseNewDbgInfoFormat, but only after parsing, to ensure
1078+
// that the IR starts off in the old format.
1079+
UseNewDbgInfoFormat = true;
1080+
10801081
// Check that the conversion routines and utilities between dbg.value
10811082
// debug-info format and DbgVariableRecords works.
10821083
Function *F = M->getFunction("f");

0 commit comments

Comments
 (0)