Skip to content

Commit a679a5b

Browse files
committed
[IR] Provide array with poison-generating metadata IDs.
Add Instruction::PoisonGeneratingMetadataIDs containing IDs of poison-generating metadata to allow easier re-use. Currently it is a static const array in Instruction, maybe here's a better place?
1 parent c25bd6e commit a679a5b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

llvm/include/llvm/IR/Instruction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ class Instruction : public User,
503503
/// Determine whether the the nneg flag is set.
504504
bool hasNonNeg() const LLVM_READONLY;
505505

506+
/// Metadata IDs that may generate poison.
507+
constexpr static const unsigned PoisonGeneratingMetadataIDs[] = {
508+
LLVMContext::MD_range, LLVMContext::MD_nonnull, LLVMContext::MD_align};
509+
506510
/// Return true if this operator has flags which may cause this instruction
507511
/// to evaluate to poison despite having non-poison inputs.
508512
bool hasPoisonGeneratingFlags() const LLVM_READONLY;

llvm/lib/IR/Instruction.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,8 @@ void Instruction::dropPoisonGeneratingFlags() {
458458
}
459459

460460
bool Instruction::hasPoisonGeneratingMetadata() const {
461-
return hasMetadata(LLVMContext::MD_range) ||
462-
hasMetadata(LLVMContext::MD_nonnull) ||
463-
hasMetadata(LLVMContext::MD_align);
461+
return any_of(PoisonGeneratingMetadataIDs,
462+
[this](unsigned ID) { return hasMetadata(ID); });
464463
}
465464

466465
bool Instruction::hasNonDebugLocLoopMetadata() const {
@@ -487,9 +486,8 @@ bool Instruction::hasNonDebugLocLoopMetadata() const {
487486
}
488487

489488
void Instruction::dropPoisonGeneratingMetadata() {
490-
eraseMetadata(LLVMContext::MD_range);
491-
eraseMetadata(LLVMContext::MD_nonnull);
492-
eraseMetadata(LLVMContext::MD_align);
489+
for (unsigned ID : PoisonGeneratingMetadataIDs)
490+
eraseMetadata(ID);
493491
}
494492

495493
bool Instruction::hasPoisonGeneratingReturnAttributes() const {

0 commit comments

Comments
 (0)