Skip to content

Commit 68f0937

Browse files
committed
[Module] Use getDeclarationIfExists() (NFC)
Don't insert declarations in order to immediately remove them again.
1 parent 75cf826 commit 68f0937

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

llvm/lib/IR/Module.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,30 @@ Module::~Module() {
119119
}
120120

121121
void Module::removeDebugIntrinsicDeclarations() {
122-
auto *DeclareIntrinsicFn =
123-
Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_declare);
124-
assert((!isMaterialized() || DeclareIntrinsicFn->hasZeroLiveUses()) &&
125-
"Debug declare intrinsic should have had uses removed.");
126-
DeclareIntrinsicFn->eraseFromParent();
127-
auto *ValueIntrinsicFn =
128-
Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_value);
129-
assert((!isMaterialized() || ValueIntrinsicFn->hasZeroLiveUses()) &&
130-
"Debug value intrinsic should have had uses removed.");
131-
ValueIntrinsicFn->eraseFromParent();
132-
auto *AssignIntrinsicFn =
133-
Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_assign);
134-
assert((!isMaterialized() || AssignIntrinsicFn->hasZeroLiveUses()) &&
135-
"Debug assign intrinsic should have had uses removed.");
136-
AssignIntrinsicFn->eraseFromParent();
137-
auto *LabelntrinsicFn =
138-
Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_label);
139-
assert((!isMaterialized() || LabelntrinsicFn->hasZeroLiveUses()) &&
140-
"Debug label intrinsic should have had uses removed.");
141-
LabelntrinsicFn->eraseFromParent();
122+
if (auto *DeclareIntrinsicFn =
123+
Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_declare)) {
124+
assert((!isMaterialized() || DeclareIntrinsicFn->hasZeroLiveUses()) &&
125+
"Debug declare intrinsic should have had uses removed.");
126+
DeclareIntrinsicFn->eraseFromParent();
127+
}
128+
if (auto *ValueIntrinsicFn =
129+
Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_value)) {
130+
assert((!isMaterialized() || ValueIntrinsicFn->hasZeroLiveUses()) &&
131+
"Debug value intrinsic should have had uses removed.");
132+
ValueIntrinsicFn->eraseFromParent();
133+
}
134+
if (auto *AssignIntrinsicFn =
135+
Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_assign)) {
136+
assert((!isMaterialized() || AssignIntrinsicFn->hasZeroLiveUses()) &&
137+
"Debug assign intrinsic should have had uses removed.");
138+
AssignIntrinsicFn->eraseFromParent();
139+
}
140+
if (auto *LabelntrinsicFn =
141+
Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_label)) {
142+
assert((!isMaterialized() || LabelntrinsicFn->hasZeroLiveUses()) &&
143+
"Debug label intrinsic should have had uses removed.");
144+
LabelntrinsicFn->eraseFromParent();
145+
}
142146
}
143147

144148
std::unique_ptr<RandomNumberGenerator>

0 commit comments

Comments
 (0)