From e9cffafdf71771af6c5af38f4901e69753c923f8 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 22 Apr 2016 04:28:05 +0000 Subject: [PATCH] Refactor IRObjectFile, extract a static CollectAsmUndefinedRefs() method to parse inline assembly (NFC) I plan to call this from ThinLTOCodeGenerator. From: Mehdi Amini llvm-svn: 267103 --- llvm/include/llvm/Object/IRObjectFile.h | 10 ++++++++++ llvm/lib/Object/IRObjectFile.cpp | 19 +++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/Object/IRObjectFile.h b/llvm/include/llvm/Object/IRObjectFile.h index ef65528..453c0f5 100644 --- a/llvm/include/llvm/Object/IRObjectFile.h +++ b/llvm/include/llvm/Object/IRObjectFile.h @@ -59,6 +59,16 @@ public: /// error code if not found. static ErrorOr 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 & + 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. diff --git a/llvm/lib/Object/IRObjectFile.cpp b/llvm/lib/Object/IRObjectFile.cpp index a4b97ef..8184e04 100644 --- a/llvm/lib/Object/IRObjectFile.cpp +++ b/llvm/lib/Object/IRObjectFile.cpp @@ -38,12 +38,24 @@ using namespace object; IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr 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(Name, Flags)); + }); +} + +// 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 & + AsmUndefinedRefs) { - const std::string &InlineAsm = M->getModuleInlineAsm(); + 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 Mod) Res |= BasicSymbolRef::SF_Global; break; } - AsmSymbols.push_back( - std::make_pair(Key, std::move(Res))); + AsmUndefinedRefs(Key, BasicSymbolRef::Flags(Res)); } } -- 2.7.4