[llvm] [NFC][LLVM] Document and adopt variadic `isa` in a few places (PR #136869)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 23 09:04:22 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
- Add mention of variadic `isa<>` in the LLVM Programmers Manual.
- Adopt it in a new places, there are several more throughout the codebase.
---
Full diff: https://github.com/llvm/llvm-project/pull/136869.diff
8 Files Affected:
- (modified) llvm/docs/ProgrammersManual.rst (+9-2)
- (modified) llvm/tools/llvm-diff/lib/DifferenceEngine.cpp (+1-1)
- (modified) llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp (+1-1)
- (modified) llvm/tools/llvm-reduce/deltas/Utils.cpp (+2-3)
- (modified) llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp (+1-1)
- (modified) llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp (+1-1)
- (modified) llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp (+1-1)
- (modified) llvm/utils/TableGen/SearchableTableEmitter.cpp (+1-1)
``````````diff
diff --git a/llvm/docs/ProgrammersManual.rst b/llvm/docs/ProgrammersManual.rst
index bb729597cc5a3..4aaae98713426 100644
--- a/llvm/docs/ProgrammersManual.rst
+++ b/llvm/docs/ProgrammersManual.rst
@@ -115,7 +115,9 @@ rarely have to include this file directly).
The ``isa<>`` operator works exactly like the Java "``instanceof``" operator.
It returns true or false depending on whether a reference or pointer points to
an instance of the specified class. This can be very useful for constraint
- checking of various sorts (example below).
+ checking of various sorts (example below). It's a variadic operator, so you
+ can specify more than one class to check if the reference or pointer points
+ to an instance of one of the classes specified.
``cast<>``:
The ``cast<>`` operator is a "checked cast" operation. It converts a pointer
@@ -131,6 +133,10 @@ rarely have to include this file directly).
if (isa<Constant>(V) || isa<Argument>(V) || isa<GlobalValue>(V))
return true;
+ // Alternatively, a more compact form is:
+ if (isa<Constant, Argument, GlobalValue>(V))
+ return true;
+
// Otherwise, it must be an instruction...
return !L->contains(cast<Instruction>(V)->getParent());
}
@@ -168,7 +174,8 @@ rarely have to include this file directly).
The ``isa_and_present<>`` operator works just like the ``isa<>`` operator,
except that it allows for a null pointer as an argument (which it then
returns false). This can sometimes be useful, allowing you to combine several
- null checks into one.
+ null checks into one. Similar to ``isa<>`` operator, you can specify more than
+ one classes to check.
``cast_if_present<>``:
The ``cast_if_present<>`` operator works just like the ``cast<>`` operator,
diff --git a/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp b/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
index 9be0eec7b73f3..f301872454fc3 100644
--- a/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
+++ b/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
@@ -569,7 +569,7 @@ class FunctionDifferenceEngine {
// Constants of the "same type" don't always actually have the same
// type; I don't know why. Just white-list them.
- if (isa<ConstantPointerNull>(L) || isa<UndefValue>(L) || isa<ConstantAggregateZero>(L))
+ if (isa<ConstantPointerNull, UndefValue, ConstantAggregateZero>(L))
return true;
// Block addresses only match if we've already encountered the
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp b/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
index 34e0791d4e974..f4fb13ce16587 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
@@ -63,7 +63,7 @@ void identifyUninterestingMDNodes(Oracle &O, MDNodeList &MDs) {
for (size_t I = 0; I < Tup->getNumOperands(); ++I) {
// Ignore any operands that are not DebugInfo metadata nodes.
if (Metadata *Op = Tup->getOperand(I).get()) {
- if (isa<DINode>(Op) || isa<DIGlobalVariableExpression>(Op))
+ if (isa<DINode, DIGlobalVariableExpression>(Op))
// Don't add uninteresting operands to the tuple.
if (!O.shouldKeep())
continue;
diff --git a/llvm/tools/llvm-reduce/deltas/Utils.cpp b/llvm/tools/llvm-reduce/deltas/Utils.cpp
index a980a0f9fad2f..00f583fb2a1b0 100644
--- a/llvm/tools/llvm-reduce/deltas/Utils.cpp
+++ b/llvm/tools/llvm-reduce/deltas/Utils.cpp
@@ -39,9 +39,8 @@ Value *llvm::getDefaultValue(Type *T) {
}
bool llvm::hasAliasUse(Function &F) {
- return any_of(F.users(), [](User *U) {
- return isa<GlobalAlias>(U) || isa<GlobalIFunc>(U);
- });
+ return any_of(F.users(),
+ [](User *U) { return isa<GlobalAlias, GlobalIFunc>(U); });
}
bool llvm::hasAliasOrBlockAddressUse(Function &F) {
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 7f58c4a88c76d..1539ffe0fd4b5 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -2915,7 +2915,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
return Res;
}
- if (isa<IntInit>(TheInit) || isa<BitInit>(TheInit)) {
+ if (isa<IntInit, BitInit>(TheInit)) {
if (!OpName.empty())
error("Constant int or bit argument should not have a name!");
if (isa<BitInit>(TheInit))
diff --git a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
index 4c809b4016cbd..9a16f5c5297d8 100644
--- a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
+++ b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
@@ -558,7 +558,7 @@ void GroupMatcher::optimize() {
//===- SwitchMatcher ------------------------------------------------------===//
bool SwitchMatcher::isSupportedPredicateType(const PredicateMatcher &P) {
- return isa<InstructionOpcodeMatcher>(P) || isa<LLTOperandMatcher>(P);
+ return isa<InstructionOpcodeMatcher, LLTOperandMatcher>(P);
}
bool SwitchMatcher::candidateConditionMatches(
diff --git a/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp b/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
index 0a835bd7b0bc0..91e2e7623b609 100644
--- a/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
@@ -463,7 +463,7 @@ std::string VarLenCodeEmitterGen::getInstructionCaseForEncoding(
const Init *Val = ES.Value;
// If it's a StringInit or DagInit, it's a reference to an operand
// or part of an operand.
- if (isa<StringInit>(Val) || isa<DagInit>(Val)) {
+ if (isa<StringInit, DagInit>(Val)) {
StringRef OperandName;
unsigned LoBit = 0U;
if (const auto *SV = dyn_cast<StringInit>(Val)) {
diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index 7251a1ba545d5..c91588b9cb02b 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -237,7 +237,7 @@ bool SearchableTableEmitter::compareBy(const Record *LHS, const Record *RHS,
const Init *LHSI = LHS->getValueInit(Field.Name);
const Init *RHSI = RHS->getValueInit(Field.Name);
- if (isa<BitsRecTy>(Field.RecType) || isa<IntRecTy>(Field.RecType)) {
+ if (isa<BitsRecTy, IntRecTy>(Field.RecType)) {
int64_t LHSi = getAsInt(LHSI);
int64_t RHSi = getAsInt(RHSI);
if (LHSi < RHSi)
``````````
</details>
https://github.com/llvm/llvm-project/pull/136869
More information about the llvm-commits
mailing list