Skip to content

Commit 0d10e96

Browse files
committed
[NFC][LLVM] Document and adopt variadic isa in a few places
- Add mention of variadic `isa<>` in the LLVM Programmers Manual. - Adopt it in a new places, there are several more throughout the codebase.
1 parent 34a4c58 commit 0d10e96

File tree

8 files changed

+17
-11
lines changed

8 files changed

+17
-11
lines changed

llvm/docs/ProgrammersManual.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ rarely have to include this file directly).
115115
The ``isa<>`` operator works exactly like the Java "``instanceof``" operator.
116116
It returns true or false depending on whether a reference or pointer points to
117117
an instance of the specified class. This can be very useful for constraint
118-
checking of various sorts (example below).
118+
checking of various sorts (example below). It's a variadic operator, so you
119+
can specify more than one class to check if the reference or pointer points
120+
to an instance of one of the classes specified.
119121

120122
``cast<>``:
121123
The ``cast<>`` operator is a "checked cast" operation. It converts a pointer
@@ -131,6 +133,10 @@ rarely have to include this file directly).
131133
if (isa<Constant>(V) || isa<Argument>(V) || isa<GlobalValue>(V))
132134
return true;
133135
136+
// Alternatively, a more compact form is:
137+
if (isa<Constant, Argument, GlobalValue>(V))
138+
return true;
139+
134140
// Otherwise, it must be an instruction...
135141
return !L->contains(cast<Instruction>(V)->getParent());
136142
}
@@ -168,7 +174,8 @@ rarely have to include this file directly).
168174
The ``isa_and_present<>`` operator works just like the ``isa<>`` operator,
169175
except that it allows for a null pointer as an argument (which it then
170176
returns false). This can sometimes be useful, allowing you to combine several
171-
null checks into one.
177+
null checks into one. Similar to ``isa<>`` operator, you can specify more than
178+
one classes to check.
172179

173180
``cast_if_present<>``:
174181
The ``cast_if_present<>`` operator works just like the ``cast<>`` operator,

llvm/tools/llvm-diff/lib/DifferenceEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ class FunctionDifferenceEngine {
569569

570570
// Constants of the "same type" don't always actually have the same
571571
// type; I don't know why. Just white-list them.
572-
if (isa<ConstantPointerNull>(L) || isa<UndefValue>(L) || isa<ConstantAggregateZero>(L))
572+
if (isa<ConstantPointerNull, UndefValue, ConstantAggregateZero>(L))
573573
return true;
574574

575575
// Block addresses only match if we've already encountered the

llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void identifyUninterestingMDNodes(Oracle &O, MDNodeList &MDs) {
6363
for (size_t I = 0; I < Tup->getNumOperands(); ++I) {
6464
// Ignore any operands that are not DebugInfo metadata nodes.
6565
if (Metadata *Op = Tup->getOperand(I).get()) {
66-
if (isa<DINode>(Op) || isa<DIGlobalVariableExpression>(Op))
66+
if (isa<DINode, DIGlobalVariableExpression>(Op))
6767
// Don't add uninteresting operands to the tuple.
6868
if (!O.shouldKeep())
6969
continue;

llvm/tools/llvm-reduce/deltas/Utils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ Value *llvm::getDefaultValue(Type *T) {
3939
}
4040

4141
bool llvm::hasAliasUse(Function &F) {
42-
return any_of(F.users(), [](User *U) {
43-
return isa<GlobalAlias>(U) || isa<GlobalIFunc>(U);
44-
});
42+
return any_of(F.users(),
43+
[](User *U) { return isa<GlobalAlias, GlobalIFunc>(U); });
4544
}
4645

4746
bool llvm::hasAliasOrBlockAddressUse(Function &F) {

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
29152915
return Res;
29162916
}
29172917

2918-
if (isa<IntInit>(TheInit) || isa<BitInit>(TheInit)) {
2918+
if (isa<IntInit, BitInit>(TheInit)) {
29192919
if (!OpName.empty())
29202920
error("Constant int or bit argument should not have a name!");
29212921
if (isa<BitInit>(TheInit))

llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ void GroupMatcher::optimize() {
558558
//===- SwitchMatcher ------------------------------------------------------===//
559559

560560
bool SwitchMatcher::isSupportedPredicateType(const PredicateMatcher &P) {
561-
return isa<InstructionOpcodeMatcher>(P) || isa<LLTOperandMatcher>(P);
561+
return isa<InstructionOpcodeMatcher, LLTOperandMatcher>(P);
562562
}
563563

564564
bool SwitchMatcher::candidateConditionMatches(

llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ std::string VarLenCodeEmitterGen::getInstructionCaseForEncoding(
463463
const Init *Val = ES.Value;
464464
// If it's a StringInit or DagInit, it's a reference to an operand
465465
// or part of an operand.
466-
if (isa<StringInit>(Val) || isa<DagInit>(Val)) {
466+
if (isa<StringInit, DagInit>(Val)) {
467467
StringRef OperandName;
468468
unsigned LoBit = 0U;
469469
if (const auto *SV = dyn_cast<StringInit>(Val)) {

llvm/utils/TableGen/SearchableTableEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ bool SearchableTableEmitter::compareBy(const Record *LHS, const Record *RHS,
237237
const Init *LHSI = LHS->getValueInit(Field.Name);
238238
const Init *RHSI = RHS->getValueInit(Field.Name);
239239

240-
if (isa<BitsRecTy>(Field.RecType) || isa<IntRecTy>(Field.RecType)) {
240+
if (isa<BitsRecTy, IntRecTy>(Field.RecType)) {
241241
int64_t LHSi = getAsInt(LHSI);
242242
int64_t RHSi = getAsInt(RHSI);
243243
if (LHSi < RHSi)

0 commit comments

Comments
 (0)