[llvm] 3cfe412 - [TableGen] llvm::Optional => std::optional
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 5 23:21:10 PST 2022
Author: Fangrui Song
Date: 2022-12-06T07:21:02Z
New Revision: 3cfe412e4c90718a3c5abe0aaf2209053a490982
URL: https://github.com/llvm/llvm-project/commit/3cfe412e4c90718a3c5abe0aaf2209053a490982
DIFF: https://github.com/llvm/llvm-project/commit/3cfe412e4c90718a3c5abe0aaf2209053a490982.diff
LOG: [TableGen] llvm::Optional => std::optional
Added:
Modified:
llvm/include/llvm/TableGen/Record.h
llvm/lib/TableGen/Record.cpp
llvm/unittests/TableGen/ParserEntryPointTest.cpp
llvm/utils/TableGen/CodeGenRegisters.cpp
llvm/utils/TableGen/CodeGenRegisters.h
llvm/utils/TableGen/CodeGenSchedule.cpp
llvm/utils/TableGen/CodeGenTarget.cpp
llvm/utils/TableGen/CodeGenTarget.h
llvm/utils/TableGen/GICombinerEmitter.cpp
llvm/utils/TableGen/GlobalISel/GIMatchTree.h
llvm/utils/TableGen/GlobalISelEmitter.cpp
llvm/utils/TableGen/IntrinsicEmitter.cpp
llvm/utils/TableGen/OptParserEmitter.cpp
llvm/utils/TableGen/RegisterInfoEmitter.cpp
llvm/utils/TableGen/X86RecognizableInstr.cpp
mlir/include/mlir/TableGen/AttrOrTypeDef.h
mlir/include/mlir/TableGen/Attribute.h
mlir/include/mlir/TableGen/Builder.h
mlir/include/mlir/TableGen/CodeGenHelpers.h
mlir/include/mlir/TableGen/Constraint.h
mlir/include/mlir/TableGen/Dialect.h
mlir/include/mlir/TableGen/Format.h
mlir/include/mlir/TableGen/Interfaces.h
mlir/include/mlir/TableGen/Operator.h
mlir/include/mlir/TableGen/Pass.h
mlir/include/mlir/TableGen/Pattern.h
mlir/include/mlir/TableGen/Type.h
mlir/lib/TableGen/AttrOrTypeDef.cpp
mlir/lib/TableGen/Attribute.cpp
mlir/lib/TableGen/Builder.cpp
mlir/lib/TableGen/CodeGenHelpers.cpp
mlir/lib/TableGen/Constraint.cpp
mlir/lib/TableGen/Dialect.cpp
mlir/lib/TableGen/Format.cpp
mlir/lib/TableGen/Interfaces.cpp
mlir/lib/TableGen/Pass.cpp
mlir/lib/TableGen/Pattern.cpp
mlir/lib/TableGen/Type.cpp
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
mlir/tools/mlir-tblgen/DialectGen.cpp
mlir/tools/mlir-tblgen/DialectGenUtilities.h
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
mlir/tools/mlir-tblgen/OpDocGen.cpp
mlir/tools/mlir-tblgen/OpFormatGen.cpp
mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
mlir/tools/mlir-tblgen/PassGen.cpp
mlir/tools/mlir-tblgen/RewriterGen.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 017beb3688054..d89dbfc5986b9 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -33,6 +33,7 @@
#include <cstdint>
#include <map>
#include <memory>
+#include <optional>
#include <string>
#include <utility>
#include <vector>
@@ -1825,7 +1826,7 @@ class Record {
/// This method looks up the specified field and returns its value as a
/// string, throwing an exception if the value is not a string and
/// llvm::Optional() if the field does not exist.
- llvm::Optional<StringRef> getValueAsOptionalString(StringRef FieldName) const;
+ std::optional<StringRef> getValueAsOptionalString(StringRef FieldName) const;
/// This method looks up the specified field and returns its value as a
/// BitsInit, throwing an exception if the field does not exist or if the
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index f19eb23ba0854..af67eba6788a4 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -2637,14 +2637,14 @@ Init *Record::getValueInit(StringRef FieldName) const {
}
StringRef Record::getValueAsString(StringRef FieldName) const {
- llvm::Optional<StringRef> S = getValueAsOptionalString(FieldName);
+ std::optional<StringRef> S = getValueAsOptionalString(FieldName);
if (!S)
PrintFatalError(getLoc(), "Record `" + getName() +
"' does not have a field named `" + FieldName + "'!\n");
return S.value();
}
-llvm::Optional<StringRef>
+std::optional<StringRef>
Record::getValueAsOptionalString(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (!R || !R->getValue())
diff --git a/llvm/unittests/TableGen/ParserEntryPointTest.cpp b/llvm/unittests/TableGen/ParserEntryPointTest.cpp
index a470cc0611cd7..56b59f7152811 100644
--- a/llvm/unittests/TableGen/ParserEntryPointTest.cpp
+++ b/llvm/unittests/TableGen/ParserEntryPointTest.cpp
@@ -34,7 +34,7 @@ TEST(Parser, SanityTest) {
EXPECT_FALSE(ProcessResult);
Record *Foo = Records.getDef("Foo");
- Optional<StringRef> Field = Foo->getValueAsOptionalString("strField");
+ std::optional<StringRef> Field = Foo->getValueAsOptionalString("strField");
EXPECT_TRUE(Field.has_value());
EXPECT_EQ(Field.value(), "value");
}
diff --git a/llvm/utils/TableGen/CodeGenRegisters.cpp b/llvm/utils/TableGen/CodeGenRegisters.cpp
index d4405fc0a6fba..8ad8a7a5bc9b0 100644
--- a/llvm/utils/TableGen/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/CodeGenRegisters.cpp
@@ -1024,7 +1024,7 @@ void CodeGenRegisterClass::computeSubClasses(CodeGenRegBank &RegBank) {
RC.inheritProperties(RegBank);
}
-Optional<std::pair<CodeGenRegisterClass *, CodeGenRegisterClass *>>
+std::optional<std::pair<CodeGenRegisterClass *, CodeGenRegisterClass *>>
CodeGenRegisterClass::getMatchingSubClassWithSubRegs(
CodeGenRegBank &RegBank, const CodeGenSubRegIndex *SubIdx) const {
auto SizeOrder = [this](const CodeGenRegisterClass *A,
diff --git a/llvm/utils/TableGen/CodeGenRegisters.h b/llvm/utils/TableGen/CodeGenRegisters.h
index 55ac47e51a309..2c3ac18c11592 100644
--- a/llvm/utils/TableGen/CodeGenRegisters.h
+++ b/llvm/utils/TableGen/CodeGenRegisters.h
@@ -392,7 +392,7 @@ namespace llvm {
/// \return std::pair<SubClass, SubRegClass> where SubClass is a SubClass is
/// a class where every register has SubIdx and SubRegClass is a class where
/// every register is covered by the SubIdx subregister of SubClass.
- Optional<std::pair<CodeGenRegisterClass *, CodeGenRegisterClass *>>
+ std::optional<std::pair<CodeGenRegisterClass *, CodeGenRegisterClass *>>
getMatchingSubClassWithSubRegs(CodeGenRegBank &RegBank,
const CodeGenSubRegIndex *SubIdx) const;
diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp
index 7146a80f063c7..0ed0476006b84 100644
--- a/llvm/utils/TableGen/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/CodeGenSchedule.cpp
@@ -100,7 +100,7 @@ struct InstRegexOp : public SetTheory::Operator {
if (removeParens(Original).find_first_of("|?") != std::string::npos)
FirstMeta = 0;
- Optional<Regex> Regexpr;
+ std::optional<Regex> Regexpr;
StringRef Prefix = Original.substr(0, FirstMeta);
StringRef PatStr = Original.substr(FirstMeta);
if (!PatStr.empty()) {
diff --git a/llvm/utils/TableGen/CodeGenTarget.cpp b/llvm/utils/TableGen/CodeGenTarget.cpp
index 80deae93fc7cb..b7240f01300ce 100644
--- a/llvm/utils/TableGen/CodeGenTarget.cpp
+++ b/llvm/utils/TableGen/CodeGenTarget.cpp
@@ -369,11 +369,9 @@ CodeGenRegBank &CodeGenTarget::getRegBank() const {
return *RegBank;
}
-Optional<CodeGenRegisterClass *>
-CodeGenTarget::getSuperRegForSubReg(const ValueTypeByHwMode &ValueTy,
- CodeGenRegBank &RegBank,
- const CodeGenSubRegIndex *SubIdx,
- bool MustBeAllocatable) const {
+std::optional<CodeGenRegisterClass *> CodeGenTarget::getSuperRegForSubReg(
+ const ValueTypeByHwMode &ValueTy, CodeGenRegBank &RegBank,
+ const CodeGenSubRegIndex *SubIdx, bool MustBeAllocatable) const {
std::vector<CodeGenRegisterClass *> Candidates;
auto &RegClasses = RegBank.getRegClasses();
diff --git a/llvm/utils/TableGen/CodeGenTarget.h b/llvm/utils/TableGen/CodeGenTarget.h
index f14828f2c347e..6846e6b5c77a1 100644
--- a/llvm/utils/TableGen/CodeGenTarget.h
+++ b/llvm/utils/TableGen/CodeGenTarget.h
@@ -108,7 +108,7 @@ class CodeGenTarget {
/// Return the largest register class on \p RegBank which supports \p Ty and
/// covers \p SubIdx if it exists.
- Optional<CodeGenRegisterClass *>
+ std::optional<CodeGenRegisterClass *>
getSuperRegForSubReg(const ValueTypeByHwMode &Ty, CodeGenRegBank &RegBank,
const CodeGenSubRegIndex *SubIdx,
bool MustBeAllocatable = false) const;
diff --git a/llvm/utils/TableGen/GICombinerEmitter.cpp b/llvm/utils/TableGen/GICombinerEmitter.cpp
index 6890bbfbd1374..2ae313081a6f1 100644
--- a/llvm/utils/TableGen/GICombinerEmitter.cpp
+++ b/llvm/utils/TableGen/GICombinerEmitter.cpp
@@ -636,7 +636,7 @@ void GICombinerEmitter::emitNameMatcher(raw_ostream &OS) const {
std::make_pair(std::string(EnumeratedRule.getName()), Code));
}
- OS << "static Optional<uint64_t> getRuleIdxForIdentifier(StringRef "
+ OS << "static std::optional<uint64_t> getRuleIdxForIdentifier(StringRef "
"RuleIdentifier) {\n"
<< " uint64_t I;\n"
<< " // getAtInteger(...) returns false on success\n"
@@ -950,7 +950,7 @@ void GICombinerEmitter::run(raw_ostream &OS) {
emitNameMatcher(OS);
- OS << "static Optional<std::pair<uint64_t, uint64_t>> "
+ OS << "static std::optional<std::pair<uint64_t, uint64_t>> "
"getRuleRangeForIdentifier(StringRef RuleIdentifier) {\n"
<< " std::pair<StringRef, StringRef> RangePair = "
"RuleIdentifier.split('-');\n"
diff --git a/llvm/utils/TableGen/GlobalISel/GIMatchTree.h b/llvm/utils/TableGen/GlobalISel/GIMatchTree.h
index 5b743be4cc3da..0ce4060fe7b40 100644
--- a/llvm/utils/TableGen/GlobalISel/GIMatchTree.h
+++ b/llvm/utils/TableGen/GlobalISel/GIMatchTree.h
@@ -24,12 +24,12 @@ class GIMatchTreeVariableBinding {
StringRef Name;
// The matched instruction it is bound to.
unsigned InstrID;
- // The matched operand (if appropriate) it is bound to.
- Optional<unsigned> OpIdx;
+ // The matched operand (if appropriate) it is bound to.
+ std::optional<unsigned> OpIdx;
public:
GIMatchTreeVariableBinding(StringRef Name, unsigned InstrID,
- Optional<unsigned> OpIdx = std::nullopt)
+ std::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 c908107f5bd56..ff30f7ff40155 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -200,7 +200,7 @@ std::set<LLTCodeGen> KnownTypes;
class InstructionMatcher;
/// Convert an MVT to an equivalent LLT if possible, or the invalid LLT() for
/// MVTs that don't map cleanly to an LLT (e.g., iPTR, *any, ...).
-static Optional<LLTCodeGen> MVTToLLT(MVT::SimpleValueType SVT) {
+static std::optional<LLTCodeGen> MVTToLLT(MVT::SimpleValueType SVT) {
MVT VT(SVT);
if (VT.isVector() && !VT.getVectorElementCount().isScalar())
@@ -466,7 +466,7 @@ struct MatchTableRecord {
/// The actual run-time value, if known
int64_t RawValue;
- MatchTableRecord(Optional<unsigned> LabelID_, StringRef EmitStr,
+ MatchTableRecord(std::optional<unsigned> LabelID_, StringRef EmitStr,
unsigned NumElements, unsigned Flags,
int64_t RawValue = std::numeric_limits<int64_t>::min())
: LabelID(LabelID_.value_or(~0u)), EmitStr(EmitStr),
@@ -966,7 +966,7 @@ class RuleMatcher : public Matcher {
return Error::success();
}
- Optional<DefinedComplexPatternSubOperand>
+ std::optional<DefinedComplexPatternSubOperand>
getComplexSubOperand(StringRef SymbolicName) const {
const auto &I = ComplexSubOperands.find(SymbolicName);
if (I == ComplexSubOperands.end())
@@ -1643,7 +1643,7 @@ class OperandMatcher : public PredicateListMatcher<OperandPredicateMatcher> {
/// Construct a new operand predicate and add it to the matcher.
template <class Kind, class... Args>
- Optional<Kind *> addPredicate(Args &&... args) {
+ std::optional<Kind *> addPredicate(Args &&...args) {
if (isSameAsAnotherOperand())
return std::nullopt;
Predicates.emplace_back(std::make_unique<Kind>(
@@ -2302,7 +2302,7 @@ class InstructionMatcher final : public PredicateListMatcher<PredicateMatcher> {
/// Construct a new instruction predicate and add it to the matcher.
template <class Kind, class... Args>
- Optional<Kind *> addPredicate(Args &&... args) {
+ std::optional<Kind *> addPredicate(Args &&...args) {
Predicates.emplace_back(
std::make_unique<Kind>(getInsnVarID(), std::forward<Args>(args)...));
return static_cast<Kind *>(Predicates.back().get());
@@ -2951,7 +2951,7 @@ class RenderComplexPatternOperand : public OperandRenderer {
unsigned RendererID;
/// When provided, this is the suboperand of the ComplexPattern operand to
/// render. Otherwise all the suboperands will be rendered.
- Optional<unsigned> SubOperand;
+ std::optional<unsigned> SubOperand;
unsigned getNumOperands() const {
return TheDef.getValueAsDag("Operands")->getNumArgs();
@@ -2960,7 +2960,7 @@ class RenderComplexPatternOperand : public OperandRenderer {
public:
RenderComplexPatternOperand(unsigned InsnID, const Record &TheDef,
StringRef SymbolicName, unsigned RendererID,
- Optional<unsigned> SubOperand = std::nullopt)
+ std::optional<unsigned> SubOperand = std::nullopt)
: OperandRenderer(OR_ComplexPattern), InsnID(InsnID), TheDef(TheDef),
SymbolicName(SymbolicName), RendererID(RendererID),
SubOperand(SubOperand) {}
@@ -3552,7 +3552,7 @@ static Expected<LLTCodeGen> getInstResultType(const TreePatternNode *Dst) {
if (ChildTypes.size() != 1)
return failedImport("Dst pattern child has multiple results");
- Optional<LLTCodeGen> MaybeOpTy;
+ std::optional<LLTCodeGen> MaybeOpTy;
if (ChildTypes.front().isMachineValueType()) {
MaybeOpTy =
MVTToLLT(ChildTypes.front().getMachineValueType().SimpleTy);
@@ -3598,7 +3598,7 @@ class GlobalISelEmitter {
SubtargetFeatureInfoMap SubtargetFeatures;
// Rule coverage information.
- Optional<CodeGenCoverage> RuleCoverage;
+ std::optional<CodeGenCoverage> RuleCoverage;
/// Variables used to help with collecting of named operands for predicates
/// with 'let PredicateCodeUsesOperands = 1'. WaitingForNamedOperands is set
@@ -3683,30 +3683,30 @@ class GlobalISelEmitter {
/// CodeGenRegisterClass will support the CodeGenRegisterClass of
/// \p SubRegNode, and the subregister index defined by \p SubRegIdxNode.
/// If no register class is found, return std::nullopt.
- Optional<const CodeGenRegisterClass *>
+ std::optional<const CodeGenRegisterClass *>
inferSuperRegisterClassForNode(const TypeSetByHwMode &Ty,
TreePatternNode *SuperRegNode,
TreePatternNode *SubRegIdxNode);
- Optional<CodeGenSubRegIndex *>
+ std::optional<CodeGenSubRegIndex *>
inferSubRegIndexForNode(TreePatternNode *SubRegIdxNode);
/// Infer a CodeGenRegisterClass which suppoorts \p Ty and \p SubRegIdxNode.
/// Return std::nullopt if no such class exists.
- Optional<const CodeGenRegisterClass *>
+ std::optional<const CodeGenRegisterClass *>
inferSuperRegisterClass(const TypeSetByHwMode &Ty,
TreePatternNode *SubRegIdxNode);
/// Return the CodeGenRegisterClass associated with \p Leaf if it has one.
- Optional<const CodeGenRegisterClass *>
+ std::optional<const CodeGenRegisterClass *>
getRegClassFromLeaf(TreePatternNode *Leaf);
/// Return a CodeGenRegisterClass for \p N if one can be found. Return
/// std::nullopt otherwise.
- Optional<const CodeGenRegisterClass *>
+ std::optional<const CodeGenRegisterClass *>
inferRegClassFromPattern(TreePatternNode *N);
/// Return the size of the MemoryVT in this predicate, if possible.
- Optional<unsigned>
+ std::optional<unsigned>
getMemSizeBitsFromPredicate(const TreePredicateFn &Predicate);
// Add builtin predicates.
@@ -3823,8 +3823,9 @@ Error GlobalISelEmitter::importRulePredicates(RuleMatcher &M,
return Error::success();
}
-Optional<unsigned> GlobalISelEmitter::getMemSizeBitsFromPredicate(const TreePredicateFn &Predicate) {
- Optional<LLTCodeGen> MemTyOrNone =
+std::optional<unsigned> GlobalISelEmitter::getMemSizeBitsFromPredicate(
+ const TreePredicateFn &Predicate) {
+ std::optional<LLTCodeGen> MemTyOrNone =
MVTToLLT(getValueType(Predicate.getMemoryVT()));
if (!MemTyOrNone)
@@ -4545,7 +4546,7 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderer(
if (ChildTypes.size() != 1)
return failedImport("Dst pattern child has multiple results");
- Optional<LLTCodeGen> OpTyOrNone;
+ std::optional<LLTCodeGen> OpTyOrNone;
if (ChildTypes.front().isMachineValueType())
OpTyOrNone = MVTToLLT(ChildTypes.front().getMachineValueType().SimpleTy);
if (!OpTyOrNone)
@@ -4659,7 +4660,7 @@ GlobalISelEmitter::createAndImportSubInstructionRenderer(
if (!SubClass)
return failedImport(
"Cannot infer register class from INSERT_SUBREG operand #1");
- Optional<const CodeGenRegisterClass *> SuperClass =
+ std::optional<const CodeGenRegisterClass *> SuperClass =
inferSuperRegisterClassForNode(Dst->getExtType(0), Dst->getChild(0),
Dst->getChild(2));
if (!SuperClass)
@@ -4977,7 +4978,7 @@ Error GlobalISelEmitter::importDefaultOperandRenderers(
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
DagInit *DefaultOps) const {
for (const auto *DefaultOp : DefaultOps->getArgs()) {
- Optional<LLTCodeGen> OpTyOrNone;
+ std::optional<LLTCodeGen> OpTyOrNone;
// Look through ValueType operators.
if (const DagInit *DefaultDagOp = dyn_cast<DagInit>(DefaultOp)) {
@@ -5029,7 +5030,7 @@ Error GlobalISelEmitter::importImplicitDefRenderers(
return Error::success();
}
-Optional<const CodeGenRegisterClass *>
+std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::getRegClassFromLeaf(TreePatternNode *Leaf) {
assert(Leaf && "Expected node?");
assert(Leaf->isLeaf() && "Expected leaf?");
@@ -5042,7 +5043,7 @@ GlobalISelEmitter::getRegClassFromLeaf(TreePatternNode *Leaf) {
return RC;
}
-Optional<const CodeGenRegisterClass *>
+std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::inferRegClassFromPattern(TreePatternNode *N) {
if (!N)
return std::nullopt;
@@ -5110,7 +5111,7 @@ GlobalISelEmitter::inferRegClassFromPattern(TreePatternNode *N) {
return std::nullopt;
}
-Optional<const CodeGenRegisterClass *>
+std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::inferSuperRegisterClass(const TypeSetByHwMode &Ty,
TreePatternNode *SubRegIdxNode) {
assert(SubRegIdxNode && "Expected subregister index node!");
@@ -5134,7 +5135,7 @@ GlobalISelEmitter::inferSuperRegisterClass(const TypeSetByHwMode &Ty,
return *RC;
}
-Optional<const CodeGenRegisterClass *>
+std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::inferSuperRegisterClassForNode(
const TypeSetByHwMode &Ty, TreePatternNode *SuperRegNode,
TreePatternNode *SubRegIdxNode) {
@@ -5144,13 +5145,13 @@ GlobalISelEmitter::inferSuperRegisterClassForNode(
// from the subregister index node. We can assume that whoever wrote the
// pattern in the first place made sure that the super register and
// subregister are compatible.
- if (Optional<const CodeGenRegisterClass *> SuperRegisterClass =
+ if (std::optional<const CodeGenRegisterClass *> SuperRegisterClass =
inferRegClassFromPattern(SuperRegNode))
return *SuperRegisterClass;
return inferSuperRegisterClass(Ty, SubRegIdxNode);
}
-Optional<CodeGenSubRegIndex *>
+std::optional<CodeGenSubRegIndex *>
GlobalISelEmitter::inferSubRegIndexForNode(TreePatternNode *SubRegIdxNode) {
if (!SubRegIdxNode->isLeaf())
return std::nullopt;
diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp
index 4e67ef7402524..6283cbc025fa4 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -602,8 +602,8 @@ void IntrinsicEmitter::EmitGenerator(const CodeGenIntrinsicTable &Ints,
}
namespace {
-Optional<bool> compareFnAttributes(const CodeGenIntrinsic *L,
- const CodeGenIntrinsic *R) {
+std::optional<bool> compareFnAttributes(const CodeGenIntrinsic *L,
+ const CodeGenIntrinsic *R) {
// Sort throwing intrinsics after non-throwing intrinsics.
if (L->canThrow != R->canThrow)
return R->canThrow;
@@ -657,7 +657,7 @@ struct FnAttributeComparator {
struct AttributeComparator {
bool operator()(const CodeGenIntrinsic *L, const CodeGenIntrinsic *R) const {
- if (Optional<bool> Res = compareFnAttributes(L, R))
+ if (std::optional<bool> Res = compareFnAttributes(L, R))
return *Res;
// Order by argument attributes.
diff --git a/llvm/utils/TableGen/OptParserEmitter.cpp b/llvm/utils/TableGen/OptParserEmitter.cpp
index cbc63ea201402..717a994c219c5 100644
--- a/llvm/utils/TableGen/OptParserEmitter.cpp
+++ b/llvm/utils/TableGen/OptParserEmitter.cpp
@@ -129,7 +129,7 @@ struct SimpleEnumValueTable {
OS << TableIndex;
}
- Optional<StringRef> emitValueTable(raw_ostream &OS) const {
+ std::optional<StringRef> emitValueTable(raw_ostream &OS) const {
if (TableIndex == -1)
return {};
OS << "static const SimpleEnumValue " << ValueTableName << "[] = {\n";
diff --git a/llvm/utils/TableGen/RegisterInfoEmitter.cpp b/llvm/utils/TableGen/RegisterInfoEmitter.cpp
index 1707574cac98e..aa4536a5575ce 100644
--- a/llvm/utils/TableGen/RegisterInfoEmitter.cpp
+++ b/llvm/utils/TableGen/RegisterInfoEmitter.cpp
@@ -1564,7 +1564,7 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
for (const auto &RC : RegisterClasses) {
OS << " {\t// " << RC.getName() << '\n';
for (auto &Idx : SubRegIndices) {
- Optional<std::pair<CodeGenRegisterClass *, CodeGenRegisterClass *>>
+ std::optional<std::pair<CodeGenRegisterClass *, CodeGenRegisterClass *>>
MatchingSubClass = RC.getMatchingSubClassWithSubRegs(RegBank, &Idx);
unsigned EnumValue = 0;
diff --git a/llvm/utils/TableGen/X86RecognizableInstr.cpp b/llvm/utils/TableGen/X86RecognizableInstr.cpp
index cd94dd624a932..e5c1e53936f6d 100644
--- a/llvm/utils/TableGen/X86RecognizableInstr.cpp
+++ b/llvm/utils/TableGen/X86RecognizableInstr.cpp
@@ -779,7 +779,7 @@ void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const {
#define MAP(from, to) \
case X86Local::MRM_##from:
- llvm::Optional<OpcodeType> opcodeType;
+ std::optional<OpcodeType> opcodeType;
switch (OpMap) {
default: llvm_unreachable("Invalid map!");
case X86Local::OB: opcodeType = ONEBYTE; break;
diff --git a/mlir/include/mlir/TableGen/AttrOrTypeDef.h b/mlir/include/mlir/TableGen/AttrOrTypeDef.h
index 6a03e3426152c..bcf7b6dce00dc 100644
--- a/mlir/include/mlir/TableGen/AttrOrTypeDef.h
+++ b/mlir/include/mlir/TableGen/AttrOrTypeDef.h
@@ -38,7 +38,7 @@ class AttrOrTypeBuilder : public Builder {
using Builder::Builder;
/// Returns an optional builder return type.
- Optional<StringRef> getReturnType() const;
+ std::optional<StringRef> getReturnType() const;
/// Returns true if this builder is able to infer the MLIRContext parameter.
bool hasInferredContextParameter() const;
@@ -65,7 +65,7 @@ class AttrOrTypeParameter {
std::string getAccessorName() const;
/// If specified, get the custom allocator code for this parameter.
- Optional<StringRef> getAllocator() const;
+ std::optional<StringRef> getAllocator() const;
/// If specified, get the custom comparator code for this parameter.
StringRef getComparator() const;
@@ -83,13 +83,13 @@ class AttrOrTypeParameter {
StringRef getConvertFromStorage() const;
/// Get an optional C++ parameter parser.
- Optional<StringRef> getParser() const;
+ std::optional<StringRef> getParser() const;
/// Get an optional C++ parameter printer.
- Optional<StringRef> getPrinter() const;
+ std::optional<StringRef> getPrinter() const;
/// Get a description of this parameter for documentation purposes.
- Optional<StringRef> getSummary() const;
+ std::optional<StringRef> getSummary() const;
/// Get the assembly syntax documentation.
StringRef getSyntax() const;
@@ -98,7 +98,7 @@ class AttrOrTypeParameter {
bool isOptional() const;
/// Get the default value of the parameter if it has one.
- Optional<StringRef> getDefaultValue() const;
+ std::optional<StringRef> getDefaultValue() const;
/// Return the underlying def of this parameter.
llvm::Init *getDef() const;
@@ -182,14 +182,14 @@ class AttrOrTypeDef {
/// Return the keyword/mnemonic to use in the printer/parser methods if we are
/// supposed to auto-generate them.
- Optional<StringRef> getMnemonic() const;
+ std::optional<StringRef> getMnemonic() const;
/// Returns if the attribute or type has a custom assembly format implemented
/// in C++. Corresponds to the `hasCustomAssemblyFormat` field.
bool hasCustomAssemblyFormat() const;
/// Returns the custom assembly format, if one was specified.
- Optional<StringRef> getAssemblyFormat() const;
+ std::optional<StringRef> getAssemblyFormat() const;
/// Returns true if the accessors based on the parameters should be generated.
bool genAccessors() const;
@@ -199,10 +199,10 @@ class AttrOrTypeDef {
bool genVerifyDecl() const;
/// Returns the def's extra class declaration code.
- Optional<StringRef> getExtraDecls() const;
+ std::optional<StringRef> getExtraDecls() const;
/// Returns the def's extra class definition code.
- Optional<StringRef> getExtraDefs() const;
+ std::optional<StringRef> getExtraDefs() const;
/// Get the code location (for error printing).
ArrayRef<SMLoc> getLoc() const;
@@ -254,7 +254,7 @@ class AttrDef : public AttrOrTypeDef {
/// Returns the attributes value type builder code block, or std::nullopt if
/// it doesn't have one.
- Optional<StringRef> getTypeBuilder() const;
+ std::optional<StringRef> getTypeBuilder() const;
static bool classof(const AttrOrTypeDef *def);
};
diff --git a/mlir/include/mlir/TableGen/Attribute.h b/mlir/include/mlir/TableGen/Attribute.h
index f2098bdb015ee..6b81189ba16fb 100644
--- a/mlir/include/mlir/TableGen/Attribute.h
+++ b/mlir/include/mlir/TableGen/Attribute.h
@@ -58,7 +58,7 @@ class Attribute : public AttrConstraint {
// Return the type constraint corresponding to the type of this attribute, or
// None if this is not a TypedAttr.
- llvm::Optional<Type> getValueType() const;
+ std::optional<Type> getValueType() const;
// Returns the template getter method call which reads this attribute's
// storage and returns the value as of the desired return type.
diff --git a/mlir/include/mlir/TableGen/Builder.h b/mlir/include/mlir/TableGen/Builder.h
index a3257bcb85a15..a7ad8716e7f04 100644
--- a/mlir/include/mlir/TableGen/Builder.h
+++ b/mlir/include/mlir/TableGen/Builder.h
@@ -40,18 +40,18 @@ class Builder {
/// Return an optional string containing the name of this parameter. If
/// None, no name was specified for this parameter by the user.
- Optional<StringRef> getName() const { return name; }
+ std::optional<StringRef> getName() const { return name; }
/// Return an optional string containing the default value to use for this
/// parameter.
- Optional<StringRef> getDefaultValue() const;
+ std::optional<StringRef> getDefaultValue() const;
private:
- Parameter(Optional<StringRef> name, const llvm::Init *def)
+ Parameter(std::optional<StringRef> name, const llvm::Init *def)
: name(name), def(def) {}
/// The optional name of the parameter.
- Optional<StringRef> name;
+ std::optional<StringRef> name;
/// The tablegen definition of the parameter. This is either a StringInit,
/// or a CArg DefInit.
@@ -68,7 +68,7 @@ class Builder {
ArrayRef<Parameter> getParameters() const { return parameters; }
/// Return an optional string containing the body of the builder.
- Optional<StringRef> getBody() const;
+ std::optional<StringRef> getBody() const;
protected:
/// The TableGen definition of this builder.
diff --git a/mlir/include/mlir/TableGen/CodeGenHelpers.h b/mlir/include/mlir/TableGen/CodeGenHelpers.h
index 90eff6d3551a0..c8fef9a7baf58 100644
--- a/mlir/include/mlir/TableGen/CodeGenHelpers.h
+++ b/mlir/include/mlir/TableGen/CodeGenHelpers.h
@@ -143,7 +143,8 @@ class StaticVerifierFunctionEmitter {
/// LogicalResult(PatternRewriter &rewriter, Operation *op, Attribute attr,
/// StringRef failureStr);
///
- Optional<StringRef> getAttrConstraintFn(const Constraint &constraint) const;
+ std::optional<StringRef>
+ getAttrConstraintFn(const Constraint &constraint) const;
/// Get the name of the static function used for the given successor
/// constraint. These functions are in the form:
@@ -228,8 +229,8 @@ struct stringifier<Twine> {
static std::string apply(const Twine &twine) { return twine.str(); }
};
template <typename OptionalT>
-struct stringifier<Optional<OptionalT>> {
- static std::string apply(Optional<OptionalT> optional) {
+struct stringifier<std::optional<OptionalT>> {
+ static std::string apply(std::optional<OptionalT> optional) {
return optional ? stringifier<OptionalT>::apply(*optional) : std::string();
}
};
diff --git a/mlir/include/mlir/TableGen/Constraint.h b/mlir/include/mlir/TableGen/Constraint.h
index 92999be9cf587..0d0c28e651ee9 100644
--- a/mlir/include/mlir/TableGen/Constraint.h
+++ b/mlir/include/mlir/TableGen/Constraint.h
@@ -60,7 +60,7 @@ class Constraint {
/// Returns the name of the TablGen def of this constraint. In some cases
/// where the current def is anonymous, the name of the base def is used (e.g.
- /// `Optional<>`/`Variadic<>` type constraints).
+ /// `std::optional<>`/`Variadic<>` type constraints).
StringRef getDefName() const;
/// Returns a unique name for the TablGen def of this constraint. This is
@@ -81,7 +81,7 @@ class Constraint {
private:
/// Return the name of the base def if there is one, or std::nullopt
/// otherwise.
- Optional<StringRef> getBaseDefName() const;
+ std::optional<StringRef> getBaseDefName() const;
// What kind of constraint this is.
Kind kind;
diff --git a/mlir/include/mlir/TableGen/Dialect.h b/mlir/include/mlir/TableGen/Dialect.h
index 269b269c8d17e..d85342c742e2e 100644
--- a/mlir/include/mlir/TableGen/Dialect.h
+++ b/mlir/include/mlir/TableGen/Dialect.h
@@ -50,7 +50,7 @@ class Dialect {
ArrayRef<StringRef> getDependentDialects() const;
// Returns the dialects extra class declaration code.
- llvm::Optional<StringRef> getExtraClassDeclaration() const;
+ std::optional<StringRef> getExtraClassDeclaration() const;
/// Returns true if this dialect has a canonicalizer.
bool hasCanonicalizer() const;
diff --git a/mlir/include/mlir/TableGen/Format.h b/mlir/include/mlir/TableGen/Format.h
index be6b90c838503..60d5887ffcbb1 100644
--- a/mlir/include/mlir/TableGen/Format.h
+++ b/mlir/include/mlir/TableGen/Format.h
@@ -61,8 +61,8 @@ class FmtContext {
FmtContext &withOp(Twine subst);
FmtContext &withSelf(Twine subst);
- Optional<StringRef> getSubstFor(PHKind placeholder) const;
- Optional<StringRef> getSubstFor(StringRef placeholder) const;
+ std::optional<StringRef> getSubstFor(PHKind placeholder) const;
+ std::optional<StringRef> getSubstFor(StringRef placeholder) const;
static PHKind getPlaceHolderKind(StringRef str);
diff --git a/mlir/include/mlir/TableGen/Interfaces.h b/mlir/include/mlir/TableGen/Interfaces.h
index 9d50b26ac9a3c..aeef36087fb8f 100644
--- a/mlir/include/mlir/TableGen/Interfaces.h
+++ b/mlir/include/mlir/TableGen/Interfaces.h
@@ -43,13 +43,13 @@ class InterfaceMethod {
bool isStatic() const;
// Return the body for this method if it has one.
- llvm::Optional<StringRef> getBody() const;
+ std::optional<StringRef> getBody() const;
// Return the default implementation for this method if it has one.
- llvm::Optional<StringRef> getDefaultImplementation() const;
+ std::optional<StringRef> getDefaultImplementation() const;
// Return the description of this method if it has one.
- llvm::Optional<StringRef> getDescription() const;
+ std::optional<StringRef> getDescription() const;
// Arguments.
ArrayRef<Argument> getArguments() const;
@@ -83,20 +83,20 @@ class Interface {
ArrayRef<InterfaceMethod> getMethods() const;
// Return the description of this method if it has one.
- llvm::Optional<StringRef> getDescription() const;
+ std::optional<StringRef> getDescription() const;
// Return the interfaces extra class declaration code.
- llvm::Optional<StringRef> getExtraClassDeclaration() const;
+ std::optional<StringRef> getExtraClassDeclaration() const;
// Return the traits extra class declaration code.
- llvm::Optional<StringRef> getExtraTraitClassDeclaration() const;
+ std::optional<StringRef> getExtraTraitClassDeclaration() const;
// Return the extra class declaration code shared between the interface and
// trait classes.
- llvm::Optional<StringRef> getExtraSharedClassDeclaration() const;
+ std::optional<StringRef> getExtraSharedClassDeclaration() const;
// Return the verify method body if it has one.
- llvm::Optional<StringRef> getVerify() const;
+ std::optional<StringRef> getVerify() const;
// If there's a verify method, return if it needs to access the ops in the
// regions.
diff --git a/mlir/include/mlir/TableGen/Operator.h b/mlir/include/mlir/TableGen/Operator.h
index 4515dc3bf4bac..6deeca7ea01fa 100644
--- a/mlir/include/mlir/TableGen/Operator.h
+++ b/mlir/include/mlir/TableGen/Operator.h
@@ -275,8 +275,8 @@ class Operator {
TypeConstraint getType() const { return *constraint; }
private:
- Optional<int> index;
- Optional<TypeConstraint> constraint;
+ std::optional<int> index;
+ std::optional<TypeConstraint> constraint;
};
// Return all arguments or type constraints with same type as result[index].
diff --git a/mlir/include/mlir/TableGen/Pass.h b/mlir/include/mlir/TableGen/Pass.h
index 715420e2d997d..d2bb6e5304ee3 100644
--- a/mlir/include/mlir/TableGen/Pass.h
+++ b/mlir/include/mlir/TableGen/Pass.h
@@ -35,13 +35,13 @@ class PassOption {
StringRef getType() const;
/// Return the default value of the option.
- Optional<StringRef> getDefaultValue() const;
+ std::optional<StringRef> getDefaultValue() const;
/// Return the description for this option.
StringRef getDescription() const;
/// Return the additional flags passed to the option constructor.
- Optional<StringRef> getAdditionalFlags() const;
+ std::optional<StringRef> getAdditionalFlags() const;
/// Flag indicating if this is a list option.
bool isListOption() const;
diff --git a/mlir/include/mlir/TableGen/Pattern.h b/mlir/include/mlir/TableGen/Pattern.h
index 8f6cdf7623633..b17932095f962 100644
--- a/mlir/include/mlir/TableGen/Pattern.h
+++ b/mlir/include/mlir/TableGen/Pattern.h
@@ -284,7 +284,7 @@ class SymbolInfoMap {
// Creates a SymbolInfo instance. `dagAndConstant` is only used for `Attr`
// and `Operand` so should be std::nullopt for `Result` and `Value` kind.
SymbolInfo(const Operator *op, Kind kind,
- Optional<DagAndConstant> dagAndConstant);
+ std::optional<DagAndConstant> dagAndConstant);
// Static methods for creating SymbolInfo.
static SymbolInfo getAttr(const Operator *op, int index) {
@@ -345,11 +345,11 @@ class SymbolInfoMap {
// the size of MultipleValue symbol). Note that operands may be bound to the
// same symbol, use the DagNode and index to distinguish them. For `Attr`
// and MultipleValue, the Dag part will be nullptr.
- Optional<DagAndConstant> dagAndConstant;
+ std::optional<DagAndConstant> dagAndConstant;
// Alternative name for the symbol. It is used in case the name
// is not unique. Applicable for `Operand` only.
- Optional<std::string> alternativeName;
+ std::optional<std::string> alternativeName;
};
using BaseT = std::unordered_multimap<std::string, SymbolInfo>;
diff --git a/mlir/include/mlir/TableGen/Type.h b/mlir/include/mlir/TableGen/Type.h
index 9aaacdbe62ff5..06cf4f5730d56 100644
--- a/mlir/include/mlir/TableGen/Type.h
+++ b/mlir/include/mlir/TableGen/Type.h
@@ -54,7 +54,7 @@ class TypeConstraint : public Constraint {
// Returns the builder call for this constraint if this is a buildable type,
// returns std::nullopt otherwise.
- Optional<StringRef> getBuilderCall() const;
+ std::optional<StringRef> getBuilderCall() const;
// Return the C++ class name for this type (which may just be ::mlir::Type).
std::string getCPPClassName() const;
diff --git a/mlir/lib/TableGen/AttrOrTypeDef.cpp b/mlir/lib/TableGen/AttrOrTypeDef.cpp
index f8fdf727f9d9a..5237446c03c6d 100644
--- a/mlir/lib/TableGen/AttrOrTypeDef.cpp
+++ b/mlir/lib/TableGen/AttrOrTypeDef.cpp
@@ -20,8 +20,8 @@ using namespace mlir::tblgen;
// AttrOrTypeBuilder
//===----------------------------------------------------------------------===//
-Optional<StringRef> AttrOrTypeBuilder::getReturnType() const {
- Optional<StringRef> type = def->getValueAsOptionalString("returnType");
+std::optional<StringRef> AttrOrTypeBuilder::getReturnType() const {
+ std::optional<StringRef> type = def->getValueAsOptionalString("returnType");
return type && !type->empty() ? type : std::nullopt;
}
@@ -148,7 +148,7 @@ unsigned AttrOrTypeDef::getNumParameters() const {
return parametersDag ? parametersDag->getNumArgs() : 0;
}
-Optional<StringRef> AttrOrTypeDef::getMnemonic() const {
+std::optional<StringRef> AttrOrTypeDef::getMnemonic() const {
return def->getValueAsOptionalString("mnemonic");
}
@@ -156,7 +156,7 @@ bool AttrOrTypeDef::hasCustomAssemblyFormat() const {
return def->getValueAsBit("hasCustomAssemblyFormat");
}
-Optional<StringRef> AttrOrTypeDef::getAssemblyFormat() const {
+std::optional<StringRef> AttrOrTypeDef::getAssemblyFormat() const {
return def->getValueAsOptionalString("assemblyFormat");
}
@@ -168,14 +168,14 @@ bool AttrOrTypeDef::genVerifyDecl() const {
return def->getValueAsBit("genVerifyDecl");
}
-Optional<StringRef> AttrOrTypeDef::getExtraDecls() const {
+std::optional<StringRef> AttrOrTypeDef::getExtraDecls() const {
auto value = def->getValueAsString("extraClassDeclaration");
- return value.empty() ? Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
-Optional<StringRef> AttrOrTypeDef::getExtraDefs() const {
+std::optional<StringRef> AttrOrTypeDef::getExtraDefs() const {
auto value = def->getValueAsString("extraClassDefinition");
- return value.empty() ? Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
ArrayRef<SMLoc> AttrOrTypeDef::getLoc() const { return def->getLoc(); }
@@ -196,7 +196,7 @@ bool AttrOrTypeDef::operator<(const AttrOrTypeDef &other) const {
// AttrDef
//===----------------------------------------------------------------------===//
-Optional<StringRef> AttrDef::getTypeBuilder() const {
+std::optional<StringRef> AttrDef::getTypeBuilder() const {
return def->getValueAsOptionalString("typeBuilder");
}
@@ -210,7 +210,7 @@ bool AttrDef::classof(const AttrOrTypeDef *def) {
template <typename InitT>
auto AttrOrTypeParameter::getDefValue(StringRef name) const {
- Optional<decltype(std::declval<InitT>().getValue())> result;
+ std::optional<decltype(std::declval<InitT>().getValue())> result;
if (auto *param = dyn_cast<llvm::DefInit>(getDef()))
if (auto *init = param->getDef()->getValue(name))
if (auto *value = dyn_cast_or_null<InitT>(init->getValue()))
@@ -231,7 +231,7 @@ std::string AttrOrTypeParameter::getAccessorName() const {
llvm::convertToCamelFromSnakeCase(getName(), /*capitalizeFirst=*/true);
}
-Optional<StringRef> AttrOrTypeParameter::getAllocator() const {
+std::optional<StringRef> AttrOrTypeParameter::getAllocator() const {
return getDefValue<llvm::StringInit>("allocator");
}
@@ -258,15 +258,15 @@ StringRef AttrOrTypeParameter::getConvertFromStorage() const {
return getDefValue<llvm::StringInit>("convertFromStorage").value_or("$_self");
}
-Optional<StringRef> AttrOrTypeParameter::getParser() const {
+std::optional<StringRef> AttrOrTypeParameter::getParser() const {
return getDefValue<llvm::StringInit>("parser");
}
-Optional<StringRef> AttrOrTypeParameter::getPrinter() const {
+std::optional<StringRef> AttrOrTypeParameter::getPrinter() const {
return getDefValue<llvm::StringInit>("printer");
}
-Optional<StringRef> AttrOrTypeParameter::getSummary() const {
+std::optional<StringRef> AttrOrTypeParameter::getSummary() const {
return getDefValue<llvm::StringInit>("summary");
}
@@ -280,8 +280,9 @@ bool AttrOrTypeParameter::isOptional() const {
return getDefaultValue().has_value();
}
-Optional<StringRef> AttrOrTypeParameter::getDefaultValue() const {
- Optional<StringRef> result = getDefValue<llvm::StringInit>("defaultValue");
+std::optional<StringRef> AttrOrTypeParameter::getDefaultValue() const {
+ std::optional<StringRef> result =
+ getDefValue<llvm::StringInit>("defaultValue");
return result && !result->empty() ? result : std::nullopt;
}
diff --git a/mlir/lib/TableGen/Attribute.cpp b/mlir/lib/TableGen/Attribute.cpp
index 37ce14e410e37..2018ecc5a8e7a 100644
--- a/mlir/lib/TableGen/Attribute.cpp
+++ b/mlir/lib/TableGen/Attribute.cpp
@@ -70,7 +70,7 @@ StringRef Attribute::getReturnType() const {
// Return the type constraint corresponding to the type of this attribute, or
// None if this is not a TypedAttr.
-llvm::Optional<Type> Attribute::getValueType() const {
+std::optional<Type> Attribute::getValueType() const {
if (auto *defInit = dyn_cast<llvm::DefInit>(def->getValueInit("valueType")))
return Type(defInit->getDef());
return std::nullopt;
diff --git a/mlir/lib/TableGen/Builder.cpp b/mlir/lib/TableGen/Builder.cpp
index 7e39255a47fef..48fb5065f4bd8 100644
--- a/mlir/lib/TableGen/Builder.cpp
+++ b/mlir/lib/TableGen/Builder.cpp
@@ -34,11 +34,12 @@ StringRef Builder::Parameter::getCppType() const {
/// Return an optional string containing the default value to use for this
/// parameter.
-Optional<StringRef> Builder::Parameter::getDefaultValue() const {
+std::optional<StringRef> Builder::Parameter::getDefaultValue() const {
if (isa<llvm::StringInit>(def))
return std::nullopt;
const llvm::Record *record = cast<llvm::DefInit>(def)->getDef();
- Optional<StringRef> value = record->getValueAsOptionalString("defaultValue");
+ std::optional<StringRef> value =
+ record->getValueAsOptionalString("defaultValue");
return value && !value->empty() ? value : std::nullopt;
}
@@ -58,7 +59,8 @@ Builder::Builder(const llvm::Record *record, ArrayRef<SMLoc> loc)
for (unsigned i = 0, e = dag->getNumArgs(); i < e; ++i) {
const llvm::StringInit *paramName = dag->getArgName(i);
const llvm::Init *paramValue = dag->getArg(i);
- Parameter param(paramName ? paramName->getValue() : Optional<StringRef>(),
+ Parameter param(paramName ? paramName->getValue()
+ : std::optional<StringRef>(),
paramValue);
// Similarly to C++, once an argument with a default value is detected, the
@@ -75,7 +77,7 @@ Builder::Builder(const llvm::Record *record, ArrayRef<SMLoc> loc)
}
/// Return an optional string containing the body of the builder.
-Optional<StringRef> Builder::getBody() const {
- Optional<StringRef> body = def->getValueAsOptionalString("body");
+std::optional<StringRef> Builder::getBody() const {
+ std::optional<StringRef> body = def->getValueAsOptionalString("body");
return body && !body->empty() ? body : std::nullopt;
}
diff --git a/mlir/lib/TableGen/CodeGenHelpers.cpp b/mlir/lib/TableGen/CodeGenHelpers.cpp
index 589e99280b4a5..5caefb416ea2f 100644
--- a/mlir/lib/TableGen/CodeGenHelpers.cpp
+++ b/mlir/lib/TableGen/CodeGenHelpers.cpp
@@ -78,10 +78,10 @@ StringRef StaticVerifierFunctionEmitter::getTypeConstraintFn(
// Find a uniqued attribute constraint. Since not all attribute constraints can
// be uniqued, return std::nullopt if one was not found.
-Optional<StringRef> StaticVerifierFunctionEmitter::getAttrConstraintFn(
+std::optional<StringRef> StaticVerifierFunctionEmitter::getAttrConstraintFn(
const Constraint &constraint) const {
auto it = attrConstraints.find(constraint);
- return it == attrConstraints.end() ? Optional<StringRef>()
+ return it == attrConstraints.end() ? std::optional<StringRef>()
: StringRef(it->second);
}
diff --git a/mlir/lib/TableGen/Constraint.cpp b/mlir/lib/TableGen/Constraint.cpp
index f8568889cba44..d8f240a1af7a4 100644
--- a/mlir/lib/TableGen/Constraint.cpp
+++ b/mlir/lib/TableGen/Constraint.cpp
@@ -52,7 +52,8 @@ std::string Constraint::getConditionTemplate() const {
}
StringRef Constraint::getSummary() const {
- if (Optional<StringRef> summary = def->getValueAsOptionalString("summary"))
+ if (std::optional<StringRef> summary =
+ def->getValueAsOptionalString("summary"))
return *summary;
return def->getName();
}
@@ -62,7 +63,7 @@ StringRef Constraint::getDescription() const {
}
StringRef Constraint::getDefName() const {
- if (Optional<StringRef> baseDefName = getBaseDefName())
+ if (std::optional<StringRef> baseDefName = getBaseDefName())
return *baseDefName;
return def->getName();
}
@@ -77,15 +78,15 @@ std::string Constraint::getUniqueDefName() const {
// Otherwise, this is an anonymous class. In these cases we still use the def
// name, but we also try attach the name of the base def when present to make
// the name more obvious.
- if (Optional<StringRef> baseDefName = getBaseDefName())
+ if (std::optional<StringRef> baseDefName = getBaseDefName())
return (*baseDefName + "(" + defName + ")").str();
return defName;
}
-Optional<StringRef> Constraint::getBaseDefName() const {
+std::optional<StringRef> Constraint::getBaseDefName() const {
// Functor used to check a base def in the case where the current def is
// anonymous.
- auto checkBaseDefFn = [&](StringRef baseName) -> Optional<StringRef> {
+ auto checkBaseDefFn = [&](StringRef baseName) -> std::optional<StringRef> {
if (const auto *defValue = def->getValue(baseName)) {
if (const auto *defInit = dyn_cast<llvm::DefInit>(defValue->getValue()))
return Constraint(defInit->getDef(), kind).getDefName();
diff --git a/mlir/lib/TableGen/Dialect.cpp b/mlir/lib/TableGen/Dialect.cpp
index eb3228ebd5a65..2bbca963ae4d5 100644
--- a/mlir/lib/TableGen/Dialect.cpp
+++ b/mlir/lib/TableGen/Dialect.cpp
@@ -57,9 +57,9 @@ ArrayRef<StringRef> Dialect::getDependentDialects() const {
return dependentDialects;
}
-llvm::Optional<StringRef> Dialect::getExtraClassDeclaration() const {
+std::optional<StringRef> Dialect::getExtraClassDeclaration() const {
auto value = def->getValueAsString("extraClassDeclaration");
- return value.empty() ? llvm::Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
bool Dialect::hasCanonicalizer() const {
diff --git a/mlir/lib/TableGen/Format.cpp b/mlir/lib/TableGen/Format.cpp
index 7209cafcab7db..aa3e14bea446a 100644
--- a/mlir/lib/TableGen/Format.cpp
+++ b/mlir/lib/TableGen/Format.cpp
@@ -48,7 +48,7 @@ FmtContext &FmtContext::withSelf(Twine subst) {
return *this;
}
-Optional<StringRef>
+std::optional<StringRef>
FmtContext::getSubstFor(FmtContext::PHKind placeholder) const {
if (placeholder == FmtContext::PHKind::None ||
placeholder == FmtContext::PHKind::Custom)
@@ -59,7 +59,7 @@ FmtContext::getSubstFor(FmtContext::PHKind placeholder) const {
return StringRef(it->second);
}
-Optional<StringRef> FmtContext::getSubstFor(StringRef placeholder) const {
+std::optional<StringRef> FmtContext::getSubstFor(StringRef placeholder) const {
auto it = customSubstMap.find(placeholder);
if (it == customSubstMap.end())
return {};
@@ -165,7 +165,7 @@ void FmtObjectBase::format(raw_ostream &s) const {
// We need the context to replace special placeholders.
s << repl.spec << kMarkerForNoSubst;
} else {
- Optional<StringRef> subst;
+ std::optional<StringRef> subst;
if (repl.placeholder == FmtContext::PHKind::Custom) {
// Skip the leading '$' sign for the custom placeholder
subst = context->getSubstFor(repl.spec.substr(1));
diff --git a/mlir/lib/TableGen/Interfaces.cpp b/mlir/lib/TableGen/Interfaces.cpp
index bc002869f134d..4ddfa2f359328 100644
--- a/mlir/lib/TableGen/Interfaces.cpp
+++ b/mlir/lib/TableGen/Interfaces.cpp
@@ -43,21 +43,21 @@ bool InterfaceMethod::isStatic() const {
}
// Return the body for this method if it has one.
-llvm::Optional<StringRef> InterfaceMethod::getBody() const {
+std::optional<StringRef> InterfaceMethod::getBody() const {
auto value = def->getValueAsString("body");
- return value.empty() ? llvm::Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
// Return the default implementation for this method if it has one.
-llvm::Optional<StringRef> InterfaceMethod::getDefaultImplementation() const {
+std::optional<StringRef> InterfaceMethod::getDefaultImplementation() const {
auto value = def->getValueAsString("defaultBody");
- return value.empty() ? llvm::Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
// Return the description of this method if it has one.
-llvm::Optional<StringRef> InterfaceMethod::getDescription() const {
+std::optional<StringRef> InterfaceMethod::getDescription() const {
auto value = def->getValueAsString("description");
- return value.empty() ? llvm::Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
ArrayRef<InterfaceMethod::Argument> InterfaceMethod::getArguments() const {
@@ -93,36 +93,36 @@ StringRef Interface::getCppNamespace() const {
ArrayRef<InterfaceMethod> Interface::getMethods() const { return methods; }
// Return the description of this method if it has one.
-llvm::Optional<StringRef> Interface::getDescription() const {
+std::optional<StringRef> Interface::getDescription() const {
auto value = def->getValueAsString("description");
- return value.empty() ? llvm::Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
// Return the interfaces extra class declaration code.
-llvm::Optional<StringRef> Interface::getExtraClassDeclaration() const {
+std::optional<StringRef> Interface::getExtraClassDeclaration() const {
auto value = def->getValueAsString("extraClassDeclaration");
- return value.empty() ? llvm::Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
// Return the traits extra class declaration code.
-llvm::Optional<StringRef> Interface::getExtraTraitClassDeclaration() const {
+std::optional<StringRef> Interface::getExtraTraitClassDeclaration() const {
auto value = def->getValueAsString("extraTraitClassDeclaration");
- return value.empty() ? llvm::Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
// Return the shared extra class declaration code.
-llvm::Optional<StringRef> Interface::getExtraSharedClassDeclaration() const {
+std::optional<StringRef> Interface::getExtraSharedClassDeclaration() const {
auto value = def->getValueAsString("extraSharedClassDeclaration");
- return value.empty() ? llvm::Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
// Return the body for this method if it has one.
-llvm::Optional<StringRef> Interface::getVerify() const {
+std::optional<StringRef> Interface::getVerify() const {
// Only OpInterface supports the verify method.
if (!isa<OpInterface>(this))
return std::nullopt;
auto value = def->getValueAsString("verify");
- return value.empty() ? llvm::Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
}
bool Interface::verifyWithRegions() const {
diff --git a/mlir/lib/TableGen/Pass.cpp b/mlir/lib/TableGen/Pass.cpp
index e9c65e8fbd149..271332d1125e5 100644
--- a/mlir/lib/TableGen/Pass.cpp
+++ b/mlir/lib/TableGen/Pass.cpp
@@ -26,18 +26,18 @@ StringRef PassOption::getArgument() const {
StringRef PassOption::getType() const { return def->getValueAsString("type"); }
-Optional<StringRef> PassOption::getDefaultValue() const {
+std::optional<StringRef> PassOption::getDefaultValue() const {
StringRef defaultVal = def->getValueAsString("defaultValue");
- return defaultVal.empty() ? Optional<StringRef>() : defaultVal;
+ return defaultVal.empty() ? std::optional<StringRef>() : defaultVal;
}
StringRef PassOption::getDescription() const {
return def->getValueAsString("description");
}
-Optional<StringRef> PassOption::getAdditionalFlags() const {
+std::optional<StringRef> PassOption::getAdditionalFlags() const {
StringRef additionalFlags = def->getValueAsString("additionalOptFlags");
- return additionalFlags.empty() ? Optional<StringRef>() : additionalFlags;
+ return additionalFlags.empty() ? std::optional<StringRef>() : additionalFlags;
}
bool PassOption::isListOption() const {
diff --git a/mlir/lib/TableGen/Pattern.cpp b/mlir/lib/TableGen/Pattern.cpp
index e8dc607e713b9..1faea137a301b 100644
--- a/mlir/lib/TableGen/Pattern.cpp
+++ b/mlir/lib/TableGen/Pattern.cpp
@@ -216,8 +216,9 @@ StringRef SymbolInfoMap::getValuePackName(StringRef symbol, int *index) {
return name;
}
-SymbolInfoMap::SymbolInfo::SymbolInfo(const Operator *op, SymbolInfo::Kind kind,
- Optional<DagAndConstant> dagAndConstant)
+SymbolInfoMap::SymbolInfo::SymbolInfo(
+ const Operator *op, SymbolInfo::Kind kind,
+ std::optional<DagAndConstant> dagAndConstant)
: op(op), kind(kind), dagAndConstant(std::move(dagAndConstant)) {}
int SymbolInfoMap::SymbolInfo::getStaticValueCount() const {
diff --git a/mlir/lib/TableGen/Type.cpp b/mlir/lib/TableGen/Type.cpp
index eacfbd4e0f029..e9f2394dd540a 100644
--- a/mlir/lib/TableGen/Type.cpp
+++ b/mlir/lib/TableGen/Type.cpp
@@ -41,7 +41,7 @@ StringRef TypeConstraint::getVariadicOfVariadicSegmentSizeAttr() const {
// Returns the builder call for this constraint if this is a buildable type,
// returns std::nullopt otherwise.
-Optional<StringRef> TypeConstraint::getBuilderCall() const {
+std::optional<StringRef> TypeConstraint::getBuilderCall() const {
const llvm::Record *baseType = def;
if (isVariableLength())
baseType = baseType->getValueAsDef("baseType");
@@ -50,10 +50,11 @@ Optional<StringRef> TypeConstraint::getBuilderCall() const {
const llvm::RecordVal *builderCall = baseType->getValue("builderCall");
if (!builderCall || !builderCall->getValue())
return std::nullopt;
- return TypeSwitch<llvm::Init *, Optional<StringRef>>(builderCall->getValue())
+ return TypeSwitch<llvm::Init *, std::optional<StringRef>>(
+ builderCall->getValue())
.Case<llvm::StringInit>([&](auto *init) {
StringRef value = init->getValue();
- return value.empty() ? Optional<StringRef>() : value;
+ return value.empty() ? std::optional<StringRef>() : value;
})
.Default([](auto *) { return std::nullopt; });
}
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index 31e73756eae9a..09285127f128a 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -151,7 +151,7 @@ class DefGen {
Class defCls;
/// An optional attribute or type storage class. The storage class will
/// exist if and only if the def has more than zero parameters.
- Optional<Class> storageCls;
+ std::optional<Class> storageCls;
/// The C++ base value of the def, either "Attribute" or "Type".
StringRef valueType;
@@ -217,7 +217,7 @@ void DefGen::createParentWithTraits() {
/// Extra class definitions have a `$cppClass` substitution that is to be
/// replaced by the C++ class name.
static std::string formatExtraDefinitions(const AttrOrTypeDef &def) {
- if (Optional<StringRef> extraDef = def.getExtraDefs()) {
+ if (std::optional<StringRef> extraDef = def.getExtraDefs()) {
FmtContext ctx = FmtContext().addSubst("cppClass", def.getCppClassName());
return tgfmt(*extraDef, &ctx).str();
}
@@ -230,7 +230,7 @@ void DefGen::emitTopLevelDeclarations() {
defCls.declare<UsingDeclaration>("Base::Base");
// Emit the extra declarations first in case there's a definition in there.
- Optional<StringRef> extraDecl = def.getExtraDecls();
+ std::optional<StringRef> extraDecl = def.getExtraDecls();
std::string extraDef = formatExtraDefinitions(def);
defCls.declare<ExtraClassDeclaration>(extraDecl ? *extraDecl : "",
std::move(extraDef));
@@ -359,7 +359,7 @@ void DefGen::emitCustomBuilder(const AttrOrTypeBuilder &builder) {
// Don't emit a body if there isn't one.
auto props = builder.getBody() ? Method::Static : Method::StaticDeclaration;
StringRef returnType = def.getCppClassName();
- if (Optional<StringRef> builderReturnType = builder.getReturnType())
+ if (std::optional<StringRef> builderReturnType = builder.getReturnType())
returnType = *builderReturnType;
Method *m = defCls.addMethod(returnType, "get", props,
getCustomBuilderParams({}, builder));
@@ -387,7 +387,7 @@ void DefGen::emitCheckedCustomBuilder(const AttrOrTypeBuilder &builder) {
// Don't emit a body if there isn't one.
auto props = builder.getBody() ? Method::Static : Method::StaticDeclaration;
StringRef returnType = def.getCppClassName();
- if (Optional<StringRef> builderReturnType = builder.getReturnType())
+ if (std::optional<StringRef> builderReturnType = builder.getReturnType())
returnType = *builderReturnType;
Method *m = defCls.addMethod(
returnType, "getChecked", props,
@@ -507,7 +507,7 @@ void DefGen::emitConstruct() {
// Use the parameters' custom allocator code, if provided.
FmtContext ctx = FmtContext().addSubst("_allocator", "allocator");
for (auto ¶m : params) {
- if (Optional<StringRef> allocCode = param.getAllocator()) {
+ if (std::optional<StringRef> allocCode = param.getAllocator()) {
ctx.withSelf(param.getName()).addSubst("_dst", param.getName());
body << tgfmt(*allocCode, &ctx) << '\n';
}
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
index 5e224b1fbfe0a..ed155c56f7761 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
@@ -333,7 +333,7 @@ void DefFormat::genParser(MethodBody &os) {
os << ",\n ";
std::string paramSelfStr;
llvm::raw_string_ostream selfOs(paramSelfStr);
- if (Optional<StringRef> defaultValue = param.getDefaultValue()) {
+ if (std::optional<StringRef> defaultValue = param.getDefaultValue()) {
selfOs << formatv("(_result_{0}.value_or(", param.getName())
<< tgfmt(*defaultValue, &ctx) << "))";
} else {
diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp
index c69154c8903f5..3a8bd6c984048 100644
--- a/mlir/tools/mlir-tblgen/DialectGen.cpp
+++ b/mlir/tools/mlir-tblgen/DialectGen.cpp
@@ -56,7 +56,8 @@ filterForDialect(ArrayRef<llvm::Record *> records, Dialect &dialect) {
DialectFilterIterator(records.end(), records.end(), filterFn)};
}
-Optional<Dialect> tblgen::findDialectToGenerate(ArrayRef<Dialect> dialects) {
+std::optional<Dialect>
+tblgen::findDialectToGenerate(ArrayRef<Dialect> dialects) {
if (dialects.empty()) {
llvm::errs() << "no dialect was found\n";
return std::nullopt;
@@ -216,8 +217,7 @@ static void emitDialectDecl(Dialect &dialect, raw_ostream &os) {
os << regionResultAttrVerifierDecl;
if (dialect.hasOperationInterfaceFallback())
os << operationInterfaceFallbackDecl;
- if (llvm::Optional<StringRef> extraDecl =
- dialect.getExtraClassDeclaration())
+ if (std::optional<StringRef> extraDecl = dialect.getExtraClassDeclaration())
os << *extraDecl;
// End the dialect decl.
@@ -237,7 +237,7 @@ static bool emitDialectDecls(const llvm::RecordKeeper &recordKeeper,
return false;
SmallVector<Dialect> dialects(dialectDefs.begin(), dialectDefs.end());
- Optional<Dialect> dialect = findDialectToGenerate(dialects);
+ std::optional<Dialect> dialect = findDialectToGenerate(dialects);
if (!dialect)
return true;
emitDialectDecl(*dialect, os);
@@ -308,7 +308,7 @@ static bool emitDialectDefs(const llvm::RecordKeeper &recordKeeper,
return false;
SmallVector<Dialect> dialects(dialectDefs.begin(), dialectDefs.end());
- Optional<Dialect> dialect = findDialectToGenerate(dialects);
+ std::optional<Dialect> dialect = findDialectToGenerate(dialects);
if (!dialect)
return true;
emitDialectDef(*dialect, os);
diff --git a/mlir/tools/mlir-tblgen/DialectGenUtilities.h b/mlir/tools/mlir-tblgen/DialectGenUtilities.h
index e36bf0e0b1d14..979a9d67b4047 100644
--- a/mlir/tools/mlir-tblgen/DialectGenUtilities.h
+++ b/mlir/tools/mlir-tblgen/DialectGenUtilities.h
@@ -17,7 +17,7 @@ class Dialect;
/// Find the dialect selected by the user to generate for. Returns std::nullopt
/// if no dialect was found, or if more than one potential dialect was found.
-Optional<Dialect> findDialectToGenerate(ArrayRef<Dialect> dialects);
+std::optional<Dialect> findDialectToGenerate(ArrayRef<Dialect> dialects);
} // namespace tblgen
} // namespace mlir
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 1898c3917c273..868b2f0591a7f 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -216,7 +216,7 @@ struct AttributeMetadata {
/// Whether the attribute is required.
bool isRequired;
/// The ODS attribute constraint. Not present for implicit attributes.
- Optional<Attribute> constraint;
+ std::optional<Attribute> constraint;
/// The number of required attributes less than this attribute.
unsigned lowerBound = 0;
/// The number of required attributes greater than this attribute.
@@ -731,7 +731,7 @@ static void genAttributeVerifier(
StringRef varName) {
std::string condition = attr.getPredicate().getCondition();
- Optional<StringRef> constraintFn;
+ std::optional<StringRef> constraintFn;
if (emitHelper.isEmittingForOp() &&
(constraintFn = staticVerifierEmitter.getAttrConstraintFn(attr))) {
body << formatv(verifyAttrUnique, *constraintFn, varName, attrName);
@@ -1148,7 +1148,7 @@ void OpEmitter::genAttrSetters() {
// TODO: Handle unit attr parameters specially, given that it is treated as
// optional but not in the same way as the others (i.e. it uses bool over
- // Optional<>).
+ // llvm::Optional<>).
StringRef paramStr = isUnitAttr ? "attrValue" : "*attrValue";
const char *optionalCodeBody = R"(
if (attrValue)
@@ -1890,12 +1890,13 @@ getBuilderSignature(const Builder &builder) {
for (unsigned i = 0, e = params.size(); i < e; ++i) {
// If no name is provided, generate one.
- Optional<StringRef> paramName = params[i].getName();
+ std::optional<StringRef> paramName = params[i].getName();
std::string name =
paramName ? paramName->str() : "odsArg" + std::to_string(i);
StringRef defaultValue;
- if (Optional<StringRef> defaultParamValue = params[i].getDefaultValue())
+ if (std::optional<StringRef> defaultParamValue =
+ params[i].getDefaultValue())
defaultValue = *defaultParamValue;
arguments.emplace_back(params[i].getCppType(), std::move(name),
@@ -1910,7 +1911,7 @@ void OpEmitter::genBuilder() {
for (const Builder &builder : op.getBuilders()) {
SmallVector<MethodParameter> arguments = getBuilderSignature(builder);
- Optional<StringRef> body = builder.getBody();
+ std::optional<StringRef> body = builder.getBody();
auto properties = body ? Method::Static : Method::StaticDeclaration;
auto *method =
opClass.addMethod("void", "build", properties, std::move(arguments));
diff --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp
index 8ebcd333a24e2..c1aa0addb05d8 100644
--- a/mlir/tools/mlir-tblgen/OpDocGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp
@@ -363,7 +363,7 @@ static bool emitDialectDoc(const RecordKeeper &recordKeeper, raw_ostream &os) {
std::vector<Record *> dialectDefs =
recordKeeper.getAllDerivedDefinitionsIfDefined("Dialect");
SmallVector<Dialect> dialects(dialectDefs.begin(), dialectDefs.end());
- Optional<Dialect> dialect = findDialectToGenerate(dialects);
+ std::optional<Dialect> dialect = findDialectToGenerate(dialects);
if (!dialect)
return true;
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index daa4e9de70539..9620a8639e746 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -59,8 +59,8 @@ struct AttributeVariable
/// Return the constant builder call for the type of this attribute, or
/// std::nullopt if it doesn't have one.
- llvm::Optional<StringRef> getTypeBuilder() const {
- llvm::Optional<Type> attrType = var->attr.getValueType();
+ std::optional<StringRef> getTypeBuilder() const {
+ std::optional<Type> attrType = var->attr.getValueType();
return attrType ? attrType->getBuilderCall() : std::nullopt;
}
@@ -252,7 +252,7 @@ struct OperationFormat {
TypeResolution() = default;
/// Get the index into the buildable types for this type, or std::nullopt.
- Optional<int> getBuilderIdx() const { return builderIdx; }
+ std::optional<int> getBuilderIdx() const { return builderIdx; }
void setBuilderIdx(int idx) { builderIdx = idx; }
/// Get the variable this type is resolved to, or nullptr.
@@ -264,10 +264,10 @@ struct OperationFormat {
return resolver.dyn_cast<const NamedAttribute *>();
}
/// Get the transformer for the type of the variable, or std::nullopt.
- Optional<StringRef> getVarTransformer() const {
+ std::optional<StringRef> getVarTransformer() const {
return variableTransformer;
}
- void setResolver(ConstArgument arg, Optional<StringRef> transformer) {
+ void setResolver(ConstArgument arg, std::optional<StringRef> transformer) {
resolver = arg;
variableTransformer = transformer;
assert(getVariable() || getAttribute());
@@ -276,13 +276,13 @@ struct OperationFormat {
private:
/// If the type is resolved with a buildable type, this is the index into
/// 'buildableTypes' in the parent format.
- Optional<int> builderIdx;
+ std::optional<int> builderIdx;
/// If the type is resolved based upon another operand or result, this is
/// the variable or the attribute that this type is resolved to.
ConstArgument resolver;
/// If the type is resolved based upon another operand or result, this is
/// a transformer to apply to the variable when resolving.
- Optional<StringRef> variableTransformer;
+ std::optional<StringRef> variableTransformer;
};
/// The context in which an element is generated.
@@ -1102,7 +1102,7 @@ static void genAttrParser(AttributeVariable *attr, MethodBody &body,
// If this attribute has a buildable type, use that when parsing the
// attribute.
std::string attrTypeStr;
- if (Optional<StringRef> typeBuilder = attr->getTypeBuilder()) {
+ if (std::optional<StringRef> typeBuilder = attr->getTypeBuilder()) {
llvm::raw_string_ostream os(attrTypeStr);
os << tgfmt(*typeBuilder, &attrTypeCtx);
} else {
@@ -1372,7 +1372,7 @@ void OperationFormat::genParserTypeResolution(Operator &op, MethodBody &body) {
FmtContext verifierFCtx;
for (TypeResolution &resolver :
llvm::concat<TypeResolution>(resultTypes, operandTypes)) {
- Optional<StringRef> transformer = resolver.getVarTransformer();
+ std::optional<StringRef> transformer = resolver.getVarTransformer();
if (!transformer)
continue;
// Ensure that we don't verify the same variables twice.
@@ -1405,10 +1405,10 @@ void OperationFormat::genParserTypeResolution(Operator &op, MethodBody &body) {
// Emit the code necessary for a type resolver.
auto emitTypeResolver = [&](TypeResolution &resolver, StringRef curVar) {
- if (Optional<int> val = resolver.getBuilderIdx()) {
+ if (std::optional<int> val = resolver.getBuilderIdx()) {
body << "odsBuildableType" << *val;
} else if (const NamedTypeConstraint *var = resolver.getVariable()) {
- if (Optional<StringRef> tform = resolver.getVarTransformer()) {
+ if (std::optional<StringRef> tform = resolver.getVarTransformer()) {
FmtContext fmtContext;
fmtContext.addSubst("_ctxt", "parser.getContext()");
if (var->isVariadic())
@@ -1422,7 +1422,7 @@ void OperationFormat::genParserTypeResolution(Operator &op, MethodBody &body) {
body << "[0]";
}
} else if (const NamedAttribute *attr = resolver.getAttribute()) {
- if (Optional<StringRef> tform = resolver.getVarTransformer())
+ if (std::optional<StringRef> tform = resolver.getVarTransformer())
body << tgfmt(*tform,
&FmtContext().withSelf(attr->name + "Attr.getType()"));
else
@@ -2246,7 +2246,7 @@ class OpFormatParser : public FormatParser {
/// properly resolve the type of a variable.
struct TypeResolutionInstance {
ConstArgument resolver;
- Optional<StringRef> transformer;
+ std::optional<StringRef> transformer;
};
/// Verify the state of operation attributes within the format.
@@ -2438,7 +2438,7 @@ static bool isOptionallyParsed(FormatElement *el) {
///
/// Since the guard element of an optional group is required, this function
/// accepts an optional element pointer to mark it as required.
-static Optional<LogicalResult> checkRangeForElement(
+static std::optional<LogicalResult> checkRangeForElement(
FormatElement *base,
function_ref<bool(FormatElement *, FormatElement *)> isInvalid,
iterator_range<ArrayRef<FormatElement *>::iterator> elementRange,
@@ -2450,13 +2450,13 @@ static Optional<LogicalResult> checkRangeForElement(
// Recurse on optional groups.
if (auto *optional = dyn_cast<OptionalElement>(element)) {
- if (Optional<LogicalResult> result = checkRangeForElement(
+ if (std::optional<LogicalResult> result = checkRangeForElement(
base, isInvalid, optional->getThenElements(),
// The optional group guard is required for the group.
optional->getThenElements().front()))
if (failed(*result))
return failure();
- if (Optional<LogicalResult> result = checkRangeForElement(
+ if (std::optional<LogicalResult> result = checkRangeForElement(
base, isInvalid, optional->getElseElements()))
if (failed(*result))
return failure();
@@ -2508,7 +2508,7 @@ static FailureOr<FormatElement *> verifyAdjacentElements(
}
// Verify subsequent elements for potential ambiguities.
- if (Optional<LogicalResult> result =
+ if (std::optional<LogicalResult> result =
checkRangeForElement(base, isInvalid, {std::next(it), e})) {
if (failed(*result))
return failure();
@@ -2603,7 +2603,7 @@ LogicalResult OpFormatParser::verifyOperands(
// Similarly to results, allow a custom builder for resolving the type if
// we aren't using the 'operands' directive.
- Optional<StringRef> builder = operand.constraint.getBuilderCall();
+ std::optional<StringRef> builder = operand.constraint.getBuilderCall();
if (!builder || (fmt.allOperands && operand.isVariableLength())) {
return emitErrorAndNote(
loc,
@@ -2668,7 +2668,7 @@ LogicalResult OpFormatParser::verifyResults(
// If the result is not variable length, allow for the case where the type
// has a builder that we can use.
NamedTypeConstraint &result = op.getResult(i);
- Optional<StringRef> builder = result.constraint.getBuilderCall();
+ std::optional<StringRef> builder = result.constraint.getBuilderCall();
if (!builder || result.isVariableLength()) {
return emitErrorAndNote(
loc,
diff --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
index 3abd828fc7468..1ffed30d5cced 100644
--- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
@@ -160,7 +160,7 @@ struct TypeInterfaceGenerator : public InterfaceGenerator {
static void emitInterfaceMethodDoc(const InterfaceMethod &method,
raw_ostream &os, StringRef prefix = "") {
- if (Optional<StringRef> description = method.getDescription())
+ if (std::optional<StringRef> description = method.getDescription())
tblgen::emitDescriptionComment(*description, os, prefix);
}
@@ -305,7 +305,7 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
os << " {\n ";
// Check for a provided body to the function.
- if (Optional<StringRef> body = method.getBody()) {
+ if (std::optional<StringRef> body = method.getBody()) {
if (method.isStatic())
os << body->trim();
else
@@ -494,9 +494,10 @@ void InterfaceGenerator::emitInterfaceDecl(const Interface &interface) {
}
// Emit any extra declarations.
- if (Optional<StringRef> extraDecls = interface.getExtraClassDeclaration())
+ if (std::optional<StringRef> extraDecls =
+ interface.getExtraClassDeclaration())
os << *extraDecls << "\n";
- if (Optional<StringRef> extraDecls =
+ if (std::optional<StringRef> extraDecls =
interface.getExtraSharedClassDeclaration())
os << tblgen::tgfmt(*extraDecls, &extraDeclsFmt);
diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp
index 8bcb1100cd71b..de159d144ffbb 100644
--- a/mlir/tools/mlir-tblgen/PassGen.cpp
+++ b/mlir/tools/mlir-tblgen/PassGen.cpp
@@ -101,7 +101,7 @@ static void emitPassOptionsStruct(const Pass &pass, raw_ostream &os) {
os.indent(2) << llvm::formatv("{0} {1}", type, opt.getCppVariableName());
- if (Optional<StringRef> defaultVal = opt.getDefaultValue())
+ if (std::optional<StringRef> defaultVal = opt.getDefaultValue())
os << " = " << defaultVal;
os << ";\n";
@@ -270,9 +270,9 @@ static void emitPassOptionDecls(const Pass &pass, raw_ostream &os) {
os << llvm::formatv(R"(<{0}> {1}{{*this, "{2}", ::llvm::cl::desc("{3}"))",
opt.getType(), opt.getCppVariableName(),
opt.getArgument(), opt.getDescription());
- if (Optional<StringRef> defaultVal = opt.getDefaultValue())
+ if (std::optional<StringRef> defaultVal = opt.getDefaultValue())
os << ", ::llvm::cl::init(" << defaultVal << ")";
- if (Optional<StringRef> additionalFlags = opt.getAdditionalFlags())
+ if (std::optional<StringRef> additionalFlags = opt.getAdditionalFlags())
os << ", " << *additionalFlags;
os << "};\n";
}
diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp
index 115ff8cfea3aa..cdb1536ce65bb 100644
--- a/mlir/tools/mlir-tblgen/RewriterGen.cpp
+++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp
@@ -1743,7 +1743,7 @@ void StaticMatcherHelper::addPattern(Record *record) {
StringRef StaticMatcherHelper::getVerifierName(DagLeaf leaf) {
if (leaf.isAttrMatcher()) {
- Optional<StringRef> constraint =
+ std::optional<StringRef> constraint =
staticVerifierEmitter.getAttrConstraintFn(leaf.getAsConstraint());
assert(constraint && "attribute constraint was not uniqued");
return *constraint;
More information about the llvm-commits
mailing list