Skip to content

Commit a7938c7

Browse files
[llvm] Don't use Optional::hasValue (NFC)
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
1 parent 77295c5 commit a7938c7

File tree

84 files changed

+249
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+249
-260
lines changed

llvm/include/llvm/Analysis/VectorUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class VFDatabase {
236236
// ensuring that the variant described in the attribute has a
237237
// corresponding definition or declaration of the vector
238238
// function in the Module M.
239-
if (Shape.hasValue() && (Shape.getValue().ScalarName == ScalarName)) {
239+
if (Shape && (Shape.getValue().ScalarName == ScalarName)) {
240240
assert(CI.getModule()->getFunction(Shape.getValue().VectorName) &&
241241
"Vector function is missing.");
242242
Mappings.push_back(Shape.getValue());

llvm/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ bool InstructionSelector::executeMatchTable(
674674
ComplexRendererFns Renderer =
675675
(ISel.*ISelInfo.ComplexPredicates[ComplexPredicateID])(
676676
State.MIs[InsnID]->getOperand(OpIdx));
677-
if (Renderer.hasValue())
677+
if (Renderer)
678678
State.Renderers[RendererID] = Renderer.getValue();
679679
else
680680
if (handleReject() == RejectAndGiveUp)

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,11 +1168,11 @@ class IRBuilderBase {
11681168
Value *getConstrainedFPRounding(Optional<RoundingMode> Rounding) {
11691169
RoundingMode UseRounding = DefaultConstrainedRounding;
11701170

1171-
if (Rounding.hasValue())
1171+
if (Rounding)
11721172
UseRounding = Rounding.getValue();
11731173

11741174
Optional<StringRef> RoundingStr = convertRoundingModeToStr(UseRounding);
1175-
assert(RoundingStr.hasValue() && "Garbage strict rounding mode!");
1175+
assert(RoundingStr && "Garbage strict rounding mode!");
11761176
auto *RoundingMDS = MDString::get(Context, RoundingStr.getValue());
11771177

11781178
return MetadataAsValue::get(Context, RoundingMDS);
@@ -1181,11 +1181,11 @@ class IRBuilderBase {
11811181
Value *getConstrainedFPExcept(Optional<fp::ExceptionBehavior> Except) {
11821182
fp::ExceptionBehavior UseExcept = DefaultConstrainedExcept;
11831183

1184-
if (Except.hasValue())
1184+
if (Except)
11851185
UseExcept = Except.getValue();
11861186

11871187
Optional<StringRef> ExceptStr = convertExceptionBehaviorToStr(UseExcept);
1188-
assert(ExceptStr.hasValue() && "Garbage strict exception behavior!");
1188+
assert(ExceptStr && "Garbage strict exception behavior!");
11891189
auto *ExceptMDS = MDString::get(Context, ExceptStr.getValue());
11901190

11911191
return MetadataAsValue::get(Context, ExceptMDS);

llvm/include/llvm/MC/MCSymbolWasm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class MCSymbolWasm : public MCSymbol {
8888

8989
bool hasImportModule() const { return ImportModule.hasValue(); }
9090
StringRef getImportModule() const {
91-
if (ImportModule.hasValue())
91+
if (ImportModule)
9292
return ImportModule.getValue();
9393
// Use a default module name of "env" for now, for compatibility with
9494
// existing tools.
@@ -100,7 +100,7 @@ class MCSymbolWasm : public MCSymbol {
100100

101101
bool hasImportName() const { return ImportName.hasValue(); }
102102
StringRef getImportName() const {
103-
if (ImportName.hasValue())
103+
if (ImportName)
104104
return ImportName.getValue();
105105
return getName();
106106
}
@@ -129,7 +129,7 @@ class MCSymbolWasm : public MCSymbol {
129129
void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
130130

131131
const wasm::WasmGlobalType &getGlobalType() const {
132-
assert(GlobalType.hasValue());
132+
assert(GlobalType);
133133
return GlobalType.getValue();
134134
}
135135
void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }

llvm/include/llvm/MC/MCSymbolXCOFF.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ class MCSymbolXCOFF : public MCSymbol {
3939
};
4040

4141
XCOFF::StorageClass getStorageClass() const {
42-
assert(StorageClass.hasValue() &&
43-
"StorageClass not set on XCOFF MCSymbol.");
42+
assert(StorageClass && "StorageClass not set on XCOFF MCSymbol.");
4443
return StorageClass.getValue();
4544
}
4645

llvm/include/llvm/Support/Error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ class FileError final : public ErrorInfo<FileError> {
12691269
void log(raw_ostream &OS) const override {
12701270
assert(Err && "Trying to log after takeError().");
12711271
OS << "'" << FileName << "': ";
1272-
if (Line.hasValue())
1272+
if (Line)
12731273
OS << "line " << Line.getValue() << ": ";
12741274
Err->log(OS);
12751275
}

llvm/include/llvm/Support/YAMLTraits.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,14 +1668,13 @@ template <typename T, typename Context>
16681668
void IO::processKeyWithDefault(const char *Key, Optional<T> &Val,
16691669
const Optional<T> &DefaultValue, bool Required,
16701670
Context &Ctx) {
1671-
assert(DefaultValue.hasValue() == false &&
1672-
"Optional<T> shouldn't have a value!");
1671+
assert(!DefaultValue && "Optional<T> shouldn't have a value!");
16731672
void *SaveInfo;
16741673
bool UseDefault = true;
16751674
const bool sameAsDefault = outputting() && !Val.hasValue();
1676-
if (!outputting() && !Val.hasValue())
1675+
if (!outputting() && !Val)
16771676
Val = T();
1678-
if (Val.hasValue() &&
1677+
if (Val &&
16791678
this->preflightKey(Key, Required, sameAsDefault, UseDefault, SaveInfo)) {
16801679

16811680
// When reading an Optional<X> key from a YAML description, we allow the

llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,14 +831,14 @@ CFLAndersAAResult::ensureCached(const Function &Fn) {
831831
scan(Fn);
832832
Iter = Cache.find(&Fn);
833833
assert(Iter != Cache.end());
834-
assert(Iter->second.hasValue());
834+
assert(Iter->second);
835835
}
836836
return Iter->second;
837837
}
838838

839839
const AliasSummary *CFLAndersAAResult::getAliasSummary(const Function &Fn) {
840840
auto &FunInfo = ensureCached(Fn);
841-
if (FunInfo.hasValue())
841+
if (FunInfo)
842842
return &FunInfo->getAliasSummary();
843843
else
844844
return nullptr;

llvm/lib/Analysis/CFLSteensAliasAnalysis.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ CFLSteensAAResult::ensureCached(Function *Fn) {
250250
scan(Fn);
251251
Iter = Cache.find(Fn);
252252
assert(Iter != Cache.end());
253-
assert(Iter->second.hasValue());
253+
assert(Iter->second);
254254
}
255255
return Iter->second;
256256
}
257257

258258
const AliasSummary *CFLSteensAAResult::getAliasSummary(Function &Fn) {
259259
auto &FunInfo = ensureCached(&Fn);
260-
if (FunInfo.hasValue())
260+
if (FunInfo)
261261
return &FunInfo->getAliasSummary();
262262
else
263263
return nullptr;
@@ -293,15 +293,15 @@ AliasResult CFLSteensAAResult::query(const MemoryLocation &LocA,
293293

294294
assert(Fn != nullptr);
295295
auto &MaybeInfo = ensureCached(Fn);
296-
assert(MaybeInfo.hasValue());
296+
assert(MaybeInfo);
297297

298298
auto &Sets = MaybeInfo->getStratifiedSets();
299299
auto MaybeA = Sets.find(InstantiatedValue{ValA, 0});
300-
if (!MaybeA.hasValue())
300+
if (!MaybeA)
301301
return AliasResult::MayAlias;
302302

303303
auto MaybeB = Sets.find(InstantiatedValue{ValB, 0});
304-
if (!MaybeB.hasValue())
304+
if (!MaybeB)
305305
return AliasResult::MayAlias;
306306

307307
auto SetA = *MaybeA;

llvm/lib/Analysis/IRSimilarityIdentifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ CmpInst::Predicate IRInstructionData::getPredicate() const {
183183
assert(isa<CmpInst>(Inst) &&
184184
"Can only get a predicate from a compare instruction");
185185

186-
if (RevisedPredicate.hasValue())
186+
if (RevisedPredicate)
187187
return RevisedPredicate.getValue();
188188

189189
return cast<CmpInst>(Inst)->getPredicate();

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
703703
BlockFrequencyInfo *BFI = &(GetBFI(F));
704704
assert(BFI && "BFI must be available");
705705
auto ProfileCount = BFI->getBlockProfileCount(BB);
706-
assert(ProfileCount.hasValue());
706+
assert(ProfileCount);
707707
if (ProfileCount.getValue() == 0)
708708
ColdSize += Cost - CostAtBBStart;
709709
}
@@ -828,14 +828,14 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
828828
}
829829

830830
auto ProfileCount = CalleeBFI->getBlockProfileCount(&BB);
831-
assert(ProfileCount.hasValue());
831+
assert(ProfileCount);
832832
CurrentSavings *= ProfileCount.getValue();
833833
CycleSavings += CurrentSavings;
834834
}
835835

836836
// Compute the cycle savings per call.
837837
auto EntryProfileCount = F.getEntryCount();
838-
assert(EntryProfileCount.hasValue() && EntryProfileCount->getCount());
838+
assert(EntryProfileCount && EntryProfileCount->getCount());
839839
auto EntryCount = EntryProfileCount->getCount();
840840
CycleSavings += EntryCount / 2;
841841
CycleSavings = CycleSavings.udiv(EntryCount);

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueCast(
918918
// transfer rule on the full set since we may be able to locally infer
919919
// interesting facts.
920920
Optional<ConstantRange> LHSRes = getRangeFor(CI->getOperand(0), CI, BB);
921-
if (!LHSRes.hasValue())
921+
if (!LHSRes)
922922
// More work to do before applying this transfer rule.
923923
return None;
924924
const ConstantRange &LHSRange = LHSRes.getValue();

llvm/lib/Analysis/LoopCacheAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ bool CacheCost::populateReferenceGroups(ReferenceGroupsTy &RefGroups) const {
645645
Optional<bool> HasSpacialReuse =
646646
R->hasSpacialReuse(Representative, CLS, AA);
647647

648-
if ((HasTemporalReuse.hasValue() && *HasTemporalReuse) ||
649-
(HasSpacialReuse.hasValue() && *HasSpacialReuse)) {
648+
if ((HasTemporalReuse && *HasTemporalReuse) ||
649+
(HasSpacialReuse && *HasSpacialReuse)) {
650650
RefGroup.push_back(std::move(R));
651651
Added = true;
652652
break;

llvm/lib/Analysis/MemoryBuiltins.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,18 +501,18 @@ Optional<StringRef> llvm::getAllocationFamily(const Value *I,
501501
if (!TLI || !TLI->getLibFunc(*Callee, TLIFn) || !TLI->has(TLIFn))
502502
return None;
503503
const auto AllocData = getAllocationDataForFunction(Callee, AnyAlloc, TLI);
504-
if (AllocData.hasValue())
504+
if (AllocData)
505505
return mangledNameForMallocFamily(AllocData.getValue().Family);
506506
const auto FreeData = getFreeFunctionDataForFunction(Callee, TLIFn);
507-
if (FreeData.hasValue())
507+
if (FreeData)
508508
return mangledNameForMallocFamily(FreeData.getValue().Family);
509509
return None;
510510
}
511511

512512
/// isLibFreeFunction - Returns true if the function is a builtin free()
513513
bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
514514
Optional<FreeFnsTy> FnData = getFreeFunctionDataForFunction(F, TLIFn);
515-
if (!FnData.hasValue())
515+
if (!FnData)
516516
return false;
517517

518518
// Check free prototype.

llvm/lib/Analysis/MemorySSA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ template <class AliasAnalysisType> class ClobberWalker {
751751
bool operator==(const generic_def_path_iterator &O) const {
752752
if (N.hasValue() != O.N.hasValue())
753753
return false;
754-
return !N.hasValue() || *N == *O.N;
754+
return !N || *N == *O.N;
755755
}
756756

757757
private:

llvm/lib/Analysis/MustExecute.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ template <typename K, typename V, typename FnTy, typename... ArgsTy>
491491
static V getOrCreateCachedOptional(K Key, DenseMap<K, Optional<V>> &Map,
492492
FnTy &&Fn, ArgsTy&&... args) {
493493
Optional<V> &OptVal = Map[Key];
494-
if (!OptVal.hasValue())
494+
if (!OptVal)
495495
OptVal = Fn(std::forward<ArgsTy>(args)...);
496496
return OptVal.getValue();
497497
}

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,15 +4847,15 @@ class SCEVBackedgeConditionFolder
48474847
SelectInst *SI = cast<SelectInst>(I);
48484848
Optional<const SCEV *> Res =
48494849
compareWithBackedgeCondition(SI->getCondition());
4850-
if (Res.hasValue()) {
4850+
if (Res) {
48514851
bool IsOne = cast<SCEVConstant>(Res.getValue())->getValue()->isOne();
48524852
Result = SE.getSCEV(IsOne ? SI->getTrueValue() : SI->getFalseValue());
48534853
}
48544854
break;
48554855
}
48564856
default: {
48574857
Optional<const SCEV *> Res = compareWithBackedgeCondition(I);
4858-
if (Res.hasValue())
4858+
if (Res)
48594859
Result = Res.getValue();
48604860
break;
48614861
}
@@ -6596,7 +6596,7 @@ ScalarEvolution::getRangeRef(const SCEV *S,
65966596

65976597
// Check if the IR explicitly contains !range metadata.
65986598
Optional<ConstantRange> MDRange = GetRangeFromMetadata(U->getValue());
6599-
if (MDRange.hasValue())
6599+
if (MDRange)
66006600
ConservativeResult = ConservativeResult.intersectWith(MDRange.getValue(),
66016601
RangeType);
66026602

@@ -9710,15 +9710,15 @@ GetQuadraticEquation(const SCEVAddRecExpr *AddRec) {
97109710
/// (b) if neither X nor Y exist, return None,
97119711
/// (c) if exactly one of X and Y exists, return that value.
97129712
static Optional<APInt> MinOptional(Optional<APInt> X, Optional<APInt> Y) {
9713-
if (X.hasValue() && Y.hasValue()) {
9713+
if (X && Y) {
97149714
unsigned W = std::max(X->getBitWidth(), Y->getBitWidth());
97159715
APInt XW = X->sext(W);
97169716
APInt YW = Y->sext(W);
97179717
return XW.slt(YW) ? *X : *Y;
97189718
}
9719-
if (!X.hasValue() && !Y.hasValue())
9719+
if (!X && !Y)
97209720
return None;
9721-
return X.hasValue() ? *X : *Y;
9721+
return X ? *X : *Y;
97229722
}
97239723

97249724
/// Helper function to truncate an optional APInt to a given BitWidth.
@@ -9760,13 +9760,13 @@ SolveQuadraticAddRecExact(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) {
97609760
APInt A, B, C, M;
97619761
unsigned BitWidth;
97629762
auto T = GetQuadraticEquation(AddRec);
9763-
if (!T.hasValue())
9763+
if (!T)
97649764
return None;
97659765

97669766
std::tie(A, B, C, M, BitWidth) = *T;
97679767
LLVM_DEBUG(dbgs() << __func__ << ": solving for unsigned overflow\n");
97689768
Optional<APInt> X = APIntOps::SolveQuadraticEquationWrap(A, B, C, BitWidth+1);
9769-
if (!X.hasValue())
9769+
if (!X)
97709770
return None;
97719771

97729772
ConstantInt *CX = ConstantInt::get(SE.getContext(), *X);
@@ -10471,7 +10471,7 @@ ScalarEvolution::getMonotonicPredicateType(const SCEVAddRecExpr *LHS,
1047110471
auto ResultSwapped =
1047210472
getMonotonicPredicateTypeImpl(LHS, ICmpInst::getSwappedPredicate(Pred));
1047310473

10474-
assert(ResultSwapped.hasValue() && "should be able to analyze both!");
10474+
assert(ResultSwapped && "should be able to analyze both!");
1047510475
assert(ResultSwapped.getValue() != Result.getValue() &&
1047610476
"monotonicity should flip as we flip the predicate");
1047710477
}

llvm/lib/Analysis/StratifiedSets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ template <typename T> class StratifiedSetsBuilder {
343343
bool has(const T &Elem) const { return get(Elem).hasValue(); }
344344

345345
bool add(const T &Main) {
346-
if (get(Main).hasValue())
346+
if (get(Main))
347347
return false;
348348

349349
auto NewIndex = getNewUnlinkedIndex();

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ void VFABI::getVectorVariantNames(
15011501
#ifndef NDEBUG
15021502
LLVM_DEBUG(dbgs() << "VFABI: adding mapping '" << S << "'\n");
15031503
Optional<VFInfo> Info = VFABI::tryDemangleForVFABI(S, *(CI.getModule()));
1504-
assert(Info.hasValue() && "Invalid name for a VFABI variant.");
1504+
assert(Info && "Invalid name for a VFABI variant.");
15051505
assert(CI.getModule()->getFunction(Info.getValue().VectorName) &&
15061506
"Vector function is missing.");
15071507
#endif

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ bool CombinerHelper::matchCombineConstantFoldFpUnary(MachineInstr &MI,
12961296

12971297
void CombinerHelper::applyCombineConstantFoldFpUnary(MachineInstr &MI,
12981298
Optional<APFloat> &Cst) {
1299-
assert(Cst.hasValue() && "Optional is unexpectedly empty!");
1299+
assert(Cst && "Optional is unexpectedly empty!");
13001300
Builder.setInstrAndDebugLoc(MI);
13011301
MachineFunction &MF = Builder.getMF();
13021302
auto *FPVal = ConstantFP::get(MF.getFunction().getContext(), *Cst);

llvm/lib/CodeGen/MIRParser/MIParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ bool MIParser::parseBasicBlockDefinition(
741741
MBB->setIsEHPad(IsLandingPad);
742742
MBB->setIsInlineAsmBrIndirectTarget(IsInlineAsmBrIndirectTarget);
743743
MBB->setIsEHFuncletEntry(IsEHFuncletEntry);
744-
if (SectionID.hasValue()) {
744+
if (SectionID) {
745745
MBB->setSectionID(SectionID.getValue());
746746
MF.setBBSectionsType(BasicBlockSection::List);
747747
}

llvm/lib/CodeGen/MachineFunctionSplitter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ bool MachineFunctionSplitter::runOnMachineFunction(MachineFunction &MF) {
106106
// We don't want to proceed further for cold functions
107107
// or functions of unknown hotness. Lukewarm functions have no prefix.
108108
Optional<StringRef> SectionPrefix = MF.getFunction().getSectionPrefix();
109-
if (SectionPrefix.hasValue() &&
110-
(SectionPrefix.getValue().equals("unlikely") ||
111-
SectionPrefix.getValue().equals("unknown"))) {
109+
if (SectionPrefix && (SectionPrefix.getValue().equals("unlikely") ||
110+
SectionPrefix.getValue().equals("unknown"))) {
112111
return false;
113112
}
114113

0 commit comments

Comments
 (0)