std::optional::value => operator*/operator->

value() has undesired exception checking semantics and calls
__throw_bad_optional_access in libc++. Moreover, the API is unavailable without
_LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see
_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS).

This commit fixes LLVMAnalysis and its dependencies.
This commit is contained in:
Fangrui Song 2022-12-16 22:44:08 +00:00
parent 27249c06b7
commit 2fa744e631
39 changed files with 144 additions and 159 deletions

View File

@ -1277,10 +1277,10 @@ bool BlockFrequencyInfoImpl<BT>::computeMassInLoop(LoopData &Loop) {
continue;
}
LLVM_DEBUG(dbgs() << getBlockName(HeaderNode)
<< " has irr loop header weight "
<< HeaderWeight.value() << "\n");
<< " has irr loop header weight " << *HeaderWeight
<< "\n");
NumHeadersWithWeight++;
uint64_t HeaderWeightValue = HeaderWeight.value();
uint64_t HeaderWeightValue = *HeaderWeight;
if (!MinHeaderWeight || HeaderWeightValue < MinHeaderWeight)
MinHeaderWeight = HeaderWeightValue;
if (HeaderWeightValue) {
@ -1732,10 +1732,10 @@ raw_ostream &BlockFrequencyInfoImpl<BT>::print(raw_ostream &OS) const {
if (std::optional<uint64_t> ProfileCount =
BlockFrequencyInfoImplBase::getBlockProfileCount(
F->getFunction(), getNode(&BB)))
OS << ", count = " << ProfileCount.value();
OS << ", count = " << *ProfileCount;
if (std::optional<uint64_t> IrrLoopHeaderWeight =
BB.getIrrLoopHeaderWeight())
OS << ", irr_loop_header_weight = " << IrrLoopHeaderWeight.value();
OS << ", irr_loop_header_weight = " << *IrrLoopHeaderWeight;
OS << "\n";
}

View File

@ -237,10 +237,10 @@ 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 && (Shape.value().ScalarName == ScalarName)) {
assert(CI.getModule()->getFunction(Shape.value().VectorName) &&
if (Shape && (Shape->ScalarName == ScalarName)) {
assert(CI.getModule()->getFunction(Shape->VectorName) &&
"Vector function is missing.");
Mappings.push_back(Shape.value());
Mappings.push_back(*Shape);
}
}
}

View File

@ -385,12 +385,12 @@ private:
const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
if (Op.isLiteral())
EmitAbbreviatedLiteral(Op, Code.value());
EmitAbbreviatedLiteral(Op, *Code);
else {
assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
Op.getEncoding() != BitCodeAbbrevOp::Blob &&
"Expected literal or scalar");
EmitAbbreviatedField(Op, Code.value());
EmitAbbreviatedField(Op, *Code);
}
}

View File

@ -1199,26 +1199,21 @@ private:
RoundingMode UseRounding = DefaultConstrainedRounding;
if (Rounding)
UseRounding = Rounding.value();
UseRounding = *Rounding;
std::optional<StringRef> RoundingStr =
convertRoundingModeToStr(UseRounding);
assert(RoundingStr && "Garbage strict rounding mode!");
auto *RoundingMDS = MDString::get(Context, RoundingStr.value());
auto *RoundingMDS = MDString::get(Context, *RoundingStr);
return MetadataAsValue::get(Context, RoundingMDS);
}
Value *getConstrainedFPExcept(std::optional<fp::ExceptionBehavior> Except) {
fp::ExceptionBehavior UseExcept = DefaultConstrainedExcept;
if (Except)
UseExcept = Except.value();
std::optional<StringRef> ExceptStr =
convertExceptionBehaviorToStr(UseExcept);
std::optional<StringRef> ExceptStr = convertExceptionBehaviorToStr(
Except.value_or(DefaultConstrainedExcept));
assert(ExceptStr && "Garbage strict exception behavior!");
auto *ExceptMDS = MDString::get(Context, ExceptStr.value());
auto *ExceptMDS = MDString::get(Context, *ExceptStr);
return MetadataAsValue::get(Context, ExceptMDS);
}

View File

@ -89,7 +89,7 @@ public:
bool hasImportModule() const { return ImportModule.has_value(); }
StringRef getImportModule() const {
if (ImportModule)
return ImportModule.value();
return *ImportModule;
// Use a default module name of "env" for now, for compatibility with
// existing tools.
// TODO(sbc): Find a way to specify a default value in the object format
@ -101,13 +101,13 @@ public:
bool hasImportName() const { return ImportName.has_value(); }
StringRef getImportName() const {
if (ImportName)
return ImportName.value();
return *ImportName;
return getName();
}
void setImportName(StringRef Name) { ImportName = Name; }
bool hasExportName() const { return ExportName.has_value(); }
StringRef getExportName() const { return ExportName.value(); }
StringRef getExportName() const { return *ExportName; }
void setExportName(StringRef Name) { ExportName = Name; }
bool isFunctionTable() const {
@ -130,14 +130,14 @@ public:
const wasm::WasmGlobalType &getGlobalType() const {
assert(GlobalType);
return GlobalType.value();
return *GlobalType;
}
void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
bool hasTableType() const { return TableType.has_value(); }
const wasm::WasmTableType &getTableType() const {
assert(hasTableType());
return TableType.value();
return *TableType;
}
void setTableType(wasm::WasmTableType TT) { TableType = TT; }
void setTableType(wasm::ValType VT) {

View File

@ -39,7 +39,7 @@ public:
XCOFF::StorageClass getStorageClass() const {
assert(StorageClass && "StorageClass not set on XCOFF MCSymbol.");
return StorageClass.value();
return *StorageClass;
}
StringRef getUnqualifiedName() const { return getUnqualifiedName(getName()); }

View File

@ -612,9 +612,7 @@ template <typename T> struct ValueIsPresent<std::optional<T>> {
static inline bool isPresent(const std::optional<T> &t) {
return t.has_value();
}
static inline decltype(auto) unwrapValue(std::optional<T> &t) {
return t.value();
}
static inline decltype(auto) unwrapValue(std::optional<T> &t) { return *t; }
};
// If something is "nullable" then we just compare it to nullptr to see if it

View File

@ -823,7 +823,7 @@ void BranchProbabilityInfo::computeEestimateBlockWeight(
if (auto BBWeight = getInitialEstimatedBlockWeight(BB))
// If we were able to find estimated weight for the block set it to this
// block and propagate up the IR.
propagateEstimatedBlockWeight(getLoopBlock(BB), DT, PDT, BBWeight.value(),
propagateEstimatedBlockWeight(getLoopBlock(BB), DT, PDT, *BBWeight,
BlockWorkList, LoopWorkList);
// BlockWorklist/LoopWorkList contains blocks/loops with at least one

View File

@ -184,7 +184,7 @@ CmpInst::Predicate IRInstructionData::getPredicate() const {
"Can only get a predicate from a compare instruction");
if (RevisedPredicate)
return RevisedPredicate.value();
return *RevisedPredicate;
return cast<CmpInst>(Inst)->getPredicate();
}

View File

@ -736,8 +736,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
BlockFrequencyInfo *BFI = &(GetBFI(F));
assert(BFI && "BFI must be available");
auto ProfileCount = BFI->getBlockProfileCount(BB);
assert(ProfileCount);
if (ProfileCount.value() == 0)
if (*ProfileCount == 0)
ColdSize += Cost - CostAtBBStart;
}
@ -861,8 +860,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
}
auto ProfileCount = CalleeBFI->getBlockProfileCount(&BB);
assert(ProfileCount);
CurrentSavings *= ProfileCount.value();
CurrentSavings *= *ProfileCount;
CycleSavings += CurrentSavings;
}
@ -1820,12 +1818,12 @@ void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
// return min(A, B) if B is valid.
auto MinIfValid = [](int A, std::optional<int> B) {
return B ? std::min(A, B.value()) : A;
return B ? std::min(A, *B) : A;
};
// return max(A, B) if B is valid.
auto MaxIfValid = [](int A, std::optional<int> B) {
return B ? std::max(A, B.value()) : A;
return B ? std::max(A, *B) : A;
};
// Various bonus percentages. These are multiplied by Threshold to get the

View File

@ -2227,10 +2227,10 @@ static Value *simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
}
if (std::optional<bool> Implied = isImpliedCondition(Op1, Op0, Q.DL)) {
// If Op1 is true implies Op0 is true, then Op1 is a subset of Op0.
if (Implied.value())
if (*Implied)
return Op1;
// If Op1 is true implies Op0 is false, then they are not true together.
if (!Implied.value())
if (!*Implied)
return ConstantInt::getFalse(Op1->getType());
}
}
@ -6324,9 +6324,9 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) {
Value *Op1 = Call->getArgOperand(1);
Value *Op2 = Call->getArgOperand(2);
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
if (Value *V = simplifyFPOp({Op0, Op1, Op2}, {}, Q,
FPI->getExceptionBehavior().value(),
FPI->getRoundingMode().value()))
if (Value *V =
simplifyFPOp({Op0, Op1, Op2}, {}, Q, *FPI->getExceptionBehavior(),
*FPI->getRoundingMode()))
return V;
return nullptr;
}
@ -6392,31 +6392,31 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) {
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
return simplifyFAddInst(
FPI->getArgOperand(0), FPI->getArgOperand(1), FPI->getFastMathFlags(),
Q, FPI->getExceptionBehavior().value(), FPI->getRoundingMode().value());
Q, *FPI->getExceptionBehavior(), *FPI->getRoundingMode());
}
case Intrinsic::experimental_constrained_fsub: {
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
return simplifyFSubInst(
FPI->getArgOperand(0), FPI->getArgOperand(1), FPI->getFastMathFlags(),
Q, FPI->getExceptionBehavior().value(), FPI->getRoundingMode().value());
Q, *FPI->getExceptionBehavior(), *FPI->getRoundingMode());
}
case Intrinsic::experimental_constrained_fmul: {
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
return simplifyFMulInst(
FPI->getArgOperand(0), FPI->getArgOperand(1), FPI->getFastMathFlags(),
Q, FPI->getExceptionBehavior().value(), FPI->getRoundingMode().value());
Q, *FPI->getExceptionBehavior(), *FPI->getRoundingMode());
}
case Intrinsic::experimental_constrained_fdiv: {
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
return simplifyFDivInst(
FPI->getArgOperand(0), FPI->getArgOperand(1), FPI->getFastMathFlags(),
Q, FPI->getExceptionBehavior().value(), FPI->getRoundingMode().value());
Q, *FPI->getExceptionBehavior(), *FPI->getRoundingMode());
}
case Intrinsic::experimental_constrained_frem: {
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
return simplifyFRemInst(
FPI->getArgOperand(0), FPI->getArgOperand(1), FPI->getFastMathFlags(),
Q, FPI->getExceptionBehavior().value(), FPI->getRoundingMode().value());
Q, *FPI->getExceptionBehavior(), *FPI->getRoundingMode());
}
default:
return nullptr;

View File

@ -924,7 +924,7 @@ LazyValueInfoImpl::solveBlockValueCast(CastInst *CI, BasicBlock *BB) {
if (!LHSRes)
// More work to do before applying this transfer rule.
return std::nullopt;
const ConstantRange &LHSRange = LHSRes.value();
const ConstantRange &LHSRange = *LHSRes;
const unsigned ResultBitWidth = CI->getType()->getIntegerBitWidth();
@ -950,8 +950,8 @@ LazyValueInfoImpl::solveBlockValueBinaryOpImpl(
// More work to do before applying this transfer rule.
return std::nullopt;
const ConstantRange &LHSRange = LHSRes.value();
const ConstantRange &RHSRange = RHSRes.value();
const ConstantRange &LHSRange = *LHSRes;
const ConstantRange &RHSRange = *RHSRes;
return ValueLatticeElement::getRange(OpFn(LHSRange, RHSRange));
}

View File

@ -508,10 +508,10 @@ llvm::getAllocationFamily(const Value *I, const TargetLibraryInfo *TLI) {
// Callee is some known library function.
const auto AllocData = getAllocationDataForFunction(Callee, AnyAlloc, TLI);
if (AllocData)
return mangledNameForMallocFamily(AllocData.value().Family);
return mangledNameForMallocFamily(AllocData->Family);
const auto FreeData = getFreeFunctionDataForFunction(Callee, TLIFn);
if (FreeData)
return mangledNameForMallocFamily(FreeData.value().Family);
return mangledNameForMallocFamily(FreeData->Family);
}
// Callee isn't a known library function, still check attributes.
if (checkFnAllocKind(I, AllocFnKind::Free | AllocFnKind::Alloc |

View File

@ -503,7 +503,7 @@ static V getOrCreateCachedOptional(K Key, DenseMap<K, std::optional<V>> &Map,
std::optional<V> &OptVal = Map[Key];
if (!OptVal)
OptVal = Fn(std::forward<ArgsTy>(args)...);
return OptVal.value();
return *OptVal;
}
const BasicBlock *

View File

@ -282,19 +282,19 @@ ProfileSummaryInfo::computeThreshold(int PercentileCutoff) const {
}
bool ProfileSummaryInfo::hasHugeWorkingSetSize() const {
return HasHugeWorkingSetSize && HasHugeWorkingSetSize.value();
return HasHugeWorkingSetSize && *HasHugeWorkingSetSize;
}
bool ProfileSummaryInfo::hasLargeWorkingSetSize() const {
return HasLargeWorkingSetSize && HasLargeWorkingSetSize.value();
return HasLargeWorkingSetSize && *HasLargeWorkingSetSize;
}
bool ProfileSummaryInfo::isHotCount(uint64_t C) const {
return HotCountThreshold && C >= HotCountThreshold.value();
return HotCountThreshold && C >= *HotCountThreshold;
}
bool ProfileSummaryInfo::isColdCount(uint64_t C) const {
return ColdCountThreshold && C <= ColdCountThreshold.value();
return ColdCountThreshold && C <= *ColdCountThreshold;
}
template <bool isHot>
@ -302,9 +302,9 @@ bool ProfileSummaryInfo::isHotOrColdCountNthPercentile(int PercentileCutoff,
uint64_t C) const {
auto CountThreshold = computeThreshold(PercentileCutoff);
if (isHot)
return CountThreshold && C >= CountThreshold.value();
return CountThreshold && C >= *CountThreshold;
else
return CountThreshold && C <= CountThreshold.value();
return CountThreshold && C <= *CountThreshold;
}
bool ProfileSummaryInfo::isHotCountNthPercentile(int PercentileCutoff,

View File

@ -4943,7 +4943,7 @@ public:
std::optional<const SCEV *> Res =
compareWithBackedgeCondition(SI->getCondition());
if (Res) {
bool IsOne = cast<SCEVConstant>(Res.value())->getValue()->isOne();
bool IsOne = cast<SCEVConstant>(*Res)->getValue()->isOne();
Result = SE.getSCEV(IsOne ? SI->getTrueValue() : SI->getFalseValue());
}
break;
@ -4951,7 +4951,7 @@ public:
default: {
std::optional<const SCEV *> Res = compareWithBackedgeCondition(I);
if (Res)
Result = Res.value();
Result = *Res;
break;
}
}
@ -6778,7 +6778,7 @@ const ConstantRange &ScalarEvolution::getRangeRef(
std::optional<ConstantRange> MDRange = GetRangeFromMetadata(U->getValue());
if (MDRange)
ConservativeResult =
ConservativeResult.intersectWith(MDRange.value(), RangeType);
ConservativeResult.intersectWith(*MDRange, RangeType);
// Use facts about recurrences in the underlying IR. Note that add
// recurrences are AddRecExprs and thus don't hit this path. This
@ -10903,8 +10903,7 @@ ScalarEvolution::getMonotonicPredicateType(const SCEVAddRecExpr *LHS,
auto ResultSwapped =
getMonotonicPredicateTypeImpl(LHS, ICmpInst::getSwappedPredicate(Pred));
assert(ResultSwapped && "should be able to analyze both!");
assert(ResultSwapped.value() != Result.value() &&
assert(*ResultSwapped != *Result &&
"monotonicity should flip as we flip the predicate");
}
#endif

View File

@ -1546,7 +1546,7 @@ void VFABI::getVectorVariantNames(
std::optional<VFInfo> Info =
VFABI::tryDemangleForVFABI(S, *(CI.getModule()));
assert(Info && "Invalid name for a VFABI variant.");
assert(CI.getModule()->getFunction(Info.value().VectorName) &&
assert(CI.getModule()->getFunction(Info->VectorName) &&
"Vector function is missing.");
#endif
VariantMappings.push_back(std::string(S));

View File

@ -1203,13 +1203,12 @@ void DWARFContext::addLocalsForDie(DWARFCompileUnit *CU, DWARFDie Subprogram,
if (auto DeclFileAttr = Die.find(DW_AT_decl_file)) {
if (const auto *LT = CU->getContext().getLineTableForUnit(CU))
LT->getFileNameByIndex(
DeclFileAttr->getAsUnsignedConstant().value(),
CU->getCompilationDir(),
*DeclFileAttr->getAsUnsignedConstant(), CU->getCompilationDir(),
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
Local.DeclFile);
}
if (auto DeclLineAttr = Die.find(DW_AT_decl_line))
Local.DeclLine = DeclLineAttr->getAsUnsignedConstant().value();
Local.DeclLine = *DeclLineAttr->getAsUnsignedConstant();
Result.push_back(Local);
return;

View File

@ -323,20 +323,20 @@ parseV5DirFileTables(const DWARFDataExtractor &DebugLineData,
FileEntry.Source = Value;
break;
case DW_LNCT_directory_index:
FileEntry.DirIdx = Value.getAsUnsignedConstant().value();
FileEntry.DirIdx = *Value.getAsUnsignedConstant();
break;
case DW_LNCT_timestamp:
FileEntry.ModTime = Value.getAsUnsignedConstant().value();
FileEntry.ModTime = *Value.getAsUnsignedConstant();
break;
case DW_LNCT_size:
FileEntry.Length = Value.getAsUnsignedConstant().value();
FileEntry.Length = *Value.getAsUnsignedConstant();
break;
case DW_LNCT_MD5:
if (!Value.getAsBlock() || Value.getAsBlock().value().size() != 16)
if (!Value.getAsBlock() || Value.getAsBlock()->size() != 16)
return createStringError(
errc::invalid_argument,
"failed to parse file entry because the MD5 hash is invalid");
std::uninitialized_copy_n(Value.getAsBlock().value().begin(), 16,
std::uninitialized_copy_n(Value.getAsBlock()->begin(), 16,
FileEntry.Checksum.begin());
break;
default:

View File

@ -1800,7 +1800,7 @@ static CallInst *emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
auto R = DIExpression::createFragmentExpression(Expr, Info.OffsetInBits,
Info.SizeInBits);
assert(R.has_value() && "failed to create fragment expression");
Expr = R.value();
Expr = *R;
}
DIExpression *AddrExpr =
DIExpression::get(StoreLikeInst.getContext(), std::nullopt);

View File

@ -4582,9 +4582,9 @@ MDNode *SwitchInstProfUpdateWrapper::buildProfBranchWeightsMD() {
assert(SI.getNumSuccessors() == Weights->size() &&
"num of prof branch_weights must accord with num of successors");
bool AllZeroes = all_of(Weights.value(), [](uint32_t W) { return W == 0; });
bool AllZeroes = all_of(*Weights, [](uint32_t W) { return W == 0; });
if (AllZeroes || Weights.value().size() < 2)
if (AllZeroes || Weights->size() < 2)
return nullptr;
return MDBuilder(SI.getParent()->getContext()).createBranchWeights(*Weights);
@ -4618,8 +4618,8 @@ SwitchInstProfUpdateWrapper::removeCase(SwitchInst::CaseIt I) {
// Copy the last case to the place of the removed one and shrink.
// This is tightly coupled with the way SwitchInst::removeCase() removes
// the cases in SwitchInst::removeCase(CaseIt).
Weights.value()[I->getCaseIndex() + 1] = Weights.value().back();
Weights.value().pop_back();
(*Weights)[I->getCaseIndex() + 1] = Weights->back();
Weights->pop_back();
}
return SI.removeCase(I);
}
@ -4632,10 +4632,10 @@ void SwitchInstProfUpdateWrapper::addCase(
if (!Weights && W && *W) {
Changed = true;
Weights = SmallVector<uint32_t, 8>(SI.getNumSuccessors(), 0);
Weights.value()[SI.getNumSuccessors() - 1] = *W;
(*Weights)[SI.getNumSuccessors() - 1] = *W;
} else if (Weights) {
Changed = true;
Weights.value().push_back(W.value_or(0));
Weights->push_back(W.value_or(0));
}
if (Weights)
assert(SI.getNumSuccessors() == Weights->size() &&

View File

@ -301,13 +301,13 @@ ConstrainedFPIntrinsic::getExceptionBehavior() const {
bool ConstrainedFPIntrinsic::isDefaultFPEnvironment() const {
std::optional<fp::ExceptionBehavior> Except = getExceptionBehavior();
if (Except) {
if (Except.value() != fp::ebIgnore)
if (*Except != fp::ebIgnore)
return false;
}
std::optional<RoundingMode> Rounding = getRoundingMode();
if (Rounding) {
if (Rounding.value() != RoundingMode::NearestTiesToEven)
if (*Rounding != RoundingMode::NearestTiesToEven)
return false;
}
@ -444,13 +444,13 @@ MaybeAlign VPIntrinsic::getPointerAlignment() const {
std::optional<unsigned> PtrParamOpt =
getMemoryPointerParamPos(getIntrinsicID());
assert(PtrParamOpt && "no pointer argument!");
return getParamAlign(PtrParamOpt.value());
return getParamAlign(*PtrParamOpt);
}
/// \return The pointer operand of this load,store, gather or scatter.
Value *VPIntrinsic::getMemoryPointerParam() const {
if (auto PtrParamOpt = getMemoryPointerParamPos(getIntrinsicID()))
return getArgOperand(PtrParamOpt.value());
return getArgOperand(*PtrParamOpt);
return nullptr;
}
@ -472,7 +472,7 @@ Value *VPIntrinsic::getMemoryDataParam() const {
auto DataParamOpt = getMemoryDataParamPos(getIntrinsicID());
if (!DataParamOpt)
return nullptr;
return getArgOperand(DataParamOpt.value());
return getArgOperand(*DataParamOpt);
}
std::optional<unsigned> VPIntrinsic::getMemoryDataParamPos(Intrinsic::ID VPID) {

View File

@ -259,7 +259,7 @@ bool LLVMContextImpl::getOpaquePointers() {
}
void LLVMContextImpl::setOpaquePointers(bool OP) {
assert((!OpaquePointers || OpaquePointers.value() == OP) &&
assert((!OpaquePointers || *OpaquePointers == OP) &&
"Cannot change opaque pointers mode once set");
OpaquePointers = OP;
}

View File

@ -204,7 +204,7 @@ Error ifs::writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub) {
std::unique_ptr<IFSStubTriple> CopyStub(new IFSStubTriple(Stub));
if (Stub.Target.Arch) {
CopyStub->Target.ArchString =
std::string(ELF::convertEMachineToArchName(Stub.Target.Arch.value()));
std::string(ELF::convertEMachineToArchName(*Stub.Target.Arch));
}
IFSTarget Target = Stub.Target;
@ -224,35 +224,34 @@ Error ifs::overrideIFSTarget(
std::optional<std::string> OverrideTriple) {
std::error_code OverrideEC(1, std::generic_category());
if (OverrideArch) {
if (Stub.Target.Arch && Stub.Target.Arch.value() != OverrideArch.value()) {
if (Stub.Target.Arch && *Stub.Target.Arch != OverrideArch.value()) {
return make_error<StringError>(
"Supplied Arch conflicts with the text stub", OverrideEC);
}
Stub.Target.Arch = OverrideArch.value();
Stub.Target.Arch = *OverrideArch;
}
if (OverrideEndianness) {
if (Stub.Target.Endianness &&
Stub.Target.Endianness.value() != OverrideEndianness.value()) {
*Stub.Target.Endianness != OverrideEndianness.value()) {
return make_error<StringError>(
"Supplied Endianness conflicts with the text stub", OverrideEC);
}
Stub.Target.Endianness = OverrideEndianness.value();
Stub.Target.Endianness = *OverrideEndianness;
}
if (OverrideBitWidth) {
if (Stub.Target.BitWidth &&
Stub.Target.BitWidth.value() != OverrideBitWidth.value()) {
*Stub.Target.BitWidth != OverrideBitWidth.value()) {
return make_error<StringError>(
"Supplied BitWidth conflicts with the text stub", OverrideEC);
}
Stub.Target.BitWidth = OverrideBitWidth.value();
Stub.Target.BitWidth = *OverrideBitWidth;
}
if (OverrideTriple) {
if (Stub.Target.Triple &&
Stub.Target.Triple.value() != OverrideTriple.value()) {
if (Stub.Target.Triple && *Stub.Target.Triple != OverrideTriple.value()) {
return make_error<StringError>(
"Supplied Triple conflicts with the text stub", OverrideEC);
}
Stub.Target.Triple = OverrideTriple.value();
Stub.Target.Triple = *OverrideTriple;
}
return Error::success();
}

View File

@ -1449,7 +1449,7 @@ void MCAsmStreamer::emitAlignmentDirective(unsigned ByteAlignment,
if (Value.has_value() || MaxBytesToEmit) {
if (Value.has_value()) {
OS << ", 0x";
OS.write_hex(truncateToSize(Value.value(), ValueSize));
OS.write_hex(truncateToSize(*Value, ValueSize));
} else {
OS << ", ";
}
@ -1473,7 +1473,7 @@ void MCAsmStreamer::emitAlignmentDirective(unsigned ByteAlignment,
OS << ' ' << ByteAlignment;
if (Value.has_value())
OS << ", " << truncateToSize(Value.value(), ValueSize);
OS << ", " << truncateToSize(*Value, ValueSize);
else if (MaxBytesToEmit)
OS << ", ";
if (MaxBytesToEmit)

View File

@ -778,9 +778,8 @@ MCSectionXCOFF *MCContext::getXCOFFSection(
// Do the lookup. If we have a hit, return it.
auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
IsDwarfSec
? XCOFFSectionKey(Section.str(), DwarfSectionSubtypeFlags.value())
: XCOFFSectionKey(Section.str(), CsectProp->MappingClass),
IsDwarfSec ? XCOFFSectionKey(Section.str(), *DwarfSectionSubtypeFlags)
: XCOFFSectionKey(Section.str(), CsectProp->MappingClass),
nullptr));
auto &Entry = *IterBool.first;
if (!IterBool.second) {
@ -810,10 +809,9 @@ MCSectionXCOFF *MCContext::getXCOFFSection(
// CachedName contains invalid character(s) such as '$' for an XCOFF symbol.
MCSectionXCOFF *Result = nullptr;
if (IsDwarfSec)
Result = new (XCOFFAllocator.Allocate())
MCSectionXCOFF(QualName->getUnqualifiedName(), Kind, QualName,
DwarfSectionSubtypeFlags.value(), Begin, CachedName,
MultiSymbolsAllowed);
Result = new (XCOFFAllocator.Allocate()) MCSectionXCOFF(
QualName->getUnqualifiedName(), Kind, QualName,
*DwarfSectionSubtypeFlags, Begin, CachedName, MultiSymbolsAllowed);
else
Result = new (XCOFFAllocator.Allocate())
MCSectionXCOFF(QualName->getUnqualifiedName(), CsectProp->MappingClass,

View File

@ -93,8 +93,8 @@ bool XCOFFSymbolInfoTy::operator<(const XCOFFSymbolInfoTy &SymInfo) const {
return SymInfo.StorageMappingClass.has_value();
if (StorageMappingClass) {
return getSMCPriority(StorageMappingClass.value()) <
getSMCPriority(SymInfo.StorageMappingClass.value());
return getSMCPriority(*StorageMappingClass) <
getSMCPriority(*SymInfo.StorageMappingClass);
}
return false;

View File

@ -4233,8 +4233,7 @@ bool MasmParser::parseStructInitializer(const StructInfo &Structure,
size_t FieldIndex = 0;
if (EndToken) {
// Initialize all fields with given initializers.
while (getTok().isNot(EndToken.value()) &&
FieldIndex < Structure.Fields.size()) {
while (getTok().isNot(*EndToken) && FieldIndex < Structure.Fields.size()) {
const FieldInfo &Field = Structure.Fields[FieldIndex++];
if (parseOptionalToken(AsmToken::Comma)) {
// Empty initializer; use the default and continue. (Also, allow line
@ -4262,10 +4261,10 @@ bool MasmParser::parseStructInitializer(const StructInfo &Structure,
FieldInitializers.push_back(Field.Contents);
if (EndToken) {
if (EndToken.value() == AsmToken::Greater)
if (*EndToken == AsmToken::Greater)
return parseAngleBracketClose();
return parseToken(EndToken.value());
return parseToken(*EndToken);
}
return false;

View File

@ -97,10 +97,10 @@ MCSchedModel::getReciprocalThroughput(const MCSubtargetInfo &STI,
continue;
unsigned NumUnits = SM.getProcResource(I->ProcResourceIdx)->NumUnits;
double Temp = NumUnits * 1.0 / I->Cycles;
Throughput = Throughput ? std::min(Throughput.value(), Temp) : Temp;
Throughput = Throughput ? std::min(*Throughput, Temp) : Temp;
}
if (Throughput)
return 1.0 / Throughput.value();
return 1.0 / *Throughput;
// If no throughput value was calculated, assume that we can execute at the
// maximum issue width scaled by number of micro-ops for the schedule class.
@ -141,10 +141,10 @@ MCSchedModel::getReciprocalThroughput(unsigned SchedClass,
if (!I->getCycles())
continue;
double Temp = countPopulation(I->getUnits()) * 1.0 / I->getCycles();
Throughput = Throughput ? std::min(Throughput.value(), Temp) : Temp;
Throughput = Throughput ? std::min(*Throughput, Temp) : Temp;
}
if (Throughput)
return 1.0 / Throughput.value();
return 1.0 / *Throughput;
// If there are no execution resources specified for this class, then assume
// that it can execute at the maximum default issue width.

View File

@ -109,7 +109,7 @@ void MCSectionXCOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
// XCOFF debug sections.
if (getKind().isMetadata() && isDwarfSect()) {
OS << "\n\t.dwsect " << format("0x%" PRIx32, getDwarfSubtypeFlags().value())
OS << "\n\t.dwsect " << format("0x%" PRIx32, *getDwarfSubtypeFlags())
<< '\n';
OS << MAI.getPrivateLabelPrefix() << getName() << ':' << '\n';
return;

View File

@ -169,11 +169,11 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const {
std::optional<unsigned> Attr =
Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);
if (Attr)
isV7 = Attr.value() == ARMBuildAttrs::v7;
isV7 = *Attr == ARMBuildAttrs::v7;
Attr = Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch_profile);
if (Attr) {
switch (Attr.value()) {
switch (*Attr) {
case ARMBuildAttrs::ApplicationProfile:
Features.AddFeature("aclass");
break;
@ -192,7 +192,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const {
Attr = Attributes.getAttributeValue(ARMBuildAttrs::THUMB_ISA_use);
if (Attr) {
switch (Attr.value()) {
switch (*Attr) {
default:
break;
case ARMBuildAttrs::Not_Allowed:
@ -207,7 +207,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const {
Attr = Attributes.getAttributeValue(ARMBuildAttrs::FP_arch);
if (Attr) {
switch (Attr.value()) {
switch (*Attr) {
default:
break;
case ARMBuildAttrs::Not_Allowed:
@ -231,7 +231,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const {
Attr = Attributes.getAttributeValue(ARMBuildAttrs::Advanced_SIMD_arch);
if (Attr) {
switch (Attr.value()) {
switch (*Attr) {
default:
break;
case ARMBuildAttrs::Not_Allowed:
@ -250,7 +250,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const {
Attr = Attributes.getAttributeValue(ARMBuildAttrs::MVE_arch);
if (Attr) {
switch (Attr.value()) {
switch (*Attr) {
default:
break;
case ARMBuildAttrs::Not_Allowed:
@ -269,7 +269,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const {
Attr = Attributes.getAttributeValue(ARMBuildAttrs::DIV_use);
if (Attr) {
switch (Attr.value()) {
switch (*Attr) {
default:
break;
case ARMBuildAttrs::DisallowDIV:
@ -546,7 +546,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
std::optional<unsigned> Attr =
Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);
if (Attr) {
switch (Attr.value()) {
switch (*Attr) {
case ARMBuildAttrs::v4:
Triple += "v4";
break;
@ -578,7 +578,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
std::optional<unsigned> ArchProfileAttr =
Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch_profile);
if (ArchProfileAttr &&
ArchProfileAttr.value() == ARMBuildAttrs::MicroControllerProfile)
*ArchProfileAttr == ARMBuildAttrs::MicroControllerProfile)
Triple += "v7m";
else
Triple += "v7";

View File

@ -47,7 +47,7 @@ Process::FindInEnvPath(StringRef EnvName, StringRef FileName,
const char EnvPathSeparatorStr[] = {Separator, '\0'};
SmallVector<StringRef, 8> Dirs;
SplitString(OptPath.value(), Dirs, EnvPathSeparatorStr);
SplitString(*OptPath, Dirs, EnvPathSeparatorStr);
for (StringRef Dir : Dirs) {
if (Dir.empty())

View File

@ -2724,14 +2724,14 @@ void JSONWriter::write(ArrayRef<YAMLVFSEntry> Entries,
OS << "{\n"
" 'version': 0,\n";
if (IsCaseSensitive)
OS << " 'case-sensitive': '"
<< (IsCaseSensitive.value() ? "true" : "false") << "',\n";
OS << " 'case-sensitive': '" << (*IsCaseSensitive ? "true" : "false")
<< "',\n";
if (UseExternalNames)
OS << " 'use-external-names': '"
<< (UseExternalNames.value() ? "true" : "false") << "',\n";
OS << " 'use-external-names': '" << (*UseExternalNames ? "true" : "false")
<< "',\n";
bool UseOverlayRelative = false;
if (IsOverlayRelative) {
UseOverlayRelative = IsOverlayRelative.value();
UseOverlayRelative = *IsOverlayRelative;
OS << " 'overlay-relative': '" << (UseOverlayRelative ? "true" : "false")
<< "',\n";
}

View File

@ -428,7 +428,7 @@ raw_ostream &raw_ostream::operator<<(const FormattedBytes &FB) {
indent(FB.IndentLevel);
if (FB.FirstByteOffset) {
uint64_t Offset = FB.FirstByteOffset.value();
uint64_t Offset = *FB.FirstByteOffset;
llvm::write_hex(*this, Offset + LineIndex, HPS, OffsetWidth);
*this << ": ";
}

View File

@ -2695,7 +2695,7 @@ StringRef Record::getValueAsString(StringRef FieldName) const {
if (!S)
PrintFatalError(getLoc(), "Record `" + getName() +
"' does not have a field named `" + FieldName + "'!\n");
return S.value();
return *S;
}
std::optional<StringRef>

View File

@ -766,8 +766,8 @@ TEST_F(FileCheckTest, NumericVariable) {
ASSERT_TRUE(Value);
EXPECT_EQ(925, cantFail(Value->getSignedValue()));
// getStringValue should return the same memory not just the same characters.
EXPECT_EQ(StringValue.begin(), FooVar.getStringValue().value().begin());
EXPECT_EQ(StringValue.end(), FooVar.getStringValue().value().end());
EXPECT_EQ(StringValue.begin(), FooVar.getStringValue()->begin());
EXPECT_EQ(StringValue.end(), FooVar.getStringValue()->end());
EvalResult = FooVarUse.eval();
ASSERT_THAT_EXPECTED(EvalResult, Succeeded());
EXPECT_EQ(925, cantFail(EvalResult->getSignedValue()));

View File

@ -151,8 +151,8 @@ TEST(AlignmentTest, isAligned_isAddrAligned) {
MaybeAlign A(T.alignment);
// Test Align
if (A) {
EXPECT_EQ(isAligned(A.value(), T.offset), T.isAligned);
EXPECT_EQ(isAddrAligned(A.value(), T.forgedAddr()), T.isAligned);
EXPECT_EQ(isAligned(*A, T.offset), T.isAligned);
EXPECT_EQ(isAddrAligned(*A, T.forgedAddr()), T.isAligned);
}
}
}

View File

@ -369,27 +369,27 @@ TEST(KnownBitsTest, ICmpExhaustive) {
EXPECT_EQ(AllSLT || NoneSLT, KnownSLT.has_value());
EXPECT_EQ(AllSLE || NoneSLE, KnownSLE.has_value());
EXPECT_EQ(AllEQ, KnownEQ.has_value() && KnownEQ.value());
EXPECT_EQ(AllNE, KnownNE.has_value() && KnownNE.value());
EXPECT_EQ(AllUGT, KnownUGT.has_value() && KnownUGT.value());
EXPECT_EQ(AllUGE, KnownUGE.has_value() && KnownUGE.value());
EXPECT_EQ(AllULT, KnownULT.has_value() && KnownULT.value());
EXPECT_EQ(AllULE, KnownULE.has_value() && KnownULE.value());
EXPECT_EQ(AllSGT, KnownSGT.has_value() && KnownSGT.value());
EXPECT_EQ(AllSGE, KnownSGE.has_value() && KnownSGE.value());
EXPECT_EQ(AllSLT, KnownSLT.has_value() && KnownSLT.value());
EXPECT_EQ(AllSLE, KnownSLE.has_value() && KnownSLE.value());
EXPECT_EQ(AllEQ, KnownEQ.has_value() && *KnownEQ);
EXPECT_EQ(AllNE, KnownNE.has_value() && *KnownNE);
EXPECT_EQ(AllUGT, KnownUGT.has_value() && *KnownUGT);
EXPECT_EQ(AllUGE, KnownUGE.has_value() && *KnownUGE);
EXPECT_EQ(AllULT, KnownULT.has_value() && *KnownULT);
EXPECT_EQ(AllULE, KnownULE.has_value() && *KnownULE);
EXPECT_EQ(AllSGT, KnownSGT.has_value() && *KnownSGT);
EXPECT_EQ(AllSGE, KnownSGE.has_value() && *KnownSGE);
EXPECT_EQ(AllSLT, KnownSLT.has_value() && *KnownSLT);
EXPECT_EQ(AllSLE, KnownSLE.has_value() && *KnownSLE);
EXPECT_EQ(NoneEQ, KnownEQ.has_value() && !KnownEQ.value());
EXPECT_EQ(NoneNE, KnownNE.has_value() && !KnownNE.value());
EXPECT_EQ(NoneUGT, KnownUGT.has_value() && !KnownUGT.value());
EXPECT_EQ(NoneUGE, KnownUGE.has_value() && !KnownUGE.value());
EXPECT_EQ(NoneULT, KnownULT.has_value() && !KnownULT.value());
EXPECT_EQ(NoneULE, KnownULE.has_value() && !KnownULE.value());
EXPECT_EQ(NoneSGT, KnownSGT.has_value() && !KnownSGT.value());
EXPECT_EQ(NoneSGE, KnownSGE.has_value() && !KnownSGE.value());
EXPECT_EQ(NoneSLT, KnownSLT.has_value() && !KnownSLT.value());
EXPECT_EQ(NoneSLE, KnownSLE.has_value() && !KnownSLE.value());
EXPECT_EQ(NoneEQ, KnownEQ.has_value() && !*KnownEQ);
EXPECT_EQ(NoneNE, KnownNE.has_value() && !*KnownNE);
EXPECT_EQ(NoneUGT, KnownUGT.has_value() && !*KnownUGT);
EXPECT_EQ(NoneUGE, KnownUGE.has_value() && !*KnownUGE);
EXPECT_EQ(NoneULT, KnownULT.has_value() && !*KnownULT);
EXPECT_EQ(NoneULE, KnownULE.has_value() && !*KnownULE);
EXPECT_EQ(NoneSGT, KnownSGT.has_value() && !*KnownSGT);
EXPECT_EQ(NoneSGE, KnownSGE.has_value() && !*KnownSGE);
EXPECT_EQ(NoneSLT, KnownSLT.has_value() && !*KnownSLT);
EXPECT_EQ(NoneSLE, KnownSLE.has_value() && !*KnownSLE);
});
});
}

View File

@ -2976,7 +2976,7 @@ public:
<< MatchTable::IntValue(RendererID);
if (SubOperand)
Table << MatchTable::Comment("SubOperand")
<< MatchTable::IntValue(SubOperand.value());
<< MatchTable::IntValue(*SubOperand);
Table << MatchTable::Comment(SymbolicName) << MatchTable::LineBreak;
}
};
@ -4995,7 +4995,7 @@ Error GlobalISelEmitter::importDefaultOperandRenderers(
auto Def = DefaultDefOp->getDef();
if (Def->getName() == "undef_tied_input") {
unsigned TempRegID = M.allocateTempRegID();
M.insertAction<MakeTempRegisterAction>(InsertPt, OpTyOrNone.value(),
M.insertAction<MakeTempRegisterAction>(InsertPt, *OpTyOrNone,
TempRegID);
InsertPt = M.insertAction<BuildMIAction>(
InsertPt, M.allocateOutputInsnID(),