Skip to content

Commit c5c1ec1

Browse files
committed
[DebugInfo][RemoveDIs] Remove some debug intrinsic-only codepaths
FastISel: we don't need to do debug-aware instruction counting any more, because there are no debug instructions, Autoupgrade: you can no-longer avoid autoupgrading of intrinsics to records DIBuilder: Delete the code for creating debug intrinsics (!) LoopUtils: No need to handle debug intructions, they don't exist These are opportunistic deletions as more places that make use of the IsNewDbgInfoFormat flag are removed.
1 parent 7433d8c commit c5c1ec1

File tree

6 files changed

+40
-150
lines changed

6 files changed

+40
-150
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
@@ -4463,7 +4463,6 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
44634463
Builder.SetInsertPoint(CI->getParent(), CI->getIterator());
44644464

44654465
if (!NewFn) {
4466-
bool FallthroughToDefaultUpgrade = false;
44674466
// Get the Function's name.
44684467
StringRef Name = F->getName();
44694468

@@ -4491,29 +4490,15 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
44914490
} else if (IsAMDGCN) {
44924491
Rep = upgradeAMDGCNIntrinsicCall(Name, CI, F, Builder);
44934492
} else if (IsDbg) {
4494-
// We might have decided we don't want the new format after all between
4495-
// first requesting the upgrade and now; skip the conversion if that is
4496-
// the case, and check here to see if the intrinsic needs to be upgraded
4497-
// normally.
4498-
if (!CI->getModule()->IsNewDbgInfoFormat) {
4499-
bool NeedsUpgrade =
4500-
upgradeIntrinsicFunction1(CI->getCalledFunction(), NewFn, false);
4501-
if (!NeedsUpgrade)
4502-
return;
4503-
FallthroughToDefaultUpgrade = true;
4504-
} else {
4505-
upgradeDbgIntrinsicToDbgRecord(Name, CI);
4506-
}
4493+
upgradeDbgIntrinsicToDbgRecord(Name, CI);
45074494
} else {
45084495
llvm_unreachable("Unknown function for CallBase upgrade.");
45094496
}
45104497

4511-
if (!FallthroughToDefaultUpgrade) {
4512-
if (Rep)
4513-
CI->replaceAllUsesWith(Rep);
4514-
CI->eraseFromParent();
4515-
return;
4516-
}
4498+
if (Rep)
4499+
CI->replaceAllUsesWith(Rep);
4500+
CI->eraseFromParent();
4501+
return;
45174502
}
45184503

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

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
@@ -605,7 +605,6 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
605605

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

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

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

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

673-
for (auto *DVI : DeadDebugInst)
674-
DVI->moveBefore(*ExitBlock, InsertDbgValueBefore);
675-
676662
// Due to the "head" bit in BasicBlock::iterator, we're going to insert
677663
// each DbgVariableRecord right at the start of the block, wheras dbg.values
678664
// 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
@@ -1011,18 +1011,8 @@ TEST_F(IRBuilderTest, DIBuilder) {
10111011
EXPECT_TRUE(verifyModule(*M));
10121012
};
10131013

1014-
// Test in new-debug mode.
1015-
EXPECT_TRUE(M->IsNewDbgInfoFormat);
10161014
RunTest();
1017-
1018-
// Test in old-debug mode.
1019-
// Reset the test then call convertFromNewDbgValues to flip the flag
1020-
// on the test's Module, Function and BasicBlock.
10211015
TearDown();
1022-
SetUp();
1023-
M->convertFromNewDbgValues();
1024-
EXPECT_FALSE(M->IsNewDbgInfoFormat);
1025-
RunTest();
10261016
}
10271017

10281018
TEST_F(IRBuilderTest, createArtificialSubprogram) {

0 commit comments

Comments
 (0)