diff --git a/llvm/lib/Analysis/InlineAdvisor.cpp b/llvm/lib/Analysis/InlineAdvisor.cpp index c427230404e6..342a9e757ac6 100644 --- a/llvm/lib/Analysis/InlineAdvisor.cpp +++ b/llvm/lib/Analysis/InlineAdvisor.cpp @@ -100,8 +100,7 @@ llvm::Optional static getDefaultInlineAdvice( GetBFI, PSI, RemarksEnabled ? &ORE : nullptr); }; return llvm::shouldInline(CB, GetInlineCost, ORE, - Params.EnableDeferral.hasValue() && - Params.EnableDeferral.getValue()); + Params.EnableDeferral.getValueOr(false)); } std::unique_ptr DefaultInlineAdvisor::getAdvice(CallBase &CB) { diff --git a/llvm/lib/Target/ARC/ARCTargetMachine.cpp b/llvm/lib/Target/ARC/ARCTargetMachine.cpp index 4a5b6fd4d5bf..b8c8949e18dd 100644 --- a/llvm/lib/Target/ARC/ARCTargetMachine.cpp +++ b/llvm/lib/Target/ARC/ARCTargetMachine.cpp @@ -21,9 +21,7 @@ using namespace llvm; static Reloc::Model getRelocModel(Optional RM) { - if (!RM.hasValue()) - return Reloc::Static; - return *RM; + return RM.getValueOr(Reloc::Static); } /// ARCTargetMachine ctor - Create an ILP32 architecture model diff --git a/llvm/lib/Target/AVR/AVRTargetMachine.cpp b/llvm/lib/Target/AVR/AVRTargetMachine.cpp index 0c7136e6f77e..0fa8623e2fb7 100644 --- a/llvm/lib/Target/AVR/AVRTargetMachine.cpp +++ b/llvm/lib/Target/AVR/AVRTargetMachine.cpp @@ -37,7 +37,7 @@ static StringRef getCPU(StringRef CPU) { } static Reloc::Model getEffectiveRelocModel(Optional RM) { - return RM.hasValue() ? *RM : Reloc::Static; + return RM.getValueOr(Reloc::Static); } AVRTargetMachine::AVRTargetMachine(const Target &T, const Triple &TT, diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp b/llvm/lib/Target/BPF/BPFTargetMachine.cpp index c35a3192282f..c0244b9f2c74 100644 --- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp +++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp @@ -57,9 +57,7 @@ static std::string computeDataLayout(const Triple &TT) { } static Reloc::Model getEffectiveRelocModel(Optional RM) { - if (!RM.hasValue()) - return Reloc::PIC_; - return *RM; + return RM.getValueOr(Reloc::PIC_); } BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT, diff --git a/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp b/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp index 3e4e1b083f7a..1c13796e84b6 100644 --- a/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp +++ b/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp @@ -44,7 +44,7 @@ CSKYTargetMachine::CSKYTargetMachine(const Target &T, const Triple &TT, Optional CM, CodeGenOpt::Level OL, bool JIT) : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options, - !RM.hasValue() ? Reloc::Static : *RM, + RM.getValueOr(Reloc::Static), getEffectiveCodeModel(CM, CodeModel::Small), OL), TLOF(std::make_unique()) { initAsmInfo(); diff --git a/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp b/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp index ba0f45fe09f7..9195bb3dc725 100644 --- a/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp +++ b/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp @@ -187,9 +187,7 @@ namespace llvm { } // end namespace llvm; static Reloc::Model getEffectiveRelocModel(Optional RM) { - if (!RM.hasValue()) - return Reloc::Static; - return *RM; + return RM.getValueOr(Reloc::Static); } extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeHexagonTarget() { diff --git a/llvm/lib/Target/Lanai/LanaiTargetMachine.cpp b/llvm/lib/Target/Lanai/LanaiTargetMachine.cpp index 69387119f1f4..a31f59214ec7 100644 --- a/llvm/lib/Target/Lanai/LanaiTargetMachine.cpp +++ b/llvm/lib/Target/Lanai/LanaiTargetMachine.cpp @@ -48,9 +48,7 @@ static std::string computeDataLayout() { } static Reloc::Model getEffectiveRelocModel(Optional RM) { - if (!RM.hasValue()) - return Reloc::PIC_; - return *RM; + return RM.getValueOr(Reloc::PIC_); } LanaiTargetMachine::LanaiTargetMachine(const Target &T, const Triple &TT, diff --git a/llvm/lib/Target/Sparc/SparcTargetMachine.cpp b/llvm/lib/Target/Sparc/SparcTargetMachine.cpp index 8ea85dd065c2..ae5228db5827 100644 --- a/llvm/lib/Target/Sparc/SparcTargetMachine.cpp +++ b/llvm/lib/Target/Sparc/SparcTargetMachine.cpp @@ -55,9 +55,7 @@ static std::string computeDataLayout(const Triple &T, bool is64Bit) { } static Reloc::Model getEffectiveRelocModel(Optional RM) { - if (!RM.hasValue()) - return Reloc::Static; - return *RM; + return RM.getValueOr(Reloc::Static); } // Code models. Some only make sense for 64-bit code. diff --git a/llvm/lib/Target/VE/VETargetMachine.cpp b/llvm/lib/Target/VE/VETargetMachine.cpp index 1077abc54141..414ae09431c0 100644 --- a/llvm/lib/Target/VE/VETargetMachine.cpp +++ b/llvm/lib/Target/VE/VETargetMachine.cpp @@ -61,9 +61,7 @@ static std::string computeDataLayout(const Triple &T) { } static Reloc::Model getEffectiveRelocModel(Optional RM) { - if (!RM.hasValue()) - return Reloc::Static; - return *RM; + return RM.getValueOr(Reloc::Static); } class VEELFTargetObjectFile : public TargetLoweringObjectFileELF { diff --git a/llvm/lib/Target/XCore/XCoreTargetMachine.cpp b/llvm/lib/Target/XCore/XCoreTargetMachine.cpp index 1eea1e37c253..046cd6b5db7d 100644 --- a/llvm/lib/Target/XCore/XCoreTargetMachine.cpp +++ b/llvm/lib/Target/XCore/XCoreTargetMachine.cpp @@ -26,9 +26,7 @@ using namespace llvm; static Reloc::Model getEffectiveRelocModel(Optional RM) { - if (!RM.hasValue()) - return Reloc::Static; - return *RM; + return RM.getValueOr(Reloc::Static); } static CodeModel::Model diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index e480d7b8d61f..65bf6a3b32dc 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1568,8 +1568,7 @@ static void updateCallProfile(Function *Callee, const ValueToValueMapTy &VMap, return; auto CallSiteCount = PSI ? PSI->getProfileCount(TheCall, CallerBFI) : None; int64_t CallCount = - std::min(CallSiteCount.hasValue() ? CallSiteCount.getValue() : 0, - CalleeEntryCount.getCount()); + std::min(CallSiteCount.getValueOr(0), CalleeEntryCount.getCount()); updateProfileCallee(Callee, -CallCount, &VMap); } diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index ba96e8437dfd..401fe450ebad 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -310,8 +310,7 @@ llvm::getOptionalElementCountLoopAttribute(Loop *TheLoop) { if (Width.hasValue()) { Optional IsScalable = getOptionalIntLoopAttribute( TheLoop, "llvm.loop.vectorize.scalable.enable"); - return ElementCount::get(*Width, - IsScalable.hasValue() ? *IsScalable : false); + return ElementCount::get(*Width, IsScalable.getValueOr(false)); } return None; diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp index b238573be494..e18de6ebf9e0 100644 --- a/llvm/utils/TableGen/GlobalISelEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp @@ -453,9 +453,8 @@ public: MatchTableRecord(Optional LabelID_, StringRef EmitStr, unsigned NumElements, unsigned Flags, int64_t RawValue = std::numeric_limits::min()) - : LabelID(LabelID_.hasValue() ? LabelID_.getValue() : ~0u), - EmitStr(EmitStr), NumElements(NumElements), Flags(Flags), - RawValue(RawValue) { + : LabelID(LabelID_.getValueOr(~0u)), EmitStr(EmitStr), + NumElements(NumElements), Flags(Flags), RawValue(RawValue) { assert((!LabelID_.hasValue() || LabelID != ~0u) && "This value is reserved for non-labels"); }