diff --git a/llvm/include/llvm/Analysis/VectorUtils.h b/llvm/include/llvm/Analysis/VectorUtils.h index df460cb49aeeb4..0005874ba04065 100644 --- a/llvm/include/llvm/Analysis/VectorUtils.h +++ b/llvm/include/llvm/Analysis/VectorUtils.h @@ -236,7 +236,7 @@ class VFDatabase { // ensuring that the variant described in the attribute has a // corresponding definition or declaration of the vector // function in the Module M. - if (Shape.hasValue() && (Shape.getValue().ScalarName == ScalarName)) { + if (Shape && (Shape.getValue().ScalarName == ScalarName)) { assert(CI.getModule()->getFunction(Shape.getValue().VectorName) && "Vector function is missing."); Mappings.push_back(Shape.getValue()); diff --git a/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h b/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h index fa6f904e33a1cc..c06b33d1117048 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h @@ -674,7 +674,7 @@ bool InstructionSelector::executeMatchTable( ComplexRendererFns Renderer = (ISel.*ISelInfo.ComplexPredicates[ComplexPredicateID])( State.MIs[InsnID]->getOperand(OpIdx)); - if (Renderer.hasValue()) + if (Renderer) State.Renderers[RendererID] = Renderer.getValue(); else if (handleReject() == RejectAndGiveUp) diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index 2b387db47ed250..3ab2b7ca515e07 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -1168,11 +1168,11 @@ class IRBuilderBase { Value *getConstrainedFPRounding(Optional Rounding) { RoundingMode UseRounding = DefaultConstrainedRounding; - if (Rounding.hasValue()) + if (Rounding) UseRounding = Rounding.getValue(); Optional RoundingStr = convertRoundingModeToStr(UseRounding); - assert(RoundingStr.hasValue() && "Garbage strict rounding mode!"); + assert(RoundingStr && "Garbage strict rounding mode!"); auto *RoundingMDS = MDString::get(Context, RoundingStr.getValue()); return MetadataAsValue::get(Context, RoundingMDS); @@ -1181,11 +1181,11 @@ class IRBuilderBase { Value *getConstrainedFPExcept(Optional Except) { fp::ExceptionBehavior UseExcept = DefaultConstrainedExcept; - if (Except.hasValue()) + if (Except) UseExcept = Except.getValue(); Optional ExceptStr = convertExceptionBehaviorToStr(UseExcept); - assert(ExceptStr.hasValue() && "Garbage strict exception behavior!"); + assert(ExceptStr && "Garbage strict exception behavior!"); auto *ExceptMDS = MDString::get(Context, ExceptStr.getValue()); return MetadataAsValue::get(Context, ExceptMDS); diff --git a/llvm/include/llvm/MC/MCSymbolWasm.h b/llvm/include/llvm/MC/MCSymbolWasm.h index 5a4852e0e89550..e487cf0af187d2 100644 --- a/llvm/include/llvm/MC/MCSymbolWasm.h +++ b/llvm/include/llvm/MC/MCSymbolWasm.h @@ -88,7 +88,7 @@ class MCSymbolWasm : public MCSymbol { bool hasImportModule() const { return ImportModule.hasValue(); } StringRef getImportModule() const { - if (ImportModule.hasValue()) + if (ImportModule) return ImportModule.getValue(); // Use a default module name of "env" for now, for compatibility with // existing tools. @@ -100,7 +100,7 @@ class MCSymbolWasm : public MCSymbol { bool hasImportName() const { return ImportName.hasValue(); } StringRef getImportName() const { - if (ImportName.hasValue()) + if (ImportName) return ImportName.getValue(); return getName(); } @@ -129,7 +129,7 @@ class MCSymbolWasm : public MCSymbol { void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; } const wasm::WasmGlobalType &getGlobalType() const { - assert(GlobalType.hasValue()); + assert(GlobalType); return GlobalType.getValue(); } void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; } diff --git a/llvm/include/llvm/MC/MCSymbolXCOFF.h b/llvm/include/llvm/MC/MCSymbolXCOFF.h index 752e1e7bba0f2f..2ec265e66300df 100644 --- a/llvm/include/llvm/MC/MCSymbolXCOFF.h +++ b/llvm/include/llvm/MC/MCSymbolXCOFF.h @@ -39,8 +39,7 @@ class MCSymbolXCOFF : public MCSymbol { }; XCOFF::StorageClass getStorageClass() const { - assert(StorageClass.hasValue() && - "StorageClass not set on XCOFF MCSymbol."); + assert(StorageClass && "StorageClass not set on XCOFF MCSymbol."); return StorageClass.getValue(); } diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h index 80a5212b8f076e..1a801b6f2c7aa5 100644 --- a/llvm/include/llvm/Support/Error.h +++ b/llvm/include/llvm/Support/Error.h @@ -1269,7 +1269,7 @@ class FileError final : public ErrorInfo { void log(raw_ostream &OS) const override { assert(Err && "Trying to log after takeError()."); OS << "'" << FileName << "': "; - if (Line.hasValue()) + if (Line) OS << "line " << Line.getValue() << ": "; Err->log(OS); } diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h index dfe9b1b0d93970..634fd47873baa7 100644 --- a/llvm/include/llvm/Support/YAMLTraits.h +++ b/llvm/include/llvm/Support/YAMLTraits.h @@ -1668,14 +1668,13 @@ template void IO::processKeyWithDefault(const char *Key, Optional &Val, const Optional &DefaultValue, bool Required, Context &Ctx) { - assert(DefaultValue.hasValue() == false && - "Optional shouldn't have a value!"); + assert(!DefaultValue && "Optional shouldn't have a value!"); void *SaveInfo; bool UseDefault = true; const bool sameAsDefault = outputting() && !Val.hasValue(); - if (!outputting() && !Val.hasValue()) + if (!outputting() && !Val) Val = T(); - if (Val.hasValue() && + if (Val && this->preflightKey(Key, Required, sameAsDefault, UseDefault, SaveInfo)) { // When reading an Optional key from a YAML description, we allow the diff --git a/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp b/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp index 1216d03e448b1d..602a01867f3b5d 100644 --- a/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp +++ b/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp @@ -831,14 +831,14 @@ CFLAndersAAResult::ensureCached(const Function &Fn) { scan(Fn); Iter = Cache.find(&Fn); assert(Iter != Cache.end()); - assert(Iter->second.hasValue()); + assert(Iter->second); } return Iter->second; } const AliasSummary *CFLAndersAAResult::getAliasSummary(const Function &Fn) { auto &FunInfo = ensureCached(Fn); - if (FunInfo.hasValue()) + if (FunInfo) return &FunInfo->getAliasSummary(); else return nullptr; diff --git a/llvm/lib/Analysis/CFLSteensAliasAnalysis.cpp b/llvm/lib/Analysis/CFLSteensAliasAnalysis.cpp index b831a599cc091f..f92869c2ec636b 100644 --- a/llvm/lib/Analysis/CFLSteensAliasAnalysis.cpp +++ b/llvm/lib/Analysis/CFLSteensAliasAnalysis.cpp @@ -250,14 +250,14 @@ CFLSteensAAResult::ensureCached(Function *Fn) { scan(Fn); Iter = Cache.find(Fn); assert(Iter != Cache.end()); - assert(Iter->second.hasValue()); + assert(Iter->second); } return Iter->second; } const AliasSummary *CFLSteensAAResult::getAliasSummary(Function &Fn) { auto &FunInfo = ensureCached(&Fn); - if (FunInfo.hasValue()) + if (FunInfo) return &FunInfo->getAliasSummary(); else return nullptr; @@ -293,15 +293,15 @@ AliasResult CFLSteensAAResult::query(const MemoryLocation &LocA, assert(Fn != nullptr); auto &MaybeInfo = ensureCached(Fn); - assert(MaybeInfo.hasValue()); + assert(MaybeInfo); auto &Sets = MaybeInfo->getStratifiedSets(); auto MaybeA = Sets.find(InstantiatedValue{ValA, 0}); - if (!MaybeA.hasValue()) + if (!MaybeA) return AliasResult::MayAlias; auto MaybeB = Sets.find(InstantiatedValue{ValB, 0}); - if (!MaybeB.hasValue()) + if (!MaybeB) return AliasResult::MayAlias; auto SetA = *MaybeA; diff --git a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp index c9450506d46c25..3d51042f4da8bb 100644 --- a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp +++ b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp @@ -183,7 +183,7 @@ CmpInst::Predicate IRInstructionData::getPredicate() const { assert(isa(Inst) && "Can only get a predicate from a compare instruction"); - if (RevisedPredicate.hasValue()) + if (RevisedPredicate) return RevisedPredicate.getValue(); return cast(Inst)->getPredicate(); diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index 63fe651bb57188..753071c2b88e37 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -703,7 +703,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { BlockFrequencyInfo *BFI = &(GetBFI(F)); assert(BFI && "BFI must be available"); auto ProfileCount = BFI->getBlockProfileCount(BB); - assert(ProfileCount.hasValue()); + assert(ProfileCount); if (ProfileCount.getValue() == 0) ColdSize += Cost - CostAtBBStart; } @@ -828,14 +828,14 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { } auto ProfileCount = CalleeBFI->getBlockProfileCount(&BB); - assert(ProfileCount.hasValue()); + assert(ProfileCount); CurrentSavings *= ProfileCount.getValue(); CycleSavings += CurrentSavings; } // Compute the cycle savings per call. auto EntryProfileCount = F.getEntryCount(); - assert(EntryProfileCount.hasValue() && EntryProfileCount->getCount()); + assert(EntryProfileCount && EntryProfileCount->getCount()); auto EntryCount = EntryProfileCount->getCount(); CycleSavings += EntryCount / 2; CycleSavings = CycleSavings.udiv(EntryCount); diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 5803c3d7f50d47..8a8e9e923b7c0b 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -918,7 +918,7 @@ Optional LazyValueInfoImpl::solveBlockValueCast( // transfer rule on the full set since we may be able to locally infer // interesting facts. Optional LHSRes = getRangeFor(CI->getOperand(0), CI, BB); - if (!LHSRes.hasValue()) + if (!LHSRes) // More work to do before applying this transfer rule. return None; const ConstantRange &LHSRange = LHSRes.getValue(); diff --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp b/llvm/lib/Analysis/LoopCacheAnalysis.cpp index 002e9930280346..2cbf1f7f2d28ea 100644 --- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp +++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp @@ -645,8 +645,8 @@ bool CacheCost::populateReferenceGroups(ReferenceGroupsTy &RefGroups) const { Optional HasSpacialReuse = R->hasSpacialReuse(Representative, CLS, AA); - if ((HasTemporalReuse.hasValue() && *HasTemporalReuse) || - (HasSpacialReuse.hasValue() && *HasSpacialReuse)) { + if ((HasTemporalReuse && *HasTemporalReuse) || + (HasSpacialReuse && *HasSpacialReuse)) { RefGroup.push_back(std::move(R)); Added = true; break; diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index 3c0e494bf1da7d..902581b597972c 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -501,10 +501,10 @@ Optional llvm::getAllocationFamily(const Value *I, if (!TLI || !TLI->getLibFunc(*Callee, TLIFn) || !TLI->has(TLIFn)) return None; const auto AllocData = getAllocationDataForFunction(Callee, AnyAlloc, TLI); - if (AllocData.hasValue()) + if (AllocData) return mangledNameForMallocFamily(AllocData.getValue().Family); const auto FreeData = getFreeFunctionDataForFunction(Callee, TLIFn); - if (FreeData.hasValue()) + if (FreeData) return mangledNameForMallocFamily(FreeData.getValue().Family); return None; } @@ -512,7 +512,7 @@ Optional llvm::getAllocationFamily(const Value *I, /// isLibFreeFunction - Returns true if the function is a builtin free() bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) { Optional FnData = getFreeFunctionDataForFunction(F, TLIFn); - if (!FnData.hasValue()) + if (!FnData) return false; // Check free prototype. diff --git a/llvm/lib/Analysis/MemorySSA.cpp b/llvm/lib/Analysis/MemorySSA.cpp index f63898be317354..56dc6e7291d56d 100644 --- a/llvm/lib/Analysis/MemorySSA.cpp +++ b/llvm/lib/Analysis/MemorySSA.cpp @@ -751,7 +751,7 @@ template class ClobberWalker { bool operator==(const generic_def_path_iterator &O) const { if (N.hasValue() != O.N.hasValue()) return false; - return !N.hasValue() || *N == *O.N; + return !N || *N == *O.N; } private: diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp index c785b500e760c8..5cff986245b9e3 100644 --- a/llvm/lib/Analysis/MustExecute.cpp +++ b/llvm/lib/Analysis/MustExecute.cpp @@ -491,7 +491,7 @@ template static V getOrCreateCachedOptional(K Key, DenseMap> &Map, FnTy &&Fn, ArgsTy&&... args) { Optional &OptVal = Map[Key]; - if (!OptVal.hasValue()) + if (!OptVal) OptVal = Fn(std::forward(args)...); return OptVal.getValue(); } diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 5eb5c6b7c594af..9a9703f995ee8b 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -4847,7 +4847,7 @@ class SCEVBackedgeConditionFolder SelectInst *SI = cast(I); Optional Res = compareWithBackedgeCondition(SI->getCondition()); - if (Res.hasValue()) { + if (Res) { bool IsOne = cast(Res.getValue())->getValue()->isOne(); Result = SE.getSCEV(IsOne ? SI->getTrueValue() : SI->getFalseValue()); } @@ -4855,7 +4855,7 @@ class SCEVBackedgeConditionFolder } default: { Optional Res = compareWithBackedgeCondition(I); - if (Res.hasValue()) + if (Res) Result = Res.getValue(); break; } @@ -6596,7 +6596,7 @@ ScalarEvolution::getRangeRef(const SCEV *S, // Check if the IR explicitly contains !range metadata. Optional MDRange = GetRangeFromMetadata(U->getValue()); - if (MDRange.hasValue()) + if (MDRange) ConservativeResult = ConservativeResult.intersectWith(MDRange.getValue(), RangeType); @@ -9710,15 +9710,15 @@ GetQuadraticEquation(const SCEVAddRecExpr *AddRec) { /// (b) if neither X nor Y exist, return None, /// (c) if exactly one of X and Y exists, return that value. static Optional MinOptional(Optional X, Optional Y) { - if (X.hasValue() && Y.hasValue()) { + if (X && Y) { unsigned W = std::max(X->getBitWidth(), Y->getBitWidth()); APInt XW = X->sext(W); APInt YW = Y->sext(W); return XW.slt(YW) ? *X : *Y; } - if (!X.hasValue() && !Y.hasValue()) + if (!X && !Y) return None; - return X.hasValue() ? *X : *Y; + return X ? *X : *Y; } /// Helper function to truncate an optional APInt to a given BitWidth. @@ -9760,13 +9760,13 @@ SolveQuadraticAddRecExact(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) { APInt A, B, C, M; unsigned BitWidth; auto T = GetQuadraticEquation(AddRec); - if (!T.hasValue()) + if (!T) return None; std::tie(A, B, C, M, BitWidth) = *T; LLVM_DEBUG(dbgs() << __func__ << ": solving for unsigned overflow\n"); Optional X = APIntOps::SolveQuadraticEquationWrap(A, B, C, BitWidth+1); - if (!X.hasValue()) + if (!X) return None; ConstantInt *CX = ConstantInt::get(SE.getContext(), *X); @@ -10471,7 +10471,7 @@ ScalarEvolution::getMonotonicPredicateType(const SCEVAddRecExpr *LHS, auto ResultSwapped = getMonotonicPredicateTypeImpl(LHS, ICmpInst::getSwappedPredicate(Pred)); - assert(ResultSwapped.hasValue() && "should be able to analyze both!"); + assert(ResultSwapped && "should be able to analyze both!"); assert(ResultSwapped.getValue() != Result.getValue() && "monotonicity should flip as we flip the predicate"); } diff --git a/llvm/lib/Analysis/StratifiedSets.h b/llvm/lib/Analysis/StratifiedSets.h index 8468f2b0d10405..de2321bca4c18c 100644 --- a/llvm/lib/Analysis/StratifiedSets.h +++ b/llvm/lib/Analysis/StratifiedSets.h @@ -343,7 +343,7 @@ template class StratifiedSetsBuilder { bool has(const T &Elem) const { return get(Elem).hasValue(); } bool add(const T &Main) { - if (get(Main).hasValue()) + if (get(Main)) return false; auto NewIndex = getNewUnlinkedIndex(); diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp index beb14c456da8a4..f863a1ffad3afe 100644 --- a/llvm/lib/Analysis/VectorUtils.cpp +++ b/llvm/lib/Analysis/VectorUtils.cpp @@ -1501,7 +1501,7 @@ void VFABI::getVectorVariantNames( #ifndef NDEBUG LLVM_DEBUG(dbgs() << "VFABI: adding mapping '" << S << "'\n"); Optional Info = VFABI::tryDemangleForVFABI(S, *(CI.getModule())); - assert(Info.hasValue() && "Invalid name for a VFABI variant."); + assert(Info && "Invalid name for a VFABI variant."); assert(CI.getModule()->getFunction(Info.getValue().VectorName) && "Vector function is missing."); #endif diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp index 674649c5f386ee..4436fd1f4564ff 100644 --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -1296,7 +1296,7 @@ bool CombinerHelper::matchCombineConstantFoldFpUnary(MachineInstr &MI, void CombinerHelper::applyCombineConstantFoldFpUnary(MachineInstr &MI, Optional &Cst) { - assert(Cst.hasValue() && "Optional is unexpectedly empty!"); + assert(Cst && "Optional is unexpectedly empty!"); Builder.setInstrAndDebugLoc(MI); MachineFunction &MF = Builder.getMF(); auto *FPVal = ConstantFP::get(MF.getFunction().getContext(), *Cst); diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 879ec00b3d63cb..62ce62f72334bb 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -741,7 +741,7 @@ bool MIParser::parseBasicBlockDefinition( MBB->setIsEHPad(IsLandingPad); MBB->setIsInlineAsmBrIndirectTarget(IsInlineAsmBrIndirectTarget); MBB->setIsEHFuncletEntry(IsEHFuncletEntry); - if (SectionID.hasValue()) { + if (SectionID) { MBB->setSectionID(SectionID.getValue()); MF.setBBSectionsType(BasicBlockSection::List); } diff --git a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp index 7d0f294ca5523f..81c97ba6a08662 100644 --- a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp +++ b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp @@ -106,9 +106,8 @@ bool MachineFunctionSplitter::runOnMachineFunction(MachineFunction &MF) { // We don't want to proceed further for cold functions // or functions of unknown hotness. Lukewarm functions have no prefix. Optional SectionPrefix = MF.getFunction().getSectionPrefix(); - if (SectionPrefix.hasValue() && - (SectionPrefix.getValue().equals("unlikely") || - SectionPrefix.getValue().equals("unknown"))) { + if (SectionPrefix && (SectionPrefix.getValue().equals("unlikely") || + SectionPrefix.getValue().equals("unknown"))) { return false; } diff --git a/llvm/lib/CodeGen/ModuloSchedule.cpp b/llvm/lib/CodeGen/ModuloSchedule.cpp index 8e8cdb24452d9b..3245d9649be1f3 100644 --- a/llvm/lib/CodeGen/ModuloSchedule.cpp +++ b/llvm/lib/CodeGen/ModuloSchedule.cpp @@ -1447,7 +1447,7 @@ Register KernelRewriter::remapUse(Register Reg, MachineInstr &MI) { Register KernelRewriter::phi(Register LoopReg, Optional InitReg, const TargetRegisterClass *RC) { // If the init register is not undef, try and find an existing phi. - if (InitReg.hasValue()) { + if (InitReg) { auto I = Phis.find({LoopReg, InitReg.getValue()}); if (I != Phis.end()) return I->second; @@ -1483,18 +1483,18 @@ Register KernelRewriter::phi(Register LoopReg, Optional InitReg, if (!RC) RC = MRI.getRegClass(LoopReg); Register R = MRI.createVirtualRegister(RC); - if (InitReg.hasValue()) { + if (InitReg) { const TargetRegisterClass *ConstrainRegClass = MRI.constrainRegClass(R, MRI.getRegClass(*InitReg)); assert(ConstrainRegClass && "Expected a valid constrained register class!"); (void)ConstrainRegClass; } BuildMI(*BB, BB->getFirstNonPHI(), DebugLoc(), TII->get(TargetOpcode::PHI), R) - .addReg(InitReg.hasValue() ? *InitReg : undef(RC)) + .addReg(InitReg ? *InitReg : undef(RC)) .addMBB(PreheaderBB) .addReg(LoopReg) .addMBB(BB); - if (!InitReg.hasValue()) + if (!InitReg) UndefPhis[LoopReg] = R; else Phis[{LoopReg, *InitReg}] = R; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 15455ebbfee893..cb1df233f619d4 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -8867,7 +8867,7 @@ void SelectionDAGBuilder::visitInlineAsm(const CallBase &Call, : OpInfo; const auto RegError = getRegistersForValue(DAG, getCurSDLoc(), OpInfo, RefOpInfo); - if (RegError.hasValue()) { + if (RegError) { const MachineFunction &MF = DAG.getMachineFunction(); const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); const char *RegName = TRI.getName(RegError.getValue()); diff --git a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp index b318c2ae76623e..19a52fde44c131 100644 --- a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp @@ -196,10 +196,10 @@ static Optional findPreviousSpillSlot(const Value *Val, for (auto &IncomingValue : Phi->incoming_values()) { Optional SpillSlot = findPreviousSpillSlot(IncomingValue, Builder, LookUpDepth - 1); - if (!SpillSlot.hasValue()) + if (!SpillSlot) return None; - if (MergedResult.hasValue() && *MergedResult != *SpillSlot) + if (MergedResult && *MergedResult != *SpillSlot) return None; MergedResult = SpillSlot; @@ -530,14 +530,14 @@ lowerStatepointMetaArgs(SmallVectorImpl &Ops, GCStrategy &S = GFI->getStrategy(); for (const Value *V : SI.Bases) { auto Opt = S.isGCManagedPointer(V->getType()->getScalarType()); - if (Opt.hasValue()) { + if (Opt) { assert(Opt.getValue() && "non gc managed base pointer found in statepoint"); } } for (const Value *V : SI.Ptrs) { auto Opt = S.isGCManagedPointer(V->getType()->getScalarType()); - if (Opt.hasValue()) { + if (Opt) { assert(Opt.getValue() && "non gc managed derived pointer found in statepoint"); } diff --git a/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp b/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp index c49c2e5e1d32fd..a66f9af9883580 100644 --- a/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp +++ b/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp @@ -70,10 +70,10 @@ uint32_t CodeViewRecordIO::maxFieldLength() const { Optional Min = Limits.front().bytesRemaining(Offset); for (auto X : makeArrayRef(Limits).drop_front()) { Optional ThisMin = X.bytesRemaining(Offset); - if (ThisMin.hasValue()) - Min = (Min.hasValue()) ? std::min(*Min, *ThisMin) : *ThisMin; + if (ThisMin) + Min = Min ? std::min(*Min, *ThisMin) : *ThisMin; } - assert(Min.hasValue() && "Every field must have a maximum length!"); + assert(Min && "Every field must have a maximum length!"); return *Min; } diff --git a/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp b/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp index 9b35b237396509..27f63b9edcd037 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp @@ -228,8 +228,8 @@ static Error mapNameAndUniqueName(CodeViewRecordIO &IO, StringRef &Name, } Error TypeRecordMapping::visitTypeBegin(CVType &CVR) { - assert(!TypeKind.hasValue() && "Already in a type mapping!"); - assert(!MemberKind.hasValue() && "Already in a member mapping!"); + assert(!TypeKind && "Already in a type mapping!"); + assert(!MemberKind && "Already in a member mapping!"); // FieldList and MethodList records can be any length because they can be // split with continuation records. All other record types cannot be @@ -260,8 +260,8 @@ Error TypeRecordMapping::visitTypeBegin(CVType &CVR, TypeIndex Index) { } Error TypeRecordMapping::visitTypeEnd(CVType &Record) { - assert(TypeKind.hasValue() && "Not in a type mapping!"); - assert(!MemberKind.hasValue() && "Still in a member mapping!"); + assert(TypeKind && "Not in a type mapping!"); + assert(!MemberKind && "Still in a member mapping!"); error(IO.endRecord()); @@ -270,8 +270,8 @@ Error TypeRecordMapping::visitTypeEnd(CVType &Record) { } Error TypeRecordMapping::visitMemberBegin(CVMemberRecord &Record) { - assert(TypeKind.hasValue() && "Not in a type mapping!"); - assert(!MemberKind.hasValue() && "Already in a member mapping!"); + assert(TypeKind && "Not in a type mapping!"); + assert(!MemberKind && "Already in a member mapping!"); // The largest possible subrecord is one in which there is a record prefix, // followed by the subrecord, followed by a continuation, and that entire @@ -296,8 +296,8 @@ Error TypeRecordMapping::visitMemberBegin(CVMemberRecord &Record) { } Error TypeRecordMapping::visitMemberEnd(CVMemberRecord &Record) { - assert(TypeKind.hasValue() && "Not in a type mapping!"); - assert(MemberKind.hasValue() && "Not in a member mapping!"); + assert(TypeKind && "Not in a type mapping!"); + assert(MemberKind && "Not in a member mapping!"); if (IO.isReading()) { if (auto EC = IO.skipPadding()) diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp index 1cb332c5fd00aa..3a719bd07c8a37 100644 --- a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp @@ -427,14 +427,14 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, for (auto &Stream : DbgStreams) { uint16_t StreamNumber = kInvalidStreamIndex; - if (Stream.hasValue()) + if (Stream) StreamNumber = Stream->StreamNumber; if (auto EC = Writer.writeInteger(StreamNumber)) return EC; } for (auto &Stream : DbgStreams) { - if (!Stream.hasValue()) + if (!Stream) continue; assert(Stream->StreamNumber != kInvalidStreamIndex); diff --git a/llvm/lib/Frontend/OpenMP/OMPContext.cpp b/llvm/lib/Frontend/OpenMP/OMPContext.cpp index eea08b23db9c1b..6e8856f481af54 100644 --- a/llvm/lib/Frontend/OpenMP/OMPContext.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPContext.cpp @@ -213,7 +213,7 @@ static int isVariantApplicableInContextHelper( }); Optional Result = HandleTrait(Property, IsActiveTrait); - if (Result.hasValue()) + if (Result) return Result.getValue(); } @@ -234,7 +234,7 @@ static int isVariantApplicableInContextHelper( ConstructMatches->push_back(ConstructIdx - 1); Optional Result = HandleTrait(Property, FoundInOrder); - if (Result.hasValue()) + if (Result) return Result.getValue(); if (!FoundInOrder) { diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp index ac03b1493dd7ad..b132a9dcb812f8 100644 --- a/llvm/lib/IR/IntrinsicInst.cpp +++ b/llvm/lib/IR/IntrinsicInst.cpp @@ -363,7 +363,7 @@ VPIntrinsic::getVectorLengthParamPos(Intrinsic::ID IntrinsicID) { /// scatter. MaybeAlign VPIntrinsic::getPointerAlignment() const { Optional PtrParamOpt = getMemoryPointerParamPos(getIntrinsicID()); - assert(PtrParamOpt.hasValue() && "no pointer argument!"); + assert(PtrParamOpt && "no pointer argument!"); return getParamAlign(PtrParamOpt.getValue()); } @@ -389,7 +389,7 @@ Optional VPIntrinsic::getMemoryPointerParamPos(Intrinsic::ID VPID) { /// \return The data (payload) operand of this store or scatter. Value *VPIntrinsic::getMemoryDataParam() const { auto DataParamOpt = getMemoryDataParamPos(getIntrinsicID()); - if (!DataParamOpt.hasValue()) + if (!DataParamOpt) return nullptr; return getArgOperand(DataParamOpt.getValue()); } diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp index dc44a34ea91014..40a1a898bb5e5e 100644 --- a/llvm/lib/IR/LLVMContextImpl.cpp +++ b/llvm/lib/IR/LLVMContextImpl.cpp @@ -254,13 +254,13 @@ bool LLVMContextImpl::hasOpaquePointersValue() { } bool LLVMContextImpl::getOpaquePointers() { - if (LLVM_UNLIKELY(!(OpaquePointers.hasValue()))) + if (LLVM_UNLIKELY(!OpaquePointers)) OpaquePointers = OpaquePointersCL; return *OpaquePointers; } void LLVMContextImpl::setOpaquePointers(bool OP) { - assert((!OpaquePointers.hasValue() || OpaquePointers.getValue() == OP) && + assert((!OpaquePointers || OpaquePointers.getValue() == OP) && "Cannot change opaque pointers mode once set"); OpaquePointers = OP; } diff --git a/llvm/lib/IR/VectorBuilder.cpp b/llvm/lib/IR/VectorBuilder.cpp index 82995ce3d05c4c..e7be7a98a593cd 100644 --- a/llvm/lib/IR/VectorBuilder.cpp +++ b/llvm/lib/IR/VectorBuilder.cpp @@ -90,9 +90,9 @@ Value *VectorBuilder::createVectorInstruction(unsigned Opcode, Type *ReturnTy, } } - if (MaskPosOpt.hasValue()) + if (MaskPosOpt) IntrinParams[*MaskPosOpt] = &requestMask(); - if (VLenPosOpt.hasValue()) + if (VLenPosOpt) IntrinParams[*VLenPosOpt] = &requestEVL(); auto *VPDecl = VPIntrinsic::getDeclarationForParams(&getModule(), VPID, diff --git a/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp b/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp index c6035dca4ce198..435dba87ba1608 100644 --- a/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp +++ b/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp @@ -86,7 +86,7 @@ bool XCOFFSymbolInfo::operator<(const XCOFFSymbolInfo &SymInfo) const { if (StorageMappingClass.hasValue() != SymInfo.StorageMappingClass.hasValue()) return SymInfo.StorageMappingClass.hasValue(); - if (StorageMappingClass.hasValue()) { + if (StorageMappingClass) { return getSMCPriority(StorageMappingClass.getValue()) < getSMCPriority(SymInfo.StorageMappingClass.getValue()); } diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp index 7ed37b02f460d1..8c582d225e3000 100644 --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -4239,7 +4239,7 @@ bool MasmParser::parseStructInitializer(const StructInfo &Structure, auto &FieldInitializers = Initializer.FieldInitializers; size_t FieldIndex = 0; - if (EndToken.hasValue()) { + if (EndToken) { // Initialize all fields with given initializers. while (getTok().isNot(EndToken.getValue()) && FieldIndex < Structure.Fields.size()) { @@ -4272,7 +4272,7 @@ bool MasmParser::parseStructInitializer(const StructInfo &Structure, FieldInitializers.push_back(Field.Contents); } - if (EndToken.hasValue()) { + if (EndToken) { if (EndToken.getValue() == AsmToken::Greater) return parseAngleBracketClose(); diff --git a/llvm/lib/MC/MCSchedule.cpp b/llvm/lib/MC/MCSchedule.cpp index db08e204411376..98eb7eada06444 100644 --- a/llvm/lib/MC/MCSchedule.cpp +++ b/llvm/lib/MC/MCSchedule.cpp @@ -98,7 +98,7 @@ MCSchedModel::getReciprocalThroughput(const MCSubtargetInfo &STI, double Temp = NumUnits * 1.0 / I->Cycles; Throughput = Throughput ? std::min(Throughput.getValue(), Temp) : Temp; } - if (Throughput.hasValue()) + if (Throughput) return 1.0 / Throughput.getValue(); // If no throughput value was calculated, assume that we can execute at the @@ -142,7 +142,7 @@ MCSchedModel::getReciprocalThroughput(unsigned SchedClass, double Temp = countPopulation(I->getUnits()) * 1.0 / I->getCycles(); Throughput = Throughput ? std::min(Throughput.getValue(), Temp) : Temp; } - if (Throughput.hasValue()) + if (Throughput) return 1.0 / Throughput.getValue(); // If there are no execution resources specified for this class, then assume diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp index a7b7a47e49ca45..340640e2231bcf 100644 --- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp @@ -639,7 +639,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig, if (Iter != Config.SectionsToRename.end()) { const SectionRename &SR = Iter->second; Sec.Name = std::string(SR.NewName); - if (SR.NewFlags.hasValue()) + if (SR.NewFlags) setSectionFlagsAndType(Sec, SR.NewFlags.getValue()); RenamedSections.insert(&Sec); } else if (RelocSec && !(Sec.Flags & SHF_ALLOC)) diff --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp index 9bac454602abb9..dcd29651164801 100644 --- a/llvm/lib/Object/ELFObjectFile.cpp +++ b/llvm/lib/Object/ELFObjectFile.cpp @@ -167,11 +167,11 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const { bool isV7 = false; Optional Attr = Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch); - if (Attr.hasValue()) + if (Attr) isV7 = Attr.getValue() == ARMBuildAttrs::v7; Attr = Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch_profile); - if (Attr.hasValue()) { + if (Attr) { switch (Attr.getValue()) { case ARMBuildAttrs::ApplicationProfile: Features.AddFeature("aclass"); @@ -190,7 +190,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const { } Attr = Attributes.getAttributeValue(ARMBuildAttrs::THUMB_ISA_use); - if (Attr.hasValue()) { + if (Attr) { switch (Attr.getValue()) { default: break; @@ -205,7 +205,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const { } Attr = Attributes.getAttributeValue(ARMBuildAttrs::FP_arch); - if (Attr.hasValue()) { + if (Attr) { switch (Attr.getValue()) { default: break; @@ -229,7 +229,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const { } Attr = Attributes.getAttributeValue(ARMBuildAttrs::Advanced_SIMD_arch); - if (Attr.hasValue()) { + if (Attr) { switch (Attr.getValue()) { default: break; @@ -248,7 +248,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const { } Attr = Attributes.getAttributeValue(ARMBuildAttrs::MVE_arch); - if (Attr.hasValue()) { + if (Attr) { switch (Attr.getValue()) { default: break; @@ -267,7 +267,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const { } Attr = Attributes.getAttributeValue(ARMBuildAttrs::DIV_use); - if (Attr.hasValue()) { + if (Attr) { switch (Attr.getValue()) { default: break; @@ -521,7 +521,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const { Optional Attr = Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch); - if (Attr.hasValue()) { + if (Attr) { switch (Attr.getValue()) { case ARMBuildAttrs::v4: Triple += "v4"; @@ -553,7 +553,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const { case ARMBuildAttrs::v7: { Optional ArchProfileAttr = Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch_profile); - if (ArchProfileAttr.hasValue() && + if (ArchProfileAttr && ArchProfileAttr.getValue() == ARMBuildAttrs::MicroControllerProfile) Triple += "v7m"; else diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp index 547b3b73eec2dd..cf3962ae927ba5 100644 --- a/llvm/lib/Support/Process.cpp +++ b/llvm/lib/Support/Process.cpp @@ -42,7 +42,7 @@ Optional Process::FindInEnvPath(StringRef EnvName, assert(!path::is_absolute(FileName)); Optional FoundPath; Optional OptPath = Process::GetEnv(EnvName); - if (!OptPath.hasValue()) + if (!OptPath) return FoundPath; const char EnvPathSeparatorStr[] = {Separator, '\0'}; diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index 9c6a0c071755d4..21f0c39bfd6eaf 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -2667,14 +2667,14 @@ void JSONWriter::write(ArrayRef Entries, OS << "{\n" " 'version': 0,\n"; - if (IsCaseSensitive.hasValue()) + if (IsCaseSensitive) OS << " 'case-sensitive': '" << (IsCaseSensitive.getValue() ? "true" : "false") << "',\n"; - if (UseExternalNames.hasValue()) + if (UseExternalNames) OS << " 'use-external-names': '" << (UseExternalNames.getValue() ? "true" : "false") << "',\n"; bool UseOverlayRelative = false; - if (IsOverlayRelative.hasValue()) { + if (IsOverlayRelative) { UseOverlayRelative = IsOverlayRelative.getValue(); OS << " 'overlay-relative': '" << (UseOverlayRelative ? "true" : "false") << "',\n"; diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp index 7648dac0059864..98ceea3c3c7a3f 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -428,7 +428,7 @@ raw_ostream &raw_ostream::operator<<(const FormattedBytes &FB) { while (!Bytes.empty()) { indent(FB.IndentLevel); - if (FB.FirstByteOffset.hasValue()) { + if (FB.FirstByteOffset) { uint64_t Offset = FB.FirstByteOffset.getValue(); llvm::write_hex(*this, Offset + LineIndex, HPS, OffsetWidth); *this << ": "; diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index e100251fbfcd56..6c205104d5697f 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -2598,7 +2598,7 @@ Init *Record::getValueInit(StringRef FieldName) const { StringRef Record::getValueAsString(StringRef FieldName) const { llvm::Optional S = getValueAsOptionalString(FieldName); - if (!S.hasValue()) + if (!S) PrintFatalError(getLoc(), "Record `" + getName() + "' does not have a field named `" + FieldName + "'!\n"); return S.getValue(); diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp index 76a39d011569b5..08c10610f0064a 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp @@ -1171,7 +1171,7 @@ bool AMDGPUInstructionSelector::selectBallot(MachineInstr &I) const { Optional Arg = getIConstantVRegValWithLookThrough(I.getOperand(2).getReg(), *MRI); - if (Arg.hasValue()) { + if (Arg) { const int64_t Value = Arg.getValue().Value.getSExtValue(); if (Value == 0) { unsigned Opcode = Is64 ? AMDGPU::S_MOV_B64 : AMDGPU::S_MOV_B32; @@ -4201,7 +4201,7 @@ AMDGPUInstructionSelector::selectMUBUFScratchOffen(MachineOperand &Root) const { MIB.addReg(Info->getScratchRSrcReg()); }, [=](MachineInstrBuilder &MIB) { // vaddr - if (FI.hasValue()) + if (FI) MIB.addFrameIndex(FI.getValue()); else MIB.addReg(VAddr); diff --git a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp index 56d471af8e2080..0b4a95bc9ce566 100644 --- a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp +++ b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp @@ -1023,7 +1023,7 @@ findCFILocation(MachineBasicBlock &B) { void HexagonFrameLowering::insertCFIInstructions(MachineFunction &MF) const { for (auto &B : MF) { auto At = findCFILocation(B); - if (At.hasValue()) + if (At) insertCFIInstructionsAt(B, At.getValue()); } } diff --git a/llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp b/llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp index 660215ca743534..d715ba901a2bbd 100644 --- a/llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp +++ b/llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp @@ -704,14 +704,14 @@ LanaiAsmParser::parseRegister(bool RestoreOnFailure) { if (Lexer.getKind() == AsmToken::Identifier) { RegNum = MatchRegisterName(Lexer.getTok().getIdentifier()); if (RegNum == 0) { - if (PercentTok.hasValue() && RestoreOnFailure) + if (PercentTok && RestoreOnFailure) Lexer.UnLex(PercentTok.getValue()); return nullptr; } Parser.Lex(); // Eat identifier token return LanaiOperand::createReg(RegNum, Start, End); } - if (PercentTok.hasValue() && RestoreOnFailure) + if (PercentTok && RestoreOnFailure) Lexer.UnLex(PercentTok.getValue()); return nullptr; } diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp index e52b49e3e83229..746f652bfa36ed 100644 --- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -1860,7 +1860,7 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, Chain = Ret.getValue(1); InFlag = Ret.getValue(2); - if (ProxyRegTruncates[i].hasValue()) { + if (ProxyRegTruncates[i]) { Ret = DAG.getNode(ISD::TRUNCATE, dl, ProxyRegTruncates[i].getValue(), Ret); } diff --git a/llvm/lib/Target/PowerPC/PPCMacroFusion.cpp b/llvm/lib/Target/PowerPC/PPCMacroFusion.cpp index caf14576fd4463..58b74c6b8c7ab1 100644 --- a/llvm/lib/Target/PowerPC/PPCMacroFusion.cpp +++ b/llvm/lib/Target/PowerPC/PPCMacroFusion.cpp @@ -267,13 +267,13 @@ static bool shouldScheduleAdjacent(const TargetInstrInfo &TII, continue; auto DepOpIdx = Feature.depOpIdx(); - if (DepOpIdx.hasValue()) { + if (DepOpIdx) { // Checking if the result of the FirstMI is the desired operand of the // SecondMI if the DepOpIdx is set. Otherwise, ignore it. if (!matchingRegOps(*FirstMI, 0, SecondMI, *DepOpIdx)) return false; } - + // Checking more on the instruction operands. if (checkOpConstraints(Feature.getKind(), *FirstMI, SecondMI)) return true; diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp index dd7a9fe917c7b9..fe396cbfc011db 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp +++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -246,10 +246,10 @@ static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT, static Reloc::Model getEffectiveRelocModel(const Triple &TT, Optional RM) { - assert((!TT.isOSAIX() || !RM.hasValue() || *RM == Reloc::PIC_) && + assert((!TT.isOSAIX() || !RM || *RM == Reloc::PIC_) && "Invalid relocation model for AIX."); - if (RM.hasValue()) + if (RM) return *RM; // Big Endian PPC and AIX default to PIC. diff --git a/llvm/lib/Target/VE/VVPISelLowering.cpp b/llvm/lib/Target/VE/VVPISelLowering.cpp index cd67a0fb40f26e..330eef4c7c2b41 100644 --- a/llvm/lib/Target/VE/VVPISelLowering.cpp +++ b/llvm/lib/Target/VE/VVPISelLowering.cpp @@ -39,7 +39,7 @@ SDValue VETargetLowering::lowerToVVP(SDValue Op, SelectionDAG &DAG) const { // Can we represent this as a VVP node. const unsigned Opcode = Op->getOpcode(); auto VVPOpcodeOpt = getVVPOpcode(Opcode); - if (!VVPOpcodeOpt.hasValue()) + if (!VVPOpcodeOpt) return SDValue(); unsigned VVPOpcode = VVPOpcodeOpt.getValue(); const bool FromVP = ISD::isVPOpcode(Opcode); diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp index 61097e115a1c4f..ec72c1de0503d1 100644 --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp @@ -86,14 +86,12 @@ bool WebAssemblyAsmTypeCheck::popType(SMLoc ErrorLoc, Optional EVT) { if (Stack.empty()) { return typeError(ErrorLoc, - EVT.hasValue() - ? StringRef("empty stack while popping ") + - WebAssembly::typeToString(EVT.getValue()) - : StringRef( - "empty stack while popping value")); + EVT ? StringRef("empty stack while popping ") + + WebAssembly::typeToString(EVT.getValue()) + : StringRef("empty stack while popping value")); } auto PVT = Stack.pop_back_val(); - if (EVT.hasValue() && EVT.getValue() != PVT) { + if (EVT && EVT.getValue() != PVT) { return typeError( ErrorLoc, StringRef("popped ") + WebAssembly::typeToString(PVT) + ", expected " + diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp index f09758a0d10334..2db4bd822349b6 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp @@ -552,7 +552,7 @@ Value *WebAssemblyLowerEmscriptenEHSjLj::wrapInvoke(CallBase *CI) { Optional NEltArg; std::tie(SizeArg, NEltArg) = FnAttrs.getAllocSizeArgs(); SizeArg += 1; - if (NEltArg.hasValue()) + if (NEltArg) NEltArg = NEltArg.getValue() + 1; FnAttrs.addAllocSizeAttr(SizeArg, NEltArg); } diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 769d79b97517a0..b05b7990e3f00b 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -297,11 +297,11 @@ AA::combineOptionalValuesInAAValueLatice(const Optional &A, const Optional &B, Type *Ty) { if (A == B) return A; - if (!B.hasValue()) + if (!B) return A; if (*B == nullptr) return nullptr; - if (!A.hasValue()) + if (!A) return Ty ? getWithType(**B, *Ty) : nullptr; if (*A == nullptr) return nullptr; @@ -718,7 +718,7 @@ Argument *IRPosition::getAssociatedArgument() const { } // If we found a unique callback candidate argument, return it. - if (CBCandidateArg.hasValue() && CBCandidateArg.getValue()) + if (CBCandidateArg && CBCandidateArg.getValue()) return CBCandidateArg.getValue(); // If no callbacks were found, or none used the underlying call site operand @@ -2695,7 +2695,7 @@ void InformationCache::initializeInformationCache(const Function &CF, while (!Worklist.empty()) { const Instruction *I = Worklist.pop_back_val(); Optional &NumUses = AssumeUsesMap[I]; - if (!NumUses.hasValue()) + if (!NumUses) NumUses = I->getNumUses(); NumUses = NumUses.getValue() - /* this assume */ 1; if (NumUses.getValue() != 0) diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index b36c712cdd6c88..4a61c2e9fd51a1 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -395,7 +395,7 @@ static bool genericValueTraversal( if (UseValueSimplify && !isa(V)) { Optional SimpleV = A.getAssumedSimplified(*V, QueryingAA, UsedAssumedInformation); - if (!SimpleV.hasValue()) + if (!SimpleV) continue; Value *NewV = SimpleV.getValue(); if (NewV && NewV != V) { @@ -1851,7 +1851,7 @@ ChangeStatus AAReturnedValuesImpl::manifest(Attributor &A) { // Check if we have an assumed unique return value that we could manifest. Optional UniqueRV = getAssumedUniqueReturnValue(A); - if (!UniqueRV.hasValue() || !UniqueRV.getValue()) + if (!UniqueRV || !UniqueRV.getValue()) return Changed; // Bookkeeping. @@ -2626,7 +2626,7 @@ struct AAUndefinedBehaviorImpl : public AAUndefinedBehavior { // Either we stopped and the appropriate action was taken, // or we got back a simplified value to continue. Optional SimplifiedPtrOp = stopOnUndefOrAssumed(A, PtrOp, &I); - if (!SimplifiedPtrOp.hasValue() || !SimplifiedPtrOp.getValue()) + if (!SimplifiedPtrOp || !SimplifiedPtrOp.getValue()) return true; const Value *PtrOpVal = SimplifiedPtrOp.getValue(); @@ -2717,10 +2717,9 @@ struct AAUndefinedBehaviorImpl : public AAUndefinedBehavior { IRPosition::value(*ArgVal), *this, UsedAssumedInformation); if (UsedAssumedInformation) continue; - if (SimplifiedVal.hasValue() && !SimplifiedVal.getValue()) + if (SimplifiedVal && !SimplifiedVal.getValue()) return true; - if (!SimplifiedVal.hasValue() || - isa(*SimplifiedVal.getValue())) { + if (!SimplifiedVal || isa(*SimplifiedVal.getValue())) { KnownUBInsts.insert(&I); continue; } @@ -4062,7 +4061,7 @@ identifyAliveSuccessors(Attributor &A, const SwitchInst &SI, bool UsedAssumedInformation = false; Optional C = A.getAssumedConstant(*SI.getCondition(), AA, UsedAssumedInformation); - if (!C.hasValue() || isa_and_nonnull(C.getValue())) { + if (!C || isa_and_nonnull(C.getValue())) { // No value yet, assume all edges are dead. } else if (isa_and_nonnull(C.getValue())) { for (auto &CaseIt : SI.cases()) { @@ -5481,7 +5480,7 @@ struct AAValueSimplifyImpl : AAValueSimplify { bool UsedAssumedInformation = false; Optional SimpleV = A.getAssumedSimplified(V, QueryingAA, UsedAssumedInformation); - if (!SimpleV.hasValue()) + if (!SimpleV) return PoisonValue::get(&Ty); Value *EffectiveV = &V; if (SimpleV.getValue()) @@ -5631,7 +5630,7 @@ struct AAValueSimplifyArgument final : AAValueSimplifyImpl { bool UsedAssumedInformation = false; Optional SimpleArgOp = A.getAssumedConstant(ACSArgPos, *this, UsedAssumedInformation); - if (!SimpleArgOp.hasValue()) + if (!SimpleArgOp) return true; if (!SimpleArgOp.getValue()) return false; @@ -5746,7 +5745,7 @@ struct AAValueSimplifyFloating : AAValueSimplifyImpl { const auto &SimplifiedLHS = A.getAssumedSimplified(IRPosition::value(*LHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedLHS.hasValue()) + if (!SimplifiedLHS) return true; if (!SimplifiedLHS.getValue()) return false; @@ -5755,7 +5754,7 @@ struct AAValueSimplifyFloating : AAValueSimplifyImpl { const auto &SimplifiedRHS = A.getAssumedSimplified(IRPosition::value(*RHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedRHS.hasValue()) + if (!SimplifiedRHS) return true; if (!SimplifiedRHS.getValue()) return false; @@ -5826,7 +5825,7 @@ struct AAValueSimplifyFloating : AAValueSimplifyImpl { *this, UsedAssumedInformation); // If we are not sure about any operand we are not sure about the entire // instruction, we'll wait. - if (!SimplifiedOp.hasValue()) + if (!SimplifiedOp) return true; if (SimplifiedOp.getValue()) @@ -6249,8 +6248,7 @@ struct AAHeapToStackFunction final : public AAHeapToStack { Alignment = std::max(Alignment, *RetAlign); if (Value *Align = getAllocAlignment(AI.CB, TLI)) { Optional AlignmentAPI = getAPInt(A, *this, *Align); - assert(AlignmentAPI.hasValue() && - AlignmentAPI.getValue().getZExtValue() > 0 && + assert(AlignmentAPI && AlignmentAPI.getValue().getZExtValue() > 0 && "Expected an alignment during manifest!"); Alignment = std::max( Alignment, assumeAligned(AlignmentAPI.getValue().getZExtValue())); @@ -6299,7 +6297,7 @@ struct AAHeapToStackFunction final : public AAHeapToStack { bool UsedAssumedInformation = false; Optional SimpleV = A.getAssumedConstant(V, AA, UsedAssumedInformation); - if (!SimpleV.hasValue()) + if (!SimpleV) return APInt(64, 0); if (auto *CI = dyn_cast_or_null(SimpleV.getValue())) return CI->getValue(); @@ -6578,9 +6576,9 @@ ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) { if (MaxHeapToStackSize != -1) { Optional Size = getSize(A, *this, AI); - if (!Size.hasValue() || Size.getValue().ugt(MaxHeapToStackSize)) { + if (!Size || Size.getValue().ugt(MaxHeapToStackSize)) { LLVM_DEBUG({ - if (!Size.hasValue()) + if (!Size) dbgs() << "[H2S] Unknown allocation size: " << *AI.CB << "\n"; else dbgs() << "[H2S] Allocation size too large: " << *AI.CB << " vs. " @@ -6633,9 +6631,9 @@ struct AAPrivatizablePtrImpl : public AAPrivatizablePtr { /// Return a privatizable type that encloses both T0 and T1. /// TODO: This is merely a stub for now as we should manage a mapping as well. Optional combineTypes(Optional T0, Optional T1) { - if (!T0.hasValue()) + if (!T0) return T1; - if (!T1.hasValue()) + if (!T1) return T0; if (T0 == T1) return T0; @@ -6695,9 +6693,9 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl { LLVM_DEBUG({ dbgs() << "[AAPrivatizablePtr] ACSPos: " << ACSArgPos << ", CSTy: "; - if (CSTy.hasValue() && CSTy.getValue()) + if (CSTy && CSTy.getValue()) CSTy.getValue()->print(dbgs()); - else if (CSTy.hasValue()) + else if (CSTy) dbgs() << ""; else dbgs() << ""; @@ -6707,16 +6705,16 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl { LLVM_DEBUG({ dbgs() << " : New Type: "; - if (Ty.hasValue() && Ty.getValue()) + if (Ty && Ty.getValue()) Ty.getValue()->print(dbgs()); - else if (Ty.hasValue()) + else if (Ty) dbgs() << ""; else dbgs() << ""; dbgs() << "\n"; }); - return !Ty.hasValue() || Ty.getValue(); + return !Ty || Ty.getValue(); }; if (!A.checkForAllCallSites(CallSiteCheck, *this, true, @@ -6728,7 +6726,7 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl { /// See AbstractAttribute::updateImpl(...). ChangeStatus updateImpl(Attributor &A) override { PrivatizableType = identifyPrivatizableType(A); - if (!PrivatizableType.hasValue()) + if (!PrivatizableType) return ChangeStatus::UNCHANGED; if (!PrivatizableType.getValue()) return indicatePessimisticFixpoint(); @@ -6817,7 +6815,7 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl { *this, IRPosition::argument(CBArg), DepClassTy::REQUIRED); if (CBArgPrivAA.isValidState()) { auto CBArgPrivTy = CBArgPrivAA.getPrivatizableType(); - if (!CBArgPrivTy.hasValue()) + if (!CBArgPrivTy) continue; if (CBArgPrivTy.getValue() == PrivatizableType) continue; @@ -6864,7 +6862,7 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl { DepClassTy::REQUIRED); if (DCArgPrivAA.isValidState()) { auto DCArgPrivTy = DCArgPrivAA.getPrivatizableType(); - if (!DCArgPrivTy.hasValue()) + if (!DCArgPrivTy) return true; if (DCArgPrivTy.getValue() == PrivatizableType) return true; @@ -7006,7 +7004,7 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl { /// See AbstractAttribute::manifest(...) ChangeStatus manifest(Attributor &A) override { - if (!PrivatizableType.hasValue()) + if (!PrivatizableType) return ChangeStatus::UNCHANGED; assert(PrivatizableType.getValue() && "Expected privatizable type!"); @@ -7149,7 +7147,7 @@ struct AAPrivatizablePtrCallSiteArgument final /// See AbstractAttribute::updateImpl(...). ChangeStatus updateImpl(Attributor &A) override { PrivatizableType = identifyPrivatizableType(A); - if (!PrivatizableType.hasValue()) + if (!PrivatizableType) return ChangeStatus::UNCHANGED; if (!PrivatizableType.getValue()) return indicatePessimisticFixpoint(); @@ -8610,7 +8608,7 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl { const auto &SimplifiedLHS = A.getAssumedSimplified(IRPosition::value(*LHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedLHS.hasValue()) + if (!SimplifiedLHS) return true; if (!SimplifiedLHS.getValue()) return false; @@ -8619,7 +8617,7 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl { const auto &SimplifiedRHS = A.getAssumedSimplified(IRPosition::value(*RHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedRHS.hasValue()) + if (!SimplifiedRHS) return true; if (!SimplifiedRHS.getValue()) return false; @@ -8663,7 +8661,7 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl { const auto &SimplifiedOpV = A.getAssumedSimplified(IRPosition::value(*OpV, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedOpV.hasValue()) + if (!SimplifiedOpV) return true; if (!SimplifiedOpV.getValue()) return false; @@ -8693,7 +8691,7 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl { const auto &SimplifiedLHS = A.getAssumedSimplified(IRPosition::value(*LHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedLHS.hasValue()) + if (!SimplifiedLHS) return true; if (!SimplifiedLHS.getValue()) return false; @@ -8702,7 +8700,7 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl { const auto &SimplifiedRHS = A.getAssumedSimplified(IRPosition::value(*RHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedRHS.hasValue()) + if (!SimplifiedRHS) return true; if (!SimplifiedRHS.getValue()) return false; @@ -8767,7 +8765,7 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl { const auto &SimplifiedOpV = A.getAssumedSimplified(IRPosition::value(V, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedOpV.hasValue()) + if (!SimplifiedOpV) return true; if (!SimplifiedOpV.getValue()) return false; @@ -9128,7 +9126,7 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { const auto &SimplifiedLHS = A.getAssumedSimplified(IRPosition::value(*LHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedLHS.hasValue()) + if (!SimplifiedLHS) return ChangeStatus::UNCHANGED; if (!SimplifiedLHS.getValue()) return indicatePessimisticFixpoint(); @@ -9137,7 +9135,7 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { const auto &SimplifiedRHS = A.getAssumedSimplified(IRPosition::value(*RHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedRHS.hasValue()) + if (!SimplifiedRHS) return ChangeStatus::UNCHANGED; if (!SimplifiedRHS.getValue()) return indicatePessimisticFixpoint(); @@ -9211,7 +9209,7 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { const auto &SimplifiedLHS = A.getAssumedSimplified(IRPosition::value(*LHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedLHS.hasValue()) + if (!SimplifiedLHS) return ChangeStatus::UNCHANGED; if (!SimplifiedLHS.getValue()) return indicatePessimisticFixpoint(); @@ -9220,7 +9218,7 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { const auto &SimplifiedRHS = A.getAssumedSimplified(IRPosition::value(*RHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedRHS.hasValue()) + if (!SimplifiedRHS) return ChangeStatus::UNCHANGED; if (!SimplifiedRHS.getValue()) return indicatePessimisticFixpoint(); @@ -9234,9 +9232,9 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { // Check if we only need one operand. bool OnlyLeft = false, OnlyRight = false; - if (C.hasValue() && *C && (*C)->isOneValue()) + if (C && *C && (*C)->isOneValue()) OnlyLeft = true; - else if (C.hasValue() && *C && (*C)->isZeroValue()) + else if (C && *C && (*C)->isZeroValue()) OnlyRight = true; const AAPotentialConstantValues *LHSAA = nullptr, *RHSAA = nullptr; @@ -9286,7 +9284,7 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { const auto &SimplifiedSrc = A.getAssumedSimplified(IRPosition::value(*Src, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedSrc.hasValue()) + if (!SimplifiedSrc) return ChangeStatus::UNCHANGED; if (!SimplifiedSrc.getValue()) return indicatePessimisticFixpoint(); @@ -9319,7 +9317,7 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { const auto &SimplifiedLHS = A.getAssumedSimplified(IRPosition::value(*LHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedLHS.hasValue()) + if (!SimplifiedLHS) return ChangeStatus::UNCHANGED; if (!SimplifiedLHS.getValue()) return indicatePessimisticFixpoint(); @@ -9328,7 +9326,7 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { const auto &SimplifiedRHS = A.getAssumedSimplified(IRPosition::value(*RHS, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedRHS.hasValue()) + if (!SimplifiedRHS) return ChangeStatus::UNCHANGED; if (!SimplifiedRHS.getValue()) return indicatePessimisticFixpoint(); @@ -9387,7 +9385,7 @@ struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { const auto &SimplifiedIncomingValue = A.getAssumedSimplified( IRPosition::value(*IncomingValue, getCallBaseContext()), *this, UsedAssumedInformation); - if (!SimplifiedIncomingValue.hasValue()) + if (!SimplifiedIncomingValue) continue; if (!SimplifiedIncomingValue.getValue()) return indicatePessimisticFixpoint(); @@ -9877,7 +9875,7 @@ struct AAFunctionReachabilityFunction : public AAFunctionReachability { ArrayRef AAEdgesList, const Function &Fn) { Optional Cached = isCachedReachable(Fn); - if (Cached.hasValue()) + if (Cached) return Cached.getValue(); // The query was not cached, thus it is new. We need to request an update diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp index 89ae575603e561..d75d99e307fdf7 100644 --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -554,7 +554,7 @@ collectRegionsConstants(OutlinableRegion &Region, // the the number has been found to be not the same value in each instance. for (Value *V : ID.OperVals) { Optional GVNOpt = C.getGVN(V); - assert(GVNOpt.hasValue() && "Expected a GVN for operand?"); + assert(GVNOpt && "Expected a GVN for operand?"); unsigned GVN = GVNOpt.getValue(); // Check if this global value has been found to not be the same already. @@ -569,7 +569,7 @@ collectRegionsConstants(OutlinableRegion &Region, // global value number. If the global value does not map to a Constant, // it is considered to not be the same value. Optional ConstantMatches = constantMatches(V, GVN, GVNToConstant); - if (ConstantMatches.hasValue()) { + if (ConstantMatches) { if (ConstantMatches.getValue()) continue; else @@ -650,7 +650,7 @@ Function *IROutliner::createFunction(Module &M, OutlinableGroup &Group, "outlined_ir_func_" + std::to_string(FunctionNameSuffix), M); // Transfer the swifterr attribute to the correct function parameter. - if (Group.SwiftErrorArgument.hasValue()) + if (Group.SwiftErrorArgument) Group.OutlinedFunction->addParamAttr(Group.SwiftErrorArgument.getValue(), Attribute::SwiftError); @@ -808,8 +808,7 @@ static void mapInputsToGVNs(IRSimilarityCandidate &C, assert(Input && "Have a nullptr as an input"); if (OutputMappings.find(Input) != OutputMappings.end()) Input = OutputMappings.find(Input)->second; - assert(C.getGVN(Input).hasValue() && - "Could not find a numbering for the given input"); + assert(C.getGVN(Input) && "Could not find a numbering for the given input"); EndInputNumbers.push_back(C.getGVN(Input).getValue()); } } @@ -948,11 +947,11 @@ findExtractedInputToOverallInputMapping(OutlinableRegion &Region, // numbering overrides any discovered location for the extracted code. for (unsigned InputVal : InputGVNs) { Optional CanonicalNumberOpt = C.getCanonicalNum(InputVal); - assert(CanonicalNumberOpt.hasValue() && "Canonical number not found?"); + assert(CanonicalNumberOpt && "Canonical number not found?"); unsigned CanonicalNumber = CanonicalNumberOpt.getValue(); Optional InputOpt = C.fromGVN(InputVal); - assert(InputOpt.hasValue() && "Global value number not found?"); + assert(InputOpt && "Global value number not found?"); Value *Input = InputOpt.getValue(); DenseMap::iterator AggArgIt = @@ -1235,11 +1234,10 @@ static Optional getGVNForPHINode(OutlinableRegion &Region, DenseMap::iterator GVNToPHIIt; DenseMap::iterator PHIToGVNIt; Optional BBGVN = Cand.getGVN(PHIBB); - assert(BBGVN.hasValue() && "Could not find GVN for the incoming block!"); + assert(BBGVN && "Could not find GVN for the incoming block!"); BBGVN = Cand.getCanonicalNum(BBGVN.getValue()); - assert(BBGVN.hasValue() && - "Could not find canonical number for the incoming block!"); + assert(BBGVN && "Could not find canonical number for the incoming block!"); // Create a pair of the exit block canonical value, and the aggregate // argument location, connected to the canonical numbers stored in the // PHINode. @@ -1517,7 +1515,7 @@ CallInst *replaceCalledFunction(Module &M, OutlinableRegion &Region) { // Make sure that the argument in the new function has the SwiftError // argument. - if (Group.SwiftErrorArgument.hasValue()) + if (Group.SwiftErrorArgument) Call->addParamAttr(Group.SwiftErrorArgument.getValue(), Attribute::SwiftError); @@ -1650,9 +1648,9 @@ static void findCanonNumsForPHI( // Find and add the canonical number for the incoming value. Optional GVN = Region.Candidate->getGVN(IVal); - assert(GVN.hasValue() && "No GVN for incoming value"); + assert(GVN && "No GVN for incoming value"); Optional CanonNum = Region.Candidate->getCanonicalNum(*GVN); - assert(CanonNum.hasValue() && "No Canonical Number for GVN"); + assert(CanonNum && "No Canonical Number for GVN"); CanonNums.push_back(std::make_pair(*CanonNum, IBlock)); } } @@ -2081,7 +2079,7 @@ static void alignOutputBlockWithAggFunc( // If there is, we remove the new output blocks. If it does not, // we add it to our list of sets of output blocks. - if (MatchingBB.hasValue()) { + if (MatchingBB) { LLVM_DEBUG(dbgs() << "Set output block for region in function" << Region.ExtractedFunction << " to " << MatchingBB.getValue()); @@ -2504,9 +2502,9 @@ static Value *findOutputValueInRegion(OutlinableRegion &Region, OutputCanon = *It->second.second.begin(); } Optional OGVN = Region.Candidate->fromCanonicalNum(OutputCanon); - assert(OGVN.hasValue() && "Could not find GVN for Canonical Number?"); + assert(OGVN && "Could not find GVN for Canonical Number?"); Optional OV = Region.Candidate->fromGVN(*OGVN); - assert(OV.hasValue() && "Could not find value for GVN?"); + assert(OV && "Could not find value for GVN?"); return *OV; } diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp index f458afafa6984c..0e043599ac5fc4 100644 --- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -2514,13 +2514,13 @@ struct AAICVTrackerFunction : public AAICVTracker { if (ValuesMap.count(CurrInst)) { Optional NewReplVal = ValuesMap.lookup(CurrInst); // Unknown value, track new. - if (!ReplVal.hasValue()) { + if (!ReplVal) { ReplVal = NewReplVal; break; } // If we found a new value, we can't know the icv value anymore. - if (NewReplVal.hasValue()) + if (NewReplVal) if (ReplVal != NewReplVal) return nullptr; @@ -2528,11 +2528,11 @@ struct AAICVTrackerFunction : public AAICVTracker { } Optional NewReplVal = getValueForCall(A, *CurrInst, ICV); - if (!NewReplVal.hasValue()) + if (!NewReplVal) continue; // Unknown value, track new. - if (!ReplVal.hasValue()) { + if (!ReplVal) { ReplVal = NewReplVal; break; } @@ -4422,7 +4422,7 @@ struct AAFoldRuntimeCallCallSiteReturned : AAFoldRuntimeCall { std::string Str("simplified value: "); - if (!SimplifiedValue.hasValue()) + if (!SimplifiedValue) return Str + std::string("none"); if (!SimplifiedValue.getValue()) @@ -4452,8 +4452,8 @@ struct AAFoldRuntimeCallCallSiteReturned : AAFoldRuntimeCall { IRPosition::callsite_returned(CB), [&](const IRPosition &IRP, const AbstractAttribute *AA, bool &UsedAssumedInformation) -> Optional { - assert((isValidState() || (SimplifiedValue.hasValue() && - SimplifiedValue.getValue() == nullptr)) && + assert((isValidState() || + (SimplifiedValue && SimplifiedValue.getValue() == nullptr)) && "Unexpected invalid state!"); if (!isAtFixpoint()) { diff --git a/llvm/lib/Transforms/IPO/SampleContextTracker.cpp b/llvm/lib/Transforms/IPO/SampleContextTracker.cpp index 9cb558bd2b156d..b154aa51ed8441 100644 --- a/llvm/lib/Transforms/IPO/SampleContextTracker.cpp +++ b/llvm/lib/Transforms/IPO/SampleContextTracker.cpp @@ -132,7 +132,7 @@ void ContextTrieNode::setFunctionSamples(FunctionSamples *FSamples) { Optional ContextTrieNode::getFunctionSize() const { return FuncSize; } void ContextTrieNode::addFunctionSize(uint32_t FSize) { - if (!FuncSize.hasValue()) + if (!FuncSize) FuncSize = 0; FuncSize = FuncSize.getValue() + FSize; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 449c0f178bf42e..69e5d009f04a46 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2678,7 +2678,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) { default: { // Handle target specific intrinsics Optional V = targetInstCombineIntrinsic(*II); - if (V.hasValue()) + if (V) return V.getValue(); break; } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index d801f4d5096456..9d4c01ac03e2f5 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -924,7 +924,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, // Handle target specific intrinsics Optional V = targetSimplifyDemandedUseBitsIntrinsic( *II, DemandedMask, Known, KnownBitsComputed); - if (V.hasValue()) + if (V) return V.getValue(); break; } @@ -1635,7 +1635,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V, Optional V = targetSimplifyDemandedVectorEltsIntrinsic( *II, DemandedElts, UndefElts, UndefElts2, UndefElts3, simplifyAndSetOp); - if (V.hasValue()) + if (V) return V.getValue(); break; } diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp index 5cc5804dcbc594..c33b1b3b1a5c7b 100644 --- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp @@ -483,7 +483,7 @@ void ThreadSanitizer::chooseInstructionsToInstrument( static bool isTsanAtomic(const Instruction *I) { // TODO: Ask TTI whether synchronization scope is between threads. auto SSID = getAtomicSyncScopeID(I); - if (!SSID.hasValue()) + if (!SSID) return false; if (isa(I) || isa(I)) return SSID.getValue() != SyncScope::SingleThread; diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp index 0e27c856947cad..2688190f401a2e 100644 --- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp +++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp @@ -1708,7 +1708,7 @@ IntersectSignedRange(ScalarEvolution &SE, const InductiveRangeCheck::Range &R2) { if (R2.isEmpty(SE, /* IsSigned */ true)) return None; - if (!R1.hasValue()) + if (!R1) return R2; auto &R1Value = R1.getValue(); // We never return empty ranges from this function, and R1 is supposed to be @@ -1737,7 +1737,7 @@ IntersectUnsignedRange(ScalarEvolution &SE, const InductiveRangeCheck::Range &R2) { if (R2.isEmpty(SE, /* IsSigned */ false)) return None; - if (!R1.hasValue()) + if (!R1) return R2; auto &R1Value = R1.getValue(); // We never return empty ranges from this function, and R1 is supposed to be @@ -1948,10 +1948,10 @@ bool InductiveRangeCheckElimination::run( for (InductiveRangeCheck &IRC : RangeChecks) { auto Result = IRC.computeSafeIterationSpace(SE, IndVar, LS.IsSignedPredicate); - if (Result.hasValue()) { + if (Result) { auto MaybeSafeIterRange = IntersectRange(SE, SafeIterRange, Result.getValue()); - if (MaybeSafeIterRange.hasValue()) { + if (MaybeSafeIterRange) { assert( !MaybeSafeIterRange.getValue().isEmpty(SE, LS.IsSignedPredicate) && "We should never return empty ranges!"); @@ -1961,7 +1961,7 @@ bool InductiveRangeCheckElimination::run( } } - if (!SafeIterRange.hasValue()) + if (!SafeIterRange) return false; LoopConstrainer LC(*L, LI, LPMAddNewLoop, LS, SE, DT, diff --git a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp index f606e9b7a4841e..0f1e119012121b 100644 --- a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp @@ -600,7 +600,7 @@ class InstPartitionContainer { {LLVMLoopDistributeFollowupAll, Part->hasDepCycle() ? LLVMLoopDistributeFollowupSequential : LLVMLoopDistributeFollowupCoincident}); - if (PartitionID.hasValue()) { + if (PartitionID) { Loop *NewLoop = Part->getDistributedLoop(); NewLoop->setLoopID(PartitionID.getValue()); } diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index 6d4c6756f04de6..1724f11bd7e28a 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -1481,7 +1481,7 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad( return Changed; // We cannot allow unaligned ops for unordered load/store, so reject // anything where the alignment isn't at least the element size. - assert((StoreAlign.hasValue() && LoadAlign.hasValue()) && + assert((StoreAlign && LoadAlign) && "Expect unordered load/store to have align."); if (StoreAlign.getValue() < StoreSize || LoadAlign.getValue() < StoreSize) return Changed; diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp index a33e5cca09b90b..8c286856322762 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp @@ -372,7 +372,7 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, Optional NewInnerEpilogueLoopID = makeFollowupLoopID( OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll, LLVMLoopUnrollAndJamFollowupRemainderInner}); - if (NewInnerEpilogueLoopID.hasValue()) + if (NewInnerEpilogueLoopID) SubLoop->setLoopID(NewInnerEpilogueLoopID.getValue()); // Find trip count and trip multiple @@ -402,14 +402,14 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, Optional NewOuterEpilogueLoopID = makeFollowupLoopID( OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll, LLVMLoopUnrollAndJamFollowupRemainderOuter}); - if (NewOuterEpilogueLoopID.hasValue()) + if (NewOuterEpilogueLoopID) EpilogueOuterLoop->setLoopID(NewOuterEpilogueLoopID.getValue()); } Optional NewInnerLoopID = makeFollowupLoopID(OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll, LLVMLoopUnrollAndJamFollowupInner}); - if (NewInnerLoopID.hasValue()) + if (NewInnerLoopID) SubLoop->setLoopID(NewInnerLoopID.getValue()); else SubLoop->setLoopID(OrigSubLoopID); @@ -418,7 +418,7 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, Optional NewOuterLoopID = makeFollowupLoopID( OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll, LLVMLoopUnrollAndJamFollowupOuter}); - if (NewOuterLoopID.hasValue()) { + if (NewOuterLoopID) { L->setLoopID(NewOuterLoopID.getValue()); // Do not setLoopAlreadyUnrolled if a followup was given. diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp index 19695133530085..fda86afe5f9d74 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -253,19 +253,19 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences( UP.MaxIterationsCountToAnalyze = UnrollMaxIterationsCountToAnalyze; // Apply user values provided by argument - if (UserThreshold.hasValue()) { + if (UserThreshold) { UP.Threshold = *UserThreshold; UP.PartialThreshold = *UserThreshold; } - if (UserCount.hasValue()) + if (UserCount) UP.Count = *UserCount; - if (UserAllowPartial.hasValue()) + if (UserAllowPartial) UP.Partial = *UserAllowPartial; - if (UserRuntime.hasValue()) + if (UserRuntime) UP.Runtime = *UserRuntime; - if (UserUpperBound.hasValue()) + if (UserUpperBound) UP.UpperBound = *UserUpperBound; - if (UserFullUnrollMaxCount.hasValue()) + if (UserFullUnrollMaxCount) UP.FullUnrollMaxCount = *UserFullUnrollMaxCount; return UP; @@ -1323,7 +1323,7 @@ static LoopUnrollResult tryToUnrollLoop( Optional RemainderLoopID = makeFollowupLoopID(OrigLoopID, {LLVMLoopUnrollFollowupAll, LLVMLoopUnrollFollowupRemainder}); - if (RemainderLoopID.hasValue()) + if (RemainderLoopID) RemainderLoop->setLoopID(RemainderLoopID.getValue()); } @@ -1331,7 +1331,7 @@ static LoopUnrollResult tryToUnrollLoop( Optional NewLoopID = makeFollowupLoopID(OrigLoopID, {LLVMLoopUnrollFollowupAll, LLVMLoopUnrollFollowupUnrolled}); - if (NewLoopID.hasValue()) { + if (NewLoopID) { L->setLoopID(NewLoopID.getValue()); // Do not setLoopAlreadyUnrolled if loop attributes have been specified diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index c4ef979790be34..f94d854f7ee87e 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -1775,7 +1775,7 @@ CodeExtractor::extractCodeRegion(const CodeExtractorAnalysisCache &CEAC, // Update the entry count of the function. if (BFI) { auto Count = BFI->getProfileCountFromFreq(EntryFreq.getFrequency()); - if (Count.hasValue()) + if (Count) newFunction->setEntryCount( ProfileCount(Count.getValue(), Function::PCT_Real)); // FIXME BFI->setBlockFreq(codeReplacer, EntryFreq.getFrequency()); diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp index 7f0852cef8ec93..f093fea19c4d49 100644 --- a/llvm/lib/Transforms/Utils/LoopPeel.cpp +++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp @@ -719,9 +719,9 @@ TargetTransformInfo::PeelingPreferences llvm::gatherPeelingPreferences( } // User specifed values provided by argument. - if (UserAllowPeeling.hasValue()) + if (UserAllowPeeling) PP.AllowPeeling = *UserAllowPeeling; - if (UserAllowProfileBasedPeeling.hasValue()) + if (UserAllowProfileBasedPeeling) PP.PeelProfiledIterations = *UserAllowProfileBasedPeeling; return PP; diff --git a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp index df24af5c6d6097..1a94532305d46a 100644 --- a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp @@ -397,7 +397,7 @@ CloneLoopBlocks(Loop *L, Value *NewIter, const bool UseEpilogRemainder, Optional NewLoopID = makeFollowupLoopID( LoopID, {LLVMLoopUnrollFollowupAll, LLVMLoopUnrollFollowupRemainder}); - if (NewLoopID.hasValue()) { + if (NewLoopID) { NewLoop->setLoopID(NewLoopID.getValue()); // Do not setLoopAlreadyUnrolled if loop attributes have been defined diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index b7656f43490bdc..df30dbc3c90b38 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -358,7 +358,7 @@ TransformationMode llvm::hasUnrollTransformation(const Loop *L) { Optional Count = getOptionalIntLoopAttribute(L, "llvm.loop.unroll.count"); - if (Count.hasValue()) + if (Count) return Count.getValue() == 1 ? TM_SuppressedByUser : TM_ForcedByUser; if (getBooleanLoopAttribute(L, "llvm.loop.unroll.enable")) @@ -379,7 +379,7 @@ TransformationMode llvm::hasUnrollAndJamTransformation(const Loop *L) { Optional Count = getOptionalIntLoopAttribute(L, "llvm.loop.unroll_and_jam.count"); - if (Count.hasValue()) + if (Count) return Count.getValue() == 1 ? TM_SuppressedByUser : TM_ForcedByUser; if (getBooleanLoopAttribute(L, "llvm.loop.unroll_and_jam.enable")) diff --git a/llvm/lib/Transforms/Utils/MisExpect.cpp b/llvm/lib/Transforms/Utils/MisExpect.cpp index 5ace0c63a73958..b73d68ebec7c7d 100644 --- a/llvm/lib/Transforms/Utils/MisExpect.cpp +++ b/llvm/lib/Transforms/Utils/MisExpect.cpp @@ -219,7 +219,7 @@ void verifyMisExpect(Instruction &I, ArrayRef RealWeights, void checkBackendInstrumentation(Instruction &I, const ArrayRef RealWeights) { auto ExpectedWeightsOpt = extractWeights(&I, I.getContext()); - if (!ExpectedWeightsOpt.hasValue()) + if (!ExpectedWeightsOpt) return; auto ExpectedWeights = ExpectedWeightsOpt.getValue(); verifyMisExpect(I, RealWeights, ExpectedWeights); @@ -228,7 +228,7 @@ void checkBackendInstrumentation(Instruction &I, void checkFrontendInstrumentation(Instruction &I, const ArrayRef ExpectedWeights) { auto RealWeightsOpt = extractWeights(&I, I.getContext()); - if (!RealWeightsOpt.hasValue()) + if (!RealWeightsOpt) return; auto RealWeights = RealWeightsOpt.getValue(); verifyMisExpect(I, RealWeights, ExpectedWeights); diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index 7388a4bd42dbef..5120ade70e1646 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -254,7 +254,7 @@ void VFABI::setVectorVariantNames(CallInst *CI, for (const std::string &VariantMapping : VariantMappings) { LLVM_DEBUG(dbgs() << "VFABI: adding mapping '" << VariantMapping << "'\n"); Optional VI = VFABI::tryDemangleForVFABI(VariantMapping, *M); - assert(VI.hasValue() && "Cannot add an invalid VFABI name."); + assert(VI && "Cannot add an invalid VFABI name."); assert(M->getNamedValue(VI.getValue().VectorName) && "Cannot add variant to attribute: " "vector function declaration is missing."); diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 5e7a762ffac972..8dab54ce9f903e 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7612,7 +7612,7 @@ void LoopVectorizationPlanner::executePlan(ElementCount BestVF, unsigned BestUF, VPBasicBlock *HeaderVPBB = BestVPlan.getVectorLoopRegion()->getEntryBasicBlock(); Loop *L = LI->getLoopFor(State.CFG.VPBB2IRBB[HeaderVPBB]); - if (VectorizedLoopID.hasValue()) + if (VectorizedLoopID) L->setLoopID(VectorizedLoopID.getValue()); else { // Keep all loop hints from the original loop on the vector loop (we'll @@ -10622,7 +10622,7 @@ bool LoopVectorizePass::processLoop(Loop *L) { Optional RemainderLoopID = makeFollowupLoopID(OrigLoopID, {LLVMLoopVectorizeFollowupAll, LLVMLoopVectorizeFollowupEpilogue}); - if (RemainderLoopID.hasValue()) { + if (RemainderLoopID) { L->setLoopID(RemainderLoopID.getValue()); } else { if (DisableRuntimeUnroll) diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index d7769efb0e4649..e47d7179cdb210 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -2636,7 +2636,7 @@ class BoUpSLP { // First check if the result is already in the cache. AliasCacheKey key = std::make_pair(Inst1, Inst2); Optional &result = AliasCache[key]; - if (result.hasValue()) { + if (result) { return result.getValue(); } bool aliased = true; diff --git a/llvm/lib/WindowsDriver/MSVCPaths.cpp b/llvm/lib/WindowsDriver/MSVCPaths.cpp index 46a4426b38b4dc..0661ed7c6ae12b 100644 --- a/llvm/lib/WindowsDriver/MSVCPaths.cpp +++ b/llvm/lib/WindowsDriver/MSVCPaths.cpp @@ -98,14 +98,14 @@ static bool getWindowsSDKDirViaCommandLine( llvm::Optional WinSdkVersion, llvm::Optional WinSysRoot, std::string &Path, int &Major, std::string &Version) { - if (WinSdkDir.hasValue() || WinSysRoot.hasValue()) { + if (WinSdkDir || WinSysRoot) { // Don't validate the input; trust the value supplied by the user. // The motivation is to prevent unnecessary file and registry access. llvm::VersionTuple SDKVersion; - if (WinSdkVersion.hasValue()) + if (WinSdkVersion) SDKVersion.tryParse(*WinSdkVersion); - if (WinSysRoot.hasValue()) { + if (WinSysRoot) { llvm::SmallString<128> SDKPath(*WinSysRoot); llvm::sys::path::append(SDKPath, "Windows Kits"); if (!SDKVersion.empty()) @@ -479,12 +479,12 @@ bool findVCToolChainViaCommandLine(vfs::FileSystem &VFS, std::string &Path, ToolsetLayout &VSLayout) { // Don't validate the input; trust the value supplied by the user. // The primary motivation is to prevent unnecessary file and registry access. - if (VCToolsDir.hasValue() || WinSysRoot.hasValue()) { - if (WinSysRoot.hasValue()) { + if (VCToolsDir || WinSysRoot) { + if (WinSysRoot) { SmallString<128> ToolsPath(*WinSysRoot); sys::path::append(ToolsPath, "VC", "Tools", "MSVC"); std::string ToolsVersion; - if (VCToolsVersion.hasValue()) + if (VCToolsVersion) ToolsVersion = VCToolsVersion->str(); else ToolsVersion = getHighestNumericTupleInDirectory(VFS, ToolsPath); diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp index f38eb00dc50f5e..46782c9b3c9a3b 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -561,12 +561,12 @@ void SourceCoverageViewHTML::renderLine(raw_ostream &OS, LineRef L, else Color = None; - if (Color.hasValue()) + if (Color) Snippets[I + 1] = Highlight(Snippets[I + 1], CurSeg->Col, CurSeg->Col + Snippets[I + 1].size()); } - if (Color.hasValue() && Segments.empty()) + if (Color && Segments.empty()) Snippets.back() = Highlight(Snippets.back(), 1, 1 + Snippets.back().size()); if (getOptions().Debug) { diff --git a/llvm/tools/llvm-mca/Views/InstructionInfoView.cpp b/llvm/tools/llvm-mca/Views/InstructionInfoView.cpp index 28915e5a2ae537..67b636737b979a 100644 --- a/llvm/tools/llvm-mca/Views/InstructionInfoView.cpp +++ b/llvm/tools/llvm-mca/Views/InstructionInfoView.cpp @@ -70,7 +70,7 @@ void InstructionInfoView::printView(raw_ostream &OS) const { else if (IIVDEntry.Latency < 100) TempStream << ' '; - if (IIVDEntry.RThroughput.hasValue()) { + if (IIVDEntry.RThroughput) { double RT = IIVDEntry.RThroughput.getValue(); TempStream << format("%.2f", RT) << ' '; if (RT < 10.0) diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 42c38207a30e38..8180665749600b 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1408,7 +1408,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, // Right now, most targets return None i.e ignore to treat a symbol // separately. But WebAssembly decodes preludes for some symbols. // - if (Status.hasValue()) { + if (Status) { if (Status.getValue() == MCDisassembler::Fail) { outs() << "// Error in decoding " << SymbolName << " : Decoding failed region as bytes.\n"; diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 11387ac2882cc2..9c6586483ef03f 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -777,12 +777,12 @@ mergeSampleProfile(const WeightedFileVector &Inputs, SymbolRemapper *Remapper, } SampleProfileMap &Profiles = Reader->getProfiles(); - if (ProfileIsProbeBased.hasValue() && + if (ProfileIsProbeBased && ProfileIsProbeBased != FunctionSamples::ProfileIsProbeBased) exitWithError( "cannot merge probe-based profile with non-probe-based profile"); ProfileIsProbeBased = FunctionSamples::ProfileIsProbeBased; - if (ProfileIsCS.hasValue() && ProfileIsCS != FunctionSamples::ProfileIsCS) + if (ProfileIsCS && ProfileIsCS != FunctionSamples::ProfileIsCS) exitWithError("cannot merge CS profile with non-CS profile"); ProfileIsCS = FunctionSamples::ProfileIsCS; for (SampleProfileMap::iterator I = Profiles.begin(), E = Profiles.end(); diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp index adf7770f5cdbde..3f51455b1802d2 100644 --- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp +++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp @@ -100,25 +100,24 @@ BinarySizeContextTracker::getFuncSizeForContext(const SampleContext &Context) { PrevNode = CurrNode; CurrNode = CurrNode->getChildContext(ChildFrame.Location, ChildFrame.FuncName); - if (CurrNode && CurrNode->getFunctionSize().hasValue()) + if (CurrNode && CurrNode->getFunctionSize()) Size = CurrNode->getFunctionSize().getValue(); } // If we traversed all nodes along the path of the context and haven't // found a size yet, pivot to look for size from sibling nodes, i.e size // of inlinee under different context. - if (!Size.hasValue()) { + if (!Size) { if (!CurrNode) CurrNode = PrevNode; - while (!Size.hasValue() && CurrNode && - !CurrNode->getAllChildContext().empty()) { + while (!Size && CurrNode && !CurrNode->getAllChildContext().empty()) { CurrNode = &CurrNode->getAllChildContext().begin()->second; - if (CurrNode->getFunctionSize().hasValue()) + if (CurrNode->getFunctionSize()) Size = CurrNode->getFunctionSize().getValue(); } } - assert(Size.hasValue() && "We should at least find one context size."); + assert(Size && "We should at least find one context size."); return Size.getValue(); } diff --git a/llvm/tools/llvm-sim/llvm-sim.cpp b/llvm/tools/llvm-sim/llvm-sim.cpp index 26e370ff30f1ef..6879d73c4434d3 100644 --- a/llvm/tools/llvm-sim/llvm-sim.cpp +++ b/llvm/tools/llvm-sim/llvm-sim.cpp @@ -85,10 +85,9 @@ exportToFile(const StringRef FilePath, Optional End = getPositionInModule((*C.back()).Inst, LLVMInstNum); - assert(Start.hasValue() && + assert(Start && "Could not find instruction number for first instruction"); - assert(End.hasValue() && - "Could not find instruction number for last instruction"); + assert(End && "Could not find instruction number for last instruction"); J.object([&] { J.attribute("start", Start.getValue()); diff --git a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp index a57b8cfdec956c..122ae7df50a04f 100644 --- a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp +++ b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp @@ -40,8 +40,8 @@ dumpDXContainer(MemoryBufferRef Source) { Obj->Header.PartOffsets->push_back(P.Offset); if (P.Part.getName() == "DXIL") { Optional DXIL = Container.getDXIL(); - assert(DXIL.hasValue() && "Since we are iterating and found a DXIL part, " - "this should never not have a value"); + assert(DXIL && "Since we are iterating and found a DXIL part, " + "this should never not have a value"); Obj->Parts.push_back(DXContainerYAML::Part{ P.Part.getName().str(), P.Part.Size, DXContainerYAML::DXILProgram{ diff --git a/llvm/unittests/Analysis/VectorFunctionABITest.cpp b/llvm/unittests/Analysis/VectorFunctionABITest.cpp index 7ac1b0384f87b4..b819bb4c5f91dc 100644 --- a/llvm/unittests/Analysis/VectorFunctionABITest.cpp +++ b/llvm/unittests/Analysis/VectorFunctionABITest.cpp @@ -75,7 +75,7 @@ class VFABIParserTest : public ::testing::Test { reset(Name, IRType); const auto OptInfo = VFABI::tryDemangleForVFABI(MangledName, *(M.get())); - if (OptInfo.hasValue()) { + if (OptInfo) { Info = OptInfo.getValue(); return true; } diff --git a/llvm/unittests/IR/VPIntrinsicTest.cpp b/llvm/unittests/IR/VPIntrinsicTest.cpp index 62e16df1f4916d..b403b428f956c9 100644 --- a/llvm/unittests/IR/VPIntrinsicTest.cpp +++ b/llvm/unittests/IR/VPIntrinsicTest.cpp @@ -233,7 +233,7 @@ TEST_F(VPIntrinsicTest, GetParamPos) { ASSERT_TRUE(F.isIntrinsic()); Optional MaskParamPos = VPIntrinsic::getMaskParamPos(F.getIntrinsicID()); - if (MaskParamPos.hasValue()) { + if (MaskParamPos) { Type *MaskParamType = F.getArg(MaskParamPos.getValue())->getType(); ASSERT_TRUE(MaskParamType->isVectorTy()); ASSERT_TRUE( @@ -242,7 +242,7 @@ TEST_F(VPIntrinsicTest, GetParamPos) { Optional VecLenParamPos = VPIntrinsic::getVectorLengthParamPos(F.getIntrinsicID()); - if (VecLenParamPos.hasValue()) { + if (VecLenParamPos) { Type *VecLenParamType = F.getArg(VecLenParamPos.getValue())->getType(); ASSERT_TRUE(VecLenParamType->isIntegerTy(32)); } diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp index 480848100446b3..8f97a380c200f7 100644 --- a/llvm/unittests/ProfileData/MemProfTest.cpp +++ b/llvm/unittests/ProfileData/MemProfTest.cpp @@ -104,7 +104,7 @@ MATCHER_P4(FrameContains, FunctionName, LineOffset, Column, Inline, "") { *result_listener << "Hash mismatch"; return false; } - if (F.SymbolName.hasValue() && F.SymbolName.getValue() != FunctionName) { + if (F.SymbolName && F.SymbolName.getValue() != FunctionName) { *result_listener << "SymbolName mismatch\nWant: " << FunctionName << "\nGot: " << F.SymbolName.getValue(); return false; diff --git a/llvm/utils/TableGen/GlobalISel/GIMatchTree.h b/llvm/utils/TableGen/GlobalISel/GIMatchTree.h index 56df37731c09a2..dfd1426c191f9b 100644 --- a/llvm/utils/TableGen/GlobalISel/GIMatchTree.h +++ b/llvm/utils/TableGen/GlobalISel/GIMatchTree.h @@ -36,7 +36,7 @@ class GIMatchTreeVariableBinding { StringRef getName() const { return Name; } unsigned getInstrID() const { return InstrID; } unsigned getOpIdx() const { - assert(OpIdx.hasValue() && "Is not an operand binding"); + assert(OpIdx && "Is not an operand binding"); return *OpIdx; } }; diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp index e4ea6daee9deb5..c8eac56d03e6dc 100644 --- a/llvm/utils/TableGen/GlobalISelEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp @@ -2936,12 +2936,12 @@ class RenderComplexPatternOperand : public OperandRenderer { } void emitRenderOpcodes(MatchTable &Table, RuleMatcher &Rule) const override { - Table << MatchTable::Opcode(SubOperand.hasValue() ? "GIR_ComplexSubOperandRenderer" - : "GIR_ComplexRenderer") + Table << MatchTable::Opcode(SubOperand ? "GIR_ComplexSubOperandRenderer" + : "GIR_ComplexRenderer") << MatchTable::Comment("InsnID") << MatchTable::IntValue(InsnID) << MatchTable::Comment("RendererID") << MatchTable::IntValue(RendererID); - if (SubOperand.hasValue()) + if (SubOperand) Table << MatchTable::Comment("SubOperand") << MatchTable::IntValue(SubOperand.getValue()); Table << MatchTable::Comment(SymbolicName) << MatchTable::LineBreak;