Skip to content

Commit 73dfdf5

Browse files
jmorsetomtor
authored andcommitted
Reapply 76197ea after removing an assertion
Specifically this is the assertion in BasicBlock.cpp. Now that we're not examining or setting that flag consistently (because it'll be deleted in about an hour) there's no need to keep this assertion. Original commit title: [DebugInfo][RemoveDIs] Remove some debug intrinsic-only codepaths (llvm#143451)
1 parent b207cd9 commit 73dfdf5

File tree

7 files changed

+40
-151
lines changed

7 files changed

+40
-151
lines changed

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,9 +1671,6 @@ void FastISel::fastEmitBranch(MachineBasicBlock *MSucc,
16711671
const DebugLoc &DbgLoc) {
16721672
const BasicBlock *BB = FuncInfo.MBB->getBasicBlock();
16731673
bool BlockHasMultipleInstrs = &BB->front() != &BB->back();
1674-
// Handle legacy case of debug intrinsics
1675-
if (BlockHasMultipleInstrs && !BB->getModule()->IsNewDbgInfoFormat)
1676-
BlockHasMultipleInstrs = BB->sizeWithoutDebug() > 1;
16771674
if (BlockHasMultipleInstrs && FuncInfo.MBB->isLayoutSuccessor(MSucc)) {
16781675
// For more accurate line information if this is the only non-debug
16791676
// instruction in the block then emit it, otherwise we have the

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4490,7 +4490,6 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
44904490
Builder.SetInsertPoint(CI->getParent(), CI->getIterator());
44914491

44924492
if (!NewFn) {
4493-
bool FallthroughToDefaultUpgrade = false;
44944493
// Get the Function's name.
44954494
StringRef Name = F->getName();
44964495

@@ -4518,29 +4517,15 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
45184517
} else if (IsAMDGCN) {
45194518
Rep = upgradeAMDGCNIntrinsicCall(Name, CI, F, Builder);
45204519
} else if (IsDbg) {
4521-
// We might have decided we don't want the new format after all between
4522-
// first requesting the upgrade and now; skip the conversion if that is
4523-
// the case, and check here to see if the intrinsic needs to be upgraded
4524-
// normally.
4525-
if (!CI->getModule()->IsNewDbgInfoFormat) {
4526-
bool NeedsUpgrade =
4527-
upgradeIntrinsicFunction1(CI->getCalledFunction(), NewFn, false);
4528-
if (!NeedsUpgrade)
4529-
return;
4530-
FallthroughToDefaultUpgrade = true;
4531-
} else {
4532-
upgradeDbgIntrinsicToDbgRecord(Name, CI);
4533-
}
4520+
upgradeDbgIntrinsicToDbgRecord(Name, CI);
45344521
} else {
45354522
llvm_unreachable("Unknown function for CallBase upgrade.");
45364523
}
45374524

4538-
if (!FallthroughToDefaultUpgrade) {
4539-
if (Rep)
4540-
CI->replaceAllUsesWith(Rep);
4541-
CI->eraseFromParent();
4542-
return;
4543-
}
4525+
if (Rep)
4526+
CI->replaceAllUsesWith(Rep);
4527+
CI->eraseFromParent();
4528+
return;
45444529
}
45454530

45464531
const auto &DefaultCase = [&]() -> void {

llvm/lib/IR/BasicBlock.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ void BasicBlock::convertToNewDbgValues() {
6060
// instruction.
6161
SmallVector<DbgRecord *, 4> DbgVarRecs;
6262
for (Instruction &I : make_early_inc_range(InstList)) {
63-
assert(!I.DebugMarker && "DebugMarker already set on old-format instrs?");
6463
if (DbgVariableIntrinsic *DVI = dyn_cast<DbgVariableIntrinsic>(&I)) {
6564
// Convert this dbg.value to a DbgVariableRecord.
6665
DbgVariableRecord *Value = new DbgVariableRecord(DVI);

llvm/lib/IR/DIBuilder.cpp

Lines changed: 20 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,36 +1047,13 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
10471047
LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID));
10481048
assert(Link && "Linked instruction must have DIAssign metadata attached");
10491049

1050-
if (M.IsNewDbgInfoFormat) {
1051-
DbgVariableRecord *DVR = DbgVariableRecord::createDVRAssign(
1052-
Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
1053-
// Insert after LinkedInstr.
1054-
BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
1055-
NextIt.setHeadBit(true);
1056-
insertDbgVariableRecord(DVR, NextIt);
1057-
return DVR;
1058-
}
1059-
1060-
LLVMContext &Ctx = LinkedInstr->getContext();
1061-
Module *M = LinkedInstr->getModule();
1062-
if (!AssignFn)
1063-
AssignFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_assign);
1064-
1065-
std::array<Value *, 6> Args = {
1066-
MetadataAsValue::get(Ctx, ValueAsMetadata::get(Val)),
1067-
MetadataAsValue::get(Ctx, SrcVar),
1068-
MetadataAsValue::get(Ctx, ValExpr),
1069-
MetadataAsValue::get(Ctx, Link),
1070-
MetadataAsValue::get(Ctx, ValueAsMetadata::get(Addr)),
1071-
MetadataAsValue::get(Ctx, AddrExpr),
1072-
};
1073-
1074-
IRBuilder<> B(Ctx);
1075-
B.SetCurrentDebugLocation(DL);
1076-
1077-
auto *DVI = cast<DbgAssignIntrinsic>(B.CreateCall(AssignFn, Args));
1078-
DVI->insertAfter(LinkedInstr->getIterator());
1079-
return DVI;
1050+
DbgVariableRecord *DVR = DbgVariableRecord::createDVRAssign(
1051+
Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
1052+
// Insert after LinkedInstr.
1053+
BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
1054+
NextIt.setHeadBit(true);
1055+
insertDbgVariableRecord(DVR, NextIt);
1056+
return DVR;
10801057
}
10811058

10821059
/// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
@@ -1101,18 +1078,10 @@ DbgInstPtr DIBuilder::insertDbgValueIntrinsic(llvm::Value *Val,
11011078
DIExpression *Expr,
11021079
const DILocation *DL,
11031080
InsertPosition InsertPt) {
1104-
if (M.IsNewDbgInfoFormat) {
1105-
DbgVariableRecord *DVR =
1106-
DbgVariableRecord::createDbgVariableRecord(Val, VarInfo, Expr, DL);
1107-
insertDbgVariableRecord(DVR, InsertPt);
1108-
return DVR;
1109-
}
1110-
1111-
if (!ValueFn)
1112-
ValueFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_value);
1113-
auto *DVI = insertDbgIntrinsic(ValueFn, Val, VarInfo, Expr, DL, InsertPt);
1114-
cast<CallInst>(DVI)->setTailCall();
1115-
return DVI;
1081+
DbgVariableRecord *DVR =
1082+
DbgVariableRecord::createDbgVariableRecord(Val, VarInfo, Expr, DL);
1083+
insertDbgVariableRecord(DVR, InsertPt);
1084+
return DVR;
11161085
}
11171086

11181087
DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
@@ -1124,25 +1093,10 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
11241093
VarInfo->getScope()->getSubprogram() &&
11251094
"Expected matching subprograms");
11261095

1127-
if (M.IsNewDbgInfoFormat) {
1128-
DbgVariableRecord *DVR =
1129-
DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
1130-
insertDbgVariableRecord(DVR, InsertPt);
1131-
return DVR;
1132-
}
1133-
1134-
if (!DeclareFn)
1135-
DeclareFn = getDeclareIntrin(M);
1136-
1137-
trackIfUnresolved(VarInfo);
1138-
trackIfUnresolved(Expr);
1139-
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
1140-
MetadataAsValue::get(VMContext, VarInfo),
1141-
MetadataAsValue::get(VMContext, Expr)};
1142-
1143-
IRBuilder<> B(DL->getContext());
1144-
initIRBuilder(B, DL, InsertPt);
1145-
return B.CreateCall(DeclareFn, Args);
1096+
DbgVariableRecord *DVR =
1097+
DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
1098+
insertDbgVariableRecord(DVR, InsertPt);
1099+
return DVR;
11461100
}
11471101

11481102
void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
@@ -1191,23 +1145,12 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
11911145
"Expected matching subprograms");
11921146

11931147
trackIfUnresolved(LabelInfo);
1194-
if (M.IsNewDbgInfoFormat) {
1195-
DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
1196-
if (InsertPt.isValid()) {
1197-
auto *BB = InsertPt.getBasicBlock();
1198-
BB->insertDbgRecordBefore(DLR, InsertPt);
1199-
}
1200-
return DLR;
1148+
DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
1149+
if (InsertPt.isValid()) {
1150+
auto *BB = InsertPt.getBasicBlock();
1151+
BB->insertDbgRecordBefore(DLR, InsertPt);
12011152
}
1202-
1203-
if (!LabelFn)
1204-
LabelFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_label);
1205-
1206-
Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)};
1207-
1208-
IRBuilder<> B(DL->getContext());
1209-
initIRBuilder(B, DL, InsertPt);
1210-
return B.CreateCall(LabelFn, Args);
1153+
return DLR;
12111154
}
12121155

12131156
void DIBuilder::replaceVTableHolder(DICompositeType *&T, DIType *VTableHolder) {

llvm/lib/IR/DebugInfo.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,22 +2123,11 @@ static void emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
21232123
Expr = *R;
21242124
}
21252125
DIExpression *AddrExpr = DIExpression::get(StoreLikeInst.getContext(), {});
2126-
if (StoreLikeInst.getParent()->IsNewDbgInfoFormat) {
2127-
auto *Assign = DbgVariableRecord::createLinkedDVRAssign(
2128-
&StoreLikeInst, Val, VarRec.Var, Expr, Dest, AddrExpr, VarRec.DL);
2129-
(void)Assign;
2130-
LLVM_DEBUG(if (Assign) errs() << " > INSERT: " << *Assign << "\n");
2131-
return;
2132-
}
2133-
auto Assign = DIB.insertDbgAssign(&StoreLikeInst, Val, VarRec.Var, Expr, Dest,
2134-
AddrExpr, VarRec.DL);
2126+
auto *Assign = DbgVariableRecord::createLinkedDVRAssign(
2127+
&StoreLikeInst, Val, VarRec.Var, Expr, Dest, AddrExpr, VarRec.DL);
21352128
(void)Assign;
2136-
LLVM_DEBUG(if (!Assign.isNull()) {
2137-
if (const auto *Record = dyn_cast<DbgRecord *>(Assign))
2138-
errs() << " > INSERT: " << *Record << "\n";
2139-
else
2140-
errs() << " > INSERT: " << *cast<Instruction *>(Assign) << "\n";
2141-
});
2129+
LLVM_DEBUG(if (Assign) errs() << " > INSERT: " << *Assign << "\n");
2130+
return;
21422131
}
21432132

21442133
#undef DEBUG_TYPE // Silence redefinition warning (from ConstantsContext.h).

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
606606

607607
// Use a map to unique and a vector to guarantee deterministic ordering.
608608
llvm::SmallDenseSet<DebugVariable, 4> DeadDebugSet;
609-
llvm::SmallVector<DbgVariableIntrinsic *, 4> DeadDebugInst;
610609
llvm::SmallVector<DbgVariableRecord *, 4> DeadDbgVariableRecords;
611610

612611
if (ExitBlock) {
@@ -633,29 +632,19 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
633632
U.set(Poison);
634633
}
635634

636-
// RemoveDIs: do the same as below for DbgVariableRecords.
637-
if (Block->IsNewDbgInfoFormat) {
638-
for (DbgVariableRecord &DVR : llvm::make_early_inc_range(
639-
filterDbgVars(I.getDbgRecordRange()))) {
640-
DebugVariable Key(DVR.getVariable(), DVR.getExpression(),
641-
DVR.getDebugLoc().get());
642-
if (!DeadDebugSet.insert(Key).second)
643-
continue;
644-
// Unlinks the DVR from it's container, for later insertion.
645-
DVR.removeFromParent();
646-
DeadDbgVariableRecords.push_back(&DVR);
647-
}
648-
}
649-
650-
// For one of each variable encountered, preserve a debug intrinsic (set
635+
// For one of each variable encountered, preserve a debug record (set
651636
// to Poison) and transfer it to the loop exit. This terminates any
652637
// variable locations that were set during the loop.
653-
auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I);
654-
if (!DVI)
655-
continue;
656-
if (!DeadDebugSet.insert(DebugVariable(DVI)).second)
657-
continue;
658-
DeadDebugInst.push_back(DVI);
638+
for (DbgVariableRecord &DVR :
639+
llvm::make_early_inc_range(filterDbgVars(I.getDbgRecordRange()))) {
640+
DebugVariable Key(DVR.getVariable(), DVR.getExpression(),
641+
DVR.getDebugLoc().get());
642+
if (!DeadDebugSet.insert(Key).second)
643+
continue;
644+
// Unlinks the DVR from it's container, for later insertion.
645+
DVR.removeFromParent();
646+
DeadDbgVariableRecords.push_back(&DVR);
647+
}
659648
}
660649

661650
// After the loop has been deleted all the values defined and modified
@@ -671,9 +660,6 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
671660
"There should be a non-PHI instruction in exit block, else these "
672661
"instructions will have no parent.");
673662

674-
for (auto *DVI : DeadDebugInst)
675-
DVI->moveBefore(*ExitBlock, InsertDbgValueBefore);
676-
677663
// Due to the "head" bit in BasicBlock::iterator, we're going to insert
678664
// each DbgVariableRecord right at the start of the block, wheras dbg.values
679665
// would be repeatedly inserted before the first instruction. To replicate

llvm/unittests/IR/IRBuilderTest.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,18 +1003,8 @@ TEST_F(IRBuilderTest, DIBuilder) {
10031003
EXPECT_TRUE(verifyModule(*M));
10041004
};
10051005

1006-
// Test in new-debug mode.
1007-
EXPECT_TRUE(M->IsNewDbgInfoFormat);
10081006
RunTest();
1009-
1010-
// Test in old-debug mode.
1011-
// Reset the test then call convertFromNewDbgValues to flip the flag
1012-
// on the test's Module, Function and BasicBlock.
10131007
TearDown();
1014-
SetUp();
1015-
M->convertFromNewDbgValues();
1016-
EXPECT_FALSE(M->IsNewDbgInfoFormat);
1017-
RunTest();
10181008
}
10191009

10201010
TEST_F(IRBuilderTest, createArtificialSubprogram) {

0 commit comments

Comments
 (0)