blob: 111f8c8f18e528601a83379267a270d1693a7fc8 [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 Blaikie4d6ccb52012-01-20 21:51:11 +000037#include "llvm/Support/ErrorHandling.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"
Daniel Dunbar006a0342009-06-03 21:06:14 +000040#include "llvm/Support/SystemUtils.h"
Dan Gohman9f36c4e2010-10-07 20:48:46 +000041#include "llvm/Support/ToolOutputFile.h"
Michael J. Spencer3cc52ea2010-11-29 18:47:54 +000042#include "llvm/Support/Host.h"
43#include "llvm/Support/Program.h"
44#include "llvm/Support/Signals.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000045#include "llvm/Support/TargetRegistry.h"
46#include "llvm/Support/TargetSelect.h"
Michael J. Spencerf2f516f2010-12-09 18:06:07 +000047#include "llvm/Support/system_error.h"
Nick Kledzik77595fc2008-02-26 20:26:43 +000048#include "llvm/Config/config.h"
Rafael Espindolac684e832011-08-02 21:50:27 +000049#include "llvm/Transforms/IPO.h"
Rafael Espindola3d453ac2011-08-02 21:50:24 +000050#include "llvm/Transforms/IPO/PassManagerBuilder.h"
Nick Lewycky8189d402009-06-17 06:52:10 +000051#include <cstdlib>
Nick Kledzik77595fc2008-02-26 20:26:43 +000052#include <unistd.h>
Nick Kledzik77595fc2008-02-26 20:26:43 +000053#include <fcntl.h>
54
55
56using namespace llvm;
57
Nick Kledzik920ae982008-07-08 21:14:10 +000058static cl::opt<bool> DisableInline("disable-inlining",
59 cl::desc("Do not run the inliner pass"));
Nick Kledzik77595fc2008-02-26 20:26:43 +000060
61
62const char* LTOCodeGenerator::getVersionString()
63{
64#ifdef LLVM_VERSION_INFO
65 return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO;
66#else
67 return PACKAGE_NAME " version " PACKAGE_VERSION;
68#endif
69}
70
71
Owen Anderson0e7a5462009-07-02 00:31:14 +000072LTOCodeGenerator::LTOCodeGenerator()
73 : _context(getGlobalContext()),
Owen Anderson8b477ed2009-07-01 16:58:40 +000074 _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
Nick Kledzik77595fc2008-02-26 20:26:43 +000075 _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
Nick Kledzikef194ed2008-02-27 22:25:36 +000076 _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
Rafael Espindolae9efea12011-02-24 21:04:06 +000077 _nativeObjectFile(NULL)
Nick Kledzik77595fc2008-02-26 20:26:43 +000078{
Nick Lewyckyd42b58b2009-07-26 22:16:39 +000079 InitializeAllTargets();
Evan Chenge78085a2011-07-22 21:58:54 +000080 InitializeAllTargetMCs();
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 Espindola38c4e532011-03-02 04:14:42 +000094 bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg);
95
96 const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs();
97 for (int i = 0, e = undefs.size(); i != e; ++i)
98 _asmUndefinedRefs[undefs[i]] = 1;
99
100 return ret;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000101}
102
103
104bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, std::string& errMsg)
105{
106 switch (debug) {
107 case LTO_DEBUG_MODEL_NONE:
108 _emitDwarfDebugInfo = false;
109 return false;
110
111 case LTO_DEBUG_MODEL_DWARF:
112 _emitDwarfDebugInfo = true;
113 return false;
114 }
David Blaikie4d6ccb52012-01-20 21:51:11 +0000115 llvm_unreachable("Unknown debug format!");
Nick Kledzik77595fc2008-02-26 20:26:43 +0000116}
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 }
David Blaikie4d6ccb52012-01-20 21:51:11 +0000129 llvm_unreachable("Unknown PIC model!");
Nick Kledzik77595fc2008-02-26 20:26:43 +0000130}
131
Rafael Espindola2d643ef2010-08-11 00:15:13 +0000132void LTOCodeGenerator::setCpu(const char* mCpu)
133{
134 _mCpu = mCpu;
135}
136
Nick Kledzik77595fc2008-02-26 20:26:43 +0000137void LTOCodeGenerator::addMustPreserveSymbol(const char* sym)
138{
139 _mustPreserveSymbols[sym] = 1;
140}
141
142
Chris Lattnerb515d752009-08-23 07:49:08 +0000143bool LTOCodeGenerator::writeMergedModules(const char *path,
144 std::string &errMsg) {
145 if (determineTarget(errMsg))
146 return true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000147
Chris Lattnerb515d752009-08-23 07:49:08 +0000148 // mark which symbols can not be internalized
149 applyScopeRestrictions();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000150
Chris Lattnerb515d752009-08-23 07:49:08 +0000151 // create output file
152 std::string ErrInfo;
Dan Gohmanf2914012010-08-20 16:59:15 +0000153 tool_output_file Out(path, ErrInfo,
154 raw_fd_ostream::F_Binary);
Chris Lattnerb515d752009-08-23 07:49:08 +0000155 if (!ErrInfo.empty()) {
156 errMsg = "could not open bitcode file for writing: ";
157 errMsg += path;
158 return true;
159 }
Nick Kledzik77595fc2008-02-26 20:26:43 +0000160
Chris Lattnerb515d752009-08-23 07:49:08 +0000161 // write bitcode to it
Dan Gohmand4c45432010-09-01 14:20:41 +0000162 WriteBitcodeToFile(_linker.getModule(), Out.os());
163 Out.os().close();
Dan Gohman4b7416b2010-05-27 20:19:47 +0000164
Dan Gohmand4c45432010-09-01 14:20:41 +0000165 if (Out.os().has_error()) {
Chris Lattnerb515d752009-08-23 07:49:08 +0000166 errMsg = "could not write bitcode file: ";
167 errMsg += path;
Dan Gohmand4c45432010-09-01 14:20:41 +0000168 Out.os().clear_error();
Chris Lattnerb515d752009-08-23 07:49:08 +0000169 return true;
170 }
171
Dan Gohmanf2914012010-08-20 16:59:15 +0000172 Out.keep();
Chris Lattnerb515d752009-08-23 07:49:08 +0000173 return false;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000174}
175
176
Rafael Espindola6421a882011-03-22 20:57:13 +0000177bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg)
178{
179 // make unique temp .o file to put generated object file
180 sys::PathWithStatus uniqueObjPath("lto-llvm.o");
181 if ( uniqueObjPath.createTemporaryFileOnDisk(false, &errMsg) ) {
182 uniqueObjPath.eraseFromDisk();
183 return true;
184 }
185 sys::RemoveFileOnSignal(uniqueObjPath);
186
187 // generate object file
188 bool genResult = false;
189 tool_output_file objFile(uniqueObjPath.c_str(), errMsg);
190 if (!errMsg.empty())
John Criswell3f0e2372011-08-18 01:19:05 +0000191 return true;
Rafael Espindola6421a882011-03-22 20:57:13 +0000192 genResult = this->generateObjectFile(objFile.os(), errMsg);
193 objFile.os().close();
194 if (objFile.os().has_error()) {
195 objFile.os().clear_error();
196 return true;
197 }
198 objFile.keep();
199 if ( genResult ) {
200 uniqueObjPath.eraseFromDisk();
201 return true;
202 }
203
204 _nativeObjectPath = uniqueObjPath.str();
205 *name = _nativeObjectPath.c_str();
206 return false;
207}
208
Nick Kledzikef194ed2008-02-27 22:25:36 +0000209const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
Nick Kledzik77595fc2008-02-26 20:26:43 +0000210{
Rafael Espindola6421a882011-03-22 20:57:13 +0000211 const char *name;
212 if (compile_to_file(&name, errMsg))
213 return NULL;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000214
Rafael Espindola6421a882011-03-22 20:57:13 +0000215 // remove old buffer if compile() called twice
216 delete _nativeObjectFile;
Nick Kledzikef194ed2008-02-27 22:25:36 +0000217
Rafael Espindola6421a882011-03-22 20:57:13 +0000218 // read .o file into memory buffer
219 OwningPtr<MemoryBuffer> BuffPtr;
220 if (error_code ec = MemoryBuffer::getFile(name, BuffPtr, -1, false)) {
221 errMsg = ec.message();
222 return NULL;
223 }
224 _nativeObjectFile = BuffPtr.take();
Rafael Espindolae9efea12011-02-24 21:04:06 +0000225
Rafael Espindola6421a882011-03-22 20:57:13 +0000226 // remove temp files
227 sys::Path(_nativeObjectPath).eraseFromDisk();
Rafael Espindolae9efea12011-02-24 21:04:06 +0000228
Rafael Espindola6421a882011-03-22 20:57:13 +0000229 // return buffer, unless error
230 if ( _nativeObjectFile == NULL )
231 return NULL;
232 *length = _nativeObjectFile->getBufferSize();
233 return _nativeObjectFile->getBufferStart();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000234}
235
Nick Kledzik77595fc2008-02-26 20:26:43 +0000236bool LTOCodeGenerator::determineTarget(std::string& errMsg)
237{
238 if ( _target == NULL ) {
Daniel Dunbar3c2d4bf2009-08-03 04:03:51 +0000239 std::string Triple = _linker.getModule()->getTargetTriple();
240 if (Triple.empty())
Sebastian Pop01738642011-11-01 21:32:20 +0000241 Triple = sys::getDefaultTargetTriple();
Daniel Dunbar3c2d4bf2009-08-03 04:03:51 +0000242
Nick Kledzik77595fc2008-02-26 20:26:43 +0000243 // create target machine from info for merged modules
Daniel Dunbar4bd03ab2009-08-03 04:20:57 +0000244 const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000245 if ( march == NULL )
246 return true;
Bill Wendling604a8182008-06-18 06:35:30 +0000247
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000248 // The relocation model is actually a static member of TargetMachine
249 // and needs to be set before the TargetMachine is instantiated.
Evan Cheng43966132011-07-19 06:37:02 +0000250 Reloc::Model RelocModel = Reloc::Default;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000251 switch( _codeModel ) {
252 case LTO_CODEGEN_PIC_MODEL_STATIC:
Evan Cheng43966132011-07-19 06:37:02 +0000253 RelocModel = Reloc::Static;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000254 break;
255 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
Evan Cheng43966132011-07-19 06:37:02 +0000256 RelocModel = Reloc::PIC_;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000257 break;
258 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
Evan Cheng43966132011-07-19 06:37:02 +0000259 RelocModel = Reloc::DynamicNoPIC;
Nick Kledzikf5a1c35f12009-06-03 22:52:12 +0000260 break;
261 }
262
Nick Lewyckyfce6b502011-07-25 21:12:44 +0000263 // construct LTOModule, hand over ownership of module and target
Bill Wendling81043ee2010-05-11 00:30:02 +0000264 SubtargetFeatures Features;
Evan Cheng276365d2011-06-30 01:53:36 +0000265 Features.getDefaultSubtargetFeatures(llvm::Triple(Triple));
Bill Wendling81043ee2010-05-11 00:30:02 +0000266 std::string FeatureStr = Features.getString();
Nick Lewycky8a8d4792011-12-02 22:16:29 +0000267 TargetOptions Options;
268 _target = march->createTargetMachine(Triple, _mCpu, FeatureStr, Options,
Evan Cheng43966132011-07-19 06:37:02 +0000269 RelocModel);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000270 }
271 return false;
272}
273
Rafael Espindola38c4e532011-03-02 04:14:42 +0000274void LTOCodeGenerator::applyRestriction(GlobalValue &GV,
275 std::vector<const char*> &mustPreserveList,
276 SmallPtrSet<GlobalValue*, 8> &asmUsed,
277 Mangler &mangler) {
278 SmallString<64> Buffer;
279 mangler.getNameWithPrefix(Buffer, &GV, false);
280
281 if (GV.isDeclaration())
282 return;
283 if (_mustPreserveSymbols.count(Buffer))
284 mustPreserveList.push_back(GV.getName().data());
285 if (_asmUndefinedRefs.count(Buffer))
286 asmUsed.insert(&GV);
287}
288
289static void findUsedValues(GlobalVariable *LLVMUsed,
290 SmallPtrSet<GlobalValue*, 8> &UsedValues) {
291 if (LLVMUsed == 0) return;
292
293 ConstantArray *Inits = dyn_cast<ConstantArray>(LLVMUsed->getInitializer());
294 if (Inits == 0) return;
295
296 for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
297 if (GlobalValue *GV =
298 dyn_cast<GlobalValue>(Inits->getOperand(i)->stripPointerCasts()))
299 UsedValues.insert(GV);
300}
301
Chris Lattner5ef31a02010-03-12 18:44:54 +0000302void LTOCodeGenerator::applyScopeRestrictions() {
303 if (_scopeRestrictionsDone) return;
304 Module *mergedModule = _linker.getModule();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000305
Chris Lattner5ef31a02010-03-12 18:44:54 +0000306 // Start off with a verification pass.
307 PassManager passes;
308 passes.add(createVerifierPass());
Nick Kledzik77595fc2008-02-26 20:26:43 +0000309
Chris Lattner5ef31a02010-03-12 18:44:54 +0000310 // mark which symbols can not be internalized
Evan Cheng203576a2011-07-20 19:50:42 +0000311 MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL);
Rafael Espindola38c4e532011-03-02 04:14:42 +0000312 Mangler mangler(Context, *_target->getTargetData());
313 std::vector<const char*> mustPreserveList;
314 SmallPtrSet<GlobalValue*, 8> asmUsed;
315
316 for (Module::iterator f = mergedModule->begin(),
317 e = mergedModule->end(); f != e; ++f)
318 applyRestriction(*f, mustPreserveList, asmUsed, mangler);
319 for (Module::global_iterator v = mergedModule->global_begin(),
320 e = mergedModule->global_end(); v != e; ++v)
321 applyRestriction(*v, mustPreserveList, asmUsed, mangler);
322 for (Module::alias_iterator a = mergedModule->alias_begin(),
323 e = mergedModule->alias_end(); a != e; ++a)
324 applyRestriction(*a, mustPreserveList, asmUsed, mangler);
325
326 GlobalVariable *LLVMCompilerUsed =
327 mergedModule->getGlobalVariable("llvm.compiler.used");
328 findUsedValues(LLVMCompilerUsed, asmUsed);
329 if (LLVMCompilerUsed)
330 LLVMCompilerUsed->eraseFromParent();
331
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000332 llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(_context);
Rafael Espindola38c4e532011-03-02 04:14:42 +0000333 std::vector<Constant*> asmUsed2;
334 for (SmallPtrSet<GlobalValue*, 16>::const_iterator i = asmUsed.begin(),
335 e = asmUsed.end(); i !=e; ++i) {
336 GlobalValue *GV = *i;
337 Constant *c = ConstantExpr::getBitCast(GV, i8PTy);
338 asmUsed2.push_back(c);
Chris Lattner5ef31a02010-03-12 18:44:54 +0000339 }
Rafael Espindola38c4e532011-03-02 04:14:42 +0000340
341 llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, asmUsed2.size());
342 LLVMCompilerUsed =
343 new llvm::GlobalVariable(*mergedModule, ATy, false,
344 llvm::GlobalValue::AppendingLinkage,
345 llvm::ConstantArray::get(ATy, asmUsed2),
346 "llvm.compiler.used");
347
348 LLVMCompilerUsed->setSection("llvm.metadata");
349
350 passes.add(createInternalizePass(mustPreserveList));
351
Chris Lattner5ef31a02010-03-12 18:44:54 +0000352 // apply scope restrictions
353 passes.run(*mergedModule);
354
355 _scopeRestrictionsDone = true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000356}
357
Nick Kledzik77595fc2008-02-26 20:26:43 +0000358/// Optimize merged modules using various IPO passes
Chris Lattner817a01f2011-05-22 00:20:07 +0000359bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
360 std::string &errMsg) {
Nick Lewyckyd42b58b2009-07-26 22:16:39 +0000361 if ( this->determineTarget(errMsg) )
Nick Kledzik77595fc2008-02-26 20:26:43 +0000362 return true;
363
364 // mark which symbols can not be internalized
365 this->applyScopeRestrictions();
366
367 Module* mergedModule = _linker.getModule();
368
Nick Kledzik920ae982008-07-08 21:14:10 +0000369 // if options were requested, set them
370 if ( !_codegenOptions.empty() )
371 cl::ParseCommandLineOptions(_codegenOptions.size(),
Dan Gohman43bc70e2010-04-17 17:44:03 +0000372 const_cast<char **>(&_codegenOptions[0]));
Devang Patela93ae712008-07-03 22:53:14 +0000373
Nick Kledzik77595fc2008-02-26 20:26:43 +0000374 // Instantiate the pass manager to organize the passes.
375 PassManager passes;
376
377 // Start off with a verification pass.
378 passes.add(createVerifierPass());
379
380 // Add an appropriate TargetData instance for this module...
381 passes.add(new TargetData(*_target->getTargetData()));
382
Chris Lattner817a01f2011-05-22 00:20:07 +0000383 PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false,
384 !DisableInline);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000385
386 // Make sure everything is still good.
387 passes.add(createVerifierPass());
388
Chris Lattner817a01f2011-05-22 00:20:07 +0000389 FunctionPassManager *codeGenPasses = new FunctionPassManager(mergedModule);
Nick Kledzik77595fc2008-02-26 20:26:43 +0000390
391 codeGenPasses->add(new TargetData(*_target->getTargetData()));
392
Dan Gohmand4c45432010-09-01 14:20:41 +0000393 formatted_raw_ostream Out(out);
394
395 if (_target->addPassesToEmitFile(*codeGenPasses, Out,
Rafael Espindolae9efea12011-02-24 21:04:06 +0000396 TargetMachine::CGFT_ObjectFile,
Chris Lattner5669e302010-02-03 05:55:08 +0000397 CodeGenOpt::Aggressive)) {
398 errMsg = "target file type not supported";
399 return true;
Nick Kledzik77595fc2008-02-26 20:26:43 +0000400 }
401
Nick Kledzik77595fc2008-02-26 20:26:43 +0000402 // Run our queue of passes all at once now, efficiently.
403 passes.run(*mergedModule);
404
405 // Run the code generator, and write assembly file
406 codeGenPasses->doInitialization();
Nick Kledzik77595fc2008-02-26 20:26:43 +0000407
Bill Wendling604a8182008-06-18 06:35:30 +0000408 for (Module::iterator
409 it = mergedModule->begin(), e = mergedModule->end(); it != e; ++it)
410 if (!it->isDeclaration())
411 codeGenPasses->run(*it);
412
413 codeGenPasses->doFinalization();
Rafael Espindolacd6c93e2011-02-20 16:27:25 +0000414 delete codeGenPasses;
Nick Lewyckyd42b58b2009-07-26 22:16:39 +0000415
Nick Kledzik77595fc2008-02-26 20:26:43 +0000416 return false; // success
417}
418
419
Nick Kledzik920ae982008-07-08 21:14:10 +0000420/// Optimize merged modules using various IPO passes
421void LTOCodeGenerator::setCodeGenDebugOptions(const char* options)
422{
Benjamin Kramerd4f19592010-01-11 18:03:24 +0000423 for (std::pair<StringRef, StringRef> o = getToken(options);
424 !o.first.empty(); o = getToken(o.second)) {
Nick Kledzik920ae982008-07-08 21:14:10 +0000425 // ParseCommandLineOptions() expects argv[0] to be program name.
426 // Lazily add that.
427 if ( _codegenOptions.empty() )
428 _codegenOptions.push_back("libLTO");
Benjamin Kramerd4f19592010-01-11 18:03:24 +0000429 _codegenOptions.push_back(strdup(o.first.str().c_str()));
Nick Kledzik920ae982008-07-08 21:14:10 +0000430 }
431}