-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[NFC][LLVM] Document and adopt variadic isa
in a few places
#136869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jurahul
wants to merge
2
commits into
llvm:main
Choose a base branch
from
jurahul:document_varadic_isa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-globalisel Author: Rahul Joshi (jurahul) Changes
Full diff: https://github.com/llvm/llvm-project/pull/136869.diff 8 Files Affected:
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)
|
@llvm/pr-subscribers-tablegen Author: Rahul Joshi (jurahul) Changes
Full diff: https://github.com/llvm/llvm-project/pull/136869.diff 8 Files Affected:
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)
|
- Add mention of variadic `isa<>` in the LLVM Programmers Manual. - Adopt it in a new places, there are several more throughout the codebase.
0d10e96
to
961ca57
Compare
arsenm
reviewed
Apr 23, 2025
Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
isa<>
in the LLVM Programmer's Manual.