[clang] Use std::optional instead of llvm::Optional (NFC)

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
This commit is contained in:
Kazu Hirata 2023-01-02 15:54:57 -08:00
parent d2ab0134ed
commit 9cf4419e24
17 changed files with 112 additions and 98 deletions

View File

@ -10,9 +10,9 @@
#define LLVM_CLANG_APINOTES_TYPES_H
#include "clang/Basic/Specifiers.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include <climits>
#include <optional>
#include <vector>
namespace llvm {
@ -74,12 +74,12 @@ public:
: Unavailable(0), UnavailableInSwift(0), SwiftPrivateSpecified(0),
SwiftPrivate(0) {}
llvm::Optional<bool> isSwiftPrivate() const {
return SwiftPrivateSpecified ? llvm::Optional<bool>(SwiftPrivate)
std::optional<bool> isSwiftPrivate() const {
return SwiftPrivateSpecified ? std::optional<bool>(SwiftPrivate)
: std::nullopt;
}
void setSwiftPrivate(llvm::Optional<bool> Private) {
void setSwiftPrivate(std::optional<bool> Private) {
SwiftPrivateSpecified = Private.has_value();
SwiftPrivate = Private.value_or(0);
}
@ -131,38 +131,38 @@ class CommonTypeInfo : public CommonEntityInfo {
/// The Swift type to which a given type is bridged.
///
/// Reflects the swift_bridge attribute.
llvm::Optional<std::string> SwiftBridge;
std::optional<std::string> SwiftBridge;
/// The NS error domain for this type.
llvm::Optional<std::string> NSErrorDomain;
std::optional<std::string> NSErrorDomain;
public:
CommonTypeInfo() {}
const llvm::Optional<std::string> &getSwiftBridge() const {
const std::optional<std::string> &getSwiftBridge() const {
return SwiftBridge;
}
void setSwiftBridge(const llvm::Optional<std::string> &SwiftType) {
void setSwiftBridge(const std::optional<std::string> &SwiftType) {
SwiftBridge = SwiftType;
}
void setSwiftBridge(const llvm::Optional<llvm::StringRef> &SwiftType) {
void setSwiftBridge(const std::optional<llvm::StringRef> &SwiftType) {
SwiftBridge = SwiftType
? llvm::Optional<std::string>(std::string(*SwiftType))
? std::optional<std::string>(std::string(*SwiftType))
: std::nullopt;
}
const llvm::Optional<std::string> &getNSErrorDomain() const {
const std::optional<std::string> &getNSErrorDomain() const {
return NSErrorDomain;
}
void setNSErrorDomain(const llvm::Optional<std::string> &Domain) {
void setNSErrorDomain(const std::optional<std::string> &Domain) {
NSErrorDomain = Domain;
}
void setNSErrorDomain(const llvm::Optional<llvm::StringRef> &Domain) {
NSErrorDomain = Domain ? llvm::Optional<std::string>(std::string(*Domain))
void setNSErrorDomain(const std::optional<llvm::StringRef> &Domain) {
NSErrorDomain = Domain ? std::optional<std::string>(std::string(*Domain))
: std::nullopt;
}
@ -221,9 +221,9 @@ public:
///
/// Returns the default nullability, if implied, or std::nullopt if there is
/// none.
llvm::Optional<NullabilityKind> getDefaultNullability() const {
std::optional<NullabilityKind> getDefaultNullability() const {
return HasDefaultNullability
? llvm::Optional<NullabilityKind>(
? std::optional<NullabilityKind>(
static_cast<NullabilityKind>(DefaultNullability))
: std::nullopt;
}
@ -237,21 +237,21 @@ public:
bool hasDesignatedInits() const { return HasDesignatedInits; }
void setHasDesignatedInits(bool Value) { HasDesignatedInits = Value; }
llvm::Optional<bool> getSwiftImportAsNonGeneric() const {
std::optional<bool> getSwiftImportAsNonGeneric() const {
return SwiftImportAsNonGenericSpecified
? llvm::Optional<bool>(SwiftImportAsNonGeneric)
? std::optional<bool>(SwiftImportAsNonGeneric)
: std::nullopt;
}
void setSwiftImportAsNonGeneric(llvm::Optional<bool> Value) {
void setSwiftImportAsNonGeneric(std::optional<bool> Value) {
SwiftImportAsNonGenericSpecified = Value.has_value();
SwiftImportAsNonGeneric = Value.value_or(false);
}
llvm::Optional<bool> getSwiftObjCMembers() const {
return SwiftObjCMembersSpecified ? llvm::Optional<bool>(SwiftObjCMembers)
std::optional<bool> getSwiftObjCMembers() const {
return SwiftObjCMembersSpecified ? std::optional<bool>(SwiftObjCMembers)
: std::nullopt;
}
void setSwiftObjCMembers(llvm::Optional<bool> Value) {
void setSwiftObjCMembers(std::optional<bool> Value) {
SwiftObjCMembersSpecified = Value.has_value();
SwiftObjCMembers = Value.value_or(false);
}
@ -315,8 +315,8 @@ class VariableInfo : public CommonEntityInfo {
public:
VariableInfo() : NullabilityAudited(false), Nullable(0) {}
llvm::Optional<NullabilityKind> getNullability() const {
return NullabilityAudited ? llvm::Optional<NullabilityKind>(
std::optional<NullabilityKind> getNullability() const {
return NullabilityAudited ? std::optional<NullabilityKind>(
static_cast<NullabilityKind>(Nullable))
: std::nullopt;
}
@ -364,12 +364,12 @@ public:
ObjCPropertyInfo()
: SwiftImportAsAccessorsSpecified(false), SwiftImportAsAccessors(false) {}
llvm::Optional<bool> getSwiftImportAsAccessors() const {
std::optional<bool> getSwiftImportAsAccessors() const {
return SwiftImportAsAccessorsSpecified
? llvm::Optional<bool>(SwiftImportAsAccessors)
? std::optional<bool>(SwiftImportAsAccessors)
: std::nullopt;
}
void setSwiftImportAsAccessors(llvm::Optional<bool> Value) {
void setSwiftImportAsAccessors(std::optional<bool> Value) {
SwiftImportAsAccessorsSpecified = Value.has_value();
SwiftImportAsAccessors = Value.value_or(false);
}
@ -428,23 +428,23 @@ public:
ParamInfo()
: NoEscapeSpecified(false), NoEscape(false), RawRetainCountConvention() {}
llvm::Optional<bool> isNoEscape() const {
std::optional<bool> isNoEscape() const {
if (!NoEscapeSpecified)
return std::nullopt;
return NoEscape;
}
void setNoEscape(llvm::Optional<bool> Value) {
void setNoEscape(std::optional<bool> Value) {
NoEscapeSpecified = Value.has_value();
NoEscape = Value.value_or(false);
}
llvm::Optional<RetainCountConventionKind> getRetainCountConvention() const {
std::optional<RetainCountConventionKind> getRetainCountConvention() const {
if (!RawRetainCountConvention)
return std::nullopt;
return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
}
void
setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
assert(getRetainCountConvention() == Value && "bitfield too small");
}
@ -556,13 +556,13 @@ public:
NullabilityKind getReturnTypeInfo() const { return getTypeInfo(0); }
llvm::Optional<RetainCountConventionKind> getRetainCountConvention() const {
std::optional<RetainCountConventionKind> getRetainCountConvention() const {
if (!RawRetainCountConvention)
return std::nullopt;
return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
}
void
setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
assert(getRetainCountConvention() == Value && "bitfield too small");
}
@ -659,16 +659,16 @@ class TagInfo : public CommonTypeInfo {
unsigned IsFlagEnum : 1;
public:
llvm::Optional<EnumExtensibilityKind> EnumExtensibility;
std::optional<EnumExtensibilityKind> EnumExtensibility;
TagInfo() : HasFlagEnum(0), IsFlagEnum(0) {}
llvm::Optional<bool> isFlagEnum() const {
std::optional<bool> isFlagEnum() const {
if (HasFlagEnum)
return IsFlagEnum;
return std::nullopt;
}
void setFlagEnum(llvm::Optional<bool> Value) {
void setFlagEnum(std::optional<bool> Value) {
HasFlagEnum = Value.has_value();
IsFlagEnum = Value.value_or(false);
}
@ -703,7 +703,7 @@ inline bool operator!=(const TagInfo &LHS, const TagInfo &RHS) {
/// Describes API notes data for a typedef.
class TypedefInfo : public CommonTypeInfo {
public:
llvm::Optional<SwiftNewTypeKind> SwiftWrapper;
std::optional<SwiftNewTypeKind> SwiftWrapper;
TypedefInfo() {}

View File

@ -9,7 +9,7 @@
#ifndef LLVM_CLANG_BASIC_CLWARNINGS_H
#define LLVM_CLANG_BASIC_CLWARNINGS_H
#include "llvm/ADT/Optional.h"
#include <optional>
namespace clang {
@ -19,7 +19,7 @@ enum class Group;
/// For cl.exe warning IDs that cleany map to clang diagnostic groups,
/// returns the corresponding group. Else, returns an empty Optional.
llvm::Optional<diag::Group> diagGroupFromCLWarningID(unsigned);
std::optional<diag::Group> diagGroupFromCLWarningID(unsigned);
} // end namespace clang

View File

@ -10,11 +10,11 @@
#define CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/type_traits.h"
#include <cassert>
#include <new>
#include <optional>
#include <utility>
namespace clang {
@ -46,9 +46,9 @@ public:
: Storage(std::in_place, std::forward<ArgTypes>(Args)...) {}
// Allow conversion from Optional<T>.
constexpr CustomizableOptional(const llvm::Optional<T> &y)
constexpr CustomizableOptional(const std::optional<T> &y)
: CustomizableOptional(y ? *y : CustomizableOptional()) {}
constexpr CustomizableOptional(llvm::Optional<T> &&y)
constexpr CustomizableOptional(std::optional<T> &&y)
: CustomizableOptional(y ? std::move(*y) : CustomizableOptional()) {}
CustomizableOptional &operator=(T &&y) {
@ -99,11 +99,11 @@ public:
}
// Allow conversion to Optional<T>.
explicit operator llvm::Optional<T> &() const & {
return *this ? **this : llvm::Optional<T>();
explicit operator std::optional<T> &() const & {
return *this ? **this : std::optional<T>();
}
explicit operator llvm::Optional<T> &&() const && {
return *this ? std::move(**this) : llvm::Optional<T>();
explicit operator std::optional<T> &&() const && {
return *this ? std::move(**this) : std::optional<T>();
}
};

View File

@ -12,6 +12,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Triple.h"
#include <optional>
#include <set>
namespace clang {
@ -37,9 +38,9 @@ llvm::StringRef getProcessorFromTargetID(const llvm::Triple &T,
/// If the target ID contains feature+, map it to true.
/// If the target ID contains feature-, map it to false.
/// If the target ID does not contain a feature (default), do not map it.
llvm::Optional<llvm::StringRef>
parseTargetID(const llvm::Triple &T, llvm::StringRef OffloadArch,
llvm::StringMap<bool> *FeatureMap);
std::optional<llvm::StringRef> parseTargetID(const llvm::Triple &T,
llvm::StringRef OffloadArch,
llvm::StringMap<bool> *FeatureMap);
/// Returns canonical target ID, assuming \p Processor is canonical and all
/// entries in \p Features are valid.

View File

@ -11,10 +11,10 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitmaskEnum.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include <cstdint>
#include <optional>
#include <set>
#include <string>
#include <unordered_map>
@ -27,7 +27,7 @@ class raw_ostream;
namespace clang {
namespace RISCV {
using VScaleVal = llvm::Optional<unsigned>;
using VScaleVal = std::optional<unsigned>;
// Modifier for vector type.
enum class VectorTypeModifier : uint8_t {
@ -197,7 +197,7 @@ struct PrototypeDescriptor {
static const PrototypeDescriptor Mask;
static const PrototypeDescriptor Vector;
static const PrototypeDescriptor VL;
static llvm::Optional<PrototypeDescriptor>
static std::optional<PrototypeDescriptor>
parsePrototypeDescriptor(llvm::StringRef PrototypeStr);
};
@ -238,7 +238,7 @@ struct LMULType {
LMULType(int Log2LMUL);
// Return the C/C++ string representation of LMUL
std::string str() const;
llvm::Optional<unsigned> getScale(unsigned ElementBitwidth) const;
std::optional<unsigned> getScale(unsigned ElementBitwidth) const;
void MulLog2LMUL(int Log2LMUL);
};
@ -354,11 +354,11 @@ public:
/// and LMUL with type transformers). It also record result of type in legal
/// or illegal set to avoid compute the same config again. The result maybe
/// have illegal RVVType.
llvm::Optional<RVVTypes>
std::optional<RVVTypes>
computeTypes(BasicType BT, int Log2LMUL, unsigned NF,
llvm::ArrayRef<PrototypeDescriptor> Prototype);
llvm::Optional<RVVTypePtr> computeType(BasicType BT, int Log2LMUL,
PrototypeDescriptor Proto);
std::optional<RVVTypePtr> computeType(BasicType BT, int Log2LMUL,
PrototypeDescriptor Proto);
};
enum PolicyScheme : uint8_t {

View File

@ -12,10 +12,11 @@
#include "clang/Basic/CLWarnings.h"
#include "clang/Basic/DiagnosticCategories.h"
#include <optional>
using namespace clang;
llvm::Optional<diag::Group>
std::optional<diag::Group>
clang::diagGroupFromCLWarningID(unsigned CLWarningID) {
switch (CLWarningID) {
case 4005: return diag::Group::MacroRedefined;

View File

@ -101,7 +101,7 @@ parseTargetIDWithFormatCheckingOnly(llvm::StringRef TargetID,
return Processor;
}
llvm::Optional<llvm::StringRef>
std::optional<llvm::StringRef>
parseTargetID(const llvm::Triple &T, llvm::StringRef TargetID,
llvm::StringMap<bool> *FeatureMap) {
auto OptionalProcessor =

View File

@ -9,12 +9,13 @@
#include "DirectoryScanner.h"
#include "llvm/Support/Path.h"
#include <optional>
namespace clang {
using namespace llvm;
Optional<sys::fs::file_status> getFileStatus(StringRef Path) {
std::optional<sys::fs::file_status> getFileStatus(StringRef Path) {
sys::fs::file_status Status;
std::error_code EC = status(Path, Status);
if (EC)

View File

@ -8,6 +8,7 @@
#include "clang/DirectoryWatcher/DirectoryWatcher.h"
#include "llvm/Support/FileSystem.h"
#include <optional>
#include <string>
#include <vector>
@ -24,6 +25,6 @@ getAsFileEvents(const std::vector<std::string> &Scan);
/// Gets status of file (or directory) at \p Path.
/// \returns std::nullopt if \p Path doesn't exist or can't get the status.
llvm::Optional<llvm::sys::fs::file_status> getFileStatus(llvm::StringRef Path);
std::optional<llvm::sys::fs::file_status> getFileStatus(llvm::StringRef Path);
} // namespace clang

View File

@ -10,7 +10,7 @@
#define LLVM_CLANG_ANALYZER_WEBKIT_PTRTYPESEMANTICS_H
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/Optional.h"
#include <optional>
namespace clang {
class CXXBaseSpecifier;
@ -28,30 +28,30 @@ class Type;
/// \returns CXXRecordDecl of the base if the type is ref-countable, nullptr if
/// not, std::nullopt if inconclusive.
llvm::Optional<const clang::CXXRecordDecl *>
isRefCountable(const clang::CXXBaseSpecifier *Base);
std::optional<const clang::CXXRecordDecl*>
isRefCountable(const clang::CXXBaseSpecifier* Base);
/// \returns true if \p Class is ref-countable, false if not, std::nullopt if
/// inconclusive.
llvm::Optional<bool> isRefCountable(const clang::CXXRecordDecl *Class);
std::optional<bool> isRefCountable(const clang::CXXRecordDecl* Class);
/// \returns true if \p Class is ref-counted, false if not.
bool isRefCounted(const clang::CXXRecordDecl *Class);
/// \returns true if \p Class is ref-countable AND not ref-counted, false if
/// not, std::nullopt if inconclusive.
llvm::Optional<bool> isUncounted(const clang::CXXRecordDecl *Class);
std::optional<bool> isUncounted(const clang::CXXRecordDecl* Class);
/// \returns true if \p T is either a raw pointer or reference to an uncounted
/// class, false if not, std::nullopt if inconclusive.
llvm::Optional<bool> isUncountedPtr(const clang::Type *T);
std::optional<bool> isUncountedPtr(const clang::Type* T);
/// \returns true if \p F creates ref-countable object from uncounted parameter,
/// false if not.
bool isCtorOfRefCounted(const clang::FunctionDecl *F);
/// \returns true if \p M is getter of a ref-counted class, false if not.
llvm::Optional<bool> isGetterOfRefCounted(const clang::CXXMethodDecl *Method);
std::optional<bool> isGetterOfRefCounted(const clang::CXXMethodDecl* Method);
/// \returns true if \p F is a conversion between ref-countable or ref-counted
/// pointer types.

View File

@ -8,7 +8,6 @@
#include "clang/Support/RISCVVIntrinsicUtils.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
@ -16,6 +15,7 @@
#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
#include <numeric>
#include <optional>
using namespace llvm;
@ -362,7 +362,8 @@ void RVVType::applyBasicType() {
assert(ElementBitwidth != 0 && "Bad element bitwidth!");
}
Optional<PrototypeDescriptor> PrototypeDescriptor::parsePrototypeDescriptor(
std::optional<PrototypeDescriptor>
PrototypeDescriptor::parsePrototypeDescriptor(
llvm::StringRef PrototypeDescriptorStr) {
PrototypeDescriptor PD;
BaseTypeModifier PT = BaseTypeModifier::Invalid;
@ -783,7 +784,7 @@ void RVVType::applyFixedLog2LMUL(int Log2LMUL, enum FixedLMULType Type) {
Scale = LMUL.getScale(ElementBitwidth);
}
Optional<RVVTypes>
std::optional<RVVTypes>
RVVTypeCache::computeTypes(BasicType BT, int Log2LMUL, unsigned NF,
ArrayRef<PrototypeDescriptor> Prototype) {
// LMUL x NF must be less than or equal to 8.
@ -814,8 +815,8 @@ static uint64_t computeRVVTypeHashValue(BasicType BT, int Log2LMUL,
((uint64_t)(Proto.VTM & 0xff) << 32);
}
Optional<RVVTypePtr> RVVTypeCache::computeType(BasicType BT, int Log2LMUL,
PrototypeDescriptor Proto) {
std::optional<RVVTypePtr> RVVTypeCache::computeType(BasicType BT, int Log2LMUL,
PrototypeDescriptor Proto) {
uint64_t Idx = computeRVVTypeHashValue(BT, Log2LMUL, Proto);
// Search first
auto It = LegalTypes.find(Idx);

View File

@ -53,6 +53,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include <atomic>
#include <optional>
using namespace llvm;
using namespace llvm::opt;
@ -1231,8 +1232,8 @@ linkAndWrapDeviceFiles(SmallVectorImpl<OffloadFile> &LinkerInputFiles,
return WrappedOutput;
}
Optional<std::string> findFile(StringRef Dir, StringRef Root,
const Twine &Name) {
std::optional<std::string> findFile(StringRef Dir, StringRef Root,
const Twine &Name) {
SmallString<128> Path;
if (Dir.startswith("="))
sys::path::append(Path, Root, Dir.substr(1), Name);
@ -1244,20 +1245,24 @@ Optional<std::string> findFile(StringRef Dir, StringRef Root,
return std::nullopt;
}
Optional<std::string> findFromSearchPaths(StringRef Name, StringRef Root,
ArrayRef<StringRef> SearchPaths) {
std::optional<std::string>
findFromSearchPaths(StringRef Name, StringRef Root,
ArrayRef<StringRef> SearchPaths) {
for (StringRef Dir : SearchPaths)
if (Optional<std::string> File = findFile(Dir, Root, Name))
if (std::optional<std::string> File = findFile(Dir, Root, Name))
return File;
return std::nullopt;
}
Optional<std::string> searchLibraryBaseName(StringRef Name, StringRef Root,
ArrayRef<StringRef> SearchPaths) {
std::optional<std::string>
searchLibraryBaseName(StringRef Name, StringRef Root,
ArrayRef<StringRef> SearchPaths) {
for (StringRef Dir : SearchPaths) {
if (Optional<std::string> File = findFile(Dir, Root, "lib" + Name + ".so"))
if (std::optional<std::string> File =
findFile(Dir, Root, "lib" + Name + ".so"))
return File;
if (Optional<std::string> File = findFile(Dir, Root, "lib" + Name + ".a"))
if (std::optional<std::string> File =
findFile(Dir, Root, "lib" + Name + ".a"))
return File;
}
return std::nullopt;
@ -1265,8 +1270,8 @@ Optional<std::string> searchLibraryBaseName(StringRef Name, StringRef Root,
/// Search for static libraries in the linker's library path given input like
/// `-lfoo` or `-l:libfoo.a`.
Optional<std::string> searchLibrary(StringRef Input, StringRef Root,
ArrayRef<StringRef> SearchPaths) {
std::optional<std::string> searchLibrary(StringRef Input, StringRef Root,
ArrayRef<StringRef> SearchPaths) {
if (Input.startswith(":"))
return findFromSearchPaths(Input.drop_front(), Root, SearchPaths);
return searchLibraryBaseName(Input, Root, SearchPaths);

View File

@ -15,6 +15,7 @@
#include <condition_variable>
#include <future>
#include <mutex>
#include <optional>
#include <thread>
using namespace llvm;
@ -177,7 +178,7 @@ struct VerifyingConsumer {
}
// Not locking - caller has to lock Mtx.
llvm::Optional<bool> result() const {
std::optional<bool> result() const {
if (ExpectedInitial.empty() && ExpectedNonInitial.empty() &&
UnexpectedInitial.empty() && UnexpectedNonInitial.empty())
return true;

View File

@ -19,6 +19,7 @@
#include <functional>
#include <map>
#include <memory>
#include <optional>
#include <set>
#define DEBUG_TYPE "libclang-test"
@ -934,7 +935,7 @@ void Class1::fun() {}
ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args, 1,
nullptr, 0, TUFlags);
llvm::Optional<CXCursor> typeRefCsr;
std::optional<CXCursor> typeRefCsr;
Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
if (cursor.kind == CXCursor_TypeRef) {
typeRefCsr.emplace(cursor);

View File

@ -12,7 +12,6 @@
#include "TableGenBackends.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
@ -30,6 +29,7 @@
#include <cctype>
#include <functional>
#include <map>
#include <optional>
#include <set>
using namespace llvm;
@ -250,8 +250,9 @@ typedef llvm::PointerUnion<RecordVec*, RecordSet*> VecOrSet;
namespace {
class InferPedantic {
typedef llvm::DenseMap<const Record*,
std::pair<unsigned, Optional<unsigned> > > GMap;
typedef llvm::DenseMap<const Record *,
std::pair<unsigned, std::optional<unsigned>>>
GMap;
DiagGroupParentMap &DiagGroupParents;
const std::vector<Record*> &Diags;
@ -675,7 +676,7 @@ private:
};
template <class Derived> struct DiagTextVisitor {
using ModifierMappingsType = Optional<std::vector<int>>;
using ModifierMappingsType = std::optional<std::vector<int>>;
private:
Derived &getDerived() { return static_cast<Derived &>(*this); }
@ -706,7 +707,7 @@ public:
private:
DiagTextVisitor &Visitor;
Optional<std::vector<int>> OldMappings;
std::optional<std::vector<int>> OldMappings;
public:
Piece *Substitution;

View File

@ -26,7 +26,6 @@
#include "TableGenBackends.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
@ -44,6 +43,7 @@
#include <cstdint>
#include <deque>
#include <map>
#include <optional>
#include <set>
#include <sstream>
#include <string>
@ -559,7 +559,7 @@ public:
/// Called by Intrinsic - this attempts to get an intrinsic that takes
/// the given types as arguments.
Intrinsic &getIntrinsic(StringRef Name, ArrayRef<Type> Types,
Optional<std::string> MangledName);
std::optional<std::string> MangledName);
/// Called by Intrinsic - returns a globally-unique number.
unsigned getUniqueNumber() { return UniqueNumber++; }
@ -1471,7 +1471,7 @@ Intrinsic::DagEmitter::emitDagCall(DagInit *DI, bool MatchMangledName) {
N = SI->getAsUnquotedString();
else
N = emitDagArg(DI->getArg(0), "").second;
Optional<std::string> MangledName;
std::optional<std::string> MangledName;
if (MatchMangledName) {
if (Intr.getRecord()->getValueAsBit("isLaneQ"))
N += "q";
@ -1895,7 +1895,7 @@ void Intrinsic::indexBody() {
//===----------------------------------------------------------------------===//
Intrinsic &NeonEmitter::getIntrinsic(StringRef Name, ArrayRef<Type> Types,
Optional<std::string> MangledName) {
std::optional<std::string> MangledName) {
// First, look up the name in the intrinsic map.
assert_with_loc(IntrinsicMap.find(Name.str()) != IntrinsicMap.end(),
("Intrinsic '" + Name + "' not found!").str());

View File

@ -25,6 +25,7 @@
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include <numeric>
#include <optional>
using namespace llvm;
using namespace clang::RISCV;
@ -560,7 +561,7 @@ void RVVEmitter::createRVVIntrinsics(
for (char I : TypeRange) {
for (int Log2LMUL : Log2LMULList) {
BasicType BT = ParseBasicType(I);
Optional<RVVTypes> Types =
std::optional<RVVTypes> Types =
TypeCache.computeTypes(BT, Log2LMUL, NF, Prototype);
// Ignored to create new intrinsic if there are any illegal types.
if (!Types)
@ -584,7 +585,7 @@ void RVVEmitter::createRVVIntrinsics(
BasicPrototype, /*IsMasked=*/false,
/*HasMaskedOffOperand=*/false, HasVL, NF,
IsPrototypeDefaultTU, UnMaskedPolicyScheme, P);
Optional<RVVTypes> PolicyTypes =
std::optional<RVVTypes> PolicyTypes =
TypeCache.computeTypes(BT, Log2LMUL, NF, PolicyPrototype);
Out.push_back(std::make_unique<RVVIntrinsic>(
Name, SuffixStr, OverloadedName, OverloadedSuffixStr, IRName,
@ -596,7 +597,7 @@ void RVVEmitter::createRVVIntrinsics(
if (!HasMasked)
continue;
// Create a masked intrinsic
Optional<RVVTypes> MaskTypes =
std::optional<RVVTypes> MaskTypes =
TypeCache.computeTypes(BT, Log2LMUL, NF, Prototype);
Out.push_back(std::make_unique<RVVIntrinsic>(
Name, SuffixStr, OverloadedName, OverloadedSuffixStr, MaskedIRName,
@ -611,7 +612,7 @@ void RVVEmitter::createRVVIntrinsics(
RVVIntrinsic::computeBuiltinTypes(
BasicPrototype, /*IsMasked=*/true, HasMaskedOffOperand, HasVL,
NF, IsPrototypeDefaultTU, MaskedPolicyScheme, P);
Optional<RVVTypes> PolicyTypes =
std::optional<RVVTypes> PolicyTypes =
TypeCache.computeTypes(BT, Log2LMUL, NF, PolicyPrototype);
Out.push_back(std::make_unique<RVVIntrinsic>(
Name, SuffixStr, OverloadedName, OverloadedSuffixStr,