[llvm] 68f0937 - [Module] Use getDeclarationIfExists() (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 24 06:37:34 PDT 2025
Author: Nikita Popov
Date: 2025-06-24T15:37:27+02:00
New Revision: 68f09370f99f1c079827f1d1e2e5774d8d2c90e3
URL: https://github.com/llvm/llvm-project/commit/68f09370f99f1c079827f1d1e2e5774d8d2c90e3
DIFF: https://github.com/llvm/llvm-project/commit/68f09370f99f1c079827f1d1e2e5774d8d2c90e3.diff
LOG: [Module] Use getDeclarationIfExists() (NFC)
Don't insert declarations in order to immediately remove them
again.
Added:
Modified:
llvm/lib/IR/Module.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 2d31481f62c67..70d364176062f 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -119,26 +119,30 @@ Module::~Module() {
}
void Module::removeDebugIntrinsicDeclarations() {
- auto *DeclareIntrinsicFn =
- Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_declare);
- assert((!isMaterialized() || DeclareIntrinsicFn->hasZeroLiveUses()) &&
- "Debug declare intrinsic should have had uses removed.");
- DeclareIntrinsicFn->eraseFromParent();
- auto *ValueIntrinsicFn =
- Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_value);
- assert((!isMaterialized() || ValueIntrinsicFn->hasZeroLiveUses()) &&
- "Debug value intrinsic should have had uses removed.");
- ValueIntrinsicFn->eraseFromParent();
- auto *AssignIntrinsicFn =
- Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_assign);
- assert((!isMaterialized() || AssignIntrinsicFn->hasZeroLiveUses()) &&
- "Debug assign intrinsic should have had uses removed.");
- AssignIntrinsicFn->eraseFromParent();
- auto *LabelntrinsicFn =
- Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_label);
- assert((!isMaterialized() || LabelntrinsicFn->hasZeroLiveUses()) &&
- "Debug label intrinsic should have had uses removed.");
- LabelntrinsicFn->eraseFromParent();
+ if (auto *DeclareIntrinsicFn =
+ Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_declare)) {
+ assert((!isMaterialized() || DeclareIntrinsicFn->hasZeroLiveUses()) &&
+ "Debug declare intrinsic should have had uses removed.");
+ DeclareIntrinsicFn->eraseFromParent();
+ }
+ if (auto *ValueIntrinsicFn =
+ Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_value)) {
+ assert((!isMaterialized() || ValueIntrinsicFn->hasZeroLiveUses()) &&
+ "Debug value intrinsic should have had uses removed.");
+ ValueIntrinsicFn->eraseFromParent();
+ }
+ if (auto *AssignIntrinsicFn =
+ Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_assign)) {
+ assert((!isMaterialized() || AssignIntrinsicFn->hasZeroLiveUses()) &&
+ "Debug assign intrinsic should have had uses removed.");
+ AssignIntrinsicFn->eraseFromParent();
+ }
+ if (auto *LabelntrinsicFn =
+ Intrinsic::getDeclarationIfExists(this, Intrinsic::dbg_label)) {
+ assert((!isMaterialized() || LabelntrinsicFn->hasZeroLiveUses()) &&
+ "Debug label intrinsic should have had uses removed.");
+ LabelntrinsicFn->eraseFromParent();
+ }
}
std::unique_ptr<RandomNumberGenerator>
More information about the llvm-commits
mailing list