summaryrefslogtreecommitdiff
path: root/tools/lto
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2011-03-18 19:51:00 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2011-03-18 19:51:00 +0000
commitf19d7a7af3f10b6d43f9e8b0271f0f836a33d52c (patch)
tree53087364c386fc3e36c974ab29227fddda313268 /tools/lto
parent19f6f503d6638ab811f0da1b09db584e62a2b435 (diff)
downloadllvm-f19d7a7af3f10b6d43f9e8b0271f0f836a33d52c.tar.gz
llvm-f19d7a7af3f10b6d43f9e8b0271f0f836a33d52c.tar.bz2
llvm-f19d7a7af3f10b6d43f9e8b0271f0f836a33d52c.tar.xz
Use lazy parsing in LTO. Unfortunately this is only a 3% time saving for
'ar'. Have to figure out how to make libLTO even lazier. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127901 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lto')
-rw-r--r--tools/lto/LTOCodeGenerator.cpp4
-rw-r--r--tools/lto/LTOModule.cpp31
2 files changed, 27 insertions, 8 deletions
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp
index 6739e06767..ffe244dbcd 100644
--- a/tools/lto/LTOCodeGenerator.cpp
+++ b/tools/lto/LTOCodeGenerator.cpp
@@ -87,6 +87,10 @@ LTOCodeGenerator::~LTOCodeGenerator()
bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg)
{
+
+ if(mod->getLLVVMModule()->MaterializeAllPermanently(&errMsg))
+ return true;
+
bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg);
const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs();
diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp
index 4cfe9ad166..78e6f283e0 100644
--- a/tools/lto/LTOModule.cpp
+++ b/tools/lto/LTOModule.cpp
@@ -91,7 +91,7 @@ LTOModule *LTOModule::makeLTOModule(const char *path,
errMsg = ec.message();
return NULL;
}
- return makeLTOModule(buffer.get(), errMsg);
+ return makeLTOModule(buffer.take(), errMsg);
}
LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
@@ -111,7 +111,7 @@ LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
errMsg = ec.message();
return NULL;
}
- return makeLTOModule(buffer.get(), errMsg);
+ return makeLTOModule(buffer.take(), errMsg);
}
/// makeBuffer - Create a MemoryBuffer from a memory range.
@@ -126,7 +126,7 @@ LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
if (!buffer)
return NULL;
- return makeLTOModule(buffer.get(), errMsg);
+ return makeLTOModule(buffer.take(), errMsg);
}
LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
@@ -139,9 +139,12 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
}
// parse bitcode buffer
- OwningPtr<Module> m(ParseBitcodeFile(buffer, getGlobalContext(), &errMsg));
- if (!m)
+ OwningPtr<Module> m(getLazyBitcodeModule(buffer, getGlobalContext(),
+ &errMsg));
+ if (!m) {
+ delete buffer;
return NULL;
+ }
std::string Triple = m->getTargetTriple();
if (Triple.empty())
@@ -638,6 +641,18 @@ bool LTOModule::addAsmGlobalSymbols(MCContext &Context) {
return false;
}
+static bool isDeclaration(const GlobalValue &V) {
+ if (V.hasAvailableExternallyLinkage())
+ return true;
+ if (V.isMaterializable())
+ return false;
+ return V.isDeclaration();
+}
+
+static bool isAliasToDeclaration(const GlobalAlias &V) {
+ return isDeclaration(*V.getAliasedGlobal());
+}
+
bool LTOModule::ParseSymbols() {
// Use mangler to add GlobalPrefix to names to match linker names.
MCContext Context(*_target->getMCAsmInfo(), NULL);
@@ -645,7 +660,7 @@ bool LTOModule::ParseSymbols() {
// add functions
for (Module::iterator f = _module->begin(); f != _module->end(); ++f) {
- if (f->isDeclaration() || f->hasAvailableExternallyLinkage())
+ if (isDeclaration(*f))
addPotentialUndefinedSymbol(f, mangler);
else
addDefinedFunctionSymbol(f, mangler);
@@ -654,7 +669,7 @@ bool LTOModule::ParseSymbols() {
// add data
for (Module::global_iterator v = _module->global_begin(),
e = _module->global_end(); v != e; ++v) {
- if (v->isDeclaration() || v->hasAvailableExternallyLinkage())
+ if (isDeclaration(*v))
addPotentialUndefinedSymbol(v, mangler);
else
addDefinedDataSymbol(v, mangler);
@@ -667,7 +682,7 @@ bool LTOModule::ParseSymbols() {
// add aliases
for (Module::alias_iterator i = _module->alias_begin(),
e = _module->alias_end(); i != e; ++i) {
- if (i->isDeclaration())
+ if (isAliasToDeclaration(*i))
addPotentialUndefinedSymbol(i, mangler);
else
addDefinedDataSymbol(i, mangler);