166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//===-LTOCodeGenerator.h - LLVM Link Time Optimizer -----------------------===// 266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// The LLVM Compiler Infrastructure 466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// This file is distributed under the University of Illinois Open Source 666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// License. See LICENSE.TXT for details. 766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//===----------------------------------------------------------------------===// 966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 1066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// This file declares the LTOCodeGenerator class. 1166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 1266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//===----------------------------------------------------------------------===// 1366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 1466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 1566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#ifndef LTO_CODE_GENERATOR_H 1666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#define LTO_CODE_GENERATOR_H 1766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 1866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Linker.h" 1966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/LLVMContext.h" 2066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/ADT/StringMap.h" 2166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/ADT/SmallVector.h" 2266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/ADT/SmallPtrSet.h" 2366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 2466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include <string> 2566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 2666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 2766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 2866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// C++ class which implements the opaque lto_code_gen_t 2966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 3066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 3166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumanstruct LTOCodeGenerator { 3266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static const char* getVersionString(); 3366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 3466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman LTOCodeGenerator(); 3566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ~LTOCodeGenerator(); 3666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 3766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool addModule(struct LTOModule*, std::string& errMsg); 3866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool setDebugInfo(lto_debug_model, std::string& errMsg); 3966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool setCodePICModel(lto_codegen_model, std::string& errMsg); 4066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void setCpu(const char *cpu); 4166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void addMustPreserveSymbol(const char* sym); 4266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool writeMergedModules(const char* path, 4366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman std::string& errMsg); 4466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool compile_to_file(const char** name, std::string& errMsg); 4566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman const void* compile(size_t* length, std::string& errMsg); 4666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void setCodeGenDebugOptions(const char *opts); 4766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumanprivate: 4866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool generateObjectFile(llvm::raw_ostream& out, 4966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman std::string& errMsg); 5066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void applyScopeRestrictions(); 5166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void applyRestriction(llvm::GlobalValue &GV, 5266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman std::vector<const char*> &mustPreserveList, 5366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman llvm::SmallPtrSet<llvm::GlobalValue*, 8> &asmUsed, 5466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman llvm::Mangler &mangler); 5566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool determineTarget(std::string& errMsg); 5666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 5766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman typedef llvm::StringMap<uint8_t> StringSet; 5866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 5966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman llvm::LLVMContext& _context; 6066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman llvm::Linker _linker; 6166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman llvm::TargetMachine* _target; 6266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool _emitDwarfDebugInfo; 6366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool _scopeRestrictionsDone; 6466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman lto_codegen_model _codeModel; 6566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman StringSet _mustPreserveSymbols; 6666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman StringSet _asmUndefinedRefs; 6766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman llvm::MemoryBuffer* _nativeObjectFile; 6866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman std::vector<const char*> _codegenOptions; 6966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman std::string _mCpu; 7066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman std::string _nativeObjectPath; 7166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman}; 7266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 7366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#endif // LTO_CODE_GENERATOR_H 7466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 75