[llvm] 8c75ecb - [IR] Provide array with poison-generating metadata IDs. (#123188)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 16 12:46:01 PST 2025
Author: Florian Hahn
Date: 2025-01-16T20:45:56Z
New Revision: 8c75ecb373059f2eed020ad0218313bba9f90b3d
URL: https://github.com/llvm/llvm-project/commit/8c75ecb373059f2eed020ad0218313bba9f90b3d
DIFF: https://github.com/llvm/llvm-project/commit/8c75ecb373059f2eed020ad0218313bba9f90b3d.diff
LOG: [IR] Provide array with poison-generating metadata IDs. (#123188)
Add Metadata::PoisonGeneratingIDs containing IDs of poison-generating
metadata to allow easier re-use.
PR: https://github.com/llvm/llvm-project/pull/123188
Added:
Modified:
llvm/include/llvm/IR/Metadata.h
llvm/lib/IR/Instruction.cpp
llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index df2384c5f6e69a..ec7d030a20de8c 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -138,6 +138,10 @@ class Metadata {
void printAsOperand(raw_ostream &OS, ModuleSlotTracker &MST,
const Module *M = nullptr) const;
/// @}
+
+ /// Metadata IDs that may generate poison.
+ constexpr static const unsigned PoisonGeneratingIDs[] = {
+ LLVMContext::MD_range, LLVMContext::MD_nonnull, LLVMContext::MD_align};
};
// Create wrappers for C Binding types (see CBindingWrapping.h).
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 147cd84125c8d1..9eaae62a6390b7 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -458,9 +458,8 @@ void Instruction::dropPoisonGeneratingFlags() {
}
bool Instruction::hasPoisonGeneratingMetadata() const {
- return hasMetadata(LLVMContext::MD_range) ||
- hasMetadata(LLVMContext::MD_nonnull) ||
- hasMetadata(LLVMContext::MD_align);
+ return any_of(Metadata::PoisonGeneratingIDs,
+ [this](unsigned ID) { return hasMetadata(ID); });
}
bool Instruction::hasNonDebugLocLoopMetadata() const {
@@ -487,9 +486,8 @@ bool Instruction::hasNonDebugLocLoopMetadata() const {
}
void Instruction::dropPoisonGeneratingMetadata() {
- eraseMetadata(LLVMContext::MD_range);
- eraseMetadata(LLVMContext::MD_nonnull);
- eraseMetadata(LLVMContext::MD_align);
+ for (unsigned ID : Metadata::PoisonGeneratingIDs)
+ eraseMetadata(ID);
}
bool Instruction::hasPoisonGeneratingReturnAttributes() const {
diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
index d540e6ca86154c..c440638884322c 100644
--- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -259,8 +259,7 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
// all promoted loads.
if (LI->hasMetadata(LLVMContext::MD_noundef))
LI->copyMetadata(*Pair.second.MustExecInstr,
- {LLVMContext::MD_range, LLVMContext::MD_nonnull,
- LLVMContext::MD_align});
+ Metadata::PoisonGeneratingIDs);
}
Args.push_back(LI);
ArgAttrVec.push_back(AttributeSet());
More information about the llvm-commits
mailing list