Skip to content

Commit e4e3ff5

Browse files
[llvm] Use std::optional::value_or (NFC) (#109568)
1 parent 59b7461 commit e4e3ff5

File tree

12 files changed

+15
-21
lines changed

12 files changed

+15
-21
lines changed

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ class TargetTransformInfoImplBase {
858858
unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
859859
Align SrcAlign, Align DestAlign,
860860
std::optional<uint32_t> AtomicCpySize) const {
861-
unsigned OpSizeInBytes = AtomicCpySize ? *AtomicCpySize : 1;
861+
unsigned OpSizeInBytes = AtomicCpySize.value_or(1);
862862
Type *OpType = Type::getIntNTy(Context, OpSizeInBytes * 8);
863863
for (unsigned i = 0; i != RemainingBytes; i += OpSizeInBytes)
864864
OpsOut.push_back(OpType);

llvm/lib/CGData/OutlinedHashTree.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void OutlinedHashTree::insert(const HashSequencePair &SequencePair) {
8484
Current = I->second.get();
8585
}
8686
if (Count)
87-
Current->Terminals = (Current->Terminals ? *Current->Terminals : 0) + Count;
87+
Current->Terminals = Current->Terminals.value_or(0) + Count;
8888
}
8989

9090
void OutlinedHashTree::merge(const OutlinedHashTree *Tree) {
@@ -98,8 +98,7 @@ void OutlinedHashTree::merge(const OutlinedHashTree *Tree) {
9898
if (!SrcNode)
9999
continue;
100100
if (SrcNode->Terminals)
101-
DstNode->Terminals =
102-
(DstNode->Terminals ? *DstNode->Terminals : 0) + *SrcNode->Terminals;
101+
DstNode->Terminals = DstNode->Terminals.value_or(0) + *SrcNode->Terminals;
103102
for (auto &[Hash, NextSrcNode] : SrcNode->Successors) {
104103
HashNode *NextDstNode;
105104
auto I = DstNode->Successors.find(Hash);

llvm/lib/CGData/OutlinedHashTreeRecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void OutlinedHashTreeRecord::convertToStableData(
130130
auto Id = P.second;
131131
HashNodeStable NodeStable;
132132
NodeStable.Hash = Node->Hash;
133-
NodeStable.Terminals = Node->Terminals ? *Node->Terminals : 0;
133+
NodeStable.Terminals = Node->Terminals.value_or(0);
134134
for (auto &P : Node->Successors)
135135
NodeStable.SuccessorIds.push_back(NodeIdMap[P.second.get()]);
136136
IdNodeStableMap[Id] = NodeStable;

llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,7 @@ void CompileUnit::cloneDieAttrExpression(
11711171
// Argument of DW_OP_addrx should be relocated here as it is not
11721172
// processed by applyValidRelocs.
11731173
OutputExpression.push_back(dwarf::DW_OP_addr);
1174-
uint64_t LinkedAddress =
1175-
SA->Address + (VarAddressAdjustment ? *VarAddressAdjustment : 0);
1174+
uint64_t LinkedAddress = SA->Address + VarAddressAdjustment.value_or(0);
11761175
if (getEndianness() != llvm::endianness::native)
11771176
sys::swapByteOrder(LinkedAddress);
11781177
ArrayRef<uint8_t> AddressBytes(
@@ -1209,7 +1208,7 @@ void CompileUnit::cloneDieAttrExpression(
12091208
if (OutOperandKind) {
12101209
OutputExpression.push_back(*OutOperandKind);
12111210
uint64_t LinkedAddress =
1212-
SA->Address + (VarAddressAdjustment ? *VarAddressAdjustment : 0);
1211+
SA->Address + VarAddressAdjustment.value_or(0);
12131212
if (getEndianness() != llvm::endianness::native)
12141213
sys::swapByteOrder(LinkedAddress);
12151214
ArrayRef<uint8_t> AddressBytes(

llvm/lib/ObjCopy/wasm/WasmWriter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ Writer::SectionHeader Writer::createSectionHeader(const Section &S,
3232
// If we read this section from an object file, use its original size for the
3333
// padding of the LEB value to avoid changing the file size. Otherwise, pad
3434
// out to 5 bytes to make it predictable, and match the behavior of clang.
35-
unsigned HeaderSecSizeEncodingLen =
36-
S.HeaderSecSizeEncodingLen ? *S.HeaderSecSizeEncodingLen : 5;
35+
unsigned HeaderSecSizeEncodingLen = S.HeaderSecSizeEncodingLen.value_or(5);
3736
encodeULEB128(SectionSize, OS, HeaderSecSizeEncodingLen);
3837
if (HasName) {
3938
encodeULEB128(S.Name.size(), OS);

llvm/lib/ObjectYAML/ELFEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ ELFState<ELFT>::toELFSymbols(ArrayRef<ELFYAML::Symbol> Symbols,
966966
Symbol.st_shndx = *Sym.Index;
967967

968968
Symbol.st_value = Sym.Value.value_or(yaml::Hex64(0));
969-
Symbol.st_other = Sym.Other ? *Sym.Other : 0;
969+
Symbol.st_other = Sym.Other.value_or(0);
970970
Symbol.st_size = Sym.Size.value_or(yaml::Hex64(0));
971971
}
972972

llvm/lib/ObjectYAML/GOFFEmitter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,9 @@ void GOFFState::writeHeader(GOFFYAML::FileHeader &FileHdr) {
237237
if (ModPropLen) {
238238
GW << binaryBe(ModPropLen) << zeros(6);
239239
if (ModPropLen >= 2)
240-
GW << binaryBe(FileHdr.InternalCCSID ? *FileHdr.InternalCCSID : 0);
240+
GW << binaryBe(FileHdr.InternalCCSID.value_or(0));
241241
if (ModPropLen >= 3)
242-
GW << binaryBe(FileHdr.TargetSoftwareEnvironment
243-
? *FileHdr.TargetSoftwareEnvironment
244-
: 0);
242+
GW << binaryBe(FileHdr.TargetSoftwareEnvironment.value_or(0));
245243
}
246244
}
247245

llvm/lib/ObjectYAML/WasmEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ bool WasmWriter::writeWasm(raw_ostream &OS) {
648648
StringStream.flush();
649649

650650
unsigned HeaderSecSizeEncodingLen =
651-
Sec->HeaderSecSizeEncodingLen ? *Sec->HeaderSecSizeEncodingLen : 5;
651+
Sec->HeaderSecSizeEncodingLen.value_or(5);
652652
unsigned RequiredLen = getULEB128Size(OutString.size());
653653
// Wasm spec does not allow LEBs larger than 5 bytes
654654
assert(RequiredLen <= 5);

llvm/lib/ObjectYAML/XCOFFEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ bool XCOFFWriter::writeSymbols() {
794794
}
795795
W.write<int16_t>(SectionIndexMap[*YamlSym.SectionName]);
796796
} else {
797-
W.write<int16_t>(YamlSym.SectionIndex ? *YamlSym.SectionIndex : 0);
797+
W.write<int16_t>(YamlSym.SectionIndex.value_or(0));
798798
}
799799
W.write<uint16_t>(YamlSym.Type);
800800
W.write<uint8_t>(YamlSym.StorageClass);

llvm/lib/ProfileData/PGOCtxProfWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ PGOCtxProfileWriter::PGOCtxProfileWriter(
4747
}
4848
Writer.ExitBlock();
4949
Writer.EnterSubblock(PGOCtxProfileBlockIDs::ProfileMetadataBlockID, CodeLen);
50-
const auto Version = VersionOverride ? *VersionOverride : CurrentVersion;
50+
const auto Version = VersionOverride.value_or(CurrentVersion);
5151
Writer.EmitRecord(PGOCtxProfileRecords::Version,
5252
SmallVector<unsigned, 1>({Version}));
5353
}

llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5870,8 +5870,7 @@ bool AMDGPUAsmParser::ParseDirectiveAMDHSAKernel() {
58705870
return TokError("amdgpu_user_sgpr_count smaller than than implied by "
58715871
"enabled user SGPRs");
58725872

5873-
unsigned UserSGPRCount =
5874-
ExplicitUserSGPRCount ? *ExplicitUserSGPRCount : ImpliedUserSGPRCount;
5873+
unsigned UserSGPRCount = ExplicitUserSGPRCount.value_or(ImpliedUserSGPRCount);
58755874

58765875
if (!isUInt<COMPUTE_PGM_RSRC2_USER_SGPR_COUNT_WIDTH>(UserSGPRCount))
58775876
return TokError("too many user SGPRs enabled");

llvm/lib/Target/Hexagon/HexagonSubtarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ void HexagonSubtarget::adjustSchedDependency(
493493
break;
494494
}
495495
}
496-
Dep.setLatency(DLatency ? *DLatency : 0);
496+
Dep.setLatency(DLatency.value_or(0));
497497
}
498498

499499
// Try to schedule uses near definitions to generate .cur.

0 commit comments

Comments
 (0)