blob: 71593a5039bba3643d4d3b5ea8033f886b226b41 [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"
Nick Kledzik77595fc2008-02-26 20:26:43 +000022
Nick Kledzikef194ed2008-02-27 22:25:36 +000023#include <string>
Nick Kledzik77595fc2008-02-26 20:26:43 +000024
25
26//
27// C++ class which implements the opaque lto_code_gen_t
28//
Owen Andersoncb371882008-08-21 00:14:44 +000029
Douglas Gregor1f291052009-12-23 17:05:07 +000030struct LTOCodeGenerator {
Nick Kledzik77595fc2008-02-26 20:26:43 +000031 static const char* getVersionString();
32
Owen Anderson0e7a5462009-07-02 00:31:14 +000033 LTOCodeGenerator();
Nick Kledzik77595fc2008-02-26 20:26:43 +000034 ~LTOCodeGenerator();
35
Douglas Gregor7aed4462009-12-23 18:27:13 +000036 bool addModule(struct LTOModule*, std::string& errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +000037 bool setDebugInfo(lto_debug_model, std::string& errMsg);
38 bool setCodePICModel(lto_codegen_model, std::string& errMsg);
Rafael Espindola2d643ef2010-08-11 00:15:13 +000039 void setCpu(const char *cpu);
Nick Kledzikcbad5862009-06-04 00:28:45 +000040 void setAssemblerPath(const char* path);
Rafael Espindola98197e52010-08-10 18:55:09 +000041 void setAssemblerArgs(const char** args, int nargs);
Nick Kledzik77595fc2008-02-26 20:26:43 +000042 void addMustPreserveSymbol(const char* sym);
Nick Kledzikef194ed2008-02-27 22:25:36 +000043 bool writeMergedModules(const char* path,
44 std::string& errMsg);
45 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:
David Greene71847812009-07-14 20:18:05 +000048 bool generateAssemblyCode(llvm::formatted_raw_ostream& out,
Owen Andersoncb371882008-08-21 00:14:44 +000049 std::string& errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +000050 bool assemble(const std::string& asmPath,
51 const std::string& objPath, std::string& errMsg);
52 void applyScopeRestrictions();
53 bool determineTarget(std::string& errMsg);
54
55 typedef llvm::StringMap<uint8_t> StringSet;
56
Owen Anderson4434ed42009-07-01 23:13:44 +000057 llvm::LLVMContext& _context;
Nick Kledzik77595fc2008-02-26 20:26:43 +000058 llvm::Linker _linker;
59 llvm::TargetMachine* _target;
60 bool _emitDwarfDebugInfo;
61 bool _scopeRestrictionsDone;
62 lto_codegen_model _codeModel;
63 StringSet _mustPreserveSymbols;
Nick Kledzikef194ed2008-02-27 22:25:36 +000064 llvm::MemoryBuffer* _nativeObjectFile;
Nick Kledzik920ae982008-07-08 21:14:10 +000065 std::vector<const char*> _codegenOptions;
Nick Kledzikcbad5862009-06-04 00:28:45 +000066 llvm::sys::Path* _assemblerPath;
Rafael Espindola2d643ef2010-08-11 00:15:13 +000067 std::string _mCpu;
Rafael Espindola98197e52010-08-10 18:55:09 +000068 std::vector<std::string> _assemblerArgs;
Nick Kledzik77595fc2008-02-26 20:26:43 +000069};
70
71#endif // LTO_CODE_GENERATOR_H
72