Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 1 | //===-LTOCodeGenerator.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 | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 7 | // |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Bill Wendling | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 10 | // This file implements the Link Time Optimization library. This library is |
Nick Kledzik | 77595fc | 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 | |
Peter Collingbourne | cc48854 | 2013-09-24 23:52:22 +0000 | [diff] [blame^] | 15 | #include "llvm/LTO/LTOCodeGenerator.h" |
| 16 | #include "llvm/LTO/LTOModule.h" |
Chandler Carruth | f010c46 | 2012-12-04 10:44:52 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringExtras.h" |
Nick Lewycky | 8189d40 | 2009-06-17 06:52:10 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/Passes.h" |
Rafael Espindola | c684e83 | 2011-08-02 21:50:27 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/Verifier.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 20 | #include "llvm/Bitcode/ReaderWriter.h" |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 21 | #include "llvm/Config/config.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 22 | #include "llvm/IR/Constants.h" |
| 23 | #include "llvm/IR/DataLayout.h" |
| 24 | #include "llvm/IR/DerivedTypes.h" |
| 25 | #include "llvm/IR/LLVMContext.h" |
| 26 | #include "llvm/IR/Module.h" |
Shuxin Yang | 8945f75 | 2013-07-22 18:40:34 +0000 | [diff] [blame] | 27 | #include "llvm/InitializePasses.h" |
Chandler Carruth | f010c46 | 2012-12-04 10:44:52 +0000 | [diff] [blame] | 28 | #include "llvm/Linker.h" |
Chris Lattner | 5ef31a0 | 2010-03-12 18:44:54 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MCAsmInfo.h" |
| 30 | #include "llvm/MC/MCContext.h" |
Evan Cheng | ab8be96 | 2011-06-29 01:14:12 +0000 | [diff] [blame] | 31 | #include "llvm/MC/SubtargetFeature.h" |
Chandler Carruth | f010c46 | 2012-12-04 10:44:52 +0000 | [diff] [blame] | 32 | #include "llvm/PassManager.h" |
Nick Kledzik | 920ae98 | 2008-07-08 21:14:10 +0000 | [diff] [blame] | 33 | #include "llvm/Support/CommandLine.h" |
Rafael Espindola | 68c0efa | 2013-06-17 18:05:35 +0000 | [diff] [blame] | 34 | #include "llvm/Support/FileSystem.h" |
David Greene | 7184781 | 2009-07-14 20:18:05 +0000 | [diff] [blame] | 35 | #include "llvm/Support/FormattedStream.h" |
Michael J. Spencer | 3cc52ea | 2010-11-29 18:47:54 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Host.h" |
Chandler Carruth | f010c46 | 2012-12-04 10:44:52 +0000 | [diff] [blame] | 37 | #include "llvm/Support/MemoryBuffer.h" |
Michael J. Spencer | 3cc52ea | 2010-11-29 18:47:54 +0000 | [diff] [blame] | 38 | #include "llvm/Support/Signals.h" |
Evan Cheng | 3e74d6f | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 39 | #include "llvm/Support/TargetRegistry.h" |
| 40 | #include "llvm/Support/TargetSelect.h" |
Chandler Carruth | f010c46 | 2012-12-04 10:44:52 +0000 | [diff] [blame] | 41 | #include "llvm/Support/ToolOutputFile.h" |
Michael J. Spencer | f2f516f | 2010-12-09 18:06:07 +0000 | [diff] [blame] | 42 | #include "llvm/Support/system_error.h" |
Chandler Carruth | f010c46 | 2012-12-04 10:44:52 +0000 | [diff] [blame] | 43 | #include "llvm/Target/TargetRegisterInfo.h" |
Peter Collingbourne | cc48854 | 2013-09-24 23:52:22 +0000 | [diff] [blame^] | 44 | #include "llvm/Target/Mangler.h" |
Chandler Carruth | f010c46 | 2012-12-04 10:44:52 +0000 | [diff] [blame] | 45 | #include "llvm/Transforms/IPO.h" |
| 46 | #include "llvm/Transforms/IPO/PassManagerBuilder.h" |
Bob Wilson | d696544 | 2013-03-29 23:28:55 +0000 | [diff] [blame] | 47 | #include "llvm/Transforms/ObjCARC.h" |
Shuxin Yang | 67d135a | 2013-08-12 18:29:43 +0000 | [diff] [blame] | 48 | using namespace llvm; |
Shuxin Yang | 67d135a | 2013-08-12 18:29:43 +0000 | [diff] [blame] | 49 | |
Bill Wendling | 9ac0aaa | 2012-08-06 21:34:54 +0000 | [diff] [blame] | 50 | static cl::opt<bool> |
Bill Wendling | 6303b66 | 2013-02-28 14:11:10 +0000 | [diff] [blame] | 51 | DisableOpt("disable-opt", cl::init(false), |
| 52 | cl::desc("Do not run any optimization passes")); |
| 53 | |
| 54 | static cl::opt<bool> |
Bill Wendling | 9ac0aaa | 2012-08-06 21:34:54 +0000 | [diff] [blame] | 55 | DisableInline("disable-inlining", cl::init(false), |
Nick Kledzik | 920ae98 | 2008-07-08 21:14:10 +0000 | [diff] [blame] | 56 | cl::desc("Do not run the inliner pass")); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 57 | |
Bill Wendling | 9ac0aaa | 2012-08-06 21:34:54 +0000 | [diff] [blame] | 58 | static cl::opt<bool> |
| 59 | DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false), |
Bill Wendling | 3197b44 | 2012-04-02 22:16:50 +0000 | [diff] [blame] | 60 | cl::desc("Do not run the GVN load PRE pass")); |
| 61 | |
Bill Wendling | caf71d4 | 2012-03-31 10:49:43 +0000 | [diff] [blame] | 62 | const char* LTOCodeGenerator::getVersionString() { |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 63 | #ifdef LLVM_VERSION_INFO |
Bill Wendling | caf71d4 | 2012-03-31 10:49:43 +0000 | [diff] [blame] | 64 | return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 65 | #else |
Bill Wendling | caf71d4 | 2012-03-31 10:49:43 +0000 | [diff] [blame] | 66 | return PACKAGE_NAME " version " PACKAGE_VERSION; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 67 | #endif |
| 68 | } |
| 69 | |
Bill Wendling | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 70 | LTOCodeGenerator::LTOCodeGenerator() |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 71 | : Context(getGlobalContext()), Linker(new Module("ld-temp.o", Context)), |
| 72 | TargetMach(NULL), EmitDwarfDebugInfo(false), ScopeRestrictionsDone(false), |
| 73 | CodeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), NativeObjectFile(NULL) { |
Shuxin Yang | 8945f75 | 2013-07-22 18:40:34 +0000 | [diff] [blame] | 74 | initializeLTOPasses(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Bill Wendling | caf71d4 | 2012-03-31 10:49:43 +0000 | [diff] [blame] | 77 | LTOCodeGenerator::~LTOCodeGenerator() { |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 78 | delete TargetMach; |
| 79 | delete NativeObjectFile; |
| 80 | delete Linker.getModule(); |
Bill Wendling | caf71d4 | 2012-03-31 10:49:43 +0000 | [diff] [blame] | 81 | |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 82 | for (std::vector<char *>::iterator I = CodegenOptions.begin(), |
| 83 | E = CodegenOptions.end(); |
| 84 | I != E; ++I) |
Bill Wendling | caf71d4 | 2012-03-31 10:49:43 +0000 | [diff] [blame] | 85 | free(*I); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Shuxin Yang | 8945f75 | 2013-07-22 18:40:34 +0000 | [diff] [blame] | 88 | // Initialize LTO passes. Please keep this funciton in sync with |
Shuxin Yang | c679d6b | 2013-07-23 06:44:34 +0000 | [diff] [blame] | 89 | // PassManagerBuilder::populateLTOPassManager(), and make sure all LTO |
Shuxin Yang | 8945f75 | 2013-07-22 18:40:34 +0000 | [diff] [blame] | 90 | // passes are initialized. |
| 91 | // |
| 92 | void LTOCodeGenerator::initializeLTOPasses() { |
| 93 | PassRegistry &R = *PassRegistry::getPassRegistry(); |
| 94 | |
| 95 | initializeInternalizePassPass(R); |
| 96 | initializeIPSCCPPass(R); |
| 97 | initializeGlobalOptPass(R); |
| 98 | initializeConstantMergePass(R); |
| 99 | initializeDAHPass(R); |
| 100 | initializeInstCombinerPass(R); |
| 101 | initializeSimpleInlinerPass(R); |
| 102 | initializePruneEHPass(R); |
| 103 | initializeGlobalDCEPass(R); |
| 104 | initializeArgPromotionPass(R); |
| 105 | initializeJumpThreadingPass(R); |
| 106 | initializeSROAPass(R); |
| 107 | initializeSROA_DTPass(R); |
| 108 | initializeSROA_SSAUpPass(R); |
| 109 | initializeFunctionAttrsPass(R); |
| 110 | initializeGlobalsModRefPass(R); |
| 111 | initializeLICMPass(R); |
| 112 | initializeGVNPass(R); |
| 113 | initializeMemCpyOptPass(R); |
| 114 | initializeDCEPass(R); |
Tom Stellard | 01d7203 | 2013-08-06 02:43:45 +0000 | [diff] [blame] | 115 | initializeCFGSimplifyPassPass(R); |
Shuxin Yang | 8945f75 | 2013-07-22 18:40:34 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 118 | bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) { |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 119 | bool ret = Linker.linkInModule(mod->getLLVVMModule(), &errMsg); |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 120 | |
| 121 | const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs(); |
| 122 | for (int i = 0, e = undefs.size(); i != e; ++i) |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 123 | AsmUndefinedRefs[undefs[i]] = 1; |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 124 | |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 125 | return !ret; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 126 | } |
Bill Wendling | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 127 | |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 128 | void LTOCodeGenerator::setDebugInfo(lto_debug_model debug) { |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 129 | switch (debug) { |
| 130 | case LTO_DEBUG_MODEL_NONE: |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 131 | EmitDwarfDebugInfo = false; |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 132 | return; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 133 | |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 134 | case LTO_DEBUG_MODEL_DWARF: |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 135 | EmitDwarfDebugInfo = true; |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 136 | return; |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 137 | } |
| 138 | llvm_unreachable("Unknown debug format!"); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 141 | void LTOCodeGenerator::setCodePICModel(lto_codegen_model model) { |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 142 | switch (model) { |
| 143 | case LTO_CODEGEN_PIC_MODEL_STATIC: |
| 144 | case LTO_CODEGEN_PIC_MODEL_DYNAMIC: |
| 145 | case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 146 | CodeModel = model; |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 147 | return; |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 148 | } |
| 149 | llvm_unreachable("Unknown PIC model!"); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Chris Lattner | b515d75 | 2009-08-23 07:49:08 +0000 | [diff] [blame] | 152 | bool LTOCodeGenerator::writeMergedModules(const char *path, |
| 153 | std::string &errMsg) { |
Shuxin Yang | 0880939 | 2013-08-06 21:51:21 +0000 | [diff] [blame] | 154 | if (!determineTarget(errMsg)) |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 155 | return false; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 156 | |
Bill Wendling | 6ba2ed5 | 2013-08-08 23:51:04 +0000 | [diff] [blame] | 157 | // mark which symbols can not be internalized |
| 158 | applyScopeRestrictions(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 159 | |
Chris Lattner | b515d75 | 2009-08-23 07:49:08 +0000 | [diff] [blame] | 160 | // create output file |
| 161 | std::string ErrInfo; |
Rafael Espindola | c1b49b5 | 2013-07-16 19:44:17 +0000 | [diff] [blame] | 162 | tool_output_file Out(path, ErrInfo, sys::fs::F_Binary); |
Chris Lattner | b515d75 | 2009-08-23 07:49:08 +0000 | [diff] [blame] | 163 | if (!ErrInfo.empty()) { |
| 164 | errMsg = "could not open bitcode file for writing: "; |
| 165 | errMsg += path; |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 166 | return false; |
Chris Lattner | b515d75 | 2009-08-23 07:49:08 +0000 | [diff] [blame] | 167 | } |
Bill Wendling | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 168 | |
Chris Lattner | b515d75 | 2009-08-23 07:49:08 +0000 | [diff] [blame] | 169 | // write bitcode to it |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 170 | WriteBitcodeToFile(Linker.getModule(), Out.os()); |
Dan Gohman | d4c4543 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 171 | Out.os().close(); |
Dan Gohman | 4b7416b | 2010-05-27 20:19:47 +0000 | [diff] [blame] | 172 | |
Dan Gohman | d4c4543 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 173 | if (Out.os().has_error()) { |
Chris Lattner | b515d75 | 2009-08-23 07:49:08 +0000 | [diff] [blame] | 174 | errMsg = "could not write bitcode file: "; |
| 175 | errMsg += path; |
Dan Gohman | d4c4543 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 176 | Out.os().clear_error(); |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 177 | return false; |
Chris Lattner | b515d75 | 2009-08-23 07:49:08 +0000 | [diff] [blame] | 178 | } |
Bill Wendling | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 179 | |
Dan Gohman | f291401 | 2010-08-20 16:59:15 +0000 | [diff] [blame] | 180 | Out.keep(); |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 181 | return true; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 184 | bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) { |
| 185 | // make unique temp .o file to put generated object file |
| 186 | SmallString<128> Filename; |
| 187 | int FD; |
| 188 | error_code EC = sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filename); |
| 189 | if (EC) { |
| 190 | errMsg = EC.message(); |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 191 | return false; |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 192 | } |
Rafael Espindola | 6421a88 | 2011-03-22 20:57:13 +0000 | [diff] [blame] | 193 | |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 194 | // generate object file |
| 195 | tool_output_file objFile(Filename.c_str(), FD); |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 196 | |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 197 | bool genResult = generateObjectFile(objFile.os(), errMsg); |
| 198 | objFile.os().close(); |
| 199 | if (objFile.os().has_error()) { |
| 200 | objFile.os().clear_error(); |
| 201 | sys::fs::remove(Twine(Filename)); |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 202 | return false; |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 203 | } |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 204 | |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 205 | objFile.keep(); |
| 206 | if (!genResult) { |
| 207 | sys::fs::remove(Twine(Filename)); |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 208 | return false; |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 209 | } |
Rafael Espindola | 6421a88 | 2011-03-22 20:57:13 +0000 | [diff] [blame] | 210 | |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 211 | NativeObjectPath = Filename.c_str(); |
| 212 | *name = NativeObjectPath.c_str(); |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 213 | return true; |
Rafael Espindola | 6421a88 | 2011-03-22 20:57:13 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 216 | const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) { |
Rafael Espindola | 6421a88 | 2011-03-22 20:57:13 +0000 | [diff] [blame] | 217 | const char *name; |
Shuxin Yang | 235089b | 2013-08-07 05:19:23 +0000 | [diff] [blame] | 218 | if (!compile_to_file(&name, errMsg)) |
Rafael Espindola | 6421a88 | 2011-03-22 20:57:13 +0000 | [diff] [blame] | 219 | return NULL; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 220 | |
Rafael Espindola | 6421a88 | 2011-03-22 20:57:13 +0000 | [diff] [blame] | 221 | // remove old buffer if compile() called twice |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 222 | delete NativeObjectFile; |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 223 | |
Rafael Espindola | 6421a88 | 2011-03-22 20:57:13 +0000 | [diff] [blame] | 224 | // read .o file into memory buffer |
| 225 | OwningPtr<MemoryBuffer> BuffPtr; |
| 226 | if (error_code ec = MemoryBuffer::getFile(name, BuffPtr, -1, false)) { |
| 227 | errMsg = ec.message(); |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 228 | sys::fs::remove(NativeObjectPath); |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 229 | return NULL; |
Rafael Espindola | 6421a88 | 2011-03-22 20:57:13 +0000 | [diff] [blame] | 230 | } |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 231 | NativeObjectFile = BuffPtr.take(); |
Rafael Espindola | e9efea1 | 2011-02-24 21:04:06 +0000 | [diff] [blame] | 232 | |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 233 | // remove temp files |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 234 | sys::fs::remove(NativeObjectPath); |
Rafael Espindola | e9efea1 | 2011-02-24 21:04:06 +0000 | [diff] [blame] | 235 | |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 236 | // return buffer, unless error |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 237 | if (NativeObjectFile == NULL) |
Shuxin Yang | cfaa636 | 2013-08-12 21:07:31 +0000 | [diff] [blame] | 238 | return NULL; |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 239 | *length = NativeObjectFile->getBufferSize(); |
| 240 | return NativeObjectFile->getBufferStart(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Bill Wendling | 8c18a6f | 2013-05-23 21:21:50 +0000 | [diff] [blame] | 243 | bool LTOCodeGenerator::determineTarget(std::string &errMsg) { |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 244 | if (TargetMach != NULL) |
Shuxin Yang | 0880939 | 2013-08-06 21:51:21 +0000 | [diff] [blame] | 245 | return true; |
Daniel Dunbar | 3c2d4bf | 2009-08-03 04:03:51 +0000 | [diff] [blame] | 246 | |
Bill Wendling | 8c18a6f | 2013-05-23 21:21:50 +0000 | [diff] [blame] | 247 | // if options were requested, set them |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 248 | if (!CodegenOptions.empty()) |
| 249 | cl::ParseCommandLineOptions(CodegenOptions.size(), |
| 250 | const_cast<char **>(&CodegenOptions[0])); |
Bill Wendling | 8c18a6f | 2013-05-23 21:21:50 +0000 | [diff] [blame] | 251 | |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 252 | std::string TripleStr = Linker.getModule()->getTargetTriple(); |
Bob Wilson | 47ed8a1 | 2012-10-12 17:39:25 +0000 | [diff] [blame] | 253 | if (TripleStr.empty()) |
| 254 | TripleStr = sys::getDefaultTargetTriple(); |
| 255 | llvm::Triple Triple(TripleStr); |
Bill Wendling | 604a818 | 2008-06-18 06:35:30 +0000 | [diff] [blame] | 256 | |
Bill Wendling | eda3fc6 | 2012-08-06 22:52:45 +0000 | [diff] [blame] | 257 | // create target machine from info for merged modules |
Bob Wilson | 47ed8a1 | 2012-10-12 17:39:25 +0000 | [diff] [blame] | 258 | const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg); |
Bill Wendling | 0ca36af | 2012-08-08 22:03:50 +0000 | [diff] [blame] | 259 | if (march == NULL) |
Shuxin Yang | 0880939 | 2013-08-06 21:51:21 +0000 | [diff] [blame] | 260 | return false; |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 261 | |
Bill Wendling | eda3fc6 | 2012-08-06 22:52:45 +0000 | [diff] [blame] | 262 | // The relocation model is actually a static member of TargetMachine and |
| 263 | // needs to be set before the TargetMachine is instantiated. |
| 264 | Reloc::Model RelocModel = Reloc::Default; |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 265 | switch (CodeModel) { |
Bill Wendling | eda3fc6 | 2012-08-06 22:52:45 +0000 | [diff] [blame] | 266 | case LTO_CODEGEN_PIC_MODEL_STATIC: |
| 267 | RelocModel = Reloc::Static; |
| 268 | break; |
| 269 | case LTO_CODEGEN_PIC_MODEL_DYNAMIC: |
| 270 | RelocModel = Reloc::PIC_; |
| 271 | break; |
| 272 | case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: |
| 273 | RelocModel = Reloc::DynamicNoPIC; |
| 274 | break; |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 275 | } |
Bill Wendling | eda3fc6 | 2012-08-06 22:52:45 +0000 | [diff] [blame] | 276 | |
| 277 | // construct LTOModule, hand over ownership of module and target |
| 278 | SubtargetFeatures Features; |
Bob Wilson | 47ed8a1 | 2012-10-12 17:39:25 +0000 | [diff] [blame] | 279 | Features.getDefaultSubtargetFeatures(Triple); |
Bill Wendling | eda3fc6 | 2012-08-06 22:52:45 +0000 | [diff] [blame] | 280 | std::string FeatureStr = Features.getString(); |
Bob Wilson | 47ed8a1 | 2012-10-12 17:39:25 +0000 | [diff] [blame] | 281 | // Set a default CPU for Darwin triples. |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 282 | if (MCpu.empty() && Triple.isOSDarwin()) { |
Bob Wilson | 47ed8a1 | 2012-10-12 17:39:25 +0000 | [diff] [blame] | 283 | if (Triple.getArch() == llvm::Triple::x86_64) |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 284 | MCpu = "core2"; |
Bob Wilson | 47ed8a1 | 2012-10-12 17:39:25 +0000 | [diff] [blame] | 285 | else if (Triple.getArch() == llvm::Triple::x86) |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 286 | MCpu = "yonah"; |
Bob Wilson | 47ed8a1 | 2012-10-12 17:39:25 +0000 | [diff] [blame] | 287 | } |
Bill Wendling | eda3fc6 | 2012-08-06 22:52:45 +0000 | [diff] [blame] | 288 | TargetOptions Options; |
| 289 | LTOModule::getTargetOptions(Options); |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 290 | TargetMach = march->createTargetMachine(TripleStr, MCpu, FeatureStr, Options, |
| 291 | RelocModel, CodeModel::Default, |
| 292 | CodeGenOpt::Aggressive); |
Shuxin Yang | 0880939 | 2013-08-06 21:51:21 +0000 | [diff] [blame] | 293 | return true; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 296 | void LTOCodeGenerator:: |
| 297 | applyRestriction(GlobalValue &GV, |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 298 | std::vector<const char*> &MustPreserveList, |
| 299 | SmallPtrSet<GlobalValue*, 8> &AsmUsed, |
| 300 | Mangler &Mangler) { |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 301 | SmallString<64> Buffer; |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 302 | Mangler.getNameWithPrefix(Buffer, &GV, false); |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 303 | |
| 304 | if (GV.isDeclaration()) |
| 305 | return; |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 306 | if (MustPreserveSymbols.count(Buffer)) |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 307 | MustPreserveList.push_back(GV.getName().data()); |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 308 | if (AsmUndefinedRefs.count(Buffer)) |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 309 | AsmUsed.insert(&GV); |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static void findUsedValues(GlobalVariable *LLVMUsed, |
| 313 | SmallPtrSet<GlobalValue*, 8> &UsedValues) { |
| 314 | if (LLVMUsed == 0) return; |
| 315 | |
Rafael Espindola | d4ee392 | 2013-04-24 17:54:35 +0000 | [diff] [blame] | 316 | ConstantArray *Inits = cast<ConstantArray>(LLVMUsed->getInitializer()); |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 317 | for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i) |
Bill Wendling | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 318 | if (GlobalValue *GV = |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 319 | dyn_cast<GlobalValue>(Inits->getOperand(i)->stripPointerCasts())) |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 320 | UsedValues.insert(GV); |
| 321 | } |
| 322 | |
Chris Lattner | 5ef31a0 | 2010-03-12 18:44:54 +0000 | [diff] [blame] | 323 | void LTOCodeGenerator::applyScopeRestrictions() { |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 324 | if (ScopeRestrictionsDone) |
| 325 | return; |
| 326 | Module *mergedModule = Linker.getModule(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 327 | |
Chris Lattner | 5ef31a0 | 2010-03-12 18:44:54 +0000 | [diff] [blame] | 328 | // Start off with a verification pass. |
| 329 | PassManager passes; |
| 330 | passes.add(createVerifierPass()); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 331 | |
Bill Wendling | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 332 | // mark which symbols can not be internalized |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 333 | MCContext MContext(TargetMach->getMCAsmInfo(), TargetMach->getRegisterInfo(), |
| 334 | NULL); |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 335 | Mangler Mangler(MContext, TargetMach); |
| 336 | std::vector<const char*> MustPreserveList; |
| 337 | SmallPtrSet<GlobalValue*, 8> AsmUsed; |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 338 | |
| 339 | for (Module::iterator f = mergedModule->begin(), |
| 340 | e = mergedModule->end(); f != e; ++f) |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 341 | applyRestriction(*f, MustPreserveList, AsmUsed, Mangler); |
Bill Wendling | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 342 | for (Module::global_iterator v = mergedModule->global_begin(), |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 343 | e = mergedModule->global_end(); v != e; ++v) |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 344 | applyRestriction(*v, MustPreserveList, AsmUsed, Mangler); |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 345 | for (Module::alias_iterator a = mergedModule->alias_begin(), |
| 346 | e = mergedModule->alias_end(); a != e; ++a) |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 347 | applyRestriction(*a, MustPreserveList, AsmUsed, Mangler); |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 348 | |
| 349 | GlobalVariable *LLVMCompilerUsed = |
| 350 | mergedModule->getGlobalVariable("llvm.compiler.used"); |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 351 | findUsedValues(LLVMCompilerUsed, AsmUsed); |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 352 | if (LLVMCompilerUsed) |
| 353 | LLVMCompilerUsed->eraseFromParent(); |
| 354 | |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 355 | if (!AsmUsed.empty()) { |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 356 | llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(Context); |
Rafael Espindola | d4ee392 | 2013-04-24 17:54:35 +0000 | [diff] [blame] | 357 | std::vector<Constant*> asmUsed2; |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 358 | for (SmallPtrSet<GlobalValue*, 16>::const_iterator i = AsmUsed.begin(), |
| 359 | e = AsmUsed.end(); i !=e; ++i) { |
Rafael Espindola | d4ee392 | 2013-04-24 17:54:35 +0000 | [diff] [blame] | 360 | GlobalValue *GV = *i; |
| 361 | Constant *c = ConstantExpr::getBitCast(GV, i8PTy); |
| 362 | asmUsed2.push_back(c); |
| 363 | } |
| 364 | |
| 365 | llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, asmUsed2.size()); |
| 366 | LLVMCompilerUsed = |
| 367 | new llvm::GlobalVariable(*mergedModule, ATy, false, |
| 368 | llvm::GlobalValue::AppendingLinkage, |
| 369 | llvm::ConstantArray::get(ATy, asmUsed2), |
| 370 | "llvm.compiler.used"); |
| 371 | |
| 372 | LLVMCompilerUsed->setSection("llvm.metadata"); |
Chris Lattner | 5ef31a0 | 2010-03-12 18:44:54 +0000 | [diff] [blame] | 373 | } |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 374 | |
Rafael Espindola | 775079c | 2013-09-04 20:08:46 +0000 | [diff] [blame] | 375 | passes.add(createInternalizePass(MustPreserveList)); |
Rafael Espindola | 38c4e53 | 2011-03-02 04:14:42 +0000 | [diff] [blame] | 376 | |
Chris Lattner | 5ef31a0 | 2010-03-12 18:44:54 +0000 | [diff] [blame] | 377 | // apply scope restrictions |
| 378 | passes.run(*mergedModule); |
Bill Wendling | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 379 | |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 380 | ScopeRestrictionsDone = true; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 383 | /// Optimize merged modules using various IPO passes |
Chris Lattner | 817a01f | 2011-05-22 00:20:07 +0000 | [diff] [blame] | 384 | bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, |
| 385 | std::string &errMsg) { |
Shuxin Yang | 0880939 | 2013-08-06 21:51:21 +0000 | [diff] [blame] | 386 | if (!this->determineTarget(errMsg)) |
| 387 | return false; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 388 | |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 389 | Module *mergedModule = Linker.getModule(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 390 | |
Bill Wendling | 8c18a6f | 2013-05-23 21:21:50 +0000 | [diff] [blame] | 391 | // Mark which symbols can not be internalized |
Bill Wendling | 64d5b28 | 2012-04-09 22:18:01 +0000 | [diff] [blame] | 392 | this->applyScopeRestrictions(); |
| 393 | |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 394 | // Instantiate the pass manager to organize the passes. |
| 395 | PassManager passes; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 396 | |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 397 | // Start off with a verification pass. |
| 398 | passes.add(createVerifierPass()); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 399 | |
Micah Villmow | 791cfc2 | 2012-10-08 16:39:34 +0000 | [diff] [blame] | 400 | // Add an appropriate DataLayout instance for this module... |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 401 | passes.add(new DataLayout(*TargetMach->getDataLayout())); |
| 402 | TargetMach->addAnalysisPasses(passes); |
Bill Wendling | 76b13ed | 2012-03-31 10:50:14 +0000 | [diff] [blame] | 403 | |
Rafael Espindola | 4d2e9d9 | 2012-04-16 10:58:38 +0000 | [diff] [blame] | 404 | // Enabling internalize here would use its AllButMain variant. It |
| 405 | // keeps only main if it exists and does nothing for libraries. Instead |
| 406 | // we create the pass ourselves with the symbol list provided by the linker. |
Bill Wendling | 8c18a6f | 2013-05-23 21:21:50 +0000 | [diff] [blame] | 407 | if (!DisableOpt) |
Bill Wendling | 6303b66 | 2013-02-28 14:11:10 +0000 | [diff] [blame] | 408 | PassManagerBuilder().populateLTOPassManager(passes, |
Bill Wendling | 50f3183 | 2012-12-10 21:33:45 +0000 | [diff] [blame] | 409 | /*Internalize=*/false, |
Bill Wendling | 3197b44 | 2012-04-02 22:16:50 +0000 | [diff] [blame] | 410 | !DisableInline, |
| 411 | DisableGVNLoadPRE); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 412 | |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 413 | // Make sure everything is still good. |
| 414 | passes.add(createVerifierPass()); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 415 | |
Lang Hames | a991b25 | 2013-03-13 21:18:46 +0000 | [diff] [blame] | 416 | PassManager codeGenPasses; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 417 | |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 418 | codeGenPasses.add(new DataLayout(*TargetMach->getDataLayout())); |
| 419 | TargetMach->addAnalysisPasses(codeGenPasses); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 420 | |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 421 | formatted_raw_ostream Out(out); |
Dan Gohman | d4c4543 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 422 | |
Bob Wilson | d696544 | 2013-03-29 23:28:55 +0000 | [diff] [blame] | 423 | // If the bitcode files contain ARC code and were compiled with optimization, |
| 424 | // the ObjCARCContractPass must be run, so do it unconditionally here. |
| 425 | codeGenPasses.add(createObjCARCContractPass()); |
| 426 | |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 427 | if (TargetMach->addPassesToEmitFile(codeGenPasses, Out, |
| 428 | TargetMachine::CGFT_ObjectFile)) { |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 429 | errMsg = "target file type not supported"; |
Shuxin Yang | 0880939 | 2013-08-06 21:51:21 +0000 | [diff] [blame] | 430 | return false; |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 431 | } |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 432 | |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 433 | // Run our queue of passes all at once now, efficiently. |
| 434 | passes.run(*mergedModule); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 435 | |
Bill Wendling | c94c562 | 2012-03-31 11:15:43 +0000 | [diff] [blame] | 436 | // Run the code generator, and write assembly file |
Lang Hames | a991b25 | 2013-03-13 21:18:46 +0000 | [diff] [blame] | 437 | codeGenPasses.run(*mergedModule); |
Nick Lewycky | d42b58b | 2009-07-26 22:16:39 +0000 | [diff] [blame] | 438 | |
Shuxin Yang | 0880939 | 2013-08-06 21:51:21 +0000 | [diff] [blame] | 439 | return true; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Bill Wendling | caf71d4 | 2012-03-31 10:49:43 +0000 | [diff] [blame] | 442 | /// setCodeGenDebugOptions - Set codegen debugging options to aid in debugging |
| 443 | /// LTO problems. |
| 444 | void LTOCodeGenerator::setCodeGenDebugOptions(const char *options) { |
| 445 | for (std::pair<StringRef, StringRef> o = getToken(options); |
| 446 | !o.first.empty(); o = getToken(o.second)) { |
| 447 | // ParseCommandLineOptions() expects argv[0] to be program name. Lazily add |
| 448 | // that. |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 449 | if (CodegenOptions.empty()) |
Peter Collingbourne | cc48854 | 2013-09-24 23:52:22 +0000 | [diff] [blame^] | 450 | CodegenOptions.push_back(strdup("libLLVMLTO")); |
Rafael Espindola | 66efc63 | 2013-09-04 17:44:24 +0000 | [diff] [blame] | 451 | CodegenOptions.push_back(strdup(o.first.str().c_str())); |
Bill Wendling | caf71d4 | 2012-03-31 10:49:43 +0000 | [diff] [blame] | 452 | } |
Nick Kledzik | 920ae98 | 2008-07-08 21:14:10 +0000 | [diff] [blame] | 453 | } |