LTO: Replace InputFile::Symbol::getFlags() with predicate accessors. NFC.

This makes the predicates independent of the flag representation
and makes the code a little easier to read.

llvm-svn: 298951
This commit is contained in:
Peter Collingbourne 2017-03-28 22:31:35 +00:00
parent 9747d8070b
commit 0d56b959ad
7 changed files with 24 additions and 25 deletions

View File

@ -343,14 +343,12 @@ void BitcodeFile::parse() {
MB.getBuffer(), Saver.save(ParentName + MB.getBufferIdentifier()))));
for (const lto::InputFile::Symbol &ObjSym : Obj->symbols()) {
StringRef SymName = Saver.save(ObjSym.getName());
auto Flags = ObjSym.getFlags();
Symbol *Sym;
if (Flags & object::BasicSymbolRef::SF_Undefined) {
if (ObjSym.isUndefined()) {
Sym = Symtab->addUndefined(SymName, this, false);
} else if (Flags & object::BasicSymbolRef::SF_Common) {
} else if (ObjSym.isCommon()) {
Sym = Symtab->addCommon(this, SymName, ObjSym.getCommonSize());
} else if ((Flags & object::BasicSymbolRef::SF_Weak) &&
(Flags & object::BasicSymbolRef::SF_Indirect)) {
} else if (ObjSym.isWeak() && ObjSym.isIndirect()) {
// Weak external.
Sym = Symtab->addUndefined(SymName, this, true);
std::string Fallback = ObjSym.getCOFFWeakExternalFallback();

View File

@ -105,9 +105,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
// flags an undefined in IR with a definition in ASM as prevailing.
// Once IRObjectFile is fixed to report only one symbol this hack can
// be removed.
R.Prevailing =
!(ObjSym.getFlags() & object::BasicSymbolRef::SF_Undefined) &&
B->getFile() == &F;
R.Prevailing = !ObjSym.isUndefined() && B->getFile() == &F;
R.VisibleToRegularObj = Sym->IsUsedInRegularObj;
if (R.Prevailing)
undefine(Sym);

View File

@ -792,8 +792,7 @@ static Symbol *createBitcodeSymbol(const std::vector<bool> &KeptComdats,
const lto::InputFile::Symbol &ObjSym,
BitcodeFile *F) {
StringRef NameRef = Saver.save(ObjSym.getName());
uint32_t Flags = ObjSym.getFlags();
uint32_t Binding = (Flags & BasicSymbolRef::SF_Weak) ? STB_WEAK : STB_GLOBAL;
uint32_t Binding = ObjSym.isWeak() ? STB_WEAK : STB_GLOBAL;
uint8_t Type = ObjSym.isTLS() ? STT_TLS : STT_NOTYPE;
uint8_t Visibility = mapVisibility(ObjSym.getVisibility());
@ -805,12 +804,12 @@ static Symbol *createBitcodeSymbol(const std::vector<bool> &KeptComdats,
Visibility, Type, CanOmitFromDynSym,
F);
if (Flags & BasicSymbolRef::SF_Undefined)
if (ObjSym.isUndefined())
return Symtab<ELFT>::X->addUndefined(NameRef, /*IsLocal=*/false, Binding,
Visibility, Type, CanOmitFromDynSym,
F);
if (Flags & BasicSymbolRef::SF_Common)
if (ObjSym.isCommon())
return Symtab<ELFT>::X->addCommon(NameRef, ObjSym.getCommonSize(),
ObjSym.getCommonAlignment(), Binding,
Visibility, STT_OBJECT, F);
@ -956,7 +955,7 @@ std::vector<StringRef> LazyObjectFile::getBitcodeSymbols() {
std::unique_ptr<lto::InputFile> Obj = check(lto::InputFile::create(this->MB));
std::vector<StringRef> V;
for (const lto::InputFile::Symbol &Sym : Obj->symbols())
if (!(Sym.getFlags() & BasicSymbolRef::SF_Undefined))
if (!Sym.isUndefined())
V.push_back(Saver.save(Sym.getName()));
return V;
}

View File

@ -125,9 +125,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
// flags an undefined in IR with a definition in ASM as prevailing.
// Once IRObjectFile is fixed to report only one symbol this hack can
// be removed.
R.Prevailing =
!(ObjSym.getFlags() & object::BasicSymbolRef::SF_Undefined) &&
B->File == &F;
R.Prevailing = !ObjSym.isUndefined() && B->File == &F;
R.VisibleToRegularObj =
Sym->IsUsedInRegularObj || (R.Prevailing && Sym->includeInDynsym());

View File

@ -152,6 +152,15 @@ public:
skip();
}
bool isUndefined() const {
return Flags & object::BasicSymbolRef::SF_Undefined;
}
bool isCommon() const { return Flags & object::BasicSymbolRef::SF_Common; }
bool isWeak() const { return Flags & object::BasicSymbolRef::SF_Weak; }
bool isIndirect() const {
return Flags & object::BasicSymbolRef::SF_Indirect;
}
/// For COFF weak externals, returns the name of the symbol that is used
/// as a fallback if the weak external remains undefined.
std::string getCOFFWeakExternalFallback() const {
@ -171,7 +180,6 @@ public:
/// Returns the mangled name of the global.
StringRef getName() const { return Name; }
uint32_t getFlags() const { return Flags; }
GlobalValue::VisibilityTypes getVisibility() const {
if (isGV())
return getGV()->getVisibility();

View File

@ -575,7 +575,7 @@ Error LTO::addRegularLTO(BitcodeModule BM, const SymbolResolution *&ResI,
if (Sym.isGV()) {
GlobalValue *GV = Sym.getGV();
if (Res.Prevailing) {
if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined)
if (Sym.isUndefined())
continue;
Keep.push_back(GV);
switch (GV->getLinkage()) {
@ -608,7 +608,7 @@ Error LTO::addRegularLTO(BitcodeModule BM, const SymbolResolution *&ResI,
// Common resolution: collect the maximum size/alignment over all commons.
// We also record if we see an instance of a common as prevailing, so that
// if none is prevailing we can ignore it later.
if (Sym.getFlags() & object::BasicSymbolRef::SF_Common) {
if (Sym.isCommon()) {
// FIXME: We should figure out what to do about commons defined by asm.
// For now they aren't reported correctly by ModuleSymbolTable.
auto &CommonRes = RegularLTO.Commons[Sym.getGV()->getName()];

View File

@ -496,8 +496,6 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
sys::path::filename(Obj->getSourceFileName()).str();
for (auto &Sym : Obj->symbols()) {
uint32_t Symflags = Sym.getFlags();
cf.syms.push_back(ld_plugin_symbol());
ld_plugin_symbol &sym = cf.syms.back();
sym.version = nullptr;
@ -523,13 +521,13 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
break;
}
if (Symflags & object::BasicSymbolRef::SF_Undefined) {
if (Sym.isUndefined()) {
sym.def = LDPK_UNDEF;
if (Symflags & object::BasicSymbolRef::SF_Weak)
if (Sym.isWeak())
sym.def = LDPK_WEAKUNDEF;
} else if (Symflags & object::BasicSymbolRef::SF_Common)
} else if (Sym.isCommon())
sym.def = LDPK_COMMON;
else if (Symflags & object::BasicSymbolRef::SF_Weak)
else if (Sym.isWeak())
sym.def = LDPK_WEAKDEF;
else
sym.def = LDPK_DEF;