[lld] Use value_or instead of getValueOr (NFC)

This commit is contained in:
Kazu Hirata 2022-06-19 00:29:41 -07:00
parent 97c87c6f7c
commit 757d9d22cd
9 changed files with 26 additions and 27 deletions

View File

@ -1295,7 +1295,7 @@ const Defined *LinkerScript::assignAddresses() {
if (script->hasSectionsCommand) {
// With a linker script, assignment of addresses to headers is covered by
// allocateHeaders().
dot = config->imageBase.getValueOr(0);
dot = config->imageBase.value_or(0);
} else {
// Assign addresses to headers right now.
dot = target->getImageBase();
@ -1331,7 +1331,7 @@ SmallVector<PhdrEntry *, 0> LinkerScript::createPhdrs() {
// Process PHDRS and FILEHDR keywords because they are not
// real output sections and cannot be added in the following loop.
for (const PhdrsCommand &cmd : phdrsCommands) {
PhdrEntry *phdr = make<PhdrEntry>(cmd.type, cmd.flags.getValueOr(PF_R));
PhdrEntry *phdr = make<PhdrEntry>(cmd.type, cmd.flags.value_or(PF_R));
if (cmd.hasFilehdr)
phdr->add(Out::elfHeader);

View File

@ -43,8 +43,8 @@ struct PlatformInfo {
inline uint32_t encodeVersion(const llvm::VersionTuple &version) {
return ((version.getMajor() << 020) |
(version.getMinor().getValueOr(0) << 010) |
version.getSubminor().getValueOr(0));
(version.getMinor().value_or(0) << 010) |
version.getSubminor().value_or(0));
}
enum class NamespaceKind {

View File

@ -581,7 +581,7 @@ createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) {
static InputGlobal *createGlobal(StringRef name, bool isMutable) {
llvm::wasm::WasmGlobal wasmGlobal;
bool is64 = config->is64.getValueOr(false);
bool is64 = config->is64.value_or(false);
wasmGlobal.Type = {uint8_t(is64 ? WASM_TYPE_I64 : WASM_TYPE_I32), isMutable};
wasmGlobal.InitExpr = intConst(0, is64);
wasmGlobal.SymbolName = name;
@ -616,11 +616,11 @@ static void createSyntheticSymbols() {
"__wasm_call_ctors", WASM_SYMBOL_VISIBILITY_HIDDEN,
make<SyntheticFunction>(nullSignature, "__wasm_call_ctors"));
bool is64 = config->is64.getValueOr(false);
bool is64 = config->is64.value_or(false);
if (config->isPic) {
WasmSym::stackPointer =
createUndefinedGlobal("__stack_pointer", config->is64.getValueOr(false)
createUndefinedGlobal("__stack_pointer", config->is64.value_or(false)
? &mutableGlobalTypeI64
: &mutableGlobalTypeI32);
// For PIC code, we import two global variables (__memory_base and
@ -672,7 +672,7 @@ static void createOptionalSymbols() {
WasmSym::heapBase = symtab->addOptionalDataSymbol("__heap_base");
WasmSym::definedMemoryBase = symtab->addOptionalDataSymbol("__memory_base");
WasmSym::definedTableBase = symtab->addOptionalDataSymbol("__table_base");
if (config->is64.getValueOr(false))
if (config->is64.value_or(false))
WasmSym::definedTableBase32 =
symtab->addOptionalDataSymbol("__table_base32");
}

View File

@ -364,7 +364,7 @@ void InputChunk::generateRelocationCode(raw_ostream &os) const {
LLVM_DEBUG(dbgs() << "generating runtime relocations: " << name
<< " count=" << relocations.size() << "\n");
bool is64 = config->is64.getValueOr(false);
bool is64 = config->is64.value_or(false);
unsigned opcode_ptr_const = is64 ? WASM_OPCODE_I64_CONST
: WASM_OPCODE_I32_CONST;
unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD

View File

@ -64,7 +64,7 @@ public:
const WasmInitExpr &getInitExpr() const { return initExpr; }
void setPointerValue(uint64_t value) {
initExpr = intConst(value, config->is64.getValueOr(false));
initExpr = intConst(value, config->is64.value_or(false));
}
private:

View File

@ -47,7 +47,7 @@ void InputFile::checkArch(Triple::ArchType arch) const {
if (is64 && !config->is64.hasValue()) {
fatal(toString(this) +
": must specify -mwasm64 to process wasm64 object files");
} else if (config->is64.getValueOr(false) != is64) {
} else if (config->is64.value_or(false) != is64) {
fatal(toString(this) +
": wasm32 object file can't be linked in wasm64 mode");
}

View File

@ -115,7 +115,7 @@ void DataSection::finalizeContents() {
writeUleb128(os, segmentCount, "data segment count");
os.flush();
bodySize = dataSectionHeader.size();
bool is64 = config->is64.getValueOr(false);
bool is64 = config->is64.value_or(false);
for (OutputSegment *segment : segments) {
if (!segment->requiredInBinary())

View File

@ -124,8 +124,8 @@ void DylinkSection::writeBody() {
for (const Symbol *sym : importInfo) {
LLVM_DEBUG(llvm::dbgs() << "imports info: " << toString(*sym) << "\n");
StringRef module = sym->importModule.getValueOr(defaultModule);
StringRef name = sym->importName.getValueOr(sym->getName());
StringRef module = sym->importModule.value_or(defaultModule);
StringRef name = sym->importName.value_or(sym->getName());
writeStr(sub.os, module, "import module");
writeStr(sub.os, name, "import name");
writeUleb128(sub.os, sym->flags, "sym flags");
@ -184,8 +184,8 @@ void ImportSection::addGOTEntry(Symbol *sym) {
void ImportSection::addImport(Symbol *sym) {
assert(!isSealed);
StringRef module = sym->importModule.getValueOr(defaultModule);
StringRef name = sym->importName.getValueOr(sym->getName());
StringRef module = sym->importModule.value_or(defaultModule);
StringRef name = sym->importName.value_or(sym->getName());
if (auto *f = dyn_cast<FunctionSymbol>(sym)) {
ImportKey<WasmSignature> key(*(f->getSignature()), module, name);
auto entry = importedFunctions.try_emplace(key, numImportedFunctions);
@ -232,7 +232,7 @@ void ImportSection::writeBody() {
writeUleb128(os, getNumImports(), "import count");
bool is64 = config->is64.getValueOr(false);
bool is64 = config->is64.value_or(false);
if (config->importMemory) {
WasmImport import;
@ -254,8 +254,8 @@ void ImportSection::writeBody() {
for (const Symbol *sym : importedSymbols) {
WasmImport import;
import.Field = sym->importName.getValueOr(sym->getName());
import.Module = sym->importModule.getValueOr(defaultModule);
import.Field = sym->importName.value_or(sym->getName());
import.Module = sym->importModule.value_or(defaultModule);
if (auto *functionSym = dyn_cast<FunctionSymbol>(sym)) {
import.Kind = WASM_EXTERNAL_FUNCTION;
@ -357,7 +357,7 @@ void MemorySection::writeBody() {
flags |= WASM_LIMITS_FLAG_HAS_MAX;
if (config->sharedMemory)
flags |= WASM_LIMITS_FLAG_IS_SHARED;
if (config->is64.getValueOr(false))
if (config->is64.value_or(false))
flags |= WASM_LIMITS_FLAG_IS_64;
writeUleb128(os, flags, "memory limits flags");
writeUleb128(os, numMemoryPages, "initial pages");
@ -415,7 +415,7 @@ void GlobalSection::addInternalGOTEntry(Symbol *sym) {
void GlobalSection::generateRelocationCode(raw_ostream &os, bool TLS) const {
assert(!config->extendedConst);
bool is64 = config->is64.getValueOr(false);
bool is64 = config->is64.value_or(false);
unsigned opcode_ptr_const = is64 ? WASM_OPCODE_I64_CONST
: WASM_OPCODE_I32_CONST;
unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD
@ -465,7 +465,7 @@ void GlobalSection::writeBody() {
writeGlobalType(os, g->getType());
writeInitExpr(os, g->getInitExpr());
}
bool is64 = config->is64.getValueOr(false);
bool is64 = config->is64.value_or(false);
uint8_t itype = is64 ? WASM_TYPE_I64 : WASM_TYPE_I32;
for (const Symbol *sym : internalGotSymbols) {
bool mutable_ = false;
@ -569,8 +569,8 @@ void ElemSection::writeBody() {
if (config->isPic) {
initExpr.Inst.Opcode = WASM_OPCODE_GLOBAL_GET;
initExpr.Inst.Value.Global =
(config->is64.getValueOr(false) ? WasmSym::tableBase32
: WasmSym::tableBase)
(config->is64.value_or(false) ? WasmSym::tableBase32
: WasmSym::tableBase)
->getGlobalIndex();
} else {
initExpr.Inst.Opcode = WASM_OPCODE_I32_CONST;

View File

@ -328,8 +328,7 @@ void Writer::layoutMemory() {
WasmSym::heapBase->setVA(memoryPtr);
}
uint64_t maxMemorySetting = 1ULL
<< (config->is64.getValueOr(false) ? 48 : 32);
uint64_t maxMemorySetting = 1ULL << (config->is64.value_or(false) ? 48 : 32);
if (config->initialMemory != 0) {
if (config->initialMemory != alignTo(config->initialMemory, WasmPageSize))
@ -1057,7 +1056,7 @@ void Writer::createInitMemoryFunction() {
assert(WasmSym::initMemoryFlag);
flagAddress = WasmSym::initMemoryFlag->getVA();
}
bool is64 = config->is64.getValueOr(false);
bool is64 = config->is64.value_or(false);
std::string bodyContent;
{
raw_string_ostream os(bodyContent);