[llvm] Use Optional::getValueOr (NFC)

This commit is contained in:
Kazu Hirata 2021-01-12 21:43:50 -08:00
parent 2c2d489b78
commit 8a20e2b3d3
13 changed files with 14 additions and 32 deletions

View File

@ -100,8 +100,7 @@ llvm::Optional<llvm::InlineCost> 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<InlineAdvice> DefaultInlineAdvisor::getAdvice(CallBase &CB) {

View File

@ -21,9 +21,7 @@
using namespace llvm;
static Reloc::Model getRelocModel(Optional<Reloc::Model> RM) {
if (!RM.hasValue())
return Reloc::Static;
return *RM;
return RM.getValueOr(Reloc::Static);
}
/// ARCTargetMachine ctor - Create an ILP32 architecture model

View File

@ -37,7 +37,7 @@ static StringRef getCPU(StringRef CPU) {
}
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
return RM.hasValue() ? *RM : Reloc::Static;
return RM.getValueOr(Reloc::Static);
}
AVRTargetMachine::AVRTargetMachine(const Target &T, const Triple &TT,

View File

@ -57,9 +57,7 @@ static std::string computeDataLayout(const Triple &TT) {
}
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
if (!RM.hasValue())
return Reloc::PIC_;
return *RM;
return RM.getValueOr(Reloc::PIC_);
}
BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT,

View File

@ -44,7 +44,7 @@ CSKYTargetMachine::CSKYTargetMachine(const Target &T, const Triple &TT,
Optional<CodeModel::Model> 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<TargetLoweringObjectFileELF>()) {
initAsmInfo();

View File

@ -187,9 +187,7 @@ namespace llvm {
} // end namespace llvm;
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
if (!RM.hasValue())
return Reloc::Static;
return *RM;
return RM.getValueOr(Reloc::Static);
}
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeHexagonTarget() {

View File

@ -48,9 +48,7 @@ static std::string computeDataLayout() {
}
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
if (!RM.hasValue())
return Reloc::PIC_;
return *RM;
return RM.getValueOr(Reloc::PIC_);
}
LanaiTargetMachine::LanaiTargetMachine(const Target &T, const Triple &TT,

View File

@ -55,9 +55,7 @@ static std::string computeDataLayout(const Triple &T, bool is64Bit) {
}
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
if (!RM.hasValue())
return Reloc::Static;
return *RM;
return RM.getValueOr(Reloc::Static);
}
// Code models. Some only make sense for 64-bit code.

View File

@ -61,9 +61,7 @@ static std::string computeDataLayout(const Triple &T) {
}
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
if (!RM.hasValue())
return Reloc::Static;
return *RM;
return RM.getValueOr(Reloc::Static);
}
class VEELFTargetObjectFile : public TargetLoweringObjectFileELF {

View File

@ -26,9 +26,7 @@
using namespace llvm;
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
if (!RM.hasValue())
return Reloc::Static;
return *RM;
return RM.getValueOr(Reloc::Static);
}
static CodeModel::Model

View File

@ -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);
}

View File

@ -310,8 +310,7 @@ llvm::getOptionalElementCountLoopAttribute(Loop *TheLoop) {
if (Width.hasValue()) {
Optional<int> 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;

View File

@ -453,9 +453,8 @@ public:
MatchTableRecord(Optional<unsigned> LabelID_, StringRef EmitStr,
unsigned NumElements, unsigned Flags,
int64_t RawValue = std::numeric_limits<int64_t>::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");
}