Skip to content

[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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions llvm/docs/ProgrammersManual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -131,7 +133,11 @@ rarely have to include this file directly).
if (isa<Constant>(V) || isa<Argument>(V) || isa<GlobalValue>(V))
return true;

// Otherwise, it must be an instruction...
// Alternate, more compact form.
if (isa<Constant, Argument, GlobalValue>(V))
return true;

// Otherwise, it must be an instruction.
return !L->contains(cast<Instruction>(V)->getParent());
}

Expand Down Expand Up @@ -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 class to check.

``cast_if_present<>``:
The ``cast_if_present<>`` operator works just like the ``cast<>`` operator,
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions llvm/tools/llvm-reduce/deltas/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/SearchableTableEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading