blob: 77d7dfe94e1742c2a8e10dcf26c0182c1f04262a [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"
Rafael Espindolac684e832011-08-02 21:50:27 +000026#include "llvm/Analysis/Verifier.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000027#include "llvm/Bitcode/ReaderWriter.h"
Chris Lattner5ef31a02010-03-12 18:44:54 +000028#include "llvm/MC/MCAsmInfo.h"
29#include "llvm/MC/MCContext.h"
Evan Chengab8be962011-06-29 01:14:12 +000030#include "llvm/MC/SubtargetFeature.h"
Chris Lattner5ef31a02010-03-12 18:44:54 +000031#include "llvm/Target/Mangler.h"
Chris Lattner5ef31a02010-03-12 18:44:54 +000032#include "llvm/Target/TargetOptions.h"
33#include "llvm/Target/TargetData.h"
34#include "llvm/Target/TargetMachine.h"
Evan Cheng0e6a0522011-07-18 20:57:22 +000035#include "llvm/Target/TargetRegisterInfo.h"
Nick Kledzik920ae982008-07-08 21:14:10 +000036#include "llvm/Support/CommandLine.h"
David Greene71847812009-07-14 20:18:05 +000037#include "llvm/Support/FormattedStream.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000038#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbar006a0342009-06-03 21:06:14 +000039#include "llvm/Support/SystemUtils.h"
Dan Gohman9f36c4e2010-10-07 20:48:46 +000040#include "llvm/Support/ToolOutputFile.h"
Michael J. Spencer3cc52ea2010-11-29 18:47:54 +000041#include "llvm/Support/Host.h"
42#include "llvm/Support/Program.h"
43#include "llvm/Support/Signals.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000044#include "llvm/Support/TargetRegistry.h"
45#include "llvm/Support/TargetSelect.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"
Rafael Espindolac684e832011-08-02 21:50:27 +000048#include "llvm/Transforms/IPO.h"
Rafael Espindola3d453ac2011-08-02 21:50:24 +000049#include "llvm/Transforms/IPO/PassManagerBuilder.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000050#include <cstdlib>
Nick Kledzik77595fc2008-02-26 20:26:43 +000051#include <unistd.h>
Nick Kledzik77595fc2008-02-26 20:26:43 +000052#include <fcntl.h>
53
54
55using namespace llvm;
56
Nick Kledzik920ae982008-07-08 21:14:10 +000057static cl::opt<bool> DisableInline("disable-inlining",
58 cl::desc("Do not run the inliner pass"));
Nick Kledzik77595fc2008-02-26 20:26:43 +000059
60
61const char* LTOCodeGenerator::getVersionString()
62{
63#ifdef LLVM_VERSION_INFO
64 return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO;
65#else
66 return PACKAGE_NAME " version " PACKAGE_VERSION;
67#endif
68}
69
70
Owen Anderson0e7a5462009-07-02 00:31:14 +000071LTOCodeGenerator::LTOCodeGenerator()
72 : _context(getGlobalContext()),
Owen Anderson8b477ed2009-07-01 16:58:40 +000073 _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
Nick Kledzik77595fc2008-02-26 20:26:43 +000074 _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
Nick Kledzikef194ed2008-02-27 22:25:36 +000075 _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
Rafael Espindolae9efea12011-02-24 21:04:06 +000076 _nativeObjectFile(NULL)
Nick Kledzik77595fc2008-02-26 20:26:43 +000077{
Nick Lewyckyd42b58b2009-07-26 22:16:39 +000078 InitializeAllTargets();
Evan Chenge78085a2011-07-22 21:58:54 +000079 InitializeAllTargetMCs();
Nick Lewyckyd42b58b2009-07-26 22:16:39 +000080 InitializeAllAsmPrinters();
Nick Kledzik77595fc2008-02-26 20:26:43 +000081}
82
83LTOCodeGenerator::~LTOCodeGenerator()
84{
Nick Kledzikef194ed2008-02-27 22:25:36 +000085 delete _target;
86 delete _nativeObjectFile;
Nick Kledzik77595fc2008-02-26 20:26:43 +000087}
88
89
90
91bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg)
92{
Rafael Espindola38c4e532011-03-02 04:14:42 +000093 bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg);
94
95 const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs();
96 for (int i = 0, e = undefs.size(); i != e; ++i)
97 _asmUndefinedRefs[undefs[i]] = 1;
98
99 return ret;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000100}
101
102
103bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, std::string& errMsg)
104{
105 switch (debug) {
106 case LTO_DEBUG_MODEL_NONE:
107 _emitDwarfDebugInfo = false;
108 return false;
109
110 case LTO_DEBUG_MODEL_DWARF:
111 _emitDwarfDebugInfo = true;
112 return false;
113 }
114 errMsg = "unknown debug format";
115 return true;
116}
117
118
119bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model,
Evan Cheng855a1682009-06-26 06:57:16 +0000120 std::string& errMsg)
Nick Kledzik77595fc2008-02-26 20:26:43 +0000121{
122 switch (model) {
123 case LTO_CODEGEN_PIC_MODEL_STATIC:
124 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
125 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
126 _codeModel = model;
127 return false;
128 }
129 errMsg = "unknown pic model";
130 return true;
131}
132
Rafael Espindola2d643ef2010-08-11 00:15:13 +0000133void LTOCodeGenerator::setCpu(const char* mCpu)
134{
135 _mCpu = mCpu;
136}
137
Nick Kledzik77595fc2008-02-26 20:26:43 +0000138void LTOCodeGenerator::addMustPreserveSymbol(const char* sym)
139{
140 _mustPreserveSymbols[sym] = 1;
141}
142
143
Chris Lattnerb515d752009-08-23 07:49:08 +0000144bool LTOCodeGenerator::writeMergedModules(const char *path,
145 std::string &errMsg) {
146 if (determineTarget(errMsg))
147 return true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000148
Chris Lattnerb515d752009-08-23 07:49:08 +0000149 // mark which symbols can not be internalized
150 applyScopeRestrictions();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000151
Chris Lattnerb515d752009-08-23 07:49:08 +0000152 // create output file
153 std::string ErrInfo;
Dan Gohmanf2914012010-08-20 16:59:15 +0000154 tool_output_file Out(path, ErrInfo,
155 raw_fd_ostream::F_Binary);
Chris Lattnerb515d752009-08-23 07:49:08 +0000156 if (!ErrInfo.empty()) {
157 errMsg = "could not open bitcode file for writing: ";
158 errMsg += path;
159 return true;
160 }
Nick Kledzik77595fc2008-02-26 20:26:43 +0000161
Chris Lattnerb515d752009-08-23 07:49:08 +0000162 // write bitcode to it
Dan Gohmand4c45432010-09-01 14:20:41 +0000163 WriteBitcodeToFile(_linker.getModule(), Out.os());
164 Out.os().close();
Dan Gohman4b7416b2010-05-27 20:19:47 +0000165
Dan Gohmand4c45432010-09-01 14:20:41 +0000166 if (Out.os().has_error()) {
Chris Lattnerb515d752009-08-23 07:49:08 +0000167 errMsg = "could not write bitcode file: ";
168 errMsg += path;
Dan Gohmand4c45432010-09-01 14:20:41 +0000169 Out.os().clear_error();
Chris Lattnerb515d752009-08-23 07:49:08 +0000170 return true;
171 }
172
Dan Gohmanf2914012010-08-20 16:59:15 +0000173 Out.keep();
Chris Lattnerb515d752009-08-23 07:49:08 +0000174 return false;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000175}
176
177
Rafael Espindola6421a882011-03-22 20:57:13 +0000178bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg)
179{
180 // make unique temp .o file to put generated object file
181 sys::PathWithStatus uniqueObjPath("lto-llvm.o");
182 if ( uniqueObjPath.createTemporaryFileOnDisk(false, &errMsg) ) {
183 uniqueObjPath.eraseFromDisk();
184 return true;
185 }
186 sys::RemoveFileOnSignal(uniqueObjPath);
187
188 // generate object file
189 bool genResult = false;
190 tool_output_file objFile(uniqueObjPath.c_str(), errMsg);
191 if (!errMsg.empty())
John Criswell3f0e2372011-08-18 01:19:05 +0000192 return true;
Rafael Espindola6421a882011-03-22 20:57:13 +0000193 genResult = this->generateObjectFile(objFile.os(), errMsg);
194 objFile.os().close();
195 if (objFile.os().has_error()) {
196 objFile.os().clear_error();
197 return true;
198 }
199 objFile.keep();
200 if ( genResult ) {
201 uniqueObjPath.eraseFromDisk();
202 return true;
203 }
204
205 _nativeObjectPath = uniqueObjPath.str();
206 *name = _nativeObjectPath.c_str();
207 return false;
208}
209
Nick Kledzikef194ed2008-02-27 22:25:36 +0000210const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
Nick Kledzik77595fc2008-02-26 20:26:43 +0000211{
Rafael Espindola6421a882011-03-22 20:57:13 +0000212 const char *name;
213 if (compile_to_file(&name, errMsg))
214 return NULL;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000215
Rafael Espindola6421a882011-03-22 20:57:13 +0000216 // remove old buffer if compile() called twice
217 delete _nativeObjectFile;
Nick Kledzikef194ed2008-02-27 22:25:36 +0000218
Rafael Espindola6421a882011-03-22 20:57:13 +0000219 // read .o file into memory buffer
220 OwningPtr<MemoryBuffer> BuffPtr;
221 if (error_code ec = MemoryBuffer::getFile(name, BuffPtr, -1, false)) {
222 errMsg = ec.message();
223 return NULL;
224 }
225 _nativeObjectFile = BuffPtr.take();
Rafael Espindolae9efea12011-02-24 21:04:06 +0000226
Rafael Espindola6421a882011-03-22 20:57:13 +0000227 // remove temp files
228 sys::Path(_nativeObjectPath).eraseFromDisk();
Rafael Espindolae9efea12011-02-24 21:04:06 +0000229
Rafael Espindola6421a882011-03-22 20:57:13 +0000230 // return buffer, unless error
231 if ( _nativeObjectFile == NULL )
232 return NULL;
233 *length = _nativeObjectFile->getBufferSize();
234 return _nativeObjectFile->getBufferStart();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000235}
236
Nick Kledzik77595fc2008-02-26 20:26:43 +0000237bool LTOCodeGenerator::determineTarget(std::string& errMsg)
238{
239 if ( _target == NULL ) {
Daniel Dunbar3c2d4bf2009-08-03 04:03:51 +0000240 std::string Triple = _linker.getModule()->getTargetTriple();
241 if (Triple.empty())
Sebastian Pop01738642011-11-01 21:32:20 +0000242 Triple = sys::getDefaultTargetTriple();
Daniel Dunbar3c2d4bf2009-08-03 04:03:51 +0000243
Nick Kledzik77595fc2008-02-26 20:26:43 +0000244 // create target machine from info for merged modules
Daniel Dunbar4bd03ab2009-08-03 04:20:57 +0000245 const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000246 if ( march == NULL )
247 return true;
Bill Wendling604a8182008-06-18 06:35:30 +0000248
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000249 // The relocation model is actually a static member of TargetMachine
250 // and needs to be set before the TargetMachine is instantiated.
Evan Cheng43966132011-07-19 06:37:02 +0000251 Reloc::Model RelocModel = Reloc::Default;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000252 switch( _codeModel ) {
253 case LTO_CODEGEN_PIC_MODEL_STATIC:
Evan Cheng43966132011-07-19 06:37:02 +0000254 RelocModel = Reloc::Static;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000255 break;
256 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
Evan Cheng43966132011-07-19 06:37:02 +0000257 RelocModel = Reloc::PIC_;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000258 break;
259 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
Evan Cheng43966132011-07-19 06:37:02 +0000260 RelocModel = Reloc::DynamicNoPIC;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000261 break;
262 }
263
Nick Lewyckyfce6b502011-07-25 21:12:44 +0000264 // construct LTOModule, hand over ownership of module and target
Bill Wendling81043ee2010-05-11 00:30:02 +0000265 SubtargetFeatures Features;
Evan Cheng276365d2011-06-30 01:53:36 +0000266 Features.getDefaultSubtargetFeatures(llvm::Triple(Triple));
Bill Wendling81043ee2010-05-11 00:30:02 +0000267 std::string FeatureStr = Features.getString();
Nick Lewycky8a8d4792011-12-02 22:16:29 +0000268 TargetOptions Options;
269 _target = march->createTargetMachine(Triple, _mCpu, FeatureStr, Options,
Evan Cheng43966132011-07-19 06:37:02 +0000270 RelocModel);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000271 }
272 return false;
273}
274
Rafael Espindola38c4e532011-03-02 04:14:42 +0000275void LTOCodeGenerator::applyRestriction(GlobalValue &GV,
276 std::vector<const char*> &mustPreserveList,
277 SmallPtrSet<GlobalValue*, 8> &asmUsed,
278 Mangler &mangler) {
279 SmallString<64> Buffer;
280 mangler.getNameWithPrefix(Buffer, &GV, false);
281
282 if (GV.isDeclaration())
283 return;
284 if (_mustPreserveSymbols.count(Buffer))
285 mustPreserveList.push_back(GV.getName().data());
286 if (_asmUndefinedRefs.count(Buffer))
287 asmUsed.insert(&GV);
288}
289
290static void findUsedValues(GlobalVariable *LLVMUsed,
291 SmallPtrSet<GlobalValue*, 8> &UsedValues) {
292 if (LLVMUsed == 0) return;
293
294 ConstantArray *Inits = dyn_cast<ConstantArray>(LLVMUsed->getInitializer());
295 if (Inits == 0) return;
296
297 for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
298 if (GlobalValue *GV =
299 dyn_cast<GlobalValue>(Inits->getOperand(i)->stripPointerCasts()))
300 UsedValues.insert(GV);
301}
302
Chris Lattner5ef31a02010-03-12 18:44:54 +0000303void LTOCodeGenerator::applyScopeRestrictions() {
304 if (_scopeRestrictionsDone) return;
305 Module *mergedModule = _linker.getModule();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000306
Chris Lattner5ef31a02010-03-12 18:44:54 +0000307 // Start off with a verification pass.
308 PassManager passes;
309 passes.add(createVerifierPass());
Nick Kledzik77595fc2008-02-26 20:26:43 +0000310
Chris Lattner5ef31a02010-03-12 18:44:54 +0000311 // mark which symbols can not be internalized
Evan Cheng203576a2011-07-20 19:50:42 +0000312 MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL);
Rafael Espindola38c4e532011-03-02 04:14:42 +0000313 Mangler mangler(Context, *_target->getTargetData());
314 std::vector<const char*> mustPreserveList;
315 SmallPtrSet<GlobalValue*, 8> asmUsed;
316
317 for (Module::iterator f = mergedModule->begin(),
318 e = mergedModule->end(); f != e; ++f)
319 applyRestriction(*f, mustPreserveList, asmUsed, mangler);
320 for (Module::global_iterator v = mergedModule->global_begin(),
321 e = mergedModule->global_end(); v != e; ++v)
322 applyRestriction(*v, mustPreserveList, asmUsed, mangler);
323 for (Module::alias_iterator a = mergedModule->alias_begin(),
324 e = mergedModule->alias_end(); a != e; ++a)
325 applyRestriction(*a, mustPreserveList, asmUsed, mangler);
326
327 GlobalVariable *LLVMCompilerUsed =
328 mergedModule->getGlobalVariable("llvm.compiler.used");
329 findUsedValues(LLVMCompilerUsed, asmUsed);
330 if (LLVMCompilerUsed)
331 LLVMCompilerUsed->eraseFromParent();
332
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000333 llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(_context);
Rafael Espindola38c4e532011-03-02 04:14:42 +0000334 std::vector<Constant*> asmUsed2;
335 for (SmallPtrSet<GlobalValue*, 16>::const_iterator i = asmUsed.begin(),
336 e = asmUsed.end(); i !=e; ++i) {
337 GlobalValue *GV = *i;
338 Constant *c = ConstantExpr::getBitCast(GV, i8PTy);
339 asmUsed2.push_back(c);
Chris Lattner5ef31a02010-03-12 18:44:54 +0000340 }
Rafael Espindola38c4e532011-03-02 04:14:42 +0000341
342 llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, asmUsed2.size());
343 LLVMCompilerUsed =
344 new llvm::GlobalVariable(*mergedModule, ATy, false,
345 llvm::GlobalValue::AppendingLinkage,
346 llvm::ConstantArray::get(ATy, asmUsed2),
347 "llvm.compiler.used");
348
349 LLVMCompilerUsed->setSection("llvm.metadata");
350
351 passes.add(createInternalizePass(mustPreserveList));
352
Chris Lattner5ef31a02010-03-12 18:44:54 +0000353 // apply scope restrictions
354 passes.run(*mergedModule);
355
356 _scopeRestrictionsDone = true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000357}
358
Nick Kledzik77595fc2008-02-26 20:26:43 +0000359/// Optimize merged modules using various IPO passes
Chris Lattner817a01f2011-05-22 00:20:07 +0000360bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
361 std::string &errMsg) {
Nick Lewyckyd42b58b2009-07-26 22:16:39 +0000362 if ( this->determineTarget(errMsg) )
Nick Kledzik77595fc2008-02-26 20:26:43 +0000363 return true;
364
365 // mark which symbols can not be internalized
366 this->applyScopeRestrictions();
367
368 Module* mergedModule = _linker.getModule();
369
Nick Kledzik920ae982008-07-08 21:14:10 +0000370 // if options were requested, set them
371 if ( !_codegenOptions.empty() )
372 cl::ParseCommandLineOptions(_codegenOptions.size(),
Dan Gohman43bc70e2010-04-17 17:44:03 +0000373 const_cast<char **>(&_codegenOptions[0]));
Devang Patela93ae712008-07-03 22:53:14 +0000374
Nick Kledzik77595fc2008-02-26 20:26:43 +0000375 // Instantiate the pass manager to organize the passes.
376 PassManager passes;
377
378 // Start off with a verification pass.
379 passes.add(createVerifierPass());
380
381 // Add an appropriate TargetData instance for this module...
382 passes.add(new TargetData(*_target->getTargetData()));
383
Chris Lattner817a01f2011-05-22 00:20:07 +0000384 PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false,
385 !DisableInline);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000386
387 // Make sure everything is still good.
388 passes.add(createVerifierPass());
389
Chris Lattner817a01f2011-05-22 00:20:07 +0000390 FunctionPassManager *codeGenPasses = new FunctionPassManager(mergedModule);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000391
392 codeGenPasses->add(new TargetData(*_target->getTargetData()));
393
Dan Gohmand4c45432010-09-01 14:20:41 +0000394 formatted_raw_ostream Out(out);
395
396 if (_target->addPassesToEmitFile(*codeGenPasses, Out,
Rafael Espindolae9efea12011-02-24 21:04:06 +0000397 TargetMachine::CGFT_ObjectFile,
Chris Lattner5669e302010-02-03 05:55:08 +0000398 CodeGenOpt::Aggressive)) {
399 errMsg = "target file type not supported";
400 return true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000401 }
402
Nick Kledzik77595fc2008-02-26 20:26:43 +0000403 // Run our queue of passes all at once now, efficiently.
404 passes.run(*mergedModule);
405
406 // Run the code generator, and write assembly file
407 codeGenPasses->doInitialization();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000408
Bill Wendling604a8182008-06-18 06:35:30 +0000409 for (Module::iterator
410 it = mergedModule->begin(), e = mergedModule->end(); it != e; ++it)
411 if (!it->isDeclaration())
412 codeGenPasses->run(*it);
413
414 codeGenPasses->doFinalization();
Rafael Espindolacd6c93e2011-02-20 16:27:25 +0000415 delete codeGenPasses;
Nick Lewyckyd42b58b2009-07-26 22:16:39 +0000416
Nick Kledzik77595fc2008-02-26 20:26:43 +0000417 return false; // success
418}
419
420
Nick Kledzik920ae982008-07-08 21:14:10 +0000421/// Optimize merged modules using various IPO passes
422void LTOCodeGenerator::setCodeGenDebugOptions(const char* options)
423{
Benjamin Kramerd4f19592010-01-11 18:03:24 +0000424 for (std::pair<StringRef, StringRef> o = getToken(options);
425 !o.first.empty(); o = getToken(o.second)) {
Nick Kledzik920ae982008-07-08 21:14:10 +0000426 // ParseCommandLineOptions() expects argv[0] to be program name.
427 // Lazily add that.
428 if ( _codegenOptions.empty() )
429 _codegenOptions.push_back("libLTO");
Benjamin Kramerd4f19592010-01-11 18:03:24 +0000430 _codegenOptions.push_back(strdup(o.first.str().c_str()));
Nick Kledzik920ae982008-07-08 21:14:10 +0000431 }
432}