summaryrefslogtreecommitdiff
path: root/include/llvm/LinkTimeOptimizer.h
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2006-08-03 15:44:57 +0000
committerDevang Patel <dpatel@apple.com>2006-08-03 15:44:57 +0000
commita89d47f54d1f83d328f6169151653bfc742607bf (patch)
treecad528fe70f3d0e0d23a3965e256fe8641010f69 /include/llvm/LinkTimeOptimizer.h
parent7e79b3898ddd919170d367a516f51296017146c2 (diff)
downloadllvm-a89d47f54d1f83d328f6169151653bfc742607bf.tar.gz
llvm-a89d47f54d1f83d328f6169151653bfc742607bf.tar.bz2
llvm-a89d47f54d1f83d328f6169151653bfc742607bf.tar.xz
Add new tool, lto, to do link time optimization. This tool installs
dynamic library that linker can use to optimize llvm byte codes at link time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29494 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/LinkTimeOptimizer.h')
-rw-r--r--include/llvm/LinkTimeOptimizer.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/include/llvm/LinkTimeOptimizer.h b/include/llvm/LinkTimeOptimizer.h
new file mode 100644
index 0000000000..52532b1947
--- /dev/null
+++ b/include/llvm/LinkTimeOptimizer.h
@@ -0,0 +1,99 @@
+//===-- llvm/LinkTimeOptimizer.h - Public Interface ------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Devang Patel and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This header provides public interface to use LLVM link time optimization
+// library. This is intended to be used by linker to do link time optimization.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __LTO_H__
+#define __LTO_H__
+
+#include <string>
+#include <vector>
+#include <set>
+#include <llvm/ADT/hash_map>
+
+namespace llvm {
+
+ class Module;
+ class GlobalValue;
+
+ enum LTOStatus {
+ LTO_UNKNOWN,
+ LTO_OPT_SUCCESS,
+ LTO_READ_SUCCESS,
+ LTO_READ_FAILURE,
+ LTO_WRITE_FAILURE,
+ LTO_NO_TARGET,
+ LTO_NO_WORK,
+ LTO_MODULE_MERGE_FAILURE,
+ LTO_ASM_FAILURE
+ };
+
+ enum LTOLinkageTypes {
+ LTOExternalLinkage, // Externally visible function
+ LTOLinkOnceLinkage, // Keep one copy of named function when linking (inline)
+ LTOWeakLinkage, // Keep one copy of named function when linking (weak)
+ LTOInternalLinkage // Rename collisions when linking (static functions)
+ };
+
+ /// This class representes LLVM symbol information without exposing details
+ /// of LLVM global values. It encapsulates symbol linkage information. This
+ /// is typically used in hash_map where associated name identifies the
+ /// the symbol name.
+ class LLVMSymbol {
+
+ public:
+
+ LTOLinkageTypes getLinkage() const { return linkage; }
+ void mayBeNotUsed();
+
+ LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g) : linkage(lt), gv(g) {}
+
+ private:
+ enum LTOLinkageTypes linkage;
+ GlobalValue *gv;
+ };
+
+ class string_compare {
+ public:
+ bool operator()(const char* left, const char* right) const {
+ return (strcmp(left, right) == 0);
+ }
+ };
+
+ /// This is the main link time optimization class. It exposes simple API
+ /// to perform link time optimization using LLVM intermodular optimizer.
+ class LinkTimeOptimizer {
+
+ public:
+ typedef hash_map<const char*, LLVMSymbol*, hash<const char*>,
+ string_compare> NameToSymbolMap;
+
+ enum LTOStatus readLLVMObjectFile(const std::string &InputFilename,
+ NameToSymbolMap &symbols,
+ std::set<const char*> &references);
+ enum LTOStatus optimizeModules(const std::string &OutputFilename,
+ std::vector<const char*> &exportList);
+
+ private:
+ std::vector<Module *> modules;
+ NameToSymbolMap allSymbols;
+ };
+
+} // End llvm namespace
+
+/// This provides C interface to initialize link time optimizer. This allows
+/// linker to use dlopen() interface to dynamically load LinkTimeOptimizer.
+/// extern "C" helps, because dlopen() interface uses name to find the symbol.
+extern "C"
+llvm::LinkTimeOptimizer *createLLVMOptimizer();
+
+#endif