blob: 1b3bc0936b2086bf188694e3071300083c0abf85 [file] [log] [blame]
Nick Kledzik77595fc2008-02-26 20:26:43 +00001//===-LTOCodeGenerator.h - LLVM Link Time Optimizer -----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Nick Kledzik77595fc2008-02-26 20:26:43 +00007//
8//===----------------------------------------------------------------------===//
Bill Wendlingab53bc72012-03-31 11:10:35 +00009//
10// This file declares the LTOCodeGenerator class.
11//
12//===----------------------------------------------------------------------===//
Nick Kledzik77595fc2008-02-26 20:26:43 +000013
14#ifndef LTO_CODE_GENERATOR_H
15#define LTO_CODE_GENERATOR_H
16
17#include "llvm/Linker.h"
18#include "llvm/ADT/StringMap.h"
Rafael Espindola38c4e532011-03-02 04:14:42 +000019#include "llvm/ADT/SmallPtrSet.h"
Bill Wendlingab53bc72012-03-31 11:10:35 +000020#include "llvm-c/lto.h"
Nick Kledzikef194ed2008-02-27 22:25:36 +000021#include <string>
Nick Kledzik77595fc2008-02-26 20:26:43 +000022
Bill Wendlingab53bc72012-03-31 11:10:35 +000023namespace llvm {
24 class LLVMContext;
25 class GlobalValue;
26 class Mangler;
27 class MemoryBuffer;
28 class TargetMachine;
29 class raw_ostream;
30}
Nick Kledzik77595fc2008-02-26 20:26:43 +000031
Bill Wendlingab53bc72012-03-31 11:10:35 +000032//===----------------------------------------------------------------------===//
33/// LTOCodeGenerator - C++ class which implements the opaque lto_code_gen_t
34/// type.
35///
Douglas Gregor1f291052009-12-23 17:05:07 +000036struct LTOCodeGenerator {
Bill Wendlingab53bc72012-03-31 11:10:35 +000037 static const char *getVersionString();
Nick Kledzik77595fc2008-02-26 20:26:43 +000038
Bill Wendlingab53bc72012-03-31 11:10:35 +000039 LTOCodeGenerator();
40 ~LTOCodeGenerator();
41
42 bool addModule(struct LTOModule*, std::string &errMsg);
43 bool setDebugInfo(lto_debug_model, std::string &errMsg);
44 bool setCodePICModel(lto_codegen_model, std::string &errMsg);
45 void setCpu(const char *cpu);
46 void addMustPreserveSymbol(const char *sym);
47 bool writeMergedModules(const char *path, std::string &errMsg);
48 bool compile_to_file(const char **name, std::string &errMsg);
49 const void *compile(size_t *length, std::string &errMsg);
50 void setCodeGenDebugOptions(const char *opts);
51
52private:
53 bool generateObjectFile(llvm::raw_ostream &out, std::string &errMsg);
54 void applyScopeRestrictions();
55 void applyRestriction(llvm::GlobalValue &GV,
56 std::vector<const char*> &mustPreserveList,
57 llvm::SmallPtrSet<llvm::GlobalValue*, 8> &asmUsed,
58 llvm::Mangler &mangler);
59 bool determineTarget(std::string &errMsg);
60
61 typedef llvm::StringMap<uint8_t> StringSet;
62
63 llvm::LLVMContext& _context;
64 llvm::Linker _linker;
65 llvm::TargetMachine* _target;
66 bool _emitDwarfDebugInfo;
67 bool _scopeRestrictionsDone;
68 lto_codegen_model _codeModel;
69 StringSet _mustPreserveSymbols;
70 StringSet _asmUndefinedRefs;
71 llvm::MemoryBuffer* _nativeObjectFile;
72 std::vector<char*> _codegenOptions;
73 std::string _mCpu;
74 std::string _nativeObjectPath;
Nick Kledzik77595fc2008-02-26 20:26:43 +000075};
76
77#endif // LTO_CODE_GENERATOR_H