aboutsummaryrefslogtreecommitdiffstats
path: root/lib/LTO
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-12-01 14:51:49 -0800
committerStephen Hines <srhines@google.com>2014-12-02 16:08:10 -0800
commit37ed9c199ca639565f6ce88105f9e39e898d82d0 (patch)
tree8fb36d3910e3ee4c4e1b7422f4f017108efc52f5 /lib/LTO
parentd2327b22152ced7bc46dc629fc908959e8a52d03 (diff)
downloadexternal_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.zip
external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.gz
external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.bz2
Update aosp/master LLVM for rebase to r222494.
Change-Id: Ic787f5e0124df789bd26f3f24680f45e678eef2d
Diffstat (limited to 'lib/LTO')
-rw-r--r--lib/LTO/LLVMBuild.txt2
-rw-r--r--lib/LTO/LTOCodeGenerator.cpp113
-rw-r--r--lib/LTO/LTOModule.cpp233
3 files changed, 189 insertions, 159 deletions
diff --git a/lib/LTO/LLVMBuild.txt b/lib/LTO/LLVMBuild.txt
index 29ed92c..b9178e9 100644
--- a/lib/LTO/LLVMBuild.txt
+++ b/lib/LTO/LLVMBuild.txt
@@ -19,4 +19,4 @@
type = Library
name = LTO
parent = Libraries
-required_libraries = BitReader BitWriter Core IPA IPO InstCombine Linker MC MCParser ObjCARC Object Scalar Support Target TransformUtils
+required_libraries = BitReader BitWriter Core IPA IPO InstCombine Linker MC ObjCARC Object Scalar Support Target TransformUtils CodeGen
diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp
index 335197a..c663d43 100644
--- a/lib/LTO/LTOCodeGenerator.cpp
+++ b/lib/LTO/LTOCodeGenerator.cpp
@@ -48,6 +48,7 @@
#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegisterInfo.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/ObjCARC.h"
@@ -63,18 +64,30 @@ const char* LTOCodeGenerator::getVersionString() {
}
LTOCodeGenerator::LTOCodeGenerator()
- : Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context)),
- TargetMach(nullptr), EmitDwarfDebugInfo(false),
- ScopeRestrictionsDone(false), CodeModel(LTO_CODEGEN_PIC_MODEL_DEFAULT),
- NativeObjectFile(nullptr), DiagHandler(nullptr), DiagContext(nullptr) {
+ : Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context)) {
+ initialize();
+}
+
+LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr<LLVMContext> Context)
+ : OwnedContext(std::move(Context)), Context(*OwnedContext),
+ IRLinker(new Module("ld-temp.o", *OwnedContext)) {
+ initialize();
+}
+
+void LTOCodeGenerator::initialize() {
+ TargetMach = nullptr;
+ EmitDwarfDebugInfo = false;
+ ScopeRestrictionsDone = false;
+ CodeModel = LTO_CODEGEN_PIC_MODEL_DEFAULT;
+ DiagHandler = nullptr;
+ DiagContext = nullptr;
+
initializeLTOPasses();
}
LTOCodeGenerator::~LTOCodeGenerator() {
delete TargetMach;
- delete NativeObjectFile;
TargetMach = nullptr;
- NativeObjectFile = nullptr;
IRLinker.deleteModule();
@@ -107,14 +120,18 @@ void LTOCodeGenerator::initializeLTOPasses() {
initializeFunctionAttrsPass(R);
initializeGlobalsModRefPass(R);
initializeLICMPass(R);
+ initializeMergedLoadStoreMotionPass(R);
initializeGVNPass(R);
initializeMemCpyOptPass(R);
initializeDCEPass(R);
initializeCFGSimplifyPassPass(R);
}
-bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) {
- bool ret = IRLinker.linkInModule(&mod->getModule(), &errMsg);
+bool LTOCodeGenerator::addModule(LTOModule *mod) {
+ assert(&mod->getModule().getContext() == &Context &&
+ "Expected module in same context");
+
+ bool ret = IRLinker.linkInModule(&mod->getModule());
const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs();
for (int i = 0, e = undefs.size(); i != e; ++i)
@@ -161,9 +178,9 @@ bool LTOCodeGenerator::writeMergedModules(const char *path,
applyScopeRestrictions();
// create output file
- std::string ErrInfo;
- tool_output_file Out(path, ErrInfo, sys::fs::F_None);
- if (!ErrInfo.empty()) {
+ std::error_code EC;
+ tool_output_file Out(path, EC, sys::fs::F_None);
+ if (EC) {
errMsg = "could not open bitcode file for writing: ";
errMsg += path;
return false;
@@ -188,6 +205,7 @@ bool LTOCodeGenerator::compile_to_file(const char** name,
bool disableOpt,
bool disableInline,
bool disableGVNLoadPRE,
+ bool disableVectorization,
std::string& errMsg) {
// make unique temp .o file to put generated object file
SmallString<128> Filename;
@@ -202,8 +220,9 @@ bool LTOCodeGenerator::compile_to_file(const char** name,
// generate object file
tool_output_file objFile(Filename.c_str(), FD);
- bool genResult = generateObjectFile(objFile.os(), disableOpt, disableInline,
- disableGVNLoadPRE, errMsg);
+ bool genResult =
+ generateObjectFile(objFile.os(), disableOpt, disableInline,
+ disableGVNLoadPRE, disableVectorization, errMsg);
objFile.os().close();
if (objFile.os().has_error()) {
objFile.os().clear_error();
@@ -226,15 +245,13 @@ const void* LTOCodeGenerator::compile(size_t* length,
bool disableOpt,
bool disableInline,
bool disableGVNLoadPRE,
+ bool disableVectorization,
std::string& errMsg) {
const char *name;
if (!compile_to_file(&name, disableOpt, disableInline, disableGVNLoadPRE,
- errMsg))
+ disableVectorization, errMsg))
return nullptr;
- // remove old buffer if compile() called twice
- delete NativeObjectFile;
-
// read .o file into memory buffer
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getFile(name, -1, false);
@@ -243,7 +260,7 @@ const void* LTOCodeGenerator::compile(size_t* length,
sys::fs::remove(NativeObjectPath);
return nullptr;
}
- NativeObjectFile = BufferOrErr.get().release();
+ NativeObjectFile = std::move(*BufferOrErr);
// remove temp files
sys::fs::remove(NativeObjectPath);
@@ -298,8 +315,7 @@ bool LTOCodeGenerator::determineTarget(std::string &errMsg) {
MCpu = "core2";
else if (Triple.getArch() == llvm::Triple::x86)
MCpu = "yonah";
- else if (Triple.getArch() == llvm::Triple::arm64 ||
- Triple.getArch() == llvm::Triple::aarch64)
+ else if (Triple.getArch() == llvm::Triple::aarch64)
MCpu = "cyclone";
}
@@ -311,9 +327,9 @@ bool LTOCodeGenerator::determineTarget(std::string &errMsg) {
void LTOCodeGenerator::
applyRestriction(GlobalValue &GV,
- const ArrayRef<StringRef> &Libcalls,
+ ArrayRef<StringRef> Libcalls,
std::vector<const char*> &MustPreserveList,
- SmallPtrSet<GlobalValue*, 8> &AsmUsed,
+ SmallPtrSetImpl<GlobalValue*> &AsmUsed,
Mangler &Mangler) {
// There are no restrictions to apply to declarations.
if (GV.isDeclaration())
@@ -342,7 +358,7 @@ applyRestriction(GlobalValue &GV,
}
static void findUsedValues(GlobalVariable *LLVMUsed,
- SmallPtrSet<GlobalValue*, 8> &UsedValues) {
+ SmallPtrSetImpl<GlobalValue*> &UsedValues) {
if (!LLVMUsed) return;
ConstantArray *Inits = cast<ConstantArray>(LLVMUsed->getInitializer());
@@ -390,12 +406,13 @@ void LTOCodeGenerator::applyScopeRestrictions() {
passes.add(createDebugInfoVerifierPass());
// mark which symbols can not be internalized
- Mangler Mangler(TargetMach->getDataLayout());
+ Mangler Mangler(TargetMach->getSubtargetImpl()->getDataLayout());
std::vector<const char*> MustPreserveList;
SmallPtrSet<GlobalValue*, 8> AsmUsed;
std::vector<StringRef> Libcalls;
TargetLibraryInfo TLI(Triple(TargetMach->getTargetTriple()));
- accumulateAndSortLibcalls(Libcalls, TLI, TargetMach->getTargetLowering());
+ accumulateAndSortLibcalls(
+ Libcalls, TLI, TargetMach->getSubtargetImpl()->getTargetLowering());
for (Module::iterator f = mergedModule->begin(),
e = mergedModule->end(); f != e; ++f)
@@ -444,6 +461,7 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
bool DisableOpt,
bool DisableInline,
bool DisableGVNLoadPRE,
+ bool DisableVectorization,
std::string &errMsg) {
if (!this->determineTarget(errMsg))
return false;
@@ -456,35 +474,27 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
// Instantiate the pass manager to organize the passes.
PassManager passes;
- // Start off with a verification pass.
- passes.add(createVerifierPass());
- passes.add(createDebugInfoVerifierPass());
-
// Add an appropriate DataLayout instance for this module...
- mergedModule->setDataLayout(TargetMach->getDataLayout());
- passes.add(new DataLayoutPass(mergedModule));
-
- // Add appropriate TargetLibraryInfo for this module.
- passes.add(new TargetLibraryInfo(Triple(TargetMach->getTargetTriple())));
-
- TargetMach->addAnalysisPasses(passes);
-
- // Enabling internalize here would use its AllButMain variant. It
- // keeps only main if it exists and does nothing for libraries. Instead
- // we create the pass ourselves with the symbol list provided by the linker.
- if (!DisableOpt)
- PassManagerBuilder().populateLTOPassManager(passes,
- /*Internalize=*/false,
- !DisableInline,
- DisableGVNLoadPRE);
-
- // Make sure everything is still good.
- passes.add(createVerifierPass());
- passes.add(createDebugInfoVerifierPass());
+ mergedModule->setDataLayout(TargetMach->getSubtargetImpl()->getDataLayout());
+
+ Triple TargetTriple(TargetMach->getTargetTriple());
+ PassManagerBuilder PMB;
+ PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
+ PMB.LoopVectorize = !DisableVectorization;
+ PMB.SLPVectorize = !DisableVectorization;
+ if (!DisableInline)
+ PMB.Inliner = createFunctionInliningPass();
+ PMB.LibraryInfo = new TargetLibraryInfo(TargetTriple);
+ if (DisableOpt)
+ PMB.OptLevel = 0;
+ PMB.VerifyInput = true;
+ PMB.VerifyOutput = true;
+
+ PMB.populateLTOPassManager(passes, TargetMach);
PassManager codeGenPasses;
- codeGenPasses.add(new DataLayoutPass(mergedModule));
+ codeGenPasses.add(new DataLayoutPass());
formatted_raw_ostream Out(out);
@@ -571,5 +581,6 @@ LTOCodeGenerator::setDiagnosticHandler(lto_diagnostic_handler_t DiagHandler,
return Context.setDiagnosticHandler(nullptr, nullptr);
// Register the LTOCodeGenerator stub in the LLVMContext to forward the
// diagnostic to the external DiagHandler.
- Context.setDiagnosticHandler(LTOCodeGenerator::DiagnosticHandler, this);
+ Context.setDiagnosticHandler(LTOCodeGenerator::DiagnosticHandler, this,
+ /* RespectFilters */ true);
}
diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp
index 844c0f2..4108ef2 100644
--- a/lib/LTO/LTOModule.cpp
+++ b/lib/LTO/LTOModule.cpp
@@ -15,6 +15,7 @@
#include "llvm/LTO/LTOModule.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/CodeGen/Analysis.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
@@ -28,6 +29,8 @@
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCTargetAsmParser.h"
#include "llvm/MC/SubtargetFeature.h"
+#include "llvm/Object/IRObjectFile.h"
+#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h"
@@ -39,32 +42,51 @@
#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetRegisterInfo.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
#include "llvm/Transforms/Utils/GlobalStatus.h"
#include <system_error>
using namespace llvm;
+using namespace llvm::object;
LTOModule::LTOModule(std::unique_ptr<object::IRObjectFile> Obj,
llvm::TargetMachine *TM)
: IRFile(std::move(Obj)), _target(TM) {}
+LTOModule::LTOModule(std::unique_ptr<object::IRObjectFile> Obj,
+ llvm::TargetMachine *TM,
+ std::unique_ptr<LLVMContext> Context)
+ : OwnedContext(std::move(Context)), IRFile(std::move(Obj)), _target(TM) {}
+
+LTOModule::~LTOModule() {}
+
/// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM
/// bitcode.
-bool LTOModule::isBitcodeFile(const void *mem, size_t length) {
- return sys::fs::identify_magic(StringRef((const char *)mem, length)) ==
- sys::fs::file_magic::bitcode;
+bool LTOModule::isBitcodeFile(const void *Mem, size_t Length) {
+ ErrorOr<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
+ MemoryBufferRef(StringRef((const char *)Mem, Length), "<mem>"));
+ return bool(BCData);
}
-bool LTOModule::isBitcodeFile(const char *path) {
- sys::fs::file_magic type;
- if (sys::fs::identify_magic(path, type))
+bool LTOModule::isBitcodeFile(const char *Path) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
+ MemoryBuffer::getFile(Path);
+ if (!BufferOrErr)
return false;
- return type == sys::fs::file_magic::bitcode;
+
+ ErrorOr<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
+ BufferOrErr.get()->getMemBufferRef());
+ return bool(BCData);
}
-bool LTOModule::isBitcodeForTarget(MemoryBuffer *buffer,
- StringRef triplePrefix) {
- std::string Triple = getBitcodeTargetTriple(buffer, getGlobalContext());
- return StringRef(Triple).startswith(triplePrefix);
+bool LTOModule::isBitcodeForTarget(MemoryBuffer *Buffer,
+ StringRef TriplePrefix) {
+ ErrorOr<MemoryBufferRef> BCOrErr =
+ IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef());
+ if (!BCOrErr)
+ return false;
+ LLVMContext Context;
+ std::string Triple = getBitcodeTargetTriple(*BCOrErr, Context);
+ return StringRef(Triple).startswith(TriplePrefix);
}
LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options,
@@ -75,7 +97,9 @@ LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options,
errMsg = EC.message();
return nullptr;
}
- return makeLTOModule(std::move(BufferOrErr.get()), options, errMsg);
+ std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get());
+ return makeLTOModule(Buffer->getMemBufferRef(), options, errMsg,
+ &getGlobalContext());
}
LTOModule *LTOModule::createFromOpenFile(int fd, const char *path, size_t size,
@@ -94,23 +118,50 @@ LTOModule *LTOModule::createFromOpenFileSlice(int fd, const char *path,
errMsg = EC.message();
return nullptr;
}
- return makeLTOModule(std::move(BufferOrErr.get()), options, errMsg);
+ std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get());
+ return makeLTOModule(Buffer->getMemBufferRef(), options, errMsg,
+ &getGlobalContext());
}
LTOModule *LTOModule::createFromBuffer(const void *mem, size_t length,
TargetOptions options,
std::string &errMsg, StringRef path) {
- std::unique_ptr<MemoryBuffer> buffer(makeBuffer(mem, length, path));
- if (!buffer)
- return nullptr;
- return makeLTOModule(std::move(buffer), options, errMsg);
+ return createInContext(mem, length, options, errMsg, path,
+ &getGlobalContext());
+}
+
+LTOModule *LTOModule::createInLocalContext(const void *mem, size_t length,
+ TargetOptions options,
+ std::string &errMsg,
+ StringRef path) {
+ return createInContext(mem, length, options, errMsg, path, nullptr);
}
-LTOModule *LTOModule::makeLTOModule(std::unique_ptr<MemoryBuffer> Buffer,
- TargetOptions options,
- std::string &errMsg) {
- ErrorOr<Module *> MOrErr =
- getLazyBitcodeModule(Buffer.get(), getGlobalContext());
+LTOModule *LTOModule::createInContext(const void *mem, size_t length,
+ TargetOptions options,
+ std::string &errMsg, StringRef path,
+ LLVMContext *Context) {
+ StringRef Data((const char *)mem, length);
+ MemoryBufferRef Buffer(Data, path);
+ return makeLTOModule(Buffer, options, errMsg, Context);
+}
+
+LTOModule *LTOModule::makeLTOModule(MemoryBufferRef Buffer,
+ TargetOptions options, std::string &errMsg,
+ LLVMContext *Context) {
+ std::unique_ptr<LLVMContext> OwnedContext;
+ if (!Context) {
+ OwnedContext = llvm::make_unique<LLVMContext>();
+ Context = OwnedContext.get();
+ }
+
+ ErrorOr<MemoryBufferRef> MBOrErr =
+ IRObjectFile::findBitcodeInMemBuffer(Buffer);
+ if (std::error_code EC = MBOrErr.getError()) {
+ errMsg = EC.message();
+ return nullptr;
+ }
+ ErrorOr<Module *> MOrErr = parseBitcodeFile(*MBOrErr, *Context);
if (std::error_code EC = MOrErr.getError()) {
errMsg = EC.message();
return nullptr;
@@ -138,20 +189,22 @@ LTOModule *LTOModule::makeLTOModule(std::unique_ptr<MemoryBuffer> Buffer,
CPU = "core2";
else if (Triple.getArch() == llvm::Triple::x86)
CPU = "yonah";
- else if (Triple.getArch() == llvm::Triple::arm64 ||
- Triple.getArch() == llvm::Triple::aarch64)
+ else if (Triple.getArch() == llvm::Triple::aarch64)
CPU = "cyclone";
}
TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
options);
- M->materializeAllPermanently(true);
- M->setDataLayout(target->getDataLayout());
+ M->setDataLayout(target->getSubtargetImpl()->getDataLayout());
std::unique_ptr<object::IRObjectFile> IRObj(
- new object::IRObjectFile(std::move(Buffer), std::move(M)));
+ new object::IRObjectFile(Buffer, std::move(M)));
- LTOModule *Ret = new LTOModule(std::move(IRObj), target);
+ LTOModule *Ret;
+ if (OwnedContext)
+ Ret = new LTOModule(std::move(IRObj), target, std::move(OwnedContext));
+ else
+ Ret = new LTOModule(std::move(IRObj), target);
if (Ret->parseSymbols(errMsg)) {
delete Ret;
@@ -164,8 +217,8 @@ LTOModule *LTOModule::makeLTOModule(std::unique_ptr<MemoryBuffer> Buffer,
}
/// Create a MemoryBuffer from a memory range with an optional name.
-MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length,
- StringRef name) {
+std::unique_ptr<MemoryBuffer>
+LTOModule::makeBuffer(const void *mem, size_t length, StringRef name) {
const char *startPtr = (const char*)mem;
return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), name, false);
}
@@ -196,27 +249,24 @@ void LTOModule::addObjCClass(const GlobalVariable *clgv) {
// second slot in __OBJC,__class is pointer to superclass name
std::string superclassName;
if (objcClassNameFromExpression(c->getOperand(1), superclassName)) {
- NameAndAttributes info;
- StringMap<NameAndAttributes>::value_type &entry =
- _undefines.GetOrCreateValue(superclassName);
- if (!entry.getValue().name) {
- const char *symbolName = entry.getKey().data();
- info.name = symbolName;
+ auto IterBool =
+ _undefines.insert(std::make_pair(superclassName, NameAndAttributes()));
+ if (IterBool.second) {
+ NameAndAttributes &info = IterBool.first->second;
+ info.name = IterBool.first->first().data();
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
info.isFunction = false;
info.symbol = clgv;
- entry.setValue(info);
}
}
// third slot in __OBJC,__class is pointer to class name
std::string className;
if (objcClassNameFromExpression(c->getOperand(2), className)) {
- StringSet::value_type &entry = _defines.GetOrCreateValue(className);
- entry.setValue(1);
+ auto Iter = _defines.insert(className).first;
NameAndAttributes info;
- info.name = entry.getKey().data();
+ info.name = Iter->first().data();
info.attributes = LTO_SYMBOL_PERMISSIONS_DATA |
LTO_SYMBOL_DEFINITION_REGULAR | LTO_SYMBOL_SCOPE_DEFAULT;
info.isFunction = false;
@@ -235,19 +285,17 @@ void LTOModule::addObjCCategory(const GlobalVariable *clgv) {
if (!objcClassNameFromExpression(c->getOperand(1), targetclassName))
return;
- NameAndAttributes info;
- StringMap<NameAndAttributes>::value_type &entry =
- _undefines.GetOrCreateValue(targetclassName);
+ auto IterBool =
+ _undefines.insert(std::make_pair(targetclassName, NameAndAttributes()));
- if (entry.getValue().name)
+ if (!IterBool.second)
return;
- const char *symbolName = entry.getKey().data();
- info.name = symbolName;
+ NameAndAttributes &info = IterBool.first->second;
+ info.name = IterBool.first->first().data();
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
info.isFunction = false;
info.symbol = clgv;
- entry.setValue(info);
}
/// addObjCClassRef - Parse i386/ppc ObjC class list data structure.
@@ -256,18 +304,17 @@ void LTOModule::addObjCClassRef(const GlobalVariable *clgv) {
if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName))
return;
- NameAndAttributes info;
- StringMap<NameAndAttributes>::value_type &entry =
- _undefines.GetOrCreateValue(targetclassName);
- if (entry.getValue().name)
+ auto IterBool =
+ _undefines.insert(std::make_pair(targetclassName, NameAndAttributes()));
+
+ if (!IterBool.second)
return;
- const char *symbolName = entry.getKey().data();
- info.name = symbolName;
+ NameAndAttributes &info = IterBool.first->second;
+ info.name = IterBool.first->first().data();
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
info.isFunction = false;
info.symbol = clgv;
- entry.setValue(info);
}
void LTOModule::addDefinedDataSymbol(const object::BasicSymbolRef &Sym) {
@@ -348,30 +395,6 @@ void LTOModule::addDefinedFunctionSymbol(const char *Name, const Function *F) {
addDefinedSymbol(Name, F, true);
}
-static bool canBeHidden(const GlobalValue *GV) {
- // FIXME: this is duplicated with another static function in AsmPrinter.cpp
- GlobalValue::LinkageTypes L = GV->getLinkage();
-
- if (L != GlobalValue::LinkOnceODRLinkage)
- return false;
-
- if (GV->hasUnnamedAddr())
- return true;
-
- // If it is a non constant variable, it needs to be uniqued across shared
- // objects.
- if (const GlobalVariable *Var = dyn_cast<GlobalVariable>(GV)) {
- if (!Var->isConstant())
- return false;
- }
-
- GlobalStatus GS;
- if (GlobalStatus::analyzeGlobal(GV, GS))
- return false;
-
- return !GS.IsCompared;
-}
-
void LTOModule::addDefinedSymbol(const char *Name, const GlobalValue *def,
bool isFunction) {
// set alignment part log2() can have rounding errors
@@ -405,17 +428,16 @@ void LTOModule::addDefinedSymbol(const char *Name, const GlobalValue *def,
attr |= LTO_SYMBOL_SCOPE_HIDDEN;
else if (def->hasProtectedVisibility())
attr |= LTO_SYMBOL_SCOPE_PROTECTED;
- else if (canBeHidden(def))
+ else if (canBeOmittedFromSymbolTable(def))
attr |= LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN;
else
attr |= LTO_SYMBOL_SCOPE_DEFAULT;
- StringSet::value_type &entry = _defines.GetOrCreateValue(Name);
- entry.setValue(1);
+ auto Iter = _defines.insert(Name).first;
// fill information structure
NameAndAttributes info;
- StringRef NameRef = entry.getKey();
+ StringRef NameRef = Iter->first();
info.name = NameRef.data();
assert(info.name[NameRef.size()] == '\0');
info.attributes = attr;
@@ -430,15 +452,13 @@ void LTOModule::addDefinedSymbol(const char *Name, const GlobalValue *def,
/// defined list.
void LTOModule::addAsmGlobalSymbol(const char *name,
lto_symbol_attributes scope) {
- StringSet::value_type &entry = _defines.GetOrCreateValue(name);
+ auto IterBool = _defines.insert(name);
// only add new define if not already defined
- if (entry.getValue())
+ if (!IterBool.second)
return;
- entry.setValue(1);
-
- NameAndAttributes &info = _undefines[entry.getKey().data()];
+ NameAndAttributes &info = _undefines[IterBool.first->first().data()];
if (info.symbol == nullptr) {
// FIXME: This is trying to take care of module ASM like this:
@@ -450,7 +470,7 @@ void LTOModule::addAsmGlobalSymbol(const char *name,
// much.
// fill information structure
- info.name = entry.getKey().data();
+ info.name = IterBool.first->first().data();
info.attributes =
LTO_SYMBOL_PERMISSIONS_DATA | LTO_SYMBOL_DEFINITION_REGULAR | scope;
info.isFunction = false;
@@ -473,24 +493,21 @@ void LTOModule::addAsmGlobalSymbol(const char *name,
/// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the
/// undefined list.
void LTOModule::addAsmGlobalSymbolUndef(const char *name) {
- StringMap<NameAndAttributes>::value_type &entry =
- _undefines.GetOrCreateValue(name);
+ auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes()));
- _asm_undefines.push_back(entry.getKey().data());
+ _asm_undefines.push_back(IterBool.first->first().data());
// we already have the symbol
- if (entry.getValue().name)
+ if (!IterBool.second)
return;
uint32_t attr = LTO_SYMBOL_DEFINITION_UNDEFINED;
attr |= LTO_SYMBOL_SCOPE_DEFAULT;
- NameAndAttributes info;
- info.name = entry.getKey().data();
+ NameAndAttributes &info = IterBool.first->second;
+ info.name = IterBool.first->first().data();
info.attributes = attr;
info.isFunction = false;
info.symbol = nullptr;
-
- entry.setValue(info);
}
/// Add a symbol which isn't defined just yet to a list to be resolved later.
@@ -502,16 +519,15 @@ void LTOModule::addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym,
Sym.printName(OS);
}
- StringMap<NameAndAttributes>::value_type &entry =
- _undefines.GetOrCreateValue(name);
+ auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes()));
// we already have the symbol
- if (entry.getValue().name)
+ if (!IterBool.second)
return;
- NameAndAttributes info;
+ NameAndAttributes &info = IterBool.first->second;
- info.name = entry.getKey().data();
+ info.name = IterBool.first->first().data();
const GlobalValue *decl = IRFile->getSymbolGV(Sym.getRawDataRefImpl());
@@ -522,8 +538,6 @@ void LTOModule::addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym,
info.isFunction = isFunc;
info.symbol = decl;
-
- entry.setValue(info);
}
/// parseSymbols - Parse the symbols from the module and model-level ASM and add
@@ -596,10 +610,15 @@ void LTOModule::parseMetadata() {
MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i));
for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
- StringRef Op = _linkeropt_strings.
- GetOrCreateValue(MDOption->getString()).getKey();
- StringRef DepLibName = _target->getTargetLowering()->
- getObjFileLowering().getDepLibFromLinkerOpt(Op);
+ // FIXME: Make StringSet::insert match Self-Associative Container
+ // requirements, returning <iter,bool> rather than bool, and use that
+ // here.
+ StringRef Op =
+ _linkeropt_strings.insert(MDOption->getString()).first->first();
+ StringRef DepLibName = _target->getSubtargetImpl()
+ ->getTargetLowering()
+ ->getObjFileLowering()
+ .getDepLibFromLinkerOpt(Op);
if (!DepLibName.empty())
_deplibs.push_back(DepLibName.data());
else if (!Op.empty())