blob: 2f02847e77c786bb69f4119c7a02db6fbab83afa [file] [log] [blame]
Nick Kledzik77595fc2008-02-26 20:26:43 +00001//===-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.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Link Time Optimization library. This library is
11// intended to be used by linker to optimize code at link time.
12//
13//===----------------------------------------------------------------------===//
14
Nick Kledzikef194ed2008-02-27 22:25:36 +000015#include "LTOModule.h"
16#include "LTOCodeGenerator.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000017#include "llvm/Constants.h"
18#include "llvm/DerivedTypes.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000019#include "llvm/Linker.h"
Owen Anderson0e7a5462009-07-02 00:31:14 +000020#include "llvm/LLVMContext.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000021#include "llvm/Module.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000022#include "llvm/PassManager.h"
23#include "llvm/ADT/StringExtras.h"
Viktor Kutuzov51cdac02009-11-17 18:48:27 +000024#include "llvm/ADT/Triple.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000025#include "llvm/Analysis/Passes.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000026#include "llvm/Bitcode/ReaderWriter.h"
Chris Lattner5ef31a02010-03-12 18:44:54 +000027#include "llvm/MC/MCAsmInfo.h"
28#include "llvm/MC/MCContext.h"
Evan Chengab8be962011-06-29 01:14:12 +000029#include "llvm/MC/SubtargetFeature.h"
Chris Lattner5ef31a02010-03-12 18:44:54 +000030#include "llvm/Target/Mangler.h"
Chris Lattner5ef31a02010-03-12 18:44:54 +000031#include "llvm/Target/TargetOptions.h"
32#include "llvm/Target/TargetData.h"
33#include "llvm/Target/TargetMachine.h"
Evan Cheng0e6a0522011-07-18 20:57:22 +000034#include "llvm/Target/TargetRegisterInfo.h"
Chris Lattner5ef31a02010-03-12 18:44:54 +000035#include "llvm/Target/TargetRegistry.h"
36#include "llvm/Target/TargetSelect.h"
Nick Kledzik920ae982008-07-08 21:14:10 +000037#include "llvm/Support/CommandLine.h"
David Greene71847812009-07-14 20:18:05 +000038#include "llvm/Support/FormattedStream.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000039#include "llvm/Support/MemoryBuffer.h"
Chris Lattner817a01f2011-05-22 00:20:07 +000040#include "llvm/Support/PassManagerBuilder.h"
Daniel Dunbar006a0342009-06-03 21:06:14 +000041#include "llvm/Support/SystemUtils.h"
Dan Gohman9f36c4e2010-10-07 20:48:46 +000042#include "llvm/Support/ToolOutputFile.h"
Michael J. Spencer3cc52ea2010-11-29 18:47:54 +000043#include "llvm/Support/Host.h"
44#include "llvm/Support/Program.h"
45#include "llvm/Support/Signals.h"
Michael J. Spencerf2f516f2010-12-09 18:06:07 +000046#include "llvm/Support/system_error.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000047#include "llvm/Config/config.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000048#include <cstdlib>
Nick Kledzik77595fc2008-02-26 20:26:43 +000049#include <unistd.h>
Nick Kledzik77595fc2008-02-26 20:26:43 +000050#include <fcntl.h>
51
52
53using namespace llvm;
54
Nick Kledzik920ae982008-07-08 21:14:10 +000055static cl::opt<bool> DisableInline("disable-inlining",
56 cl::desc("Do not run the inliner pass"));
Nick Kledzik77595fc2008-02-26 20:26:43 +000057
58
59const char* LTOCodeGenerator::getVersionString()
60{
61#ifdef LLVM_VERSION_INFO
62 return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO;
63#else
64 return PACKAGE_NAME " version " PACKAGE_VERSION;
65#endif
66}
67
68
Owen Anderson0e7a5462009-07-02 00:31:14 +000069LTOCodeGenerator::LTOCodeGenerator()
70 : _context(getGlobalContext()),
Owen Anderson8b477ed2009-07-01 16:58:40 +000071 _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
Nick Kledzik77595fc2008-02-26 20:26:43 +000072 _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
Nick Kledzikef194ed2008-02-27 22:25:36 +000073 _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
Rafael Espindolae9efea12011-02-24 21:04:06 +000074 _nativeObjectFile(NULL)
Nick Kledzik77595fc2008-02-26 20:26:43 +000075{
Nick Lewyckyd42b58b2009-07-26 22:16:39 +000076 InitializeAllTargets();
Evan Cheng1abf2cb2011-07-14 23:50:31 +000077 InitializeAllMCAsmInfos();
Evan Cheng43966132011-07-19 06:37:02 +000078 InitializeAllMCCodeGenInfos();
Evan Cheng0e6a0522011-07-18 20:57:22 +000079 InitializeAllMCRegisterInfos();
Cameron Zwarichbf843e62011-07-11 22:19:51 +000080 InitializeAllMCSubtargetInfos();
Nick Lewyckyd42b58b2009-07-26 22:16:39 +000081 InitializeAllAsmPrinters();
Nick Kledzik77595fc2008-02-26 20:26:43 +000082}
83
84LTOCodeGenerator::~LTOCodeGenerator()
85{
Nick Kledzikef194ed2008-02-27 22:25:36 +000086 delete _target;
87 delete _nativeObjectFile;
Nick Kledzik77595fc2008-02-26 20:26:43 +000088}
89
90
91
92bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg)
93{
Rafael Espindolaf19d7a72011-03-18 19:51:00 +000094
95 if(mod->getLLVVMModule()->MaterializeAllPermanently(&errMsg))
96 return true;
97
Rafael Espindola38c4e532011-03-02 04:14:42 +000098 bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg);
99
100 const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs();
101 for (int i = 0, e = undefs.size(); i != e; ++i)
102 _asmUndefinedRefs[undefs[i]] = 1;
103
104 return ret;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000105}
106
107
108bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, std::string& errMsg)
109{
110 switch (debug) {
111 case LTO_DEBUG_MODEL_NONE:
112 _emitDwarfDebugInfo = false;
113 return false;
114
115 case LTO_DEBUG_MODEL_DWARF:
116 _emitDwarfDebugInfo = true;
117 return false;
118 }
119 errMsg = "unknown debug format";
120 return true;
121}
122
123
124bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model,
Evan Cheng855a1682009-06-26 06:57:16 +0000125 std::string& errMsg)
Nick Kledzik77595fc2008-02-26 20:26:43 +0000126{
127 switch (model) {
128 case LTO_CODEGEN_PIC_MODEL_STATIC:
129 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
130 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
131 _codeModel = model;
132 return false;
133 }
134 errMsg = "unknown pic model";
135 return true;
136}
137
Rafael Espindola2d643ef2010-08-11 00:15:13 +0000138void LTOCodeGenerator::setCpu(const char* mCpu)
139{
140 _mCpu = mCpu;
141}
142
Nick Kledzik77595fc2008-02-26 20:26:43 +0000143void LTOCodeGenerator::addMustPreserveSymbol(const char* sym)
144{
145 _mustPreserveSymbols[sym] = 1;
146}
147
148
Chris Lattnerb515d752009-08-23 07:49:08 +0000149bool LTOCodeGenerator::writeMergedModules(const char *path,
150 std::string &errMsg) {
151 if (determineTarget(errMsg))
152 return true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000153
Chris Lattnerb515d752009-08-23 07:49:08 +0000154 // mark which symbols can not be internalized
155 applyScopeRestrictions();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000156
Chris Lattnerb515d752009-08-23 07:49:08 +0000157 // create output file
158 std::string ErrInfo;
Dan Gohmanf2914012010-08-20 16:59:15 +0000159 tool_output_file Out(path, ErrInfo,
160 raw_fd_ostream::F_Binary);
Chris Lattnerb515d752009-08-23 07:49:08 +0000161 if (!ErrInfo.empty()) {
162 errMsg = "could not open bitcode file for writing: ";
163 errMsg += path;
164 return true;
165 }
Nick Kledzik77595fc2008-02-26 20:26:43 +0000166
Chris Lattnerb515d752009-08-23 07:49:08 +0000167 // write bitcode to it
Dan Gohmand4c45432010-09-01 14:20:41 +0000168 WriteBitcodeToFile(_linker.getModule(), Out.os());
169 Out.os().close();
Dan Gohman4b7416b2010-05-27 20:19:47 +0000170
Dan Gohmand4c45432010-09-01 14:20:41 +0000171 if (Out.os().has_error()) {
Chris Lattnerb515d752009-08-23 07:49:08 +0000172 errMsg = "could not write bitcode file: ";
173 errMsg += path;
Dan Gohmand4c45432010-09-01 14:20:41 +0000174 Out.os().clear_error();
Chris Lattnerb515d752009-08-23 07:49:08 +0000175 return true;
176 }
177
Dan Gohmanf2914012010-08-20 16:59:15 +0000178 Out.keep();
Chris Lattnerb515d752009-08-23 07:49:08 +0000179 return false;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000180}
181
182
Rafael Espindola6421a882011-03-22 20:57:13 +0000183bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg)
184{
185 // make unique temp .o file to put generated object file
186 sys::PathWithStatus uniqueObjPath("lto-llvm.o");
187 if ( uniqueObjPath.createTemporaryFileOnDisk(false, &errMsg) ) {
188 uniqueObjPath.eraseFromDisk();
189 return true;
190 }
191 sys::RemoveFileOnSignal(uniqueObjPath);
192
193 // generate object file
194 bool genResult = false;
195 tool_output_file objFile(uniqueObjPath.c_str(), errMsg);
196 if (!errMsg.empty())
197 return NULL;
198 genResult = this->generateObjectFile(objFile.os(), errMsg);
199 objFile.os().close();
200 if (objFile.os().has_error()) {
201 objFile.os().clear_error();
202 return true;
203 }
204 objFile.keep();
205 if ( genResult ) {
206 uniqueObjPath.eraseFromDisk();
207 return true;
208 }
209
210 _nativeObjectPath = uniqueObjPath.str();
211 *name = _nativeObjectPath.c_str();
212 return false;
213}
214
Nick Kledzikef194ed2008-02-27 22:25:36 +0000215const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
Nick Kledzik77595fc2008-02-26 20:26:43 +0000216{
Rafael Espindola6421a882011-03-22 20:57:13 +0000217 const char *name;
218 if (compile_to_file(&name, errMsg))
219 return NULL;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000220
Rafael Espindola6421a882011-03-22 20:57:13 +0000221 // remove old buffer if compile() called twice
222 delete _nativeObjectFile;
Nick Kledzikef194ed2008-02-27 22:25:36 +0000223
Rafael Espindola6421a882011-03-22 20:57:13 +0000224 // 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();
228 return NULL;
229 }
230 _nativeObjectFile = BuffPtr.take();
Rafael Espindolae9efea12011-02-24 21:04:06 +0000231
Rafael Espindola6421a882011-03-22 20:57:13 +0000232 // remove temp files
233 sys::Path(_nativeObjectPath).eraseFromDisk();
Rafael Espindolae9efea12011-02-24 21:04:06 +0000234
Rafael Espindola6421a882011-03-22 20:57:13 +0000235 // return buffer, unless error
236 if ( _nativeObjectFile == NULL )
237 return NULL;
238 *length = _nativeObjectFile->getBufferSize();
239 return _nativeObjectFile->getBufferStart();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000240}
241
Nick Kledzik77595fc2008-02-26 20:26:43 +0000242bool LTOCodeGenerator::determineTarget(std::string& errMsg)
243{
244 if ( _target == NULL ) {
Daniel Dunbar3c2d4bf2009-08-03 04:03:51 +0000245 std::string Triple = _linker.getModule()->getTargetTriple();
246 if (Triple.empty())
247 Triple = sys::getHostTriple();
248
Nick Kledzik77595fc2008-02-26 20:26:43 +0000249 // create target machine from info for merged modules
Daniel Dunbar4bd03ab2009-08-03 04:20:57 +0000250 const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000251 if ( march == NULL )
252 return true;
Bill Wendling604a8182008-06-18 06:35:30 +0000253
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000254 // The relocation model is actually a static member of TargetMachine
255 // and needs to be set before the TargetMachine is instantiated.
Evan Cheng43966132011-07-19 06:37:02 +0000256 Reloc::Model RelocModel = Reloc::Default;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000257 switch( _codeModel ) {
258 case LTO_CODEGEN_PIC_MODEL_STATIC:
Evan Cheng43966132011-07-19 06:37:02 +0000259 RelocModel = Reloc::Static;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000260 break;
261 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
Evan Cheng43966132011-07-19 06:37:02 +0000262 RelocModel = Reloc::PIC_;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000263 break;
264 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
Evan Cheng43966132011-07-19 06:37:02 +0000265 RelocModel = Reloc::DynamicNoPIC;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000266 break;
267 }
268
Bill Wendling604a8182008-06-18 06:35:30 +0000269 // construct LTModule, hand over ownership of module and target
Bill Wendling81043ee2010-05-11 00:30:02 +0000270 SubtargetFeatures Features;
Evan Cheng276365d2011-06-30 01:53:36 +0000271 Features.getDefaultSubtargetFeatures(llvm::Triple(Triple));
Bill Wendling81043ee2010-05-11 00:30:02 +0000272 std::string FeatureStr = Features.getString();
Evan Cheng43966132011-07-19 06:37:02 +0000273 _target = march->createTargetMachine(Triple, _mCpu, FeatureStr,
274 RelocModel);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000275 }
276 return false;
277}
278
Rafael Espindola38c4e532011-03-02 04:14:42 +0000279void LTOCodeGenerator::applyRestriction(GlobalValue &GV,
280 std::vector<const char*> &mustPreserveList,
281 SmallPtrSet<GlobalValue*, 8> &asmUsed,
282 Mangler &mangler) {
283 SmallString<64> Buffer;
284 mangler.getNameWithPrefix(Buffer, &GV, false);
285
286 if (GV.isDeclaration())
287 return;
288 if (_mustPreserveSymbols.count(Buffer))
289 mustPreserveList.push_back(GV.getName().data());
290 if (_asmUndefinedRefs.count(Buffer))
291 asmUsed.insert(&GV);
292}
293
294static void findUsedValues(GlobalVariable *LLVMUsed,
295 SmallPtrSet<GlobalValue*, 8> &UsedValues) {
296 if (LLVMUsed == 0) return;
297
298 ConstantArray *Inits = dyn_cast<ConstantArray>(LLVMUsed->getInitializer());
299 if (Inits == 0) return;
300
301 for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
302 if (GlobalValue *GV =
303 dyn_cast<GlobalValue>(Inits->getOperand(i)->stripPointerCasts()))
304 UsedValues.insert(GV);
305}
306
Chris Lattner5ef31a02010-03-12 18:44:54 +0000307void LTOCodeGenerator::applyScopeRestrictions() {
308 if (_scopeRestrictionsDone) return;
309 Module *mergedModule = _linker.getModule();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000310
Chris Lattner5ef31a02010-03-12 18:44:54 +0000311 // Start off with a verification pass.
312 PassManager passes;
313 passes.add(createVerifierPass());
Nick Kledzik77595fc2008-02-26 20:26:43 +0000314
Chris Lattner5ef31a02010-03-12 18:44:54 +0000315 // mark which symbols can not be internalized
Evan Cheng0e6a0522011-07-18 20:57:22 +0000316 MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),
Evan Chenge76a33b2011-07-20 05:58:47 +0000317 NULL, NULL);
Rafael Espindola38c4e532011-03-02 04:14:42 +0000318 Mangler mangler(Context, *_target->getTargetData());
319 std::vector<const char*> mustPreserveList;
320 SmallPtrSet<GlobalValue*, 8> asmUsed;
321
322 for (Module::iterator f = mergedModule->begin(),
323 e = mergedModule->end(); f != e; ++f)
324 applyRestriction(*f, mustPreserveList, asmUsed, mangler);
325 for (Module::global_iterator v = mergedModule->global_begin(),
326 e = mergedModule->global_end(); v != e; ++v)
327 applyRestriction(*v, mustPreserveList, asmUsed, mangler);
328 for (Module::alias_iterator a = mergedModule->alias_begin(),
329 e = mergedModule->alias_end(); a != e; ++a)
330 applyRestriction(*a, mustPreserveList, asmUsed, mangler);
331
332 GlobalVariable *LLVMCompilerUsed =
333 mergedModule->getGlobalVariable("llvm.compiler.used");
334 findUsedValues(LLVMCompilerUsed, asmUsed);
335 if (LLVMCompilerUsed)
336 LLVMCompilerUsed->eraseFromParent();
337
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000338 llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(_context);
Rafael Espindola38c4e532011-03-02 04:14:42 +0000339 std::vector<Constant*> asmUsed2;
340 for (SmallPtrSet<GlobalValue*, 16>::const_iterator i = asmUsed.begin(),
341 e = asmUsed.end(); i !=e; ++i) {
342 GlobalValue *GV = *i;
343 Constant *c = ConstantExpr::getBitCast(GV, i8PTy);
344 asmUsed2.push_back(c);
Chris Lattner5ef31a02010-03-12 18:44:54 +0000345 }
Rafael Espindola38c4e532011-03-02 04:14:42 +0000346
347 llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, asmUsed2.size());
348 LLVMCompilerUsed =
349 new llvm::GlobalVariable(*mergedModule, ATy, false,
350 llvm::GlobalValue::AppendingLinkage,
351 llvm::ConstantArray::get(ATy, asmUsed2),
352 "llvm.compiler.used");
353
354 LLVMCompilerUsed->setSection("llvm.metadata");
355
356 passes.add(createInternalizePass(mustPreserveList));
357
Chris Lattner5ef31a02010-03-12 18:44:54 +0000358 // apply scope restrictions
359 passes.run(*mergedModule);
360
361 _scopeRestrictionsDone = true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000362}
363
Nick Kledzik77595fc2008-02-26 20:26:43 +0000364/// Optimize merged modules using various IPO passes
Chris Lattner817a01f2011-05-22 00:20:07 +0000365bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
366 std::string &errMsg) {
Nick Lewyckyd42b58b2009-07-26 22:16:39 +0000367 if ( this->determineTarget(errMsg) )
Nick Kledzik77595fc2008-02-26 20:26:43 +0000368 return true;
369
370 // mark which symbols can not be internalized
371 this->applyScopeRestrictions();
372
373 Module* mergedModule = _linker.getModule();
374
Nick Kledzik920ae982008-07-08 21:14:10 +0000375 // if options were requested, set them
376 if ( !_codegenOptions.empty() )
377 cl::ParseCommandLineOptions(_codegenOptions.size(),
Dan Gohman43bc70e2010-04-17 17:44:03 +0000378 const_cast<char **>(&_codegenOptions[0]));
Devang Patela93ae712008-07-03 22:53:14 +0000379
Nick Kledzik77595fc2008-02-26 20:26:43 +0000380 // Instantiate the pass manager to organize the passes.
381 PassManager passes;
382
383 // Start off with a verification pass.
384 passes.add(createVerifierPass());
385
386 // Add an appropriate TargetData instance for this module...
387 passes.add(new TargetData(*_target->getTargetData()));
388
Chris Lattner817a01f2011-05-22 00:20:07 +0000389 PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false,
390 !DisableInline);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000391
392 // Make sure everything is still good.
393 passes.add(createVerifierPass());
394
Chris Lattner817a01f2011-05-22 00:20:07 +0000395 FunctionPassManager *codeGenPasses = new FunctionPassManager(mergedModule);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000396
397 codeGenPasses->add(new TargetData(*_target->getTargetData()));
398
Dan Gohmand4c45432010-09-01 14:20:41 +0000399 formatted_raw_ostream Out(out);
400
401 if (_target->addPassesToEmitFile(*codeGenPasses, Out,
Rafael Espindolae9efea12011-02-24 21:04:06 +0000402 TargetMachine::CGFT_ObjectFile,
Chris Lattner5669e302010-02-03 05:55:08 +0000403 CodeGenOpt::Aggressive)) {
404 errMsg = "target file type not supported";
405 return true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000406 }
407
Nick Kledzik77595fc2008-02-26 20:26:43 +0000408 // Run our queue of passes all at once now, efficiently.
409 passes.run(*mergedModule);
410
411 // Run the code generator, and write assembly file
412 codeGenPasses->doInitialization();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000413
Bill Wendling604a8182008-06-18 06:35:30 +0000414 for (Module::iterator
415 it = mergedModule->begin(), e = mergedModule->end(); it != e; ++it)
416 if (!it->isDeclaration())
417 codeGenPasses->run(*it);
418
419 codeGenPasses->doFinalization();
Rafael Espindolacd6c93e2011-02-20 16:27:25 +0000420 delete codeGenPasses;
Nick Lewyckyd42b58b2009-07-26 22:16:39 +0000421
Nick Kledzik77595fc2008-02-26 20:26:43 +0000422 return false; // success
423}
424
425
Nick Kledzik920ae982008-07-08 21:14:10 +0000426/// Optimize merged modules using various IPO passes
427void LTOCodeGenerator::setCodeGenDebugOptions(const char* options)
428{
Benjamin Kramerd4f19592010-01-11 18:03:24 +0000429 for (std::pair<StringRef, StringRef> o = getToken(options);
430 !o.first.empty(); o = getToken(o.second)) {
Nick Kledzik920ae982008-07-08 21:14:10 +0000431 // ParseCommandLineOptions() expects argv[0] to be program name.
432 // Lazily add that.
433 if ( _codegenOptions.empty() )
434 _codegenOptions.push_back("libLTO");
Benjamin Kramerd4f19592010-01-11 18:03:24 +0000435 _codegenOptions.push_back(strdup(o.first.str().c_str()));
Nick Kledzik920ae982008-07-08 21:14:10 +0000436 }
437}