Refactor IRObjectFile, extract a static CollectAsmUndefinedRefs() method to parse inline assembly (NFC)

I plan to call this from ThinLTOCodeGenerator.

From: Mehdi Amini <mehdi.amini@apple.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267103 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mehdi Amini 2016-04-22 04:28:05 +00:00
parent 3441786e27
commit 90c7bb067d
2 changed files with 25 additions and 4 deletions

View File

@ -59,6 +59,16 @@ public:
/// error code if not found.
static ErrorOr<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
/// Parse inline ASM and collect the symbols that are not defined in
/// the current module.
///
/// For each found symbol, call \p AsmUndefinedRefs with the name of the
/// symbol found and the associated flags.
static void CollectAsmUndefinedRefs(
Module &TheModule,
const std::function<void(StringRef, BasicSymbolRef::Flags)> &
AsmUndefinedRefs);
/// \brief Finds and returns bitcode in the given memory buffer (which may
/// be either a bitcode file or a native object file with embedded bitcode),
/// or an error code if not found.

View File

@ -38,12 +38,24 @@ using namespace object;
IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod)
: SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) {
Mang.reset(new Mangler());
CollectAsmUndefinedRefs(*M, [this](StringRef Name,
BasicSymbolRef::Flags Flags) {
AsmSymbols.push_back(std::make_pair<std::string, uint32_t>(Name, Flags));
});
}
const std::string &InlineAsm = M->getModuleInlineAsm();
// Parse inline ASM and collect the list of symbols that are not defined in
// the current module. This is inspired from IRObjectFile.
void IRObjectFile::CollectAsmUndefinedRefs(
Module &TheModule,
const std::function<void(StringRef, BasicSymbolRef::Flags)> &
AsmUndefinedRefs) {
const std::string &InlineAsm = TheModule.getModuleInlineAsm();
if (InlineAsm.empty())
return;
Triple TT(M->getTargetTriple());
Triple TT(TheModule.getTargetTriple());
std::string Err;
const Target *T = TargetRegistry::lookupTarget(TT.str(), Err);
if (!T)
@ -106,8 +118,7 @@ IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod)
Res |= BasicSymbolRef::SF_Global;
break;
}
AsmSymbols.push_back(
std::make_pair<std::string, uint32_t>(Key, std::move(Res)));
AsmUndefinedRefs(Key, BasicSymbolRef::Flags(Res));
}
}