[Mlir-commits] [mlir] 6ba4b62 - Return None instead of Optional<T>() (NFC)
Kazu Hirata
llvmlistbot at llvm.org
Mon Nov 21 19:06:51 PST 2022
Author: Kazu Hirata
Date: 2022-11-21T19:06:42-08:00
New Revision: 6ba4b62af8df00edb7e1cc0c473f6770fb1cfe3b
URL: https://github.com/llvm/llvm-project/commit/6ba4b62af8df00edb7e1cc0c473f6770fb1cfe3b
DIFF: https://github.com/llvm/llvm-project/commit/6ba4b62af8df00edb7e1cc0c473f6770fb1cfe3b.diff
LOG: Return None instead of Optional<T>() (NFC)
This patch replaces:
return Optional<T>();
with:
return None;
to make the migration from llvm::Optional to std::optional easier.
Specifically, I can deprecate None (in my source tree, that is) to
identify all the instances of None that should be replaced with
std::nullopt.
Note that "return None" far outnumbers "return Optional<T>();". There
are more than 2000 instances of "return None" in our source tree.
All of the instances in this patch come from functions that return
Optional<T> except Archive::findSym and ASTNodeImporter::import, where
we return Expected<Optional<T>>. Note that we can construct
Expected<Optional<T>> from any parameter convertible to Optional<T>,
which None certainly is.
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
Differential Revision: https://reviews.llvm.org/D138464
Added:
Modified:
clang/include/clang/AST/ASTImporterSharedState.h
clang/lib/AST/ASTImporter.cpp
clang/lib/ASTMatchers/Dynamic/Parser.cpp
clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
clang/lib/CodeGen/CodeGenAction.cpp
clang/lib/Driver/ToolChains/AVR.cpp
clang/lib/Driver/ToolChains/Arch/CSKY.cpp
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/lib/CodeGen/SelectOptimize.cpp
llvm/lib/DebugInfo/PDB/DIA/DIADataStream.cpp
llvm/lib/IR/BasicBlock.cpp
llvm/lib/LineEditor/LineEditor.cpp
llvm/lib/MC/MCSubtargetInfo.cpp
llvm/lib/Object/Archive.cpp
llvm/lib/Support/Z3Solver.cpp
llvm/lib/TableGen/Record.cpp
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
llvm/lib/Target/PowerPC/PPCFastISel.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ASTImporterSharedState.h b/clang/include/clang/AST/ASTImporterSharedState.h
index ce7fb290c976..e374dbd0d4bf 100644
--- a/clang/include/clang/AST/ASTImporterSharedState.h
+++ b/clang/include/clang/AST/ASTImporterSharedState.h
@@ -70,7 +70,7 @@ class ASTImporterSharedState {
if (Pos != ImportErrors.end())
return Pos->second;
else
- return Optional<ASTImportError>();
+ return None;
}
void setImportDeclError(Decl *To, ASTImportError Error) {
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 88262268fc97..78ac57ca2608 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -223,7 +223,7 @@ namespace clang {
template<typename T>
Expected<Optional<T>> import(Optional<T> From) {
if (!From)
- return Optional<T>();
+ return None;
return import(*From);
}
@@ -10022,7 +10022,7 @@ ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const {
if (Pos != ImportDeclErrors.end())
return Pos->second;
else
- return Optional<ASTImportError>();
+ return None;
}
void ASTImporter::setImportDeclError(Decl *From, ASTImportError Error) {
diff --git a/clang/lib/ASTMatchers/Dynamic/Parser.cpp b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
index 6470df27e6e2..cf4afe76de0d 100644
--- a/clang/lib/ASTMatchers/Dynamic/Parser.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
@@ -910,10 +910,10 @@ Parser::parseMatcherExpression(StringRef &Code, Sema *S,
Diagnostics *Error) {
VariantValue Value;
if (!parseExpression(Code, S, NamedValues, &Value, Error))
- return llvm::Optional<DynTypedMatcher>();
+ return llvm::None;
if (!Value.isMatcher()) {
Error->addError(SourceRange(), Error->ET_ParserNotAMatcher);
- return llvm::Optional<DynTypedMatcher>();
+ return llvm::None;
}
llvm::Optional<DynTypedMatcher> Result =
Value.getMatcher().getSingleMatcher();
diff --git a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
index 813eb1597756..91fa8bfee422 100644
--- a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
@@ -126,7 +126,7 @@ class VariantMatcher::PolymorphicPayload : public VariantMatcher::Payload {
llvm::Optional<DynTypedMatcher> getSingleMatcher() const override {
if (Matchers.size() != 1)
- return llvm::Optional<DynTypedMatcher>();
+ return llvm::None;
return Matchers[0];
}
@@ -190,7 +190,7 @@ class VariantMatcher::VariadicOpPayload : public VariantMatcher::Payload {
: Op(Op), Args(std::move(Args)) {}
llvm::Optional<DynTypedMatcher> getSingleMatcher() const override {
- return llvm::Optional<DynTypedMatcher>();
+ return llvm::None;
}
std::string getTypeAsString() const override {
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 8c12a6768d38..52971019145e 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -698,7 +698,7 @@ BackendConsumer::getFunctionSourceLocation(const Function &F) const {
if (Pair.first == Hash)
return Pair.second;
}
- return Optional<FullSourceLoc>();
+ return None;
}
void BackendConsumer::UnsupportedDiagHandler(
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp
index 8317bf5fbe9d..6dbe6c62bb2e 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -345,14 +345,14 @@ llvm::Optional<StringRef> GetMCUFamilyName(StringRef MCUName) {
for (const auto &MCU : MCUInfo)
if (MCU.Name == MCUName)
return Optional<StringRef>(MCU.Family);
- return Optional<StringRef>();
+ return None;
}
llvm::Optional<unsigned> GetMCUSectionAddressData(StringRef MCUName) {
for (const auto &MCU : MCUInfo)
if (MCU.Name == MCUName && MCU.DataAddr > 0)
return Optional<unsigned>(MCU.DataAddr);
- return Optional<unsigned>();
+ return None;
}
const StringRef PossibleAVRLibcLocations[] = {
diff --git a/clang/lib/Driver/ToolChains/Arch/CSKY.cpp b/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
index 814f9849ef05..9b432534f441 100644
--- a/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
@@ -33,7 +33,7 @@ csky::getCSKYArchName(const Driver &D, const ArgList &Args,
if (ArchKind == llvm::CSKY::ArchKind::INVALID) {
D.Diag(clang::diag::err_drv_invalid_arch_name) << A->getAsString(Args);
- return llvm::Optional<llvm::StringRef>();
+ return llvm::None;
}
return llvm::Optional<llvm::StringRef>(A->getValue());
}
@@ -42,7 +42,7 @@ csky::getCSKYArchName(const Driver &D, const ArgList &Args,
llvm::CSKY::ArchKind ArchKind = llvm::CSKY::parseCPUArch(A->getValue());
if (ArchKind == llvm::CSKY::ArchKind::INVALID) {
D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
- return llvm::Optional<llvm::StringRef>();
+ return llvm::None;
}
return llvm::Optional<llvm::StringRef>(llvm::CSKY::getArchName(ArchKind));
}
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index acf8d245ac3e..05cab5b45e28 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -459,7 +459,7 @@ class TargetTransformInfoImplBase {
case TargetTransformInfo::CacheLevel::L1D:
[[fallthrough]];
case TargetTransformInfo::CacheLevel::L2D:
- return llvm::Optional<unsigned>();
+ return llvm::None;
}
llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
}
@@ -470,7 +470,7 @@ class TargetTransformInfoImplBase {
case TargetTransformInfo::CacheLevel::L1D:
[[fallthrough]];
case TargetTransformInfo::CacheLevel::L2D:
- return llvm::Optional<unsigned>();
+ return llvm::None;
}
llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp
index 3fdf1fcd0e93..ca46e8aa7d42 100644
--- a/llvm/lib/CodeGen/SelectOptimize.cpp
+++ b/llvm/lib/CodeGen/SelectOptimize.cpp
@@ -949,7 +949,7 @@ Optional<uint64_t> SelectOptimize::computeInstCost(const Instruction *I) {
TTI->getInstructionCost(I, TargetTransformInfo::TCK_Latency);
if (auto OC = ICost.getValue())
return Optional<uint64_t>(*OC);
- return Optional<uint64_t>();
+ return None;
}
ScaledNumber<uint64_t>
diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIADataStream.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIADataStream.cpp
index 8a806f298d0f..247406c49efc 100644
--- a/llvm/lib/DebugInfo/PDB/DIA/DIADataStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/DIA/DIADataStream.cpp
@@ -30,11 +30,11 @@ DIADataStream::getItemAtIndex(uint32_t Index) const {
DWORD RecordSize = 0;
StreamData->Item(Index, 0, &RecordSize, nullptr);
if (RecordSize == 0)
- return llvm::Optional<RecordType>();
+ return llvm::None;
Record.resize(RecordSize);
if (S_OK != StreamData->Item(Index, RecordSize, &RecordSize, &Record[0]))
- return llvm::Optional<RecordType>();
+ return llvm::None;
return Record;
}
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 20101a96e8c4..160492ae7fb1 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -512,7 +512,7 @@ Optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
return Optional<uint64_t>(CI->getValue().getZExtValue());
}
}
- return Optional<uint64_t>();
+ return None;
}
BasicBlock::iterator llvm::skipDebugIntrinsics(BasicBlock::iterator It) {
diff --git a/llvm/lib/LineEditor/LineEditor.cpp b/llvm/lib/LineEditor/LineEditor.cpp
index baa5b73a6cb1..b29a0b0bb741 100644
--- a/llvm/lib/LineEditor/LineEditor.cpp
+++ b/llvm/lib/LineEditor/LineEditor.cpp
@@ -255,7 +255,7 @@ Optional<std::string> LineEditor::readLine() const {
// Either of these may mean end-of-file.
if (!Line || LineLen == 0)
- return Optional<std::string>();
+ return None;
// Strip any newlines off the end of the string.
while (LineLen > 0 &&
@@ -301,7 +301,7 @@ Optional<std::string> LineEditor::readLine() const {
char *Res = ::fgets(Buf, sizeof(Buf), Data->In);
if (!Res) {
if (Line.empty())
- return Optional<std::string>();
+ return None;
else
return Line;
}
diff --git a/llvm/lib/MC/MCSubtargetInfo.cpp b/llvm/lib/MC/MCSubtargetInfo.cpp
index defb1436146f..d851c20d3557 100644
--- a/llvm/lib/MC/MCSubtargetInfo.cpp
+++ b/llvm/lib/MC/MCSubtargetInfo.cpp
@@ -336,16 +336,16 @@ void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const {
}
Optional<unsigned> MCSubtargetInfo::getCacheSize(unsigned Level) const {
- return Optional<unsigned>();
+ return None;
}
Optional<unsigned>
MCSubtargetInfo::getCacheAssociativity(unsigned Level) const {
- return Optional<unsigned>();
+ return None;
}
Optional<unsigned> MCSubtargetInfo::getCacheLineSize(unsigned Level) const {
- return Optional<unsigned>();
+ return None;
}
unsigned MCSubtargetInfo::getPrefetchDistance() const {
diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp
index 9c0f64346bb8..64683507a3e5 100644
--- a/llvm/lib/Object/Archive.cpp
+++ b/llvm/lib/Object/Archive.cpp
@@ -1158,7 +1158,7 @@ Expected<Optional<Archive::Child>> Archive::findSym(StringRef name) const {
return MemberOrErr.takeError();
}
}
- return Optional<Child>();
+ return None;
}
// Returns true if archive file contains no member file.
diff --git a/llvm/lib/Support/Z3Solver.cpp b/llvm/lib/Support/Z3Solver.cpp
index b49d8d2afbb3..1f8444df3c9a 100644
--- a/llvm/lib/Support/Z3Solver.cpp
+++ b/llvm/lib/Support/Z3Solver.cpp
@@ -878,7 +878,7 @@ class Z3Solver : public SMTSolver {
if (res == Z3_L_FALSE)
return false;
- return Optional<bool>();
+ return None;
}
void push() override { return Z3_solver_push(Context.Context, Solver); }
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index de0797181a7b..381d93d43e2e 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -2648,9 +2648,9 @@ llvm::Optional<StringRef>
Record::getValueAsOptionalString(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (!R || !R->getValue())
- return llvm::Optional<StringRef>();
+ return llvm::None;
if (isa<UnsetInit>(R->getValue()))
- return llvm::Optional<StringRef>();
+ return llvm::None;
if (StringInit *SI = dyn_cast<StringInit>(R->getValue()))
return SI->getValue();
diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
index 046baee08069..abb4081962f4 100644
--- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -2608,7 +2608,7 @@ static Optional<std::pair<int, int>> parseVectorKind(StringRef Suffix,
}
if (Res == std::make_pair(-1, -1))
- return Optional<std::pair<int, int>>();
+ return None;
return Optional<std::pair<int, int>>(Res);
}
diff --git a/llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp b/llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
index 9ba79b0cd1dd..f28ee176fec8 100644
--- a/llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
+++ b/llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
@@ -3535,7 +3535,7 @@ getContiguousRangeOfSetBits(const APInt &A) {
unsigned FirstOne = A.getBitWidth() - A.countLeadingZeros() - 1;
unsigned LastOne = A.countTrailingZeros();
if (A.countPopulation() != (FirstOne - LastOne + 1))
- return Optional<std::pair<unsigned,unsigned>>();
+ return None;
return std::make_pair(FirstOne, LastOne);
}
diff --git a/llvm/lib/Target/PowerPC/PPCFastISel.cpp b/llvm/lib/Target/PowerPC/PPCFastISel.cpp
index 0225e6793b9d..5c4bcccb255c 100644
--- a/llvm/lib/Target/PowerPC/PPCFastISel.cpp
+++ b/llvm/lib/Target/PowerPC/PPCFastISel.cpp
@@ -226,7 +226,7 @@ static Optional<PPC::Predicate> getComparePred(CmpInst::Predicate Pred) {
case CmpInst::FCMP_OLE:
case CmpInst::FCMP_ONE:
default:
- return Optional<PPC::Predicate>();
+ return None;
case CmpInst::FCMP_OEQ:
case CmpInst::ICMP_EQ:
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
index f380b2582c65..d07cf5938d49 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
@@ -39,7 +39,7 @@ Optional<wasm::ValType> WebAssembly::parseType(StringRef Type) {
return wasm::ValType::FUNCREF;
if (Type == "externref")
return wasm::ValType::EXTERNREF;
- return Optional<wasm::ValType>();
+ return None;
}
WebAssembly::BlockType WebAssembly::parseBlockType(StringRef Type) {
diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
index 8c0bb597a1f7..0ce46c9bd685 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
@@ -157,7 +157,7 @@ static Optional<Value> createContractArithOp(Location loc, Value x, Value y,
if (isInt) {
if (kind == CombiningKind::MINF || kind == CombiningKind::MAXF)
// Only valid for floating point types.
- return Optional<Value>();
+ return None;
mul = rewriter.create<arith::MulIOp>(loc, x, y);
} else {
// Float case.
@@ -166,7 +166,7 @@ static Optional<Value> createContractArithOp(Location loc, Value x, Value y,
kind == CombiningKind::MAXSI || kind == CombiningKind::OR ||
kind == CombiningKind::XOR)
// Only valid for integer types.
- return Optional<Value>();
+ return None;
// Special case for fused multiply-add.
if (acc && acc.getType().isa<VectorType>() && kind == CombiningKind::ADD) {
return Optional<Value>(rewriter.create<vector::FMAOp>(loc, x, y, acc));
diff --git a/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp b/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
index ba05b034f18e..4e7ed8db19f4 100644
--- a/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
+++ b/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
@@ -77,7 +77,7 @@ SmallVector<int64_t, 4> mlir::computeElementOffsetsFromVectorSliceOffsets(
Optional<SmallVector<int64_t, 4>> mlir::shapeRatio(ArrayRef<int64_t> superShape,
ArrayRef<int64_t> subShape) {
if (superShape.size() < subShape.size()) {
- return Optional<SmallVector<int64_t, 4>>();
+ return None;
}
// Starting from the end, compute the integer divisors.
More information about the Mlir-commits
mailing list