[llvm] ed88e60 - [utils] Use std::nullopt instead of None (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 2 21:12:00 PST 2022
Author: Kazu Hirata
Date: 2022-12-02T21:11:42-08:00
New Revision: ed88e60b373383322c4b7465d43dc6c06092facb
URL: https://github.com/llvm/llvm-project/commit/ed88e60b373383322c4b7465d43dc6c06092facb
DIFF: https://github.com/llvm/llvm-project/commit/ed88e60b373383322c4b7465d43dc6c06092facb.diff
LOG: [utils] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated. The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.
This is part of an effort to migrate from
llvm::Optional to std::optional:
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
Added:
Modified:
llvm/utils/TableGen/CodeGenRegisters.cpp
llvm/utils/TableGen/CodeGenTarget.cpp
llvm/utils/TableGen/GlobalISel/GIMatchTree.h
llvm/utils/TableGen/GlobalISelEmitter.cpp
llvm/utils/TableGen/IntrinsicEmitter.cpp
llvm/utils/not/not.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/CodeGenRegisters.cpp b/llvm/utils/TableGen/CodeGenRegisters.cpp
index 54541260c9a10..d4405fc0a6fba 100644
--- a/llvm/utils/TableGen/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/CodeGenRegisters.cpp
@@ -1044,7 +1044,7 @@ CodeGenRegisterClass::getMatchingSubClassWithSubRegs(
// index and order them by size. BiggestSuperRC should always be first.
CodeGenRegisterClass *BiggestSuperRegRC = getSubClassWithSubReg(SubIdx);
if (!BiggestSuperRegRC)
- return None;
+ return std::nullopt;
BitVector SuperRegRCsBV = BiggestSuperRegRC->getSubClasses();
std::vector<CodeGenRegisterClass *> SuperRegRCs;
for (auto &RC : RegClasses)
@@ -1107,7 +1107,7 @@ CodeGenRegisterClass::getMatchingSubClassWithSubRegs(
return std::make_pair(ChosenSuperRegClass, SubRegRC);
}
- return None;
+ return std::nullopt;
}
void CodeGenRegisterClass::getSuperRegClasses(const CodeGenSubRegIndex *SubIdx,
diff --git a/llvm/utils/TableGen/CodeGenTarget.cpp b/llvm/utils/TableGen/CodeGenTarget.cpp
index 108bf4d33df4a..80deae93fc7cb 100644
--- a/llvm/utils/TableGen/CodeGenTarget.cpp
+++ b/llvm/utils/TableGen/CodeGenTarget.cpp
@@ -400,7 +400,7 @@ CodeGenTarget::getSuperRegForSubReg(const ValueTypeByHwMode &ValueTy,
// If we didn't find anything, we're done.
if (Candidates.empty())
- return None;
+ return std::nullopt;
// Find and return the largest of our candidate classes.
llvm::stable_sort(Candidates, [&](const CodeGenRegisterClass *A,
diff --git a/llvm/utils/TableGen/GlobalISel/GIMatchTree.h b/llvm/utils/TableGen/GlobalISel/GIMatchTree.h
index 55a86259661db..5b743be4cc3da 100644
--- a/llvm/utils/TableGen/GlobalISel/GIMatchTree.h
+++ b/llvm/utils/TableGen/GlobalISel/GIMatchTree.h
@@ -29,7 +29,7 @@ class GIMatchTreeVariableBinding {
public:
GIMatchTreeVariableBinding(StringRef Name, unsigned InstrID,
- Optional<unsigned> OpIdx = None)
+ Optional<unsigned> OpIdx = std::nullopt)
: Name(Name), InstrID(InstrID), OpIdx(OpIdx) {}
bool isInstr() const { return !OpIdx; }
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index 9910284c93a62..ecc3e79a2772d 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -210,7 +210,7 @@ static Optional<LLTCodeGen> MVTToLLT(MVT::SimpleValueType SVT) {
if (VT.isInteger() || VT.isFloatingPoint())
return LLTCodeGen(LLT::scalar(VT.getSizeInBits()));
- return None;
+ return std::nullopt;
}
static std::string explainPredicates(const TreePatternNode *N) {
@@ -518,7 +518,8 @@ class MatchTable {
public:
static MatchTableRecord LineBreak;
static MatchTableRecord Comment(StringRef Comment) {
- return MatchTableRecord(None, Comment, 0, MatchTableRecord::MTRF_Comment);
+ return MatchTableRecord(std::nullopt, Comment, 0,
+ MatchTableRecord::MTRF_Comment);
}
static MatchTableRecord Opcode(StringRef Opcode, int IndentAdjust = 0) {
unsigned ExtraFlags = 0;
@@ -527,29 +528,29 @@ class MatchTable {
if (IndentAdjust < 0)
ExtraFlags |= MatchTableRecord::MTRF_Outdent;
- return MatchTableRecord(None, Opcode, 1,
+ return MatchTableRecord(std::nullopt, Opcode, 1,
MatchTableRecord::MTRF_CommaFollows | ExtraFlags);
}
static MatchTableRecord NamedValue(StringRef NamedValue) {
- return MatchTableRecord(None, NamedValue, 1,
+ return MatchTableRecord(std::nullopt, NamedValue, 1,
MatchTableRecord::MTRF_CommaFollows);
}
static MatchTableRecord NamedValue(StringRef NamedValue, int64_t RawValue) {
- return MatchTableRecord(None, NamedValue, 1,
+ return MatchTableRecord(std::nullopt, NamedValue, 1,
MatchTableRecord::MTRF_CommaFollows, RawValue);
}
static MatchTableRecord NamedValue(StringRef Namespace,
StringRef NamedValue) {
- return MatchTableRecord(None, (Namespace + "::" + NamedValue).str(), 1,
- MatchTableRecord::MTRF_CommaFollows);
+ return MatchTableRecord(std::nullopt, (Namespace + "::" + NamedValue).str(),
+ 1, MatchTableRecord::MTRF_CommaFollows);
}
static MatchTableRecord NamedValue(StringRef Namespace, StringRef NamedValue,
int64_t RawValue) {
- return MatchTableRecord(None, (Namespace + "::" + NamedValue).str(), 1,
- MatchTableRecord::MTRF_CommaFollows, RawValue);
+ return MatchTableRecord(std::nullopt, (Namespace + "::" + NamedValue).str(),
+ 1, MatchTableRecord::MTRF_CommaFollows, RawValue);
}
static MatchTableRecord IntValue(int64_t IntValue) {
- return MatchTableRecord(None, llvm::to_string(IntValue), 1,
+ return MatchTableRecord(std::nullopt, llvm::to_string(IntValue), 1,
MatchTableRecord::MTRF_CommaFollows);
}
static MatchTableRecord Label(unsigned LabelID) {
@@ -625,7 +626,7 @@ class MatchTable {
};
MatchTableRecord MatchTable::LineBreak = {
- None, "" /* Emit String */, 0 /* Elements */,
+ std::nullopt, "" /* Emit String */, 0 /* Elements */,
MatchTableRecord::MTRF_LineBreakFollows};
void MatchTableRecord::emit(raw_ostream &OS, bool LineBreakIsNextAfterThis,
@@ -969,7 +970,7 @@ class RuleMatcher : public Matcher {
getComplexSubOperand(StringRef SymbolicName) const {
const auto &I = ComplexSubOperands.find(SymbolicName);
if (I == ComplexSubOperands.end())
- return None;
+ return std::nullopt;
return I->second;
}
@@ -1644,7 +1645,7 @@ class OperandMatcher : public PredicateListMatcher<OperandPredicateMatcher> {
template <class Kind, class... Args>
Optional<Kind *> addPredicate(Args &&... args) {
if (isSameAsAnotherOperand())
- return None;
+ return std::nullopt;
Predicates.emplace_back(std::make_unique<Kind>(
getInsnVarID(), getOpIdx(), std::forward<Args>(args)...));
return static_cast<Kind *>(Predicates.back().get());
@@ -2959,7 +2960,7 @@ class RenderComplexPatternOperand : public OperandRenderer {
public:
RenderComplexPatternOperand(unsigned InsnID, const Record &TheDef,
StringRef SymbolicName, unsigned RendererID,
- Optional<unsigned> SubOperand = None)
+ Optional<unsigned> SubOperand = std::nullopt)
: OperandRenderer(OR_ComplexPattern), InsnID(InsnID), TheDef(TheDef),
SymbolicName(SymbolicName), RendererID(RendererID),
SubOperand(SubOperand) {}
@@ -3827,7 +3828,7 @@ Optional<unsigned> GlobalISelEmitter::getMemSizeBitsFromPredicate(const TreePred
MVTToLLT(getValueType(Predicate.getMemoryVT()));
if (!MemTyOrNone)
- return None;
+ return std::nullopt;
// Align so unusual types like i1 don't get rounded down.
return llvm::alignTo(
@@ -5034,17 +5035,17 @@ GlobalISelEmitter::getRegClassFromLeaf(TreePatternNode *Leaf) {
assert(Leaf->isLeaf() && "Expected leaf?");
Record *RCRec = getInitValueAsRegClass(Leaf->getLeafValue());
if (!RCRec)
- return None;
+ return std::nullopt;
CodeGenRegisterClass *RC = CGRegs.getRegClass(RCRec);
if (!RC)
- return None;
+ return std::nullopt;
return RC;
}
Optional<const CodeGenRegisterClass *>
GlobalISelEmitter::inferRegClassFromPattern(TreePatternNode *N) {
if (!N)
- return None;
+ return std::nullopt;
if (N->isLeaf())
return getRegClassFromLeaf(N);
@@ -5054,18 +5055,18 @@ GlobalISelEmitter::inferRegClassFromPattern(TreePatternNode *N) {
// Only handle things that produce a single type.
if (N->getNumTypes() != 1)
- return None;
+ return std::nullopt;
Record *OpRec = N->getOperator();
// We only want instructions.
if (!OpRec->isSubClassOf("Instruction"))
- return None;
+ return std::nullopt;
// Don't want to try and infer things when there could potentially be more
// than one candidate register class.
auto &Inst = Target.getInstruction(OpRec);
if (Inst.Operands.NumDefs > 1)
- return None;
+ return std::nullopt;
// Handle any special-case instructions which we can safely infer register
// classes from.
@@ -5076,7 +5077,7 @@ GlobalISelEmitter::inferRegClassFromPattern(TreePatternNode *N) {
// has the desired register class as the first child.
TreePatternNode *RCChild = N->getChild(IsRegSequence ? 0 : 1);
if (!RCChild->isLeaf())
- return None;
+ return std::nullopt;
return getRegClassFromLeaf(RCChild);
}
if (InstName == "INSERT_SUBREG") {
@@ -5106,7 +5107,7 @@ GlobalISelEmitter::inferRegClassFromPattern(TreePatternNode *N) {
return &RC;
}
- return None;
+ return std::nullopt;
}
Optional<const CodeGenRegisterClass *>
@@ -5115,12 +5116,12 @@ GlobalISelEmitter::inferSuperRegisterClass(const TypeSetByHwMode &Ty,
assert(SubRegIdxNode && "Expected subregister index node!");
// We need a ValueTypeByHwMode for getSuperRegForSubReg.
if (!Ty.isValueTypeByHwMode(false))
- return None;
+ return std::nullopt;
if (!SubRegIdxNode->isLeaf())
- return None;
+ return std::nullopt;
DefInit *SubRegInit = dyn_cast<DefInit>(SubRegIdxNode->getLeafValue());
if (!SubRegInit)
- return None;
+ return std::nullopt;
CodeGenSubRegIndex *SubIdx = CGRegs.getSubRegIdx(SubRegInit->getDef());
// Use the information we found above to find a minimal register class which
@@ -5129,7 +5130,7 @@ GlobalISelEmitter::inferSuperRegisterClass(const TypeSetByHwMode &Ty,
Target.getSuperRegForSubReg(Ty.getValueTypeByHwMode(), CGRegs, SubIdx,
/* MustBeAllocatable */ true);
if (!RC)
- return None;
+ return std::nullopt;
return *RC;
}
@@ -5152,11 +5153,11 @@ GlobalISelEmitter::inferSuperRegisterClassForNode(
Optional<CodeGenSubRegIndex *>
GlobalISelEmitter::inferSubRegIndexForNode(TreePatternNode *SubRegIdxNode) {
if (!SubRegIdxNode->isLeaf())
- return None;
+ return std::nullopt;
DefInit *SubRegInit = dyn_cast<DefInit>(SubRegIdxNode->getLeafValue());
if (!SubRegInit)
- return None;
+ return std::nullopt;
return CGRegs.getSubRegIdx(SubRegInit->getDef());
}
@@ -5681,11 +5682,11 @@ void GlobalISelEmitter::run(raw_ostream &OS) {
auto RuleCoverageBufOrErr = MemoryBuffer::getFile(UseCoverageFile);
if (!RuleCoverageBufOrErr) {
PrintWarning(SMLoc(), "Missing rule coverage data");
- RuleCoverage = None;
+ RuleCoverage = std::nullopt;
} else {
if (!RuleCoverage->parse(*RuleCoverageBufOrErr.get(), Target.getName())) {
PrintWarning(SMLoc(), "Ignoring invalid or missing rule coverage data");
- RuleCoverage = None;
+ RuleCoverage = std::nullopt;
}
}
}
diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp
index 8338df3235a25..4e67ef7402524 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -646,7 +646,7 @@ Optional<bool> compareFnAttributes(const CodeGenIntrinsic *L,
uint32_t RK = R->ME.toIntValue();
if (LK != RK) return (LK > RK);
- return None;
+ return std::nullopt;
}
struct FnAttributeComparator {
diff --git a/llvm/utils/not/not.cpp b/llvm/utils/not/not.cpp
index 4454035b079e9..4fcc0e89fc402 100644
--- a/llvm/utils/not/not.cpp
+++ b/llvm/utils/not/not.cpp
@@ -58,7 +58,8 @@ int main(int argc, const char **argv) {
for (int i = 0; i < argc; ++i)
Argv.push_back(argv[i]);
std::string ErrMsg;
- int Result = sys::ExecuteAndWait(*Program, Argv, None, {}, 0, 0, &ErrMsg);
+ int Result =
+ sys::ExecuteAndWait(*Program, Argv, std::nullopt, {}, 0, 0, &ErrMsg);
#ifdef _WIN32
// Handle abort() in msvcrt -- It has exit code as 3. abort(), aka
// unreachable, should be recognized as a crash. However, some binaries use
More information about the llvm-commits
mailing list