[llvm] e4e3ff5 - [llvm] Use std::optional::value_or (NFC) (#109568)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 22 01:00:28 PDT 2024
Author: Kazu Hirata
Date: 2024-09-22T01:00:24-07:00
New Revision: e4e3ff5adc8b374be0620223ea2b654adde038ea
URL: https://github.com/llvm/llvm-project/commit/e4e3ff5adc8b374be0620223ea2b654adde038ea
DIFF: https://github.com/llvm/llvm-project/commit/e4e3ff5adc8b374be0620223ea2b654adde038ea.diff
LOG: [llvm] Use std::optional::value_or (NFC) (#109568)
Added:
Modified:
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/lib/CGData/OutlinedHashTree.cpp
llvm/lib/CGData/OutlinedHashTreeRecord.cpp
llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
llvm/lib/ObjCopy/wasm/WasmWriter.cpp
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/lib/ObjectYAML/GOFFEmitter.cpp
llvm/lib/ObjectYAML/WasmEmitter.cpp
llvm/lib/ObjectYAML/XCOFFEmitter.cpp
llvm/lib/ProfileData/PGOCtxProfWriter.cpp
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index c592bc8f6ba2a1..79c8bafbc6c0df 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -858,7 +858,7 @@ class TargetTransformInfoImplBase {
unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
Align SrcAlign, Align DestAlign,
std::optional<uint32_t> AtomicCpySize) const {
- unsigned OpSizeInBytes = AtomicCpySize ? *AtomicCpySize : 1;
+ unsigned OpSizeInBytes = AtomicCpySize.value_or(1);
Type *OpType = Type::getIntNTy(Context, OpSizeInBytes * 8);
for (unsigned i = 0; i != RemainingBytes; i += OpSizeInBytes)
OpsOut.push_back(OpType);
diff --git a/llvm/lib/CGData/OutlinedHashTree.cpp b/llvm/lib/CGData/OutlinedHashTree.cpp
index 7bf8168e5afa17..7ddab66ae41f3d 100644
--- a/llvm/lib/CGData/OutlinedHashTree.cpp
+++ b/llvm/lib/CGData/OutlinedHashTree.cpp
@@ -84,7 +84,7 @@ void OutlinedHashTree::insert(const HashSequencePair &SequencePair) {
Current = I->second.get();
}
if (Count)
- Current->Terminals = (Current->Terminals ? *Current->Terminals : 0) + Count;
+ Current->Terminals = Current->Terminals.value_or(0) + Count;
}
void OutlinedHashTree::merge(const OutlinedHashTree *Tree) {
@@ -98,8 +98,7 @@ void OutlinedHashTree::merge(const OutlinedHashTree *Tree) {
if (!SrcNode)
continue;
if (SrcNode->Terminals)
- DstNode->Terminals =
- (DstNode->Terminals ? *DstNode->Terminals : 0) + *SrcNode->Terminals;
+ DstNode->Terminals = DstNode->Terminals.value_or(0) + *SrcNode->Terminals;
for (auto &[Hash, NextSrcNode] : SrcNode->Successors) {
HashNode *NextDstNode;
auto I = DstNode->Successors.find(Hash);
diff --git a/llvm/lib/CGData/OutlinedHashTreeRecord.cpp b/llvm/lib/CGData/OutlinedHashTreeRecord.cpp
index d1d57fe3fc9f4c..cc760634d7fae1 100644
--- a/llvm/lib/CGData/OutlinedHashTreeRecord.cpp
+++ b/llvm/lib/CGData/OutlinedHashTreeRecord.cpp
@@ -130,7 +130,7 @@ void OutlinedHashTreeRecord::convertToStableData(
auto Id = P.second;
HashNodeStable NodeStable;
NodeStable.Hash = Node->Hash;
- NodeStable.Terminals = Node->Terminals ? *Node->Terminals : 0;
+ NodeStable.Terminals = Node->Terminals.value_or(0);
for (auto &P : Node->Successors)
NodeStable.SuccessorIds.push_back(NodeIdMap[P.second.get()]);
IdNodeStableMap[Id] = NodeStable;
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
index 4daf781a2b53fa..b7a980cb7f068f 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
@@ -1171,8 +1171,7 @@ void CompileUnit::cloneDieAttrExpression(
// Argument of DW_OP_addrx should be relocated here as it is not
// processed by applyValidRelocs.
OutputExpression.push_back(dwarf::DW_OP_addr);
- uint64_t LinkedAddress =
- SA->Address + (VarAddressAdjustment ? *VarAddressAdjustment : 0);
+ uint64_t LinkedAddress = SA->Address + VarAddressAdjustment.value_or(0);
if (getEndianness() != llvm::endianness::native)
sys::swapByteOrder(LinkedAddress);
ArrayRef<uint8_t> AddressBytes(
@@ -1209,7 +1208,7 @@ void CompileUnit::cloneDieAttrExpression(
if (OutOperandKind) {
OutputExpression.push_back(*OutOperandKind);
uint64_t LinkedAddress =
- SA->Address + (VarAddressAdjustment ? *VarAddressAdjustment : 0);
+ SA->Address + VarAddressAdjustment.value_or(0);
if (getEndianness() != llvm::endianness::native)
sys::swapByteOrder(LinkedAddress);
ArrayRef<uint8_t> AddressBytes(
diff --git a/llvm/lib/ObjCopy/wasm/WasmWriter.cpp b/llvm/lib/ObjCopy/wasm/WasmWriter.cpp
index bfab25ce8097a5..ad4d2ef2ad930a 100644
--- a/llvm/lib/ObjCopy/wasm/WasmWriter.cpp
+++ b/llvm/lib/ObjCopy/wasm/WasmWriter.cpp
@@ -32,8 +32,7 @@ Writer::SectionHeader Writer::createSectionHeader(const Section &S,
// If we read this section from an object file, use its original size for the
// padding of the LEB value to avoid changing the file size. Otherwise, pad
// out to 5 bytes to make it predictable, and match the behavior of clang.
- unsigned HeaderSecSizeEncodingLen =
- S.HeaderSecSizeEncodingLen ? *S.HeaderSecSizeEncodingLen : 5;
+ unsigned HeaderSecSizeEncodingLen = S.HeaderSecSizeEncodingLen.value_or(5);
encodeULEB128(SectionSize, OS, HeaderSecSizeEncodingLen);
if (HasName) {
encodeULEB128(S.Name.size(), OS);
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 79ddee43dd352f..fc234581a45a70 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -966,7 +966,7 @@ ELFState<ELFT>::toELFSymbols(ArrayRef<ELFYAML::Symbol> Symbols,
Symbol.st_shndx = *Sym.Index;
Symbol.st_value = Sym.Value.value_or(yaml::Hex64(0));
- Symbol.st_other = Sym.Other ? *Sym.Other : 0;
+ Symbol.st_other = Sym.Other.value_or(0);
Symbol.st_size = Sym.Size.value_or(yaml::Hex64(0));
}
diff --git a/llvm/lib/ObjectYAML/GOFFEmitter.cpp b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
index 345904407e1d24..c5bf4cc4fa5521 100644
--- a/llvm/lib/ObjectYAML/GOFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
@@ -237,11 +237,9 @@ void GOFFState::writeHeader(GOFFYAML::FileHeader &FileHdr) {
if (ModPropLen) {
GW << binaryBe(ModPropLen) << zeros(6);
if (ModPropLen >= 2)
- GW << binaryBe(FileHdr.InternalCCSID ? *FileHdr.InternalCCSID : 0);
+ GW << binaryBe(FileHdr.InternalCCSID.value_or(0));
if (ModPropLen >= 3)
- GW << binaryBe(FileHdr.TargetSoftwareEnvironment
- ? *FileHdr.TargetSoftwareEnvironment
- : 0);
+ GW << binaryBe(FileHdr.TargetSoftwareEnvironment.value_or(0));
}
}
diff --git a/llvm/lib/ObjectYAML/WasmEmitter.cpp b/llvm/lib/ObjectYAML/WasmEmitter.cpp
index 4f384928b89f1d..817d364694b43a 100644
--- a/llvm/lib/ObjectYAML/WasmEmitter.cpp
+++ b/llvm/lib/ObjectYAML/WasmEmitter.cpp
@@ -648,7 +648,7 @@ bool WasmWriter::writeWasm(raw_ostream &OS) {
StringStream.flush();
unsigned HeaderSecSizeEncodingLen =
- Sec->HeaderSecSizeEncodingLen ? *Sec->HeaderSecSizeEncodingLen : 5;
+ Sec->HeaderSecSizeEncodingLen.value_or(5);
unsigned RequiredLen = getULEB128Size(OutString.size());
// Wasm spec does not allow LEBs larger than 5 bytes
assert(RequiredLen <= 5);
diff --git a/llvm/lib/ObjectYAML/XCOFFEmitter.cpp b/llvm/lib/ObjectYAML/XCOFFEmitter.cpp
index 0f03d3c48a3177..e0df8f6399f547 100644
--- a/llvm/lib/ObjectYAML/XCOFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/XCOFFEmitter.cpp
@@ -794,7 +794,7 @@ bool XCOFFWriter::writeSymbols() {
}
W.write<int16_t>(SectionIndexMap[*YamlSym.SectionName]);
} else {
- W.write<int16_t>(YamlSym.SectionIndex ? *YamlSym.SectionIndex : 0);
+ W.write<int16_t>(YamlSym.SectionIndex.value_or(0));
}
W.write<uint16_t>(YamlSym.Type);
W.write<uint8_t>(YamlSym.StorageClass);
diff --git a/llvm/lib/ProfileData/PGOCtxProfWriter.cpp b/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
index 99b5b2b3d05811..4c0f3d459988b1 100644
--- a/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
+++ b/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
@@ -47,7 +47,7 @@ PGOCtxProfileWriter::PGOCtxProfileWriter(
}
Writer.ExitBlock();
Writer.EnterSubblock(PGOCtxProfileBlockIDs::ProfileMetadataBlockID, CodeLen);
- const auto Version = VersionOverride ? *VersionOverride : CurrentVersion;
+ const auto Version = VersionOverride.value_or(CurrentVersion);
Writer.EmitRecord(PGOCtxProfileRecords::Version,
SmallVector<unsigned, 1>({Version}));
}
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 728e421b7f89e3..f21c091bceea29 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -5870,8 +5870,7 @@ bool AMDGPUAsmParser::ParseDirectiveAMDHSAKernel() {
return TokError("amdgpu_user_sgpr_count smaller than than implied by "
"enabled user SGPRs");
- unsigned UserSGPRCount =
- ExplicitUserSGPRCount ? *ExplicitUserSGPRCount : ImpliedUserSGPRCount;
+ unsigned UserSGPRCount = ExplicitUserSGPRCount.value_or(ImpliedUserSGPRCount);
if (!isUInt<COMPUTE_PGM_RSRC2_USER_SGPR_COUNT_WIDTH>(UserSGPRCount))
return TokError("too many user SGPRs enabled");
diff --git a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
index 5e713842ff674a..35ef2675610c13 100644
--- a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
@@ -493,7 +493,7 @@ void HexagonSubtarget::adjustSchedDependency(
break;
}
}
- Dep.setLatency(DLatency ? *DLatency : 0);
+ Dep.setLatency(DLatency.value_or(0));
}
// Try to schedule uses near definitions to generate .cur.
More information about the llvm-commits
mailing list