summaryrefslogtreecommitdiffstats
path: root/tools/lto
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lto')
-rw-r--r--tools/lto/CMakeLists.txt3
-rw-r--r--tools/lto/LTOCodeGenerator.cpp66
-rw-r--r--tools/lto/LTOCodeGenerator.h6
-rw-r--r--tools/lto/LTODisassembler.cpp26
-rw-r--r--tools/lto/LTOModule.cpp61
-rw-r--r--tools/lto/LTOModule.h28
-rw-r--r--tools/lto/Makefile2
-rw-r--r--tools/lto/lto.cpp5
-rw-r--r--tools/lto/lto.exports2
9 files changed, 124 insertions, 75 deletions
diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt
index 9112976..5820b14 100644
--- a/tools/lto/CMakeLists.txt
+++ b/tools/lto/CMakeLists.txt
@@ -6,10 +6,13 @@ add_definitions( -DLLVM_VERSION_INFO=\"${PACKAGE_VERSION}\" )
set(SOURCES
LTOCodeGenerator.cpp
+ LTODisassembler.cpp
lto.cpp
LTOModule.cpp
)
+set(LLVM_COMMON_DEPENDS intrinsics_gen)
+
if( NOT WIN32 AND LLVM_ENABLE_PIC )
set(bsl ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS ON)
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp
index b1c4f43..e7c83f9 100644
--- a/tools/lto/LTOCodeGenerator.cpp
+++ b/tools/lto/LTOCodeGenerator.cpp
@@ -14,39 +14,44 @@
#include "LTOCodeGenerator.h"
#include "LTOModule.h"
-#include "llvm/Constants.h"
-#include "llvm/DataLayout.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Linker.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Module.h"
-#include "llvm/PassManager.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Config/config.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Linker.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/SubtargetFeature.h"
-#include "llvm/Target/Mangler.h"
-#include "llvm/Target/TargetOptions.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/Target/TargetRegisterInfo.h"
-#include "llvm/Transforms/IPO.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/PassManager.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/Host.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/system_error.h"
-#include "llvm/ADT/StringExtras.h"
+#include "llvm/Target/Mangler.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetOptions.h"
+#include "llvm/Target/TargetRegisterInfo.h"
+#include "llvm/Transforms/IPO.h"
+#include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/ObjCARC.h"
using namespace llvm;
static cl::opt<bool>
+DisableOpt("disable-opt", cl::init(false),
+ cl::desc("Do not run any optimization passes"));
+
+static cl::opt<bool>
DisableInline("disable-inlining", cl::init(false),
cl::desc("Do not run the inliner pass"));
@@ -371,26 +376,33 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
// Add an appropriate DataLayout instance for this module...
passes.add(new DataLayout(*_target->getDataLayout()));
- passes.add(new TargetTransformInfo(_target->getScalarTargetTransformInfo(),
- _target->getVectorTargetTransformInfo()));
+ _target->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.
- PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/false,
+ if (!DisableOpt) {
+ PassManagerBuilder().populateLTOPassManager(passes,
+ /*Internalize=*/false,
!DisableInline,
DisableGVNLoadPRE);
+ }
// Make sure everything is still good.
passes.add(createVerifierPass());
- FunctionPassManager *codeGenPasses = new FunctionPassManager(mergedModule);
+ PassManager codeGenPasses;
- codeGenPasses->add(new DataLayout(*_target->getDataLayout()));
+ codeGenPasses.add(new DataLayout(*_target->getDataLayout()));
+ _target->addAnalysisPasses(codeGenPasses);
formatted_raw_ostream Out(out);
- if (_target->addPassesToEmitFile(*codeGenPasses, Out,
+ // If the bitcode files contain ARC code and were compiled with optimization,
+ // the ObjCARCContractPass must be run, so do it unconditionally here.
+ codeGenPasses.add(createObjCARCContractPass());
+
+ if (_target->addPassesToEmitFile(codeGenPasses, Out,
TargetMachine::CGFT_ObjectFile)) {
errMsg = "target file type not supported";
return true;
@@ -400,15 +412,7 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
passes.run(*mergedModule);
// Run the code generator, and write assembly file
- codeGenPasses->doInitialization();
-
- for (Module::iterator
- it = mergedModule->begin(), e = mergedModule->end(); it != e; ++it)
- if (!it->isDeclaration())
- codeGenPasses->run(*it);
-
- codeGenPasses->doFinalization();
- delete codeGenPasses;
+ codeGenPasses.run(*mergedModule);
return false; // success
}
diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h
index 3081b7d..601dbfa 100644
--- a/tools/lto/LTOCodeGenerator.h
+++ b/tools/lto/LTOCodeGenerator.h
@@ -14,10 +14,10 @@
#ifndef LTO_CODE_GENERATOR_H
#define LTO_CODE_GENERATOR_H
-#include "llvm/Linker.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/SmallPtrSet.h"
#include "llvm-c/lto.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/Linker.h"
#include <string>
namespace llvm {
diff --git a/tools/lto/LTODisassembler.cpp b/tools/lto/LTODisassembler.cpp
new file mode 100644
index 0000000..186aceb
--- /dev/null
+++ b/tools/lto/LTODisassembler.cpp
@@ -0,0 +1,26 @@
+//===-- LTODisassembler.cpp - LTO Disassembler interface ------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This function provides utility methods used by clients of libLTO that want
+// to use the disassembler.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm-c/lto.h"
+#include "llvm/Support/TargetSelect.h"
+
+using namespace llvm;
+
+void lto_initialize_disassembler() {
+ // Initialize targets and assembly printers/parsers.
+ llvm::InitializeAllTargetInfos();
+ llvm::InitializeAllTargetMCs();
+ llvm::InitializeAllAsmParsers();
+ llvm::InitializeAllDisassemblers();
+}
diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp
index ffdcbe6..ff67769 100644
--- a/tools/lto/LTOModule.cpp
+++ b/tools/lto/LTOModule.cpp
@@ -13,19 +13,20 @@
//===----------------------------------------------------------------------===//
#include "LTOModule.h"
-#include "llvm/Constants.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Module.h"
+#include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCParser/MCAsmParser.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCTargetAsmParser.h"
#include "llvm/MC/SubtargetFeature.h"
-#include "llvm/MC/MCParser/MCAsmParser.h"
-#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -34,8 +35,7 @@
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/system_error.h"
-#include "llvm/ADT/OwningPtr.h"
-#include "llvm/ADT/Triple.h"
+#include "llvm/Target/TargetRegisterInfo.h"
using namespace llvm;
static cl::opt<bool>
@@ -320,8 +320,9 @@ MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
}
/// objcClassNameFromExpression - Get string that the data pointer points to.
-bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) {
- if (ConstantExpr *ce = dyn_cast<ConstantExpr>(c)) {
+bool
+LTOModule::objcClassNameFromExpression(const Constant *c, std::string &name) {
+ if (const ConstantExpr *ce = dyn_cast<ConstantExpr>(c)) {
Constant *op = ce->getOperand(0);
if (GlobalVariable *gvn = dyn_cast<GlobalVariable>(op)) {
Constant *cn = gvn->getInitializer();
@@ -337,8 +338,8 @@ bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) {
}
/// addObjCClass - Parse i386/ppc ObjC class data structure.
-void LTOModule::addObjCClass(GlobalVariable *clgv) {
- ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer());
+void LTOModule::addObjCClass(const GlobalVariable *clgv) {
+ const ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer());
if (!c) return;
// second slot in __OBJC,__class is pointer to superclass name
@@ -374,8 +375,8 @@ void LTOModule::addObjCClass(GlobalVariable *clgv) {
}
/// addObjCCategory - Parse i386/ppc ObjC category data structure.
-void LTOModule::addObjCCategory(GlobalVariable *clgv) {
- ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer());
+void LTOModule::addObjCCategory(const GlobalVariable *clgv) {
+ const ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer());
if (!c) return;
// second slot in __OBJC,__category is pointer to target class name
@@ -399,7 +400,7 @@ void LTOModule::addObjCCategory(GlobalVariable *clgv) {
}
/// addObjCClassRef - Parse i386/ppc ObjC class list data structure.
-void LTOModule::addObjCClassRef(GlobalVariable *clgv) {
+void LTOModule::addObjCClassRef(const GlobalVariable *clgv) {
std::string targetclassName;
if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName))
return;
@@ -419,7 +420,7 @@ void LTOModule::addObjCClassRef(GlobalVariable *clgv) {
}
/// addDefinedDataSymbol - Add a data symbol as defined to the list.
-void LTOModule::addDefinedDataSymbol(GlobalValue *v) {
+void LTOModule::addDefinedDataSymbol(const GlobalValue *v) {
// Add to list of defined symbols.
addDefinedSymbol(v, false);
@@ -448,34 +449,34 @@ void LTOModule::addDefinedDataSymbol(GlobalValue *v) {
// special case if this data blob is an ObjC class definition
if (v->getSection().compare(0, 15, "__OBJC,__class,") == 0) {
- if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
+ if (const GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
addObjCClass(gv);
}
}
// special case if this data blob is an ObjC category definition
else if (v->getSection().compare(0, 18, "__OBJC,__category,") == 0) {
- if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
+ if (const GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
addObjCCategory(gv);
}
}
// special case if this data blob is the list of referenced classes
else if (v->getSection().compare(0, 18, "__OBJC,__cls_refs,") == 0) {
- if (GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
+ if (const GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) {
addObjCClassRef(gv);
}
}
}
/// addDefinedFunctionSymbol - Add a function symbol as defined to the list.
-void LTOModule::addDefinedFunctionSymbol(Function *f) {
+void LTOModule::addDefinedFunctionSymbol(const Function *f) {
// add to list of defined symbols
addDefinedSymbol(f, true);
}
/// addDefinedSymbol - Add a defined symbol to the list.
-void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) {
+void LTOModule::addDefinedSymbol(const GlobalValue *def, bool isFunction) {
// ignore all llvm.* symbols
if (def->getName().startswith("llvm."))
return;
@@ -492,7 +493,7 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) {
if (isFunction) {
attr |= LTO_SYMBOL_PERMISSIONS_CODE;
} else {
- GlobalVariable *gv = dyn_cast<GlobalVariable>(def);
+ const GlobalVariable *gv = dyn_cast<GlobalVariable>(def);
if (gv && gv->isConstant())
attr |= LTO_SYMBOL_PERMISSIONS_RODATA;
else
@@ -607,7 +608,8 @@ void LTOModule::addAsmGlobalSymbolUndef(const char *name) {
/// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet to a
/// list to be resolved later.
-void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, bool isFunc) {
+void
+LTOModule::addPotentialUndefinedSymbol(const GlobalValue *decl, bool isFunc) {
// ignore all llvm.* symbols
if (decl->getName().startswith("llvm."))
return;
@@ -731,7 +733,8 @@ namespace {
return Symbols.end();
}
- RecordStreamer(MCContext &Context) : MCStreamer(Context) {}
+ RecordStreamer(MCContext &Context)
+ : MCStreamer(SK_RecordStreamer, Context) {}
virtual void EmitInstruction(const MCInst &Inst) {
// Scan for values.
@@ -743,6 +746,9 @@ namespace {
Symbol->setSection(*getCurrentSection());
markDefined(*Symbol);
}
+ virtual void EmitDebugLabel(MCSymbol *Symbol) {
+ EmitLabel(Symbol);
+ }
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
// FIXME: should we handle aliases?
markDefined(*Symbol);
@@ -760,8 +766,13 @@ namespace {
markDefined(*Symbol);
}
+ virtual void EmitBundleAlignMode(unsigned AlignPow2) {}
+ virtual void EmitBundleLock(bool AlignToEnd) {}
+ virtual void EmitBundleUnlock() {}
+
// Noop calls.
virtual void ChangeSection(const MCSection *Section) {}
+ virtual void InitToTextSection() {}
virtual void InitSections() {}
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {}
virtual void EmitThumbFunc(MCSymbol *Func) {}
@@ -794,6 +805,10 @@ namespace {
const MCSymbol *Label,
unsigned PointerSize) {}
virtual void FinishImpl() {}
+
+ static bool classof(const MCStreamer *S) {
+ return S->getKind() == SK_RecordStreamer;
+ }
};
} // end anonymous namespace
diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h
index 8e52206..83f3a7d 100644
--- a/tools/lto/LTOModule.h
+++ b/tools/lto/LTOModule.h
@@ -14,15 +14,15 @@
#ifndef LTO_MODULE_H
#define LTO_MODULE_H
-#include "llvm/Module.h"
+#include "llvm-c/lto.h"
+#include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/IR/Module.h"
#include "llvm/MC/MCContext.h"
#include "llvm/Target/Mangler.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/ADT/OwningPtr.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm-c/lto.h"
-#include <vector>
#include <string>
+#include <vector>
// Forward references to llvm classes.
namespace llvm {
@@ -44,7 +44,7 @@ private:
const char *name;
uint32_t attributes;
bool isFunction;
- llvm::GlobalValue *symbol;
+ const llvm::GlobalValue *symbol;
};
llvm::OwningPtr<llvm::Module> _module;
@@ -138,16 +138,16 @@ private:
/// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet
/// to a list to be resolved later.
- void addPotentialUndefinedSymbol(llvm::GlobalValue *dcl, bool isFunc);
+ void addPotentialUndefinedSymbol(const llvm::GlobalValue *dcl, bool isFunc);
/// addDefinedSymbol - Add a defined symbol to the list.
- void addDefinedSymbol(llvm::GlobalValue *def, bool isFunction);
+ void addDefinedSymbol(const llvm::GlobalValue *def, bool isFunction);
/// addDefinedFunctionSymbol - Add a function symbol as defined to the list.
- void addDefinedFunctionSymbol(llvm::Function *f);
+ void addDefinedFunctionSymbol(const llvm::Function *f);
/// addDefinedDataSymbol - Add a data symbol as defined to the list.
- void addDefinedDataSymbol(llvm::GlobalValue *v);
+ void addDefinedDataSymbol(const llvm::GlobalValue *v);
/// addAsmGlobalSymbols - Add global symbols from module-level ASM to the
/// defined or undefined lists.
@@ -162,17 +162,17 @@ private:
void addAsmGlobalSymbolUndef(const char *);
/// addObjCClass - Parse i386/ppc ObjC class data structure.
- void addObjCClass(llvm::GlobalVariable *clgv);
+ void addObjCClass(const llvm::GlobalVariable *clgv);
/// addObjCCategory - Parse i386/ppc ObjC category data structure.
- void addObjCCategory(llvm::GlobalVariable *clgv);
+ void addObjCCategory(const llvm::GlobalVariable *clgv);
/// addObjCClassRef - Parse i386/ppc ObjC class list data structure.
- void addObjCClassRef(llvm::GlobalVariable *clgv);
+ void addObjCClassRef(const llvm::GlobalVariable *clgv);
/// objcClassNameFromExpression - Get string that the data pointer points
/// to.
- bool objcClassNameFromExpression(llvm::Constant* c, std::string &name);
+ bool objcClassNameFromExpression(const llvm::Constant* c, std::string &name);
/// isTargetMatch - Returns 'true' if the memory buffer is for the specified
/// target triple.
diff --git a/tools/lto/Makefile b/tools/lto/Makefile
index 3610fed..ab2e16e 100644
--- a/tools/lto/Makefile
+++ b/tools/lto/Makefile
@@ -51,7 +51,7 @@ ifeq ($(HOST_OS),Darwin)
endif
# If we're doing an Apple-style build, add the LTO object path.
- ifeq ($(RC_BUILDIT),YES)
+ ifeq ($(RC_XBS),YES)
TempFile := $(shell mkdir -p ${OBJROOT}/dSYMs ; mktemp ${OBJROOT}/dSYMs/llvm-lto.XXXXXX)
LLVMLibsOptions := $(LLVMLibsOptions) \
-Wl,-object_path_lto -Wl,$(TempFile)
diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp
index a7e633d..11ad532 100644
--- a/tools/lto/lto.cpp
+++ b/tools/lto/lto.cpp
@@ -13,10 +13,9 @@
//===----------------------------------------------------------------------===//
#include "llvm-c/lto.h"
-#include "llvm-c/Core.h"
-
-#include "LTOModule.h"
#include "LTOCodeGenerator.h"
+#include "LTOModule.h"
+#include "llvm-c/Core.h"
// Holds most recent error string.
diff --git a/tools/lto/lto.exports b/tools/lto/lto.exports
index 4940bb1..46d0d74 100644
--- a/tools/lto/lto.exports
+++ b/tools/lto/lto.exports
@@ -1,5 +1,6 @@
lto_get_error_message
lto_get_version
+lto_initialize_disassembler
lto_module_create
lto_module_create_from_fd
lto_module_create_from_fd_at_offset
@@ -28,6 +29,7 @@ lto_codegen_set_assembler_path
lto_codegen_set_cpu
lto_codegen_compile_to_file
LLVMCreateDisasm
+LLVMCreateDisasmCPU
LLVMDisasmDispose
LLVMDisasmInstruction
LLVMSetDisasmOptions
OpenPOWER on IntegriCloud