blob: cff6cb15a8942ce247c155d72a6594dfcf527764 [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"
Chris Lattner5ef31a02010-03-12 18:44:54 +000036#include "llvm/Target/TargetRegistry.h"
37#include "llvm/Target/TargetSelect.h"
Nick Kledzik920ae982008-07-08 21:14:10 +000038#include "llvm/Support/CommandLine.h"
David Greene71847812009-07-14 20:18:05 +000039#include "llvm/Support/FormattedStream.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000040#include "llvm/Support/MemoryBuffer.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"
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 Espindolaf19d7a72011-03-18 19:51:00 +000093
94 if(mod->getLLVVMModule()->MaterializeAllPermanently(&errMsg))
95 return true;
96
Rafael Espindola38c4e532011-03-02 04:14:42 +000097 bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg);
98
99 const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs();
100 for (int i = 0, e = undefs.size(); i != e; ++i)
101 _asmUndefinedRefs[undefs[i]] = 1;
102
103 return ret;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000104}
105
106
107bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, std::string& errMsg)
108{
109 switch (debug) {
110 case LTO_DEBUG_MODEL_NONE:
111 _emitDwarfDebugInfo = false;
112 return false;
113
114 case LTO_DEBUG_MODEL_DWARF:
115 _emitDwarfDebugInfo = true;
116 return false;
117 }
118 errMsg = "unknown debug format";
119 return true;
120}
121
122
123bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model,
Evan Cheng855a1682009-06-26 06:57:16 +0000124 std::string& errMsg)
Nick Kledzik77595fc2008-02-26 20:26:43 +0000125{
126 switch (model) {
127 case LTO_CODEGEN_PIC_MODEL_STATIC:
128 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
129 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
130 _codeModel = model;
131 return false;
132 }
133 errMsg = "unknown pic model";
134 return true;
135}
136
Rafael Espindola2d643ef2010-08-11 00:15:13 +0000137void LTOCodeGenerator::setCpu(const char* mCpu)
138{
139 _mCpu = mCpu;
140}
141
Nick Kledzik77595fc2008-02-26 20:26:43 +0000142void LTOCodeGenerator::addMustPreserveSymbol(const char* sym)
143{
144 _mustPreserveSymbols[sym] = 1;
145}
146
147
Chris Lattnerb515d752009-08-23 07:49:08 +0000148bool LTOCodeGenerator::writeMergedModules(const char *path,
149 std::string &errMsg) {
150 if (determineTarget(errMsg))
151 return true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000152
Chris Lattnerb515d752009-08-23 07:49:08 +0000153 // mark which symbols can not be internalized
154 applyScopeRestrictions();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000155
Chris Lattnerb515d752009-08-23 07:49:08 +0000156 // create output file
157 std::string ErrInfo;
Dan Gohmanf2914012010-08-20 16:59:15 +0000158 tool_output_file Out(path, ErrInfo,
159 raw_fd_ostream::F_Binary);
Chris Lattnerb515d752009-08-23 07:49:08 +0000160 if (!ErrInfo.empty()) {
161 errMsg = "could not open bitcode file for writing: ";
162 errMsg += path;
163 return true;
164 }
Nick Kledzik77595fc2008-02-26 20:26:43 +0000165
Chris Lattnerb515d752009-08-23 07:49:08 +0000166 // write bitcode to it
Dan Gohmand4c45432010-09-01 14:20:41 +0000167 WriteBitcodeToFile(_linker.getModule(), Out.os());
168 Out.os().close();
Dan Gohman4b7416b2010-05-27 20:19:47 +0000169
Dan Gohmand4c45432010-09-01 14:20:41 +0000170 if (Out.os().has_error()) {
Chris Lattnerb515d752009-08-23 07:49:08 +0000171 errMsg = "could not write bitcode file: ";
172 errMsg += path;
Dan Gohmand4c45432010-09-01 14:20:41 +0000173 Out.os().clear_error();
Chris Lattnerb515d752009-08-23 07:49:08 +0000174 return true;
175 }
176
Dan Gohmanf2914012010-08-20 16:59:15 +0000177 Out.keep();
Chris Lattnerb515d752009-08-23 07:49:08 +0000178 return false;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000179}
180
181
Rafael Espindola6421a882011-03-22 20:57:13 +0000182bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg)
183{
184 // make unique temp .o file to put generated object file
185 sys::PathWithStatus uniqueObjPath("lto-llvm.o");
186 if ( uniqueObjPath.createTemporaryFileOnDisk(false, &errMsg) ) {
187 uniqueObjPath.eraseFromDisk();
188 return true;
189 }
190 sys::RemoveFileOnSignal(uniqueObjPath);
191
192 // generate object file
193 bool genResult = false;
194 tool_output_file objFile(uniqueObjPath.c_str(), errMsg);
195 if (!errMsg.empty())
John Criswell3f0e2372011-08-18 01:19:05 +0000196 return true;
Rafael Espindola6421a882011-03-22 20:57:13 +0000197 genResult = this->generateObjectFile(objFile.os(), errMsg);
198 objFile.os().close();
199 if (objFile.os().has_error()) {
200 objFile.os().clear_error();
201 return true;
202 }
203 objFile.keep();
204 if ( genResult ) {
205 uniqueObjPath.eraseFromDisk();
206 return true;
207 }
208
209 _nativeObjectPath = uniqueObjPath.str();
210 *name = _nativeObjectPath.c_str();
211 return false;
212}
213
Nick Kledzikef194ed2008-02-27 22:25:36 +0000214const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
Nick Kledzik77595fc2008-02-26 20:26:43 +0000215{
Rafael Espindola6421a882011-03-22 20:57:13 +0000216 const char *name;
217 if (compile_to_file(&name, errMsg))
218 return NULL;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000219
Rafael Espindola6421a882011-03-22 20:57:13 +0000220 // remove old buffer if compile() called twice
221 delete _nativeObjectFile;
Nick Kledzikef194ed2008-02-27 22:25:36 +0000222
Rafael Espindola6421a882011-03-22 20:57:13 +0000223 // read .o file into memory buffer
224 OwningPtr<MemoryBuffer> BuffPtr;
225 if (error_code ec = MemoryBuffer::getFile(name, BuffPtr, -1, false)) {
226 errMsg = ec.message();
227 return NULL;
228 }
229 _nativeObjectFile = BuffPtr.take();
Rafael Espindolae9efea12011-02-24 21:04:06 +0000230
Rafael Espindola6421a882011-03-22 20:57:13 +0000231 // remove temp files
232 sys::Path(_nativeObjectPath).eraseFromDisk();
Rafael Espindolae9efea12011-02-24 21:04:06 +0000233
Rafael Espindola6421a882011-03-22 20:57:13 +0000234 // return buffer, unless error
235 if ( _nativeObjectFile == NULL )
236 return NULL;
237 *length = _nativeObjectFile->getBufferSize();
238 return _nativeObjectFile->getBufferStart();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000239}
240
Nick Kledzik77595fc2008-02-26 20:26:43 +0000241bool LTOCodeGenerator::determineTarget(std::string& errMsg)
242{
243 if ( _target == NULL ) {
Daniel Dunbar3c2d4bf2009-08-03 04:03:51 +0000244 std::string Triple = _linker.getModule()->getTargetTriple();
245 if (Triple.empty())
246 Triple = sys::getHostTriple();
247
Nick Kledzik77595fc2008-02-26 20:26:43 +0000248 // create target machine from info for merged modules
Daniel Dunbar4bd03ab2009-08-03 04:20:57 +0000249 const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000250 if ( march == NULL )
251 return true;
Bill Wendling604a8182008-06-18 06:35:30 +0000252
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000253 // The relocation model is actually a static member of TargetMachine
254 // and needs to be set before the TargetMachine is instantiated.
Evan Cheng43966132011-07-19 06:37:02 +0000255 Reloc::Model RelocModel = Reloc::Default;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000256 switch( _codeModel ) {
257 case LTO_CODEGEN_PIC_MODEL_STATIC:
Evan Cheng43966132011-07-19 06:37:02 +0000258 RelocModel = Reloc::Static;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000259 break;
260 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
Evan Cheng43966132011-07-19 06:37:02 +0000261 RelocModel = Reloc::PIC_;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000262 break;
263 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
Evan Cheng43966132011-07-19 06:37:02 +0000264 RelocModel = Reloc::DynamicNoPIC;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000265 break;
266 }
267
Nick Lewyckyfce6b502011-07-25 21:12:44 +0000268 // construct LTOModule, hand over ownership of module and target
Bill Wendling81043ee2010-05-11 00:30:02 +0000269 SubtargetFeatures Features;
Evan Cheng276365d2011-06-30 01:53:36 +0000270 Features.getDefaultSubtargetFeatures(llvm::Triple(Triple));
Bill Wendling81043ee2010-05-11 00:30:02 +0000271 std::string FeatureStr = Features.getString();
Evan Cheng43966132011-07-19 06:37:02 +0000272 _target = march->createTargetMachine(Triple, _mCpu, FeatureStr,
273 RelocModel);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000274 }
275 return false;
276}
277
Rafael Espindola38c4e532011-03-02 04:14:42 +0000278void LTOCodeGenerator::applyRestriction(GlobalValue &GV,
279 std::vector<const char*> &mustPreserveList,
280 SmallPtrSet<GlobalValue*, 8> &asmUsed,
281 Mangler &mangler) {
282 SmallString<64> Buffer;
283 mangler.getNameWithPrefix(Buffer, &GV, false);
284
285 if (GV.isDeclaration())
286 return;
287 if (_mustPreserveSymbols.count(Buffer))
288 mustPreserveList.push_back(GV.getName().data());
289 if (_asmUndefinedRefs.count(Buffer))
290 asmUsed.insert(&GV);
291}
292
293static void findUsedValues(GlobalVariable *LLVMUsed,
294 SmallPtrSet<GlobalValue*, 8> &UsedValues) {
295 if (LLVMUsed == 0) return;
296
297 ConstantArray *Inits = dyn_cast<ConstantArray>(LLVMUsed->getInitializer());
298 if (Inits == 0) return;
299
300 for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
301 if (GlobalValue *GV =
302 dyn_cast<GlobalValue>(Inits->getOperand(i)->stripPointerCasts()))
303 UsedValues.insert(GV);
304}
305
Chris Lattner5ef31a02010-03-12 18:44:54 +0000306void LTOCodeGenerator::applyScopeRestrictions() {
307 if (_scopeRestrictionsDone) return;
308 Module *mergedModule = _linker.getModule();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000309
Chris Lattner5ef31a02010-03-12 18:44:54 +0000310 // Start off with a verification pass.
311 PassManager passes;
312 passes.add(createVerifierPass());
Nick Kledzik77595fc2008-02-26 20:26:43 +0000313
Chris Lattner5ef31a02010-03-12 18:44:54 +0000314 // mark which symbols can not be internalized
Evan Cheng203576a2011-07-20 19:50:42 +0000315 MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL);
Rafael Espindola38c4e532011-03-02 04:14:42 +0000316 Mangler mangler(Context, *_target->getTargetData());
317 std::vector<const char*> mustPreserveList;
318 SmallPtrSet<GlobalValue*, 8> asmUsed;
319
320 for (Module::iterator f = mergedModule->begin(),
321 e = mergedModule->end(); f != e; ++f)
322 applyRestriction(*f, mustPreserveList, asmUsed, mangler);
323 for (Module::global_iterator v = mergedModule->global_begin(),
324 e = mergedModule->global_end(); v != e; ++v)
325 applyRestriction(*v, mustPreserveList, asmUsed, mangler);
326 for (Module::alias_iterator a = mergedModule->alias_begin(),
327 e = mergedModule->alias_end(); a != e; ++a)
328 applyRestriction(*a, mustPreserveList, asmUsed, mangler);
329
330 GlobalVariable *LLVMCompilerUsed =
331 mergedModule->getGlobalVariable("llvm.compiler.used");
332 findUsedValues(LLVMCompilerUsed, asmUsed);
333 if (LLVMCompilerUsed)
334 LLVMCompilerUsed->eraseFromParent();
335
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000336 llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(_context);
Rafael Espindola38c4e532011-03-02 04:14:42 +0000337 std::vector<Constant*> asmUsed2;
338 for (SmallPtrSet<GlobalValue*, 16>::const_iterator i = asmUsed.begin(),
339 e = asmUsed.end(); i !=e; ++i) {
340 GlobalValue *GV = *i;
341 Constant *c = ConstantExpr::getBitCast(GV, i8PTy);
342 asmUsed2.push_back(c);
Chris Lattner5ef31a02010-03-12 18:44:54 +0000343 }
Rafael Espindola38c4e532011-03-02 04:14:42 +0000344
345 llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, asmUsed2.size());
346 LLVMCompilerUsed =
347 new llvm::GlobalVariable(*mergedModule, ATy, false,
348 llvm::GlobalValue::AppendingLinkage,
349 llvm::ConstantArray::get(ATy, asmUsed2),
350 "llvm.compiler.used");
351
352 LLVMCompilerUsed->setSection("llvm.metadata");
353
354 passes.add(createInternalizePass(mustPreserveList));
355
Chris Lattner5ef31a02010-03-12 18:44:54 +0000356 // apply scope restrictions
357 passes.run(*mergedModule);
358
359 _scopeRestrictionsDone = true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000360}
361
Nick Kledzik77595fc2008-02-26 20:26:43 +0000362/// Optimize merged modules using various IPO passes
Chris Lattner817a01f2011-05-22 00:20:07 +0000363bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
364 std::string &errMsg) {
Nick Lewyckyd42b58b2009-07-26 22:16:39 +0000365 if ( this->determineTarget(errMsg) )
Nick Kledzik77595fc2008-02-26 20:26:43 +0000366 return true;
367
368 // mark which symbols can not be internalized
369 this->applyScopeRestrictions();
370
371 Module* mergedModule = _linker.getModule();
372
Nick Kledzik920ae982008-07-08 21:14:10 +0000373 // if options were requested, set them
374 if ( !_codegenOptions.empty() )
375 cl::ParseCommandLineOptions(_codegenOptions.size(),
Dan Gohman43bc70e2010-04-17 17:44:03 +0000376 const_cast<char **>(&_codegenOptions[0]));
Devang Patela93ae712008-07-03 22:53:14 +0000377
Nick Kledzik77595fc2008-02-26 20:26:43 +0000378 // Instantiate the pass manager to organize the passes.
379 PassManager passes;
380
381 // Start off with a verification pass.
382 passes.add(createVerifierPass());
383
384 // Add an appropriate TargetData instance for this module...
385 passes.add(new TargetData(*_target->getTargetData()));
386
Chris Lattner817a01f2011-05-22 00:20:07 +0000387 PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false,
388 !DisableInline);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000389
390 // Make sure everything is still good.
391 passes.add(createVerifierPass());
392
Chris Lattner817a01f2011-05-22 00:20:07 +0000393 FunctionPassManager *codeGenPasses = new FunctionPassManager(mergedModule);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000394
395 codeGenPasses->add(new TargetData(*_target->getTargetData()));
396
Dan Gohmand4c45432010-09-01 14:20:41 +0000397 formatted_raw_ostream Out(out);
398
399 if (_target->addPassesToEmitFile(*codeGenPasses, Out,
Rafael Espindolae9efea12011-02-24 21:04:06 +0000400 TargetMachine::CGFT_ObjectFile,
Chris Lattner5669e302010-02-03 05:55:08 +0000401 CodeGenOpt::Aggressive)) {
402 errMsg = "target file type not supported";
403 return true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000404 }
405
Nick Kledzik77595fc2008-02-26 20:26:43 +0000406 // Run our queue of passes all at once now, efficiently.
407 passes.run(*mergedModule);
408
409 // Run the code generator, and write assembly file
410 codeGenPasses->doInitialization();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000411
Bill Wendling604a8182008-06-18 06:35:30 +0000412 for (Module::iterator
413 it = mergedModule->begin(), e = mergedModule->end(); it != e; ++it)
414 if (!it->isDeclaration())
415 codeGenPasses->run(*it);
416
417 codeGenPasses->doFinalization();
Rafael Espindolacd6c93e2011-02-20 16:27:25 +0000418 delete codeGenPasses;
Nick Lewyckyd42b58b2009-07-26 22:16:39 +0000419
Nick Kledzik77595fc2008-02-26 20:26:43 +0000420 return false; // success
421}
422
423
Nick Kledzik920ae982008-07-08 21:14:10 +0000424/// Optimize merged modules using various IPO passes
425void LTOCodeGenerator::setCodeGenDebugOptions(const char* options)
426{
Benjamin Kramerd4f19592010-01-11 18:03:24 +0000427 for (std::pair<StringRef, StringRef> o = getToken(options);
428 !o.first.empty(); o = getToken(o.second)) {
Nick Kledzik920ae982008-07-08 21:14:10 +0000429 // ParseCommandLineOptions() expects argv[0] to be program name.
430 // Lazily add that.
431 if ( _codegenOptions.empty() )
432 _codegenOptions.push_back("libLTO");
Benjamin Kramerd4f19592010-01-11 18:03:24 +0000433 _codegenOptions.push_back(strdup(o.first.str().c_str()));
Nick Kledzik920ae982008-07-08 21:14:10 +0000434 }
435}