Don't use Optional::hasValue (NFC)

This commit is contained in:
Kazu Hirata 2022-06-20 20:26:05 -07:00
parent 0916d96d12
commit d66cbc565a
18 changed files with 20 additions and 44 deletions

View File

@ -440,8 +440,7 @@ public:
}
void
setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
RawRetainCountConvention =
Value.hasValue() ? static_cast<unsigned>(Value.getValue()) + 1 : 0;
RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
assert(getRetainCountConvention() == Value && "bitfield too small");
}
@ -559,8 +558,7 @@ public:
}
void
setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
RawRetainCountConvention =
Value.hasValue() ? static_cast<unsigned>(Value.getValue()) + 1 : 0;
RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
assert(getRetainCountConvention() == Value && "bitfield too small");
}

View File

@ -142,8 +142,7 @@ public:
auto Mapping = VersionMappings.find(Kind.Value);
if (Mapping == VersionMappings.end())
return nullptr;
return Mapping->getSecond().hasValue() ? Mapping->getSecond().getPointer()
: nullptr;
return Mapping->getSecond() ? Mapping->getSecond().getPointer() : nullptr;
}
static Optional<DarwinSDKInfo>

View File

@ -201,8 +201,7 @@ MacroDirective::DefInfo MacroDirective::getDefinition() {
Optional<bool> isPublic;
for (; MD; MD = MD->getPrevious()) {
if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD))
return DefInfo(DefMD, UndefLoc,
!isPublic.hasValue() || isPublic.getValue());
return DefInfo(DefMD, UndefLoc, !isPublic || *isPublic);
if (UndefMacroDirective *UndefMD = dyn_cast<UndefMacroDirective>(MD)) {
UndefLoc = UndefMD->getLocation();

View File

@ -61,8 +61,7 @@ Expected<json::Value> FifoFileIO::ReadJSON(std::chrono::milliseconds timeout) {
if (!buffer.empty())
line = buffer;
}));
if (future->wait_for(timeout) == std::future_status::timeout ||
!line.hasValue())
if (future->wait_for(timeout) == std::future_status::timeout || !line)
return createStringError(inconvertibleErrorCode(),
"Timed out trying to get messages from the " +
m_other_endpoint_name);

View File

@ -102,9 +102,7 @@ struct FunctionInfo {
/// debug info, we might end up with multiple FunctionInfo objects for the
/// same range and we need to be able to tell which one is the better object
/// to use.
bool hasRichInfo() const {
return OptLineTable.hasValue() || Inline.hasValue();
}
bool hasRichInfo() const { return OptLineTable || Inline; }
/// Query if a FunctionInfo object is valid.
///

View File

@ -221,8 +221,7 @@ struct Frame {
void printYAML(raw_ostream &OS) const {
OS << " -\n"
<< " Function: " << Function << "\n"
<< " SymbolName: "
<< (SymbolName.hasValue() ? SymbolName.getValue() : "<None>") << "\n"
<< " SymbolName: " << SymbolName.value_or("<None>") << "\n"
<< " LineOffset: " << LineOffset << "\n"
<< " Column: " << Column << "\n"
<< " Inline: " << IsInlineFrame << "\n";

View File

@ -689,9 +689,7 @@ struct RegsForValue {
const DataLayout &DL, unsigned Reg, Type *Ty,
Optional<CallingConv::ID> CC);
bool isABIMangled() const {
return CallConv.hasValue();
}
bool isABIMangled() const { return CallConv.has_value(); }
/// Add the specified values to this one.
void append(const RegsForValue &RHS) {

View File

@ -1364,8 +1364,7 @@ static void sectionMapping(IO &IO, ELFYAML::HashSection &Section) {
// obj2yaml does not dump these fields. They can be used to override nchain
// and nbucket values for creating broken sections.
assert(!IO.outputting() ||
(!Section.NBucket.hasValue() && !Section.NChain.hasValue()));
assert(!IO.outputting() || (!Section.NBucket && !Section.NChain));
IO.mapOptional("NChain", Section.NChain);
IO.mapOptional("NBucket", Section.NBucket);
}

View File

@ -419,8 +419,7 @@ public:
getNumRegisters(LLVMContext &Context, EVT VT,
Optional<MVT> RegisterVT) const override {
// i128 inline assembly operand.
if (VT == MVT::i128 &&
RegisterVT.hasValue() && RegisterVT.getValue() == MVT::Untyped)
if (VT == MVT::i128 && RegisterVT && *RegisterVT == MVT::Untyped)
return 1;
return TargetLowering::getNumRegisters(Context, VT);
}

View File

@ -701,8 +701,7 @@ PreservedAnalyses LoopSimplifyCFGPass::run(Loop &L, LoopAnalysisManager &AM,
MSSAU = MemorySSAUpdater(AR.MSSA);
bool DeleteCurrentLoop = false;
if (!simplifyLoopCFG(L, AR.DT, AR.LI, AR.SE,
MSSAU.hasValue() ? MSSAU.getPointer() : nullptr,
DeleteCurrentLoop))
MSSAU ? MSSAU.getPointer() : nullptr, DeleteCurrentLoop))
return PreservedAnalyses::all();
if (DeleteCurrentLoop)

View File

@ -3151,8 +3151,7 @@ PreservedAnalyses SimpleLoopUnswitchPass::run(Loop &L, LoopAnalysisManager &AM,
AR.MSSA->verifyMemorySSA();
}
if (!unswitchLoop(L, AR.DT, AR.LI, AR.AC, AR.AA, AR.TTI, Trivial, NonTrivial,
UnswitchCB, &AR.SE,
MSSAU.hasValue() ? MSSAU.getPointer() : nullptr,
UnswitchCB, &AR.SE, MSSAU ? MSSAU.getPointer() : nullptr,
DestroyLoopCB))
return PreservedAnalyses::all();

View File

@ -265,8 +265,7 @@ bool CodeCoverageTool::isEquivalentFile(StringRef FilePath1,
StringRef FilePath2) {
auto Status1 = getFileStatus(FilePath1);
auto Status2 = getFileStatus(FilePath2);
return Status1.hasValue() && Status2.hasValue() &&
sys::fs::equivalent(Status1.getValue(), Status2.getValue());
return Status1 && Status2 && sys::fs::equivalent(*Status1, *Status2);
}
ErrorOr<const MemoryBuffer &>

View File

@ -229,8 +229,7 @@ template <> struct stringifier<Twine> {
template <typename OptionalT>
struct stringifier<Optional<OptionalT>> {
static std::string apply(Optional<OptionalT> optional) {
return optional.hasValue() ? stringifier<OptionalT>::apply(*optional)
: std::string();
return optional ? stringifier<OptionalT>::apply(*optional) : std::string();
}
};
} // namespace detail

View File

@ -626,9 +626,7 @@ Matrix IntegerRelation::getBoundedDirections() const {
return dirs;
}
bool IntegerRelation::isIntegerEmpty() const {
return !findIntegerSample().hasValue();
}
bool IntegerRelation::isIntegerEmpty() const { return !findIntegerSample(); }
/// Let this set be S. If S is bounded then we directly call into the GBR
/// sampling algorithm. Otherwise, there are some unbounded directions, i.e.,

View File

@ -251,8 +251,7 @@ static Optional<Type> convertArrayType(spirv::ArrayType type,
unsigned stride = type.getArrayStride();
Type elementType = type.getElementType();
auto sizeInBytes = elementType.cast<spirv::SPIRVType>().getSizeInBytes();
if (stride != 0 &&
!(sizeInBytes.hasValue() && sizeInBytes.getValue() == stride))
if (stride != 0 && !(sizeInBytes && *sizeInBytes == stride))
return llvm::None;
auto llvmElementType = converter.convertType(elementType);

View File

@ -1134,8 +1134,7 @@ void mlir::getComputationSliceState(
// 3. Is being inserted at the innermost insertion point.
Optional<bool> isMaximal = sliceState->isMaximal();
if (isLoopParallelAndContainsReduction(getSliceLoop(i)) &&
isInnermostInsertion() && srcIsUnitSlice() && isMaximal.hasValue() &&
isMaximal.getValue())
isInnermostInsertion() && srcIsUnitSlice() && isMaximal && *isMaximal)
continue;
for (unsigned j = i; j < numSliceLoopIVs; ++j) {
sliceState->lbs[j] = AffineMap();

View File

@ -1297,9 +1297,7 @@ static bool isFusionProfitable(Operation *srcOpInst, Operation *srcStoreOpInst,
msg << " fusion is most profitable at depth " << *dstLoopDepth << " with "
<< std::setprecision(2) << additionalComputeFraction
<< "% redundant computation and a ";
msg << (storageReduction.hasValue()
? std::to_string(storageReduction.getValue())
: "<unknown>");
msg << (storageReduction ? std::to_string(*storageReduction) : "<unknown>");
msg << "% storage reduction.\n";
llvm::dbgs() << msg.str();
});

View File

@ -1108,8 +1108,7 @@ LogicalResult mlir::loopUnrollByFactor(
// If the trip count is lower than the unroll factor, no unrolled body.
// TODO: option to specify cleanup loop unrolling.
if (mayBeConstantTripCount.hasValue() &&
mayBeConstantTripCount.getValue() < unrollFactor)
if (mayBeConstantTripCount && *mayBeConstantTripCount < unrollFactor)
return failure();
// Generate the cleanup loop if trip count isn't a multiple of unrollFactor.
@ -1216,8 +1215,7 @@ LogicalResult mlir::loopUnrollJamByFactor(AffineForOp forOp,
return success();
// If the trip count is lower than the unroll jam factor, no unroll jam.
if (mayBeConstantTripCount.hasValue() &&
mayBeConstantTripCount.getValue() < unrollJamFactor) {
if (mayBeConstantTripCount && *mayBeConstantTripCount < unrollJamFactor) {
LLVM_DEBUG(llvm::dbgs() << "[failed] trip count < unroll-jam factor\n");
return failure();
}