Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 1 | //===-lto.cpp - 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. |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 7 | // |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 10 | // This file implements the Link Time Optimization library. This library is |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 11 | // intended to be used by linker to optimize code at link time. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm-c/lto.h" |
Rafael Espindola | 0b385c7 | 2013-09-30 16:39:19 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/CommandFlags.h" |
Peter Collingbourne | 4ccf0f1 | 2013-09-24 23:52:22 +0000 | [diff] [blame] | 17 | #include "llvm/LTO/LTOCodeGenerator.h" |
| 18 | #include "llvm/LTO/LTOModule.h" |
Alp Toker | ac90380 | 2014-07-04 00:58:41 +0000 | [diff] [blame] | 19 | #include "llvm/Support/MemoryBuffer.h" |
Rafael Espindola | 77c50d2 | 2014-06-19 19:11:22 +0000 | [diff] [blame] | 20 | #include "llvm/Support/TargetSelect.h" |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 21 | |
Rafael Espindola | 0b385c7 | 2013-09-30 16:39:19 +0000 | [diff] [blame] | 22 | // extra command-line flags needed for LTOCodeGenerator |
| 23 | static cl::opt<bool> |
| 24 | DisableOpt("disable-opt", cl::init(false), |
| 25 | cl::desc("Do not run any optimization passes")); |
| 26 | |
| 27 | static cl::opt<bool> |
| 28 | DisableInline("disable-inlining", cl::init(false), |
| 29 | cl::desc("Do not run the inliner pass")); |
| 30 | |
| 31 | static cl::opt<bool> |
| 32 | DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false), |
| 33 | cl::desc("Do not run the GVN load PRE pass")); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 34 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 35 | // Holds most recent error string. |
| 36 | // *** Not thread safe *** |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 37 | static std::string sLastErrorString; |
| 38 | |
Peter Collingbourne | 4ccf0f1 | 2013-09-24 23:52:22 +0000 | [diff] [blame] | 39 | // Holds the initialization state of the LTO module. |
| 40 | // *** Not thread safe *** |
| 41 | static bool initialized = false; |
| 42 | |
Rafael Espindola | efa02d5 | 2013-10-02 14:36:23 +0000 | [diff] [blame] | 43 | // Holds the command-line option parsing state of the LTO module. |
| 44 | static bool parsedOptions = false; |
| 45 | |
Peter Collingbourne | 4ccf0f1 | 2013-09-24 23:52:22 +0000 | [diff] [blame] | 46 | // Initialize the configured targets if they have not been initialized. |
| 47 | static void lto_initialize() { |
| 48 | if (!initialized) { |
Rafael Espindola | 77c50d2 | 2014-06-19 19:11:22 +0000 | [diff] [blame] | 49 | InitializeAllTargetInfos(); |
| 50 | InitializeAllTargets(); |
| 51 | InitializeAllTargetMCs(); |
| 52 | InitializeAllAsmParsers(); |
| 53 | InitializeAllAsmPrinters(); |
| 54 | InitializeAllDisassemblers(); |
Peter Collingbourne | 4ccf0f1 | 2013-09-24 23:52:22 +0000 | [diff] [blame] | 55 | initialized = true; |
| 56 | } |
| 57 | } |
| 58 | |
Patrik Hagglund | 9be9d87 | 2014-05-05 12:24:08 +0000 | [diff] [blame] | 59 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LTOCodeGenerator, lto_code_gen_t) |
| 60 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LTOModule, lto_module_t) |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 61 | |
Tom Roeder | fd1bc60 | 2014-04-25 21:46:51 +0000 | [diff] [blame] | 62 | // Convert the subtarget features into a string to pass to LTOCodeGenerator. |
| 63 | static void lto_add_attrs(lto_code_gen_t cg) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 64 | LTOCodeGenerator *CG = unwrap(cg); |
Tom Roeder | fd1bc60 | 2014-04-25 21:46:51 +0000 | [diff] [blame] | 65 | if (MAttrs.size()) { |
| 66 | std::string attrs; |
| 67 | for (unsigned i = 0; i < MAttrs.size(); ++i) { |
| 68 | if (i > 0) |
| 69 | attrs.append(","); |
| 70 | attrs.append(MAttrs[i]); |
| 71 | } |
| 72 | |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 73 | CG->setAttr(attrs.c_str()); |
Tom Roeder | fd1bc60 | 2014-04-25 21:46:51 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 77 | extern const char* lto_get_version() { |
| 78 | return LTOCodeGenerator::getVersionString(); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 81 | const char* lto_get_error_message() { |
| 82 | return sLastErrorString.c_str(); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Reid Kleckner | ddac151 | 2013-10-24 22:26:04 +0000 | [diff] [blame] | 85 | bool lto_module_is_object_file(const char* path) { |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 86 | return LTOModule::isBitcodeFile(path); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Reid Kleckner | ddac151 | 2013-10-24 22:26:04 +0000 | [diff] [blame] | 89 | bool lto_module_is_object_file_for_target(const char* path, |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 90 | const char* target_triplet_prefix) { |
Rafael Espindola | adf21f2 | 2014-07-06 17:43:13 +0000 | [diff] [blame] | 91 | ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer = MemoryBuffer::getFile(path); |
| 92 | if (!Buffer) |
Alp Toker | ac90380 | 2014-07-04 00:58:41 +0000 | [diff] [blame] | 93 | return false; |
Rafael Espindola | adf21f2 | 2014-07-06 17:43:13 +0000 | [diff] [blame] | 94 | return LTOModule::isBitcodeForTarget(Buffer->get(), target_triplet_prefix); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Reid Kleckner | ddac151 | 2013-10-24 22:26:04 +0000 | [diff] [blame] | 97 | bool lto_module_is_object_file_in_memory(const void* mem, size_t length) { |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 98 | return LTOModule::isBitcodeFile(mem, length); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Reid Kleckner | ddac151 | 2013-10-24 22:26:04 +0000 | [diff] [blame] | 101 | bool |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 102 | lto_module_is_object_file_in_memory_for_target(const void* mem, |
| 103 | size_t length, |
| 104 | const char* target_triplet_prefix) { |
Alp Toker | ac90380 | 2014-07-04 00:58:41 +0000 | [diff] [blame] | 105 | std::unique_ptr<MemoryBuffer> buffer(LTOModule::makeBuffer(mem, length)); |
| 106 | if (!buffer) |
| 107 | return false; |
| 108 | return LTOModule::isBitcodeForTarget(buffer.get(), target_triplet_prefix); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 111 | lto_module_t lto_module_create(const char* path) { |
Peter Collingbourne | 4ccf0f1 | 2013-09-24 23:52:22 +0000 | [diff] [blame] | 112 | lto_initialize(); |
Eli Bendersky | f0f2100 | 2014-02-19 17:09:35 +0000 | [diff] [blame] | 113 | llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); |
Peter Collingbourne | 63086fe | 2014-07-03 23:28:00 +0000 | [diff] [blame] | 114 | return wrap(LTOModule::createFromFile(path, Options, sLastErrorString)); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 117 | lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) { |
Peter Collingbourne | 4ccf0f1 | 2013-09-24 23:52:22 +0000 | [diff] [blame] | 118 | lto_initialize(); |
Eli Bendersky | f0f2100 | 2014-02-19 17:09:35 +0000 | [diff] [blame] | 119 | llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 120 | return wrap( |
Peter Collingbourne | 63086fe | 2014-07-03 23:28:00 +0000 | [diff] [blame] | 121 | LTOModule::createFromOpenFile(fd, path, size, Options, sLastErrorString)); |
Rafael Espindola | 56e41f7 | 2011-02-08 22:40:47 +0000 | [diff] [blame] | 122 | } |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 123 | |
Rafael Espindola | b39c7c7 | 2011-03-17 00:36:11 +0000 | [diff] [blame] | 124 | lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path, |
| 125 | size_t file_size, |
| 126 | size_t map_size, |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 127 | off_t offset) { |
Peter Collingbourne | 4ccf0f1 | 2013-09-24 23:52:22 +0000 | [diff] [blame] | 128 | lto_initialize(); |
Eli Bendersky | f0f2100 | 2014-02-19 17:09:35 +0000 | [diff] [blame] | 129 | llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); |
Peter Collingbourne | 63086fe | 2014-07-03 23:28:00 +0000 | [diff] [blame] | 130 | return wrap(LTOModule::createFromOpenFileSlice(fd, path, map_size, offset, |
| 131 | Options, sLastErrorString)); |
Rafael Espindola | b39c7c7 | 2011-03-17 00:36:11 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 134 | lto_module_t lto_module_create_from_memory(const void* mem, size_t length) { |
Peter Collingbourne | 4ccf0f1 | 2013-09-24 23:52:22 +0000 | [diff] [blame] | 135 | lto_initialize(); |
Eli Bendersky | f0f2100 | 2014-02-19 17:09:35 +0000 | [diff] [blame] | 136 | llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); |
Peter Collingbourne | 63086fe | 2014-07-03 23:28:00 +0000 | [diff] [blame] | 137 | return wrap(LTOModule::createFromBuffer(mem, length, Options, sLastErrorString)); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Manman Ren | 03456a1 | 2014-02-10 23:26:14 +0000 | [diff] [blame] | 140 | lto_module_t lto_module_create_from_memory_with_path(const void* mem, |
| 141 | size_t length, |
| 142 | const char *path) { |
| 143 | lto_initialize(); |
Eli Bendersky | f0f2100 | 2014-02-19 17:09:35 +0000 | [diff] [blame] | 144 | llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 145 | return wrap( |
Peter Collingbourne | 63086fe | 2014-07-03 23:28:00 +0000 | [diff] [blame] | 146 | LTOModule::createFromBuffer(mem, length, Options, sLastErrorString, path)); |
Manman Ren | 03456a1 | 2014-02-10 23:26:14 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 149 | void lto_module_dispose(lto_module_t mod) { delete unwrap(mod); } |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 150 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 151 | const char* lto_module_get_target_triple(lto_module_t mod) { |
Rafael Espindola | d749fb5 | 2014-07-04 14:19:41 +0000 | [diff] [blame] | 152 | return unwrap(mod)->getTargetTriple().c_str(); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 155 | void lto_module_set_target_triple(lto_module_t mod, const char *triple) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 156 | return unwrap(mod)->setTargetTriple(triple); |
Rafael Espindola | 4ef89f5 | 2010-08-09 21:09:46 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 159 | unsigned int lto_module_get_num_symbols(lto_module_t mod) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 160 | return unwrap(mod)->getSymbolCount(); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 163 | const char* lto_module_get_symbol_name(lto_module_t mod, unsigned int index) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 164 | return unwrap(mod)->getSymbolName(index); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 167 | lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod, |
| 168 | unsigned int index) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 169 | return unwrap(mod)->getSymbolAttributes(index); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Yunzhong Gao | a88d7ab | 2014-01-21 18:31:27 +0000 | [diff] [blame] | 172 | unsigned int lto_module_get_num_deplibs(lto_module_t mod) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 173 | return unwrap(mod)->getDependentLibraryCount(); |
Yunzhong Gao | a88d7ab | 2014-01-21 18:31:27 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Yunzhong Gao | a88d7ab | 2014-01-21 18:31:27 +0000 | [diff] [blame] | 176 | const char* lto_module_get_deplib(lto_module_t mod, unsigned int index) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 177 | return unwrap(mod)->getDependentLibrary(index); |
Yunzhong Gao | a88d7ab | 2014-01-21 18:31:27 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Yunzhong Gao | a88d7ab | 2014-01-21 18:31:27 +0000 | [diff] [blame] | 180 | unsigned int lto_module_get_num_linkeropts(lto_module_t mod) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 181 | return unwrap(mod)->getLinkerOptCount(); |
Yunzhong Gao | a88d7ab | 2014-01-21 18:31:27 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Yunzhong Gao | a88d7ab | 2014-01-21 18:31:27 +0000 | [diff] [blame] | 184 | const char* lto_module_get_linkeropt(lto_module_t mod, unsigned int index) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 185 | return unwrap(mod)->getLinkerOpt(index); |
Yunzhong Gao | a88d7ab | 2014-01-21 18:31:27 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Quentin Colombet | 5fa1f6f | 2014-01-15 22:04:35 +0000 | [diff] [blame] | 188 | void lto_codegen_set_diagnostic_handler(lto_code_gen_t cg, |
| 189 | lto_diagnostic_handler_t diag_handler, |
| 190 | void *ctxt) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 191 | unwrap(cg)->setDiagnosticHandler(diag_handler, ctxt); |
Quentin Colombet | 5fa1f6f | 2014-01-15 22:04:35 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 194 | lto_code_gen_t lto_codegen_create(void) { |
Peter Collingbourne | 4ccf0f1 | 2013-09-24 23:52:22 +0000 | [diff] [blame] | 195 | lto_initialize(); |
Rafael Espindola | 0b385c7 | 2013-09-30 16:39:19 +0000 | [diff] [blame] | 196 | |
Eli Bendersky | f0f2100 | 2014-02-19 17:09:35 +0000 | [diff] [blame] | 197 | TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); |
Rafael Espindola | 0b385c7 | 2013-09-30 16:39:19 +0000 | [diff] [blame] | 198 | |
| 199 | LTOCodeGenerator *CodeGen = new LTOCodeGenerator(); |
| 200 | if (CodeGen) |
| 201 | CodeGen->setTargetOptions(Options); |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 202 | return wrap(CodeGen); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 205 | void lto_codegen_dispose(lto_code_gen_t cg) { delete unwrap(cg); } |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 206 | |
Reid Kleckner | ddac151 | 2013-10-24 22:26:04 +0000 | [diff] [blame] | 207 | bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 208 | return !unwrap(cg)->addModule(unwrap(mod), sLastErrorString); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Reid Kleckner | ddac151 | 2013-10-24 22:26:04 +0000 | [diff] [blame] | 211 | bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 212 | unwrap(cg)->setDebugInfo(debug); |
Shuxin Yang | b6696a9 | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 213 | return false; |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Reid Kleckner | ddac151 | 2013-10-24 22:26:04 +0000 | [diff] [blame] | 216 | bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 217 | unwrap(cg)->setCodePICModel(model); |
Shuxin Yang | b6696a9 | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 218 | return false; |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Bill Wendling | 152e473 | 2012-03-31 10:44:20 +0000 | [diff] [blame] | 221 | void lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 222 | return unwrap(cg)->setCpu(cpu); |
Rafael Espindola | ccab1dd | 2010-08-11 00:15:13 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 225 | void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char *path) { |
Rafael Espindola | fac373c | 2011-02-24 21:04:06 +0000 | [diff] [blame] | 226 | // In here only for backwards compatibility. We use MC now. |
Nick Kledzik | cac8c8a | 2009-06-04 00:28:45 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Bill Wendling | 152e473 | 2012-03-31 10:44:20 +0000 | [diff] [blame] | 229 | void lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args, |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 230 | int nargs) { |
Rafael Espindola | fac373c | 2011-02-24 21:04:06 +0000 | [diff] [blame] | 231 | // In here only for backwards compatibility. We use MC now. |
Rafael Espindola | 0045646 | 2010-08-10 18:55:09 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Bill Wendling | 36cbf03 | 2012-03-30 10:29:38 +0000 | [diff] [blame] | 234 | void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, |
Bill Wendling | 152e473 | 2012-03-31 10:44:20 +0000 | [diff] [blame] | 235 | const char *symbol) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 236 | unwrap(cg)->addMustPreserveSymbol(symbol); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Reid Kleckner | ddac151 | 2013-10-24 22:26:04 +0000 | [diff] [blame] | 239 | bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) { |
Rafael Espindola | efa02d5 | 2013-10-02 14:36:23 +0000 | [diff] [blame] | 240 | if (!parsedOptions) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 241 | unwrap(cg)->parseCodeGenDebugOptions(); |
Tom Roeder | fd1bc60 | 2014-04-25 21:46:51 +0000 | [diff] [blame] | 242 | lto_add_attrs(cg); |
Rafael Espindola | efa02d5 | 2013-10-02 14:36:23 +0000 | [diff] [blame] | 243 | parsedOptions = true; |
| 244 | } |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 245 | return !unwrap(cg)->writeMergedModules(path, sLastErrorString); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Bill Wendling | 152e473 | 2012-03-31 10:44:20 +0000 | [diff] [blame] | 248 | const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) { |
Rafael Espindola | efa02d5 | 2013-10-02 14:36:23 +0000 | [diff] [blame] | 249 | if (!parsedOptions) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 250 | unwrap(cg)->parseCodeGenDebugOptions(); |
Tom Roeder | fd1bc60 | 2014-04-25 21:46:51 +0000 | [diff] [blame] | 251 | lto_add_attrs(cg); |
Rafael Espindola | efa02d5 | 2013-10-02 14:36:23 +0000 | [diff] [blame] | 252 | parsedOptions = true; |
| 253 | } |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 254 | return unwrap(cg)->compile(length, DisableOpt, DisableInline, |
| 255 | DisableGVNLoadPRE, sLastErrorString); |
Nick Kledzik | 07b4a62 | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Reid Kleckner | ddac151 | 2013-10-24 22:26:04 +0000 | [diff] [blame] | 258 | bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) { |
Rafael Espindola | efa02d5 | 2013-10-02 14:36:23 +0000 | [diff] [blame] | 259 | if (!parsedOptions) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 260 | unwrap(cg)->parseCodeGenDebugOptions(); |
Tom Roeder | fd1bc60 | 2014-04-25 21:46:51 +0000 | [diff] [blame] | 261 | lto_add_attrs(cg); |
Rafael Espindola | efa02d5 | 2013-10-02 14:36:23 +0000 | [diff] [blame] | 262 | parsedOptions = true; |
| 263 | } |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 264 | return !unwrap(cg)->compile_to_file(name, DisableOpt, DisableInline, |
| 265 | DisableGVNLoadPRE, sLastErrorString); |
Rafael Espindola | 26b57ff | 2011-03-22 20:57:13 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Bill Wendling | 152e473 | 2012-03-31 10:44:20 +0000 | [diff] [blame] | 268 | void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) { |
Rafael Espindola | 83ceb8e | 2014-05-03 14:59:52 +0000 | [diff] [blame] | 269 | unwrap(cg)->setCodeGenDebugOptions(opt); |
Duncan Sands | 31554ab | 2009-07-03 15:38:01 +0000 | [diff] [blame] | 270 | } |