blob: f8fd357df406061a9da1e07e9d0a8585d826d902 [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.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the LTOCodeGenerator class.
11//
12//===----------------------------------------------------------------------===//
13
14
15#ifndef LTO_CODE_GENERATOR_H
16#define LTO_CODE_GENERATOR_H
17
18#include "llvm/Linker.h"
Owen Anderson8b477ed2009-07-01 16:58:40 +000019#include "llvm/LLVMContext.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000020#include "llvm/ADT/StringMap.h"
Devang Patela93ae712008-07-03 22:53:14 +000021#include "llvm/ADT/SmallVector.h"
Rafael Espindola38c4e532011-03-02 04:14:42 +000022#include "llvm/ADT/SmallPtrSet.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000023
Nick Kledzikef194ed2008-02-27 22:25:36 +000024#include <string>
Nick Kledzik77595fc2008-02-26 20:26:43 +000025
26
27//
28// C++ class which implements the opaque lto_code_gen_t
29//
Owen Andersoncb371882008-08-21 00:14:44 +000030
Douglas Gregor1f291052009-12-23 17:05:07 +000031struct LTOCodeGenerator {
Nick Kledzik77595fc2008-02-26 20:26:43 +000032 static const char* getVersionString();
33
Owen Anderson0e7a5462009-07-02 00:31:14 +000034 LTOCodeGenerator();
Nick Kledzik77595fc2008-02-26 20:26:43 +000035 ~LTOCodeGenerator();
36
Douglas Gregor7aed4462009-12-23 18:27:13 +000037 bool addModule(struct LTOModule*, std::string& errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +000038 bool setDebugInfo(lto_debug_model, std::string& errMsg);
39 bool setCodePICModel(lto_codegen_model, std::string& errMsg);
Rafael Espindola2d643ef2010-08-11 00:15:13 +000040 void setCpu(const char *cpu);
Nick Kledzik77595fc2008-02-26 20:26:43 +000041 void addMustPreserveSymbol(const char* sym);
Nick Kledzikef194ed2008-02-27 22:25:36 +000042 bool writeMergedModules(const char* path,
43 std::string& errMsg);
Rafael Espindola6421a882011-03-22 20:57:13 +000044 bool compile_to_file(const char** name, std::string& errMsg);
Nick Kledzikef194ed2008-02-27 22:25:36 +000045 const void* compile(size_t* length, std::string& errMsg);
Nick Kledzik920ae982008-07-08 21:14:10 +000046 void setCodeGenDebugOptions(const char *opts);
Nick Kledzik77595fc2008-02-26 20:26:43 +000047private:
Rafael Espindolae9efea12011-02-24 21:04:06 +000048 bool generateObjectFile(llvm::raw_ostream& out,
49 std::string& errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +000050 void applyScopeRestrictions();
Rafael Espindola38c4e532011-03-02 04:14:42 +000051 void applyRestriction(llvm::GlobalValue &GV,
52 std::vector<const char*> &mustPreserveList,
53 llvm::SmallPtrSet<llvm::GlobalValue*, 8> &asmUsed,
54 llvm::Mangler &mangler);
Nick Kledzik77595fc2008-02-26 20:26:43 +000055 bool determineTarget(std::string& errMsg);
56
57 typedef llvm::StringMap<uint8_t> StringSet;
58
Owen Anderson4434ed42009-07-01 23:13:44 +000059 llvm::LLVMContext& _context;
Nick Kledzik77595fc2008-02-26 20:26:43 +000060 llvm::Linker _linker;
61 llvm::TargetMachine* _target;
62 bool _emitDwarfDebugInfo;
63 bool _scopeRestrictionsDone;
64 lto_codegen_model _codeModel;
65 StringSet _mustPreserveSymbols;
Rafael Espindola38c4e532011-03-02 04:14:42 +000066 StringSet _asmUndefinedRefs;
Nick Kledzikef194ed2008-02-27 22:25:36 +000067 llvm::MemoryBuffer* _nativeObjectFile;
Nick Kledzik920ae982008-07-08 21:14:10 +000068 std::vector<const char*> _codegenOptions;
Rafael Espindola2d643ef2010-08-11 00:15:13 +000069 std::string _mCpu;
Rafael Espindola6421a882011-03-22 20:57:13 +000070 std::string _nativeObjectPath;
Nick Kledzik77595fc2008-02-26 20:26:43 +000071};
72
73#endif // LTO_CODE_GENERATOR_H
74