Skip to content

[llvm] Use std::optional::value_or (NFC) #109568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/CGData/OutlinedHashTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CGData/OutlinedHashTreeRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/ObjCopy/wasm/WasmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ObjectYAML/ELFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/ObjectYAML/GOFFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ObjectYAML/WasmEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ObjectYAML/XCOFFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ProfileData/PGOCtxProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}));
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading